test-org.el 271 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342
  1. ;;; test-org.el --- tests for org.el
  2. ;; Copyright (c) David Maus
  3. ;; Authors: David Maus
  4. ;; This file is not part of GNU Emacs.
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. ;; Template test file for Org tests
  16. ;;; Code:
  17. (eval-and-compile (require 'cl-lib))
  18. ;;; Comments
  19. (ert-deftest test-org/toggle-comment ()
  20. "Test `org-toggle-comment' specifications."
  21. ;; Simple headline.
  22. (should
  23. (equal "* Test"
  24. (org-test-with-temp-text "* COMMENT Test"
  25. (org-toggle-comment)
  26. (buffer-string))))
  27. (should
  28. (equal "* COMMENT Test"
  29. (org-test-with-temp-text "* Test"
  30. (org-toggle-comment)
  31. (buffer-string))))
  32. ;; Headline with a regular keyword.
  33. (should
  34. (equal "* TODO Test"
  35. (org-test-with-temp-text "* TODO COMMENT Test"
  36. (org-toggle-comment)
  37. (buffer-string))))
  38. (should
  39. (equal "* TODO COMMENT Test"
  40. (org-test-with-temp-text "* TODO Test"
  41. (org-toggle-comment)
  42. (buffer-string))))
  43. ;; Empty headline.
  44. (should
  45. (equal "* "
  46. (org-test-with-temp-text "* COMMENT"
  47. (org-toggle-comment)
  48. (buffer-string))))
  49. (should
  50. (equal "* COMMENT"
  51. (org-test-with-temp-text "* "
  52. (org-toggle-comment)
  53. (buffer-string))))
  54. ;; Headline with a single keyword.
  55. (should
  56. (equal "* TODO "
  57. (org-test-with-temp-text "* TODO COMMENT"
  58. (org-toggle-comment)
  59. (buffer-string))))
  60. (should
  61. (equal "* TODO COMMENT"
  62. (org-test-with-temp-text "* TODO"
  63. (org-toggle-comment)
  64. (buffer-string))))
  65. ;; Headline with a keyword, a priority cookie and contents.
  66. (should
  67. (equal "* TODO [#A] Headline"
  68. (org-test-with-temp-text "* TODO [#A] COMMENT Headline"
  69. (org-toggle-comment)
  70. (buffer-string))))
  71. (should
  72. (equal "* TODO [#A] COMMENT Headline"
  73. (org-test-with-temp-text "* TODO [#A] Headline"
  74. (org-toggle-comment)
  75. (buffer-string)))))
  76. (ert-deftest test-org/comment-dwim ()
  77. "Test `comment-dwim' behaviour in an Org buffer."
  78. ;; No region selected, no comment on current line and line not
  79. ;; empty: insert comment on line above.
  80. (should
  81. (equal "# \nComment"
  82. (org-test-with-temp-text "Comment"
  83. (call-interactively #'org-comment-dwim)
  84. (buffer-string))))
  85. ;; No region selected, no comment on current line and line empty:
  86. ;; insert comment on this line.
  87. (should
  88. (equal "# \nParagraph"
  89. (org-test-with-temp-text "\nParagraph"
  90. (call-interactively #'org-comment-dwim)
  91. (buffer-string))))
  92. ;; No region selected, and a comment on this line: indent it.
  93. (should
  94. (equal "* Headline\n # Comment"
  95. (org-test-with-temp-text "* Headline\n# <point>Comment"
  96. (let ((org-adapt-indentation t))
  97. (call-interactively #'org-comment-dwim))
  98. (buffer-string))))
  99. ;; Also recognize single # at column 0 as comments.
  100. (should
  101. (equal "# Comment"
  102. (org-test-with-temp-text "# Comment"
  103. (call-interactively #'org-comment-dwim)
  104. (buffer-string))))
  105. ;; Region selected and only comments and blank lines within it:
  106. ;; un-comment all commented lines.
  107. (should
  108. (equal "Comment 1\n\nComment 2"
  109. (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
  110. (transient-mark-mode 1)
  111. (push-mark (point) t t)
  112. (goto-char (point-max))
  113. (call-interactively #'org-comment-dwim)
  114. (buffer-string))))
  115. ;; Region selected without comments: comment all lines if
  116. ;; `comment-empty-lines' is non-nil, only non-blank lines otherwise.
  117. (should
  118. (equal "# Comment 1\n\n# Comment 2"
  119. (org-test-with-temp-text "Comment 1\n\nComment 2"
  120. (transient-mark-mode 1)
  121. (push-mark (point) t t)
  122. (goto-char (point-max))
  123. (let ((comment-empty-lines nil))
  124. (call-interactively #'org-comment-dwim))
  125. (buffer-string))))
  126. (should
  127. (equal "# Comment 1\n# \n# Comment 2"
  128. (org-test-with-temp-text "Comment 1\n\nComment 2"
  129. (transient-mark-mode 1)
  130. (push-mark (point) t t)
  131. (goto-char (point-max))
  132. (let ((comment-empty-lines t))
  133. (call-interactively #'org-comment-dwim))
  134. (buffer-string))))
  135. ;; In front of a keyword without region, insert a new comment.
  136. (should
  137. (equal "# \n#+KEYWORD: value"
  138. (org-test-with-temp-text "#+KEYWORD: value"
  139. (call-interactively #'org-comment-dwim)
  140. (buffer-string))))
  141. ;; Comment a heading
  142. (should
  143. (equal "* COMMENT Test"
  144. (org-test-with-temp-text "* Test"
  145. (call-interactively #'org-comment-dwim)
  146. (buffer-string))))
  147. ;; In a source block, use appropriate syntax.
  148. (should
  149. (equal " ;; "
  150. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n<point>\n#+END_SRC"
  151. (let ((org-edit-src-content-indentation 2))
  152. (call-interactively #'org-comment-dwim))
  153. (buffer-substring-no-properties (line-beginning-position)
  154. (point)))))
  155. (should
  156. (equal "#+BEGIN_SRC emacs-lisp\n ;; a\n ;; b\n#+END_SRC"
  157. (org-test-with-temp-text
  158. "#+BEGIN_SRC emacs-lisp\n<point>a\nb\n#+END_SRC"
  159. (transient-mark-mode 1)
  160. (push-mark (point) t t)
  161. (forward-line 2)
  162. (let ((org-edit-src-content-indentation 2))
  163. (call-interactively #'org-comment-dwim))
  164. (buffer-string)))))
  165. ;;; Date and time analysis
  166. (ert-deftest test-org/org-read-date ()
  167. "Test `org-read-date' specifications."
  168. ;; Parse ISO date with abbreviated year and month.
  169. (should (equal "2012-03-29 16:40"
  170. (let ((org-time-was-given t))
  171. (org-read-date t nil "12-3-29 16:40"))))
  172. ;; Parse Europeans dates.
  173. (should (equal "2012-03-29 16:40"
  174. (let ((org-time-was-given t))
  175. (org-read-date t nil "29.03.2012 16:40"))))
  176. ;; Parse Europeans dates without year.
  177. (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
  178. (let ((org-time-was-given t))
  179. (org-read-date t nil "29.03. 16:40"))))
  180. ;; Relative date applied to current time if there is single
  181. ;; plus/minus, or to default date when there are two of them.
  182. (should
  183. (equal
  184. "2015-03-04"
  185. (org-test-at-time "2014-03-04"
  186. (org-read-date
  187. t nil "+1y" nil
  188. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))
  189. (should
  190. (equal
  191. "2013-03-29"
  192. (org-test-at-time "2014-03-04"
  193. (org-read-date
  194. t nil "++1y" nil
  195. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))
  196. ;; When `org-read-date-prefer-future' is non-nil, prefer future
  197. ;; dates (relatively to now) when incomplete. Otherwise, use
  198. ;; default date.
  199. (should
  200. (equal
  201. "2014-04-01"
  202. (org-test-at-time "2014-03-04"
  203. (let ((org-read-date-prefer-future t))
  204. (org-read-date t nil "1")))))
  205. (should
  206. (equal
  207. "2013-03-04"
  208. (org-test-at-time "2012-03-29"
  209. (let ((org-read-date-prefer-future t))
  210. (org-read-date t nil "3-4")))))
  211. (should
  212. (equal
  213. "2012-03-04"
  214. (org-test-at-time "2012-03-29"
  215. (let ((org-read-date-prefer-future nil))
  216. (org-read-date t nil "3-4")))))
  217. ;; When set to `org-read-date-prefer-future' is set to `time', read
  218. ;; day is moved to tomorrow if specified hour is before current
  219. ;; time. However, it only happens in no other part of the date is
  220. ;; specified.
  221. (should
  222. (equal
  223. "2012-03-30"
  224. (org-test-at-time "2012-03-29 16:40"
  225. (let ((org-read-date-prefer-future 'time))
  226. (org-read-date t nil "00:40" nil)))))
  227. (should-not
  228. (equal
  229. "2012-03-30"
  230. (org-test-at-time "2012-03-29 16:40"
  231. (let ((org-read-date-prefer-future 'time))
  232. (org-read-date t nil "29 00:40" nil)))))
  233. ;; Caveat: `org-read-date-prefer-future' always refers to current
  234. ;; time, not default time, when they differ.
  235. (should
  236. (equal
  237. "2014-04-01"
  238. (org-test-at-time "2014-03-04"
  239. (let ((org-read-date-prefer-future t))
  240. (org-read-date
  241. t nil "1" nil
  242. (apply #'encode-time (org-parse-time-string "2012-03-29")))))))
  243. (should
  244. (equal
  245. "2014-03-25"
  246. (org-test-at-time "2014-03-04"
  247. (let ((org-read-date-prefer-future t))
  248. (org-read-date
  249. t nil "25" nil
  250. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))))
  251. (ert-deftest test-org/org-parse-time-string ()
  252. "Test `org-parse-time-string'."
  253. (should (equal (org-parse-time-string "2012-03-29 16:40")
  254. '(0 40 16 29 3 2012 nil -1 nil)))
  255. (should (equal (org-parse-time-string "[2012-03-29 16:40]")
  256. '(0 40 16 29 3 2012 nil -1 nil)))
  257. (should (equal (org-parse-time-string "<2012-03-29 16:40>")
  258. '(0 40 16 29 3 2012 nil -1 nil)))
  259. (should (equal (org-parse-time-string "<2012-03-29>")
  260. '(0 0 0 29 3 2012 nil -1 nil)))
  261. (should (equal (org-parse-time-string "<2012-03-29>" t)
  262. '(0 nil nil 29 3 2012 nil -1 nil))))
  263. (ert-deftest test-org/closest-date ()
  264. "Test `org-closest-date' specifications."
  265. (require 'calendar)
  266. ;; Time stamps without a repeater are returned unchanged.
  267. (should
  268. (equal
  269. '(3 29 2012)
  270. (calendar-gregorian-from-absolute
  271. (org-closest-date "<2012-03-29>" "<2014-03-04>" nil))))
  272. ;; Time stamps with a null repeater are returned unchanged.
  273. (should
  274. (equal
  275. '(3 29 2012)
  276. (calendar-gregorian-from-absolute
  277. (org-closest-date "<2012-03-29 +0d>" "<2014-03-04>" nil))))
  278. ;; if PREFER is set to `past' always return a date before, or equal
  279. ;; to CURRENT.
  280. (should
  281. (equal
  282. '(3 1 2014)
  283. (calendar-gregorian-from-absolute
  284. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'past))))
  285. (should
  286. (equal
  287. '(3 4 2014)
  288. (calendar-gregorian-from-absolute
  289. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'past))))
  290. ;; if PREFER is set to `future' always return a date before, or equal
  291. ;; to CURRENT.
  292. (should
  293. (equal
  294. '(3 29 2014)
  295. (calendar-gregorian-from-absolute
  296. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'future))))
  297. (should
  298. (equal
  299. '(3 4 2014)
  300. (calendar-gregorian-from-absolute
  301. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'future))))
  302. ;; If PREFER is neither `past' nor `future', select closest date.
  303. (should
  304. (equal
  305. '(3 1 2014)
  306. (calendar-gregorian-from-absolute
  307. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" nil))))
  308. (should
  309. (equal
  310. '(5 4 2014)
  311. (calendar-gregorian-from-absolute
  312. (org-closest-date "<2012-03-04 +1m>" "<2014-04-28>" nil))))
  313. ;; Test "day" repeater.
  314. (should
  315. (equal '(3 8 2014)
  316. (calendar-gregorian-from-absolute
  317. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'past))))
  318. (should
  319. (equal '(3 10 2014)
  320. (calendar-gregorian-from-absolute
  321. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'future))))
  322. ;; Test "month" repeater.
  323. (should
  324. (equal '(1 5 2015)
  325. (calendar-gregorian-from-absolute
  326. (org-closest-date "<2014-03-05 +2m>" "<2015-02-04>" 'past))))
  327. (should
  328. (equal '(3 29 2014)
  329. (calendar-gregorian-from-absolute
  330. (org-closest-date "<2012-03-29 +2m>" "<2014-03-04>" 'future))))
  331. ;; Test "year" repeater.
  332. (should
  333. (equal '(3 5 2014)
  334. (calendar-gregorian-from-absolute
  335. (org-closest-date "<2014-03-05 +2y>" "<2015-02-04>" 'past))))
  336. (should
  337. (equal '(3 29 2014)
  338. (calendar-gregorian-from-absolute
  339. (org-closest-date "<2012-03-29 +2y>" "<2014-03-04>" 'future)))))
  340. (ert-deftest test-org/deadline-close-p ()
  341. "Test `org-deadline-close-p' specifications."
  342. (org-test-at-time "2016-06-03 Fri 01:43"
  343. ;; Timestamps are close if they are within `ndays' of lead time.
  344. (org-test-with-temp-text "* Heading"
  345. (should (org-deadline-close-p "2016-06-03 Fri" 0))
  346. (should (org-deadline-close-p "2016-06-02 Thu" 0))
  347. (should-not (org-deadline-close-p "2016-06-04 Sat" 0))
  348. (should (org-deadline-close-p "2016-06-04 Sat" 1))
  349. (should (org-deadline-close-p "2016-06-03 Fri 12:00" 0)))
  350. ;; Read `ndays' from timestamp if argument not given.
  351. (org-test-with-temp-text "* H"
  352. (should (org-deadline-close-p "2016-06-04 Sat -1d"))
  353. (should-not (org-deadline-close-p "2016-06-04 Sat -0d"))
  354. (should (org-deadline-close-p "2016-06-10 Fri -1w"))
  355. (should-not (org-deadline-close-p "2016-06-11 Sat -1w")))
  356. ;; Prefer `ndays' argument over lead time in timestamp.
  357. (org-test-with-temp-text "* H"
  358. (should (org-deadline-close-p "2016-06-04 Sat -0d" 1))
  359. (should-not (org-deadline-close-p "2016-06-04 Sat -0d" 0)))
  360. ;; Completed tasks are never close.
  361. (let ((org-todo-keywords '(("TODO" "|" "DONE"))))
  362. (org-test-with-temp-text "* TODO Heading"
  363. (should (org-deadline-close-p "2016-06-03")))
  364. (org-test-with-temp-text "* DONE Heading"
  365. (should-not (org-deadline-close-p "2016-06-03"))))))
  366. ;;; Drawers
  367. (ert-deftest test-org/at-property-p ()
  368. "Test `org-at-property-p' specifications."
  369. (should
  370. (equal 't
  371. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:PROP: t\n:END:\n"
  372. (org-at-property-p))))
  373. (should
  374. (equal 't
  375. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n:END:\n"
  376. (org-at-property-p)))))
  377. (ert-deftest test-org/at-property-drawer-p ()
  378. "Test `org-at-property-drawer-p' specifications."
  379. (should
  380. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:PROP: t\n:END:\n"
  381. (org-at-property-drawer-p)))
  382. (should
  383. (org-test-with-temp-text ":PROPERTIES:\n:PROP: t\n:END:\n"
  384. (org-at-property-drawer-p)))
  385. ;; The function only returns t if point is at the first line of
  386. ;; a property block.
  387. (should-not
  388. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n:END:\n"
  389. (org-at-property-drawer-p)))
  390. ;; The function ignores incomplete drawers.
  391. (should-not
  392. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n"
  393. (org-at-property-drawer-p)))
  394. ;; tab separating the value.
  395. (should
  396. (org-test-with-temp-text ":PROPERTIES:\n:PROP: t\n:END:\n"
  397. (org-at-property-drawer-p))))
  398. (ert-deftest test-org/get-property-block ()
  399. "Test `org-get-property-block' specifications."
  400. (should
  401. (equal '(14 . 14)
  402. (org-test-with-temp-text ":PROPERTIES:\n:END:\n* H\n"
  403. (org-get-property-block))))
  404. (should
  405. (equal '(14 . 14)
  406. (org-test-with-temp-text ":PROPERTIES:\n:END:\n"
  407. (org-get-property-block))))
  408. ;; Comments above a document property block is ok.
  409. (should
  410. (equal '(18 . 18)
  411. (org-test-with-temp-text "# C\n:PROPERTIES:\n:END:\n"
  412. (org-get-property-block))))
  413. ;; Keywords above a document property block is ok.
  414. (should
  415. (equal '(22 . 22)
  416. (org-test-with-temp-text "# C\n# C\n:PROPERTIES:\n:END:\n"
  417. (org-get-property-block))))
  418. ;; Comments and keywords are allowed before a document property block.
  419. (should
  420. (equal '(18 . 27)
  421. (org-test-with-temp-text "# C\n:PROPERTIES:\n:KEY: V:\n:END:\n"
  422. (org-get-property-block))))
  423. ;; A document property block will not be valid if there are lines
  424. ;; with whitespace above it
  425. (should-not
  426. (org-test-with-temp-text "\n:PROPERTIES:\n:END:\n"
  427. (org-get-property-block)))
  428. (should
  429. (equal '(18 . 18)
  430. (org-test-with-temp-text "* H\n:PROPERTIES:\n:END:\n<point>"
  431. (org-get-property-block))))
  432. (should
  433. (equal "* H\n:PROPERTIES:\n:END:\n"
  434. (org-test-with-temp-text "* H"
  435. (let ((org-adapt-indentation nil))
  436. (org-get-property-block nil 'force))
  437. (buffer-string))))
  438. (should
  439. (equal ":PROPERTIES:\n:END:\n"
  440. (org-test-with-temp-text ""
  441. (org-get-property-block nil 'force)
  442. (buffer-string))))
  443. (should
  444. (equal "* H1\n :PROPERTIES:\n :END:\n* H2"
  445. (org-test-with-temp-text "* H1\n* H2"
  446. (let ((org-adapt-indentation t))
  447. (org-get-property-block nil 'force))
  448. (buffer-string)))))
  449. (ert-deftest test-org/insert-property-drawer ()
  450. "Test `org-insert-property-drawer' specifications."
  451. ;; Insert drawer in empty buffer
  452. (should
  453. (equal ":PROPERTIES:\n:END:\n"
  454. (org-test-with-temp-text ""
  455. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  456. (buffer-string))))
  457. ;; Insert drawer in document header with existing comment and
  458. ;; keyword.
  459. (should
  460. (equal "# C\n:PROPERTIES:\n:END:\n#+TITLE: T"
  461. (org-test-with-temp-text "# C\n#+TITLE: T"
  462. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  463. (buffer-string))))
  464. ;; Insert drawer in document header with existing keyword.
  465. (should
  466. (equal ":PROPERTIES:\n:END:\n#+TITLE: T"
  467. (org-test-with-temp-text "#+TITLE: T"
  468. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  469. (buffer-string))))
  470. (should
  471. (equal ":PROPERTIES:\n:END:"
  472. (org-test-with-temp-text ":PROPERTIES:\n:END:"
  473. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  474. (buffer-string))))
  475. ;; Insert drawer in document header with one existing heading in buffer.
  476. (should
  477. (equal ":PROPERTIES:\n:END:\n\n* T\n"
  478. (org-test-with-temp-text "\n* T\n"
  479. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  480. (buffer-string))))
  481. ;; Insert drawer right after headline if there is no planning line,
  482. ;; or after it otherwise.
  483. (should
  484. (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
  485. (org-test-with-temp-text "* H\nParagraph<point>"
  486. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  487. (buffer-string))))
  488. (should
  489. (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
  490. (org-test-with-temp-text
  491. "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
  492. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  493. (buffer-string))))
  494. ;; Indent inserted drawer.
  495. (should
  496. (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
  497. (org-test-with-temp-text "* H\nParagraph<point>"
  498. (let ((org-adapt-indentation t)) (org-insert-property-drawer))
  499. (buffer-string))))
  500. ;; Handle insertion at eob.
  501. (should
  502. (equal "* H\n:PROPERTIES:\n:END:\n"
  503. (org-test-with-temp-text "* H"
  504. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  505. (buffer-string))))
  506. ;; Skip inlinetasks before point.
  507. (when (featurep 'org-inlinetask)
  508. (should
  509. (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
  510. (org-test-with-temp-text
  511. "* H\n*************** I\n*************** END\nP<point>"
  512. (let ((org-adapt-indentation nil)
  513. (org-inlinetask-min-level 15))
  514. (org-insert-property-drawer))
  515. (buffer-string)))))
  516. ;; Correctly set drawer in an inlinetask.
  517. (when (featurep 'org-inlinetask)
  518. (should
  519. (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
  520. (org-test-with-temp-text
  521. "* H\n*************** I\nP<point>\n*************** END"
  522. (let ((org-adapt-indentation nil)
  523. (org-inlinetask-min-level 15))
  524. (org-insert-property-drawer))
  525. (buffer-string))))))
  526. ;;; Filling
  527. (ert-deftest test-org/fill-element ()
  528. "Test `org-fill-element' specifications."
  529. ;; At an Org table, align it.
  530. (should
  531. (equal "| a |\n"
  532. (org-test-with-temp-text "|a|"
  533. (org-fill-element)
  534. (buffer-string))))
  535. (should
  536. (equal "#+name: table\n| a |\n"
  537. (org-test-with-temp-text "#+name: table\n| a |\n"
  538. (org-fill-element)
  539. (buffer-string))))
  540. ;; At a paragraph, preserve line breaks.
  541. (org-test-with-temp-text "some \\\\\nlong\ntext"
  542. (let ((fill-column 20))
  543. (org-fill-element)
  544. (should (equal (buffer-string) "some \\\\\nlong text"))))
  545. ;; Correctly fill a paragraph when point is at its very end.
  546. (should
  547. (equal "A B"
  548. (org-test-with-temp-text "A\nB"
  549. (let ((fill-column 20))
  550. (goto-char (point-max))
  551. (org-fill-element)
  552. (buffer-string)))))
  553. ;; Correctly fill the last paragraph of a greater element.
  554. (should
  555. (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
  556. (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
  557. (let ((fill-column 8))
  558. (forward-line)
  559. (end-of-line)
  560. (org-fill-element)
  561. (buffer-string)))))
  562. ;; Correctly fill an element in a narrowed buffer.
  563. (should
  564. (equal "01234\n6"
  565. (org-test-with-temp-text "01234 6789"
  566. (let ((fill-column 5))
  567. (narrow-to-region 1 8)
  568. (org-fill-element)
  569. (buffer-string)))))
  570. ;; Handle `adaptive-fill-regexp' in paragraphs.
  571. (should
  572. (equal "> a b"
  573. (org-test-with-temp-text "> a\n> b"
  574. (let ((fill-column 5)
  575. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  576. (org-fill-element)
  577. (buffer-string)))))
  578. ;; Special case: Fill first paragraph when point is at an item or
  579. ;; a plain-list or a footnote reference.
  580. (should
  581. (equal "- A B"
  582. (org-test-with-temp-text "- A\n B"
  583. (let ((fill-column 20))
  584. (org-fill-element)
  585. (buffer-string)))))
  586. (should
  587. (equal "[fn:1] A B"
  588. (org-test-with-temp-text "[fn:1] A\nB"
  589. (let ((fill-column 20))
  590. (org-fill-element)
  591. (buffer-string)))))
  592. (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
  593. (let ((fill-column 20))
  594. (org-fill-element)
  595. (should (equal (buffer-string)
  596. "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
  597. ;; Fill contents of `comment-block' elements.
  598. (should
  599. (equal
  600. (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
  601. (let ((fill-column 20))
  602. (forward-line)
  603. (org-fill-element)
  604. (buffer-string)))
  605. "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
  606. ;; Fill `comment' elements.
  607. (should
  608. (equal " # A B"
  609. (org-test-with-temp-text " # A\n # B"
  610. (let ((fill-column 20))
  611. (org-fill-element)
  612. (buffer-string)))))
  613. ;; Do not mix consecutive comments when filling one of them.
  614. (should
  615. (equal "# A B\n\n# C"
  616. (org-test-with-temp-text "# A\n# B\n\n# C"
  617. (let ((fill-column 20))
  618. (org-fill-element)
  619. (buffer-string)))))
  620. ;; Use commented empty lines as separators when filling comments.
  621. (should
  622. (equal "# A B\n#\n# C"
  623. (org-test-with-temp-text "# A\n# B\n#\n# C"
  624. (let ((fill-column 20))
  625. (org-fill-element)
  626. (buffer-string)))))
  627. ;; Handle `adaptive-fill-regexp' in comments.
  628. (should
  629. (equal "# > a b"
  630. (org-test-with-temp-text "# > a\n# > b"
  631. (let ((fill-column 20)
  632. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  633. (org-fill-element)
  634. (buffer-string)))))
  635. ;; Do nothing at affiliated keywords.
  636. (should
  637. (equal "#+NAME: para\nSome\ntext."
  638. (org-test-with-temp-text "#+NAME: para\nSome\ntext."
  639. (let ((fill-column 20))
  640. (org-fill-element)
  641. (buffer-string)))))
  642. ;; Do not move point after table when filling a table.
  643. (should-not
  644. (org-test-with-temp-text "| a | b |\n| c | d |\n"
  645. (forward-char)
  646. (org-fill-element)
  647. (eobp)))
  648. ;; Do not fill "n" macro, with or without arguments, followed by
  649. ;; a dot or a closing parenthesis since it could be confused with
  650. ;; a numbered bullet.
  651. (should-not
  652. (equal "123456789\n{{{n}}}."
  653. (org-test-with-temp-text "123456789 {{{n}}}."
  654. (let ((fill-column 10))
  655. (org-fill-element)
  656. (buffer-string)))))
  657. (should-not
  658. (equal "123456789\n{{{n}}}\)"
  659. (org-test-with-temp-text "123456789 {{{n}}}\)"
  660. (let ((fill-column 10))
  661. (org-fill-element)
  662. (buffer-string)))))
  663. (should-not
  664. (equal "123456789\n{{{n()}}}."
  665. (org-test-with-temp-text "123456789 {{{n()}}}."
  666. (let ((fill-column 10))
  667. (org-fill-element)
  668. (buffer-string)))))
  669. (should-not
  670. (equal "123456789\n{{{n(counter)}}}."
  671. (org-test-with-temp-text "123456789 {{{n(counter)}}}."
  672. (let ((fill-column 10))
  673. (org-fill-element)
  674. (buffer-string))))))
  675. (ert-deftest test-org/fill-paragraph ()
  676. "Test `org-fill-paragraph' specifications."
  677. ;; Regular test.
  678. (should
  679. (equal "012345678\n9"
  680. (org-test-with-temp-text "012345678 9"
  681. (let ((fill-column 10))
  682. (org-fill-paragraph)
  683. (buffer-string)))))
  684. ;; Fill paragraph even at end of buffer.
  685. (should
  686. (equal "012345678\n9\n"
  687. (org-test-with-temp-text "012345678 9\n<point>"
  688. (let ((fill-column 10))
  689. (org-fill-paragraph)
  690. (buffer-string)))))
  691. ;; Between two paragraphs, fill the next one.
  692. (should
  693. (equal "012345678 9\n\n012345678\n9"
  694. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  695. (let ((fill-column 10))
  696. (org-fill-paragraph)
  697. (buffer-string)))))
  698. (should
  699. (equal "012345678\n9\n\n012345678 9"
  700. (org-test-with-temp-text "012345678 9<point>\n\n012345678 9"
  701. (let ((fill-column 10))
  702. (org-fill-paragraph)
  703. (buffer-string)))))
  704. ;; Fill paragraph in a comment block.
  705. (should
  706. (equal "#+begin_comment\n012345678\n9\n#+end_comment"
  707. (org-test-with-temp-text
  708. "#+begin_comment\n<point>012345678 9\n#+end_comment"
  709. (let ((fill-column 10))
  710. (org-fill-paragraph)
  711. (buffer-string)))))
  712. ;; When a region is selected, fill every paragraph in the region.
  713. (should
  714. (equal "012345678\n9\n\n012345678\n9"
  715. (org-test-with-temp-text "012345678 9\n\n012345678 9"
  716. (let ((fill-column 10))
  717. (transient-mark-mode 1)
  718. (push-mark (point-min) t t)
  719. (goto-char (point-max))
  720. (call-interactively #'org-fill-paragraph)
  721. (buffer-string)))))
  722. (should
  723. (equal "012345678\n9\n\n012345678 9"
  724. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  725. (let ((fill-column 10))
  726. (transient-mark-mode 1)
  727. (push-mark (point) t t)
  728. (goto-char (point-min))
  729. (call-interactively #'org-fill-paragraph)
  730. (buffer-string)))))
  731. (should
  732. (equal "012345678 9\n\n012345678\n9"
  733. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  734. (let ((fill-column 10))
  735. (transient-mark-mode 1)
  736. (push-mark (point) t t)
  737. (goto-char (point-max))
  738. (call-interactively #'org-fill-paragraph)
  739. (buffer-string)))))
  740. ;; Fill every list item in a region
  741. (should
  742. (equal "\n- 2345678\n 9\n- 2345678\n 9"
  743. (org-test-with-temp-text "\n- 2345678 9\n- 2345678 9"
  744. (let ((fill-column 10))
  745. (transient-mark-mode 1)
  746. (push-mark (point-min) t t)
  747. (goto-char (point-max))
  748. (call-interactively #'org-fill-paragraph)
  749. (buffer-string)))))
  750. (should
  751. (equal "\n- 2345678\n 9\n- 2345678"
  752. (org-test-with-temp-text "\n- 2345678 9\n- 2345678"
  753. (let ((fill-column 10))
  754. (transient-mark-mode 1)
  755. (push-mark (point-min) t t)
  756. (goto-char (point-max))
  757. (call-interactively #'org-fill-paragraph)
  758. (buffer-string))))))
  759. (ert-deftest test-org/fill-region ()
  760. "Test `fill-region' behaviour."
  761. ;; fill-region should fill every item of a list
  762. (should
  763. (equal "\n- 2345678\n 9\n- 2345678\n 9"
  764. (org-test-with-temp-text "\n- 2345678 9\n- 2345678 9"
  765. (let ((fill-column 10))
  766. (transient-mark-mode 1)
  767. (push-mark (point-min) t t)
  768. (goto-char (point-max))
  769. (call-interactively #'fill-region)
  770. (buffer-string)))))
  771. (should
  772. (equal "\n- 1 2\n- 1 2"
  773. (org-test-with-temp-text "\n- 1\n 2\n- 1\n 2"
  774. (let ((fill-column 10))
  775. (transient-mark-mode 1)
  776. (push-mark (point-min) t t)
  777. (goto-char (point-max))
  778. (call-interactively #'fill-region)
  779. (buffer-string))))) )
  780. (ert-deftest test-org/auto-fill-function ()
  781. "Test auto-filling features."
  782. ;; Auto fill paragraph.
  783. (should
  784. (equal "12345\n7890"
  785. (org-test-with-temp-text "12345 7890"
  786. (let ((fill-column 5))
  787. (end-of-line)
  788. (org-auto-fill-function)
  789. (buffer-string)))))
  790. ;; Auto fill first paragraph in an item.
  791. (should
  792. (equal "- 12345\n 7890"
  793. (org-test-with-temp-text "- 12345 7890"
  794. (let ((fill-column 7))
  795. (end-of-line)
  796. (org-auto-fill-function)
  797. (buffer-string)))))
  798. ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
  799. (should
  800. (equal "> 12345\n 7890"
  801. (org-test-with-temp-text "> 12345 7890"
  802. (let ((fill-column 10)
  803. (adaptive-fill-regexp "[ \t]*>+[ \t]*")
  804. (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
  805. (end-of-line)
  806. (org-auto-fill-function)
  807. (buffer-string)))))
  808. (should
  809. (equal "> 12345\n> 12345\n> 7890"
  810. (org-test-with-temp-text "> 12345\n> 12345 7890"
  811. (let ((fill-column 10)
  812. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  813. (goto-char (point-max))
  814. (org-auto-fill-function)
  815. (buffer-string)))))
  816. (should-not
  817. (equal " 12345\n *12345\n *12345"
  818. (org-test-with-temp-text " 12345\n *12345 12345"
  819. (let ((fill-column 10)
  820. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  821. (goto-char (point-max))
  822. (org-auto-fill-function)
  823. (buffer-string)))))
  824. ;; Auto fill comments.
  825. (should
  826. (equal " # 12345\n # 7890"
  827. (org-test-with-temp-text " # 12345 7890"
  828. (let ((fill-column 10))
  829. (end-of-line)
  830. (org-auto-fill-function)
  831. (buffer-string)))))
  832. ;; A hash within a line isn't a comment.
  833. (should-not
  834. (equal "12345 # 7890\n# 1"
  835. (org-test-with-temp-text "12345 # 7890 1"
  836. (let ((fill-column 12))
  837. (end-of-line)
  838. (org-auto-fill-function)
  839. (buffer-string)))))
  840. ;; Correctly interpret empty prefix.
  841. (should-not
  842. (equal "# a\n# b\nRegular\n# paragraph"
  843. (org-test-with-temp-text "# a\n# b\nRegular paragraph"
  844. (let ((fill-column 12))
  845. (end-of-line 3)
  846. (org-auto-fill-function)
  847. (buffer-string)))))
  848. ;; Comment block: auto fill contents.
  849. (should
  850. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  851. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  852. (let ((fill-column 5))
  853. (forward-line)
  854. (end-of-line)
  855. (org-auto-fill-function)
  856. (buffer-string)))))
  857. (should
  858. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  859. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  860. (let ((fill-column 5))
  861. (forward-line)
  862. (end-of-line)
  863. (org-auto-fill-function)
  864. (buffer-string)))))
  865. ;; Do not fill if a new item could be created.
  866. (should-not
  867. (equal "12345\n- 90"
  868. (org-test-with-temp-text "12345 - 90"
  869. (let ((fill-column 5))
  870. (end-of-line)
  871. (org-auto-fill-function)
  872. (buffer-string)))))
  873. ;; Do not fill if a line break could be introduced.
  874. (should-not
  875. (equal "123\\\\\n7890"
  876. (org-test-with-temp-text "123\\\\ 7890"
  877. (let ((fill-column 6))
  878. (end-of-line)
  879. (org-auto-fill-function)
  880. (buffer-string)))))
  881. ;; Do not fill affiliated keywords.
  882. (should-not
  883. (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
  884. (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
  885. (let ((fill-column 20))
  886. (end-of-line)
  887. (org-auto-fill-function)
  888. (buffer-string))))))
  889. ;;; Indentation
  890. (ert-deftest test-org/indent-line ()
  891. "Test `org-indent-line' specifications."
  892. ;; Do not indent diary sexps, footnote definitions or headlines.
  893. (should
  894. (zerop
  895. (org-test-with-temp-text "%%(org-calendar-holiday)"
  896. (org-indent-line)
  897. (org-get-indentation))))
  898. (should
  899. (zerop
  900. (org-test-with-temp-text "[fn:1] fn"
  901. (let ((org-adapt-indentation t)) (org-indent-line))
  902. (org-get-indentation))))
  903. (should
  904. (zerop
  905. (org-test-with-temp-text "* H"
  906. (org-indent-line)
  907. (org-get-indentation))))
  908. ;; Do not indent before first headline.
  909. (should
  910. (zerop
  911. (org-test-with-temp-text ""
  912. (org-indent-line)
  913. (org-get-indentation))))
  914. ;; Indent according to headline level otherwise, unless
  915. ;; `org-adapt-indentation' is nil.
  916. (should
  917. (= 2
  918. (org-test-with-temp-text "* H\n<point>A"
  919. (let ((org-adapt-indentation t)) (org-indent-line))
  920. (org-get-indentation))))
  921. (should
  922. (= 2
  923. (org-test-with-temp-text "* H\n<point>\nA"
  924. (let ((org-adapt-indentation t)) (org-indent-line))
  925. (org-get-indentation))))
  926. (should
  927. (zerop
  928. (org-test-with-temp-text "* H\n<point>A"
  929. (let ((org-adapt-indentation nil)) (org-indent-line))
  930. (org-get-indentation))))
  931. ;; Indenting preserves point position.
  932. (should
  933. (org-test-with-temp-text "* H\nA<point>B"
  934. (let ((org-adapt-indentation t)) (org-indent-line))
  935. (looking-at "B")))
  936. ;; Do not change indentation at an item or a LaTeX environment.
  937. (should
  938. (= 1
  939. (org-test-with-temp-text "* H\n<point> - A"
  940. (let ((org-adapt-indentation t)) (org-indent-line))
  941. (org-get-indentation))))
  942. (should
  943. (= 1
  944. (org-test-with-temp-text
  945. "\\begin{equation}\n <point>1+1=2\n\\end{equation}"
  946. (org-indent-line)
  947. (org-get-indentation))))
  948. ;; On blank lines at the end of a list, indent like last element
  949. ;; within it if the line is still in the list. If the last element
  950. ;; is an item, indent like its contents. Otherwise, indent like the
  951. ;; whole list.
  952. (should
  953. (= 4
  954. (org-test-with-temp-text "* H\n- A\n - AA\n<point>"
  955. (let ((org-adapt-indentation t)) (org-indent-line))
  956. (org-get-indentation))))
  957. (should
  958. (= 4
  959. (org-test-with-temp-text "* H\n- A\n -\n\n<point>"
  960. (let ((org-adapt-indentation t)) (org-indent-line))
  961. (org-get-indentation))))
  962. (should
  963. (zerop
  964. (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n<point>"
  965. (let ((org-adapt-indentation t)) (org-indent-line))
  966. (org-get-indentation))))
  967. (should
  968. (= 4
  969. (org-test-with-temp-text "* H\n- A\n - \n<point>"
  970. (let ((org-adapt-indentation t)) (org-indent-line))
  971. (org-get-indentation))))
  972. (should
  973. (= 4
  974. (org-test-with-temp-text
  975. "* H\n - \n #+BEGIN_SRC emacs-lisp\n t\n #+END_SRC\n<point>"
  976. (let ((org-adapt-indentation t)) (org-indent-line))
  977. (org-get-indentation))))
  978. (should
  979. (= 2
  980. (org-test-with-temp-text "- A\n B\n\n<point>"
  981. (let ((org-adapt-indentation nil)) (org-indent-line))
  982. (org-get-indentation))))
  983. (should
  984. (= 2
  985. (org-test-with-temp-text
  986. "- A\n \begin{cases} 1 + 1\n \end{cases}\n\n<point>"
  987. (let ((org-adapt-indentation nil)) (org-indent-line))
  988. (org-get-indentation))))
  989. ;; Likewise, on a blank line at the end of a footnote definition,
  990. ;; indent at column 0 if line belongs to the definition. Otherwise,
  991. ;; indent like the definition itself.
  992. (should
  993. (zerop
  994. (org-test-with-temp-text "* H\n[fn:1] Definition\n<point>"
  995. (let ((org-adapt-indentation t)) (org-indent-line))
  996. (org-get-indentation))))
  997. (should
  998. (zerop
  999. (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n<point>"
  1000. (let ((org-adapt-indentation t)) (org-indent-line))
  1001. (org-get-indentation))))
  1002. ;; After the end of the contents of a greater element, indent like
  1003. ;; the beginning of the element.
  1004. (should
  1005. (= 1
  1006. (org-test-with-temp-text
  1007. " #+BEGIN_CENTER\n Contents\n<point>#+END_CENTER"
  1008. (org-indent-line)
  1009. (org-get-indentation))))
  1010. ;; On blank lines after a paragraph, indent like its last non-empty
  1011. ;; line.
  1012. (should
  1013. (= 1
  1014. (org-test-with-temp-text " Paragraph\n\n<point>"
  1015. (org-indent-line)
  1016. (org-get-indentation))))
  1017. ;; At the first line of an element, indent like previous element's
  1018. ;; first line, ignoring footnotes definitions and inline tasks, or
  1019. ;; according to parent.
  1020. (let ((org-adapt-indentation t))
  1021. (should
  1022. (= 2
  1023. (org-test-with-temp-text "A\n\n B\n\nC<point>"
  1024. (org-indent-line)
  1025. (org-get-indentation))))
  1026. (should
  1027. (= 1
  1028. (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC<point>"
  1029. (org-indent-line)
  1030. (org-get-indentation))))
  1031. (should
  1032. (= 1
  1033. (org-test-with-temp-text
  1034. " #+BEGIN_CENTER\n<point> Contents\n#+END_CENTER"
  1035. (org-indent-line)
  1036. (org-get-indentation)))))
  1037. ;; Within code part of a source block, use language major mode if
  1038. ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
  1039. ;; according to line above.
  1040. (should
  1041. (= 6
  1042. (org-test-with-temp-text
  1043. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  1044. (let ((org-src-tab-acts-natively t)
  1045. (org-edit-src-content-indentation 0))
  1046. (org-indent-line))
  1047. (org-get-indentation))))
  1048. (should
  1049. (= 1
  1050. (org-test-with-temp-text
  1051. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  1052. (let ((org-src-tab-acts-natively nil)
  1053. (org-edit-src-content-indentation 0))
  1054. (org-indent-line))
  1055. (org-get-indentation))))
  1056. ;; Otherwise, indent like the first non-blank line above.
  1057. (should
  1058. (zerop
  1059. (org-test-with-temp-text
  1060. "#+BEGIN_CENTER\nline1\n\n<point> line2\n#+END_CENTER"
  1061. (org-indent-line)
  1062. (org-get-indentation))))
  1063. ;; Align node properties according to `org-property-format'. Handle
  1064. ;; nicely empty values.
  1065. (should
  1066. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1067. (org-test-with-temp-text
  1068. "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
  1069. (let ((org-property-format "%-10s %s")) (org-indent-line))
  1070. (buffer-string))))
  1071. (should
  1072. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1073. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
  1074. (let ((org-property-format "%-10s %s")) (org-indent-line))
  1075. (buffer-string)))))
  1076. (ert-deftest test-org/indent-region ()
  1077. "Test `org-indent-region' specifications."
  1078. ;; Indent paragraph.
  1079. (let ((org-adapt-indentation t))
  1080. (should
  1081. (equal "A\nB\nC"
  1082. (org-test-with-temp-text " A\nB\n C"
  1083. (org-indent-region (point-min) (point-max))
  1084. (buffer-string)))))
  1085. ;; Indent greater elements along with their contents.
  1086. (should
  1087. (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
  1088. (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
  1089. (org-indent-region (point-min) (point-max))
  1090. (buffer-string))))
  1091. ;; Ignore contents of verse blocks. Only indent block delimiters.
  1092. (should
  1093. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1094. (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1095. (org-indent-region (point-min) (point-max))
  1096. (buffer-string))))
  1097. (let ((org-adapt-indentation t))
  1098. (should
  1099. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1100. (org-test-with-temp-text " #+BEGIN_VERSE\n A\n B\n #+END_VERSE"
  1101. (org-indent-region (point-min) (point-max))
  1102. (buffer-string)))))
  1103. ;; Indent example blocks as a single block, unless indentation
  1104. ;; should be preserved. In this case only indent the block markers.
  1105. (should
  1106. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1107. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1108. (org-indent-region (point-min) (point-max))
  1109. (buffer-string))))
  1110. (let ((org-adapt-indentation t))
  1111. (should
  1112. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1113. (org-test-with-temp-text " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1114. (org-indent-region (point-min) (point-max))
  1115. (buffer-string))))
  1116. (should
  1117. (equal "#+BEGIN_EXAMPLE -i\n A\n B\n#+END_EXAMPLE"
  1118. (org-test-with-temp-text
  1119. " #+BEGIN_EXAMPLE -i\n A\n B\n #+END_EXAMPLE"
  1120. (org-indent-region (point-min) (point-max))
  1121. (buffer-string))))
  1122. (should
  1123. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1124. (org-test-with-temp-text
  1125. " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1126. (let ((org-src-preserve-indentation t))
  1127. (org-indent-region (point-min) (point-max)))
  1128. (buffer-string)))))
  1129. ;; Treat export blocks as a whole.
  1130. (should
  1131. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1132. (org-test-with-temp-text "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1133. (org-indent-region (point-min) (point-max))
  1134. (buffer-string))))
  1135. (let ((org-adapt-indentation t))
  1136. (should
  1137. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1138. (org-test-with-temp-text
  1139. " #+BEGIN_EXPORT latex\n A\n B\n #+END_EXPORT"
  1140. (org-indent-region (point-min) (point-max))
  1141. (buffer-string)))))
  1142. ;; Indent according to mode if `org-src-tab-acts-natively' is
  1143. ;; non-nil. Otherwise, do not indent code at all.
  1144. (should
  1145. (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
  1146. (org-test-with-temp-text
  1147. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1148. (let ((org-src-tab-acts-natively t)
  1149. (org-edit-src-content-indentation 0))
  1150. (org-indent-region (point-min) (point-max)))
  1151. (buffer-string))))
  1152. (should
  1153. (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1154. (org-test-with-temp-text
  1155. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1156. (let ((org-src-tab-acts-natively nil)
  1157. (org-edit-src-content-indentation 0))
  1158. (org-indent-region (point-min) (point-max)))
  1159. (buffer-string))))
  1160. ;; Align node properties according to `org-property-format'. Handle
  1161. ;; nicely empty values.
  1162. (should
  1163. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1164. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
  1165. (let ((org-property-format "%-10s %s")
  1166. (org-adapt-indentation nil))
  1167. (org-indent-region (point) (point-max)))
  1168. (buffer-string))))
  1169. (should
  1170. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1171. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
  1172. (let ((org-property-format "%-10s %s")
  1173. (org-adapt-indentation nil))
  1174. (org-indent-region (point) (point-max)))
  1175. (buffer-string))))
  1176. ;; Indent property drawers according to `org-adapt-indentation'.
  1177. (let ((org-adapt-indentation 'headline-data))
  1178. (should
  1179. (equal "* H\n :PROPERTIES:\n :key:\n :END:"
  1180. (org-test-with-temp-text "* H\n:PROPERTIES:\n:key:\n:END:"
  1181. (org-indent-region (point-min) (point-max))
  1182. (buffer-string)))))
  1183. ;; Indent plain lists.
  1184. (let ((org-adapt-indentation t))
  1185. (should
  1186. (equal "- A\n B\n - C\n\n D"
  1187. (org-test-with-temp-text "- A\n B\n - C\n\n D"
  1188. (org-indent-region (point-min) (point-max))
  1189. (buffer-string))))
  1190. (should
  1191. (equal "- A\n\n- B"
  1192. (org-test-with-temp-text " - A\n\n - B"
  1193. (org-indent-region (point-min) (point-max))
  1194. (buffer-string)))))
  1195. ;; Indent footnote definitions.
  1196. (should
  1197. (equal "[fn:1] Definition\n\nDefinition"
  1198. (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
  1199. (org-indent-region (point-min) (point-max))
  1200. (buffer-string))))
  1201. ;; Special case: Start indenting on a blank line.
  1202. (should
  1203. (equal "\nParagraph"
  1204. (org-test-with-temp-text "\n Paragraph"
  1205. (org-indent-region (point-min) (point-max))
  1206. (buffer-string)))))
  1207. ;;; Editing
  1208. (ert-deftest test-org/delete-indentation ()
  1209. "Test `org-delete-indentation' specifications."
  1210. ;; Regular test.
  1211. (should (equal "foo bar"
  1212. (org-test-with-temp-text
  1213. "foo \n bar<point>"
  1214. (org-delete-indentation)
  1215. (buffer-string))))
  1216. ;; With optional argument.
  1217. (should (equal "foo bar"
  1218. (org-test-with-temp-text
  1219. "foo<point> \n bar"
  1220. (org-delete-indentation t)
  1221. (buffer-string))))
  1222. ;; At headline text should be appended to the headline text.
  1223. (should
  1224. (equal"* foo bar :tag:"
  1225. (let (org-auto-align-tags)
  1226. (org-test-with-temp-text
  1227. "* foo :tag:\n bar<point>"
  1228. (org-delete-indentation)
  1229. (buffer-string)))))
  1230. (should
  1231. (equal "* foo bar :tag:"
  1232. (let (org-auto-align-tags)
  1233. (org-test-with-temp-text
  1234. "* foo <point>:tag:\n bar"
  1235. (org-delete-indentation t)
  1236. (buffer-string))))))
  1237. (ert-deftest test-org/return ()
  1238. "Test `org-return' specifications."
  1239. ;; Regular test.
  1240. (should
  1241. (equal "Para\ngraph"
  1242. (org-test-with-temp-text "Para<point>graph"
  1243. (org-return)
  1244. (buffer-string))))
  1245. ;; With optional argument, indent line.
  1246. (should
  1247. (equal " Para\n graph"
  1248. (org-test-with-temp-text " Para<point>graph"
  1249. (org-return t)
  1250. (buffer-string))))
  1251. ;; On a table, call `org-table-next-row'.
  1252. (should
  1253. (org-test-with-temp-text "| <point>a |\n| b |"
  1254. (org-return)
  1255. (looking-at-p "b")))
  1256. ;; Open link or timestamp under point when `org-return-follows-link'
  1257. ;; is non-nil.
  1258. (should
  1259. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1260. (let ((org-return-follows-link t)
  1261. (org-link-search-must-match-exact-headline nil))
  1262. (org-return))
  1263. (looking-at-p "<<target>>")))
  1264. (should-not
  1265. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1266. (let ((org-return-follows-link nil)) (org-return))
  1267. (looking-at-p "<<target>>")))
  1268. (should
  1269. (org-test-with-temp-text "* [[b][a<point>]]\n* b"
  1270. (let ((org-return-follows-link t)) (org-return))
  1271. (looking-at-p "* b")))
  1272. (should
  1273. (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
  1274. (let ((org-return-follows-link t)
  1275. (org-link-search-must-match-exact-headline nil))
  1276. (org-return))
  1277. (looking-at-p "<<target>>")))
  1278. (should-not
  1279. (org-test-with-temp-text "Link [[target]]<point> <<target>>"
  1280. (let ((org-return-follows-link t)
  1281. (org-link-search-must-match-exact-headline nil))
  1282. (org-return))
  1283. (looking-at-p "<<target>>")))
  1284. ;; When `org-return-follows-link' is non-nil, tolerate links and
  1285. ;; timestamps in comments, node properties, etc.
  1286. (should
  1287. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1288. (let ((org-return-follows-link t)
  1289. (org-link-search-must-match-exact-headline nil))
  1290. (org-return))
  1291. (looking-at-p "<<target>>")))
  1292. (should-not
  1293. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1294. (let ((org-return-follows-link nil)) (org-return))
  1295. (looking-at-p "<<target>>")))
  1296. (should-not
  1297. (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
  1298. (let ((org-return-follows-link t)
  1299. (org-link-search-must-match-exact-headline nil))
  1300. (org-return))
  1301. (looking-at-p "<<target>>")))
  1302. ;; Non-nil `org-return-follows-link' ignores read-only state of
  1303. ;; a buffer.
  1304. (should
  1305. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1306. (let ((org-return-follows-link t)
  1307. (org-link-search-must-match-exact-headline nil))
  1308. (setq buffer-read-only t)
  1309. (call-interactively #'org-return))
  1310. (looking-at-p "<<target>>")))
  1311. ;; `org-return-follows-link' handle multi-line lines.
  1312. (should
  1313. (org-test-with-temp-text
  1314. "[[target][This is a very\n long description<point>]]\n <<target>>"
  1315. (let ((org-return-follows-link t)
  1316. (org-link-search-must-match-exact-headline nil))
  1317. (org-return))
  1318. (looking-at-p "<<target>>")))
  1319. (should-not
  1320. (org-test-with-temp-text
  1321. "[[target][This is a very\n long description]]<point>\n <<target>>"
  1322. (let ((org-return-follows-link t)
  1323. (org-link-search-must-match-exact-headline nil))
  1324. (org-return))
  1325. (looking-at-p "<<target>>")))
  1326. ;; However, do not open link when point is in a table.
  1327. (should
  1328. (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
  1329. (let ((org-return-follows-link t)) (org-return))
  1330. (looking-at-p "between")))
  1331. ;; Special case: in a list, when indenting, do not break structure.
  1332. (should
  1333. (equal "- A\n B"
  1334. (org-test-with-temp-text "- A <point>B"
  1335. (org-return t)
  1336. (buffer-string))))
  1337. (should
  1338. (equal "- A\n\n- B"
  1339. (org-test-with-temp-text "- A\n<point>- B"
  1340. (org-return t)
  1341. (buffer-string))))
  1342. ;; On tags part of a headline, add a newline below it instead of
  1343. ;; breaking it.
  1344. (should
  1345. (equal "* H :tag:\n"
  1346. (org-test-with-temp-text "* H :<point>tag:"
  1347. (org-return)
  1348. (buffer-string))))
  1349. ;; Before headline text, add a newline below it instead of breaking
  1350. ;; it.
  1351. (should
  1352. (equal "* TODO H :tag:\n"
  1353. (org-test-with-temp-text "* <point>TODO H :tag:"
  1354. (org-return)
  1355. (buffer-string))))
  1356. (should
  1357. (equal "* TODO [#B] H :tag:\n"
  1358. (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
  1359. (org-return)
  1360. (buffer-string))))
  1361. (should ;TODO are case-sensitive
  1362. (equal "* \nTodo"
  1363. (org-test-with-temp-text "* <point>Todo"
  1364. (org-return)
  1365. (buffer-string))))
  1366. ;; At headline text, break headline text but preserve tags.
  1367. (should
  1368. (equal "* TODO [#B] foo :tag:\nbar"
  1369. (let (org-auto-align-tags)
  1370. (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
  1371. (org-return)
  1372. (buffer-string)))))
  1373. ;; At bol of headline insert newline.
  1374. (should
  1375. (equal "\n* h"
  1376. (org-test-with-temp-text "<point>* h"
  1377. (org-return)
  1378. (buffer-string))))
  1379. ;; Refuse to leave invalid headline in buffer.
  1380. (should
  1381. (equal "* h\n"
  1382. (org-test-with-temp-text "*<point> h"
  1383. (org-return)
  1384. (buffer-string))))
  1385. ;; Before first column or after last one in a table, split the
  1386. ;; table.
  1387. (should
  1388. (equal "| a |\n\n| b |"
  1389. (org-test-with-temp-text "| a |\n<point>| b |"
  1390. (org-return)
  1391. (buffer-string))))
  1392. (should
  1393. (equal "| a |\n\n| b |"
  1394. (org-test-with-temp-text "| a |<point>\n| b |"
  1395. (org-return)
  1396. (buffer-string))))
  1397. ;; Do not auto-fill on hitting <RET> inside a property drawer.
  1398. (should
  1399. (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:"
  1400. (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:"
  1401. (setq-local fill-column 10)
  1402. (auto-fill-mode 1)
  1403. (org-return)
  1404. (buffer-string)))))
  1405. (ert-deftest test-org/with-electric-indent ()
  1406. "Test RET and C-j specifications with `electric-indent-mode' on."
  1407. ;; Call commands interactively, since this is how `newline' knows it
  1408. ;; must run `post-self-insert-hook'.
  1409. ;;
  1410. ;; RET, like `newline', should indent.
  1411. (should
  1412. (equal " Para\n graph"
  1413. (org-test-with-temp-text " Para<point>graph"
  1414. (electric-indent-local-mode 1)
  1415. (call-interactively 'org-return)
  1416. (buffer-string))))
  1417. (should
  1418. (equal "- item1\n item2"
  1419. (org-test-with-temp-text "- item1<point>item2"
  1420. (electric-indent-local-mode 1)
  1421. (call-interactively 'org-return)
  1422. (buffer-string))))
  1423. ;; TODO: test more values of `org-adapt-indentation'.
  1424. (let ((org-adapt-indentation t))
  1425. (should
  1426. (equal "* heading\n body"
  1427. (org-test-with-temp-text "* heading<point>body"
  1428. (electric-indent-local-mode 1)
  1429. (call-interactively 'org-return)
  1430. (buffer-string)))))
  1431. ;; C-j, like `electric-newline-and-maybe-indent', should not indent.
  1432. (should
  1433. (equal " Para\ngraph"
  1434. (org-test-with-temp-text " Para<point>graph"
  1435. (electric-indent-local-mode 1)
  1436. (call-interactively 'org-return-and-maybe-indent)
  1437. (buffer-string))))
  1438. (should
  1439. (equal "- item1\nitem2"
  1440. (org-test-with-temp-text "- item1<point>item2"
  1441. (electric-indent-local-mode 1)
  1442. (call-interactively 'org-return-and-maybe-indent)
  1443. (buffer-string))))
  1444. ;; TODO: test more values of `org-adapt-indentation'.
  1445. (let ((org-adapt-indentation t))
  1446. (should
  1447. (equal "* heading\nbody"
  1448. (org-test-with-temp-text "* heading<point>body"
  1449. (electric-indent-local-mode 1)
  1450. (call-interactively 'org-return-and-maybe-indent)
  1451. (buffer-string))))))
  1452. (ert-deftest test-org/without-electric-indent ()
  1453. "Test RET and C-j specifications with `electric-indent-mode' off."
  1454. ;; Call commands interactively, since this is how `newline' knows it
  1455. ;; must run `post-self-insert-hook'.
  1456. ;;
  1457. ;; RET, like `newline', should not indent.
  1458. (should
  1459. (equal " Para\ngraph"
  1460. (org-test-with-temp-text " Para<point>graph"
  1461. (electric-indent-local-mode 0)
  1462. (call-interactively 'org-return)
  1463. (buffer-string))))
  1464. (should
  1465. (equal "- item1\nitem2"
  1466. (org-test-with-temp-text "- item1<point>item2"
  1467. (electric-indent-local-mode 0)
  1468. (call-interactively 'org-return)
  1469. (buffer-string))))
  1470. (should
  1471. (equal "* heading\nbody"
  1472. (org-test-with-temp-text "* heading<point>body"
  1473. (electric-indent-local-mode 0)
  1474. (call-interactively 'org-return)
  1475. (buffer-string))))
  1476. ;; C-j, like `electric-newline-and-maybe-indent', should indent.
  1477. (should
  1478. (equal " Para\n graph"
  1479. (org-test-with-temp-text " Para<point>graph"
  1480. (electric-indent-local-mode 0)
  1481. (call-interactively 'org-return-and-maybe-indent)
  1482. (buffer-string))))
  1483. (should
  1484. (equal "- item1\n item2"
  1485. (org-test-with-temp-text "- item1<point>item2"
  1486. (electric-indent-local-mode 0)
  1487. (call-interactively 'org-return-and-maybe-indent)
  1488. (buffer-string))))
  1489. ;; TODO: test more values of `org-adapt-indentation'.
  1490. (let ((org-adapt-indentation t))
  1491. (should
  1492. (equal "* heading\n body"
  1493. (org-test-with-temp-text "* heading<point>body"
  1494. (electric-indent-local-mode 0)
  1495. (call-interactively 'org-return-and-maybe-indent)
  1496. (buffer-string))))))
  1497. (ert-deftest test-org/meta-return ()
  1498. "Test M-RET (`org-meta-return') specifications."
  1499. ;; In a table field insert a row above.
  1500. (should
  1501. (org-test-with-temp-text "| a |"
  1502. (forward-char)
  1503. (org-meta-return)
  1504. (forward-line -1)
  1505. (looking-at "| |$")))
  1506. ;; In a paragraph change current line into a header.
  1507. (should
  1508. (org-test-with-temp-text "a"
  1509. (org-meta-return)
  1510. (beginning-of-line)
  1511. (looking-at "\* a$")))
  1512. ;; In an item insert an item, in this case above.
  1513. (should
  1514. (org-test-with-temp-text "- a"
  1515. (org-meta-return)
  1516. (beginning-of-line)
  1517. (looking-at "- $")))
  1518. ;; In a drawer and item insert an item, in this case above.
  1519. (should
  1520. (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
  1521. (forward-line)
  1522. (org-fold-reveal)
  1523. (org-meta-return)
  1524. (beginning-of-line)
  1525. (looking-at "- $"))))
  1526. (ert-deftest test-org/insert-heading ()
  1527. "Test `org-insert-heading' specifications."
  1528. ;; In an empty buffer, insert a new headline.
  1529. (should
  1530. (equal "* "
  1531. (org-test-with-temp-text ""
  1532. (org-insert-heading)
  1533. (buffer-string))))
  1534. ;; At the beginning of a line, turn it into a headline.
  1535. (should
  1536. (equal "* P"
  1537. (org-test-with-temp-text "<point>P"
  1538. (org-insert-heading)
  1539. (buffer-string))))
  1540. ;; In the middle of a line, split the line if allowed, otherwise,
  1541. ;; insert the headline at its end.
  1542. (should
  1543. (equal "Para\n* graph"
  1544. (org-test-with-temp-text "Para<point>graph"
  1545. (let ((org-M-RET-may-split-line '((default . t))))
  1546. (org-insert-heading))
  1547. (buffer-string))))
  1548. (should
  1549. (equal "Paragraph\n* "
  1550. (org-test-with-temp-text "Para<point>graph"
  1551. (let ((org-M-RET-may-split-line '((default . nil))))
  1552. (org-insert-heading))
  1553. (buffer-string))))
  1554. ;; At the beginning of a headline, create one above.
  1555. (should
  1556. (equal "* \n* H"
  1557. (org-test-with-temp-text "* H"
  1558. (org-insert-heading)
  1559. (buffer-string))))
  1560. ;; In the middle of a headline, split it if allowed.
  1561. (should
  1562. (equal "* H\n* 1"
  1563. (org-test-with-temp-text "* H<point>1"
  1564. (let ((org-M-RET-may-split-line '((headline . t))))
  1565. (org-insert-heading))
  1566. (buffer-string))))
  1567. (should
  1568. (equal "* H1\n* "
  1569. (org-test-with-temp-text "* H<point>1"
  1570. (let ((org-M-RET-may-split-line '((headline . nil))))
  1571. (org-insert-heading))
  1572. (buffer-string))))
  1573. ;; However, splitting cannot happen on TODO keywords, priorities or
  1574. ;; tags.
  1575. (should
  1576. (equal "* TODO H1\n* "
  1577. (org-test-with-temp-text "* TO<point>DO H1"
  1578. (let ((org-M-RET-may-split-line '((headline . t))))
  1579. (org-insert-heading))
  1580. (buffer-string))))
  1581. (should
  1582. (equal "* [#A] H1\n* "
  1583. (org-test-with-temp-text "* [#<point>A] H1"
  1584. (let ((org-M-RET-may-split-line '((headline . t))))
  1585. (org-insert-heading))
  1586. (buffer-string))))
  1587. (should
  1588. (equal "* H1 :tag:\n* "
  1589. (org-test-with-temp-text "* H1 :ta<point>g:"
  1590. (let ((org-M-RET-may-split-line '((headline . t))))
  1591. (org-insert-heading))
  1592. (buffer-string))))
  1593. ;; New headline level depends on the level of the headline above.
  1594. (should
  1595. (equal "** H\n** P"
  1596. (org-test-with-temp-text "** H\n<point>P"
  1597. (org-insert-heading)
  1598. (buffer-string))))
  1599. (should
  1600. (equal "** H\nPara\n** graph"
  1601. (org-test-with-temp-text "** H\nPara<point>graph"
  1602. (let ((org-M-RET-may-split-line '((default . t))))
  1603. (org-insert-heading))
  1604. (buffer-string))))
  1605. (should
  1606. (equal "** \n** H"
  1607. (org-test-with-temp-text "** H"
  1608. (org-insert-heading)
  1609. (buffer-string))))
  1610. ;; When called with one universal argument, insert a new headline at
  1611. ;; the end of the current subtree, independently on the position of
  1612. ;; point.
  1613. (should
  1614. (equal
  1615. "* "
  1616. (org-test-with-temp-text ""
  1617. (let ((org-insert-heading-respect-content nil))
  1618. (org-insert-heading '(4)))
  1619. (buffer-string))))
  1620. (should
  1621. (equal
  1622. "entry
  1623. * "
  1624. (org-test-with-temp-text "entry"
  1625. (let ((org-insert-heading-respect-content nil))
  1626. (org-insert-heading '(4)))
  1627. (buffer-string))))
  1628. (should
  1629. (equal
  1630. "* H1\n** H2\n* "
  1631. (org-test-with-temp-text "* H1\n** H2"
  1632. (let ((org-insert-heading-respect-content nil))
  1633. (org-insert-heading '(4)))
  1634. (buffer-string))))
  1635. (should
  1636. (equal
  1637. "* H1\n** H2\n* "
  1638. (org-test-with-temp-text "* H<point>1\n** H2"
  1639. (let ((org-insert-heading-respect-content nil))
  1640. (org-insert-heading '(4)))
  1641. (buffer-string))))
  1642. ;; When called with two universal arguments, insert a new headline
  1643. ;; at the end of the grandparent subtree.
  1644. (should
  1645. (equal "* H1\n** H3\n- item\n** H2\n** "
  1646. (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
  1647. (let ((org-insert-heading-respect-content nil))
  1648. (org-insert-heading '(16)))
  1649. (buffer-string))))
  1650. ;; When optional TOP-LEVEL argument is non-nil, always insert
  1651. ;; a level 1 heading.
  1652. (should
  1653. (equal "* H1\n** H2\n* "
  1654. (org-test-with-temp-text "* H1\n** H2<point>"
  1655. (org-insert-heading nil nil t)
  1656. (buffer-string))))
  1657. (should
  1658. (equal "* H1\n- item\n* "
  1659. (org-test-with-temp-text "* H1\n- item<point>"
  1660. (org-insert-heading nil nil t)
  1661. (buffer-string))))
  1662. ;; Obey `org-blank-before-new-entry'.
  1663. (should
  1664. (equal "* H1\n\n* "
  1665. (org-test-with-temp-text "* H1<point>"
  1666. (let ((org-blank-before-new-entry '((heading . t))))
  1667. (org-insert-heading))
  1668. (buffer-string))))
  1669. (should
  1670. (equal "* H1\n* "
  1671. (org-test-with-temp-text "* H1<point>"
  1672. (let ((org-blank-before-new-entry '((heading . nil))))
  1673. (org-insert-heading))
  1674. (buffer-string))))
  1675. (should
  1676. (equal "* H1\n* H2\n* "
  1677. (org-test-with-temp-text "* H1\n* H2<point>"
  1678. (let ((org-blank-before-new-entry '((heading . auto))))
  1679. (org-insert-heading))
  1680. (buffer-string))))
  1681. (should
  1682. (equal "* H1\n\n* H2\n\n* "
  1683. (org-test-with-temp-text "* H1\n\n* H2<point>"
  1684. (let ((org-blank-before-new-entry '((heading . auto))))
  1685. (org-insert-heading))
  1686. (buffer-string))))
  1687. ;; Corner case: correctly insert a headline after an empty one.
  1688. (should
  1689. (equal "* \n* "
  1690. (org-test-with-temp-text "* <point>"
  1691. (org-insert-heading)
  1692. (buffer-string))))
  1693. (should
  1694. (org-test-with-temp-text "* <point>\n"
  1695. (org-insert-heading)
  1696. (looking-at-p "\n\\'")))
  1697. ;; Do not insert spurious headlines when inserting a new headline.
  1698. (should
  1699. (equal "* H1\n* H2\n* \n"
  1700. (org-test-with-temp-text "* H1\n* H2<point>\n"
  1701. (org-insert-heading)
  1702. (buffer-string))))
  1703. ;; Preserve visibility at beginning of line. In particular, when
  1704. ;; removing spurious blank lines, do not visually merge heading with
  1705. ;; the line visible above.
  1706. (should-not
  1707. (org-test-with-temp-text "* H1<point>\nContents\n\n* H2\n"
  1708. (org-overview)
  1709. (let ((org-blank-before-new-entry '((heading . nil))))
  1710. (org-insert-heading '(4)))
  1711. (invisible-p (line-end-position 0))))
  1712. ;; Properly handle empty lines when forcing a headline below current
  1713. ;; one.
  1714. (should
  1715. (equal "* H1\n\n* H\n\n* "
  1716. (org-test-with-temp-text "* H1\n\n* H<point>"
  1717. (let ((org-blank-before-new-entry '((heading . t))))
  1718. (org-insert-heading '(4))
  1719. (buffer-string))))))
  1720. (ert-deftest test-org/insert-todo-heading-respect-content ()
  1721. "Test `org-insert-todo-heading-respect-content' specifications."
  1722. ;; Create a TODO heading.
  1723. (should
  1724. (org-test-with-temp-text "* H1\n Body"
  1725. (org-insert-todo-heading-respect-content)
  1726. (nth 2 (org-heading-components))))
  1727. ;; Add headline at the end of the first subtree
  1728. (should
  1729. (equal
  1730. "* TODO "
  1731. (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
  1732. (org-insert-todo-heading-respect-content)
  1733. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1734. ;; In a list, do not create a new item.
  1735. (should
  1736. (equal
  1737. "* TODO "
  1738. (org-test-with-temp-text "* H\n- an item\n- another one"
  1739. (search-forward "an ")
  1740. (org-insert-todo-heading-respect-content)
  1741. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1742. ;; Use the same TODO keyword as current heading.
  1743. (should
  1744. (equal
  1745. "* TODO \n"
  1746. (org-test-with-temp-text "* TODO\n** WAITING\n"
  1747. (org-insert-todo-heading-respect-content)
  1748. (buffer-substring-no-properties (line-beginning-position) (point-max))))))
  1749. (ert-deftest test-org/clone-with-time-shift ()
  1750. "Test `org-clone-subtree-with-time-shift'."
  1751. ;; Raise an error before first heading.
  1752. (should-error
  1753. (org-test-with-temp-text ""
  1754. (org-clone-subtree-with-time-shift 1)))
  1755. ;; Raise an error on invalid number of clones.
  1756. (should-error
  1757. (org-test-with-temp-text "* Clone me"
  1758. (org-clone-subtree-with-time-shift -1)))
  1759. ;; Clone non-repeating once.
  1760. (should
  1761. (equal "\
  1762. * H1\n<2015-06-21>
  1763. * H1\n<2015-06-23>
  1764. "
  1765. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1766. (org-clone-subtree-with-time-shift 1 "+2d")
  1767. (replace-regexp-in-string
  1768. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1769. nil nil 1))))
  1770. ;; Clone repeating once.
  1771. (should
  1772. (equal "\
  1773. * H1\n<2015-06-21>
  1774. * H1\n<2015-06-23>
  1775. * H1\n<2015-06-25 +1w>
  1776. "
  1777. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1778. (org-clone-subtree-with-time-shift 1 "+2d")
  1779. (replace-regexp-in-string
  1780. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1781. nil nil 1))))
  1782. ;; Clone repeating once in backward.
  1783. (should
  1784. (equal "\
  1785. * H1\n<2015-06-21>
  1786. * H1\n<2015-06-19>
  1787. * H1\n<2015-06-17 +1w>
  1788. "
  1789. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1790. (org-clone-subtree-with-time-shift 1 "-2d")
  1791. (replace-regexp-in-string
  1792. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1793. nil nil 1))))
  1794. ;; Clone non-repeating zero times.
  1795. (should
  1796. (equal "\
  1797. * H1\n<2015-06-21>
  1798. "
  1799. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1800. (org-clone-subtree-with-time-shift 0 "+2d")
  1801. (replace-regexp-in-string
  1802. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1803. nil nil 1))))
  1804. ;; Clone repeating "zero" times.
  1805. (should
  1806. (equal "\
  1807. * H1\n<2015-06-21>
  1808. * H1\n<2015-06-23 +1w>
  1809. "
  1810. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1811. (org-clone-subtree-with-time-shift 0 "+2d")
  1812. (replace-regexp-in-string
  1813. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1814. nil nil 1))))
  1815. ;; Clone with blank SHIFT argument.
  1816. (should
  1817. (string-prefix-p
  1818. "* H <2012-03-29"
  1819. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1820. (org-clone-subtree-with-time-shift 1 "")
  1821. (buffer-substring-no-properties (line-beginning-position 2)
  1822. (line-end-position 2)))))
  1823. ;; Find time stamps before point. If SHIFT is not specified, ask
  1824. ;; for a time shift.
  1825. (should
  1826. (string-prefix-p
  1827. "* H <2012-03-30"
  1828. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1829. (org-clone-subtree-with-time-shift 1 "+1d")
  1830. (buffer-substring-no-properties (line-beginning-position 2)
  1831. (line-end-position 2)))))
  1832. (should
  1833. (string-prefix-p
  1834. "* H <2014-03-05"
  1835. (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
  1836. (cl-letf (((symbol-function 'read-from-minibuffer)
  1837. (lambda (&rest args) "+1d")))
  1838. (org-clone-subtree-with-time-shift 1))
  1839. (buffer-substring-no-properties (line-beginning-position 2)
  1840. (line-end-position 2)))))
  1841. ;; Hour shift.
  1842. (should
  1843. (equal "\
  1844. * H1\n<2015-06-21 20:00>
  1845. * H1\n<2015-06-21 23:00>
  1846. * H1\n<2015-06-22 02:00>
  1847. "
  1848. (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>"
  1849. (org-clone-subtree-with-time-shift 2 "+3h")
  1850. (replace-regexp-in-string
  1851. "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" ""
  1852. (buffer-substring-no-properties (point-min) (point-max))
  1853. nil nil 1))))
  1854. (should
  1855. (equal "\
  1856. * H1\n<2015-06-21 20:00>
  1857. * H1\n<2015-06-21 18:00>
  1858. "
  1859. (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>"
  1860. (org-clone-subtree-with-time-shift 1 "-2h")
  1861. (replace-regexp-in-string
  1862. "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" ""
  1863. (buffer-substring-no-properties (point-min) (point-max))
  1864. nil nil 1)))))
  1865. ;;; Fixed-Width Areas
  1866. (ert-deftest test-org/toggle-fixed-width ()
  1867. "Test `org-toggle-fixed-width' specifications."
  1868. ;; No region: Toggle on fixed-width marker in paragraphs.
  1869. (should
  1870. (equal ": A"
  1871. (org-test-with-temp-text "A"
  1872. (org-toggle-fixed-width)
  1873. (buffer-string))))
  1874. ;; No region: Toggle off fixed-width markers in fixed-width areas.
  1875. (should
  1876. (equal "A"
  1877. (org-test-with-temp-text ": A"
  1878. (org-toggle-fixed-width)
  1879. (buffer-string))))
  1880. ;; No region: Toggle on marker in blank lines after elements or just
  1881. ;; after a headline.
  1882. (should
  1883. (equal "* H\n: "
  1884. (org-test-with-temp-text "* H\n"
  1885. (forward-line)
  1886. (org-toggle-fixed-width)
  1887. (buffer-string))))
  1888. (should
  1889. (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
  1890. (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
  1891. (goto-char (point-max))
  1892. (org-toggle-fixed-width)
  1893. (buffer-string))))
  1894. ;; No region: Toggle on marker in front of one line elements (e.g.,
  1895. ;; headlines, clocks)
  1896. (should
  1897. (equal ": * Headline"
  1898. (org-test-with-temp-text "* Headline"
  1899. (org-toggle-fixed-width)
  1900. (buffer-string))))
  1901. (should
  1902. (equal ": #+KEYWORD: value"
  1903. (org-test-with-temp-text "#+KEYWORD: value"
  1904. (org-toggle-fixed-width)
  1905. (buffer-string))))
  1906. ;; No region: error in other situations.
  1907. (should-error
  1908. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
  1909. (forward-line)
  1910. (org-toggle-fixed-width)
  1911. (buffer-string)))
  1912. ;; No region: Indentation is preserved.
  1913. (should
  1914. (equal "- A\n : B"
  1915. (org-test-with-temp-text "- A\n B"
  1916. (forward-line)
  1917. (org-toggle-fixed-width)
  1918. (buffer-string))))
  1919. ;; Region: If it contains only fixed-width elements and blank lines,
  1920. ;; toggle off fixed-width markup.
  1921. (should
  1922. (equal "A\n\nB"
  1923. (org-test-with-temp-text ": A\n\n: B"
  1924. (transient-mark-mode 1)
  1925. (push-mark (point) t t)
  1926. (goto-char (point-max))
  1927. (org-toggle-fixed-width)
  1928. (buffer-string))))
  1929. ;; Region: If it contains anything else, toggle on fixed-width but
  1930. ;; not on fixed-width areas.
  1931. (should
  1932. (equal ": A\n: \n: B\n: \n: C"
  1933. (org-test-with-temp-text "A\n\n: B\n\nC"
  1934. (transient-mark-mode 1)
  1935. (push-mark (point) t t)
  1936. (goto-char (point-max))
  1937. (org-toggle-fixed-width)
  1938. (buffer-string))))
  1939. ;; Region: Ignore blank lines at its end, unless it contains only
  1940. ;; such lines.
  1941. (should
  1942. (equal ": A\n\n"
  1943. (org-test-with-temp-text "A\n\n"
  1944. (transient-mark-mode 1)
  1945. (push-mark (point) t t)
  1946. (goto-char (point-max))
  1947. (org-toggle-fixed-width)
  1948. (buffer-string))))
  1949. (should
  1950. (equal ": \n: \n"
  1951. (org-test-with-temp-text "\n\n"
  1952. (transient-mark-mode 1)
  1953. (push-mark (point) t t)
  1954. (goto-char (point-max))
  1955. (org-toggle-fixed-width)
  1956. (buffer-string)))))
  1957. (ert-deftest test-org/kill-line ()
  1958. "Test `org-kill-line' specifications."
  1959. ;; At the beginning of a line, kill whole line.
  1960. (should
  1961. (equal ""
  1962. (org-test-with-temp-text "abc"
  1963. (org-kill-line)
  1964. (buffer-string))))
  1965. ;; In the middle of a line, kill line until its end.
  1966. (should
  1967. (equal "a"
  1968. (org-test-with-temp-text "a<point>bc"
  1969. (org-kill-line)
  1970. (buffer-string))))
  1971. ;; Do not kill newline character.
  1972. (should
  1973. (equal "\n123"
  1974. (org-test-with-temp-text "abc\n123"
  1975. (org-kill-line)
  1976. (buffer-string))))
  1977. (should
  1978. (equal "a\n123"
  1979. (org-test-with-temp-text "a<point>bc\n123"
  1980. (org-kill-line)
  1981. (buffer-string))))
  1982. ;; When `org-special-ctrl-k' is non-nil and point is at a headline,
  1983. ;; kill until tags.
  1984. (should
  1985. (equal "* A :tag:"
  1986. (org-test-with-temp-text "* A<point>B :tag:"
  1987. (let ((org-special-ctrl-k t)
  1988. (org-tags-column 0))
  1989. (org-kill-line))
  1990. (buffer-string))))
  1991. ;; If point is on tags, only kill part left until the end of line.
  1992. (should
  1993. (equal "* A :tag:"
  1994. (org-test-with-temp-text "* A :tag:<point>tag2:"
  1995. (let ((org-special-ctrl-k t)
  1996. (org-tags-column 0))
  1997. (org-kill-line))
  1998. (buffer-string))))
  1999. ;; However, if point is at the beginning of the line, kill whole
  2000. ;; headline.
  2001. (should
  2002. (equal ""
  2003. (org-test-with-temp-text "* AB :tag:"
  2004. (let ((org-special-ctrl-k t)
  2005. (org-tags-column 0))
  2006. (org-kill-line))
  2007. (buffer-string))))
  2008. ;; When `org-ctrl-k-protect-subtree' is non-nil, and point is in
  2009. ;; invisible text, ask before removing it. When set to `error',
  2010. ;; throw an error.
  2011. (should-error
  2012. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  2013. (org-overview)
  2014. (let ((org-special-ctrl-k nil)
  2015. (org-ctrl-k-protect-subtree t))
  2016. (cl-letf (((symbol-function 'y-or-n-p) 'ignore))
  2017. (org-kill-line)))))
  2018. (should-error
  2019. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  2020. (org-overview)
  2021. (let ((org-special-ctrl-k nil)
  2022. (org-ctrl-k-protect-subtree 'error))
  2023. (org-kill-line)))))
  2024. ;;; Headline
  2025. (ert-deftest test-org/get-heading ()
  2026. "Test `org-get-heading' specifications."
  2027. ;; Return current heading, even if point is not on it.
  2028. (should
  2029. (equal "H"
  2030. (org-test-with-temp-text "* H"
  2031. (org-get-heading))))
  2032. (should
  2033. (equal "H"
  2034. (org-test-with-temp-text "* H\nText<point>"
  2035. (org-get-heading))))
  2036. ;; Without any optional argument, return TODO keyword, priority
  2037. ;; cookie, COMMENT keyword and tags.
  2038. (should
  2039. (equal "TODO H"
  2040. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2041. (org-get-heading))))
  2042. (should
  2043. (equal "[#A] H"
  2044. (org-test-with-temp-text "* [#A] H"
  2045. (org-get-heading))))
  2046. (should
  2047. (equal "COMMENT H"
  2048. (org-test-with-temp-text "* COMMENT H"
  2049. (org-get-heading))))
  2050. (should
  2051. (equal "H :tag:"
  2052. (org-test-with-temp-text "* H :tag:"
  2053. (org-get-heading))))
  2054. ;; With NO-TAGS argument, ignore tags.
  2055. (should
  2056. (equal "TODO H"
  2057. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2058. (org-get-heading t))))
  2059. (should
  2060. (equal "H"
  2061. (org-test-with-temp-text "* H :tag:"
  2062. (org-get-heading t))))
  2063. ;; With NO-TODO, ignore TODO keyword.
  2064. (should
  2065. (equal "H"
  2066. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2067. (org-get-heading nil t))))
  2068. (should
  2069. (equal "H :tag:"
  2070. (org-test-with-temp-text "* H :tag:"
  2071. (org-get-heading nil t))))
  2072. ;; TODO keywords are case-sensitive.
  2073. (should
  2074. (equal "Todo H"
  2075. (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
  2076. (org-get-heading nil t))))
  2077. ;; With NO-PRIORITY, ignore priority.
  2078. (should
  2079. (equal "H"
  2080. (org-test-with-temp-text "* [#A] H"
  2081. (org-get-heading nil nil t))))
  2082. (should
  2083. (equal "H"
  2084. (org-test-with-temp-text "* H"
  2085. (org-get-heading nil nil t))))
  2086. (should
  2087. (equal "TODO H"
  2088. (org-test-with-temp-text "* TODO [#A] H"
  2089. (org-get-heading nil nil t))))
  2090. ;; With NO-COMMENT, ignore COMMENT keyword.
  2091. (should
  2092. (equal "H"
  2093. (org-test-with-temp-text "* COMMENT H"
  2094. (org-get-heading nil nil nil t))))
  2095. (should
  2096. (equal "H"
  2097. (org-test-with-temp-text "* H"
  2098. (org-get-heading nil nil nil t))))
  2099. (should
  2100. (equal "TODO [#A] H"
  2101. (org-test-with-temp-text "* TODO [#A] COMMENT H"
  2102. (org-get-heading nil nil nil t))))
  2103. ;; On an empty headline, return value is consistent.
  2104. (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
  2105. (should (equal "" (org-test-with-temp-text "* " (org-get-heading t))))
  2106. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t))))
  2107. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t))))
  2108. (should
  2109. (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t)))))
  2110. (ert-deftest test-org/in-commented-heading-p ()
  2111. "Test `org-in-commented-heading-p' specifications."
  2112. ;; Commented headline.
  2113. (should
  2114. (org-test-with-temp-text "* COMMENT Headline\nBody"
  2115. (goto-char (point-max))
  2116. (org-in-commented-heading-p)))
  2117. ;; Commented ancestor.
  2118. (should
  2119. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  2120. (goto-char (point-max))
  2121. (org-in-commented-heading-p)))
  2122. ;; Comment keyword is case-sensitive.
  2123. (should-not
  2124. (org-test-with-temp-text "* Comment Headline\nBody"
  2125. (goto-char (point-max))
  2126. (org-in-commented-heading-p)))
  2127. ;; Keyword is standalone.
  2128. (should-not
  2129. (org-test-with-temp-text "* COMMENTHeadline\nBody"
  2130. (goto-char (point-max))
  2131. (org-in-commented-heading-p)))
  2132. ;; Optional argument.
  2133. (should-not
  2134. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  2135. (goto-char (point-max))
  2136. (org-in-commented-heading-p t))))
  2137. (ert-deftest test-org/in-archived-heading-p ()
  2138. "Test `org-in-archived-heading-p' specifications."
  2139. ;; Archived headline.
  2140. (should
  2141. (org-test-with-temp-text "* Headline :ARCHIVE:\nBody"
  2142. (goto-char (point-max))
  2143. (org-in-archived-heading-p)))
  2144. ;; Archived ancestor.
  2145. (should
  2146. (org-test-with-temp-text "* Headline :ARCHIVE:\n** Level 2\nBody"
  2147. (goto-char (point-max))
  2148. (org-in-archived-heading-p)))
  2149. ;; Optional argument.
  2150. (should-not
  2151. (org-test-with-temp-text "* Headline :ARCHIVE:\n** Level 2\nBody"
  2152. (goto-char (point-max))
  2153. (org-in-archived-heading-p t)))
  2154. ;; Archive tag containing ARCHIVE as substring
  2155. (should-not
  2156. (org-test-with-temp-text "* Headline :NOARCHIVE:\n** Level 2\nBody"
  2157. (goto-char (point-max))
  2158. (org-in-archived-heading-p))))
  2159. (ert-deftest test-org/entry-blocked-p ()
  2160. ;; Check other dependencies.
  2161. (should
  2162. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  2163. (let ((org-enforce-todo-dependencies t)
  2164. (org-blocker-hook
  2165. '(org-block-todo-from-children-or-siblings-or-parent)))
  2166. (org-entry-blocked-p))))
  2167. (should-not
  2168. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  2169. (let ((org-enforce-todo-dependencies t)
  2170. (org-blocker-hook
  2171. '(org-block-todo-from-children-or-siblings-or-parent)))
  2172. (org-entry-blocked-p))))
  2173. ;; Entry without a TODO keyword or with a DONE keyword cannot be
  2174. ;; blocked.
  2175. (should-not
  2176. (org-test-with-temp-text "* Blocked\n** TODO one"
  2177. (let ((org-enforce-todo-dependencies t)
  2178. (org-blocker-hook
  2179. '(org-block-todo-from-children-or-siblings-or-parent)))
  2180. (org-entry-blocked-p))))
  2181. (should-not
  2182. (org-test-with-temp-text "* DONE Blocked\n** TODO one"
  2183. (let ((org-enforce-todo-dependencies t)
  2184. (org-blocker-hook
  2185. '(org-block-todo-from-children-or-siblings-or-parent)))
  2186. (org-entry-blocked-p))))
  2187. ;; Follow :ORDERED: specifications.
  2188. (should
  2189. (org-test-with-temp-text
  2190. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
  2191. (let ((org-enforce-todo-dependencies t)
  2192. (org-blocker-hook
  2193. '(org-block-todo-from-children-or-siblings-or-parent)))
  2194. (org-entry-blocked-p))))
  2195. (should-not
  2196. (org-test-with-temp-text
  2197. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
  2198. (let ((org-enforce-todo-dependencies t)
  2199. (org-blocker-hook
  2200. '(org-block-todo-from-children-or-siblings-or-parent)))
  2201. (org-entry-blocked-p)))))
  2202. (ert-deftest test-org/get-outline-path ()
  2203. "Test `org-get-outline-path' specifications."
  2204. ;; Top-level headlines have no outline path.
  2205. (should-not
  2206. (org-test-with-temp-text "* H"
  2207. (org-get-outline-path)))
  2208. ;; Otherwise, outline path is the path leading to the headline.
  2209. (should
  2210. (equal '("H")
  2211. (org-test-with-temp-text "* H\n** S<point>"
  2212. (org-get-outline-path))))
  2213. ;; Find path even when point is not on a headline.
  2214. (should
  2215. (equal '("H")
  2216. (org-test-with-temp-text "* H\n** S\nText<point>"
  2217. (org-get-outline-path))))
  2218. ;; TODO keywords, tags and statistics cookies are ignored.
  2219. (should
  2220. (equal '("H")
  2221. (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
  2222. (org-get-outline-path))))
  2223. ;; Links are replaced with their description or their path.
  2224. (should
  2225. (equal '("Org")
  2226. (org-test-with-temp-text
  2227. "* [[https://orgmode.org][Org]]\n** S<point>"
  2228. (org-get-outline-path))))
  2229. (should
  2230. (equal '("https://orgmode.org")
  2231. (org-test-with-temp-text
  2232. "* [[https://orgmode.org]]\n** S<point>"
  2233. (org-get-outline-path))))
  2234. ;; When WITH-SELF is non-nil, include current heading.
  2235. (should
  2236. (equal '("H")
  2237. (org-test-with-temp-text "* H"
  2238. (org-get-outline-path t))))
  2239. (should
  2240. (equal '("H" "S")
  2241. (org-test-with-temp-text "* H\n** S\nText<point>"
  2242. (org-get-outline-path t))))
  2243. ;; Using cache is transparent to the user.
  2244. (should
  2245. (equal '("H")
  2246. (org-test-with-temp-text "* H\n** S<point>"
  2247. (setq org-outline-path-cache nil)
  2248. (org-get-outline-path nil t))))
  2249. ;; Do not corrupt cache when finding outline path in distant part of
  2250. ;; the buffer.
  2251. (should
  2252. (equal '("H2")
  2253. (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
  2254. (setq org-outline-path-cache nil)
  2255. (org-get-outline-path nil t)
  2256. (search-forward "S2")
  2257. (org-get-outline-path nil t))))
  2258. ;; Do not choke on empty headlines.
  2259. (should
  2260. (org-test-with-temp-text "* H\n** <point>"
  2261. (org-get-outline-path)))
  2262. (should
  2263. (org-test-with-temp-text "* \n** H<point>"
  2264. (org-get-outline-path))))
  2265. (ert-deftest test-org/format-outline-path ()
  2266. "Test `org-format-outline-path' specifications."
  2267. (should
  2268. (string= (org-format-outline-path (list "one" "two" "three"))
  2269. "one/two/three"))
  2270. ;; Empty path.
  2271. (should
  2272. (string= (org-format-outline-path '())
  2273. ""))
  2274. (should
  2275. (string= (org-format-outline-path '(nil))
  2276. ""))
  2277. ;; Empty path and prefix.
  2278. (should
  2279. (string= (org-format-outline-path '() nil ">>")
  2280. ">>"))
  2281. ;; Trailing whitespace in headings.
  2282. (should
  2283. (string= (org-format-outline-path (list "one\t" "tw o " "three "))
  2284. "one/tw o/three"))
  2285. ;; Non-default prefix and separators.
  2286. (should
  2287. (string= (org-format-outline-path (list "one" "two" "three") nil ">>" "|")
  2288. ">>|one|two|three"))
  2289. ;; Truncate.
  2290. (should
  2291. (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
  2292. "one/two/.."))
  2293. ;; Give a very narrow width.
  2294. (should
  2295. (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
  2296. "on"))
  2297. ;; Give a prefix that extends beyond the width.
  2298. (should
  2299. (string= (org-format-outline-path (list "one" "two" "three" "four") 10
  2300. ">>>>>>>>>>")
  2301. ">>>>>>>>..")))
  2302. (ert-deftest test-org/org-find-olp ()
  2303. "Test `org-find-olp' specifications."
  2304. (org-test-with-temp-text
  2305. "
  2306. * Headline
  2307. ** COMMENT headline2
  2308. ** TODO headline3
  2309. *** [#A] headline4 :tags:
  2310. ** [#A]headline5
  2311. ** [0%] headline6
  2312. ** headline7 [100%]
  2313. ** headline8 [1/5] :some:more:tags:
  2314. * Test
  2315. "
  2316. (should (org-find-olp '("Headline") t))
  2317. (should-error (org-find-olp '("Headline" "Test") t))
  2318. (should-error (org-find-olp '("Headlinealksjd") t))
  2319. (should (org-find-olp '("Headline" "headline2") t))
  2320. (should (org-find-olp '("Headline" "headline3") t))
  2321. (should (org-find-olp '("Headline" "headline3" "headline4") t))
  2322. (should-error (org-find-olp '("Headline" "headline5") t))
  2323. (should (org-find-olp '("Headline" "headline6") t))
  2324. (should (org-find-olp '("Headline" "headline7") t))
  2325. (should (org-find-olp '("Headline" "headline8") t))))
  2326. (ert-deftest test-org/map-entries ()
  2327. "Test `org-map-entries' specifications."
  2328. ;; Full match.
  2329. (should
  2330. (equal '(1 11)
  2331. (org-test-with-temp-text "* Level 1\n** Level 2"
  2332. (org-map-entries #'point))))
  2333. ;; Level match.
  2334. (should
  2335. (equal '(1)
  2336. (org-test-with-temp-text "* Level 1\n** Level 2"
  2337. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL=1")))))
  2338. (should
  2339. (equal '(11)
  2340. (org-test-with-temp-text "* Level 1\n** Level 2"
  2341. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL>1")))))
  2342. ;; Tag match.
  2343. (should
  2344. (equal '(11)
  2345. (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
  2346. (org-map-entries #'point "yes"))))
  2347. (should
  2348. (equal '(14)
  2349. (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
  2350. (org-map-entries #'point "+yes-a"))))
  2351. (should
  2352. (equal '(11 23)
  2353. (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
  2354. (org-map-entries #'point "{yes?}"))))
  2355. ;; Priority match.
  2356. (should
  2357. (equal '(1)
  2358. (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
  2359. (org-map-entries #'point "PRIORITY=\"A\""))))
  2360. ;; Date match.
  2361. (should
  2362. (equal '(36)
  2363. (org-test-with-temp-text "
  2364. * H1
  2365. SCHEDULED: <2012-03-29 thu.>
  2366. * H2
  2367. SCHEDULED: <2014-03-04 tue.>"
  2368. (org-map-entries #'point "SCHEDULED=\"<2014-03-04 tue.>\""))))
  2369. (should
  2370. (equal '(2)
  2371. (org-test-with-temp-text "
  2372. * H1
  2373. SCHEDULED: <2012-03-29 thu.>
  2374. * H2
  2375. SCHEDULED: <2014-03-04 tue.>"
  2376. (org-map-entries #'point "SCHEDULED<\"<2013-01-01>\""))))
  2377. ;; Regular property match.
  2378. (should
  2379. (equal '(2)
  2380. (org-test-with-temp-text "
  2381. * H1
  2382. :PROPERTIES:
  2383. :TEST: 1
  2384. :END:
  2385. * H2
  2386. :PROPERTIES:
  2387. :TEST: 2
  2388. :END:"
  2389. (org-map-entries #'point "TEST=1"))))
  2390. ;; Multiple criteria.
  2391. (should
  2392. (equal '(23)
  2393. (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
  2394. (let (org-odd-levels-only
  2395. (org-use-tag-inheritance nil))
  2396. (org-map-entries #'point "yes+LEVEL=1")))))
  2397. ;; "or" criteria.
  2398. (should
  2399. (equal '(12 24)
  2400. (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
  2401. (let (org-odd-levels-only)
  2402. (org-map-entries #'point "LEVEL=2|no")))))
  2403. (should
  2404. (equal '(1 12)
  2405. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
  2406. (let (org-odd-levels-only)
  2407. (org-map-entries #'point "yes|no")))))
  2408. ;; "and" criteria.
  2409. (should
  2410. (equal '(22)
  2411. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
  2412. (let (org-odd-levels-only)
  2413. (org-map-entries #'point "yes&no")))))
  2414. ;; Setting `org-map-continue-from'
  2415. (should
  2416. (string= ""
  2417. (org-test-with-temp-text "* H1\n* H2\n* H3n* H4"
  2418. (org-map-entries
  2419. (lambda ()
  2420. (org-cut-subtree)
  2421. (setq org-map-continue-from (point))))
  2422. (buffer-string))))
  2423. (should
  2424. (string= "* H1\n* H2\n* H3\n"
  2425. (org-test-with-temp-text "* H1\n* H2\n* H3\n* H4"
  2426. (org-map-entries
  2427. (lambda ()
  2428. (when (string= "H4"
  2429. (org-element-property
  2430. :raw-value (org-element-at-point)))
  2431. (org-cut-subtree)
  2432. (setq org-map-continue-from
  2433. (org-element-property
  2434. :begin (org-element-at-point))))))
  2435. (buffer-string)))))
  2436. (ert-deftest test-org/edit-headline ()
  2437. "Test `org-edit-headline' specifications."
  2438. (should
  2439. (equal "* B"
  2440. (org-test-with-temp-text "* A"
  2441. (org-edit-headline "B")
  2442. (buffer-string))))
  2443. ;; Handle empty headings.
  2444. (should
  2445. (equal "* "
  2446. (org-test-with-temp-text "* A"
  2447. (org-edit-headline "")
  2448. (buffer-string))))
  2449. (should
  2450. (equal "* A"
  2451. (org-test-with-temp-text "* "
  2452. (org-edit-headline "A")
  2453. (buffer-string))))
  2454. ;; Handle TODO keywords and priority cookies.
  2455. (should
  2456. (equal "* TODO B"
  2457. (org-test-with-temp-text "* TODO A"
  2458. (org-edit-headline "B")
  2459. (buffer-string))))
  2460. (should
  2461. (equal "* [#A] B"
  2462. (org-test-with-temp-text "* [#A] A"
  2463. (org-edit-headline "B")
  2464. (buffer-string))))
  2465. (should
  2466. (equal "* TODO [#A] B"
  2467. (org-test-with-temp-text "* TODO [#A] A"
  2468. (org-edit-headline "B")
  2469. (buffer-string))))
  2470. ;; Handle tags.
  2471. (equal "* B :tag:"
  2472. (org-test-with-temp-text "* A :tag:"
  2473. (let ((org-tags-column 4)) (org-edit-headline "B"))
  2474. (buffer-string))))
  2475. ;;; Keywords
  2476. (ert-deftest test-org/set-regexps-and-options ()
  2477. "Test `org-set-regexps-and-options' specifications."
  2478. ;; TAGS keyword.
  2479. (should
  2480. (equal '(("A"))
  2481. (let ((org-tag-alist '(("A")))
  2482. (org-tag-persistent-alist nil))
  2483. (org-test-with-temp-text ""
  2484. (org-mode-restart)
  2485. org-current-tag-alist))))
  2486. (should
  2487. (equal '(("B"))
  2488. (let ((org-tag-alist '(("A")))
  2489. (org-tag-persistent-alist nil))
  2490. (org-test-with-temp-text "#+TAGS: B"
  2491. (org-mode-restart)
  2492. org-current-tag-alist))))
  2493. (should
  2494. (equal '(("C") ("B"))
  2495. (let ((org-tag-alist '(("A")))
  2496. (org-tag-persistent-alist '(("C"))))
  2497. (org-test-with-temp-text "#+TAGS: B"
  2498. (org-mode-restart)
  2499. org-current-tag-alist))))
  2500. (should
  2501. (equal '(("B"))
  2502. (let ((org-tag-alist '(("A")))
  2503. (org-tag-persistent-alist '(("C"))))
  2504. (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
  2505. (org-mode-restart)
  2506. org-current-tag-alist))))
  2507. (should
  2508. (equal '(("A" . ?a) ("B") ("C"))
  2509. (let ((org-tag-persistant-alist nil))
  2510. (org-test-with-temp-text "#+TAGS: A(a) B C"
  2511. (org-mode-restart)
  2512. org-current-tag-alist))))
  2513. (should
  2514. (equal '(("A") (:newline) ("B"))
  2515. (let ((org-tag-persistent-alist nil))
  2516. (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
  2517. (org-mode-restart)
  2518. org-current-tag-alist))))
  2519. (should
  2520. (equal '((:startgroup) ("A") ("B") (:endgroup) ("C"))
  2521. (let ((org-tag-persistent-alist nil))
  2522. (org-test-with-temp-text "#+TAGS: { A B } C"
  2523. (org-mode-restart)
  2524. org-current-tag-alist))))
  2525. (should
  2526. (equal '((:startgroup) ("A") (:grouptags) ("B") ("C") (:endgroup))
  2527. (let ((org-tag-persistent-alist nil))
  2528. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2529. (org-mode-restart)
  2530. org-current-tag-alist))))
  2531. (should
  2532. (equal '(("A" "B" "C"))
  2533. (let ((org-tag-persistent-alist nil))
  2534. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2535. (org-mode-restart)
  2536. org-tag-groups-alist))))
  2537. (should
  2538. (equal '((:startgrouptag) ("A") (:grouptags) ("B") ("C") (:endgrouptag))
  2539. (let ((org-tag-persistent-alist nil))
  2540. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2541. (org-mode-restart)
  2542. org-current-tag-alist))))
  2543. (should
  2544. (equal '(("A" "B" "C"))
  2545. (let ((org-tag-persistent-alist nil))
  2546. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2547. (org-mode-restart)
  2548. org-tag-groups-alist))))
  2549. (should-not
  2550. (let ((org-tag-alist '(("A"))))
  2551. (org-test-with-temp-text "#+TAGS:"
  2552. (org-mode-restart)
  2553. org-current-tag-alist)))
  2554. ;; FILETAGS keyword.
  2555. (should
  2556. (equal '("A" "B" "C")
  2557. (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
  2558. (org-mode-restart)
  2559. org-file-tags)))
  2560. ;; PROPERTY keyword. Property names are case-insensitive.
  2561. (should
  2562. (equal "foo=1"
  2563. (org-test-with-temp-text "#+PROPERTY: var foo=1"
  2564. (org-mode-restart)
  2565. (cdr (assoc "var" org-keyword-properties)))))
  2566. (should
  2567. (equal
  2568. "foo=1 bar=2"
  2569. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
  2570. (org-mode-restart)
  2571. (cdr (assoc "var" org-keyword-properties)))))
  2572. (should
  2573. (equal
  2574. "foo=1 bar=2"
  2575. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
  2576. (org-mode-restart)
  2577. (cdr (assoc "var" org-keyword-properties)))))
  2578. ;; ARCHIVE keyword.
  2579. (should
  2580. (equal "%s_done::"
  2581. (org-test-with-temp-text "#+ARCHIVE: %s_done::"
  2582. (org-mode-restart)
  2583. org-archive-location)))
  2584. ;; CATEGORY keyword.
  2585. (should
  2586. (eq 'test
  2587. (org-test-with-temp-text "#+CATEGORY: test"
  2588. (org-mode-restart)
  2589. org-category)))
  2590. (should
  2591. (equal "test"
  2592. (org-test-with-temp-text "#+CATEGORY: test"
  2593. (org-mode-restart)
  2594. (cdr (assoc "CATEGORY" org-keyword-properties)))))
  2595. ;; COLUMNS keyword.
  2596. (should
  2597. (equal "%25ITEM %TAGS %PRIORITY %TODO"
  2598. (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
  2599. (org-mode-restart)
  2600. org-columns-default-format)))
  2601. ;; CONSTANTS keyword. Constants names are case sensitive.
  2602. (should
  2603. (equal '("299792458." "3.14")
  2604. (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
  2605. (org-mode-restart)
  2606. (mapcar
  2607. (lambda (n) (cdr (assoc n org-table-formula-constants-local)))
  2608. '("c" "pi")))))
  2609. (should
  2610. (equal "3.14"
  2611. (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
  2612. (org-mode-restart)
  2613. (cdr (assoc "pi" org-table-formula-constants-local)))))
  2614. (should
  2615. (equal "22/7"
  2616. (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
  2617. (org-mode-restart)
  2618. (cdr (assoc "PI" org-table-formula-constants-local)))))
  2619. ;; LINK keyword.
  2620. (should
  2621. (equal
  2622. '("url1" "url2")
  2623. (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
  2624. (org-mode-restart)
  2625. (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local)))
  2626. '("a" "b")))))
  2627. ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
  2628. (should
  2629. (equal
  2630. '(?X ?Z ?Y)
  2631. (org-test-with-temp-text "#+PRIORITIES: X Z Y"
  2632. (org-mode-restart)
  2633. (list org-priority-highest org-priority-lowest org-priority-default))))
  2634. (should
  2635. (equal
  2636. '(?A ?C ?B)
  2637. (org-test-with-temp-text "#+PRIORITIES: X Z"
  2638. (org-mode-restart)
  2639. (list org-priority-highest org-priority-lowest org-priority-default))))
  2640. ;; STARTUP keyword.
  2641. (should
  2642. (equal '(t t)
  2643. (org-test-with-temp-text "#+STARTUP: fold odd"
  2644. (org-mode-restart)
  2645. (list org-startup-folded org-odd-levels-only))))
  2646. ;; TODO keywords.
  2647. (should
  2648. (equal '(("A" "B") ("C"))
  2649. (org-test-with-temp-text "#+TODO: A B | C"
  2650. (org-mode-restart)
  2651. (list org-not-done-keywords org-done-keywords))))
  2652. (should
  2653. (equal '(("A" "C") ("B" "D"))
  2654. (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
  2655. (org-mode-restart)
  2656. (list org-not-done-keywords org-done-keywords))))
  2657. (should
  2658. (equal '(("A" "B") ("C"))
  2659. (org-test-with-temp-text "#+TYP_TODO: A B | C"
  2660. (org-mode-restart)
  2661. (list org-not-done-keywords org-done-keywords))))
  2662. (should
  2663. (equal '((:startgroup) ("A" . ?a) (:endgroup))
  2664. (org-test-with-temp-text "#+TODO: A(a)"
  2665. (org-mode-restart)
  2666. org-todo-key-alist)))
  2667. (should
  2668. (equal '(("D" note nil) ("C" time nil) ("B" note time))
  2669. (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
  2670. (org-mode-restart)
  2671. org-todo-log-states)))
  2672. ;; Enter SETUPFILE keyword.
  2673. (should
  2674. (equal "1"
  2675. (org-test-with-temp-text
  2676. (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
  2677. (org-mode-restart)
  2678. (cdr (assoc "a" org-keyword-properties))))))
  2679. (ert-deftest test-org/collect-keywords ()
  2680. "Test `org-collect-keywords'."
  2681. (should-not
  2682. (org-test-with-temp-text "#+begin_example\n#+foo: bar\n#+end_example"
  2683. (org-collect-keywords '("FOO")))))
  2684. ;;; Links
  2685. ;;;; Coderefs
  2686. (ert-deftest test-org/coderef ()
  2687. "Test coderef links specifications."
  2688. (should
  2689. (org-test-with-temp-text "
  2690. #+BEGIN_SRC emacs-lisp
  2691. \(+ 1 1) (ref:sc)
  2692. #+END_SRC
  2693. \[[(sc)<point>]]"
  2694. (org-open-at-point)
  2695. (looking-at "(ref:sc)")))
  2696. ;; Find coderef even with alternate label format.
  2697. (should
  2698. (org-test-with-temp-text "
  2699. #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
  2700. \(+ 1 1) {ref:sc}
  2701. #+END_SRC
  2702. \[[(sc)<point>]]"
  2703. (org-open-at-point)
  2704. (looking-at "{ref:sc}"))))
  2705. ;;;; Custom ID
  2706. (ert-deftest test-org/custom-id ()
  2707. "Test custom ID links specifications."
  2708. (should
  2709. (org-test-with-temp-text
  2710. "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2711. (org-open-at-point)
  2712. (looking-at-p "\\* H1")))
  2713. ;; Handle escape characters.
  2714. (should
  2715. (org-test-with-temp-text
  2716. "* H1\n:PROPERTIES:\n:CUSTOM_ID: [%]\n:END:\n* H2\n[[#\\[%\\]<point>]]"
  2717. (org-open-at-point)
  2718. (looking-at-p "\\* H1")))
  2719. ;; Throw an error on false positives.
  2720. (should-error
  2721. (org-test-with-temp-text
  2722. "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2723. (org-open-at-point)
  2724. (looking-at-p "\\* H1"))))
  2725. ;;;; Fuzzy Links
  2726. ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
  2727. ;; a named element (#+name: text) and to headlines (* Text).
  2728. (ert-deftest test-org/fuzzy-links ()
  2729. "Test fuzzy links specifications."
  2730. ;; Fuzzy link goes in priority to a matching target.
  2731. (should
  2732. (org-test-with-temp-text
  2733. "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
  2734. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2735. (looking-at "<<Test>>")))
  2736. ;; Then fuzzy link points to an element with a given name.
  2737. (should
  2738. (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
  2739. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2740. (looking-at "#\\+NAME: Test")))
  2741. ;; A target still lead to a matching headline otherwise.
  2742. (should
  2743. (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
  2744. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2745. (looking-at "\\* Head2")))
  2746. ;; With a leading star in link, enforce heading match.
  2747. (should
  2748. (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
  2749. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2750. (looking-at "\\* Test")))
  2751. ;; With a leading star in link, enforce exact heading match, even
  2752. ;; with `org-link-search-must-match-exact-headline' set to nil.
  2753. (should-error
  2754. (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
  2755. (let ((org-link-search-must-match-exact-headline nil))
  2756. (org-open-at-point))))
  2757. ;; Handle non-nil `org-link-search-must-match-exact-headline'.
  2758. (should
  2759. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
  2760. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2761. (looking-at "\\* Test")))
  2762. (should
  2763. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
  2764. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2765. (looking-at "\\* Test")))
  2766. ;; Heading match should not care about spaces, cookies, TODO
  2767. ;; keywords, priorities, and tags. However, TODO keywords are
  2768. ;; case-sensitive.
  2769. (should
  2770. (let ((first-line
  2771. "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
  2772. (org-test-with-temp-text
  2773. (concat first-line "\nFoo Bar\n<point>[[*Test 1 2]]")
  2774. (let ((org-link-search-must-match-exact-headline nil)
  2775. (org-todo-regexp "TODO"))
  2776. (org-open-at-point))
  2777. (looking-at (regexp-quote first-line)))))
  2778. (should-error
  2779. (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
  2780. (let ((org-link-search-must-match-exact-headline nil)
  2781. (org-todo-regexp "TODO"))
  2782. (org-open-at-point))))
  2783. ;; Heading match should still be exact.
  2784. (should-error
  2785. (org-test-with-temp-text "
  2786. ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
  2787. Foo Bar
  2788. <point>[[*Test 1]]"
  2789. (let ((org-link-search-must-match-exact-headline nil)
  2790. (org-todo-regexp "TODO"))
  2791. (org-open-at-point))))
  2792. (should
  2793. (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
  2794. (let ((org-link-search-must-match-exact-headline nil)
  2795. (org-todo-regexp "TODO"))
  2796. (org-open-at-point))
  2797. (looking-at-p (regexp-quote "** Test 1 2"))))
  2798. ;; Heading match ignores COMMENT keyword.
  2799. (should
  2800. (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
  2801. (org-open-at-point)
  2802. (looking-at "\\* COMMENT Test")))
  2803. (should
  2804. (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
  2805. (org-open-at-point)
  2806. (looking-at "\\* TODO COMMENT Test")))
  2807. ;; Correctly un-escape fuzzy links.
  2808. (should
  2809. (org-test-with-temp-text "* [foo]\n[[*\\[foo\\]][With escaped characters]]"
  2810. (org-open-at-point)
  2811. (bobp)))
  2812. ;; Match search strings containing newline characters, including
  2813. ;; blank lines.
  2814. (should
  2815. (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
  2816. (let ((file (buffer-file-name)))
  2817. (goto-char (point-max))
  2818. (insert (format "[[file:%s::line1 line2]]" file))
  2819. (beginning-of-line)
  2820. (let ((org-link-search-must-match-exact-headline nil))
  2821. (org-open-at-point 0))
  2822. (looking-at-p "line1"))))
  2823. (should
  2824. (org-test-with-temp-text-in-file "Paragraph\n\nline1\n\nline2\n\n"
  2825. (let ((file (buffer-file-name)))
  2826. (goto-char (point-max))
  2827. (insert (format "[[file:%s::line1 line2]]" file))
  2828. (beginning-of-line)
  2829. (let ((org-link-search-must-match-exact-headline nil))
  2830. (org-open-at-point 0))
  2831. (looking-at-p "line1")))))
  2832. ;;;; Open at point
  2833. (ert-deftest test-org/open-at-point/keyword ()
  2834. "Does `org-open-at-point' open link in a keyword line?"
  2835. (should
  2836. (org-test-with-temp-text
  2837. "<<top>>\n#+KEYWORD: <point>[[top]]"
  2838. (org-open-at-point) t))
  2839. (should
  2840. (org-test-with-temp-text
  2841. "* H\n<<top>>\n#+KEYWORD: <point>[[top]]"
  2842. (org-open-at-point) t)))
  2843. (ert-deftest test-org/open-at-point/property ()
  2844. "Does `org-open-at-point' open link in property drawer?"
  2845. (should
  2846. (org-test-with-temp-text
  2847. "* Headline
  2848. :PROPERTIES:
  2849. :URL: <point>[[*Headline]]
  2850. :END:"
  2851. (org-open-at-point) t)))
  2852. (ert-deftest test-org/open-at-point/comment ()
  2853. "Does `org-open-at-point' open link in a commented line?"
  2854. (should
  2855. (org-test-with-temp-text
  2856. "<<top>>\n# <point>[[top]]"
  2857. (org-open-at-point) t))
  2858. (should
  2859. (org-test-with-temp-text
  2860. "* H\n<<top>>\n# <point>[[top]]"
  2861. (org-open-at-point) t)))
  2862. (ert-deftest test-org/open-at-point/inline-image ()
  2863. "Test `org-open-at-point' on nested links."
  2864. (should
  2865. (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
  2866. (org-open-at-point)
  2867. (bobp))))
  2868. (ert-deftest test-org/open-at-point/radio-target ()
  2869. "Test `org-open-at-point' on radio targets."
  2870. (should
  2871. (org-test-with-temp-text "<<<target>>> <point>target"
  2872. (org-update-radio-target-regexp)
  2873. (org-open-at-point)
  2874. (eq (org-element-type (org-element-context)) 'radio-target))))
  2875. (ert-deftest test-org/open-at-point/radio-target-shadowed ()
  2876. "Test `org-open-at-point' on shadowed radio targets."
  2877. (should
  2878. (org-test-with-temp-text
  2879. "<<<target shadowed>>> <<<target>>> <point>target shadowed"
  2880. (org-update-radio-target-regexp)
  2881. (org-open-at-point)
  2882. (string=
  2883. (org-element-property :value
  2884. (org-element-radio-target-parser))
  2885. "target shadowed"))))
  2886. (ert-deftest test-org/open-at-point/tag ()
  2887. "Test `org-open-at-point' on tags."
  2888. (should
  2889. (org-test-with-temp-text "* H :<point>tag:"
  2890. (catch :result
  2891. (cl-letf (((symbol-function 'org-tags-view)
  2892. (lambda (&rest args) (throw :result t))))
  2893. (org-open-at-point)
  2894. nil))))
  2895. (should-not
  2896. (org-test-with-temp-text-in-file "* H<point> :tag:"
  2897. (catch :result
  2898. (cl-letf (((symbol-function 'org-tags-view)
  2899. (lambda (&rest args) (throw :result t))))
  2900. ;; When point isn't on a tag it's going to try other things,
  2901. ;; possibly trying to open attachments which will return an
  2902. ;; error if there isn't an attachment. Suppress that error.
  2903. (ignore-errors
  2904. (org-open-at-point))
  2905. nil)))))
  2906. ;;; Node Properties
  2907. (ert-deftest test-org/accumulated-properties-in-drawers ()
  2908. "Ensure properties accumulate in subtree drawers."
  2909. (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
  2910. (org-babel-next-src-block)
  2911. (should (equal '(2 1) (org-babel-execute-src-block)))))
  2912. (ert-deftest test-org/custom-properties ()
  2913. "Test custom properties specifications."
  2914. ;; Standard test.
  2915. (should
  2916. (let ((org-custom-properties '("FOO")))
  2917. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2918. (org-toggle-custom-properties-visibility)
  2919. (org-invisible-p2))))
  2920. ;; Properties are case-insensitive.
  2921. (should
  2922. (let ((org-custom-properties '("FOO")))
  2923. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
  2924. (org-toggle-custom-properties-visibility)
  2925. (org-invisible-p2))))
  2926. (should
  2927. (let ((org-custom-properties '("foo")))
  2928. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2929. (org-toggle-custom-properties-visibility)
  2930. (org-invisible-p2))))
  2931. ;; Multiple custom properties in the same drawer.
  2932. (should
  2933. (let ((org-custom-properties '("FOO" "BAR")))
  2934. (org-test-with-temp-text
  2935. "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
  2936. (org-fold-reveal)
  2937. (org-toggle-custom-properties-visibility)
  2938. (and (org-invisible-p2)
  2939. (not (progn (forward-line) (org-invisible-p2)))
  2940. (progn (forward-line) (org-invisible-p2))))))
  2941. ;; Hide custom properties with an empty value.
  2942. (should
  2943. (let ((org-custom-properties '("FOO")))
  2944. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
  2945. (org-toggle-custom-properties-visibility)
  2946. (org-invisible-p2))))
  2947. ;; Do not hide fake properties.
  2948. (should-not
  2949. (let ((org-custom-properties '("FOO")))
  2950. (org-test-with-temp-text ":FOO: val\n"
  2951. (org-toggle-custom-properties-visibility)
  2952. (org-invisible-p2))))
  2953. (should-not
  2954. (let ((org-custom-properties '("A")))
  2955. (org-test-with-temp-text
  2956. "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
  2957. (org-fold-reveal)
  2958. (org-toggle-custom-properties-visibility)
  2959. (org-invisible-p2)))))
  2960. ;;; Mark Region
  2961. (ert-deftest test-org/mark-element ()
  2962. "Test `org-mark-element' specifications."
  2963. ;; Mark beginning and end of element.
  2964. (should
  2965. (equal '(t t)
  2966. (org-test-with-temp-text "Para<point>graph"
  2967. (org-mark-element)
  2968. (list (bobp) (= (mark) (point-max))))))
  2969. (should
  2970. (equal '(t t)
  2971. (org-test-with-temp-text "P1\n\nPara<point>graph\n\nP2"
  2972. (org-mark-element)
  2973. (list (looking-at "Paragraph")
  2974. (org-with-point-at (mark) (looking-at "P2"))))))
  2975. ;; Do not set mark past (point-max).
  2976. (should
  2977. (org-test-with-temp-text "Para<point>graph"
  2978. (narrow-to-region 2 6)
  2979. (org-mark-element)
  2980. (= 6 (mark)))))
  2981. (ert-deftest test-org/mark-subtree ()
  2982. "Test `org-mark-subtree' specifications."
  2983. ;; Error when point is before first headline.
  2984. (should-error
  2985. (org-test-with-temp-text "Paragraph\n* Headline\nBody"
  2986. (progn (transient-mark-mode 1)
  2987. (org-mark-subtree))))
  2988. ;; Without argument, mark current subtree.
  2989. (should
  2990. (equal
  2991. '(12 32)
  2992. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  2993. (progn (transient-mark-mode 1)
  2994. (forward-line 2)
  2995. (org-mark-subtree)
  2996. (list (region-beginning) (region-end))))))
  2997. ;; With an argument, move ARG up.
  2998. (should
  2999. (equal
  3000. '(1 32)
  3001. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  3002. (progn (transient-mark-mode 1)
  3003. (forward-line 2)
  3004. (org-mark-subtree 1)
  3005. (list (region-beginning) (region-end))))))
  3006. ;; Do not get fooled by inlinetasks.
  3007. (when (featurep 'org-inlinetask)
  3008. (should
  3009. (= 1
  3010. (org-test-with-temp-text "* Headline\n*************** Task\nContents"
  3011. (progn (transient-mark-mode 1)
  3012. (forward-line 1)
  3013. (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
  3014. (region-beginning)))))))
  3015. ;;; Miscellaneous
  3016. (ert-deftest test-org/sort-entries ()
  3017. "Test `org-sort-entries'."
  3018. ;; Sort alphabetically.
  3019. (should
  3020. (equal "\n* abc\n* def\n* xyz\n"
  3021. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  3022. (org-sort-entries nil ?a)
  3023. (buffer-string))))
  3024. (should
  3025. (equal "\n* xyz\n* def\n* abc\n"
  3026. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  3027. (org-sort-entries nil ?A)
  3028. (buffer-string))))
  3029. (should
  3030. (equal "\n* \n* klm\n* xyz\n"
  3031. (org-test-with-temp-text "\n* xyz\n* \n* klm\n"
  3032. (org-sort-entries nil ?a)
  3033. (buffer-string))))
  3034. ;; Sort numerically.
  3035. (should
  3036. (equal "\n* 1\n* 2\n* 10\n"
  3037. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  3038. (org-sort-entries nil ?n)
  3039. (buffer-string))))
  3040. (should
  3041. (equal "\n* 10\n* 2\n* 1\n"
  3042. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  3043. (org-sort-entries nil ?N)
  3044. (buffer-string))))
  3045. (should
  3046. (equal "\n* \n* 1\n* 2\n"
  3047. (org-test-with-temp-text "\n* 1\n* \n* 2\n"
  3048. (org-sort-entries nil ?n)
  3049. (buffer-string))))
  3050. ;; Sort by custom function.
  3051. (should
  3052. (equal "\n* b\n* aa\n* ccc\n"
  3053. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  3054. (org-sort-entries nil ?f
  3055. (lambda ()
  3056. (length (buffer-substring (point-at-bol)
  3057. (point-at-eol))))
  3058. #'<)
  3059. (buffer-string))))
  3060. (should
  3061. (equal "\n* ccc\n* aa\n* b\n"
  3062. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  3063. (org-sort-entries nil ?F
  3064. (lambda ()
  3065. (length (buffer-substring (point-at-bol)
  3066. (point-at-eol))))
  3067. #'<)
  3068. (buffer-string))))
  3069. ;; Sort by TODO keyword.
  3070. (should
  3071. (equal "\n* TODO h1\n* TODO h3\n* DONE h2\n"
  3072. (org-test-with-temp-text
  3073. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  3074. (org-sort-entries nil ?o)
  3075. (buffer-string))))
  3076. (should
  3077. (equal "\n* DONE h2\n* TODO h1\n* TODO h3\n"
  3078. (org-test-with-temp-text
  3079. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  3080. (org-sort-entries nil ?O)
  3081. (buffer-string))))
  3082. ;; Sort by priority.
  3083. (should
  3084. (equal "\n* [#A] h2\n* [#B] h3\n* [#C] h1\n"
  3085. (org-test-with-temp-text
  3086. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  3087. (org-sort-entries nil ?p)
  3088. (buffer-string))))
  3089. (should
  3090. (equal "\n* [#C] h1\n* [#B] h3\n* [#A] h2\n"
  3091. (org-test-with-temp-text
  3092. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  3093. (org-sort-entries nil ?P)
  3094. (buffer-string))))
  3095. ;; Sort by creation time.
  3096. (should
  3097. (equal "
  3098. * h3
  3099. [2017-05-08 Mon]
  3100. * h2
  3101. [2017-05-09 Tue]
  3102. * h1
  3103. [2018-05-09 Wed]
  3104. "
  3105. (org-test-with-temp-text
  3106. "
  3107. * h1
  3108. [2018-05-09 Wed]
  3109. * h2
  3110. [2017-05-09 Tue]
  3111. * h3
  3112. [2017-05-08 Mon]
  3113. "
  3114. (org-sort-entries nil ?c)
  3115. (buffer-string))))
  3116. ;; Sort by scheduled date.
  3117. (should
  3118. (equal "
  3119. * TODO h4
  3120. SCHEDULED: <2017-05-06 Sat>
  3121. * TODO h3
  3122. SCHEDULED: <2017-05-08 Mon>
  3123. * TODO h2
  3124. DEADLINE: <2017-05-09 Tue>
  3125. * TODO h1
  3126. DEADLINE: <2017-05-07 Sun>
  3127. "
  3128. (org-test-with-temp-text
  3129. "
  3130. * TODO h2
  3131. DEADLINE: <2017-05-09 Tue>
  3132. * TODO h1
  3133. DEADLINE: <2017-05-07 Sun>
  3134. * TODO h3
  3135. SCHEDULED: <2017-05-08 Mon>
  3136. * TODO h4
  3137. SCHEDULED: <2017-05-06 Sat>
  3138. "
  3139. (org-sort-entries nil ?s)
  3140. (buffer-string))))
  3141. ;; Sort by deadline date.
  3142. (should
  3143. (equal "
  3144. * TODO h1
  3145. DEADLINE: <2017-05-07 Sun>
  3146. * TODO h2
  3147. DEADLINE: <2017-05-09 Tue>
  3148. * TODO h3
  3149. SCHEDULED: <2017-05-08 Mon>
  3150. * TODO h4
  3151. SCHEDULED: <2017-05-06 Sat>
  3152. "
  3153. (org-test-with-temp-text
  3154. "
  3155. * TODO h2
  3156. DEADLINE: <2017-05-09 Tue>
  3157. * TODO h1
  3158. DEADLINE: <2017-05-07 Sun>
  3159. * TODO h3
  3160. SCHEDULED: <2017-05-08 Mon>
  3161. * TODO h4
  3162. SCHEDULED: <2017-05-06 Sat>
  3163. "
  3164. (org-sort-entries nil ?d)
  3165. (buffer-string))))
  3166. ;; Sort by any date/time
  3167. (should
  3168. (equal "
  3169. * TODO h4
  3170. SCHEDULED: <2017-05-06 Sat>
  3171. * TODO h1
  3172. DEADLINE: <2017-05-07 Sun>
  3173. * TODO h3
  3174. SCHEDULED: <2017-05-08 Mon>
  3175. * TODO h2
  3176. DEADLINE: <2017-05-09 Tue>
  3177. "
  3178. (org-test-with-temp-text
  3179. "
  3180. * TODO h2
  3181. DEADLINE: <2017-05-09 Tue>
  3182. * TODO h1
  3183. DEADLINE: <2017-05-07 Sun>
  3184. * TODO h3
  3185. SCHEDULED: <2017-05-08 Mon>
  3186. * TODO h4
  3187. SCHEDULED: <2017-05-06 Sat>
  3188. "
  3189. (org-sort-entries nil ?t)
  3190. (buffer-string))))
  3191. ;; Sort by clocking time.
  3192. (should
  3193. (equal "
  3194. * clocked h2
  3195. :LOGBOOK:
  3196. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3197. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  3198. :END:
  3199. * clocked h1
  3200. :LOGBOOK:
  3201. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3202. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  3203. :END:
  3204. "
  3205. (org-test-with-temp-text
  3206. "
  3207. * clocked h1
  3208. :LOGBOOK:
  3209. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3210. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  3211. :END:
  3212. * clocked h2
  3213. :LOGBOOK:
  3214. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3215. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  3216. :END:
  3217. "
  3218. (org-sort-entries nil ?k)
  3219. (buffer-string))))
  3220. ;; Preserve file local variables when sorting.
  3221. (should
  3222. (equal "\n* A\n* B\n# Local Variables:\n# foo: t\n# End:\n"
  3223. (org-test-with-temp-text
  3224. "\n* B\n* A\n# Local Variables:\n# foo: t\n# End:"
  3225. (org-sort-entries nil ?a)
  3226. (buffer-string)))))
  3227. (ert-deftest test-org/string-collate-greaterp ()
  3228. "Test `org-string-collate-greaterp' specifications."
  3229. (should (org-string-collate-greaterp "def" "abc"))
  3230. (should-not (org-string-collate-greaterp "abc" "def")))
  3231. (ert-deftest test-org/file-contents ()
  3232. "Test `org-file-contents' specifications."
  3233. ;; Open files.
  3234. (should
  3235. (string= "#+BIND: variable value
  3236. #+DESCRIPTION: l2
  3237. #+LANGUAGE: en
  3238. #+SELECT_TAGS: b
  3239. #+TITLE: b
  3240. #+PROPERTY: a 1
  3241. " (org-file-contents (expand-file-name "setupfile3.org"
  3242. (concat org-test-dir "examples/")))))
  3243. ;; Throw error when trying to access an invalid file.
  3244. (should-error (org-file-contents "this-file-must-not-exist"))
  3245. ;; Try to access an invalid file, but do not throw an error.
  3246. (should
  3247. (progn (org-file-contents "this-file-must-not-exist" :noerror) t))
  3248. ;; Open URL.
  3249. (should
  3250. (string= "foo"
  3251. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3252. (unwind-protect
  3253. ;; Simulate successful retrieval of a URL.
  3254. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3255. (lambda (&rest_)
  3256. (with-current-buffer buffer
  3257. (insert "HTTP/1.1 200 OK\n\nfoo"))
  3258. buffer)))
  3259. (org-file-contents "http://some-valid-url"))
  3260. (kill-buffer buffer)))))
  3261. ;; Throw error when trying to access an invalid URL.
  3262. (should-error
  3263. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3264. (unwind-protect
  3265. ;; Simulate unsuccessful retrieval of a URL.
  3266. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3267. (lambda (&rest_)
  3268. (with-current-buffer buffer
  3269. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3270. buffer)))
  3271. (org-file-contents "http://this-url-must-not-exist"))
  3272. (kill-buffer buffer))))
  3273. ;; Try to access an invalid URL, but do not throw an error.
  3274. (should-error
  3275. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3276. (unwind-protect
  3277. ;; Simulate unsuccessful retrieval of a URL.
  3278. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3279. (lambda (&rest_)
  3280. (with-current-buffer buffer
  3281. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3282. buffer)))
  3283. (org-file-contents "http://this-url-must-not-exist"))
  3284. (kill-buffer buffer))))
  3285. (should
  3286. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3287. (unwind-protect
  3288. ;; Simulate unsuccessful retrieval of a URL.
  3289. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3290. (lambda (&rest_)
  3291. (with-current-buffer buffer
  3292. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3293. buffer)))
  3294. (org-file-contents "http://this-url-must-not-exist" :noerror))
  3295. (kill-buffer buffer))
  3296. t)))
  3297. ;;; Navigation
  3298. (ert-deftest test-org/next-visible-heading ()
  3299. "Test `org-next-visible-heading' specifications."
  3300. ;; Move to the beginning of the next headline, taking into
  3301. ;; consideration ARG.
  3302. (should
  3303. (org-test-with-temp-text "* H1\n* H2"
  3304. (org-next-visible-heading 1)
  3305. (looking-at "\\* H2")))
  3306. (should
  3307. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3308. (org-next-visible-heading 2)
  3309. (looking-at "\\* H3")))
  3310. ;; Ignore invisible headlines.
  3311. (should
  3312. (org-test-with-temp-text "* H1\n** H2\n* H3"
  3313. (org-cycle)
  3314. (org-next-visible-heading 1)
  3315. (looking-at "\\* H3")))
  3316. ;; Move point between headlines, not on blank lines between.
  3317. (should
  3318. (org-test-with-temp-text "* H1\n** H2\n\n\n\n* H3"
  3319. (let ((org-cycle-separator-lines 1))
  3320. (org-cycle)
  3321. (org-next-visible-heading 1))
  3322. (looking-at "\\* H3")))
  3323. ;; Move at end of buffer when there is no more headline.
  3324. (should
  3325. (org-test-with-temp-text "* H1"
  3326. (org-next-visible-heading 1)
  3327. (eobp)))
  3328. (should
  3329. (org-test-with-temp-text "* H1\n* H2"
  3330. (org-next-visible-heading 2)
  3331. (eobp)))
  3332. ;; With a negative argument, move backwards.
  3333. (should
  3334. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3335. (org-next-visible-heading -1)
  3336. (looking-at "\\* H2")))
  3337. (should
  3338. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3339. (org-next-visible-heading -2)
  3340. (looking-at "\\* H1"))))
  3341. (ert-deftest test-org/previous-visible-heading ()
  3342. "Test `org-previous-visible-heading' specifications."
  3343. ;; Move to the beginning of the next headline, taking into
  3344. ;; consideration ARG.
  3345. (should
  3346. (org-test-with-temp-text "* H1\n<point>* H2"
  3347. (org-previous-visible-heading 1)
  3348. (looking-at "\\* H1")))
  3349. (should
  3350. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3351. (org-previous-visible-heading 2)
  3352. (looking-at "\\* H1")))
  3353. ;; Ignore invisible headlines.
  3354. (should
  3355. (org-test-with-temp-text "* H1\n** H2\n<point>* H3"
  3356. (org-overview)
  3357. (org-previous-visible-heading 1)
  3358. (looking-at "\\* H1")))
  3359. ;; Move point between headlines, not on blank lines between.
  3360. (should
  3361. (org-test-with-temp-text "* H1\n\n\n\n** H2\n<point>* H3"
  3362. (let ((org-cycle-separator-lines 1))
  3363. (org-overview)
  3364. (org-previous-visible-heading 1))
  3365. (looking-at "\\* H1")))
  3366. ;; Move at end of buffer when there is no more headline.
  3367. (should
  3368. (org-test-with-temp-text "* H1"
  3369. (org-previous-visible-heading 1)
  3370. (bobp)))
  3371. (should
  3372. (org-test-with-temp-text "* H1\n* <point>H2"
  3373. (org-previous-visible-heading 2)
  3374. (bobp)))
  3375. ;; Invisible parts may not start at a headline, i.e., when revealing
  3376. ;; parts of the buffer. Handle this.
  3377. (should
  3378. (org-test-with-temp-text "* Main\n** H1\nFoo\n** H2\nBar\n** H3\nBaz"
  3379. (org-overview)
  3380. (search-forward "H1")
  3381. (org-show-context 'minimal)
  3382. (org-cycle)
  3383. (search-forward "H3")
  3384. (org-show-context 'minimal)
  3385. ;; At this point, buffer displays, with point at "|",
  3386. ;;
  3387. ;; * Main
  3388. ;; ** H1
  3389. ;; Foo
  3390. ;; ** H3|
  3391. (org-previous-visible-heading 1)
  3392. (looking-at "\\*+ H1"))))
  3393. (ert-deftest test-org/forward-heading-same-level ()
  3394. "Test `org-forward-heading-same-level' specifications."
  3395. ;; Test navigation at top level, forward and backward.
  3396. (should
  3397. (equal "* H2"
  3398. (org-test-with-temp-text "* H1\n* H2"
  3399. (org-forward-heading-same-level 1)
  3400. (buffer-substring-no-properties (point) (line-end-position)))))
  3401. (should
  3402. (equal "* H1"
  3403. (org-test-with-temp-text "* H1\n<point>* H2"
  3404. (org-forward-heading-same-level -1)
  3405. (buffer-substring-no-properties (point) (line-end-position)))))
  3406. ;; Test navigation in a sub-tree, forward and backward.
  3407. (should
  3408. (equal "* H2"
  3409. (org-test-with-temp-text "* H1\n** H11\n** H12\n* H2"
  3410. (org-forward-heading-same-level 1)
  3411. (buffer-substring-no-properties (point) (line-end-position)))))
  3412. (should
  3413. (equal "* H1"
  3414. (org-test-with-temp-text "* H1\n** H11\n** H12\n<point>* H2"
  3415. (org-forward-heading-same-level -1)
  3416. (buffer-substring-no-properties (point) (line-end-position)))))
  3417. ;; Stop at first or last sub-heading.
  3418. (should-not
  3419. (equal "* H2"
  3420. (org-test-with-temp-text "* H1\n** H11\n<point>** H12\n* H2"
  3421. (org-forward-heading-same-level 1)
  3422. (buffer-substring-no-properties (point) (line-end-position)))))
  3423. (should-not
  3424. (equal "* H2"
  3425. (org-test-with-temp-text "* H1\n<point>** H11\n** H12\n* H2"
  3426. (org-forward-heading-same-level -1)
  3427. (buffer-substring-no-properties (point) (line-end-position)))))
  3428. ;; Allow multiple moves.
  3429. (should
  3430. (equal "* H3"
  3431. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3432. (org-forward-heading-same-level 2)
  3433. (buffer-substring-no-properties (point) (line-end-position)))))
  3434. (should
  3435. (equal "* H1"
  3436. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3437. (org-forward-heading-same-level -2)
  3438. (buffer-substring-no-properties (point) (line-end-position)))))
  3439. ;; Ignore spurious moves when first (or last) sibling is reached.
  3440. (should
  3441. (equal "** H3"
  3442. (org-test-with-temp-text "* First\n<point>** H1\n** H2\n** H3\n* Last"
  3443. (org-forward-heading-same-level 100)
  3444. (buffer-substring-no-properties (point) (line-end-position)))))
  3445. (should
  3446. (equal "** H1"
  3447. (org-test-with-temp-text "* First\n** H1\n** H2\n<point>** H3\n* Last"
  3448. (org-forward-heading-same-level -100)
  3449. (buffer-substring-no-properties (point) (line-end-position))))))
  3450. (ert-deftest test-org/end-of-meta-data ()
  3451. "Test `org-end-of-meta-data' specifications."
  3452. ;; Skip planning line.
  3453. (should
  3454. (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
  3455. (org-end-of-meta-data)
  3456. (eobp)))
  3457. ;; Skip properties drawer.
  3458. (should
  3459. (org-test-with-temp-text
  3460. "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
  3461. (org-end-of-meta-data)
  3462. (eobp)))
  3463. ;; Skip both.
  3464. (should
  3465. (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
  3466. (org-end-of-meta-data)
  3467. (eobp)))
  3468. ;; Nothing to skip, go to first line.
  3469. (should
  3470. (org-test-with-temp-text "* Headline\nContents"
  3471. (org-end-of-meta-data)
  3472. (looking-at "Contents")))
  3473. ;; With option argument, skip empty lines, regular drawers and
  3474. ;; clocking lines.
  3475. (should
  3476. (org-test-with-temp-text "* Headline\n\nContents"
  3477. (org-end-of-meta-data t)
  3478. (looking-at "Contents")))
  3479. (should
  3480. (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
  3481. (org-end-of-meta-data t)
  3482. (looking-at "Contents")))
  3483. (should
  3484. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
  3485. (org-end-of-meta-data t)
  3486. (looking-at "Contents")))
  3487. ;; Special case: do not skip incomplete drawers.
  3488. (should
  3489. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
  3490. (org-end-of-meta-data t)
  3491. (looking-at ":LOGBOOK:")))
  3492. ;; Special case: Be careful about consecutive headlines.
  3493. (should-not
  3494. (org-test-with-temp-text "* H1\n*H2\nContents"
  3495. (org-end-of-meta-data t)
  3496. (looking-at "Contents"))))
  3497. (ert-deftest test-org/shiftright-heading ()
  3498. "Test `org-shiftright' on headings."
  3499. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  3500. (should
  3501. (equal "* TODO a1\n** a2\n* DONE b1\n"
  3502. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3503. (org-shiftright)
  3504. (buffer-string))))
  3505. (should
  3506. (equal "* TODO a1\n** TODO a2\n* b1\n"
  3507. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3508. (let ((org-loop-over-headlines-in-active-region t))
  3509. (transient-mark-mode 1)
  3510. (push-mark (point) t t)
  3511. (search-forward "* DONE b1")
  3512. (org-shiftright))
  3513. (buffer-string))))
  3514. (should
  3515. (equal "* TODO a1\n** a2\n* b1\n"
  3516. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3517. (let ((org-loop-over-headlines-in-active-region 'start-level))
  3518. (transient-mark-mode 1)
  3519. (push-mark (point) t t)
  3520. (search-forward "* DONE b1")
  3521. (org-shiftright))
  3522. (buffer-string))))))
  3523. (ert-deftest test-org/beginning-of-line ()
  3524. "Test `org-beginning-of-line' specifications."
  3525. ;; Move to beginning of line. If current line in invisible, move to
  3526. ;; beginning of visible line instead.
  3527. (should
  3528. (org-test-with-temp-text "Some text\nSome other text<point>"
  3529. (org-beginning-of-line)
  3530. (bolp)))
  3531. (should
  3532. (org-test-with-temp-text "* H1\n** H2<point>"
  3533. (org-overview)
  3534. (org-beginning-of-line)
  3535. (= (line-beginning-position) 1)))
  3536. ;; With `visual-line-mode' active, move to beginning of visual line.
  3537. (should-not
  3538. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3539. (visual-line-mode)
  3540. (dotimes (i 1000) (insert "very "))
  3541. (org-beginning-of-line)
  3542. (bolp)))
  3543. ;; In a wide headline, with `visual-line-mode', prefer going to the
  3544. ;; beginning of a visual line than to the logical beginning of line,
  3545. ;; even if special movement is active.
  3546. (should-not
  3547. (org-test-with-temp-text "* A <point>long headline"
  3548. (visual-line-mode)
  3549. (dotimes (i 1000) (insert "very "))
  3550. (goto-char (point-max))
  3551. (org-beginning-of-line)
  3552. (bobp)))
  3553. (should-not
  3554. (org-test-with-temp-text "* A <point>long headline"
  3555. (visual-line-mode)
  3556. (dotimes (i 1000) (insert "very "))
  3557. (goto-char (point-max))
  3558. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line))
  3559. (bobp)))
  3560. ;; At an headline with special movement, first move at beginning of
  3561. ;; title, then at the beginning of line, rinse, repeat.
  3562. (should
  3563. (org-test-with-temp-text "* TODO Headline<point>"
  3564. (let ((org-special-ctrl-a/e t))
  3565. (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
  3566. (progn (org-beginning-of-line) (bolp))
  3567. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3568. (should
  3569. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3570. (let ((org-special-ctrl-a/e t))
  3571. (org-beginning-of-line)
  3572. (looking-at "Headline"))))
  3573. (should
  3574. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3575. (let ((org-special-ctrl-a/e '(t . nil)))
  3576. (org-beginning-of-line)
  3577. (looking-at "Headline"))))
  3578. (should-not
  3579. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3580. (let ((org-special-ctrl-a/e '(nil . nil)))
  3581. (org-beginning-of-line)
  3582. (looking-at "Headline"))))
  3583. ;; At an headline with reversed movement, first move to beginning of
  3584. ;; line, then to the beginning of title.
  3585. (should
  3586. (org-test-with-temp-text "* TODO Headline<point>"
  3587. (let ((org-special-ctrl-a/e 'reversed)
  3588. (this-command last-command))
  3589. (and (progn (org-beginning-of-line) (bolp))
  3590. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3591. (should
  3592. (org-test-with-temp-text "* TODO Headline<point>"
  3593. (let ((org-special-ctrl-a/e '(reversed . nil))
  3594. (this-command last-command))
  3595. (and (progn (org-beginning-of-line) (bolp))
  3596. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3597. (should-not
  3598. (org-test-with-temp-text "* TODO Headline<point>"
  3599. (let ((org-special-ctrl-a/e '(t . nil))
  3600. (this-command last-command))
  3601. (and (progn (org-beginning-of-line) (bolp))
  3602. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3603. ;; At an item with special movement, first move after to beginning
  3604. ;; of title, then to the beginning of line, rinse, repeat.
  3605. (should
  3606. (org-test-with-temp-text "- [ ] Item<point>"
  3607. (let ((org-special-ctrl-a/e t))
  3608. (and (progn (org-beginning-of-line) (looking-at-p "Item"))
  3609. (progn (org-beginning-of-line) (bolp))
  3610. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3611. ;; At an item with reversed movement, first move to beginning of
  3612. ;; line, then to the beginning of title.
  3613. (should
  3614. (org-test-with-temp-text "- [X] Item<point>"
  3615. (let ((org-special-ctrl-a/e 'reversed)
  3616. (this-command last-command))
  3617. (and (progn (org-beginning-of-line) (bolp))
  3618. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3619. ;; Leave point before invisible characters at column 0.
  3620. (should
  3621. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3622. (let ((org-special-ctrl-a/e nil))
  3623. (org-beginning-of-line)
  3624. (bolp))))
  3625. (should
  3626. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3627. (let ((org-special-ctrl-a/e t))
  3628. (org-beginning-of-line)
  3629. (bolp))))
  3630. (should
  3631. (org-test-with-temp-text "[[http<point>://orgmode.org]]"
  3632. (visual-line-mode)
  3633. (org-beginning-of-line)
  3634. (bolp)))
  3635. ;; Special case: Do not error when the buffer contains only a single
  3636. ;; asterisk.
  3637. (should
  3638. (org-test-with-temp-text "*<point>"
  3639. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line) t)))
  3640. (should
  3641. (org-test-with-temp-text "*<point>"
  3642. (let ((org-special-ctrl-a/e nil)) (org-beginning-of-line) t))))
  3643. (ert-deftest test-org/end-of-line ()
  3644. "Test `org-end-of-line' specifications."
  3645. ;; Standard test.
  3646. (should
  3647. (org-test-with-temp-text "Some text\nSome other text"
  3648. (org-end-of-line)
  3649. (eolp)))
  3650. ;; With `visual-line-mode' active, move to end of visible line.
  3651. ;; However, never go past ellipsis.
  3652. (should-not
  3653. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3654. (visual-line-mode)
  3655. (dotimes (i 1000) (insert "very "))
  3656. (goto-char (point-min))
  3657. (org-end-of-line)
  3658. (eolp)))
  3659. (should-not
  3660. (org-test-with-temp-text "* A short headline\nSome contents"
  3661. (visual-line-mode)
  3662. (org-overview)
  3663. (org-end-of-line)
  3664. (eobp)))
  3665. ;; In a wide headline, with `visual-line-mode', prefer going to end
  3666. ;; of visible line if tags, or end of line, are farther.
  3667. (should-not
  3668. (org-test-with-temp-text "* A <point>long headline"
  3669. (visual-line-mode)
  3670. (dotimes (i 1000) (insert "very "))
  3671. (goto-char (point-min))
  3672. (org-end-of-line)
  3673. (eolp)))
  3674. (should-not
  3675. (org-test-with-temp-text "* A <point>long headline :tag:"
  3676. (visual-line-mode)
  3677. (dotimes (i 1000) (insert "very "))
  3678. (goto-char (point-min))
  3679. (org-end-of-line)
  3680. (eolp)))
  3681. ;; At an headline without special movement, go to end of line.
  3682. ;; However, never go past ellipsis.
  3683. (should
  3684. (org-test-with-temp-text "* Headline2b :tag:\n"
  3685. (let ((org-special-ctrl-a/e nil))
  3686. (and (progn (org-end-of-line) (eolp))
  3687. (progn (org-end-of-line) (eolp))))))
  3688. (should
  3689. (org-test-with-temp-text "* Headline2b :tag:\n"
  3690. (let ((org-special-ctrl-a/e '(t . nil)))
  3691. (and (progn (org-end-of-line) (eolp))
  3692. (progn (org-end-of-line) (eolp))))))
  3693. (should
  3694. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3695. (org-overview)
  3696. (let ((org-special-ctrl-a/e nil))
  3697. (org-end-of-line)
  3698. (= 1 (line-beginning-position)))))
  3699. ;; At an headline with special movement, first move before tags,
  3700. ;; then at the end of line, rinse, repeat. However, never go past
  3701. ;; ellipsis.
  3702. (should
  3703. (org-test-with-temp-text "* Headline1 :tag:\n"
  3704. (let ((org-special-ctrl-a/e t))
  3705. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3706. (progn (org-end-of-line) (eolp))
  3707. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3708. (should
  3709. (org-test-with-temp-text "* Headline1 :tag:\n"
  3710. (let ((org-special-ctrl-a/e '(nil . t)))
  3711. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3712. (progn (org-end-of-line) (eolp))
  3713. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3714. (should-not
  3715. (org-test-with-temp-text "* Headline1 :tag:\n"
  3716. (let ((org-special-ctrl-a/e '(nil . nil)))
  3717. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3718. (progn (org-end-of-line) (eolp))
  3719. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3720. (should
  3721. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3722. (org-overview)
  3723. (let ((org-special-ctrl-a/e t))
  3724. (org-end-of-line)
  3725. (org-end-of-line)
  3726. (= 1 (line-beginning-position)))))
  3727. ;; At an headline, with reversed movement, first go to end of line,
  3728. ;; then before tags. However, never go past ellipsis.
  3729. (should
  3730. (org-test-with-temp-text "* Headline3 :tag:\n"
  3731. (let ((org-special-ctrl-a/e 'reversed)
  3732. (this-command last-command))
  3733. (and (progn (org-end-of-line) (eolp))
  3734. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3735. (should
  3736. (org-test-with-temp-text "* Headline3 :tag:\n"
  3737. (let ((org-special-ctrl-a/e '(nil . reversed))
  3738. (this-command last-command))
  3739. (and (progn (org-end-of-line) (eolp))
  3740. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3741. (should-not
  3742. (org-test-with-temp-text "* Headline3 :tag:\n"
  3743. (let ((org-special-ctrl-a/e '(nil . t))
  3744. (this-command last-command))
  3745. (and (progn (org-end-of-line) (eolp))
  3746. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3747. (should
  3748. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3749. (org-overview)
  3750. (let ((org-special-ctrl-a/e 'reversed))
  3751. (org-end-of-line)
  3752. (= 1 (line-beginning-position)))))
  3753. ;; At a block without hidden contents.
  3754. (should
  3755. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3756. (progn (org-end-of-line) (eolp))))
  3757. ;; At a block with hidden contents.
  3758. (should-not
  3759. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3760. (let ((org-special-ctrl-a/e t))
  3761. (org-fold-hide-block-toggle)
  3762. (org-end-of-line)
  3763. (eobp))))
  3764. ;; Get past invisible characters at the end of line.
  3765. (should
  3766. (org-test-with-temp-text "[[https://orgmode.org]]"
  3767. (org-end-of-line)
  3768. (eolp))))
  3769. (ert-deftest test-org/open-line ()
  3770. "Test `org-open-line' specifications."
  3771. ;; Call `open-line' outside of tables.
  3772. (should
  3773. (equal "\nText"
  3774. (org-test-with-temp-text "Text"
  3775. (org-open-line 1)
  3776. (buffer-string))))
  3777. ;; At a table, create a row above.
  3778. (should
  3779. (equal "\n| |\n| a |"
  3780. (org-test-with-temp-text "\n<point>| a |"
  3781. (org-open-line 1)
  3782. (buffer-string))))
  3783. ;; At the very first character of the buffer, also call `open-line'.
  3784. (should
  3785. (equal "\n| a |"
  3786. (org-test-with-temp-text "| a |"
  3787. (org-open-line 1)
  3788. (buffer-string))))
  3789. ;; Narrowing does not count.
  3790. (should
  3791. (equal "Text\n| |\n| a |"
  3792. (org-test-with-temp-text "Text\n<point>| a |"
  3793. (narrow-to-region (point) (point-max))
  3794. (org-open-line 1)
  3795. (widen)
  3796. (buffer-string)))))
  3797. (ert-deftest test-org/forward-sentence ()
  3798. "Test `org-forward-sentence' specifications."
  3799. ;; At the end of a table cell, move to the end of the next one.
  3800. (should
  3801. (org-test-with-temp-text "| a<point> | b |"
  3802. (org-forward-sentence)
  3803. (looking-at " |$")))
  3804. ;; Elsewhere in a cell, move to its end.
  3805. (should
  3806. (org-test-with-temp-text "| a<point>c | b |"
  3807. (org-forward-sentence)
  3808. (looking-at " | b |$")))
  3809. ;; Otherwise, simply call `forward-sentence'.
  3810. (should
  3811. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3812. (org-forward-sentence)
  3813. (looking-at " Sentence 2.")))
  3814. (should
  3815. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3816. (org-forward-sentence)
  3817. (org-forward-sentence)
  3818. (eobp)))
  3819. ;; At the end of an element, jump to the next one, without stopping
  3820. ;; on blank lines in-between.
  3821. (should
  3822. (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
  3823. (org-forward-sentence)
  3824. (eobp)))
  3825. ;; Headlines are considered to be sentences by themselves, even if
  3826. ;; they do not end with a full stop.
  3827. (should
  3828. (equal
  3829. "* Headline"
  3830. (org-test-with-temp-text "* <point>Headline\nSentence."
  3831. (org-forward-sentence)
  3832. (buffer-substring-no-properties (line-beginning-position) (point)))))
  3833. (should
  3834. (org-test-with-temp-text "* Headline<point>\nSentence."
  3835. (org-forward-sentence)
  3836. (eobp)))
  3837. (should
  3838. (org-test-with-temp-text "Sentence.<point>\n\n* Headline\n\nSentence 2."
  3839. (org-forward-sentence)
  3840. (and (org-at-heading-p) (eolp)))))
  3841. (ert-deftest test-org/backward-sentence ()
  3842. "Test `org-backward-sentence' specifications."
  3843. ;; At the beginning of a table cell, move to the beginning of the
  3844. ;; previous one.
  3845. (should
  3846. (org-test-with-temp-text "| a | <point>b |"
  3847. (org-backward-sentence)
  3848. (looking-at "a | b |$")))
  3849. ;; Elsewhere in a cell, move to its beginning.
  3850. (should
  3851. (org-test-with-temp-text "| a | b<point>c |"
  3852. (org-backward-sentence)
  3853. (looking-at "bc |$")))
  3854. ;; Otherwise, simply call `backward-sentence'.
  3855. (should
  3856. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3857. (org-backward-sentence)
  3858. (looking-at "Sentence 2.")))
  3859. (should
  3860. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3861. (org-backward-sentence)
  3862. (org-backward-sentence)
  3863. (bobp)))
  3864. ;; Make sure to hit the beginning of a sentence on the same line as
  3865. ;; an item.
  3866. (should
  3867. (org-test-with-temp-text "- Line 1\n line <point>2."
  3868. (org-backward-sentence)
  3869. (looking-at "Line 1"))))
  3870. (ert-deftest test-org/forward-paragraph ()
  3871. "Test `org-forward-paragraph' specifications."
  3872. ;; At end of buffer, do not return an error.
  3873. (should
  3874. (org-test-with-temp-text "Paragraph"
  3875. (goto-char (point-max))
  3876. (org-forward-paragraph)
  3877. t))
  3878. ;; Standard test.
  3879. (should
  3880. (= 2
  3881. (org-test-with-temp-text "P1\n\nP2"
  3882. (org-forward-paragraph)
  3883. (org-current-line))))
  3884. (should
  3885. (= 2
  3886. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  3887. (org-forward-paragraph)
  3888. (org-current-line))))
  3889. ;; Enter greater elements.
  3890. (should
  3891. (= 2
  3892. (org-test-with-temp-text "#+begin_center\nP1\n#+end_center\nP2"
  3893. (org-forward-paragraph)
  3894. (org-current-line))))
  3895. ;; Do not enter elements with invisible contents.
  3896. (should
  3897. (= 4
  3898. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  3899. (org-cycle)
  3900. (org-forward-paragraph)
  3901. (org-current-line))))
  3902. (should
  3903. (= 6
  3904. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\nP3"
  3905. (org-fold-hide-block-toggle)
  3906. (org-forward-paragraph)
  3907. (org-current-line))))
  3908. ;; On an item or a footnote definition, move past the first element
  3909. ;; inside, if any.
  3910. (should
  3911. (= 2
  3912. (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
  3913. (org-forward-paragraph)
  3914. (org-current-line))))
  3915. (should
  3916. (= 2
  3917. (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
  3918. (org-forward-paragraph)
  3919. (org-current-line))))
  3920. ;; On a table (resp. a property drawer) do not move through table
  3921. ;; rows (resp. node properties).
  3922. (should
  3923. (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
  3924. (org-forward-paragraph)
  3925. (looking-at "Paragraph")))
  3926. (should
  3927. (org-test-with-temp-text
  3928. "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
  3929. (org-forward-paragraph)
  3930. (looking-at "Paragraph")))
  3931. ;; Skip consecutive keywords, clocks and diary S-exps.
  3932. (should
  3933. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n"
  3934. (org-forward-paragraph)
  3935. (eobp)))
  3936. (should
  3937. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n"
  3938. (org-forward-paragraph)
  3939. (eobp)))
  3940. (should
  3941. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n"
  3942. (org-forward-paragraph)
  3943. (eobp)))
  3944. (should-not
  3945. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n"
  3946. (org-forward-paragraph)
  3947. (eobp)))
  3948. (should-not
  3949. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n"
  3950. (org-forward-paragraph)
  3951. (eobp)))
  3952. ;; In a plain list with one item every line, skip the whole list,
  3953. ;; even with point in the middle of the list.
  3954. (should
  3955. (org-test-with-temp-text "- A\n - B\n- C\n"
  3956. (org-forward-paragraph)
  3957. (eobp)))
  3958. (should
  3959. (org-test-with-temp-text "- A\n - <point>B\n- C\n"
  3960. (org-forward-paragraph)
  3961. (eobp)))
  3962. ;; On a comment, verse or source block, stop at "contents"
  3963. ;; boundaries and blank lines.
  3964. (should
  3965. (= 2
  3966. (org-test-with-temp-text "#+begin_src emacs-lisp\nL1\n\nL2\n#+end_src"
  3967. (org-forward-paragraph)
  3968. (org-current-line))))
  3969. (should
  3970. (= 3
  3971. (org-test-with-temp-text "#+begin_verse\n<point>L1\n\nL2\n#+end_verse"
  3972. (org-forward-paragraph)
  3973. (org-current-line))))
  3974. (should
  3975. (= 5
  3976. (org-test-with-temp-text "#+begin_comment\nL1\n\n<point>L2\n#+end_comment"
  3977. (org-forward-paragraph)
  3978. (org-current-line))))
  3979. ;; Being on an affiliated keyword shouldn't make any difference.
  3980. (should
  3981. (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
  3982. (org-forward-paragraph)
  3983. (eobp))))
  3984. (ert-deftest test-org/backward-paragraph ()
  3985. "Test `org-backward-paragraph' specifications."
  3986. ;; Do not error at beginning of buffer.
  3987. (should
  3988. (org-test-with-temp-text "Paragraph"
  3989. (org-backward-paragraph)
  3990. t))
  3991. ;; At blank lines at the very beginning of a buffer, move to
  3992. ;; point-min.
  3993. (should
  3994. (org-test-with-temp-text "\n\n<point>\n\nParagraph"
  3995. (org-backward-paragraph)
  3996. (bobp)))
  3997. ;; Regular test.
  3998. (should
  3999. (= 2
  4000. (org-test-with-temp-text "P1\n\nP2<point>"
  4001. (org-backward-paragraph)
  4002. (org-current-line))))
  4003. (should
  4004. (= 4
  4005. (org-test-with-temp-text "P1\n\nP2\n\nP3<point>"
  4006. (org-backward-paragraph)
  4007. (org-current-line))))
  4008. ;; Try to move on the line above current element.
  4009. (should
  4010. (= 2
  4011. (org-test-with-temp-text "\n\n<point>Paragraph"
  4012. (org-backward-paragraph)
  4013. (org-current-line))))
  4014. ;; Do not leave point in an invisible area.
  4015. (should
  4016. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  4017. (org-cycle)
  4018. (goto-char (point-max))
  4019. (beginning-of-line)
  4020. (org-backward-paragraph)
  4021. (bobp)))
  4022. (should
  4023. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\n"
  4024. (org-fold-hide-block-toggle)
  4025. (goto-char (point-max))
  4026. (org-backward-paragraph)
  4027. (bobp)))
  4028. ;; On the first element in an item or a footnote definition, jump
  4029. ;; before the footnote or the item.
  4030. (should
  4031. (org-test-with-temp-text "- line1<point>"
  4032. (org-backward-paragraph)
  4033. (bobp)))
  4034. (should
  4035. (org-test-with-temp-text "[fn:1] line1n<point>"
  4036. (org-backward-paragraph)
  4037. (bobp)))
  4038. ;; On the second element in an item or a footnote definition, jump
  4039. ;; to item or the definition.
  4040. (should
  4041. (= 2
  4042. (org-test-with-temp-text "- line1\n\n<point> line2"
  4043. (org-backward-paragraph)
  4044. (org-current-line))))
  4045. (should
  4046. (= 2
  4047. (org-test-with-temp-text "[fn:1] line1\n\n<point> line2"
  4048. (org-backward-paragraph)
  4049. (org-current-line))))
  4050. ;; On a table (resp. a property drawer), ignore table rows
  4051. ;; (resp. node properties).
  4052. (should
  4053. (org-test-with-temp-text "| a | b |\n| c | d |\n<point>P1"
  4054. (org-backward-paragraph)
  4055. (bobp)))
  4056. (should
  4057. (= 2
  4058. (org-test-with-temp-text
  4059. "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
  4060. (org-backward-paragraph)
  4061. (org-current-line))))
  4062. ;; In a plain list with one item every line, skip the whole list,
  4063. ;; even with point in the middle of the list.
  4064. (should
  4065. (org-test-with-temp-text "- A\n - B\n- C\n<point>"
  4066. (org-backward-paragraph)
  4067. (bobp)))
  4068. (should
  4069. (org-test-with-temp-text "- A\n - B\n- <point>C\n"
  4070. (org-backward-paragraph)
  4071. (bobp)))
  4072. ;; Skip consecutive keywords, clocks and diary S-exps.
  4073. (should
  4074. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n<point>"
  4075. (org-backward-paragraph)
  4076. (bobp)))
  4077. (should
  4078. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n<point>"
  4079. (org-backward-paragraph)
  4080. (bobp)))
  4081. (should
  4082. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n<point>"
  4083. (org-backward-paragraph)
  4084. (bobp)))
  4085. (should-not
  4086. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n<point>"
  4087. (org-backward-paragraph)
  4088. (bobp)))
  4089. (should-not
  4090. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n<point>"
  4091. (org-backward-paragraph)
  4092. (bobp)))
  4093. ;; On a comment, example, source and verse blocks, stop at blank
  4094. ;; lines.
  4095. (should
  4096. (= 1
  4097. (org-test-with-temp-text
  4098. "#+begin_comment\n<point>L1\n\nL2\n\nL3\n#+end_comment"
  4099. (org-backward-paragraph)
  4100. (org-current-line))))
  4101. (should
  4102. (= 2
  4103. (org-test-with-temp-text
  4104. "#+begin_verse\nL1\n\n<point>L2\n\nL3\n#+end_verse"
  4105. (org-backward-paragraph)
  4106. (org-current-line))))
  4107. (should
  4108. (= 3
  4109. (org-test-with-temp-text
  4110. "#+begin_src emacs-lisp\nL1\n\nL2\n\n<point>L3\n#+end_src"
  4111. (org-backward-paragraph)
  4112. (org-current-line))))
  4113. ;; When called from the opening line itself, however, move to
  4114. ;; beginning of block.
  4115. (should
  4116. (org-test-with-temp-text "#+begin_<point>example\nL1\n#+end_example"
  4117. (org-backward-paragraph)
  4118. (bobp)))
  4119. ;; On an empty heading, move above it.
  4120. (should
  4121. (org-test-with-temp-text "\n* <point>"
  4122. (org-backward-paragraph)
  4123. (bobp)))
  4124. (should
  4125. (org-test-with-temp-text "\n* \n<point>"
  4126. (org-backward-paragraph)
  4127. (bobp))))
  4128. (ert-deftest test-org/forward-element ()
  4129. "Test `org-forward-element' specifications."
  4130. ;; 1. At EOB: should error.
  4131. (org-test-with-temp-text "Some text\n"
  4132. (goto-char (point-max))
  4133. (should-error (org-forward-element)))
  4134. ;; 2. Standard move: expected to ignore blank lines.
  4135. (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
  4136. (org-forward-element)
  4137. (should (looking-at (regexp-quote "Second paragraph."))))
  4138. ;; 3. Headline tests.
  4139. (org-test-with-temp-text "
  4140. * Head 1
  4141. ** Head 1.1
  4142. *** Head 1.1.1
  4143. ** Head 1.2"
  4144. ;; 3.1. At an headline beginning: move to next headline at the
  4145. ;; same level.
  4146. (goto-line 3)
  4147. (org-forward-element)
  4148. (should (looking-at (regexp-quote "** Head 1.2")))
  4149. ;; 3.2. At an headline beginning: move to parent headline if no
  4150. ;; headline at the same level.
  4151. (goto-line 3)
  4152. (org-forward-element)
  4153. (should (looking-at (regexp-quote "** Head 1.2"))))
  4154. ;; 4. Greater element tests.
  4155. (org-test-with-temp-text
  4156. "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
  4157. ;; 4.1. At a greater element: expected to skip contents.
  4158. (org-forward-element)
  4159. (should (looking-at (regexp-quote "Outside.")))
  4160. ;; 4.2. At the end of greater element contents: expected to skip
  4161. ;; to the end of the greater element.
  4162. (goto-line 2)
  4163. (org-forward-element)
  4164. (should (looking-at (regexp-quote "Outside."))))
  4165. ;; 5. List tests.
  4166. (org-test-with-temp-text "
  4167. - item1
  4168. - sub1
  4169. - sub2
  4170. - sub3
  4171. Inner paragraph.
  4172. - item2
  4173. Outside."
  4174. ;; 5.1. At list top point: expected to move to the element after
  4175. ;; the list.
  4176. (goto-line 2)
  4177. (org-forward-element)
  4178. (should (looking-at (regexp-quote "Outside.")))
  4179. ;; 5.2. Special case: at the first line of a sub-list, but not at
  4180. ;; beginning of line, move to next item.
  4181. (goto-line 2)
  4182. (forward-char)
  4183. (org-forward-element)
  4184. (should (looking-at "- item2"))
  4185. (goto-line 4)
  4186. (forward-char)
  4187. (org-forward-element)
  4188. (should (looking-at " - sub2"))
  4189. ;; 5.3 At sub-list beginning: expected to move after the sub-list.
  4190. (goto-line 4)
  4191. (org-forward-element)
  4192. (should (looking-at (regexp-quote " Inner paragraph.")))
  4193. ;; 5.4. At sub-list end: expected to move outside the sub-list.
  4194. (goto-line 8)
  4195. (org-forward-element)
  4196. (should (looking-at (regexp-quote " Inner paragraph.")))
  4197. ;; 5.5. At an item: expected to move to next item, if any.
  4198. (goto-line 6)
  4199. (org-forward-element)
  4200. (should (looking-at " - sub3"))))
  4201. (ert-deftest test-org/backward-element ()
  4202. "Test `org-backward-element' specifications."
  4203. ;; 1. Should error at BOB.
  4204. (org-test-with-temp-text " \nParagraph."
  4205. (should-error (org-backward-element)))
  4206. ;; 2. Should move at BOB when called on the first element in buffer.
  4207. (should
  4208. (org-test-with-temp-text "\n#+TITLE: test"
  4209. (progn (forward-line)
  4210. (org-backward-element)
  4211. (bobp))))
  4212. ;; 3. Not at the beginning of an element: move at its beginning.
  4213. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  4214. (goto-line 3)
  4215. (end-of-line)
  4216. (org-backward-element)
  4217. (should (looking-at (regexp-quote "Paragraph2."))))
  4218. ;; 4. Headline tests.
  4219. (org-test-with-temp-text "
  4220. * Head 1
  4221. ** Head 1.1
  4222. *** Head 1.1.1
  4223. ** Head 1.2"
  4224. ;; 4.1. At an headline beginning: move to previous headline at the
  4225. ;; same level.
  4226. (goto-line 5)
  4227. (org-backward-element)
  4228. (should (looking-at (regexp-quote "** Head 1.1")))
  4229. ;; 4.2. At an headline beginning: move to parent headline if no
  4230. ;; headline at the same level.
  4231. (goto-line 3)
  4232. (org-backward-element)
  4233. (should (looking-at (regexp-quote "* Head 1")))
  4234. ;; 4.3. At the first top-level headline: should error.
  4235. (goto-line 2)
  4236. (should-error (org-backward-element)))
  4237. ;; 5. At beginning of first element inside a greater element:
  4238. ;; expected to move to greater element's beginning.
  4239. (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
  4240. (goto-line 3)
  4241. (org-backward-element)
  4242. (should (looking-at "#\\+BEGIN_CENTER")))
  4243. ;; 6. At the beginning of the first element in a section: should
  4244. ;; move back to headline, if any.
  4245. (should
  4246. (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
  4247. (progn (goto-char (point-max))
  4248. (beginning-of-line)
  4249. (org-backward-element)
  4250. (org-at-heading-p))))
  4251. ;; 7. List tests.
  4252. (org-test-with-temp-text "
  4253. - item1
  4254. - sub1
  4255. - sub2
  4256. - sub3
  4257. Inner paragraph.
  4258. - item2
  4259. Outside."
  4260. ;; 7.1. At beginning of sub-list: expected to move to the
  4261. ;; paragraph before it.
  4262. (goto-line 4)
  4263. (org-backward-element)
  4264. (should (looking-at "item1"))
  4265. ;; 7.2. At an item in a list: expected to move at previous item.
  4266. (goto-line 8)
  4267. (org-backward-element)
  4268. (should (looking-at " - sub2"))
  4269. (goto-line 12)
  4270. (org-backward-element)
  4271. (should (looking-at "- item1"))
  4272. ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
  4273. ;; beginning.
  4274. (goto-line 10)
  4275. (org-backward-element)
  4276. (should (looking-at " - sub1"))
  4277. (goto-line 15)
  4278. (org-backward-element)
  4279. (should (looking-at "- item1"))
  4280. ;; 7.4. At blank-lines before list end: expected to move to top
  4281. ;; item.
  4282. (goto-line 14)
  4283. (org-backward-element)
  4284. (should (looking-at "- item1"))))
  4285. (ert-deftest test-org/up-element ()
  4286. "Test `org-up-element' specifications."
  4287. ;; 1. At BOB or with no surrounding element: should error.
  4288. (org-test-with-temp-text "Paragraph."
  4289. (should-error (org-up-element)))
  4290. (org-test-with-temp-text "* Head1\n* Head2"
  4291. (goto-line 2)
  4292. (should-error (org-up-element)))
  4293. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  4294. (goto-line 3)
  4295. (should-error (org-up-element)))
  4296. ;; 2. At an headline: move to parent headline.
  4297. (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
  4298. (goto-line 3)
  4299. (org-up-element)
  4300. (should (looking-at "\\* Head1")))
  4301. ;; 3. Inside a greater element: move to greater element beginning.
  4302. (org-test-with-temp-text
  4303. "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
  4304. (goto-line 3)
  4305. (org-up-element)
  4306. (should (looking-at "#\\+BEGIN_CENTER")))
  4307. ;; 4. List tests.
  4308. (org-test-with-temp-text "* Top
  4309. - item1
  4310. - sub1
  4311. - sub2
  4312. Paragraph within sub2.
  4313. - item2"
  4314. ;; 4.1. Within an item: move to the item beginning.
  4315. (goto-line 8)
  4316. (org-up-element)
  4317. (should (looking-at " - sub2"))
  4318. ;; 4.2. At an item in a sub-list: move to parent item.
  4319. (goto-line 4)
  4320. (org-up-element)
  4321. (should (looking-at "- item1"))
  4322. ;; 4.3. At an item in top list: move to beginning of whole list.
  4323. (goto-line 10)
  4324. (org-up-element)
  4325. (should (looking-at "- item1"))
  4326. ;; 4.4. Special case. At very top point: should move to parent of
  4327. ;; list.
  4328. (goto-line 2)
  4329. (org-up-element)
  4330. (should (looking-at "\\* Top"))))
  4331. (ert-deftest test-org/down-element ()
  4332. "Test `org-down-element' specifications."
  4333. ;; Error when the element hasn't got a recursive type.
  4334. (org-test-with-temp-text "Paragraph."
  4335. (should-error (org-down-element)))
  4336. ;; Error when the element has no contents
  4337. (org-test-with-temp-text "* Headline"
  4338. (should-error (org-down-element)))
  4339. ;; When at a plain-list, move to first item.
  4340. (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
  4341. (goto-line 2)
  4342. (org-down-element)
  4343. (should (looking-at " - Item 1.1")))
  4344. (org-test-with-temp-text "#+NAME: list\n- Item 1"
  4345. (org-down-element)
  4346. (should (looking-at " Item 1")))
  4347. ;; When at a table, move to first row
  4348. (org-test-with-temp-text "#+NAME: table\n| a | b |"
  4349. (org-down-element)
  4350. (should (looking-at " a | b |")))
  4351. ;; Otherwise, move inside the greater element.
  4352. (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
  4353. (org-down-element)
  4354. (should (looking-at "Paragraph"))))
  4355. (ert-deftest test-org/drag-element-backward ()
  4356. "Test `org-drag-element-backward' specifications."
  4357. ;; Standard test.
  4358. (should
  4359. (equal
  4360. "#+key2: val2\n#+key1: val1\n#+key3: val3"
  4361. (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
  4362. (org-drag-element-backward)
  4363. (buffer-string))))
  4364. (should
  4365. (equal
  4366. "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
  4367. (org-test-with-temp-text
  4368. "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
  4369. (org-drag-element-backward)
  4370. (buffer-string))))
  4371. ;; Preserve blank lines.
  4372. (should
  4373. (equal "Paragraph 2\n\n\nPara1\n\nPara3"
  4374. (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
  4375. (org-drag-element-backward)
  4376. (buffer-string))))
  4377. ;; Preserve column.
  4378. (should
  4379. (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
  4380. (org-drag-element-backward)
  4381. (looking-at-p "2")))
  4382. ;; Error when trying to move first element of buffer.
  4383. (should-error
  4384. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4385. (org-drag-element-backward))
  4386. :type 'user-error)
  4387. ;; Error when trying to swap nested elements.
  4388. (should-error
  4389. (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
  4390. (org-drag-element-backward))
  4391. :type 'user-error)
  4392. ;; Error when trying to swap an headline element and a non-headline
  4393. ;; element.
  4394. (should-error
  4395. (org-test-with-temp-text "Test.\n<point>* Head 1"
  4396. (org-drag-element-backward))
  4397. :type 'error)
  4398. ;; Error when called before first element.
  4399. (should-error
  4400. (org-test-with-temp-text "\n<point>"
  4401. (org-drag-element-backward))
  4402. :type 'user-error)
  4403. ;; Preserve visibility of elements and their contents.
  4404. (should
  4405. (equal '((63 . 82) (26 . 48))
  4406. (let ((org-fold-core-style 'text-properties))
  4407. (org-test-with-temp-text
  4408. "
  4409. #+BEGIN_CENTER
  4410. Text.
  4411. #+END_CENTER
  4412. - item 1
  4413. #+BEGIN_QUOTE
  4414. Text.
  4415. #+END_QUOTE"
  4416. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4417. (search-backward "- item 1")
  4418. (org-drag-element-backward)
  4419. (let (regions)
  4420. (goto-char (point-min))
  4421. (while (< (point) (point-max))
  4422. (let ((region (org-fold-get-region-at-point)))
  4423. (if (not region)
  4424. (goto-char (org-fold-next-folding-state-change))
  4425. (goto-char (cdr region))
  4426. (push region regions))))
  4427. regions)))))
  4428. (should
  4429. (equal '((63 . 82) (26 . 48))
  4430. (let ((org-fold-core-style 'overlays))
  4431. (org-test-with-temp-text
  4432. "
  4433. #+BEGIN_CENTER
  4434. Text.
  4435. #+END_CENTER
  4436. - item 1
  4437. #+BEGIN_QUOTE
  4438. Text.
  4439. #+END_QUOTE"
  4440. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4441. (search-backward "- item 1")
  4442. (org-drag-element-backward)
  4443. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4444. (overlays-in (point-min) (point-max)))))))
  4445. ;; Pathological case: handle call with point in blank lines right
  4446. ;; after a headline.
  4447. (should
  4448. (equal "* H2\n\n* H1\nText\n"
  4449. (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
  4450. (org-drag-element-backward)
  4451. (buffer-string)))))
  4452. (ert-deftest test-org/drag-element-forward ()
  4453. "Test `org-drag-element-forward' specifications."
  4454. ;; 1. Error when trying to move first element of buffer.
  4455. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4456. (goto-line 3)
  4457. (should-error (org-drag-element-forward)))
  4458. ;; 2. Error when trying to swap nested elements.
  4459. (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
  4460. (forward-line)
  4461. (should-error (org-drag-element-forward)))
  4462. ;; 3. Error when trying to swap a non-headline element and an
  4463. ;; headline.
  4464. (org-test-with-temp-text "Test.\n* Head 1"
  4465. (should-error (org-drag-element-forward)))
  4466. ;; 4. Error when called before first element.
  4467. (should-error
  4468. (org-test-with-temp-text "\n"
  4469. (forward-line)
  4470. (org-drag-element-backward))
  4471. :type 'user-error)
  4472. ;; 5. Otherwise, swap elements, preserving column and blank lines
  4473. ;; between elements.
  4474. (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
  4475. (search-forward "graph")
  4476. (org-drag-element-forward)
  4477. (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
  4478. (should (looking-at " 1")))
  4479. ;; 5. Preserve visibility of elements and their contents.
  4480. (let ((org-fold-core-style 'text-properties))
  4481. (org-test-with-temp-text
  4482. "
  4483. #+BEGIN_CENTER
  4484. Text.
  4485. #+END_CENTER
  4486. - item 1
  4487. #+BEGIN_QUOTE
  4488. Text.
  4489. #+END_QUOTE"
  4490. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4491. (search-backward "#+BEGIN_CENTER")
  4492. (org-drag-element-forward)
  4493. (should
  4494. (equal
  4495. '((63 . 82) (26 . 48))
  4496. (let (regions)
  4497. (goto-char (point-min))
  4498. (while (< (point) (point-max))
  4499. (let ((region (org-fold-get-region-at-point)))
  4500. (if (not region)
  4501. (goto-char (org-fold-next-folding-state-change))
  4502. (goto-char (cdr region))
  4503. (push region regions))))
  4504. regions)))))
  4505. (let ((org-fold-core-style 'overlays))
  4506. (org-test-with-temp-text
  4507. "
  4508. #+BEGIN_CENTER
  4509. Text.
  4510. #+END_CENTER
  4511. - item 1
  4512. #+BEGIN_QUOTE
  4513. Text.
  4514. #+END_QUOTE"
  4515. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4516. (search-backward "#+BEGIN_CENTER")
  4517. (org-drag-element-forward)
  4518. (should
  4519. (equal
  4520. '((63 . 82) (26 . 48))
  4521. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4522. (overlays-in (point-min) (point-max))))))))
  4523. (ert-deftest test-org/next-block ()
  4524. "Test `org-next-block' specifications."
  4525. ;; Regular test.
  4526. (should
  4527. (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  4528. (org-next-block 1)
  4529. (looking-at "#\\+BEGIN_CENTER")))
  4530. ;; Ignore case.
  4531. (should
  4532. (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
  4533. (let ((case-fold-search nil))
  4534. (org-next-block 1)
  4535. (looking-at "#\\+begin_center"))))
  4536. ;; Ignore current line.
  4537. (should
  4538. (org-test-with-temp-text
  4539. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
  4540. (org-next-block 1)
  4541. (looking-at "#\\+BEGIN_CENTER")))
  4542. ;; Throw an error when no block is found.
  4543. (should-error
  4544. (org-test-with-temp-text "Paragraph"
  4545. (org-next-block 1)))
  4546. ;; With an argument, skip many blocks at once.
  4547. (should
  4548. (org-test-with-temp-text
  4549. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4550. (org-next-block 2)
  4551. (looking-at "#\\+BEGIN_QUOTE")))
  4552. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4553. (should
  4554. (org-test-with-temp-text
  4555. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4556. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4557. (looking-at "#\\+BEGIN_QUOTE")))
  4558. ;; Optional argument is also case-insensitive.
  4559. (should
  4560. (org-test-with-temp-text
  4561. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
  4562. (let ((case-fold-search nil))
  4563. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4564. (looking-at "#\\+begin_quote")))))
  4565. (ert-deftest test-org/insert-structure-template ()
  4566. "Test `org-insert-structure-template'."
  4567. ;; Test in empty buffer.
  4568. (should
  4569. (string= "#+begin_foo\n#+end_foo\n"
  4570. (org-test-with-temp-text ""
  4571. (org-insert-structure-template "foo")
  4572. (buffer-string))))
  4573. ;; Test with multiple lines in buffer.
  4574. (should
  4575. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4576. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4577. (transient-mark-mode 1)
  4578. (org-mark-element)
  4579. (org-insert-structure-template "foo")
  4580. (buffer-string))))
  4581. ;; Mark only the current line.
  4582. (should
  4583. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4584. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4585. (transient-mark-mode 1)
  4586. (set-mark (point-min))
  4587. (end-of-line)
  4588. (org-insert-structure-template "foo")
  4589. (buffer-string))))
  4590. ;; Middle of paragraph.
  4591. (should
  4592. (string= "p1\n#+begin_foo\np2\n#+end_foo\np3"
  4593. (org-test-with-temp-text "p1\n<point>p2\np3"
  4594. (set-mark (line-beginning-position))
  4595. (end-of-line)
  4596. (activate-mark)
  4597. (org-insert-structure-template "foo")
  4598. (buffer-string))))
  4599. ;; Test with text in buffer, no region, no final newline.
  4600. (should
  4601. (string= "#+begin_foo\nI'm a paragraph.\n#+end_foo\n"
  4602. (org-test-with-temp-text "I'm a paragraph."
  4603. (org-mark-element)
  4604. (org-insert-structure-template "foo")
  4605. (buffer-string))))
  4606. ;; Test with text in buffer and region set.
  4607. (should
  4608. (string= "#+begin_foo\nI'm a paragraph\n\nI'm a second paragrah\n#+end_foo\n"
  4609. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragrah"
  4610. (set-mark (point))
  4611. (goto-char (point-max))
  4612. (org-insert-structure-template "foo")
  4613. (buffer-string))))
  4614. ;; Test with example escaping.
  4615. (should
  4616. (string= "#+begin_example\n,* Heading\n#+end_example\n"
  4617. (org-test-with-temp-text "* Heading"
  4618. (org-mark-element)
  4619. (org-insert-structure-template "example")
  4620. (buffer-string))))
  4621. ;; Test with indentation.
  4622. (should
  4623. (string= " #+begin_foo\n This is a paragraph\n #+end_foo\n"
  4624. (org-test-with-temp-text " This is a paragraph"
  4625. (org-mark-element)
  4626. (org-insert-structure-template "foo")
  4627. (buffer-string))))
  4628. (should
  4629. (string= " #+begin_foo\n Line 1\n Line2\n #+end_foo\n"
  4630. (org-test-with-temp-text " Line 1\n Line2"
  4631. (org-mark-element)
  4632. (org-insert-structure-template "foo")
  4633. (buffer-string))))
  4634. ;; Test point location.
  4635. (should
  4636. (string= "#+begin_foo\n"
  4637. (org-test-with-temp-text ""
  4638. (org-insert-structure-template "foo")
  4639. (buffer-substring (point-min) (point)))))
  4640. (should
  4641. (string= "#+begin_src "
  4642. (org-test-with-temp-text ""
  4643. (org-insert-structure-template "src")
  4644. (buffer-substring (point-min) (point))))))
  4645. (ert-deftest test-org/previous-block ()
  4646. "Test `org-previous-block' specifications."
  4647. ;; Regular test.
  4648. (should
  4649. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
  4650. (org-previous-block 1)
  4651. (looking-at "#\\+BEGIN_CENTER")))
  4652. ;; Ignore case.
  4653. (should
  4654. (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
  4655. (let ((case-fold-search nil))
  4656. (org-previous-block 1)
  4657. (looking-at "#\\+begin_center"))))
  4658. ;; Ignore current line.
  4659. (should
  4660. (org-test-with-temp-text
  4661. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
  4662. (org-previous-block 1)
  4663. (looking-at "#\\+BEGIN_QUOTE")))
  4664. ;; Throw an error when no block is found.
  4665. (should-error
  4666. (org-test-with-temp-text "Paragraph<point>"
  4667. (org-previous-block 1)))
  4668. ;; With an argument, skip many blocks at once.
  4669. (should
  4670. (org-test-with-temp-text
  4671. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4672. (org-previous-block 2)
  4673. (looking-at "#\\+BEGIN_CENTER")))
  4674. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4675. (should
  4676. (org-test-with-temp-text
  4677. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4678. (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4679. (looking-at "#\\+BEGIN_QUOTE")))
  4680. ;; Optional argument is also case-insensitive.
  4681. (should
  4682. (org-test-with-temp-text
  4683. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
  4684. (let ((case-fold-search nil))
  4685. (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4686. (looking-at "#\\+begin_quote")))))
  4687. ;;; Outline structure
  4688. (ert-deftest test-org/demote ()
  4689. "Test `org-demote' specifications."
  4690. ;; Add correct number of stars according to `org-odd-levels-only'.
  4691. (should
  4692. (= 2
  4693. (org-test-with-temp-text "* H"
  4694. (let ((org-odd-levels-only nil)) (org-demote))
  4695. (org-current-level))))
  4696. (should
  4697. (= 3
  4698. (org-test-with-temp-text "* H"
  4699. (let ((org-odd-levels-only t)) (org-demote))
  4700. (org-current-level))))
  4701. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4702. (should
  4703. (org-test-with-temp-text "* H :tag:"
  4704. (let ((org-tags-column 10)
  4705. (org-auto-align-tags t)
  4706. (org-odd-levels-only nil))
  4707. (org-demote))
  4708. (org-move-to-column 10)
  4709. (looking-at-p ":tag:$")))
  4710. (should-not
  4711. (org-test-with-temp-text "* H :tag:"
  4712. (let ((org-tags-column 10)
  4713. (org-auto-align-tags nil)
  4714. (org-odd-levels-only nil))
  4715. (org-demote))
  4716. (org-move-to-column 10)
  4717. (looking-at-p ":tag:$")))
  4718. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4719. ;; info and property drawers accordingly.
  4720. (should
  4721. (= 3
  4722. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4723. (let ((org-odd-levels-only nil)
  4724. (org-adapt-indentation t))
  4725. (org-demote))
  4726. (forward-line)
  4727. (org-get-indentation))))
  4728. (should
  4729. (= 3
  4730. (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4731. (let ((org-odd-levels-only nil)
  4732. (org-adapt-indentation t))
  4733. (org-demote))
  4734. (forward-line)
  4735. (org-get-indentation))))
  4736. (should-not
  4737. (= 3
  4738. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4739. (let ((org-odd-levels-only nil)
  4740. (org-adapt-indentation nil))
  4741. (org-demote))
  4742. (forward-line)
  4743. (org-get-indentation))))
  4744. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4745. ;; section accordingly. Ignore, however, footnote definitions and
  4746. ;; inlinetasks boundaries.
  4747. (should
  4748. (= 3
  4749. (org-test-with-temp-text "* H\n Paragraph"
  4750. (let ((org-odd-levels-only nil)
  4751. (org-adapt-indentation t))
  4752. (org-demote))
  4753. (forward-line)
  4754. (org-get-indentation))))
  4755. (should
  4756. (= 2
  4757. (org-test-with-temp-text "* H\n Paragraph"
  4758. (let ((org-odd-levels-only nil)
  4759. (org-adapt-indentation nil))
  4760. (org-demote))
  4761. (forward-line)
  4762. (org-get-indentation))))
  4763. (should
  4764. (zerop
  4765. (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
  4766. (let ((org-odd-levels-only nil)
  4767. (org-adapt-indentation t))
  4768. (org-demote))
  4769. (goto-char (point-max))
  4770. (org-get-indentation))))
  4771. (should
  4772. (= 3
  4773. (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
  4774. (let ((org-odd-levels-only nil)
  4775. (org-adapt-indentation t))
  4776. (org-demote))
  4777. (goto-char (point-max))
  4778. (org-get-indentation))))
  4779. (when (featurep 'org-inlinetask)
  4780. (should
  4781. (zerop
  4782. (let ((org-inlinetask-min-level 5)
  4783. (org-adapt-indentation t))
  4784. (org-test-with-temp-text "* H\n***** I\n***** END"
  4785. (org-demote)
  4786. (forward-line)
  4787. (org-get-indentation))))))
  4788. (when (featurep 'org-inlinetask)
  4789. (should
  4790. (= 3
  4791. (let ((org-inlinetask-min-level 5)
  4792. (org-adapt-indentation t))
  4793. (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
  4794. (org-demote)
  4795. (forward-line 2)
  4796. (org-get-indentation))))))
  4797. ;; When `org-adapt-indentation' is non-nil, log drawers are
  4798. ;; adjusted.
  4799. (should
  4800. (equal
  4801. "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4802. (org-test-with-temp-text "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4803. (let ((org-odd-levels-only nil)
  4804. (org-adapt-indentation t))
  4805. (org-demote))
  4806. (buffer-string))))
  4807. (should
  4808. (equal
  4809. "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4810. (org-test-with-temp-text "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4811. (let ((org-odd-levels-only nil)
  4812. (org-adapt-indentation 'headline-data))
  4813. (org-demote))
  4814. (buffer-string))))
  4815. (should
  4816. (equal
  4817. "** H\n :LOGBOOK:\n - a\n :END:"
  4818. (org-test-with-temp-text "* H\n:LOGBOOK:\n- a\n:END:"
  4819. (let ((org-odd-levels-only nil)
  4820. (org-adapt-indentation t))
  4821. (org-demote))
  4822. (buffer-string))))
  4823. ;; Ignore contents of source blocks or example blocks when
  4824. ;; indentation should be preserved (through
  4825. ;; `org-src-preserve-indentation' or "-i" flag).
  4826. (should-not
  4827. (zerop
  4828. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4829. (let ((org-adapt-indentation t)
  4830. (org-src-preserve-indentation nil))
  4831. (org-demote))
  4832. (forward-line 2)
  4833. (org-get-indentation))))
  4834. (should
  4835. (zerop
  4836. (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
  4837. (let ((org-adapt-indentation t)
  4838. (org-src-preserve-indentation t))
  4839. (org-demote))
  4840. (forward-line 2)
  4841. (org-get-indentation))))
  4842. (should
  4843. (zerop
  4844. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4845. (let ((org-adapt-indentation t)
  4846. (org-src-preserve-indentation t))
  4847. (org-demote))
  4848. (forward-line 2)
  4849. (org-get-indentation))))
  4850. (should
  4851. (zerop
  4852. (org-test-with-temp-text
  4853. "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
  4854. (let ((org-adapt-indentation t)
  4855. (org-src-preserve-indentation nil))
  4856. (org-demote))
  4857. (forward-line 2)
  4858. (org-get-indentation)))))
  4859. (ert-deftest test-org/promote ()
  4860. "Test `org-promote' specifications."
  4861. ;; Return an error if headline is to be promoted to level 0, unless
  4862. ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
  4863. ;; headline becomes a comment.
  4864. (should-error
  4865. (org-test-with-temp-text "* H"
  4866. (let ((org-allow-promoting-top-level-subtree nil)) (org-promote))))
  4867. (should
  4868. (equal "# H"
  4869. (org-test-with-temp-text "* H"
  4870. (let ((org-allow-promoting-top-level-subtree t)) (org-promote))
  4871. (buffer-string))))
  4872. ;; Remove correct number of stars according to
  4873. ;; `org-odd-levels-only'.
  4874. (should
  4875. (= 2
  4876. (org-test-with-temp-text "*** H"
  4877. (let ((org-odd-levels-only nil)) (org-promote))
  4878. (org-current-level))))
  4879. (should
  4880. (= 1
  4881. (org-test-with-temp-text "*** H"
  4882. (let ((org-odd-levels-only t)) (org-promote))
  4883. (org-current-level))))
  4884. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4885. (should
  4886. (org-test-with-temp-text "** H :tag:"
  4887. (let ((org-tags-column 10)
  4888. (org-auto-align-tags t)
  4889. (org-odd-levels-only nil))
  4890. (org-promote))
  4891. (org-move-to-column 10)
  4892. (looking-at-p ":tag:$")))
  4893. (should-not
  4894. (org-test-with-temp-text "** H :tag:"
  4895. (let ((org-tags-column 10)
  4896. (org-auto-align-tags nil)
  4897. (org-odd-levels-only nil))
  4898. (org-promote))
  4899. (org-move-to-column 10)
  4900. (looking-at-p ":tag:$")))
  4901. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4902. ;; info and property drawers.
  4903. (should
  4904. (= 2
  4905. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4906. (let ((org-odd-levels-only nil)
  4907. (org-adapt-indentation t))
  4908. (org-promote))
  4909. (forward-line)
  4910. (org-get-indentation))))
  4911. (should
  4912. (= 2
  4913. (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4914. (let ((org-odd-levels-only nil)
  4915. (org-adapt-indentation t))
  4916. (org-promote))
  4917. (forward-line)
  4918. (org-get-indentation))))
  4919. (should-not
  4920. (= 2
  4921. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4922. (let ((org-odd-levels-only nil)
  4923. (org-adapt-indentation nil))
  4924. (org-promote))
  4925. (forward-line)
  4926. (org-get-indentation))))
  4927. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4928. ;; section accordingly. Ignore, however, footnote definitions and
  4929. ;; inlinetasks boundaries.
  4930. (should
  4931. (= 2
  4932. (org-test-with-temp-text "** H\n Paragraph"
  4933. (let ((org-odd-levels-only nil)
  4934. (org-adapt-indentation t))
  4935. (org-promote))
  4936. (forward-line)
  4937. (org-get-indentation))))
  4938. (should-not
  4939. (= 2
  4940. (org-test-with-temp-text "** H\n Paragraph"
  4941. (let ((org-odd-levels-only nil)
  4942. (org-adapt-indentation nil))
  4943. (org-promote))
  4944. (forward-line)
  4945. (org-get-indentation))))
  4946. (should
  4947. (= 2
  4948. (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
  4949. (let ((org-odd-levels-only nil)
  4950. (org-adapt-indentation t))
  4951. (org-promote))
  4952. (forward-line)
  4953. (org-get-indentation))))
  4954. (when (featurep 'org-inlinetask)
  4955. (should
  4956. (zerop
  4957. (let ((org-inlinetask-min-level 5)
  4958. (org-adapt-indentation t))
  4959. (org-test-with-temp-text "** H\n***** I\n***** END"
  4960. (org-promote)
  4961. (forward-line)
  4962. (org-get-indentation))))))
  4963. (when (featurep 'org-inlinetask)
  4964. (should
  4965. (= 2
  4966. (let ((org-inlinetask-min-level 5)
  4967. (org-adapt-indentation t))
  4968. (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
  4969. (org-promote)
  4970. (forward-line 2)
  4971. (org-get-indentation))))))
  4972. ;; Give up shifting if it would break document's structure
  4973. ;; otherwise.
  4974. (should
  4975. (= 3
  4976. (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
  4977. (let ((org-odd-levels-only nil)
  4978. (org-adapt-indentation t))
  4979. (org-promote))
  4980. (forward-line)
  4981. (org-get-indentation))))
  4982. (should
  4983. (= 3
  4984. (org-test-with-temp-text "** H\n Paragraph\n * list."
  4985. (let ((org-odd-levels-only nil)
  4986. (org-adapt-indentation t))
  4987. (org-promote))
  4988. (forward-line)
  4989. (org-get-indentation))))
  4990. ;; When `org-adapt-indentation' is non-nil, log drawers are
  4991. ;; adjusted.
  4992. (should
  4993. (equal
  4994. "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4995. (org-test-with-temp-text "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4996. (let ((org-odd-levels-only nil)
  4997. (org-adapt-indentation t))
  4998. (org-promote))
  4999. (buffer-string))))
  5000. (should
  5001. (equal
  5002. "* H\n :LOGBOOK:\n - a\n :END:\n b"
  5003. (org-test-with-temp-text "** H\n :LOGBOOK:\n - a\n :END:\n b"
  5004. (let ((org-odd-levels-only nil)
  5005. (org-adapt-indentation 'headline-data))
  5006. (org-promote))
  5007. (buffer-string))))
  5008. (should
  5009. (equal
  5010. "* H\n:LOGBOOK:\n- a\n:END:"
  5011. (org-test-with-temp-text "** H\n:LOGBOOK:\n- a\n:END:"
  5012. (let ((org-odd-levels-only nil)
  5013. (org-adapt-indentation t))
  5014. (org-promote))
  5015. (buffer-string))))
  5016. (should
  5017. (equal
  5018. "# H\n:LOGBOOK:\n- a\n:END:"
  5019. (org-test-with-temp-text "* H\n:LOGBOOK:\n- a\n:END:"
  5020. (let ((org-odd-levels-only nil)
  5021. (org-allow-promoting-top-level-subtree t)
  5022. (org-adapt-indentation t))
  5023. (org-promote))
  5024. (buffer-string))))
  5025. ;; Ignore contents of source blocks or example blocks when
  5026. ;; indentation should be preserved (through
  5027. ;; `org-src-preserve-indentation' or "-i" flag).
  5028. (should-not
  5029. (zerop
  5030. (org-test-with-temp-text
  5031. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  5032. (let ((org-adapt-indentation t)
  5033. (org-src-preserve-indentation nil)
  5034. (org-odd-levels-only nil))
  5035. (org-promote))
  5036. (forward-line)
  5037. (org-get-indentation))))
  5038. (should
  5039. (zerop
  5040. (org-test-with-temp-text
  5041. "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
  5042. (let ((org-adapt-indentation t)
  5043. (org-src-preserve-indentation t)
  5044. (org-odd-levels-only nil))
  5045. (org-promote))
  5046. (forward-line)
  5047. (org-get-indentation))))
  5048. (should
  5049. (zerop
  5050. (org-test-with-temp-text
  5051. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  5052. (let ((org-adapt-indentation t)
  5053. (org-src-preserve-indentation t)
  5054. (org-odd-levels-only nil))
  5055. (org-promote))
  5056. (forward-line)
  5057. (org-get-indentation))))
  5058. (should
  5059. (zerop
  5060. (org-test-with-temp-text
  5061. "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
  5062. (let ((org-adapt-indentation t)
  5063. (org-src-preserve-indentation nil)
  5064. (org-odd-levels-only nil))
  5065. (org-promote))
  5066. (forward-line)
  5067. (org-get-indentation)))))
  5068. (ert-deftest test-org/org-get-valid-level ()
  5069. "Test function `org-get-valid-level' specifications."
  5070. (let ((org-odd-levels-only nil))
  5071. (should (equal 1 (org-get-valid-level 0 0)))
  5072. (should (equal 1 (org-get-valid-level 0 1)))
  5073. (should (equal 2 (org-get-valid-level 0 2)))
  5074. (should (equal 3 (org-get-valid-level 0 3)))
  5075. (should (equal 1 (org-get-valid-level 1 0)))
  5076. (should (equal 2 (org-get-valid-level 1 1)))
  5077. (should (equal 23 (org-get-valid-level 1 22)))
  5078. (should (equal 1 (org-get-valid-level 1 -1)))
  5079. (should (equal 1 (org-get-valid-level 2 -1))))
  5080. (let ((org-odd-levels-only t))
  5081. (should (equal 1 (org-get-valid-level 0 0)))
  5082. (should (equal 1 (org-get-valid-level 0 1)))
  5083. (should (equal 3 (org-get-valid-level 0 2)))
  5084. (should (equal 5 (org-get-valid-level 0 3)))
  5085. (should (equal 1 (org-get-valid-level 1 0)))
  5086. (should (equal 3 (org-get-valid-level 1 1)))
  5087. (should (equal 3 (org-get-valid-level 2 1)))
  5088. (should (equal 5 (org-get-valid-level 3 1)))
  5089. (should (equal 5 (org-get-valid-level 4 1)))
  5090. (should (equal 43 (org-get-valid-level 1 21)))
  5091. (should (equal 1 (org-get-valid-level 1 -1)))
  5092. (should (equal 1 (org-get-valid-level 2 -1)))
  5093. (should (equal 1 (org-get-valid-level 3 -1)))
  5094. (should (equal 3 (org-get-valid-level 4 -1)))
  5095. (should (equal 3 (org-get-valid-level 5 -1)))))
  5096. ;;; Planning
  5097. (ert-deftest test-org/at-planning-p ()
  5098. "Test `org-at-planning-p' specifications."
  5099. ;; Regular test.
  5100. (should
  5101. (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
  5102. (org-at-planning-p)))
  5103. (should-not
  5104. (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
  5105. (org-at-planning-p)))
  5106. ;; Correctly find planning attached to inlinetasks.
  5107. (when (featurep 'org-inlinetask)
  5108. (should
  5109. (org-test-with-temp-text
  5110. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
  5111. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  5112. (should-not
  5113. (org-test-with-temp-text
  5114. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  5115. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  5116. (should-not
  5117. (org-test-with-temp-text
  5118. "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  5119. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  5120. (should-not
  5121. (org-test-with-temp-text
  5122. "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
  5123. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
  5124. (ert-deftest test-org/add-planning-info ()
  5125. "Test `org-add-planning-info'."
  5126. ;; Create deadline when `org-adapt-indentation' is non-nil.
  5127. (should
  5128. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5129. (org-test-with-temp-text "* H\nParagraph<point>"
  5130. (let ((org-adapt-indentation t))
  5131. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5132. (replace-regexp-in-string
  5133. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5134. nil nil 1))))
  5135. ;; Create deadline when `org-adapt-indentation' is nil.
  5136. (should
  5137. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  5138. (org-test-with-temp-text "* H\nParagraph<point>"
  5139. (let ((org-adapt-indentation nil))
  5140. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5141. (replace-regexp-in-string
  5142. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5143. nil nil 1))))
  5144. ;; Update deadline when `org-adapt-indentation' is non-nil.
  5145. (should
  5146. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5147. (org-test-with-temp-text "\
  5148. * H
  5149. DEADLINE: <2015-06-24 Wed>
  5150. Paragraph<point>"
  5151. (let ((org-adapt-indentation t))
  5152. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5153. (replace-regexp-in-string
  5154. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5155. nil nil 1))))
  5156. ;; Update deadline when `org-adapt-indentation' is nil.
  5157. (should
  5158. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  5159. (org-test-with-temp-text "\
  5160. * H
  5161. DEADLINE: <2015-06-24 Wed>
  5162. Paragraph<point>"
  5163. (let ((org-adapt-indentation nil))
  5164. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5165. (replace-regexp-in-string
  5166. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5167. nil nil 1))))
  5168. ;; Schedule when `org-adapt-indentation' is non-nil.
  5169. (should
  5170. (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
  5171. (org-test-with-temp-text "* H\nParagraph<point>"
  5172. (let ((org-adapt-indentation t))
  5173. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  5174. (replace-regexp-in-string
  5175. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5176. nil nil 1))))
  5177. ;; Schedule when `org-adapt-indentation' is nil.
  5178. (should
  5179. (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
  5180. (org-test-with-temp-text "* H\nParagraph<point>"
  5181. (let ((org-adapt-indentation nil))
  5182. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  5183. (replace-regexp-in-string
  5184. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5185. nil nil 1))))
  5186. ;; Add deadline when scheduled.
  5187. (should
  5188. (equal "\
  5189. * H
  5190. DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
  5191. Paragraph"
  5192. (org-test-with-temp-text "\
  5193. * H
  5194. SCHEDULED: <2015-06-24 Wed>
  5195. Paragraph<point>"
  5196. (let ((org-adapt-indentation t))
  5197. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5198. (replace-regexp-in-string
  5199. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5200. nil nil 1))))
  5201. ;; Remove middle entry.
  5202. (should
  5203. (equal "\
  5204. * H
  5205. CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
  5206. Paragraph"
  5207. (org-test-with-temp-text "\
  5208. * H
  5209. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  5210. Paragraph<point>"
  5211. (let ((org-adapt-indentation t))
  5212. (org-add-planning-info nil nil 'deadline))
  5213. (replace-regexp-in-string
  5214. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  5215. nil nil 1))))
  5216. ;; Remove last entry and then middle entry (order should not
  5217. ;; matter).
  5218. (should
  5219. (equal "\
  5220. * H
  5221. CLOSED: [2015-06-24]
  5222. Paragraph"
  5223. (org-test-with-temp-text "\
  5224. * H
  5225. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  5226. Paragraph<point>"
  5227. (let ((org-adapt-indentation t))
  5228. (org-add-planning-info nil nil 'scheduled 'deadline))
  5229. (replace-regexp-in-string
  5230. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  5231. nil nil 1))))
  5232. ;; Remove closed when `org-adapt-indentation' is non-nil.
  5233. (should
  5234. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5235. (org-test-with-temp-text "\
  5236. * H
  5237. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  5238. Paragraph<point>"
  5239. (let ((org-adapt-indentation t))
  5240. (org-add-planning-info nil nil 'closed))
  5241. (replace-regexp-in-string
  5242. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5243. nil nil 1))))
  5244. (should
  5245. (equal "* H\n Paragraph"
  5246. (org-test-with-temp-text "\
  5247. * H
  5248. CLOSED: [2015-06-25 Thu]
  5249. Paragraph<point>"
  5250. (let ((org-adapt-indentation t))
  5251. (org-add-planning-info nil nil 'closed))
  5252. (replace-regexp-in-string
  5253. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5254. nil nil 1))))
  5255. ;; Remove closed when `org-adapt-indentation' is nil.
  5256. (should
  5257. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  5258. (org-test-with-temp-text "\
  5259. * H
  5260. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  5261. Paragraph<point>"
  5262. (let ((org-adapt-indentation nil))
  5263. (org-add-planning-info nil nil 'closed))
  5264. (replace-regexp-in-string
  5265. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5266. nil nil 1))))
  5267. (should
  5268. (equal "* H\nParagraph"
  5269. (org-test-with-temp-text "\
  5270. * H
  5271. CLOSED: [2015-06-25 Thu]
  5272. Paragraph<point>"
  5273. (let ((org-adapt-indentation nil))
  5274. (org-add-planning-info nil nil 'closed))
  5275. (replace-regexp-in-string
  5276. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5277. nil nil 1))))
  5278. ;; Remove closed entry and delete empty line.
  5279. (should
  5280. (equal "\
  5281. * H
  5282. Paragraph"
  5283. (org-test-with-temp-text "\
  5284. * H
  5285. CLOSED: [2015-06-24 Wed]
  5286. Paragraph<point>"
  5287. (let ((org-adapt-indentation t))
  5288. (org-add-planning-info nil nil 'closed))
  5289. (replace-regexp-in-string
  5290. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5291. nil nil 1))))
  5292. ;; Remove one entry and update another.
  5293. (should
  5294. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5295. (org-test-with-temp-text "\
  5296. * H
  5297. SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
  5298. Paragraph<point>"
  5299. (let ((org-adapt-indentation t))
  5300. (org-add-planning-info 'deadline "<2015-06-25 Thu>" 'scheduled))
  5301. (replace-regexp-in-string
  5302. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5303. nil nil 1)))))
  5304. (ert-deftest test-org/deadline ()
  5305. "Test `org-deadline' specifications."
  5306. ;; Insert a new value or replace existing one.
  5307. (should
  5308. (equal "* H\nDEADLINE: <2012-03-29>"
  5309. (org-test-with-temp-text "* H"
  5310. (let ((org-adapt-indentation nil)
  5311. (org-last-inserted-timestamp nil))
  5312. (org-deadline nil "<2012-03-29 Tue>"))
  5313. (replace-regexp-in-string
  5314. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5315. nil nil 1))))
  5316. (should
  5317. (equal "* H\nDEADLINE: <2014-03-04>"
  5318. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5319. (let ((org-adapt-indentation nil)
  5320. (org-last-inserted-timestamp nil))
  5321. (org-deadline nil "<2014-03-04 Thu>"))
  5322. (replace-regexp-in-string
  5323. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5324. nil nil 1))))
  5325. ;; Accept delta time, e.g., "+2d".
  5326. (should
  5327. (equal "* H\nDEADLINE: <2015-03-04>"
  5328. (org-test-at-time "2014-03-04"
  5329. (org-test-with-temp-text "* H"
  5330. (let ((org-adapt-indentation nil)
  5331. (org-last-inserted-timestamp nil))
  5332. (org-deadline nil "+1y"))
  5333. (replace-regexp-in-string
  5334. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5335. ;; Preserve repeater.
  5336. (should
  5337. (equal "* H\nDEADLINE: <2012-03-29 +2y>"
  5338. (org-test-with-temp-text "* H"
  5339. (let ((org-adapt-indentation nil)
  5340. (org-last-inserted-timestamp nil))
  5341. (org-deadline nil "<2012-03-29 Tue +2y>"))
  5342. (replace-regexp-in-string
  5343. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5344. ;; Preserve warning period.
  5345. (should
  5346. (equal "* H\nDEADLINE: <2021-07-20 -1d>"
  5347. (org-test-with-temp-text "* H"
  5348. (let ((org-adapt-indentation nil)
  5349. (org-last-inserted-timestamp nil))
  5350. (org-deadline nil "<2021-07-20 Tue -1d>"))
  5351. (replace-regexp-in-string
  5352. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5353. (should
  5354. (equal "* H\nDEADLINE: <2021-07-20 +1m -3d>"
  5355. (org-test-with-temp-text "* H"
  5356. (let ((org-adapt-indentation nil)
  5357. (org-last-inserted-timestamp nil))
  5358. (org-deadline nil "<2021-07-20 Tue +1m -3d>"))
  5359. (replace-regexp-in-string
  5360. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5361. ;; Remove CLOSED keyword, if any.
  5362. (should
  5363. (equal "* H\nDEADLINE: <2012-03-29>"
  5364. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  5365. (let ((org-adapt-indentation nil)
  5366. (org-last-inserted-timestamp nil))
  5367. (org-deadline nil "<2012-03-29 Tue>"))
  5368. (replace-regexp-in-string
  5369. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5370. ;; With C-u argument, remove DEADLINE keyword.
  5371. (should
  5372. (equal "* H\n"
  5373. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5374. (let ((org-adapt-indentation nil)
  5375. (org-last-inserted-timestamp nil))
  5376. (org-deadline '(4)))
  5377. (buffer-string))))
  5378. (should
  5379. (equal "* H"
  5380. (org-test-with-temp-text "* H"
  5381. (let ((org-adapt-indentation nil)
  5382. (org-last-inserted-timestamp nil))
  5383. (org-deadline '(4)))
  5384. (buffer-string))))
  5385. ;; With C-u C-u argument, prompt for a delay cookie.
  5386. (should
  5387. (equal "* H\nDEADLINE: <2012-03-29 -705d>"
  5388. (cl-letf (((symbol-function 'org-read-date)
  5389. (lambda (&rest args)
  5390. (apply #'encode-time
  5391. (org-parse-time-string "2014-03-04")))))
  5392. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5393. (let ((org-adapt-indentation nil)
  5394. (org-last-inserted-timestamp nil))
  5395. (org-deadline '(16)))
  5396. (buffer-string)))))
  5397. (should-error
  5398. (cl-letf (((symbol-function 'org-read-date)
  5399. (lambda (&rest args)
  5400. (apply #'encode-time
  5401. (org-parse-time-string "2014-03-04")))))
  5402. (org-test-with-temp-text "* H"
  5403. (let ((org-adapt-indentation nil)
  5404. (org-last-inserted-timestamp nil))
  5405. (org-deadline '(16)))
  5406. (buffer-string))))
  5407. ;; When a region is active and
  5408. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5409. ;; same value in all headlines in region.
  5410. (should
  5411. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5412. (org-test-with-temp-text "* H1\n* H2"
  5413. (let ((org-adapt-indentation nil)
  5414. (org-last-inserted-timestamp nil)
  5415. (org-loop-over-headlines-in-active-region t))
  5416. (transient-mark-mode 1)
  5417. (push-mark (point) t t)
  5418. (goto-char (point-max))
  5419. (org-deadline nil "2012-03-29"))
  5420. (replace-regexp-in-string
  5421. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5422. (should-not
  5423. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5424. (org-test-with-temp-text "* H1\n* H2"
  5425. (let ((org-adapt-indentation nil)
  5426. (org-last-inserted-timestamp nil)
  5427. (org-loop-over-headlines-in-active-region nil))
  5428. (transient-mark-mode 1)
  5429. (push-mark (point) t t)
  5430. (goto-char (point-max))
  5431. (org-deadline nil "2012-03-29"))
  5432. (replace-regexp-in-string
  5433. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5434. (ert-deftest test-org/schedule ()
  5435. "Test `org-schedule' specifications."
  5436. ;; Insert a new value or replace existing one.
  5437. (should
  5438. (equal "* H\nSCHEDULED: <2012-03-29>"
  5439. (org-test-with-temp-text "* H"
  5440. (let ((org-adapt-indentation nil)
  5441. (org-last-inserted-timestamp nil))
  5442. (org-schedule nil "<2012-03-29 Tue>"))
  5443. (replace-regexp-in-string
  5444. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5445. nil nil 1))))
  5446. (should
  5447. (equal "* H\nSCHEDULED: <2014-03-04>"
  5448. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5449. (let ((org-adapt-indentation nil)
  5450. (org-last-inserted-timestamp nil))
  5451. (org-schedule nil "<2014-03-04 Thu>"))
  5452. (replace-regexp-in-string
  5453. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5454. nil nil 1))))
  5455. ;; Accept delta time, e.g., "+2d".
  5456. (should
  5457. (equal "* H\nSCHEDULED: <2015-03-04>"
  5458. (org-test-at-time "2014-03-04"
  5459. (org-test-with-temp-text "* H"
  5460. (let ((org-adapt-indentation nil)
  5461. (org-last-inserted-timestamp nil))
  5462. (org-schedule nil "+1y"))
  5463. (replace-regexp-in-string
  5464. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5465. ;; Preserve repeater.
  5466. (should
  5467. (equal "* H\nSCHEDULED: <2012-03-29 +2y>"
  5468. (org-test-with-temp-text "* H"
  5469. (let ((org-adapt-indentation nil)
  5470. (org-last-inserted-timestamp nil))
  5471. (org-schedule nil "<2012-03-29 Tue +2y>"))
  5472. (replace-regexp-in-string
  5473. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5474. ;; Remove CLOSED keyword, if any.
  5475. (should
  5476. (equal "* H\nSCHEDULED: <2012-03-29>"
  5477. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  5478. (let ((org-adapt-indentation nil)
  5479. (org-last-inserted-timestamp nil))
  5480. (org-schedule nil "<2012-03-29 Tue>"))
  5481. (replace-regexp-in-string
  5482. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5483. ;; With C-u argument, remove SCHEDULED keyword.
  5484. (should
  5485. (equal "* H\n"
  5486. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5487. (let ((org-adapt-indentation nil)
  5488. (org-last-inserted-timestamp nil))
  5489. (org-schedule '(4)))
  5490. (buffer-string))))
  5491. (should
  5492. (equal "* H"
  5493. (org-test-with-temp-text "* H"
  5494. (let ((org-adapt-indentation nil)
  5495. (org-last-inserted-timestamp nil))
  5496. (org-schedule '(4)))
  5497. (buffer-string))))
  5498. ;; With C-u C-u argument, prompt for a delay cookie.
  5499. (should
  5500. (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
  5501. (cl-letf (((symbol-function 'org-read-date)
  5502. (lambda (&rest args)
  5503. (apply #'encode-time
  5504. (org-parse-time-string "2014-03-04")))))
  5505. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5506. (let ((org-adapt-indentation nil)
  5507. (org-last-inserted-timestamp nil))
  5508. (org-schedule '(16)))
  5509. (buffer-string)))))
  5510. (should-error
  5511. (cl-letf (((symbol-function 'org-read-date)
  5512. (lambda (&rest args)
  5513. (apply #'encode-time
  5514. (org-parse-time-string "2014-03-04")))))
  5515. (org-test-with-temp-text "* H"
  5516. (let ((org-adapt-indentation nil)
  5517. (org-last-inserted-timestamp nil))
  5518. (org-schedule '(16)))
  5519. (buffer-string))))
  5520. ;; When a region is active and
  5521. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5522. ;; same value in all headlines in region.
  5523. (should
  5524. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5525. (org-test-with-temp-text "* H1\n* H2"
  5526. (let ((org-adapt-indentation nil)
  5527. (org-last-inserted-timestamp nil)
  5528. (org-loop-over-headlines-in-active-region t))
  5529. (transient-mark-mode 1)
  5530. (push-mark (point) t t)
  5531. (goto-char (point-max))
  5532. (org-schedule nil "2012-03-29"))
  5533. (replace-regexp-in-string
  5534. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5535. (should-not
  5536. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5537. (org-test-with-temp-text "* H1\n* H2"
  5538. (let ((org-adapt-indentation nil)
  5539. (org-last-inserted-timestamp nil)
  5540. (org-loop-over-headlines-in-active-region nil))
  5541. (transient-mark-mode 1)
  5542. (push-mark (point) t t)
  5543. (goto-char (point-max))
  5544. (org-schedule nil "2012-03-29"))
  5545. (replace-regexp-in-string
  5546. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5547. (should
  5548. ;; check if a repeater survives re-scheduling.
  5549. (string-match-p
  5550. "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
  5551. (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
  5552. (let ((org-adapt-indentation nil)
  5553. (org-last-inserted-timestamp nil))
  5554. (org-schedule nil "2017-02-01"))
  5555. (buffer-string)))))
  5556. ;;; Property API
  5557. (ert-deftest test-org/buffer-property-keys ()
  5558. "Test `org-buffer-property-keys' specifications."
  5559. ;; Retrieve properties across siblings.
  5560. (should
  5561. (equal '("A" "B")
  5562. (org-test-with-temp-text "
  5563. * H1
  5564. :PROPERTIES:
  5565. :A: 1
  5566. :END:
  5567. * H2
  5568. :PROPERTIES:
  5569. :B: 1
  5570. :END:"
  5571. (org-buffer-property-keys))))
  5572. ;; Retrieve properties across children.
  5573. (should
  5574. (equal '("A" "B")
  5575. (org-test-with-temp-text "
  5576. * H1
  5577. :PROPERTIES:
  5578. :A: 1
  5579. :END:
  5580. ** H2
  5581. :PROPERTIES:
  5582. :B: 1
  5583. :END:"
  5584. (org-buffer-property-keys))))
  5585. ;; Retrieve muliple properties in the same drawer.
  5586. (should
  5587. (equal '("A" "B")
  5588. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5589. (org-buffer-property-keys))))
  5590. ;; Ignore extension symbol in property name.
  5591. (should
  5592. (equal '("A")
  5593. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5594. (org-buffer-property-keys))))
  5595. ;; Add bare property if xxx_ALL property is there
  5596. (should
  5597. (equal '("A" "B" "B_ALL")
  5598. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B_ALL: foo bar\n:END:"
  5599. (org-buffer-property-keys))))
  5600. ;; Add bare property if xxx_ALL property is there - check dupes
  5601. (should
  5602. (equal '("A" "B" "B_ALL")
  5603. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:B_ALL: foo bar\n:END:"
  5604. (org-buffer-property-keys))))
  5605. ;; Retrieve properties from #+PROPERTY keyword lines
  5606. (should
  5607. (equal '("A" "C")
  5608. (org-test-with-temp-text "#+PROPERTY: C foo\n* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5609. (org-buffer-property-keys))))
  5610. ;; Retrieve properties from #+PROPERTY keyword lines - make sure an _ALL property also
  5611. ;; adds the bare property
  5612. (should
  5613. (equal '("A" "C" "C_ALL")
  5614. (org-test-with-temp-text "#+PROPERTY: C_ALL foo bar\n* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5615. (org-buffer-property-keys))))
  5616. ;; With non-nil COLUMNS, extract property names from columns.
  5617. (should
  5618. (equal '("A" "B")
  5619. (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
  5620. (org-buffer-property-keys nil nil t))))
  5621. (should
  5622. (equal '("A" "B" "COLUMNS")
  5623. (org-test-with-temp-text
  5624. "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
  5625. (org-buffer-property-keys nil nil t))))
  5626. ;; In COLUMNS, ignore title and summary-type.
  5627. (should
  5628. (equal '("A")
  5629. (org-test-with-temp-text "#+COLUMNS: %A(Foo)"
  5630. (org-buffer-property-keys nil nil t))))
  5631. (should
  5632. (equal '("A")
  5633. (org-test-with-temp-text "#+COLUMNS: %A{Foo}"
  5634. (org-buffer-property-keys nil nil t))))
  5635. (should
  5636. (equal '("A")
  5637. (org-test-with-temp-text "#+COLUMNS: %A(Foo){Bar}"
  5638. (org-buffer-property-keys nil nil t)))))
  5639. (ert-deftest test-org/property-values ()
  5640. "Test `org-property-values' specifications."
  5641. ;; Regular test.
  5642. (should
  5643. (equal '("2" "1")
  5644. (org-test-with-temp-text
  5645. "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
  5646. (org-property-values "A"))))
  5647. ;; Ignore empty values.
  5648. (should-not
  5649. (org-test-with-temp-text
  5650. "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
  5651. (org-property-values "A")))
  5652. ;; Take into consideration extended values.
  5653. (should
  5654. (equal '("1 2")
  5655. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5656. (org-property-values "A")))))
  5657. (ert-deftest test-org/set-property ()
  5658. "Test `org-set-property' specifications."
  5659. (should
  5660. (equal
  5661. ":PROPERTIES:\n:TEST: t\n:END:\n"
  5662. (org-test-with-temp-text ""
  5663. (let ((org-property-format "%s %s"))
  5664. (org-set-property "TEST" "t"))
  5665. (buffer-string))))
  5666. (should
  5667. (equal
  5668. "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5669. (org-test-with-temp-text "* H"
  5670. (let ((org-adapt-indentation nil)
  5671. (org-property-format "%s %s"))
  5672. (org-set-property "TEST" "t"))
  5673. (buffer-string)))))
  5674. (ert-deftest test-org/delete-property ()
  5675. "Test `org-delete-property' specifications."
  5676. (should
  5677. (equal
  5678. ""
  5679. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5680. (org-delete-property "TEST")
  5681. (buffer-string))))
  5682. (should
  5683. (equal
  5684. ":PROPERTIES:\n:TEST1: t\n:END:\n"
  5685. (org-test-with-temp-text ":PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5686. (org-delete-property "TEST2")
  5687. (buffer-string))))
  5688. (should
  5689. (equal
  5690. "* H\n"
  5691. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5692. (org-delete-property "TEST")
  5693. (buffer-string))))
  5694. (should
  5695. (equal
  5696. "* H\n:PROPERTIES:\n:TEST1: t\n:END:\n"
  5697. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5698. (org-delete-property "TEST2")
  5699. (buffer-string)))))
  5700. (ert-deftest test-org/delete-property-globally ()
  5701. "Test `org-delete-property-global' specifications."
  5702. (should
  5703. (equal
  5704. ""
  5705. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5706. (org-delete-property-globally "TEST")
  5707. (buffer-string))))
  5708. (should
  5709. (equal
  5710. "* H\n"
  5711. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n* H\n:PROPERTIES:\n:TEST: nil\n:END:"
  5712. (org-delete-property-globally "TEST")
  5713. (buffer-string)))))
  5714. (ert-deftest test-org/find-property ()
  5715. "Test `org-find-property' specifications."
  5716. ;; Regular test.
  5717. (should
  5718. (= 1
  5719. (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
  5720. (org-find-property "prop"))))
  5721. ;; Find properties in top-level property drawer.
  5722. (should
  5723. (= 1
  5724. (org-test-with-temp-text ":PROPERTIES:\n:PROP: value\n:END:"
  5725. (org-find-property "prop"))))
  5726. ;; Ignore false positives.
  5727. (should
  5728. (= 27
  5729. (org-test-with-temp-text
  5730. "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
  5731. (org-find-property "A"))))
  5732. ;; Return first entry found in buffer.
  5733. (should
  5734. (= 1
  5735. (org-test-with-temp-text
  5736. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5737. (org-find-property "A"))))
  5738. ;; Only search visible part of the buffer.
  5739. (should
  5740. (= 31
  5741. (org-test-with-temp-text
  5742. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5743. (org-narrow-to-subtree)
  5744. (org-find-property "A"))))
  5745. ;; With optional argument, only find entries with a specific value.
  5746. (should-not
  5747. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5748. (org-find-property "A" "2")))
  5749. (should
  5750. (= 31
  5751. (org-test-with-temp-text
  5752. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
  5753. (org-find-property "A" "2"))))
  5754. ;; Use "nil" for explicit nil values.
  5755. (should
  5756. (= 31
  5757. (org-test-with-temp-text
  5758. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
  5759. (org-find-property "A" "nil")))))
  5760. (ert-deftest test-org/entry-delete ()
  5761. "Test `org-entry-delete' specifications."
  5762. ;; Regular test.
  5763. (should
  5764. (string-match
  5765. " *:PROPERTIES:\n *:B: +2\n *:END:"
  5766. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5767. (org-entry-delete (point) "A")
  5768. (buffer-string))))
  5769. ;; Also remove accumulated properties.
  5770. (should-not
  5771. (string-match
  5772. ":A"
  5773. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
  5774. (org-entry-delete (point) "A")
  5775. (buffer-string))))
  5776. ;; When last property is removed, remove the property drawer.
  5777. (should-not
  5778. (string-match
  5779. ":PROPERTIES:"
  5780. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
  5781. (org-entry-delete (point) "A")
  5782. (buffer-string))))
  5783. ;; Return a non-nil value when some property was removed.
  5784. (should
  5785. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5786. (org-entry-delete (point) "A")))
  5787. (should-not
  5788. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5789. (org-entry-delete (point) "C")))
  5790. ;; Special properties cannot be located in a drawer. Allow to
  5791. ;; remove them anyway, in case of user error.
  5792. (should
  5793. (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
  5794. (org-entry-delete (point) "SCHEDULED"))))
  5795. (ert-deftest test-org/entry-get ()
  5796. "Test `org-entry-get' specifications."
  5797. ;; Regular test.
  5798. (should
  5799. (equal "1"
  5800. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:"
  5801. (org-entry-get (point) "A"))))
  5802. (should
  5803. (equal "1"
  5804. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5805. (org-entry-get (point) "A"))))
  5806. ;; Ignore case.
  5807. (should
  5808. (equal "1"
  5809. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5810. (org-entry-get (point) "a"))))
  5811. ;; Handle extended values, both before and after base value.
  5812. (should
  5813. (equal "1 2 3"
  5814. (org-test-with-temp-text
  5815. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5816. (org-entry-get (point) "A"))))
  5817. ;; Empty values are returned as the empty string.
  5818. (should
  5819. (equal ""
  5820. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
  5821. (org-entry-get (point) "A"))))
  5822. ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
  5823. ;; otherwise, return nil.
  5824. (should-not
  5825. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5826. (org-entry-get (point) "A")))
  5827. (should
  5828. (equal "nil"
  5829. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5830. (org-entry-get (point) "A" nil t))))
  5831. ;; Return nil when no property is found, independently on the
  5832. ;; LITERAL-NIL argument.
  5833. (should-not
  5834. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5835. (org-entry-get (point) "B")))
  5836. (should-not
  5837. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5838. (org-entry-get (point) "B" nil t)))
  5839. ;; Handle inheritance, when allowed. Include extended values and
  5840. ;; possibly global values.
  5841. (should
  5842. (equal
  5843. "1"
  5844. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:\n* H"
  5845. (org-entry-get (point-max) "A" t))))
  5846. (should
  5847. (equal
  5848. "1"
  5849. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5850. (org-entry-get (point-max) "A" t))))
  5851. (should
  5852. (equal
  5853. "1"
  5854. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5855. (let ((org-use-property-inheritance t))
  5856. (org-entry-get (point-max) "A" 'selective)))))
  5857. (should-not
  5858. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5859. (let ((org-use-property-inheritance nil))
  5860. (org-entry-get (point-max) "A" 'selective))))
  5861. (should-not
  5862. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H2"
  5863. (let ((org-use-property-inheritance t))
  5864. (org-entry-get (point-max) "A" t))))
  5865. (should
  5866. (equal
  5867. "1 2"
  5868. (org-test-with-temp-text
  5869. ":PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5870. (org-entry-get (point-max) "A" t))))
  5871. (should
  5872. (equal
  5873. "1 2"
  5874. (org-test-with-temp-text
  5875. "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5876. (org-entry-get (point-max) "A" t))))
  5877. (should
  5878. (equal
  5879. "1 2"
  5880. (org-test-with-temp-text
  5881. ":PROPERTIES:\n:A: 1\n:END:\n* H1\n* H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5882. (org-entry-get (point-max) "A" t))))
  5883. (should
  5884. (equal
  5885. "1 2"
  5886. (org-test-with-temp-text
  5887. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2.1\n** H2.2\n:PROPERTIES:\n:A+: 2\n:END:"
  5888. (org-entry-get (point-max) "A" t))))
  5889. (should
  5890. (equal "1"
  5891. (org-test-with-temp-text
  5892. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
  5893. (org-mode-restart)
  5894. (org-entry-get (point-max) "A" t))))
  5895. (should
  5896. (equal "0 1"
  5897. (org-test-with-temp-text
  5898. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
  5899. (org-mode-restart)
  5900. (org-entry-get (point-max) "A" t))))
  5901. ;; document level property-drawer has precedance over
  5902. ;; global-property by PROPERTY-keyword.
  5903. (should
  5904. (equal "0 2"
  5905. (org-test-with-temp-text
  5906. ":PROPERTIES:\n:A: 0\n:END:\n#+PROPERTY: A 1\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5907. (org-mode-restart)
  5908. (org-entry-get (point-max) "A" t))))
  5909. ;; Use alternate separators
  5910. (should
  5911. (equal "0~2"
  5912. (org-test-with-temp-text
  5913. ":PROPERTIES:\n:A: 0\n:A+: 2\n:END:"
  5914. (let ((org-property-separators '((("A") . "~"))))
  5915. (org-entry-get (point) "A")))))
  5916. ;; Default separator is single space
  5917. (should
  5918. (equal "0 2"
  5919. (org-test-with-temp-text
  5920. ":PROPERTIES:\n:A: 0\n:B: 1\n:A+: 2\n:B+: 3\n:END:"
  5921. (let ((org-property-separators '((("B") . "~"))))
  5922. (org-entry-get (point) "A")))))
  5923. ;; Regular expression matching for separator
  5924. (should
  5925. (equal "0/2"
  5926. (org-test-with-temp-text
  5927. ":PROPERTIES:\n:A: 0\n:A+: 2\n:END:"
  5928. (let ((org-property-separators '((("B") . "~") ("[AC]" . "/"))))
  5929. (org-entry-get (point) "A")))))
  5930. ;; Separator works with inheritance
  5931. (should
  5932. (equal "1~2"
  5933. (org-test-with-temp-text
  5934. "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5935. (let ((org-property-separators '((("A") . "~"))))
  5936. (org-entry-get (point-max) "A" t))))))
  5937. (ert-deftest test-org/entry-properties ()
  5938. "Test `org-entry-properties' specifications."
  5939. ;; Get "ITEM" property.
  5940. (should
  5941. (equal "H"
  5942. (org-test-with-temp-text "* TODO H"
  5943. (cdr (assoc "ITEM" (org-entry-properties nil "ITEM"))))))
  5944. (should
  5945. (equal "H"
  5946. (org-test-with-temp-text "* TODO H"
  5947. (cdr (assoc "ITEM" (org-entry-properties))))))
  5948. ;; Get "TODO" property. TODO keywords are case sensitive.
  5949. (should
  5950. (equal "TODO"
  5951. (org-test-with-temp-text "* TODO H"
  5952. (cdr (assoc "TODO" (org-entry-properties nil "TODO"))))))
  5953. (should
  5954. (equal "TODO"
  5955. (org-test-with-temp-text "* TODO H"
  5956. (cdr (assoc "TODO" (org-entry-properties))))))
  5957. (should-not
  5958. (org-test-with-temp-text "* H"
  5959. (assoc "TODO" (org-entry-properties nil "TODO"))))
  5960. (should-not
  5961. (org-test-with-temp-text "* todo H"
  5962. (assoc "TODO" (org-entry-properties nil "TODO"))))
  5963. ;; Get "PRIORITY" property.
  5964. (should
  5965. (equal "A"
  5966. (org-test-with-temp-text "* [#A] H"
  5967. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  5968. (should
  5969. (equal "A"
  5970. (org-test-with-temp-text "* [#A] H"
  5971. (cdr (assoc "PRIORITY" (org-entry-properties))))))
  5972. (should
  5973. (equal (char-to-string org-priority-default)
  5974. (org-test-with-temp-text "* H"
  5975. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  5976. ;; Get "FILE" property.
  5977. (should
  5978. (org-test-with-temp-text-in-file "* H\nParagraph"
  5979. (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil "FILE")))
  5980. (buffer-file-name))))
  5981. (should
  5982. (org-test-with-temp-text-in-file "* H\nParagraph"
  5983. (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
  5984. (buffer-file-name))))
  5985. (should-not
  5986. (org-test-with-temp-text "* H\nParagraph"
  5987. (cdr (assoc "FILE" (org-entry-properties nil "FILE")))))
  5988. ;; Get "TAGS" property.
  5989. (should
  5990. (equal ":tag1:tag2:"
  5991. (org-test-with-temp-text "* H :tag1:tag2:"
  5992. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS"))))))
  5993. (should
  5994. (equal ":tag1:tag2:"
  5995. (org-test-with-temp-text "* H :tag1:tag2:"
  5996. (cdr (assoc "TAGS" (org-entry-properties))))))
  5997. (should-not
  5998. (org-test-with-temp-text "* H"
  5999. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS")))))
  6000. ;; Get "ALLTAGS" property.
  6001. (should
  6002. (equal ":tag1:tag2:"
  6003. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  6004. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS"))))))
  6005. (should
  6006. (equal ":tag1:tag2:"
  6007. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  6008. (cdr (assoc "ALLTAGS" (org-entry-properties))))))
  6009. (should-not
  6010. (org-test-with-temp-text "* H"
  6011. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS")))))
  6012. ;; Get "BLOCKED" property.
  6013. (should
  6014. (equal "t"
  6015. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  6016. (let ((org-enforce-todo-dependencies t)
  6017. (org-blocker-hook
  6018. '(org-block-todo-from-children-or-siblings-or-parent)))
  6019. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  6020. (should
  6021. (equal ""
  6022. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  6023. (let ((org-enforce-todo-dependencies t)
  6024. (org-blocker-hook
  6025. '(org-block-todo-from-children-or-siblings-or-parent)))
  6026. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  6027. ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
  6028. (should
  6029. (equal
  6030. "[2012-03-29 thu.]"
  6031. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  6032. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED"))))))
  6033. (should
  6034. (equal
  6035. "[2012-03-29 thu.]"
  6036. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  6037. (cdr (assoc "CLOSED" (org-entry-properties))))))
  6038. (should-not
  6039. (org-test-with-temp-text "* H"
  6040. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED")))))
  6041. (should
  6042. (equal
  6043. "<2014-03-04 tue.>"
  6044. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6045. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE"))))))
  6046. (should
  6047. (equal
  6048. "<2014-03-04 tue.>"
  6049. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6050. (cdr (assoc "DEADLINE" (org-entry-properties))))))
  6051. (should-not
  6052. (org-test-with-temp-text "* H"
  6053. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE")))))
  6054. (should
  6055. (equal
  6056. "<2014-03-04 tue.>"
  6057. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6058. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED"))))))
  6059. (should
  6060. (equal
  6061. "<2014-03-04 tue.>"
  6062. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6063. (cdr (assoc "SCHEDULED" (org-entry-properties))))))
  6064. (should-not
  6065. (org-test-with-temp-text "* H"
  6066. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED")))))
  6067. ;; Get "CATEGORY"
  6068. (should
  6069. (equal "cat"
  6070. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  6071. (cdr (assoc "CATEGORY" (org-entry-properties))))))
  6072. (should
  6073. (equal "cat"
  6074. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  6075. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  6076. (should
  6077. (equal "cat"
  6078. (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
  6079. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  6080. (should
  6081. (equal "cat2"
  6082. (org-test-with-temp-text
  6083. (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6084. "\n"
  6085. "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
  6086. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  6087. ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
  6088. (should
  6089. (equal "<2012-03-29 thu.>"
  6090. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
  6091. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  6092. (should
  6093. (equal "[2012-03-29 thu.]"
  6094. (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
  6095. (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
  6096. (should
  6097. (equal "<2012-03-29 thu.>"
  6098. (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
  6099. (cdr (assoc "TIMESTAMP" (org-entry-properties nil "TIMESTAMP"))))))
  6100. (should
  6101. (equal "[2014-03-04 tue.]"
  6102. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
  6103. (cdr (assoc "TIMESTAMP_IA"
  6104. (org-entry-properties nil "TIMESTAMP_IA"))))))
  6105. (should-not
  6106. (equal "<2012-03-29 thu.>"
  6107. (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
  6108. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  6109. ;; Get standard properties.
  6110. (should
  6111. (equal "1"
  6112. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6113. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  6114. ;; Handle extended properties.
  6115. (should
  6116. (equal "1 2 3"
  6117. (org-test-with-temp-text
  6118. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  6119. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  6120. (should
  6121. (equal "1 2 3"
  6122. (org-test-with-temp-text
  6123. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
  6124. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  6125. ;; Ignore forbidden (special) properties.
  6126. (should-not
  6127. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
  6128. (cdr (assoc "TODO" (org-entry-properties nil 'standard))))))
  6129. (ert-deftest test-org/entry-put ()
  6130. "Test `org-entry-put' specifications."
  6131. ;; Error when not a string or nil.
  6132. (should-error
  6133. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  6134. (org-entry-put 1 "test" 2)))
  6135. ;; Error when property name is invalid.
  6136. (should-error
  6137. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  6138. (org-entry-put 1 "no space" "value")))
  6139. (should-error
  6140. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  6141. (org-entry-put 1 "" "value")))
  6142. ;; Set "TODO" property.
  6143. (should
  6144. (string-match (regexp-quote " TODO H")
  6145. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  6146. (org-entry-put (point) "TODO" "TODO")
  6147. (buffer-string))))
  6148. (should
  6149. (string-match (regexp-quote "* H")
  6150. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  6151. (org-entry-put (point) "TODO" nil)
  6152. (buffer-string))))
  6153. ;; Set "PRIORITY" property.
  6154. (should
  6155. (equal "* [#A] H"
  6156. (org-test-with-temp-text "* [#B] H"
  6157. (org-entry-put (point) "PRIORITY" "A")
  6158. (buffer-string))))
  6159. (should
  6160. (equal "* H"
  6161. (org-test-with-temp-text "* [#B] H"
  6162. (org-entry-put (point) "PRIORITY" nil)
  6163. (buffer-string))))
  6164. ;; Set "SCHEDULED" property.
  6165. (should
  6166. (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
  6167. (org-test-with-temp-text "* H"
  6168. (org-entry-put (point) "SCHEDULED" "2014-03-04")
  6169. (buffer-string))))
  6170. (should
  6171. (string= "* H\n"
  6172. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6173. (org-entry-put (point) "SCHEDULED" nil)
  6174. (buffer-string))))
  6175. (should
  6176. (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
  6177. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6178. (org-entry-put (point) "SCHEDULED" "earlier")
  6179. (buffer-string))))
  6180. (should
  6181. (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
  6182. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6183. (org-entry-put (point) "SCHEDULED" "later")
  6184. (buffer-string))))
  6185. ;; Set "DEADLINE" property.
  6186. (should
  6187. (string-match "^ *DEADLINE: <2014-03-04 .*?>"
  6188. (org-test-with-temp-text "* H"
  6189. (org-entry-put (point) "DEADLINE" "2014-03-04")
  6190. (buffer-string))))
  6191. (should
  6192. (string= "* H\n"
  6193. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6194. (org-entry-put (point) "DEADLINE" nil)
  6195. (buffer-string))))
  6196. (should
  6197. (string-match "^ *DEADLINE: <2014-03-03 .*?>"
  6198. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6199. (org-entry-put (point) "DEADLINE" "earlier")
  6200. (buffer-string))))
  6201. (should
  6202. (string-match "^ *DEADLINE: <2014-03-05 .*?>"
  6203. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6204. (org-entry-put (point) "DEADLINE" "later")
  6205. (buffer-string))))
  6206. ;; Set "CATEGORY" property
  6207. (should
  6208. (string-match "^ *:CATEGORY: cat"
  6209. (org-test-with-temp-text "* H"
  6210. (org-entry-put (point) "CATEGORY" "cat")
  6211. (buffer-string))))
  6212. ;; Regular properties, with or without pre-existing drawer.
  6213. (should
  6214. (string-match "^ *:A: +2$"
  6215. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6216. (org-entry-put (point) "A" "2")
  6217. (buffer-string))))
  6218. (should
  6219. (string-match "^ *:A: +1$"
  6220. (org-test-with-temp-text "* H"
  6221. (org-entry-put (point) "A" "1")
  6222. (buffer-string))))
  6223. ;; Special case: two consecutive headlines.
  6224. (should
  6225. (string-match "\\* A\n *:PROPERTIES:"
  6226. (org-test-with-temp-text "* A\n** B"
  6227. (org-entry-put (point) "A" "1")
  6228. (buffer-string)))))
  6229. (ert-deftest test-org/refresh-properties ()
  6230. "Test `org-refresh-properties' specifications."
  6231. (should
  6232. (equal "1"
  6233. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6234. (org-refresh-properties "A" 'org-test)
  6235. (get-text-property (point) 'org-test))))
  6236. (should-not
  6237. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6238. (org-refresh-properties "B" 'org-test)
  6239. (get-text-property (point) 'org-test)))
  6240. ;; Handle properties only defined with extension syntax, i.e.,
  6241. ;; "PROPERTY+".
  6242. (should
  6243. (equal "1"
  6244. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
  6245. (org-refresh-properties "A" 'org-test)
  6246. (get-text-property (point) 'org-test))))
  6247. ;; When property is inherited, add text property to the whole
  6248. ;; sub-tree.
  6249. (should
  6250. (equal "1"
  6251. (org-test-with-temp-text
  6252. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
  6253. (let ((org-use-property-inheritance t))
  6254. (org-refresh-properties "A" 'org-test))
  6255. (get-text-property (point) 'org-test))))
  6256. ;; When a document level property-drawer is used, those properties
  6257. ;; should work exactly like headline-properties as if at a
  6258. ;; headline-level 0.
  6259. (should
  6260. (equal "1"
  6261. (org-test-with-temp-text
  6262. ":PROPERTIES:\n:A: 1\n:END:\n"
  6263. (org-mode-restart)
  6264. (let ((org-use-property-inheritance t))
  6265. (org-refresh-properties "A" 'org-test))
  6266. (get-text-property (point) 'org-test))))
  6267. (should-not
  6268. (equal "1"
  6269. (org-test-with-temp-text
  6270. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  6271. (org-mode-restart)
  6272. (let ((org-use-property-inheritance nil))
  6273. (org-refresh-properties "A" 'org-test))
  6274. (get-text-property (point) 'org-test))))
  6275. (should
  6276. (equal "1"
  6277. (org-test-with-temp-text
  6278. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  6279. (org-mode-restart)
  6280. (let ((org-use-property-inheritance t))
  6281. (org-refresh-properties "A" 'org-test))
  6282. (get-text-property (point) 'org-test))))
  6283. (should
  6284. (equal "2"
  6285. (org-test-with-temp-text
  6286. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1\n:PROPERTIES:\n:A: 2\n:END:"
  6287. (org-mode-restart)
  6288. (let ((org-use-property-inheritance t))
  6289. (org-refresh-properties "A" 'org-test))
  6290. (get-text-property (point) 'org-test))))
  6291. ;; When property is inherited, use global value across the whole
  6292. ;; buffer. However local values have precedence, as well as the
  6293. ;; document level property-drawer.
  6294. (should-not
  6295. (equal "1"
  6296. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  6297. (org-mode-restart)
  6298. (let ((org-use-property-inheritance nil))
  6299. (org-refresh-properties "A" 'org-test))
  6300. (get-text-property (point) 'org-test))))
  6301. (should
  6302. (equal "1"
  6303. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  6304. (org-mode-restart)
  6305. (let ((org-use-property-inheritance t))
  6306. (org-refresh-properties "A" 'org-test))
  6307. (get-text-property (point) 'org-test))))
  6308. (should
  6309. (equal "2"
  6310. (org-test-with-temp-text
  6311. "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
  6312. (org-mode-restart)
  6313. (let ((org-use-property-inheritance t))
  6314. (org-refresh-properties "A" 'org-test))
  6315. (get-text-property (point) 'org-test))))
  6316. ;; When both keyword-property and document-level property-block is
  6317. ;; defined, the property-block has precedance.
  6318. (should
  6319. (equal "1"
  6320. (org-test-with-temp-text
  6321. ":PROPERTIES:\n:A: 1\n:END:\n#+PROPERTY: A 2\n<point>* H1"
  6322. (org-mode-restart)
  6323. (let ((org-use-property-inheritance t))
  6324. (org-refresh-properties "A" 'org-test))
  6325. (get-text-property (point) 'org-test)))))
  6326. (ert-deftest test-org/refresh-category-properties ()
  6327. "Test `org-refresh-category-properties' specifications"
  6328. (should
  6329. (equal "cat1"
  6330. (org-test-with-temp-text
  6331. ":PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6332. (org-refresh-category-properties)
  6333. (org-get-category))))
  6334. (should
  6335. (equal "cat1"
  6336. (org-test-with-temp-text
  6337. "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6338. (org-refresh-category-properties)
  6339. (org-get-category))))
  6340. ;; Even though property-inheritance is deactivated, category
  6341. ;; property should be inherited. As described in
  6342. ;; `org-use-property-inheritance'.
  6343. (should
  6344. (equal "cat1"
  6345. (org-test-with-temp-text
  6346. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  6347. (org-mode-restart)
  6348. (let ((org-use-property-inheritance nil))
  6349. (org-refresh-category-properties))
  6350. (org-get-category))))
  6351. (should
  6352. (equal "cat1"
  6353. (org-test-with-temp-text
  6354. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  6355. (org-mode-restart)
  6356. (let ((org-use-property-inheritance t))
  6357. (org-refresh-category-properties))
  6358. (org-get-category))))
  6359. (should
  6360. (equal "cat2"
  6361. (org-test-with-temp-text
  6362. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H\n:PROPERTIES:\n:CATEGORY: cat2\n:END:\n"
  6363. (org-mode-restart)
  6364. (let ((org-use-property-inheritance t))
  6365. (org-refresh-category-properties))
  6366. (org-get-category)))))
  6367. ;;; Refile
  6368. (ert-deftest test-org/refile-get-targets ()
  6369. "Test `org-refile-get-targets' specifications."
  6370. ;; :maxlevel includes all headings above specified value.
  6371. (should
  6372. (equal '("H1" "H2" "H3")
  6373. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6374. (let ((org-refile-use-outline-path nil)
  6375. (org-refile-targets `((nil :maxlevel . 3))))
  6376. (mapcar #'car (org-refile-get-targets))))))
  6377. (should
  6378. (equal '("H1" "H2")
  6379. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6380. (let ((org-refile-use-outline-path nil)
  6381. (org-refile-targets `((nil :maxlevel . 2))))
  6382. (mapcar #'car (org-refile-get-targets))))))
  6383. ;; :level limits targets to headlines with the specified level.
  6384. (should
  6385. (equal '("H2")
  6386. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6387. (let ((org-refile-use-outline-path nil)
  6388. (org-refile-targets `((nil :level . 2))))
  6389. (mapcar #'car (org-refile-get-targets))))))
  6390. ;; :tag limits targets to headlines with specified tag.
  6391. (should
  6392. (equal '("H1")
  6393. (org-test-with-temp-text "* H1 :foo:\n** H2\n*** H3 :bar:"
  6394. (let ((org-refile-use-outline-path nil)
  6395. (org-refile-targets `((nil :tag . "foo"))))
  6396. (mapcar #'car (org-refile-get-targets))))))
  6397. ;; :todo limits targets to headlines with specified TODO keyword.
  6398. (should
  6399. (equal '("H2")
  6400. (org-test-with-temp-text "* H1\n** TODO H2\n*** DONE H3"
  6401. (let ((org-refile-use-outline-path nil)
  6402. (org-refile-targets `((nil :todo . "TODO"))))
  6403. (mapcar #'car (org-refile-get-targets))))))
  6404. ;; :regexp filters targets matching provided regexp.
  6405. (should
  6406. (equal '("F2" "F3")
  6407. (org-test-with-temp-text "* H1\n** F2\n*** F3"
  6408. (let ((org-refile-use-outline-path nil)
  6409. (org-refile-targets `((nil :regexp . "F"))))
  6410. (mapcar #'car (org-refile-get-targets))))))
  6411. ;; A nil `org-refile-targets' includes only top level headlines in
  6412. ;; current buffer.
  6413. (should
  6414. (equal '("H1" "H2")
  6415. (org-test-with-temp-text "* H1\n** S1\n* H2"
  6416. (let ((org-refile-use-outline-path nil)
  6417. (org-refile-targets nil))
  6418. (mapcar #'car (org-refile-get-targets))))))
  6419. ;; Return value is the union of the targets according to all the
  6420. ;; defined rules. However, prevent duplicates.
  6421. (should
  6422. (equal '("F2" "F3" "H1")
  6423. (org-test-with-temp-text "* TODO H1\n** F2\n*** F3"
  6424. (let ((org-refile-use-outline-path nil)
  6425. (org-refile-targets `((nil :regexp . "F")
  6426. (nil :todo . "TODO"))))
  6427. (mapcar #'car (org-refile-get-targets))))))
  6428. (should
  6429. (equal '("F2" "F3" "H1")
  6430. (org-test-with-temp-text "* TODO H1\n** TODO F2\n*** F3"
  6431. (let ((org-refile-use-outline-path nil)
  6432. (org-refile-targets `((nil :regexp . "F")
  6433. (nil :todo . "TODO"))))
  6434. (mapcar #'car (org-refile-get-targets))))))
  6435. ;; When `org-refile-use-outline-path' is non-nil, provide targets as
  6436. ;; paths.
  6437. (should
  6438. (equal '("H1" "H1/H2" "H1/H2/H3")
  6439. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6440. (let ((org-refile-use-outline-path t)
  6441. (org-refile-targets `((nil :maxlevel . 3))))
  6442. (mapcar #'car (org-refile-get-targets))))))
  6443. ;; When providing targets as paths, escape forward slashes in
  6444. ;; headings with backslashes.
  6445. (should
  6446. (equal '("H1\\/foo")
  6447. (org-test-with-temp-text "* H1/foo"
  6448. (let ((org-refile-use-outline-path t)
  6449. (org-refile-targets `((nil :maxlevel . 1))))
  6450. (mapcar #'car (org-refile-get-targets))))))
  6451. ;; When `org-refile-use-outline-path' is `file', include file name
  6452. ;; without directory in targets.
  6453. (should
  6454. (org-test-with-temp-text-in-file "* H1"
  6455. (let* ((filename (buffer-file-name))
  6456. (org-refile-use-outline-path 'file)
  6457. (org-refile-targets `(((,filename) :level . 1))))
  6458. (member (file-name-nondirectory filename)
  6459. (mapcar #'car (org-refile-get-targets))))))
  6460. ;; When `org-refile-use-outline-path' is `full-file-path', include
  6461. ;; full file name.
  6462. (should
  6463. (org-test-with-temp-text-in-file "* H1"
  6464. (let* ((filename (file-truename (buffer-file-name)))
  6465. (org-refile-use-outline-path 'full-file-path)
  6466. (org-refile-targets `(((,filename) :level . 1))))
  6467. (member filename (mapcar #'car (org-refile-get-targets))))))
  6468. ;; When `org-refile-use-outline-path' is `buffer-name', include
  6469. ;; buffer name.
  6470. (should
  6471. (org-test-with-temp-text "* H1"
  6472. (let* ((org-refile-use-outline-path 'buffer-name)
  6473. (org-refile-targets `((nil :level . 1))))
  6474. (member (buffer-name) (mapcar #'car (org-refile-get-targets)))))))
  6475. ;;; Sparse trees
  6476. (ert-deftest test-org/match-sparse-tree ()
  6477. "Test `org-match-sparse-tree' specifications."
  6478. ;; Match tags.
  6479. (should-not
  6480. (org-test-with-temp-text "* H\n** H1 :tag:"
  6481. (org-match-sparse-tree nil "tag")
  6482. (search-forward "H1")
  6483. (org-invisible-p2)))
  6484. (should
  6485. (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
  6486. (org-match-sparse-tree nil "tag")
  6487. (search-forward "H2")
  6488. (org-invisible-p2)))
  6489. ;; "-" operator for tags.
  6490. (should-not
  6491. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6492. (org-match-sparse-tree nil "tag1-tag2")
  6493. (search-forward "H1")
  6494. (org-invisible-p2)))
  6495. (should
  6496. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6497. (org-match-sparse-tree nil "tag1-tag2")
  6498. (search-forward "H2")
  6499. (org-invisible-p2)))
  6500. ;; "&" operator for tags.
  6501. (should
  6502. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6503. (org-match-sparse-tree nil "tag1&tag2")
  6504. (search-forward "H1")
  6505. (org-invisible-p2)))
  6506. (should-not
  6507. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6508. (org-match-sparse-tree nil "tag1&tag2")
  6509. (search-forward "H2")
  6510. (org-invisible-p2)))
  6511. ;; "|" operator for tags.
  6512. (should-not
  6513. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6514. (org-match-sparse-tree nil "tag1|tag2")
  6515. (search-forward "H1")
  6516. (org-invisible-p2)))
  6517. (should-not
  6518. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6519. (org-match-sparse-tree nil "tag1|tag2")
  6520. (search-forward "H2")
  6521. (org-invisible-p2)))
  6522. ;; Regexp match on tags.
  6523. (should-not
  6524. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6525. (org-match-sparse-tree nil "{^tag.*}")
  6526. (search-forward "H1")
  6527. (org-invisible-p2)))
  6528. (should
  6529. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6530. (org-match-sparse-tree nil "{^tag.*}")
  6531. (search-forward "H2")
  6532. (org-invisible-p2)))
  6533. ;; Match group tags.
  6534. (should-not
  6535. (org-test-with-temp-text
  6536. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6537. (org-match-sparse-tree nil "work")
  6538. (search-forward "H1")
  6539. (org-invisible-p2)))
  6540. (should-not
  6541. (org-test-with-temp-text
  6542. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6543. (org-match-sparse-tree nil "work")
  6544. (search-forward "H2")
  6545. (org-invisible-p2)))
  6546. ;; Match group tags with hard brackets.
  6547. (should-not
  6548. (org-test-with-temp-text
  6549. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6550. (org-match-sparse-tree nil "work")
  6551. (search-forward "H1")
  6552. (org-invisible-p2)))
  6553. (should-not
  6554. (org-test-with-temp-text
  6555. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6556. (org-match-sparse-tree nil "work")
  6557. (search-forward "H2")
  6558. (org-invisible-p2)))
  6559. ;; Match tags in hierarchies
  6560. (should-not
  6561. (org-test-with-temp-text
  6562. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6563. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6564. #+TAGS: { Lev_3 : Lev_4 }\n
  6565. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6566. (org-match-sparse-tree nil "Lev_1")
  6567. (search-forward "H4")
  6568. (org-invisible-p2)))
  6569. (should-not
  6570. (org-test-with-temp-text
  6571. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6572. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6573. #+TAGS: { Lev_3 : Lev_4 }\n
  6574. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6575. (org-match-sparse-tree nil "Lev_1+Lev_3")
  6576. (search-forward "H4")
  6577. (org-invisible-p2)))
  6578. ;; Match regular expressions in tags
  6579. (should-not
  6580. (org-test-with-temp-text
  6581. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
  6582. (org-match-sparse-tree nil "Lev")
  6583. (search-forward "H1")
  6584. (org-invisible-p2)))
  6585. (should
  6586. (org-test-with-temp-text
  6587. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
  6588. (org-match-sparse-tree nil "Lev")
  6589. (search-forward "H1")
  6590. (org-invisible-p2)))
  6591. ;; Match properties.
  6592. (should
  6593. (org-test-with-temp-text
  6594. "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
  6595. (org-match-sparse-tree nil "A=\"1\"")
  6596. (search-forward "H2")
  6597. (org-invisible-p2)))
  6598. (should-not
  6599. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6600. (org-match-sparse-tree nil "A=\"1\"")
  6601. (search-forward "H2")
  6602. (org-invisible-p2)))
  6603. ;; Case is not significant when matching properties.
  6604. (should-not
  6605. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6606. (org-match-sparse-tree nil "a=\"1\"")
  6607. (search-forward "H2")
  6608. (org-invisible-p2)))
  6609. (should-not
  6610. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
  6611. (org-match-sparse-tree nil "A=\"1\"")
  6612. (search-forward "H2")
  6613. (org-invisible-p2)))
  6614. ;; Match special LEVEL property.
  6615. (should-not
  6616. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6617. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6618. (search-forward "H1")
  6619. (org-invisible-p2)))
  6620. (should
  6621. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6622. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6623. (search-forward "H2")
  6624. (org-invisible-p2)))
  6625. ;; Comparison operators when matching properties.
  6626. (should
  6627. (org-test-with-temp-text
  6628. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6629. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6630. (search-forward "H1")
  6631. (org-invisible-p2)))
  6632. (should-not
  6633. (org-test-with-temp-text
  6634. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6635. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6636. (search-forward "H2")
  6637. (org-invisible-p2)))
  6638. ;; Regexp match on properties values.
  6639. (should-not
  6640. (org-test-with-temp-text
  6641. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6642. (org-match-sparse-tree nil "A={f.*}")
  6643. (search-forward "H1")
  6644. (org-invisible-p2)))
  6645. (should
  6646. (org-test-with-temp-text
  6647. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6648. (org-match-sparse-tree nil "A={f.*}")
  6649. (search-forward "H2")
  6650. (org-invisible-p2)))
  6651. ;; With an optional argument, limit match to TODO entries.
  6652. (should-not
  6653. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6654. (org-match-sparse-tree t "tag")
  6655. (search-forward "H1")
  6656. (org-invisible-p2)))
  6657. (should
  6658. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6659. (org-match-sparse-tree t "tag")
  6660. (search-forward "H2")
  6661. (org-invisible-p2))))
  6662. (ert-deftest test-org/occur ()
  6663. "Test `org-occur' specifications."
  6664. ;; Count number of matches.
  6665. (should
  6666. (= 1
  6667. (org-test-with-temp-text "* H\nA\n* H2"
  6668. (org-occur "A"))))
  6669. (should
  6670. (= 2
  6671. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6672. (org-occur "A"))))
  6673. ;; Test CALLBACK optional argument.
  6674. (should
  6675. (= 0
  6676. (org-test-with-temp-text "* H\nA\n* H2"
  6677. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6678. (should
  6679. (= 1
  6680. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6681. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6682. ;; Case-fold searches according to `org-occur-case-fold-search'.
  6683. (should
  6684. (= 2
  6685. (org-test-with-temp-text "Aa"
  6686. (let ((org-occur-case-fold-search t)) (org-occur "A")))))
  6687. (should
  6688. (= 2
  6689. (org-test-with-temp-text "Aa"
  6690. (let ((org-occur-case-fold-search t)) (org-occur "a")))))
  6691. (should
  6692. (= 1
  6693. (org-test-with-temp-text "Aa"
  6694. (let ((org-occur-case-fold-search nil)) (org-occur "A")))))
  6695. (should
  6696. (= 1
  6697. (org-test-with-temp-text "Aa"
  6698. (let ((org-occur-case-fold-search nil)) (org-occur "a")))))
  6699. (should
  6700. (= 1
  6701. (org-test-with-temp-text "Aa"
  6702. (let ((org-occur-case-fold-search 'smart)) (org-occur "A")))))
  6703. (should
  6704. (= 2
  6705. (org-test-with-temp-text "Aa"
  6706. (let ((org-occur-case-fold-search 'smart)) (org-occur "a"))))))
  6707. ;;; Tags
  6708. (ert-deftest test-org/tag-string-to-alist ()
  6709. "Test `org-tag-string-to-alist' specifications."
  6710. ;; Tag without selection key.
  6711. (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
  6712. ;; Tag with selection key.
  6713. (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t))))
  6714. ;; Tag group.
  6715. (should
  6716. (equal
  6717. (org-tag-string-to-alist "[ group : t1 t2 ]")
  6718. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag))))
  6719. ;; Mutually exclusive tags.
  6720. (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
  6721. '((:startgroup) ("tag1") ("tag2") (:endgroup))))
  6722. (should
  6723. (equal
  6724. (org-tag-string-to-alist "{ group : tag1 tag2 }")
  6725. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))))
  6726. (ert-deftest test-org/tag-alist-to-string ()
  6727. "Test `org-tag-alist-to-string' specifications."
  6728. (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
  6729. (should (equal (org-tag-alist-to-string '(("tag1" . ?t))) "tag1(t)"))
  6730. (should
  6731. (equal
  6732. (org-tag-alist-to-string
  6733. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6734. "[ group : t1 t2 ]"))
  6735. (should
  6736. (equal (org-tag-alist-to-string
  6737. '((:startgroup) ("tag1") ("tag2") (:endgroup)))
  6738. "{ tag1 tag2 }"))
  6739. (should
  6740. (equal
  6741. (org-tag-alist-to-string
  6742. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))
  6743. "{ group : tag1 tag2 }")))
  6744. (ert-deftest test-org/tag-alist-to-groups ()
  6745. "Test `org-tag-alist-to-groups' specifications."
  6746. (should
  6747. (equal (org-tag-alist-to-groups
  6748. '((:startgroup) ("group") (:grouptags) ("t1") ("t2") (:endgroup)))
  6749. '(("group" "t1" "t2"))))
  6750. (should
  6751. (equal
  6752. (org-tag-alist-to-groups
  6753. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6754. '(("group" "t1" "t2"))))
  6755. (should-not
  6756. (org-tag-alist-to-groups
  6757. '((:startgroup) ("group") ("t1") ("t2") (:endgroup)))))
  6758. (ert-deftest test-org/tag-align ()
  6759. "Test tags alignment."
  6760. ;; Test aligning tags with different display width.
  6761. (should
  6762. ;; 12345678901234567890
  6763. (equal "* Test :abc:"
  6764. (org-test-with-temp-text "* Test :abc:"
  6765. (let ((org-tags-column -20)
  6766. (indent-tabs-mode nil))
  6767. (org-fix-tags-on-the-fly))
  6768. (buffer-string))))
  6769. (should
  6770. ;; 12345678901234567890
  6771. (equal "* Test :日本語:"
  6772. (org-test-with-temp-text "* Test :日本語:"
  6773. (let ((org-tags-column -20)
  6774. (indent-tabs-mode nil))
  6775. (org-fix-tags-on-the-fly))
  6776. (buffer-string))))
  6777. ;; Make sure aligning tags do not skip invisible text.
  6778. (should
  6779. (equal "* [[linkx]] :tag:"
  6780. (org-test-with-temp-text "* [[link<point>]] :tag:"
  6781. (let ((org-tags-column 0))
  6782. (org-fix-tags-on-the-fly)
  6783. (insert "x")
  6784. (buffer-string)))))
  6785. ;; Aligning tags preserve position.
  6786. (should
  6787. (= 6 (org-test-with-temp-text "* 345 <point> :tag:"
  6788. (let ((org-tags-column 78)
  6789. (indent-tabs-mode nil))
  6790. (org-fix-tags-on-the-fly))
  6791. (current-column))))
  6792. ;; Aligning all tags in visible buffer.
  6793. (should
  6794. ;; 12345678901234567890
  6795. (equal (concat "* Level 1 :abc:\n"
  6796. "** Level 2 :def:")
  6797. (org-test-with-temp-text (concat "* Level 1 :abc:\n"
  6798. "** Level 2 :def:")
  6799. (let ((org-tags-column -20)
  6800. (indent-tabs-mode nil))
  6801. ;; (org-align-tags :all) must work even when the point
  6802. ;; is at the end of the buffer.
  6803. (goto-char (point-max))
  6804. (org-align-tags :all))
  6805. (buffer-string)))))
  6806. (ert-deftest test-org/get-tags ()
  6807. "Test `org-get-tags' specifications."
  6808. ;; Standard test.
  6809. (should
  6810. (equal '("foo")
  6811. (org-test-with-temp-text "* Test :foo:" (org-get-tags))))
  6812. (should
  6813. (equal '("foo" "bar")
  6814. (org-test-with-temp-text "* Test :foo:bar:" (org-get-tags))))
  6815. ;; Tags for inlinetasks.
  6816. (should
  6817. (equal '("foo" "bar")
  6818. (progn
  6819. (require 'org-inlinetask)
  6820. (org-test-with-temp-text (concat (make-string org-inlinetask-min-level ?*) " Test :foo:bar:")
  6821. (org-get-tags (org-element-at-point))))))
  6822. (should
  6823. (equal '("foo" "bar")
  6824. (progn
  6825. (require 'org-inlinetask)
  6826. (org-test-with-temp-text (concat (make-string org-inlinetask-min-level ?*) " Test :foo:bar:")
  6827. (org-get-tags nil)))))
  6828. ;; Return nil when there is no tag.
  6829. (should-not
  6830. (org-test-with-temp-text "* Test" (org-get-tags)))
  6831. ;; Tags are inherited from parent headlines.
  6832. (should
  6833. (equal '("tag")
  6834. (let ((org-use-tag-inheritance t))
  6835. (org-test-with-temp-text "* H0 :foo:\n* H1 :tag:\n<point>** H2"
  6836. (org-get-tags)))))
  6837. ;; Tags are inherited from `org-file-tags'.
  6838. (should
  6839. (equal '("tag")
  6840. (org-test-with-temp-text "* H1"
  6841. (let ((org-file-tags '("tag"))
  6842. (org-use-tag-inheritance t))
  6843. (org-get-tags)))))
  6844. ;; Only inherited tags have the `inherited' text property.
  6845. (should
  6846. (get-text-property 0 'inherited
  6847. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6848. (let ((org-use-tag-inheritance t))
  6849. (assoc-string "foo" (org-get-tags))))))
  6850. (should-not
  6851. (get-text-property 0 'inherited
  6852. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6853. (let ((org-use-tag-inheritance t))
  6854. (assoc-string "bar" (org-get-tags))))))
  6855. ;; Obey to `org-use-tag-inheritance'.
  6856. (should-not
  6857. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6858. (let ((org-use-tag-inheritance nil))
  6859. (assoc-string "foo" (org-get-tags)))))
  6860. (should-not
  6861. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6862. (let ((org-use-tag-inheritance nil)
  6863. (org-file-tags '("foo")))
  6864. (assoc-string "foo" (org-get-tags)))))
  6865. (should-not
  6866. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6867. (let ((org-use-tag-inheritance '("bar")))
  6868. (assoc-string "foo" (org-get-tags)))))
  6869. (should
  6870. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6871. (let ((org-use-tag-inheritance '("bar")))
  6872. (assoc-string "bar" (org-get-tags)))))
  6873. (should-not
  6874. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6875. (let ((org-use-tag-inheritance "b.*"))
  6876. (assoc-string "foo" (org-get-tags)))))
  6877. (should
  6878. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6879. (let ((org-use-tag-inheritance "b.*"))
  6880. (assoc-string "bar" (org-get-tags)))))
  6881. ;; When optional argument LOCAL is non-nil, ignore tag inheritance.
  6882. (should
  6883. (equal '("baz")
  6884. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6885. (let ((org-use-tag-inheritance t))
  6886. (org-get-tags nil t)))))
  6887. ;; When optional argument POS is non-nil, get tags there instead.
  6888. (should
  6889. (equal '("foo")
  6890. (org-test-with-temp-text "* H1 :foo:\n* <point>H2 :bar:"
  6891. (org-get-tags 1))))
  6892. ;; Make sure tags excluded from inheritance are returned if local
  6893. (should
  6894. (equal '("foo")
  6895. (org-test-with-temp-text "* Test :foo:"
  6896. (let ((org-use-tag-inheritance t)
  6897. (org-tags-exclude-from-inheritance '("foo")))
  6898. (org-get-tags)))))
  6899. ;; Test the collection of tags from #+filetags and parent tags.
  6900. (should
  6901. (equal '("a" "b" "c" "d")
  6902. (org-test-with-temp-text (concat "#+filetags: a\n"
  6903. "* Level 1 :b:\n"
  6904. "** Level 2 :c:\n"
  6905. "*** Level 3 :d:\n"
  6906. "<point>")
  6907. (let ((org-use-tag-inheritance t))
  6908. (org-mode-restart) ;So that `org-file-tags' get populated from #+filetags
  6909. (org-get-tags)))))
  6910. ;; Pathological case: tagged headline with an empty body.
  6911. (should (org-test-with-temp-text "* :tag:" (org-get-tags))))
  6912. (ert-deftest test-org/set-tags ()
  6913. "Test `org-set-tags' specifications."
  6914. ;; Throw an error on invalid data.
  6915. (should-error
  6916. (org-test-with-temp-text "* H"
  6917. (org-set-tags 'foo)))
  6918. ;; `nil', an empty, and a blank string remove all tags.
  6919. (should
  6920. (equal "* H"
  6921. (org-test-with-temp-text "* H :tag1:tag2:"
  6922. (org-set-tags nil)
  6923. (buffer-string))))
  6924. (should
  6925. (equal "* H"
  6926. (org-test-with-temp-text "* H :tag1:tag2:"
  6927. (org-set-tags "")
  6928. (buffer-string))))
  6929. (should
  6930. (equal "* H"
  6931. (org-test-with-temp-text "* H :tag1:tag2:"
  6932. (org-set-tags " ")
  6933. (buffer-string))))
  6934. ;; If there's nothing to remove, just bail out.
  6935. (should
  6936. (equal "* H"
  6937. (org-test-with-temp-text "* H"
  6938. (org-set-tags nil)
  6939. (buffer-string))))
  6940. (should
  6941. (equal "* "
  6942. (org-test-with-temp-text "* "
  6943. (org-set-tags nil)
  6944. (buffer-string))))
  6945. ;; If DATA is a tag string, set current tags to it, even if it means
  6946. ;; replacing old tags.
  6947. (should
  6948. (equal "* H :tag0:"
  6949. (org-test-with-temp-text "* H :tag1:tag2:"
  6950. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  6951. (buffer-string))))
  6952. (should
  6953. (equal "* H :tag0:"
  6954. (org-test-with-temp-text "* H"
  6955. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  6956. (buffer-string))))
  6957. ;; If DATA is a list, set tags to this list, even if it means
  6958. ;; replacing old tags.
  6959. (should
  6960. (equal "* H :tag0:"
  6961. (org-test-with-temp-text "* H :tag1:tag2:"
  6962. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6963. (buffer-string))))
  6964. (should
  6965. (equal "* H :tag0:"
  6966. (org-test-with-temp-text "* H"
  6967. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6968. (buffer-string))))
  6969. ;; When set, apply `org-tags-sort-function'.
  6970. (should
  6971. (equal "* H :a:b:"
  6972. (org-test-with-temp-text "* H"
  6973. (let ((org-tags-column 1)
  6974. (org-tags-sort-function #'string<))
  6975. (org-set-tags '("b" "a"))
  6976. (buffer-string)))))
  6977. ;; When new tags are identical to the previous ones, still align.
  6978. (should
  6979. (equal "* H :foo:"
  6980. (org-test-with-temp-text "* H :foo:"
  6981. (let ((org-tags-column 1))
  6982. (org-set-tags '("foo"))
  6983. (buffer-string)))))
  6984. ;; When tags have been changed, run `org-after-tags-change-hook'.
  6985. (should
  6986. (catch :return
  6987. (org-test-with-temp-text "* H :foo:"
  6988. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  6989. (org-set-tags '("bar"))
  6990. nil))))
  6991. (should-not
  6992. (catch :return
  6993. (org-test-with-temp-text "* H :foo:"
  6994. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  6995. (org-set-tags '("foo"))
  6996. nil))))
  6997. ;; Special case: handle empty headlines.
  6998. (should
  6999. (equal "* :tag0:"
  7000. (org-test-with-temp-text "* "
  7001. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  7002. (buffer-string))))
  7003. ;; Modify buffer only when a tag change happens or alignment is
  7004. ;; done.
  7005. (should-not
  7006. (org-test-with-temp-text "* H :foo:"
  7007. (set-buffer-modified-p nil)
  7008. (let ((org-tags-column 1)) (org-set-tags '("foo")))
  7009. (buffer-modified-p)))
  7010. (should
  7011. (org-test-with-temp-text "* H :foo:"
  7012. (set-buffer-modified-p nil)
  7013. (let ((org-tags-column 10)) (org-set-tags '("foo")))
  7014. (buffer-modified-p)))
  7015. (should
  7016. (org-test-with-temp-text "* H :foo:"
  7017. (set-buffer-modified-p nil)
  7018. (let ((org-tags-column 10)) (org-set-tags '("bar")))
  7019. (buffer-modified-p)))
  7020. ;; Pathological case: when setting tags of a folded headline, do not
  7021. ;; let new tags being sucked into invisibility.
  7022. (should-not
  7023. (org-test-with-temp-text "* H1\nContent\n* H2\n\n Other Content"
  7024. ;; Show only headlines
  7025. (org-content)
  7026. ;; Set NEXT tag on current entry
  7027. (org-set-tags ":NEXT:")
  7028. ;; Move point to that NEXT tag
  7029. (search-forward "NEXT") (backward-word)
  7030. ;; And it should be visible (i.e. no overlays)
  7031. (overlays-at (point)))))
  7032. (ert-deftest test-org/set-tags-command ()
  7033. "Test `org-set-tags-command' specifications"
  7034. ;; Set tags at current headline.
  7035. (should
  7036. (equal "* H1 :foo:"
  7037. (org-test-with-temp-text "* H1"
  7038. (cl-letf (((symbol-function 'completing-read-multiple)
  7039. (lambda (&rest args) '("foo"))))
  7040. (let ((org-use-fast-tag-selection nil)
  7041. (org-tags-column 1))
  7042. (org-set-tags-command)))
  7043. (buffer-string))))
  7044. ;; Preserve position when called from the section below.
  7045. (should
  7046. (equal "* H1 :foo:\nContents"
  7047. (org-test-with-temp-text "* H1\n<point>Contents"
  7048. (cl-letf (((symbol-function 'completing-read-multiple)
  7049. (lambda (&rest args) '("foo"))))
  7050. (let ((org-use-fast-tag-selection nil)
  7051. (org-tags-column 1))
  7052. (org-set-tags-command)))
  7053. (buffer-string))))
  7054. (should-not
  7055. (equal "* H1 :foo:\nContents2"
  7056. (org-test-with-temp-text "* H1\n<point>Contents2"
  7057. (cl-letf (((symbol-function 'completing-read-multiple)
  7058. (lambda (&rest args) '("foo"))))
  7059. (let ((org-use-fast-tag-selection nil)
  7060. (org-tags-column 1))
  7061. (org-set-tags-command)))
  7062. (org-at-heading-p))))
  7063. ;; When a region is active and
  7064. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  7065. ;; same value in all headlines in region.
  7066. (should
  7067. (equal "* H1 :foo:\nContents\n* H2 :foo:"
  7068. (org-test-with-temp-text "* H1\nContents\n* H2"
  7069. (cl-letf (((symbol-function 'completing-read-multiple)
  7070. (lambda (&rest args) '("foo"))))
  7071. (let ((org-use-fast-tag-selection nil)
  7072. (org-loop-over-headlines-in-active-region t)
  7073. (org-tags-column 1))
  7074. (transient-mark-mode 1)
  7075. (push-mark (point) t t)
  7076. (goto-char (point-max))
  7077. (org-set-tags-command)))
  7078. (buffer-string))))
  7079. (should
  7080. (equal "* H1\nContents\n* H2 :foo:"
  7081. (org-test-with-temp-text "* H1\nContents\n* H2"
  7082. (cl-letf (((symbol-function 'completing-read-multiple)
  7083. (lambda (&rest args) '("foo"))))
  7084. (let ((org-use-fast-tag-selection nil)
  7085. (org-loop-over-headlines-in-active-region nil)
  7086. (org-tags-column 1))
  7087. (transient-mark-mode 1)
  7088. (push-mark (point) t t)
  7089. (goto-char (point-max))
  7090. (org-set-tags-command)))
  7091. (buffer-string))))
  7092. ;; With a C-u prefix argument, align all tags in the buffer.
  7093. (should
  7094. (equal "* H1 :foo:\n* H2 :bar:"
  7095. (org-test-with-temp-text "* H1 :foo:\n* H2 :bar:"
  7096. (let ((org-tags-column 1)) (org-set-tags-command '(4)))
  7097. (buffer-string))))
  7098. ;; Point does not move with empty headline.
  7099. (should
  7100. (equal ":foo:"
  7101. (org-test-with-temp-text "* <point>"
  7102. (cl-letf (((symbol-function 'completing-read-multiple)
  7103. (lambda (&rest args) '("foo"))))
  7104. (let ((org-use-fast-tag-selection nil)
  7105. (org-tags-column 1))
  7106. (org-set-tags-command)))
  7107. (buffer-substring (point) (line-end-position)))))
  7108. ;; Point does not move at start of line.
  7109. (should
  7110. (equal "* H1 :foo:"
  7111. (org-test-with-temp-text "* H1"
  7112. (cl-letf (((symbol-function 'completing-read-multiple)
  7113. (lambda (&rest args) '("foo"))))
  7114. (let ((org-use-fast-tag-selection nil)
  7115. (org-tags-column 1))
  7116. (org-set-tags-command)))
  7117. (buffer-substring (point) (line-end-position)))))
  7118. ;; Point does not move when within *'s.
  7119. (should
  7120. (equal "* H1 :foo:"
  7121. (org-test-with-temp-text "*<point>* H1"
  7122. (cl-letf (((symbol-function 'completing-read-multiple)
  7123. (lambda (&rest args) '("foo"))))
  7124. (let ((org-use-fast-tag-selection nil)
  7125. (org-tags-column 1))
  7126. (org-set-tags-command)))
  7127. (buffer-substring (point) (line-end-position)))))
  7128. ;; Point workaround does not get fooled when looking at a space.
  7129. (should
  7130. (equal " b :foo:"
  7131. (org-test-with-temp-text "* a<point> b"
  7132. (cl-letf (((symbol-function 'completing-read-multiple)
  7133. (lambda (&rest args) '("foo"))))
  7134. (let ((org-use-fast-tag-selection nil)
  7135. (org-tags-column 1))
  7136. (org-set-tags-command)))
  7137. (buffer-substring (point) (line-end-position)))))
  7138. ;; Handle tags both set locally and inherited.
  7139. (should
  7140. (equal "b :foo:"
  7141. (org-test-with-temp-text "* a :foo:\n** <point>b :foo:"
  7142. (cl-letf (((symbol-function 'completing-read-multiple)
  7143. (lambda (prompt coll &optional pred req initial &rest args)
  7144. (list initial))))
  7145. (let ((org-use-fast-tag-selection nil)
  7146. (org-tags-column 1))
  7147. (org-set-tags-command)))
  7148. (buffer-substring (point) (line-end-position))))))
  7149. (ert-deftest test-org/toggle-tag ()
  7150. "Test `org-toggle-tag' specifications."
  7151. ;; Insert missing tag.
  7152. (should
  7153. (equal "* H :tag:"
  7154. (org-test-with-temp-text "* H"
  7155. (let ((org-tags-column 1)) (org-toggle-tag "tag"))
  7156. (buffer-string))))
  7157. (should
  7158. (equal "* H :tag1:tag2:"
  7159. (org-test-with-temp-text "* H :tag1:"
  7160. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  7161. (buffer-string))))
  7162. ;; Remove existing tag.
  7163. (should
  7164. (equal "* H"
  7165. (org-test-with-temp-text "* H :tag:"
  7166. (org-toggle-tag "tag")
  7167. (buffer-string))))
  7168. (should
  7169. (equal "* H :tag1:"
  7170. (org-test-with-temp-text "* H :tag1:tag2:"
  7171. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  7172. (buffer-string))))
  7173. (should
  7174. (equal "* H :tag2:"
  7175. (org-test-with-temp-text "* H :tag1:tag2:"
  7176. (let ((org-tags-column 1)) (org-toggle-tag "tag1"))
  7177. (buffer-string))))
  7178. ;; With optional argument ONOFF set to `on', try to insert the tag,
  7179. ;; even if its already there.
  7180. (should
  7181. (equal "* H :tag:"
  7182. (org-test-with-temp-text "* H"
  7183. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  7184. (buffer-string))))
  7185. (should
  7186. (equal "* H :tag:"
  7187. (org-test-with-temp-text "* H :tag:"
  7188. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  7189. (buffer-string))))
  7190. ;; With optional argument ONOFF set to `off', try to remove the tag,
  7191. ;; even if its not there.
  7192. (should
  7193. (equal "* H"
  7194. (org-test-with-temp-text "* H :tag:"
  7195. (org-toggle-tag "tag" 'off)
  7196. (buffer-string))))
  7197. (should
  7198. (equal "* H :tag:"
  7199. (org-test-with-temp-text "* H :tag:"
  7200. (let ((org-tags-column 1)) (org-toggle-tag "foo" 'off))
  7201. (buffer-string))))
  7202. ;; Special case: Handle properly tag inheritance. In particular, do
  7203. ;; not set inherited tags.
  7204. (should
  7205. (equal "* H1 :tag:\n** H2 :tag2:tag:"
  7206. (org-test-with-temp-text "* H1 :tag:\n** <point>H2 :tag2:"
  7207. (let ((org-use-tag-inheritance t)
  7208. (org-tags-column 1))
  7209. (org-toggle-tag "tag"))
  7210. (buffer-string))))
  7211. (should
  7212. (equal "* H1 :tag1:tag2:\n** H2 :foo:"
  7213. (org-test-with-temp-text "* H1 :tag1:tag2:\n** <point>H2"
  7214. (let ((org-use-tag-inheritance t)
  7215. (org-tags-column 1))
  7216. (org-toggle-tag "foo"))
  7217. (buffer-string)))))
  7218. (ert-deftest test-org/tags-expand ()
  7219. "Test `org-tags-expand' specifications."
  7220. ;; Expand tag groups as a regexp enclosed within curly brackets.
  7221. (should
  7222. (equal "{\\<[ABC]\\>}"
  7223. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7224. (org-mode-restart)
  7225. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  7226. (should
  7227. (equal "{\\<\\(?:Aa\\|Bb\\|Cc\\)\\>}"
  7228. (org-test-with-temp-text "#+TAGS: [ Aa : Bb Cc ]"
  7229. (org-mode-restart)
  7230. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "Aa")))))
  7231. ;; Preserve operator before the regexp.
  7232. (should
  7233. (equal "+{\\<[ABC]\\>}"
  7234. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7235. (org-mode-restart)
  7236. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "+A")))))
  7237. (should
  7238. (equal "-{\\<[ABC]\\>}"
  7239. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7240. (org-mode-restart)
  7241. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "-A")))))
  7242. ;; Handle "|" syntax.
  7243. (should
  7244. (equal "{\\<[ABC]\\>}|D"
  7245. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7246. (org-mode-restart)
  7247. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|D")))))
  7248. ;; Handle nested groups.
  7249. (should
  7250. (equal "{\\<[A-D]\\>}"
  7251. (org-test-with-temp-text "#+TAGS: [ A : B C ]\n#+TAGS: [ B : D ]"
  7252. (org-mode-restart)
  7253. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  7254. ;; Expand multiple occurrences of the same group.
  7255. (should
  7256. (equal "{\\<[ABC]\\>}|{\\<[ABC]\\>}"
  7257. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7258. (org-mode-restart)
  7259. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|A")))))
  7260. ;; Preserve regexp matches.
  7261. (should
  7262. (equal "{A+}"
  7263. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7264. (org-mode-restart)
  7265. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "{A+}"))))))
  7266. ;;; TODO keywords
  7267. (ert-deftest test-org/auto-repeat-maybe ()
  7268. "Test `org-auto-repeat-maybe' specifications."
  7269. ;; Do not auto repeat when there is no valid time stamp with
  7270. ;; a repeater in the entry.
  7271. (should-not
  7272. (string-prefix-p
  7273. "* TODO H"
  7274. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7275. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
  7276. (org-todo "DONE")
  7277. (buffer-string)))))
  7278. (should-not
  7279. (string-prefix-p
  7280. "* TODO H"
  7281. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7282. (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
  7283. (org-todo "DONE")
  7284. (buffer-string)))))
  7285. ;; When switching to DONE state, switch back to first TODO keyword
  7286. ;; in sequence, or the same keyword if they have different types.
  7287. (should
  7288. (string-prefix-p
  7289. "* TODO H"
  7290. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7291. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7292. (org-todo "DONE")
  7293. (buffer-string)))))
  7294. (should
  7295. (string-prefix-p
  7296. "* KWD1 H"
  7297. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  7298. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  7299. (org-todo "DONE")
  7300. (buffer-string)))))
  7301. (should
  7302. (string-prefix-p
  7303. "* KWD2 H"
  7304. (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
  7305. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  7306. (org-todo "DONE")
  7307. (buffer-string)))))
  7308. ;; If there was no TODO keyword in the first place, do not insert
  7309. ;; any either.
  7310. (should
  7311. (string-prefix-p
  7312. "* H"
  7313. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7314. (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
  7315. (org-todo "DONE")
  7316. (buffer-string)))))
  7317. ;; Revert to REPEAT_TO_STATE, if set.
  7318. (should
  7319. (string-prefix-p
  7320. "* KWD2 H"
  7321. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  7322. (org-test-with-temp-text
  7323. "* KWD2 H
  7324. :PROPERTIES:
  7325. :REPEAT_TO_STATE: KWD2
  7326. :END:
  7327. <2012-03-29 Thu +2y>"
  7328. (org-todo "DONE")
  7329. (buffer-string)))))
  7330. ;; When switching to DONE state, update base date. If there are
  7331. ;; multiple repeated time stamps, update them all.
  7332. (should
  7333. (string-match-p
  7334. "<2014-03-29 .* \\+2y>"
  7335. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7336. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7337. (org-todo "DONE")
  7338. (buffer-string)))))
  7339. (should
  7340. (string-match-p
  7341. "<2015-03-04 .* \\+1y>"
  7342. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7343. (org-test-with-temp-text
  7344. "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
  7345. (org-todo "DONE")
  7346. (buffer-string)))))
  7347. ;; Throw an error if repeater unit is the hour and no time is
  7348. ;; provided in the time-stamp.
  7349. (should-error
  7350. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7351. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
  7352. (org-todo "DONE")
  7353. (buffer-string))))
  7354. ;; Handle every repeater type using hours step.
  7355. (should
  7356. (string-match-p
  7357. "2014-03-04 .* 02:00"
  7358. (org-test-at-time "<2014-03-04 02:35>"
  7359. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 +8h>"
  7360. (org-todo "DONE")
  7361. (buffer-string)))))
  7362. (should
  7363. (string-match-p
  7364. "2014-03-04 .* 10:00"
  7365. (org-test-at-time "<2014-03-04 02:35>"
  7366. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 ++8h>"
  7367. (org-todo "DONE")
  7368. (buffer-string)))))
  7369. (should
  7370. (string-match-p
  7371. "2014-03-04 .* 10:35"
  7372. (org-test-at-time "<2014-03-04 02:35>"
  7373. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 .+8h>"
  7374. (org-todo "DONE")
  7375. (buffer-string)))))
  7376. ;; Do not repeat inactive time stamps with a repeater.
  7377. (should-not
  7378. (string-match-p
  7379. "\\[2014-03-29 .* \\+2y\\]"
  7380. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7381. (org-test-with-temp-text
  7382. "* TODO H\n[2012-03-29 Thu. +2y]"
  7383. (org-todo "DONE")
  7384. (buffer-string)))))
  7385. ;; Do not repeat commented time stamps.
  7386. (should-not
  7387. (string-prefix-p
  7388. "<2015-03-04 .* \\+1y>"
  7389. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7390. (org-test-with-temp-text
  7391. "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
  7392. (org-todo "DONE")
  7393. (buffer-string)))))
  7394. (should-not
  7395. (string-prefix-p
  7396. "<2015-03-04 .* \\+1y>"
  7397. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7398. (org-test-with-temp-text
  7399. "* TODO H
  7400. <2012-03-29 Thu. +2y>
  7401. #+BEGIN_EXAMPLE
  7402. <2014-03-04 Tue +1y>
  7403. #+END_EXAMPLE"
  7404. (org-todo "DONE")
  7405. (buffer-string)))))
  7406. ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
  7407. ;; entry, record time of last repeat.
  7408. (should-not
  7409. (string-match-p
  7410. ":LAST_REPEAT:"
  7411. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  7412. (org-log-repeat nil))
  7413. (cl-letf (((symbol-function 'org-add-log-setup)
  7414. (lambda (&rest args) nil)))
  7415. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  7416. (org-todo "DONE")
  7417. (buffer-string))))))
  7418. (should
  7419. (string-match-p
  7420. ":LAST_REPEAT:"
  7421. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  7422. (org-log-repeat t))
  7423. (cl-letf (((symbol-function 'org-add-log-setup)
  7424. (lambda (&rest args) nil)))
  7425. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  7426. (org-todo "DONE")
  7427. (buffer-string))))))
  7428. (should
  7429. (string-match-p
  7430. ":LAST_REPEAT:"
  7431. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7432. (cl-letf (((symbol-function 'org-add-log-setup)
  7433. (lambda (&rest args) nil)))
  7434. (org-test-with-temp-text
  7435. "* TODO H\n<2012-03-29 Thu +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
  7436. (org-todo "DONE")
  7437. (buffer-string))))))
  7438. ;; When a SCHEDULED entry has no repeater, remove it upon repeating
  7439. ;; the entry as it is no longer relevant.
  7440. (should-not
  7441. (string-match-p
  7442. "^SCHEDULED:"
  7443. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7444. (org-test-with-temp-text
  7445. "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
  7446. (org-todo "DONE")
  7447. (buffer-string)))))
  7448. ;; Properly advance repeater even when a clock entry is specified
  7449. ;; and `org-log-repeat' is nil.
  7450. (should
  7451. (string-match-p
  7452. "SCHEDULED: <2014-03-29"
  7453. (let ((org-log-repeat nil)
  7454. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7455. (org-test-with-temp-text
  7456. "* TODO H
  7457. SCHEDULED: <2012-03-29 Thu +2y>
  7458. CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] => 6:40"
  7459. (org-todo "DONE")
  7460. (buffer-string)))))
  7461. ;; Make sure that logbook state change record does not get
  7462. ;; duplicated when `org-log-repeat' `org-log-done' are non-nil.
  7463. (should
  7464. (string-match-p
  7465. (rx "* TODO Read book
  7466. SCHEDULED: <2021-06-16 " (1+ (not space)) " +1d>
  7467. :PROPERTIES:
  7468. :LAST_REPEAT:" (1+ nonl) "
  7469. :END:
  7470. - State \"DONE\" from \"TODO\"" (1+ nonl) buffer-end)
  7471. (let ((org-log-repeat 'time)
  7472. (org-todo-keywords '((sequence "TODO" "|" "DONE(d!)")))
  7473. (org-log-into-drawer nil))
  7474. (org-test-with-temp-text
  7475. "* TODO Read book
  7476. SCHEDULED: <2021-06-15 Tue +1d>"
  7477. (org-todo "DONE")
  7478. (when (memq 'org-add-log-note post-command-hook)
  7479. (org-add-log-note))
  7480. (buffer-string))))))
  7481. (ert-deftest test-org/org-log-done ()
  7482. "Test `org-log-done' specifications."
  7483. ;; nil value.
  7484. (should
  7485. (string=
  7486. "* DONE task"
  7487. (let ((org-log-done nil)
  7488. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7489. (org-test-with-temp-text
  7490. "* TODO task"
  7491. (org-todo "DONE")
  7492. (when (memq 'org-add-log-note post-command-hook)
  7493. (org-add-log-note))
  7494. (buffer-string)))))
  7495. ;; `time' value.
  7496. (should
  7497. (string=
  7498. (format
  7499. "* DONE task
  7500. CLOSED: %s"
  7501. (org-test-with-temp-text ""
  7502. (org-insert-time-stamp (current-time) t t)
  7503. (buffer-string)))
  7504. (let ((org-log-done 'time)
  7505. (org-log-done-with-time t)
  7506. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7507. (org-test-with-temp-text
  7508. "* TODO task"
  7509. (org-todo "DONE")
  7510. (when (memq 'org-add-log-note post-command-hook)
  7511. (org-add-log-note))
  7512. (buffer-string)))))
  7513. (should
  7514. (string=
  7515. (format
  7516. "* DONE task
  7517. CLOSED: %s"
  7518. (org-test-with-temp-text ""
  7519. (org-insert-time-stamp (current-time) nil t)
  7520. (buffer-string)))
  7521. (let ((org-log-done 'time)
  7522. (org-log-done-with-time nil)
  7523. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7524. (org-test-with-temp-text
  7525. "* TODO task"
  7526. (org-todo "DONE")
  7527. (when (memq 'org-add-log-note post-command-hook)
  7528. (org-add-log-note))
  7529. (buffer-string)))))
  7530. ;; TODO: Test `note' value.
  7531. ;; Test startup overrides.
  7532. (should
  7533. (string=
  7534. "#+STARTUP: nologdone
  7535. * DONE task"
  7536. (let ((org-log-done 'time)
  7537. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7538. (org-test-with-temp-text
  7539. "#+STARTUP: nologdone
  7540. <point>* TODO task"
  7541. (org-set-regexps-and-options)
  7542. (org-todo "DONE")
  7543. (when (memq 'org-add-log-note post-command-hook)
  7544. (org-add-log-note))
  7545. (buffer-string)))))
  7546. (should
  7547. (string=
  7548. (format
  7549. "#+STARTUP: logdone
  7550. * DONE task
  7551. CLOSED: %s"
  7552. (org-test-with-temp-text ""
  7553. (org-insert-time-stamp (current-time) t t)
  7554. (buffer-string)))
  7555. (let ((org-log-done nil)
  7556. (org-log-done-with-time t)
  7557. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7558. (org-test-with-temp-text
  7559. "#+STARTUP: logdone
  7560. <point>* TODO task"
  7561. (org-set-regexps-and-options)
  7562. (org-todo "DONE")
  7563. (when (memq 'org-add-log-note post-command-hook)
  7564. (org-add-log-note))
  7565. (buffer-string)))))
  7566. ;; Test local property overrides.
  7567. (should
  7568. (string=
  7569. "* DONE task
  7570. :PROPERTIES:
  7571. :LOGGING: nil
  7572. :END:"
  7573. (let ((org-log-done 'time)
  7574. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7575. (org-test-with-temp-text
  7576. "* TODO task
  7577. :PROPERTIES:
  7578. :LOGGING: nil
  7579. :END:"
  7580. (org-todo "DONE")
  7581. (when (memq 'org-add-log-note post-command-hook)
  7582. (org-add-log-note))
  7583. (buffer-string)))))
  7584. (should
  7585. (string=
  7586. (format
  7587. "* DONE task
  7588. CLOSED: %s
  7589. :PROPERTIES:
  7590. :LOGGING: logdone
  7591. :END:"
  7592. (org-test-with-temp-text ""
  7593. (org-insert-time-stamp (current-time) t t)
  7594. (buffer-string)))
  7595. (let ((org-log-done nil)
  7596. (org-log-done-with-time t)
  7597. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7598. (org-test-with-temp-text
  7599. "* TODO task
  7600. :PROPERTIES:
  7601. :LOGGING: logdone
  7602. :END:"
  7603. (org-todo "DONE")
  7604. (when (memq 'org-add-log-note post-command-hook)
  7605. (org-add-log-note))
  7606. (buffer-string))))))
  7607. (ert-deftest test-org/org-todo-prefix ()
  7608. "Test `org-todo' prefix arg behavior."
  7609. ;; FIXME: Add tests for all other allowed prefix arguments.
  7610. ;; -1 prefix arg should cancel repeater and mark DONE.
  7611. (should
  7612. (string-match-p
  7613. "DONE H\\(.*\n\\)*<2012-03-29 Thu \\+0y>"
  7614. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7615. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7616. (org-todo -1)
  7617. (buffer-string)))))
  7618. ;; - prefix arg should cancel repeater and mark DONE.
  7619. (should
  7620. (string-match-p
  7621. "DONE H\\(.*\n\\)*<2012-03-29 Thu \\+0y>"
  7622. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7623. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7624. (org-todo '-)
  7625. (buffer-string))))))
  7626. ;;; Timestamps API
  7627. (ert-deftest test-org/at-timestamp-p ()
  7628. "Test `org-at-timestamp-p' specifications."
  7629. (should
  7630. (org-test-with-temp-text "<2012-03-29 Thu>"
  7631. (org-at-timestamp-p)))
  7632. (should-not
  7633. (org-test-with-temp-text "2012-03-29 Thu"
  7634. (org-at-timestamp-p)))
  7635. ;; Test return values.
  7636. (should
  7637. (eq 'bracket
  7638. (org-test-with-temp-text "<2012-03-29 Thu>"
  7639. (org-at-timestamp-p))))
  7640. (should
  7641. (eq 'year
  7642. (org-test-with-temp-text "<<point>2012-03-29 Thu>"
  7643. (org-at-timestamp-p))))
  7644. (should
  7645. (eq 'month
  7646. (org-test-with-temp-text "<2012-<point>03-29 Thu>"
  7647. (org-at-timestamp-p))))
  7648. (should
  7649. (eq 'day
  7650. (org-test-with-temp-text "<2012-03-<point>29 Thu>"
  7651. (org-at-timestamp-p))))
  7652. (should
  7653. (eq 'day
  7654. (org-test-with-temp-text "<2012-03-29 T<point>hu>"
  7655. (org-at-timestamp-p))))
  7656. (should
  7657. (wholenump
  7658. (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
  7659. (org-at-timestamp-p))))
  7660. (should
  7661. (eq 'bracket
  7662. (org-test-with-temp-text "<2012-03-29 Thu<point>>"
  7663. (org-at-timestamp-p))))
  7664. (should
  7665. (eq 'after
  7666. (org-test-with-temp-text "<2012-03-29 Thu><point>»"
  7667. (org-at-timestamp-p))))
  7668. ;; Test `inactive' optional argument.
  7669. (should
  7670. (org-test-with-temp-text "[2012-03-29 Thu]"
  7671. (org-at-timestamp-p 'inactive)))
  7672. (should-not
  7673. (org-test-with-temp-text "[2012-03-29 Thu]"
  7674. (org-at-timestamp-p)))
  7675. ;; When optional argument is `agenda', recognize time-stamps in
  7676. ;; planning info line, property drawers and clocks.
  7677. (should
  7678. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7679. (org-at-timestamp-p 'agenda)))
  7680. (should-not
  7681. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7682. (org-at-timestamp-p)))
  7683. (should
  7684. (org-test-with-temp-text
  7685. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7686. (org-at-timestamp-p 'agenda)))
  7687. (should-not
  7688. (org-test-with-temp-text
  7689. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7690. (org-at-timestamp-p)))
  7691. (should
  7692. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7693. (let ((org-agenda-include-inactive-timestamps t))
  7694. (org-at-timestamp-p 'agenda))))
  7695. (should-not
  7696. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7697. (let ((org-agenda-include-inactive-timestamps t))
  7698. (org-at-timestamp-p))))
  7699. (should-not
  7700. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7701. (let ((org-agenda-include-inactive-timestamps t))
  7702. (org-at-timestamp-p 'inactive))))
  7703. ;; When optional argument is `lax', match any part of the document
  7704. ;; with Org timestamp syntax.
  7705. (should
  7706. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7707. (org-at-timestamp-p 'lax)))
  7708. (should-not
  7709. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7710. (org-at-timestamp-p)))
  7711. (should
  7712. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7713. (org-at-timestamp-p 'lax)))
  7714. (should-not
  7715. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7716. (org-at-timestamp-p)))
  7717. (should
  7718. (org-test-with-temp-text
  7719. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7720. (org-at-timestamp-p 'lax)))
  7721. (should-not
  7722. (org-test-with-temp-text
  7723. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7724. (org-at-timestamp-p)))
  7725. ;; Optional argument `lax' also matches inactive timestamps.
  7726. (should
  7727. (org-test-with-temp-text "# [2012-03-29 Thu]<point>"
  7728. (org-at-timestamp-p 'lax))))
  7729. (ert-deftest test-org/time-stamp ()
  7730. "Test `org-time-stamp' specifications."
  7731. ;; Insert chosen time stamp at point.
  7732. (should
  7733. (string-match
  7734. "Te<2014-03-04 .*?>xt"
  7735. (org-test-with-temp-text "Te<point>xt"
  7736. (cl-letf (((symbol-function 'org-read-date)
  7737. (lambda (&rest args)
  7738. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7739. (org-time-stamp nil)
  7740. (buffer-string)))))
  7741. ;; With a prefix argument, also insert time.
  7742. (should
  7743. (string-match
  7744. "Te<2014-03-04 .*? 00:41>xt"
  7745. (org-test-with-temp-text "Te<point>xt"
  7746. (cl-letf (((symbol-function 'org-read-date)
  7747. (lambda (&rest args)
  7748. (apply #'encode-time
  7749. (org-parse-time-string "2014-03-04 00:41")))))
  7750. (org-time-stamp '(4))
  7751. (buffer-string)))))
  7752. ;; With two universal prefix arguments, insert an active timestamp
  7753. ;; with the current time without prompting the user.
  7754. (should
  7755. (string-match
  7756. "Te<2014-03-04 .*? 00:41>xt"
  7757. (org-test-with-temp-text "Te<point>xt"
  7758. (org-test-at-time "2014-03-04 00:41"
  7759. (org-time-stamp '(16))
  7760. (buffer-string)))))
  7761. ;; When optional argument is non-nil, insert an inactive timestamp.
  7762. (should
  7763. (string-match
  7764. "Te\\[2014-03-04 .*?\\]xt"
  7765. (org-test-with-temp-text "Te<point>xt"
  7766. (cl-letf (((symbol-function 'org-read-date)
  7767. (lambda (&rest args)
  7768. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7769. (org-time-stamp nil t)
  7770. (buffer-string)))))
  7771. ;; When called from a timestamp, replace existing one.
  7772. (should
  7773. (string-match
  7774. "<2014-03-04 .*?>"
  7775. (org-test-with-temp-text "<2012-03-29<point> thu.>"
  7776. (cl-letf (((symbol-function 'org-read-date)
  7777. (lambda (&rest args)
  7778. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7779. (org-time-stamp nil)
  7780. (buffer-string)))))
  7781. (should
  7782. (string-match
  7783. "<2014-03-04 .*?>--<2014-03-04 .*?>"
  7784. (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
  7785. (cl-letf (((symbol-function 'org-read-date)
  7786. (lambda (&rest args)
  7787. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7788. (org-time-stamp nil)
  7789. (buffer-string)))))
  7790. ;; When replacing a timestamp, preserve repeater, if any.
  7791. (should
  7792. (string-match
  7793. "<2014-03-04 .*? \\+2y>"
  7794. (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
  7795. (cl-letf (((symbol-function 'org-read-date)
  7796. (lambda (&rest args)
  7797. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7798. (org-time-stamp nil)
  7799. (buffer-string)))))
  7800. ;; When called twice in a raw, build a date range.
  7801. (should
  7802. (string-match
  7803. "<2012-03-29 .*?>--<2014-03-04 .*?>"
  7804. (org-test-with-temp-text "<2012-03-29 thu.><point>"
  7805. (cl-letf (((symbol-function 'org-read-date)
  7806. (lambda (&rest args)
  7807. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7808. (let ((last-command 'org-time-stamp)
  7809. (this-command 'org-time-stamp))
  7810. (org-time-stamp nil))
  7811. (buffer-string))))))
  7812. (ert-deftest test-org/timestamp-has-time-p ()
  7813. "Test `org-timestamp-has-time-p' specifications."
  7814. ;; With time.
  7815. (should
  7816. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7817. (org-timestamp-has-time-p (org-element-context))))
  7818. ;; Without time.
  7819. (should-not
  7820. (org-test-with-temp-text "<2012-03-29 Thu>"
  7821. (org-timestamp-has-time-p (org-element-context)))))
  7822. (ert-deftest test-org/get-repeat ()
  7823. "Test `org-get-repeat' specifications."
  7824. (should
  7825. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
  7826. (org-get-repeat)))
  7827. (should-not
  7828. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
  7829. (org-get-repeat)))
  7830. ;; Return proper repeat string.
  7831. (should
  7832. (equal "+2y"
  7833. (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
  7834. (org-get-repeat))))
  7835. ;; Prevent false positive (commented or verbatim time stamps)
  7836. (should-not
  7837. (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
  7838. (org-get-repeat)))
  7839. (should-not
  7840. (org-test-with-temp-text
  7841. "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
  7842. (org-get-repeat)))
  7843. ;; Return nil when called before first heading.
  7844. (should-not
  7845. (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
  7846. (org-get-repeat)))
  7847. ;; When called with an optional argument, extract repeater from that
  7848. ;; string instead.
  7849. (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
  7850. (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
  7851. (ert-deftest test-org/timestamp-format ()
  7852. "Test `org-timestamp-format' specifications."
  7853. ;; Regular test.
  7854. (should
  7855. (equal
  7856. "2012-03-29 16:40"
  7857. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7858. (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
  7859. ;; Range end.
  7860. (should
  7861. (equal
  7862. "2012-03-29"
  7863. (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
  7864. (org-timestamp-format (org-element-context) "%Y-%m-%d" t)))))
  7865. (ert-deftest test-org/timestamp-split-range ()
  7866. "Test `org-timestamp-split-range' specifications."
  7867. ;; Extract range start (active).
  7868. (should
  7869. (equal '(2012 3 29)
  7870. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7871. (let ((ts (org-timestamp-split-range (org-element-context))))
  7872. (mapcar (lambda (p) (org-element-property p ts))
  7873. '(:year-end :month-end :day-end))))))
  7874. ;; Extract range start (inactive)
  7875. (should
  7876. (equal '(2012 3 29)
  7877. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7878. (let ((ts (org-timestamp-split-range (org-element-context))))
  7879. (mapcar (lambda (p) (org-element-property p ts))
  7880. '(:year-end :month-end :day-end))))))
  7881. ;; Extract range end (active).
  7882. (should
  7883. (equal '(2012 3 30)
  7884. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7885. (let ((ts (org-timestamp-split-range
  7886. (org-element-context) t)))
  7887. (mapcar (lambda (p) (org-element-property p ts))
  7888. '(:year-end :month-end :day-end))))))
  7889. ;; Extract range end (inactive)
  7890. (should
  7891. (equal '(2012 3 30)
  7892. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7893. (let ((ts (org-timestamp-split-range
  7894. (org-element-context) t)))
  7895. (mapcar (lambda (p) (org-element-property p ts))
  7896. '(:year-end :month-end :day-end))))))
  7897. ;; Return the timestamp if not a range.
  7898. (should
  7899. (org-test-with-temp-text "[2012-03-29 Thu]"
  7900. (let* ((ts-orig (org-element-context))
  7901. (ts-copy (org-timestamp-split-range ts-orig)))
  7902. (eq ts-orig ts-copy))))
  7903. (should
  7904. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7905. (let* ((ts-orig (org-element-context))
  7906. (ts-copy (org-timestamp-split-range ts-orig)))
  7907. (eq ts-orig ts-copy)))))
  7908. (ert-deftest test-org/timestamp-translate ()
  7909. "Test `org-timestamp-translate' specifications."
  7910. ;; Translate whole date range.
  7911. (should
  7912. (equal "<29>--<30>"
  7913. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7914. (let ((org-display-custom-times t)
  7915. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7916. (org-timestamp-translate (org-element-context))))))
  7917. ;; Translate date range start.
  7918. (should
  7919. (equal "<29>"
  7920. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7921. (let ((org-display-custom-times t)
  7922. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7923. (org-timestamp-translate (org-element-context) 'start)))))
  7924. ;; Translate date range end.
  7925. (should
  7926. (equal "<30>"
  7927. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7928. (let ((org-display-custom-times t)
  7929. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7930. (org-timestamp-translate (org-element-context) 'end)))))
  7931. ;; Translate time range.
  7932. (should
  7933. (equal "<08>--<16>"
  7934. (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
  7935. (let ((org-display-custom-times t)
  7936. (org-time-stamp-custom-formats '("<%d>" . "<%H>")))
  7937. (org-timestamp-translate (org-element-context))))))
  7938. ;; Translate non-range timestamp.
  7939. (should
  7940. (equal "<29>"
  7941. (org-test-with-temp-text "<2012-03-29 Thu>"
  7942. (let ((org-display-custom-times t)
  7943. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7944. (org-timestamp-translate (org-element-context))))))
  7945. ;; Do not change `diary' timestamps.
  7946. (should
  7947. (equal "<%%(org-float t 4 2)>"
  7948. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7949. (let ((org-display-custom-times t)
  7950. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7951. (org-timestamp-translate (org-element-context)))))))
  7952. (ert-deftest test-org/timestamp-from-string ()
  7953. "Test `org-timestamp-from-string' specifications."
  7954. ;; Return nil if argument is not a valid Org timestamp.
  7955. (should-not (org-timestamp-from-string ""))
  7956. (should-not (org-timestamp-from-string nil))
  7957. (should-not (org-timestamp-from-string "<2012-03-29"))
  7958. ;; Otherwise, return a valid Org timestamp object.
  7959. (should
  7960. (string-match-p "<2012-03-29 .+>"
  7961. (org-element-interpret-data
  7962. (org-timestamp-from-string "<2012-03-29 Thu>"))))
  7963. (should
  7964. (string-match-p "[2014-03-04 .+]"
  7965. (org-element-interpret-data
  7966. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  7967. (ert-deftest test-org/timestamp-from-time ()
  7968. "Test `org-timestamp-from-time' specifications."
  7969. ;; Standard test.
  7970. (should
  7971. (string-match-p
  7972. "<2012-03-29 .+>"
  7973. (org-element-interpret-data
  7974. (org-timestamp-from-time
  7975. (apply #'encode-time
  7976. (org-parse-time-string "<2012-03-29 Thu 16:40>"))))))
  7977. ;; When optional argument WITH-TIME is non-nil, provide time
  7978. ;; information.
  7979. (should
  7980. (string-match-p
  7981. "<2012-03-29 .+ 16:40>"
  7982. (org-element-interpret-data
  7983. (org-timestamp-from-time
  7984. (apply #'encode-time
  7985. (org-parse-time-string "<2012-03-29 Thu 16:40>"))
  7986. t))))
  7987. ;; When optional argument INACTIVE is non-nil, return an inactive
  7988. ;; timestamp.
  7989. (should
  7990. (string-match-p
  7991. "[2012-03-29 .+]"
  7992. (org-element-interpret-data
  7993. (org-timestamp-from-time
  7994. (apply #'encode-time
  7995. (org-parse-time-string "<2012-03-29 Thu 16:40>"))
  7996. nil t)))))
  7997. (ert-deftest test-org/timestamp-to-time ()
  7998. "Test `org-timestamp-to-time' specifications."
  7999. (should
  8000. (equal "2014-03-04"
  8001. (format-time-string
  8002. "%Y-%m-%d"
  8003. (org-timestamp-to-time
  8004. (org-timestamp-from-string "<2014-03-04 Tue>")))))
  8005. (should
  8006. (equal "2014-03-04"
  8007. (format-time-string
  8008. "%Y-%m-%d"
  8009. (org-timestamp-to-time
  8010. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  8011. (should
  8012. (equal "2012-03-29 08:30"
  8013. (format-time-string
  8014. "%Y-%m-%d %H:%M"
  8015. (org-timestamp-to-time
  8016. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")))))
  8017. (should
  8018. (equal "2012-03-29"
  8019. (format-time-string
  8020. "%Y-%m-%d"
  8021. (org-timestamp-to-time
  8022. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")))))
  8023. (should
  8024. (equal "2012-03-29"
  8025. (format-time-string
  8026. "%Y-%m-%d"
  8027. (org-timestamp-to-time
  8028. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")))))
  8029. ;; When optional argument END is non-nil, use end of date range or
  8030. ;; time range.
  8031. (should
  8032. (equal "2012-03-29 16:40"
  8033. (format-time-string
  8034. "%Y-%m-%d %H:%M"
  8035. (org-timestamp-to-time
  8036. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")
  8037. t))))
  8038. (should
  8039. (equal "2014-03-04"
  8040. (format-time-string
  8041. "%Y-%m-%d"
  8042. (org-timestamp-to-time
  8043. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")
  8044. t))))
  8045. (should
  8046. (equal "2014-03-04"
  8047. (format-time-string
  8048. "%Y-%m-%d"
  8049. (org-timestamp-to-time
  8050. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")
  8051. t)))))
  8052. ;;; Yank and Kill
  8053. (ert-deftest test-org/paste-subtree ()
  8054. "Test `org-paste-subtree' specifications."
  8055. ;; Return an error if text to yank is not a set of subtrees.
  8056. (should-error (org-paste-subtree nil "Text"))
  8057. ;; Adjust level according to current one.
  8058. (should
  8059. (equal "* H\n* Text\n"
  8060. (org-test-with-temp-text "* H\n<point>"
  8061. (org-paste-subtree nil "* Text")
  8062. (buffer-string))))
  8063. (should
  8064. (equal "* H1\n** H2\n** Text\n"
  8065. (org-test-with-temp-text "* H1\n** H2\n<point>"
  8066. (org-paste-subtree nil "* Text")
  8067. (buffer-string))))
  8068. ;; When not on a heading, move to next heading before yanking.
  8069. (should
  8070. (equal "* H1\nParagraph\n* Text\n* H2"
  8071. (org-test-with-temp-text "* H1\n<point>Paragraph\n* H2"
  8072. (org-paste-subtree nil "* Text")
  8073. (buffer-string))))
  8074. ;; If point is between two headings, use the deepest level.
  8075. (should
  8076. (equal "* H1\n\n* Text\n* H2"
  8077. (org-test-with-temp-text "* H1\n<point>\n* H2"
  8078. (org-paste-subtree nil "* Text")
  8079. (buffer-string))))
  8080. (should
  8081. (equal "** H1\n\n** Text\n* H2"
  8082. (org-test-with-temp-text "** H1\n<point>\n* H2"
  8083. (org-paste-subtree nil "* Text")
  8084. (buffer-string))))
  8085. (should
  8086. (equal "* H1\n\n** Text\n** H2"
  8087. (org-test-with-temp-text "* H1\n<point>\n** H2"
  8088. (org-paste-subtree nil "* Text")
  8089. (buffer-string))))
  8090. ;; When on an empty heading, after the stars, deduce the new level
  8091. ;; from the number of stars.
  8092. (should
  8093. (equal "*** Text\n"
  8094. (org-test-with-temp-text "*** <point>"
  8095. (org-paste-subtree nil "* Text")
  8096. (buffer-string))))
  8097. ;; Optional argument LEVEL forces a level for the subtree.
  8098. (should
  8099. (equal "* H\n*** Text\n"
  8100. (org-test-with-temp-text "* H<point>"
  8101. (org-paste-subtree 3 "* Text")
  8102. (buffer-string)))))
  8103. (ert-deftest test-org/cut-and-paste-subtree ()
  8104. "Test `org-cut-subtree' and `org-paste-subtree'."
  8105. (should
  8106. (equal
  8107. "* Two
  8108. two
  8109. * One
  8110. "
  8111. (org-test-with-temp-text
  8112. "* One
  8113. <point>* Two
  8114. two
  8115. "
  8116. (call-interactively #'org-cut-subtree)
  8117. (goto-char (point-min))
  8118. (call-interactively #'org-paste-subtree)
  8119. (buffer-string))))
  8120. (should
  8121. (equal
  8122. "* One
  8123. * Two
  8124. "
  8125. (org-test-with-temp-text
  8126. "* One
  8127. <point>* Two
  8128. "
  8129. (call-interactively #'org-cut-subtree)
  8130. (backward-char)
  8131. (call-interactively #'org-paste-subtree)
  8132. (buffer-string)))))
  8133. (provide 'test-org)
  8134. ;;; test-org.el ends here