test-org.el 273 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435
  1. ;;; test-org.el --- tests for org.el
  2. ;; Copyright (c) David Maus
  3. ;; Authors: David Maus
  4. ;; This file is not part of GNU Emacs.
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. ;; Template test file for Org tests
  16. ;;; Code:
  17. (eval-and-compile (require 'cl-lib))
  18. ;;; Comments
  19. (ert-deftest test-org/toggle-comment ()
  20. "Test `org-toggle-comment' specifications."
  21. ;; Simple headline.
  22. (should
  23. (equal "* Test"
  24. (org-test-with-temp-text "* COMMENT Test"
  25. (org-toggle-comment)
  26. (buffer-string))))
  27. (should
  28. (equal "* COMMENT Test"
  29. (org-test-with-temp-text "* Test"
  30. (org-toggle-comment)
  31. (buffer-string))))
  32. ;; Headline with a regular keyword.
  33. (should
  34. (equal "* TODO Test"
  35. (org-test-with-temp-text "* TODO COMMENT Test"
  36. (org-toggle-comment)
  37. (buffer-string))))
  38. (should
  39. (equal "* TODO COMMENT Test"
  40. (org-test-with-temp-text "* TODO Test"
  41. (org-toggle-comment)
  42. (buffer-string))))
  43. ;; Empty headline.
  44. (should
  45. (equal "* "
  46. (org-test-with-temp-text "* COMMENT"
  47. (org-toggle-comment)
  48. (buffer-string))))
  49. (should
  50. (equal "* COMMENT"
  51. (org-test-with-temp-text "* "
  52. (org-toggle-comment)
  53. (buffer-string))))
  54. ;; Headline with a single keyword.
  55. (should
  56. (equal "* TODO "
  57. (org-test-with-temp-text "* TODO COMMENT"
  58. (org-toggle-comment)
  59. (buffer-string))))
  60. (should
  61. (equal "* TODO COMMENT"
  62. (org-test-with-temp-text "* TODO"
  63. (org-toggle-comment)
  64. (buffer-string))))
  65. ;; Headline with a keyword, a priority cookie and contents.
  66. (should
  67. (equal "* TODO [#A] Headline"
  68. (org-test-with-temp-text "* TODO [#A] COMMENT Headline"
  69. (org-toggle-comment)
  70. (buffer-string))))
  71. (should
  72. (equal "* TODO [#A] COMMENT Headline"
  73. (org-test-with-temp-text "* TODO [#A] Headline"
  74. (org-toggle-comment)
  75. (buffer-string)))))
  76. (ert-deftest test-org/comment-dwim ()
  77. "Test `comment-dwim' behaviour in an Org buffer."
  78. ;; No region selected, no comment on current line and line not
  79. ;; empty: insert comment on line above.
  80. (should
  81. (equal "# \nComment"
  82. (org-test-with-temp-text "Comment"
  83. (call-interactively #'org-comment-dwim)
  84. (buffer-string))))
  85. ;; No region selected, no comment on current line and line empty:
  86. ;; insert comment on this line.
  87. (should
  88. (equal "# \nParagraph"
  89. (org-test-with-temp-text "\nParagraph"
  90. (call-interactively #'org-comment-dwim)
  91. (buffer-string))))
  92. ;; No region selected, and a comment on this line: indent it.
  93. (should
  94. (equal "* Headline\n # Comment"
  95. (org-test-with-temp-text "* Headline\n# <point>Comment"
  96. (let ((org-adapt-indentation t))
  97. (call-interactively #'org-comment-dwim))
  98. (buffer-string))))
  99. ;; Also recognize single # at column 0 as comments.
  100. (should
  101. (equal "# Comment"
  102. (org-test-with-temp-text "# Comment"
  103. (call-interactively #'org-comment-dwim)
  104. (buffer-string))))
  105. ;; Region selected and only comments and blank lines within it:
  106. ;; un-comment all commented lines.
  107. (should
  108. (equal "Comment 1\n\nComment 2"
  109. (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
  110. (transient-mark-mode 1)
  111. (push-mark (point) t t)
  112. (goto-char (point-max))
  113. (call-interactively #'org-comment-dwim)
  114. (buffer-string))))
  115. ;; Region selected without comments: comment all lines if
  116. ;; `comment-empty-lines' is non-nil, only non-blank lines otherwise.
  117. (should
  118. (equal "# Comment 1\n\n# Comment 2"
  119. (org-test-with-temp-text "Comment 1\n\nComment 2"
  120. (transient-mark-mode 1)
  121. (push-mark (point) t t)
  122. (goto-char (point-max))
  123. (let ((comment-empty-lines nil))
  124. (call-interactively #'org-comment-dwim))
  125. (buffer-string))))
  126. (should
  127. (equal "# Comment 1\n# \n# Comment 2"
  128. (org-test-with-temp-text "Comment 1\n\nComment 2"
  129. (transient-mark-mode 1)
  130. (push-mark (point) t t)
  131. (goto-char (point-max))
  132. (let ((comment-empty-lines t))
  133. (call-interactively #'org-comment-dwim))
  134. (buffer-string))))
  135. ;; In front of a keyword without region, insert a new comment.
  136. (should
  137. (equal "# \n#+KEYWORD: value"
  138. (org-test-with-temp-text "#+KEYWORD: value"
  139. (call-interactively #'org-comment-dwim)
  140. (buffer-string))))
  141. ;; Comment a heading
  142. (should
  143. (equal "* COMMENT Test"
  144. (org-test-with-temp-text "* Test"
  145. (call-interactively #'org-comment-dwim)
  146. (buffer-string))))
  147. ;; In a source block, use appropriate syntax.
  148. (should
  149. (equal " ;; "
  150. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n<point>\n#+END_SRC"
  151. (let ((org-edit-src-content-indentation 2))
  152. (call-interactively #'org-comment-dwim))
  153. (buffer-substring-no-properties (line-beginning-position)
  154. (point)))))
  155. (should
  156. (equal "#+BEGIN_SRC emacs-lisp\n ;; a\n ;; b\n#+END_SRC"
  157. (org-test-with-temp-text
  158. "#+BEGIN_SRC emacs-lisp\n<point>a\nb\n#+END_SRC"
  159. (transient-mark-mode 1)
  160. (push-mark (point) t t)
  161. (forward-line 2)
  162. (let ((org-edit-src-content-indentation 2))
  163. (call-interactively #'org-comment-dwim))
  164. (buffer-string)))))
  165. ;;; Date and time analysis
  166. (ert-deftest test-org/org-read-date ()
  167. "Test `org-read-date' specifications."
  168. ;; Parse ISO date with abbreviated year and month.
  169. (should (equal "2012-03-29 16:40"
  170. (let ((org-time-was-given t))
  171. (org-read-date t nil "12-3-29 16:40"))))
  172. ;; Parse Europeans dates.
  173. (should (equal "2012-03-29 16:40"
  174. (let ((org-time-was-given t))
  175. (org-read-date t nil "29.03.2012 16:40"))))
  176. ;; Parse Europeans dates without year.
  177. (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
  178. (let ((org-time-was-given t))
  179. (org-read-date t nil "29.03. 16:40"))))
  180. ;; Relative date applied to current time if there is single
  181. ;; plus/minus, or to default date when there are two of them.
  182. (should
  183. (equal
  184. "2015-03-04"
  185. (org-test-at-time "2014-03-04"
  186. (org-read-date
  187. t nil "+1y" nil
  188. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))
  189. (should
  190. (equal
  191. "2013-03-29"
  192. (org-test-at-time "2014-03-04"
  193. (org-read-date
  194. t nil "++1y" nil
  195. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))
  196. ;; When `org-read-date-prefer-future' is non-nil, prefer future
  197. ;; dates (relatively to now) when incomplete. Otherwise, use
  198. ;; default date.
  199. (should
  200. (equal
  201. "2014-04-01"
  202. (org-test-at-time "2014-03-04"
  203. (let ((org-read-date-prefer-future t))
  204. (org-read-date t nil "1")))))
  205. (should
  206. (equal
  207. "2013-03-04"
  208. (org-test-at-time "2012-03-29"
  209. (let ((org-read-date-prefer-future t))
  210. (org-read-date t nil "3-4")))))
  211. (should
  212. (equal
  213. "2012-03-04"
  214. (org-test-at-time "2012-03-29"
  215. (let ((org-read-date-prefer-future nil))
  216. (org-read-date t nil "3-4")))))
  217. ;; When set to `org-read-date-prefer-future' is set to `time', read
  218. ;; day is moved to tomorrow if specified hour is before current
  219. ;; time. However, it only happens in no other part of the date is
  220. ;; specified.
  221. (should
  222. (equal
  223. "2012-03-30"
  224. (org-test-at-time "2012-03-29 16:40"
  225. (let ((org-read-date-prefer-future 'time))
  226. (org-read-date t nil "00:40" nil)))))
  227. (should-not
  228. (equal
  229. "2012-03-30"
  230. (org-test-at-time "2012-03-29 16:40"
  231. (let ((org-read-date-prefer-future 'time))
  232. (org-read-date t nil "29 00:40" nil)))))
  233. ;; Caveat: `org-read-date-prefer-future' always refers to current
  234. ;; time, not default time, when they differ.
  235. (should
  236. (equal
  237. "2014-04-01"
  238. (org-test-at-time "2014-03-04"
  239. (let ((org-read-date-prefer-future t))
  240. (org-read-date
  241. t nil "1" nil
  242. (apply #'encode-time (org-parse-time-string "2012-03-29")))))))
  243. (should
  244. (equal
  245. "2014-03-25"
  246. (org-test-at-time "2014-03-04"
  247. (let ((org-read-date-prefer-future t))
  248. (org-read-date
  249. t nil "25" nil
  250. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))))
  251. (ert-deftest test-org/org-parse-time-string ()
  252. "Test `org-parse-time-string'."
  253. (should (equal (org-parse-time-string "2012-03-29 16:40")
  254. '(0 40 16 29 3 2012 nil nil nil)))
  255. (should (equal (org-parse-time-string "[2012-03-29 16:40]")
  256. '(0 40 16 29 3 2012 nil nil nil)))
  257. (should (equal (org-parse-time-string "<2012-03-29 16:40>")
  258. '(0 40 16 29 3 2012 nil nil nil)))
  259. (should (equal (org-parse-time-string "<2012-03-29>")
  260. '(0 0 0 29 3 2012 nil nil nil)))
  261. (should (equal (org-parse-time-string "<2012-03-29>" t)
  262. '(0 nil nil 29 3 2012 nil nil nil))))
  263. (ert-deftest test-org/closest-date ()
  264. "Test `org-closest-date' specifications."
  265. (require 'calendar)
  266. ;; Time stamps without a repeater are returned unchanged.
  267. (should
  268. (equal
  269. '(3 29 2012)
  270. (calendar-gregorian-from-absolute
  271. (org-closest-date "<2012-03-29>" "<2014-03-04>" nil))))
  272. ;; Time stamps with a null repeater are returned unchanged.
  273. (should
  274. (equal
  275. '(3 29 2012)
  276. (calendar-gregorian-from-absolute
  277. (org-closest-date "<2012-03-29 +0d>" "<2014-03-04>" nil))))
  278. ;; if PREFER is set to `past' always return a date before, or equal
  279. ;; to CURRENT.
  280. (should
  281. (equal
  282. '(3 1 2014)
  283. (calendar-gregorian-from-absolute
  284. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'past))))
  285. (should
  286. (equal
  287. '(3 4 2014)
  288. (calendar-gregorian-from-absolute
  289. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'past))))
  290. ;; if PREFER is set to `future' always return a date before, or equal
  291. ;; to CURRENT.
  292. (should
  293. (equal
  294. '(3 29 2014)
  295. (calendar-gregorian-from-absolute
  296. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'future))))
  297. (should
  298. (equal
  299. '(3 4 2014)
  300. (calendar-gregorian-from-absolute
  301. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'future))))
  302. ;; If PREFER is neither `past' nor `future', select closest date.
  303. (should
  304. (equal
  305. '(3 1 2014)
  306. (calendar-gregorian-from-absolute
  307. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" nil))))
  308. (should
  309. (equal
  310. '(5 4 2014)
  311. (calendar-gregorian-from-absolute
  312. (org-closest-date "<2012-03-04 +1m>" "<2014-04-28>" nil))))
  313. ;; Test "day" repeater.
  314. (should
  315. (equal '(3 8 2014)
  316. (calendar-gregorian-from-absolute
  317. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'past))))
  318. (should
  319. (equal '(3 10 2014)
  320. (calendar-gregorian-from-absolute
  321. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'future))))
  322. ;; Test "month" repeater.
  323. (should
  324. (equal '(1 5 2015)
  325. (calendar-gregorian-from-absolute
  326. (org-closest-date "<2014-03-05 +2m>" "<2015-02-04>" 'past))))
  327. (should
  328. (equal '(3 29 2014)
  329. (calendar-gregorian-from-absolute
  330. (org-closest-date "<2012-03-29 +2m>" "<2014-03-04>" 'future))))
  331. ;; Test "year" repeater.
  332. (should
  333. (equal '(3 5 2014)
  334. (calendar-gregorian-from-absolute
  335. (org-closest-date "<2014-03-05 +2y>" "<2015-02-04>" 'past))))
  336. (should
  337. (equal '(3 29 2014)
  338. (calendar-gregorian-from-absolute
  339. (org-closest-date "<2012-03-29 +2y>" "<2014-03-04>" 'future)))))
  340. (ert-deftest test-org/deadline-close-p ()
  341. "Test `org-deadline-close-p' specifications."
  342. (org-test-at-time "2016-06-03 Fri 01:43"
  343. ;; Timestamps are close if they are within `ndays' of lead time.
  344. (org-test-with-temp-text "* Heading"
  345. (should (org-deadline-close-p "2016-06-03 Fri" 0))
  346. (should (org-deadline-close-p "2016-06-02 Thu" 0))
  347. (should-not (org-deadline-close-p "2016-06-04 Sat" 0))
  348. (should (org-deadline-close-p "2016-06-04 Sat" 1))
  349. (should (org-deadline-close-p "2016-06-03 Fri 12:00" 0)))
  350. ;; Read `ndays' from timestamp if argument not given.
  351. (org-test-with-temp-text "* H"
  352. (should (org-deadline-close-p "2016-06-04 Sat -1d"))
  353. (should-not (org-deadline-close-p "2016-06-04 Sat -0d"))
  354. (should (org-deadline-close-p "2016-06-10 Fri -1w"))
  355. (should-not (org-deadline-close-p "2016-06-11 Sat -1w")))
  356. ;; Prefer `ndays' argument over lead time in timestamp.
  357. (org-test-with-temp-text "* H"
  358. (should (org-deadline-close-p "2016-06-04 Sat -0d" 1))
  359. (should-not (org-deadline-close-p "2016-06-04 Sat -0d" 0)))
  360. ;; Completed tasks are never close.
  361. (let ((org-todo-keywords '(("TODO" "|" "DONE"))))
  362. (org-test-with-temp-text "* TODO Heading"
  363. (should (org-deadline-close-p "2016-06-03")))
  364. (org-test-with-temp-text "* DONE Heading"
  365. (should-not (org-deadline-close-p "2016-06-03"))))))
  366. ;;; Drawers
  367. (ert-deftest test-org/at-property-p ()
  368. "Test `org-at-property-p' specifications."
  369. (should
  370. (equal 't
  371. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:PROP: t\n:END:\n"
  372. (org-at-property-p))))
  373. (should
  374. (equal 't
  375. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n:END:\n"
  376. (org-at-property-p)))))
  377. (ert-deftest test-org/at-property-drawer-p ()
  378. "Test `org-at-property-drawer-p' specifications."
  379. (should
  380. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:PROP: t\n:END:\n"
  381. (org-at-property-drawer-p)))
  382. (should
  383. (org-test-with-temp-text ":PROPERTIES:\n:PROP: t\n:END:\n"
  384. (org-at-property-drawer-p)))
  385. ;; The function only returns t if point is at the first line of
  386. ;; a property block.
  387. (should-not
  388. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n:END:\n"
  389. (org-at-property-drawer-p)))
  390. ;; The function ignores incomplete drawers.
  391. (should-not
  392. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n"
  393. (org-at-property-drawer-p)))
  394. ;; 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. (ert-deftest test-org/auto-fill-function ()
  741. "Test auto-filling features."
  742. ;; Auto fill paragraph.
  743. (should
  744. (equal "12345\n7890"
  745. (org-test-with-temp-text "12345 7890"
  746. (let ((fill-column 5))
  747. (end-of-line)
  748. (org-auto-fill-function)
  749. (buffer-string)))))
  750. ;; Auto fill first paragraph in an item.
  751. (should
  752. (equal "- 12345\n 7890"
  753. (org-test-with-temp-text "- 12345 7890"
  754. (let ((fill-column 7))
  755. (end-of-line)
  756. (org-auto-fill-function)
  757. (buffer-string)))))
  758. ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
  759. (should
  760. (equal "> 12345\n 7890"
  761. (org-test-with-temp-text "> 12345 7890"
  762. (let ((fill-column 10)
  763. (adaptive-fill-regexp "[ \t]*>+[ \t]*")
  764. (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
  765. (end-of-line)
  766. (org-auto-fill-function)
  767. (buffer-string)))))
  768. (should
  769. (equal "> 12345\n> 12345\n> 7890"
  770. (org-test-with-temp-text "> 12345\n> 12345 7890"
  771. (let ((fill-column 10)
  772. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  773. (goto-char (point-max))
  774. (org-auto-fill-function)
  775. (buffer-string)))))
  776. (should-not
  777. (equal " 12345\n *12345\n *12345"
  778. (org-test-with-temp-text " 12345\n *12345 12345"
  779. (let ((fill-column 10)
  780. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  781. (goto-char (point-max))
  782. (org-auto-fill-function)
  783. (buffer-string)))))
  784. ;; Auto fill comments.
  785. (should
  786. (equal " # 12345\n # 7890"
  787. (org-test-with-temp-text " # 12345 7890"
  788. (let ((fill-column 10))
  789. (end-of-line)
  790. (org-auto-fill-function)
  791. (buffer-string)))))
  792. ;; A hash within a line isn't a comment.
  793. (should-not
  794. (equal "12345 # 7890\n# 1"
  795. (org-test-with-temp-text "12345 # 7890 1"
  796. (let ((fill-column 12))
  797. (end-of-line)
  798. (org-auto-fill-function)
  799. (buffer-string)))))
  800. ;; Correctly interpret empty prefix.
  801. (should-not
  802. (equal "# a\n# b\nRegular\n# paragraph"
  803. (org-test-with-temp-text "# a\n# b\nRegular paragraph"
  804. (let ((fill-column 12))
  805. (end-of-line 3)
  806. (org-auto-fill-function)
  807. (buffer-string)))))
  808. ;; Comment block: auto fill contents.
  809. (should
  810. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  811. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  812. (let ((fill-column 5))
  813. (forward-line)
  814. (end-of-line)
  815. (org-auto-fill-function)
  816. (buffer-string)))))
  817. (should
  818. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  819. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  820. (let ((fill-column 5))
  821. (forward-line)
  822. (end-of-line)
  823. (org-auto-fill-function)
  824. (buffer-string)))))
  825. ;; Do not fill if a new item could be created.
  826. (should-not
  827. (equal "12345\n- 90"
  828. (org-test-with-temp-text "12345 - 90"
  829. (let ((fill-column 5))
  830. (end-of-line)
  831. (org-auto-fill-function)
  832. (buffer-string)))))
  833. ;; Do not fill if a line break could be introduced.
  834. (should-not
  835. (equal "123\\\\\n7890"
  836. (org-test-with-temp-text "123\\\\ 7890"
  837. (let ((fill-column 6))
  838. (end-of-line)
  839. (org-auto-fill-function)
  840. (buffer-string)))))
  841. ;; Do not fill affiliated keywords.
  842. (should-not
  843. (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
  844. (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
  845. (let ((fill-column 20))
  846. (end-of-line)
  847. (org-auto-fill-function)
  848. (buffer-string))))))
  849. ;;; Indentation
  850. (ert-deftest test-org/indent-line ()
  851. "Test `org-indent-line' specifications."
  852. ;; Do not indent diary sexps, footnote definitions or headlines.
  853. (should
  854. (zerop
  855. (org-test-with-temp-text "%%(org-calendar-holiday)"
  856. (org-indent-line)
  857. (org-get-indentation))))
  858. (should
  859. (zerop
  860. (org-test-with-temp-text "[fn:1] fn"
  861. (let ((org-adapt-indentation t)) (org-indent-line))
  862. (org-get-indentation))))
  863. (should
  864. (zerop
  865. (org-test-with-temp-text "* H"
  866. (org-indent-line)
  867. (org-get-indentation))))
  868. ;; Do not indent before first headline.
  869. (should
  870. (zerop
  871. (org-test-with-temp-text ""
  872. (org-indent-line)
  873. (org-get-indentation))))
  874. ;; Indent according to headline level otherwise, unless
  875. ;; `org-adapt-indentation' is nil.
  876. (should
  877. (= 2
  878. (org-test-with-temp-text "* H\n<point>A"
  879. (let ((org-adapt-indentation t)) (org-indent-line))
  880. (org-get-indentation))))
  881. (should
  882. (= 2
  883. (org-test-with-temp-text "* H\n<point>\nA"
  884. (let ((org-adapt-indentation t)) (org-indent-line))
  885. (org-get-indentation))))
  886. (should
  887. (zerop
  888. (org-test-with-temp-text "* H\n<point>A"
  889. (let ((org-adapt-indentation nil)) (org-indent-line))
  890. (org-get-indentation))))
  891. ;; Indenting preserves point position.
  892. (should
  893. (org-test-with-temp-text "* H\nA<point>B"
  894. (let ((org-adapt-indentation t)) (org-indent-line))
  895. (looking-at "B")))
  896. ;; Do not change indentation at an item or a LaTeX environment.
  897. (should
  898. (= 1
  899. (org-test-with-temp-text "* H\n<point> - A"
  900. (let ((org-adapt-indentation t)) (org-indent-line))
  901. (org-get-indentation))))
  902. (should
  903. (= 1
  904. (org-test-with-temp-text
  905. "\\begin{equation}\n <point>1+1=2\n\\end{equation}"
  906. (org-indent-line)
  907. (org-get-indentation))))
  908. ;; On blank lines at the end of a list, indent like last element
  909. ;; within it if the line is still in the list. If the last element
  910. ;; is an item, indent like its contents. Otherwise, indent like the
  911. ;; whole list.
  912. (should
  913. (= 4
  914. (org-test-with-temp-text "* H\n- A\n - AA\n<point>"
  915. (let ((org-adapt-indentation t)) (org-indent-line))
  916. (org-get-indentation))))
  917. (should
  918. (= 4
  919. (org-test-with-temp-text "* H\n- A\n -\n\n<point>"
  920. (let ((org-adapt-indentation t)) (org-indent-line))
  921. (org-get-indentation))))
  922. (should
  923. (zerop
  924. (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n<point>"
  925. (let ((org-adapt-indentation t)) (org-indent-line))
  926. (org-get-indentation))))
  927. (should
  928. (= 4
  929. (org-test-with-temp-text "* H\n- A\n - \n<point>"
  930. (let ((org-adapt-indentation t)) (org-indent-line))
  931. (org-get-indentation))))
  932. (should
  933. (= 4
  934. (org-test-with-temp-text
  935. "* H\n - \n #+BEGIN_SRC emacs-lisp\n t\n #+END_SRC\n<point>"
  936. (let ((org-adapt-indentation t)) (org-indent-line))
  937. (org-get-indentation))))
  938. (should
  939. (= 2
  940. (org-test-with-temp-text "- A\n B\n\n<point>"
  941. (let ((org-adapt-indentation nil)) (org-indent-line))
  942. (org-get-indentation))))
  943. (should
  944. (= 2
  945. (org-test-with-temp-text
  946. "- A\n \begin{cases} 1 + 1\n \end{cases}\n\n<point>"
  947. (let ((org-adapt-indentation nil)) (org-indent-line))
  948. (org-get-indentation))))
  949. ;; Likewise, on a blank line at the end of a footnote definition,
  950. ;; indent at column 0 if line belongs to the definition. Otherwise,
  951. ;; indent like the definition itself.
  952. (should
  953. (zerop
  954. (org-test-with-temp-text "* H\n[fn:1] Definition\n<point>"
  955. (let ((org-adapt-indentation t)) (org-indent-line))
  956. (org-get-indentation))))
  957. (should
  958. (zerop
  959. (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n<point>"
  960. (let ((org-adapt-indentation t)) (org-indent-line))
  961. (org-get-indentation))))
  962. ;; After the end of the contents of a greater element, indent like
  963. ;; the beginning of the element.
  964. (should
  965. (= 1
  966. (org-test-with-temp-text
  967. " #+BEGIN_CENTER\n Contents\n<point>#+END_CENTER"
  968. (org-indent-line)
  969. (org-get-indentation))))
  970. ;; On blank lines after a paragraph, indent like its last non-empty
  971. ;; line.
  972. (should
  973. (= 1
  974. (org-test-with-temp-text " Paragraph\n\n<point>"
  975. (org-indent-line)
  976. (org-get-indentation))))
  977. ;; At the first line of an element, indent like previous element's
  978. ;; first line, ignoring footnotes definitions and inline tasks, or
  979. ;; according to parent.
  980. (let ((org-adapt-indentation t))
  981. (should
  982. (= 2
  983. (org-test-with-temp-text "A\n\n B\n\nC<point>"
  984. (org-indent-line)
  985. (org-get-indentation))))
  986. (should
  987. (= 1
  988. (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC<point>"
  989. (org-indent-line)
  990. (org-get-indentation))))
  991. (should
  992. (= 1
  993. (org-test-with-temp-text
  994. " #+BEGIN_CENTER\n<point> Contents\n#+END_CENTER"
  995. (org-indent-line)
  996. (org-get-indentation)))))
  997. ;; Within code part of a source block, use language major mode if
  998. ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
  999. ;; according to line above.
  1000. (should
  1001. (= 6
  1002. (org-test-with-temp-text
  1003. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  1004. (let ((org-src-tab-acts-natively t)
  1005. (org-edit-src-content-indentation 0))
  1006. (org-indent-line))
  1007. (org-get-indentation))))
  1008. (should
  1009. (= 1
  1010. (org-test-with-temp-text
  1011. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  1012. (let ((org-src-tab-acts-natively nil)
  1013. (org-edit-src-content-indentation 0))
  1014. (org-indent-line))
  1015. (org-get-indentation))))
  1016. ;; Otherwise, indent like the first non-blank line above.
  1017. (should
  1018. (zerop
  1019. (org-test-with-temp-text
  1020. "#+BEGIN_CENTER\nline1\n\n<point> line2\n#+END_CENTER"
  1021. (org-indent-line)
  1022. (org-get-indentation))))
  1023. ;; Align node properties according to `org-property-format'. Handle
  1024. ;; nicely empty values.
  1025. (should
  1026. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1027. (org-test-with-temp-text
  1028. "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
  1029. (let ((org-property-format "%-10s %s")) (org-indent-line))
  1030. (buffer-string))))
  1031. (should
  1032. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1033. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
  1034. (let ((org-property-format "%-10s %s")) (org-indent-line))
  1035. (buffer-string)))))
  1036. (ert-deftest test-org/indent-region ()
  1037. "Test `org-indent-region' specifications."
  1038. ;; Indent paragraph.
  1039. (let ((org-adapt-indentation t))
  1040. (should
  1041. (equal "A\nB\nC"
  1042. (org-test-with-temp-text " A\nB\n C"
  1043. (org-indent-region (point-min) (point-max))
  1044. (buffer-string)))))
  1045. ;; Indent greater elements along with their contents.
  1046. (should
  1047. (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
  1048. (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
  1049. (org-indent-region (point-min) (point-max))
  1050. (buffer-string))))
  1051. ;; Ignore contents of verse blocks. Only indent block delimiters.
  1052. (should
  1053. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1054. (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1055. (org-indent-region (point-min) (point-max))
  1056. (buffer-string))))
  1057. (let ((org-adapt-indentation t))
  1058. (should
  1059. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1060. (org-test-with-temp-text " #+BEGIN_VERSE\n A\n B\n #+END_VERSE"
  1061. (org-indent-region (point-min) (point-max))
  1062. (buffer-string)))))
  1063. ;; Indent example blocks as a single block, unless indentation
  1064. ;; should be preserved. In this case only indent the block markers.
  1065. (should
  1066. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1067. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1068. (org-indent-region (point-min) (point-max))
  1069. (buffer-string))))
  1070. (let ((org-adapt-indentation t))
  1071. (should
  1072. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1073. (org-test-with-temp-text " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1074. (org-indent-region (point-min) (point-max))
  1075. (buffer-string))))
  1076. (should
  1077. (equal "#+BEGIN_EXAMPLE -i\n A\n B\n#+END_EXAMPLE"
  1078. (org-test-with-temp-text
  1079. " #+BEGIN_EXAMPLE -i\n A\n B\n #+END_EXAMPLE"
  1080. (org-indent-region (point-min) (point-max))
  1081. (buffer-string))))
  1082. (should
  1083. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1084. (org-test-with-temp-text
  1085. " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1086. (let ((org-src-preserve-indentation t))
  1087. (org-indent-region (point-min) (point-max)))
  1088. (buffer-string)))))
  1089. ;; Treat export blocks as a whole.
  1090. (should
  1091. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1092. (org-test-with-temp-text "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1093. (org-indent-region (point-min) (point-max))
  1094. (buffer-string))))
  1095. (let ((org-adapt-indentation t))
  1096. (should
  1097. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1098. (org-test-with-temp-text
  1099. " #+BEGIN_EXPORT latex\n A\n B\n #+END_EXPORT"
  1100. (org-indent-region (point-min) (point-max))
  1101. (buffer-string)))))
  1102. ;; Indent according to mode if `org-src-tab-acts-natively' is
  1103. ;; non-nil. Otherwise, do not indent code at all.
  1104. (should
  1105. (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
  1106. (org-test-with-temp-text
  1107. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1108. (let ((org-src-tab-acts-natively t)
  1109. (org-edit-src-content-indentation 0))
  1110. (org-indent-region (point-min) (point-max)))
  1111. (buffer-string))))
  1112. (should
  1113. (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1114. (org-test-with-temp-text
  1115. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1116. (let ((org-src-tab-acts-natively nil)
  1117. (org-edit-src-content-indentation 0))
  1118. (org-indent-region (point-min) (point-max)))
  1119. (buffer-string))))
  1120. ;; Align node properties according to `org-property-format'. Handle
  1121. ;; nicely empty values.
  1122. (should
  1123. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1124. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
  1125. (let ((org-property-format "%-10s %s")
  1126. (org-adapt-indentation nil))
  1127. (org-indent-region (point) (point-max)))
  1128. (buffer-string))))
  1129. (should
  1130. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1131. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
  1132. (let ((org-property-format "%-10s %s")
  1133. (org-adapt-indentation nil))
  1134. (org-indent-region (point) (point-max)))
  1135. (buffer-string))))
  1136. ;; Indent plain lists.
  1137. (let ((org-adapt-indentation t))
  1138. (should
  1139. (equal "- A\n B\n - C\n\n D"
  1140. (org-test-with-temp-text "- A\n B\n - C\n\n D"
  1141. (org-indent-region (point-min) (point-max))
  1142. (buffer-string))))
  1143. (should
  1144. (equal "- A\n\n- B"
  1145. (org-test-with-temp-text " - A\n\n - B"
  1146. (org-indent-region (point-min) (point-max))
  1147. (buffer-string)))))
  1148. ;; Indent footnote definitions.
  1149. (should
  1150. (equal "[fn:1] Definition\n\nDefinition"
  1151. (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
  1152. (org-indent-region (point-min) (point-max))
  1153. (buffer-string))))
  1154. ;; Special case: Start indenting on a blank line.
  1155. (should
  1156. (equal "\nParagraph"
  1157. (org-test-with-temp-text "\n Paragraph"
  1158. (org-indent-region (point-min) (point-max))
  1159. (buffer-string)))))
  1160. ;;; Editing
  1161. (ert-deftest test-org/delete-indentation ()
  1162. "Test `org-delete-indentation' specifications."
  1163. ;; Regular test.
  1164. (should (equal "foo bar"
  1165. (org-test-with-temp-text
  1166. "foo \n bar<point>"
  1167. (org-delete-indentation)
  1168. (buffer-string))))
  1169. ;; With optional argument.
  1170. (should (equal "foo bar"
  1171. (org-test-with-temp-text
  1172. "foo<point> \n bar"
  1173. (org-delete-indentation t)
  1174. (buffer-string))))
  1175. ;; At headline text should be appended to the headline text.
  1176. (should
  1177. (equal"* foo bar :tag:"
  1178. (let (org-auto-align-tags)
  1179. (org-test-with-temp-text
  1180. "* foo :tag:\n bar<point>"
  1181. (org-delete-indentation)
  1182. (buffer-string)))))
  1183. (should
  1184. (equal "* foo bar :tag:"
  1185. (let (org-auto-align-tags)
  1186. (org-test-with-temp-text
  1187. "* foo <point>:tag:\n bar"
  1188. (org-delete-indentation t)
  1189. (buffer-string))))))
  1190. (ert-deftest test-org/return ()
  1191. "Test `org-return' specifications."
  1192. ;; Regular test.
  1193. (should
  1194. (equal "Para\ngraph"
  1195. (org-test-with-temp-text "Para<point>graph"
  1196. (org-return)
  1197. (buffer-string))))
  1198. ;; With optional argument, indent line.
  1199. (should
  1200. (equal " Para\n graph"
  1201. (org-test-with-temp-text " Para<point>graph"
  1202. (org-return t)
  1203. (buffer-string))))
  1204. ;; On a table, call `org-table-next-row'.
  1205. (should
  1206. (org-test-with-temp-text "| <point>a |\n| b |"
  1207. (org-return)
  1208. (looking-at-p "b")))
  1209. ;; Open link or timestamp under point when `org-return-follows-link'
  1210. ;; is non-nil.
  1211. (should
  1212. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1213. (let ((org-return-follows-link t)
  1214. (org-link-search-must-match-exact-headline nil))
  1215. (org-return))
  1216. (looking-at-p "<<target>>")))
  1217. (should-not
  1218. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1219. (let ((org-return-follows-link nil)) (org-return))
  1220. (looking-at-p "<<target>>")))
  1221. (should
  1222. (org-test-with-temp-text "* [[b][a<point>]]\n* b"
  1223. (let ((org-return-follows-link t)) (org-return))
  1224. (looking-at-p "* b")))
  1225. (should
  1226. (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
  1227. (let ((org-return-follows-link t)
  1228. (org-link-search-must-match-exact-headline nil))
  1229. (org-return))
  1230. (looking-at-p "<<target>>")))
  1231. (should-not
  1232. (org-test-with-temp-text "Link [[target]]<point> <<target>>"
  1233. (let ((org-return-follows-link t)
  1234. (org-link-search-must-match-exact-headline nil))
  1235. (org-return))
  1236. (looking-at-p "<<target>>")))
  1237. ;; When `org-return-follows-link' is non-nil, tolerate links and
  1238. ;; timestamps in comments, node properties, etc.
  1239. (should
  1240. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1241. (let ((org-return-follows-link t)
  1242. (org-link-search-must-match-exact-headline nil))
  1243. (org-return))
  1244. (looking-at-p "<<target>>")))
  1245. (should-not
  1246. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1247. (let ((org-return-follows-link nil)) (org-return))
  1248. (looking-at-p "<<target>>")))
  1249. (should-not
  1250. (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
  1251. (let ((org-return-follows-link t)
  1252. (org-link-search-must-match-exact-headline nil))
  1253. (org-return))
  1254. (looking-at-p "<<target>>")))
  1255. ;; Non-nil `org-return-follows-link' ignores read-only state of
  1256. ;; a buffer.
  1257. (should
  1258. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1259. (let ((org-return-follows-link t)
  1260. (org-link-search-must-match-exact-headline nil))
  1261. (setq buffer-read-only t)
  1262. (call-interactively #'org-return))
  1263. (looking-at-p "<<target>>")))
  1264. ;; `org-return-follows-link' handle multi-line lines.
  1265. (should
  1266. (org-test-with-temp-text
  1267. "[[target][This is a very\n long description<point>]]\n <<target>>"
  1268. (let ((org-return-follows-link t)
  1269. (org-link-search-must-match-exact-headline nil))
  1270. (org-return))
  1271. (looking-at-p "<<target>>")))
  1272. (should-not
  1273. (org-test-with-temp-text
  1274. "[[target][This is a very\n long description]]<point>\n <<target>>"
  1275. (let ((org-return-follows-link t)
  1276. (org-link-search-must-match-exact-headline nil))
  1277. (org-return))
  1278. (looking-at-p "<<target>>")))
  1279. ;; However, do not open link when point is in a table.
  1280. (should
  1281. (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
  1282. (let ((org-return-follows-link t)) (org-return))
  1283. (looking-at-p "between")))
  1284. ;; Special case: in a list, when indenting, do not break structure.
  1285. (should
  1286. (equal "- A\n B"
  1287. (org-test-with-temp-text "- A <point>B"
  1288. (org-return t)
  1289. (buffer-string))))
  1290. (should
  1291. (equal "- A\n\n- B"
  1292. (org-test-with-temp-text "- A\n<point>- B"
  1293. (org-return t)
  1294. (buffer-string))))
  1295. ;; On tags part of a headline, add a newline below it instead of
  1296. ;; breaking it.
  1297. (should
  1298. (equal "* H :tag:\n"
  1299. (org-test-with-temp-text "* H :<point>tag:"
  1300. (org-return)
  1301. (buffer-string))))
  1302. ;; Before headline text, add a newline below it instead of breaking
  1303. ;; it.
  1304. (should
  1305. (equal "* TODO H :tag:\n"
  1306. (org-test-with-temp-text "* <point>TODO H :tag:"
  1307. (org-return)
  1308. (buffer-string))))
  1309. (should
  1310. (equal "* TODO [#B] H :tag:\n"
  1311. (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
  1312. (org-return)
  1313. (buffer-string))))
  1314. (should ;TODO are case-sensitive
  1315. (equal "* \nTodo"
  1316. (org-test-with-temp-text "* <point>Todo"
  1317. (org-return)
  1318. (buffer-string))))
  1319. ;; At headline text, break headline text but preserve tags.
  1320. (should
  1321. (equal "* TODO [#B] foo :tag:\nbar"
  1322. (let (org-auto-align-tags)
  1323. (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
  1324. (org-return)
  1325. (buffer-string)))))
  1326. ;; At bol of headline insert newline.
  1327. (should
  1328. (equal "\n* h"
  1329. (org-test-with-temp-text "<point>* h"
  1330. (org-return)
  1331. (buffer-string))))
  1332. ;; Refuse to leave invalid headline in buffer.
  1333. (should
  1334. (equal "* h\n"
  1335. (org-test-with-temp-text "*<point> h"
  1336. (org-return)
  1337. (buffer-string))))
  1338. ;; Before first column or after last one in a table, split the
  1339. ;; table.
  1340. (should
  1341. (equal "| a |\n\n| b |"
  1342. (org-test-with-temp-text "| a |\n<point>| b |"
  1343. (org-return)
  1344. (buffer-string))))
  1345. (should
  1346. (equal "| a |\n\n| b |"
  1347. (org-test-with-temp-text "| a |<point>\n| b |"
  1348. (org-return)
  1349. (buffer-string))))
  1350. ;; Do not auto-fill on hitting <RET> inside a property drawer.
  1351. (should
  1352. (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:"
  1353. (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:"
  1354. (setq-local fill-column 10)
  1355. (auto-fill-mode 1)
  1356. (org-return)
  1357. (buffer-string)))))
  1358. (ert-deftest test-org/with-electric-indent ()
  1359. "Test RET and C-j specifications with `electric-indent-mode' on."
  1360. ;; Call commands interactively, since this is how `newline' knows it
  1361. ;; must run `post-self-insert-hook'.
  1362. ;;
  1363. ;; RET, like `newline', should indent.
  1364. (should
  1365. (equal " Para\n graph"
  1366. (org-test-with-temp-text " Para<point>graph"
  1367. (electric-indent-local-mode 1)
  1368. (call-interactively 'org-return)
  1369. (buffer-string))))
  1370. (should
  1371. (equal "- item1\n item2"
  1372. (org-test-with-temp-text "- item1<point>item2"
  1373. (electric-indent-local-mode 1)
  1374. (call-interactively 'org-return)
  1375. (buffer-string))))
  1376. ;; TODO: test more values of `org-adapt-indentation'.
  1377. (let ((org-adapt-indentation t))
  1378. (should
  1379. (equal "* heading\n body"
  1380. (org-test-with-temp-text "* heading<point>body"
  1381. (electric-indent-local-mode 1)
  1382. (call-interactively 'org-return)
  1383. (buffer-string)))))
  1384. ;; C-j, like `electric-newline-and-maybe-indent', should not indent.
  1385. (should
  1386. (equal " Para\ngraph"
  1387. (org-test-with-temp-text " Para<point>graph"
  1388. (electric-indent-local-mode 1)
  1389. (call-interactively 'org-return-and-maybe-indent)
  1390. (buffer-string))))
  1391. (should
  1392. (equal "- item1\nitem2"
  1393. (org-test-with-temp-text "- item1<point>item2"
  1394. (electric-indent-local-mode 1)
  1395. (call-interactively 'org-return-and-maybe-indent)
  1396. (buffer-string))))
  1397. ;; TODO: test more values of `org-adapt-indentation'.
  1398. (let ((org-adapt-indentation t))
  1399. (should
  1400. (equal "* heading\nbody"
  1401. (org-test-with-temp-text "* heading<point>body"
  1402. (electric-indent-local-mode 1)
  1403. (call-interactively 'org-return-and-maybe-indent)
  1404. (buffer-string))))))
  1405. (ert-deftest test-org/without-electric-indent ()
  1406. "Test RET and C-j specifications with `electric-indent-mode' off."
  1407. ;; Call commands interactively, since this is how `newline' knows it
  1408. ;; must run `post-self-insert-hook'.
  1409. ;;
  1410. ;; RET, like `newline', should not indent.
  1411. (should
  1412. (equal " Para\ngraph"
  1413. (org-test-with-temp-text " Para<point>graph"
  1414. (electric-indent-local-mode 0)
  1415. (call-interactively 'org-return)
  1416. (buffer-string))))
  1417. (should
  1418. (equal "- item1\nitem2"
  1419. (org-test-with-temp-text "- item1<point>item2"
  1420. (electric-indent-local-mode 0)
  1421. (call-interactively 'org-return)
  1422. (buffer-string))))
  1423. (should
  1424. (equal "* heading\nbody"
  1425. (org-test-with-temp-text "* heading<point>body"
  1426. (electric-indent-local-mode 0)
  1427. (call-interactively 'org-return)
  1428. (buffer-string))))
  1429. ;; C-j, like `electric-newline-and-maybe-indent', should indent.
  1430. (should
  1431. (equal " Para\n graph"
  1432. (org-test-with-temp-text " Para<point>graph"
  1433. (electric-indent-local-mode 0)
  1434. (call-interactively 'org-return-and-maybe-indent)
  1435. (buffer-string))))
  1436. (should
  1437. (equal "- item1\n item2"
  1438. (org-test-with-temp-text "- item1<point>item2"
  1439. (electric-indent-local-mode 0)
  1440. (call-interactively 'org-return-and-maybe-indent)
  1441. (buffer-string))))
  1442. ;; TODO: test more values of `org-adapt-indentation'.
  1443. (let ((org-adapt-indentation t))
  1444. (should
  1445. (equal "* heading\n body"
  1446. (org-test-with-temp-text "* heading<point>body"
  1447. (electric-indent-local-mode 0)
  1448. (call-interactively 'org-return-and-maybe-indent)
  1449. (buffer-string))))))
  1450. (ert-deftest test-org/meta-return ()
  1451. "Test M-RET (`org-meta-return') specifications."
  1452. ;; In a table field insert a row above.
  1453. (should
  1454. (org-test-with-temp-text "| a |"
  1455. (forward-char)
  1456. (org-meta-return)
  1457. (forward-line -1)
  1458. (looking-at "| |$")))
  1459. ;; In a paragraph change current line into a header.
  1460. (should
  1461. (org-test-with-temp-text "a"
  1462. (org-meta-return)
  1463. (beginning-of-line)
  1464. (looking-at "\* a$")))
  1465. ;; In an item insert an item, in this case above.
  1466. (should
  1467. (org-test-with-temp-text "- a"
  1468. (org-meta-return)
  1469. (beginning-of-line)
  1470. (looking-at "- $")))
  1471. ;; In a drawer and item insert an item, in this case above.
  1472. (should
  1473. (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
  1474. (forward-line)
  1475. (org-meta-return)
  1476. (beginning-of-line)
  1477. (looking-at "- $"))))
  1478. (ert-deftest test-org/insert-heading ()
  1479. "Test `org-insert-heading' specifications."
  1480. ;; In an empty buffer, insert a new headline.
  1481. (should
  1482. (equal "* "
  1483. (org-test-with-temp-text ""
  1484. (org-insert-heading)
  1485. (buffer-string))))
  1486. ;; At the beginning of a line, turn it into a headline.
  1487. (should
  1488. (equal "* P"
  1489. (org-test-with-temp-text "<point>P"
  1490. (org-insert-heading)
  1491. (buffer-string))))
  1492. ;; In the middle of a line, split the line if allowed, otherwise,
  1493. ;; insert the headline at its end.
  1494. (should
  1495. (equal "Para\n* graph"
  1496. (org-test-with-temp-text "Para<point>graph"
  1497. (let ((org-M-RET-may-split-line '((default . t))))
  1498. (org-insert-heading))
  1499. (buffer-string))))
  1500. (should
  1501. (equal "Paragraph\n* "
  1502. (org-test-with-temp-text "Para<point>graph"
  1503. (let ((org-M-RET-may-split-line '((default . nil))))
  1504. (org-insert-heading))
  1505. (buffer-string))))
  1506. ;; At the beginning of a headline, create one above.
  1507. (should
  1508. (equal "* \n* H"
  1509. (org-test-with-temp-text "* H"
  1510. (org-insert-heading)
  1511. (buffer-string))))
  1512. ;; In the middle of a headline, split it if allowed.
  1513. (should
  1514. (equal "* H\n* 1"
  1515. (org-test-with-temp-text "* H<point>1"
  1516. (let ((org-M-RET-may-split-line '((headline . t))))
  1517. (org-insert-heading))
  1518. (buffer-string))))
  1519. (should
  1520. (equal "* H1\n* "
  1521. (org-test-with-temp-text "* H<point>1"
  1522. (let ((org-M-RET-may-split-line '((headline . nil))))
  1523. (org-insert-heading))
  1524. (buffer-string))))
  1525. ;; However, splitting cannot happen on TODO keywords, priorities or
  1526. ;; tags.
  1527. (should
  1528. (equal "* TODO H1\n* "
  1529. (org-test-with-temp-text "* TO<point>DO H1"
  1530. (let ((org-M-RET-may-split-line '((headline . t))))
  1531. (org-insert-heading))
  1532. (buffer-string))))
  1533. (should
  1534. (equal "* [#A] H1\n* "
  1535. (org-test-with-temp-text "* [#<point>A] H1"
  1536. (let ((org-M-RET-may-split-line '((headline . t))))
  1537. (org-insert-heading))
  1538. (buffer-string))))
  1539. (should
  1540. (equal "* H1 :tag:\n* "
  1541. (org-test-with-temp-text "* H1 :ta<point>g:"
  1542. (let ((org-M-RET-may-split-line '((headline . t))))
  1543. (org-insert-heading))
  1544. (buffer-string))))
  1545. ;; New headline level depends on the level of the headline above.
  1546. (should
  1547. (equal "** H\n** P"
  1548. (org-test-with-temp-text "** H\n<point>P"
  1549. (org-insert-heading)
  1550. (buffer-string))))
  1551. (should
  1552. (equal "** H\nPara\n** graph"
  1553. (org-test-with-temp-text "** H\nPara<point>graph"
  1554. (let ((org-M-RET-may-split-line '((default . t))))
  1555. (org-insert-heading))
  1556. (buffer-string))))
  1557. (should
  1558. (equal "** \n** H"
  1559. (org-test-with-temp-text "** H"
  1560. (org-insert-heading)
  1561. (buffer-string))))
  1562. ;; When called with one universal argument, insert a new headline at
  1563. ;; the end of the current subtree, independently on the position of
  1564. ;; point.
  1565. (should
  1566. (equal
  1567. "* "
  1568. (org-test-with-temp-text ""
  1569. (let ((org-insert-heading-respect-content nil))
  1570. (org-insert-heading '(4)))
  1571. (buffer-string))))
  1572. (should
  1573. (equal
  1574. "entry
  1575. * "
  1576. (org-test-with-temp-text "entry"
  1577. (let ((org-insert-heading-respect-content nil))
  1578. (org-insert-heading '(4)))
  1579. (buffer-string))))
  1580. (should
  1581. (equal
  1582. "* H1\n** H2\n* "
  1583. (org-test-with-temp-text "* H1\n** H2"
  1584. (let ((org-insert-heading-respect-content nil))
  1585. (org-insert-heading '(4)))
  1586. (buffer-string))))
  1587. (should
  1588. (equal
  1589. "* H1\n** H2\n* "
  1590. (org-test-with-temp-text "* H<point>1\n** H2"
  1591. (let ((org-insert-heading-respect-content nil))
  1592. (org-insert-heading '(4)))
  1593. (buffer-string))))
  1594. ;; When called with two universal arguments, insert a new headline
  1595. ;; at the end of the grandparent subtree.
  1596. (should
  1597. (equal "* H1\n** H3\n- item\n** H2\n** "
  1598. (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
  1599. (let ((org-insert-heading-respect-content nil))
  1600. (org-insert-heading '(16)))
  1601. (buffer-string))))
  1602. ;; When optional TOP-LEVEL argument is non-nil, always insert
  1603. ;; a level 1 heading.
  1604. (should
  1605. (equal "* H1\n** H2\n* "
  1606. (org-test-with-temp-text "* H1\n** H2<point>"
  1607. (org-insert-heading nil nil t)
  1608. (buffer-string))))
  1609. (should
  1610. (equal "* H1\n- item\n* "
  1611. (org-test-with-temp-text "* H1\n- item<point>"
  1612. (org-insert-heading nil nil t)
  1613. (buffer-string))))
  1614. ;; Obey `org-blank-before-new-entry'.
  1615. (should
  1616. (equal "* H1\n\n* "
  1617. (org-test-with-temp-text "* H1<point>"
  1618. (let ((org-blank-before-new-entry '((heading . t))))
  1619. (org-insert-heading))
  1620. (buffer-string))))
  1621. (should
  1622. (equal "* H1\n* "
  1623. (org-test-with-temp-text "* H1<point>"
  1624. (let ((org-blank-before-new-entry '((heading . nil))))
  1625. (org-insert-heading))
  1626. (buffer-string))))
  1627. (should
  1628. (equal "* H1\n* H2\n* "
  1629. (org-test-with-temp-text "* H1\n* H2<point>"
  1630. (let ((org-blank-before-new-entry '((heading . auto))))
  1631. (org-insert-heading))
  1632. (buffer-string))))
  1633. (should
  1634. (equal "* H1\n\n* H2\n\n* "
  1635. (org-test-with-temp-text "* H1\n\n* H2<point>"
  1636. (let ((org-blank-before-new-entry '((heading . auto))))
  1637. (org-insert-heading))
  1638. (buffer-string))))
  1639. ;; Corner case: correctly insert a headline after an empty one.
  1640. (should
  1641. (equal "* \n* "
  1642. (org-test-with-temp-text "* <point>"
  1643. (org-insert-heading)
  1644. (buffer-string))))
  1645. (should
  1646. (org-test-with-temp-text "* <point>\n"
  1647. (org-insert-heading)
  1648. (looking-at-p "\n\\'")))
  1649. ;; Do not insert spurious headlines when inserting a new headline.
  1650. (should
  1651. (equal "* H1\n* H2\n* \n"
  1652. (org-test-with-temp-text "* H1\n* H2<point>\n"
  1653. (org-insert-heading)
  1654. (buffer-string))))
  1655. ;; Preserve visibility at beginning of line. In particular, when
  1656. ;; removing spurious blank lines, do not visually merge heading with
  1657. ;; the line visible above.
  1658. (should-not
  1659. (org-test-with-temp-text "* H1<point>\nContents\n\n* H2\n"
  1660. (org-overview)
  1661. (let ((org-blank-before-new-entry '((heading . nil))))
  1662. (org-insert-heading '(4)))
  1663. (invisible-p (line-end-position 0))))
  1664. ;; Properly handle empty lines when forcing a headline below current
  1665. ;; one.
  1666. (should
  1667. (equal "* H1\n\n* H\n\n* "
  1668. (org-test-with-temp-text "* H1\n\n* H<point>"
  1669. (let ((org-blank-before-new-entry '((heading . t))))
  1670. (org-insert-heading '(4))
  1671. (buffer-string))))))
  1672. (ert-deftest test-org/insert-todo-heading-respect-content ()
  1673. "Test `org-insert-todo-heading-respect-content' specifications."
  1674. ;; Create a TODO heading.
  1675. (should
  1676. (org-test-with-temp-text "* H1\n Body"
  1677. (org-insert-todo-heading-respect-content)
  1678. (nth 2 (org-heading-components))))
  1679. ;; Add headline at the end of the first subtree
  1680. (should
  1681. (equal
  1682. "* TODO "
  1683. (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
  1684. (org-insert-todo-heading-respect-content)
  1685. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1686. ;; In a list, do not create a new item.
  1687. (should
  1688. (equal
  1689. "* TODO "
  1690. (org-test-with-temp-text "* H\n- an item\n- another one"
  1691. (search-forward "an ")
  1692. (org-insert-todo-heading-respect-content)
  1693. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1694. ;; Use the same TODO keyword as current heading.
  1695. (should
  1696. (equal
  1697. "* TODO \n"
  1698. (org-test-with-temp-text "* TODO\n** WAITING\n"
  1699. (org-insert-todo-heading-respect-content)
  1700. (buffer-substring-no-properties (line-beginning-position) (point-max))))))
  1701. (ert-deftest test-org/clone-with-time-shift ()
  1702. "Test `org-clone-subtree-with-time-shift'."
  1703. ;; Raise an error before first heading.
  1704. (should-error
  1705. (org-test-with-temp-text ""
  1706. (org-clone-subtree-with-time-shift 1)))
  1707. ;; Raise an error on invalid number of clones.
  1708. (should-error
  1709. (org-test-with-temp-text "* Clone me"
  1710. (org-clone-subtree-with-time-shift -1)))
  1711. ;; Clone non-repeating once.
  1712. (should
  1713. (equal "\
  1714. * H1\n<2015-06-21>
  1715. * H1\n<2015-06-23>
  1716. "
  1717. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1718. (org-clone-subtree-with-time-shift 1 "+2d")
  1719. (replace-regexp-in-string
  1720. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1721. nil nil 1))))
  1722. ;; Clone repeating once.
  1723. (should
  1724. (equal "\
  1725. * H1\n<2015-06-21>
  1726. * H1\n<2015-06-23>
  1727. * H1\n<2015-06-25 +1w>
  1728. "
  1729. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1730. (org-clone-subtree-with-time-shift 1 "+2d")
  1731. (replace-regexp-in-string
  1732. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1733. nil nil 1))))
  1734. ;; Clone repeating once in backward.
  1735. (should
  1736. (equal "\
  1737. * H1\n<2015-06-21>
  1738. * H1\n<2015-06-19>
  1739. * H1\n<2015-06-17 +1w>
  1740. "
  1741. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1742. (org-clone-subtree-with-time-shift 1 "-2d")
  1743. (replace-regexp-in-string
  1744. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1745. nil nil 1))))
  1746. ;; Clone non-repeating zero times.
  1747. (should
  1748. (equal "\
  1749. * H1\n<2015-06-21>
  1750. "
  1751. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1752. (org-clone-subtree-with-time-shift 0 "+2d")
  1753. (replace-regexp-in-string
  1754. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1755. nil nil 1))))
  1756. ;; Clone repeating "zero" times.
  1757. (should
  1758. (equal "\
  1759. * H1\n<2015-06-21>
  1760. * H1\n<2015-06-23 +1w>
  1761. "
  1762. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1763. (org-clone-subtree-with-time-shift 0 "+2d")
  1764. (replace-regexp-in-string
  1765. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1766. nil nil 1))))
  1767. ;; Clone with blank SHIFT argument.
  1768. (should
  1769. (string-prefix-p
  1770. "* H <2012-03-29"
  1771. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1772. (org-clone-subtree-with-time-shift 1 "")
  1773. (buffer-substring-no-properties (line-beginning-position 2)
  1774. (line-end-position 2)))))
  1775. ;; Find time stamps before point. If SHIFT is not specified, ask
  1776. ;; for a time shift.
  1777. (should
  1778. (string-prefix-p
  1779. "* H <2012-03-30"
  1780. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1781. (org-clone-subtree-with-time-shift 1 "+1d")
  1782. (buffer-substring-no-properties (line-beginning-position 2)
  1783. (line-end-position 2)))))
  1784. (should
  1785. (string-prefix-p
  1786. "* H <2014-03-05"
  1787. (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
  1788. (cl-letf (((symbol-function 'read-from-minibuffer)
  1789. (lambda (&rest args) "+1d")))
  1790. (org-clone-subtree-with-time-shift 1))
  1791. (buffer-substring-no-properties (line-beginning-position 2)
  1792. (line-end-position 2)))))
  1793. ;; Hour shift.
  1794. (should
  1795. (equal "\
  1796. * H1\n<2015-06-21 20:00>
  1797. * H1\n<2015-06-21 23:00>
  1798. * H1\n<2015-06-22 02:00>
  1799. "
  1800. (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>"
  1801. (org-clone-subtree-with-time-shift 2 "+3h")
  1802. (replace-regexp-in-string
  1803. "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" ""
  1804. (buffer-substring-no-properties (point-min) (point-max))
  1805. nil nil 1))))
  1806. (should
  1807. (equal "\
  1808. * H1\n<2015-06-21 20:00>
  1809. * H1\n<2015-06-21 18:00>
  1810. "
  1811. (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>"
  1812. (org-clone-subtree-with-time-shift 1 "-2h")
  1813. (replace-regexp-in-string
  1814. "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" ""
  1815. (buffer-substring-no-properties (point-min) (point-max))
  1816. nil nil 1)))))
  1817. ;;; Fixed-Width Areas
  1818. (ert-deftest test-org/toggle-fixed-width ()
  1819. "Test `org-toggle-fixed-width' specifications."
  1820. ;; No region: Toggle on fixed-width marker in paragraphs.
  1821. (should
  1822. (equal ": A"
  1823. (org-test-with-temp-text "A"
  1824. (org-toggle-fixed-width)
  1825. (buffer-string))))
  1826. ;; No region: Toggle off fixed-width markers in fixed-width areas.
  1827. (should
  1828. (equal "A"
  1829. (org-test-with-temp-text ": A"
  1830. (org-toggle-fixed-width)
  1831. (buffer-string))))
  1832. ;; No region: Toggle on marker in blank lines after elements or just
  1833. ;; after a headline.
  1834. (should
  1835. (equal "* H\n: "
  1836. (org-test-with-temp-text "* H\n"
  1837. (forward-line)
  1838. (org-toggle-fixed-width)
  1839. (buffer-string))))
  1840. (should
  1841. (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
  1842. (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
  1843. (goto-char (point-max))
  1844. (org-toggle-fixed-width)
  1845. (buffer-string))))
  1846. ;; No region: Toggle on marker in front of one line elements (e.g.,
  1847. ;; headlines, clocks)
  1848. (should
  1849. (equal ": * Headline"
  1850. (org-test-with-temp-text "* Headline"
  1851. (org-toggle-fixed-width)
  1852. (buffer-string))))
  1853. (should
  1854. (equal ": #+KEYWORD: value"
  1855. (org-test-with-temp-text "#+KEYWORD: value"
  1856. (org-toggle-fixed-width)
  1857. (buffer-string))))
  1858. ;; No region: error in other situations.
  1859. (should-error
  1860. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
  1861. (forward-line)
  1862. (org-toggle-fixed-width)
  1863. (buffer-string)))
  1864. ;; No region: Indentation is preserved.
  1865. (should
  1866. (equal "- A\n : B"
  1867. (org-test-with-temp-text "- A\n B"
  1868. (forward-line)
  1869. (org-toggle-fixed-width)
  1870. (buffer-string))))
  1871. ;; Region: If it contains only fixed-width elements and blank lines,
  1872. ;; toggle off fixed-width markup.
  1873. (should
  1874. (equal "A\n\nB"
  1875. (org-test-with-temp-text ": A\n\n: B"
  1876. (transient-mark-mode 1)
  1877. (push-mark (point) t t)
  1878. (goto-char (point-max))
  1879. (org-toggle-fixed-width)
  1880. (buffer-string))))
  1881. ;; Region: If it contains anything else, toggle on fixed-width but
  1882. ;; not on fixed-width areas.
  1883. (should
  1884. (equal ": A\n: \n: B\n: \n: C"
  1885. (org-test-with-temp-text "A\n\n: B\n\nC"
  1886. (transient-mark-mode 1)
  1887. (push-mark (point) t t)
  1888. (goto-char (point-max))
  1889. (org-toggle-fixed-width)
  1890. (buffer-string))))
  1891. ;; Region: Ignore blank lines at its end, unless it contains only
  1892. ;; such lines.
  1893. (should
  1894. (equal ": A\n\n"
  1895. (org-test-with-temp-text "A\n\n"
  1896. (transient-mark-mode 1)
  1897. (push-mark (point) t t)
  1898. (goto-char (point-max))
  1899. (org-toggle-fixed-width)
  1900. (buffer-string))))
  1901. (should
  1902. (equal ": \n: \n"
  1903. (org-test-with-temp-text "\n\n"
  1904. (transient-mark-mode 1)
  1905. (push-mark (point) t t)
  1906. (goto-char (point-max))
  1907. (org-toggle-fixed-width)
  1908. (buffer-string)))))
  1909. (ert-deftest test-org/kill-line ()
  1910. "Test `org-kill-line' specifications."
  1911. ;; At the beginning of a line, kill whole line.
  1912. (should
  1913. (equal ""
  1914. (org-test-with-temp-text "abc"
  1915. (org-kill-line)
  1916. (buffer-string))))
  1917. ;; In the middle of a line, kill line until its end.
  1918. (should
  1919. (equal "a"
  1920. (org-test-with-temp-text "a<point>bc"
  1921. (org-kill-line)
  1922. (buffer-string))))
  1923. ;; Do not kill newline character.
  1924. (should
  1925. (equal "\n123"
  1926. (org-test-with-temp-text "abc\n123"
  1927. (org-kill-line)
  1928. (buffer-string))))
  1929. (should
  1930. (equal "a\n123"
  1931. (org-test-with-temp-text "a<point>bc\n123"
  1932. (org-kill-line)
  1933. (buffer-string))))
  1934. ;; When `org-special-ctrl-k' is non-nil and point is at a headline,
  1935. ;; kill until tags.
  1936. (should
  1937. (equal "* A :tag:"
  1938. (org-test-with-temp-text "* A<point>B :tag:"
  1939. (let ((org-special-ctrl-k t)
  1940. (org-tags-column 0))
  1941. (org-kill-line))
  1942. (buffer-string))))
  1943. ;; If point is on tags, only kill part left until the end of line.
  1944. (should
  1945. (equal "* A :tag:"
  1946. (org-test-with-temp-text "* A :tag:<point>tag2:"
  1947. (let ((org-special-ctrl-k t)
  1948. (org-tags-column 0))
  1949. (org-kill-line))
  1950. (buffer-string))))
  1951. ;; However, if point is at the beginning of the line, kill whole
  1952. ;; headline.
  1953. (should
  1954. (equal ""
  1955. (org-test-with-temp-text "* AB :tag:"
  1956. (let ((org-special-ctrl-k t)
  1957. (org-tags-column 0))
  1958. (org-kill-line))
  1959. (buffer-string))))
  1960. ;; When `org-ctrl-k-protect-subtree' is non-nil, and point is in
  1961. ;; invisible text, ask before removing it. When set to `error',
  1962. ;; throw an error.
  1963. (should-error
  1964. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  1965. (org-overview)
  1966. (let ((org-special-ctrl-k nil)
  1967. (org-ctrl-k-protect-subtree t))
  1968. (cl-letf (((symbol-function 'y-or-n-p) 'ignore))
  1969. (org-kill-line)))))
  1970. (should-error
  1971. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  1972. (org-overview)
  1973. (let ((org-special-ctrl-k nil)
  1974. (org-ctrl-k-protect-subtree 'error))
  1975. (org-kill-line)))))
  1976. ;;; Headline
  1977. (ert-deftest test-org/get-heading ()
  1978. "Test `org-get-heading' specifications."
  1979. ;; Return current heading, even if point is not on it.
  1980. (should
  1981. (equal "H"
  1982. (org-test-with-temp-text "* H"
  1983. (org-get-heading))))
  1984. (should
  1985. (equal "H"
  1986. (org-test-with-temp-text "* H\nText<point>"
  1987. (org-get-heading))))
  1988. ;; Without any optional argument, return TODO keyword, priority
  1989. ;; cookie, COMMENT keyword and tags.
  1990. (should
  1991. (equal "TODO H"
  1992. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  1993. (org-get-heading))))
  1994. (should
  1995. (equal "[#A] H"
  1996. (org-test-with-temp-text "* [#A] H"
  1997. (org-get-heading))))
  1998. (should
  1999. (equal "COMMENT H"
  2000. (org-test-with-temp-text "* COMMENT H"
  2001. (org-get-heading))))
  2002. (should
  2003. (equal "H :tag:"
  2004. (org-test-with-temp-text "* H :tag:"
  2005. (org-get-heading))))
  2006. ;; With NO-TAGS argument, ignore tags.
  2007. (should
  2008. (equal "TODO H"
  2009. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2010. (org-get-heading t))))
  2011. (should
  2012. (equal "H"
  2013. (org-test-with-temp-text "* H :tag:"
  2014. (org-get-heading t))))
  2015. ;; With NO-TODO, ignore TODO keyword.
  2016. (should
  2017. (equal "H"
  2018. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2019. (org-get-heading nil t))))
  2020. (should
  2021. (equal "H :tag:"
  2022. (org-test-with-temp-text "* H :tag:"
  2023. (org-get-heading nil t))))
  2024. ;; TODO keywords are case-sensitive.
  2025. (should
  2026. (equal "Todo H"
  2027. (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
  2028. (org-get-heading nil t))))
  2029. ;; With NO-PRIORITY, ignore priority.
  2030. (should
  2031. (equal "H"
  2032. (org-test-with-temp-text "* [#A] H"
  2033. (org-get-heading nil nil t))))
  2034. (should
  2035. (equal "H"
  2036. (org-test-with-temp-text "* H"
  2037. (org-get-heading nil nil t))))
  2038. (should
  2039. (equal "TODO H"
  2040. (org-test-with-temp-text "* TODO [#A] H"
  2041. (org-get-heading nil nil t))))
  2042. ;; With NO-COMMENT, ignore COMMENT keyword.
  2043. (should
  2044. (equal "H"
  2045. (org-test-with-temp-text "* COMMENT H"
  2046. (org-get-heading nil nil nil t))))
  2047. (should
  2048. (equal "H"
  2049. (org-test-with-temp-text "* H"
  2050. (org-get-heading nil nil nil t))))
  2051. (should
  2052. (equal "TODO [#A] H"
  2053. (org-test-with-temp-text "* TODO [#A] COMMENT H"
  2054. (org-get-heading nil nil nil t))))
  2055. ;; On an empty headline, return value is consistent.
  2056. (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
  2057. (should (equal "" (org-test-with-temp-text "* " (org-get-heading t))))
  2058. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t))))
  2059. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t))))
  2060. (should
  2061. (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t)))))
  2062. (ert-deftest test-org/in-commented-heading-p ()
  2063. "Test `org-in-commented-heading-p' specifications."
  2064. ;; Commented headline.
  2065. (should
  2066. (org-test-with-temp-text "* COMMENT Headline\nBody"
  2067. (goto-char (point-max))
  2068. (org-in-commented-heading-p)))
  2069. ;; Commented ancestor.
  2070. (should
  2071. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  2072. (goto-char (point-max))
  2073. (org-in-commented-heading-p)))
  2074. ;; Comment keyword is case-sensitive.
  2075. (should-not
  2076. (org-test-with-temp-text "* Comment Headline\nBody"
  2077. (goto-char (point-max))
  2078. (org-in-commented-heading-p)))
  2079. ;; Keyword is standalone.
  2080. (should-not
  2081. (org-test-with-temp-text "* COMMENTHeadline\nBody"
  2082. (goto-char (point-max))
  2083. (org-in-commented-heading-p)))
  2084. ;; Optional argument.
  2085. (should-not
  2086. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  2087. (goto-char (point-max))
  2088. (org-in-commented-heading-p t))))
  2089. (ert-deftest test-org/in-archived-heading-p ()
  2090. "Test `org-in-archived-heading-p' specifications."
  2091. ;; Archived headline.
  2092. (should
  2093. (org-test-with-temp-text "* Headline :ARCHIVE:\nBody"
  2094. (goto-char (point-max))
  2095. (org-in-archived-heading-p)))
  2096. ;; Archived ancestor.
  2097. (should
  2098. (org-test-with-temp-text "* Headline :ARCHIVE:\n** Level 2\nBody"
  2099. (goto-char (point-max))
  2100. (org-in-archived-heading-p)))
  2101. ;; Optional argument.
  2102. (should-not
  2103. (org-test-with-temp-text "* Headline :ARCHIVE:\n** Level 2\nBody"
  2104. (goto-char (point-max))
  2105. (org-in-archived-heading-p t)))
  2106. ;; Archive tag containing ARCHIVE as substring
  2107. (should-not
  2108. (org-test-with-temp-text "* Headline :NOARCHIVE:\n** Level 2\nBody"
  2109. (goto-char (point-max))
  2110. (org-in-archived-heading-p))))
  2111. (ert-deftest test-org/entry-blocked-p ()
  2112. ;; Check other dependencies.
  2113. (should
  2114. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  2115. (let ((org-enforce-todo-dependencies t)
  2116. (org-blocker-hook
  2117. '(org-block-todo-from-children-or-siblings-or-parent)))
  2118. (org-entry-blocked-p))))
  2119. (should-not
  2120. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  2121. (let ((org-enforce-todo-dependencies t)
  2122. (org-blocker-hook
  2123. '(org-block-todo-from-children-or-siblings-or-parent)))
  2124. (org-entry-blocked-p))))
  2125. ;; Entry without a TODO keyword or with a DONE keyword cannot be
  2126. ;; blocked.
  2127. (should-not
  2128. (org-test-with-temp-text "* Blocked\n** TODO one"
  2129. (let ((org-enforce-todo-dependencies t)
  2130. (org-blocker-hook
  2131. '(org-block-todo-from-children-or-siblings-or-parent)))
  2132. (org-entry-blocked-p))))
  2133. (should-not
  2134. (org-test-with-temp-text "* DONE Blocked\n** TODO one"
  2135. (let ((org-enforce-todo-dependencies t)
  2136. (org-blocker-hook
  2137. '(org-block-todo-from-children-or-siblings-or-parent)))
  2138. (org-entry-blocked-p))))
  2139. ;; Follow :ORDERED: specifications.
  2140. (should
  2141. (org-test-with-temp-text
  2142. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
  2143. (let ((org-enforce-todo-dependencies t)
  2144. (org-blocker-hook
  2145. '(org-block-todo-from-children-or-siblings-or-parent)))
  2146. (org-entry-blocked-p))))
  2147. (should-not
  2148. (org-test-with-temp-text
  2149. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
  2150. (let ((org-enforce-todo-dependencies t)
  2151. (org-blocker-hook
  2152. '(org-block-todo-from-children-or-siblings-or-parent)))
  2153. (org-entry-blocked-p)))))
  2154. (ert-deftest test-org/get-outline-path ()
  2155. "Test `org-get-outline-path' specifications."
  2156. ;; Top-level headlines have no outline path.
  2157. (should-not
  2158. (org-test-with-temp-text "* H"
  2159. (org-get-outline-path)))
  2160. ;; Otherwise, outline path is the path leading to the headline.
  2161. (should
  2162. (equal '("H")
  2163. (org-test-with-temp-text "* H\n** S<point>"
  2164. (org-get-outline-path))))
  2165. ;; Find path even when point is not on a headline.
  2166. (should
  2167. (equal '("H")
  2168. (org-test-with-temp-text "* H\n** S\nText<point>"
  2169. (org-get-outline-path))))
  2170. ;; TODO keywords, tags and statistics cookies are ignored.
  2171. (should
  2172. (equal '("H")
  2173. (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
  2174. (org-get-outline-path))))
  2175. ;; Links are replaced with their description or their path.
  2176. (should
  2177. (equal '("Org")
  2178. (org-test-with-temp-text
  2179. "* [[https://orgmode.org][Org]]\n** S<point>"
  2180. (org-get-outline-path))))
  2181. (should
  2182. (equal '("https://orgmode.org")
  2183. (org-test-with-temp-text
  2184. "* [[https://orgmode.org]]\n** S<point>"
  2185. (org-get-outline-path))))
  2186. ;; When WITH-SELF is non-nil, include current heading.
  2187. (should
  2188. (equal '("H")
  2189. (org-test-with-temp-text "* H"
  2190. (org-get-outline-path t))))
  2191. (should
  2192. (equal '("H" "S")
  2193. (org-test-with-temp-text "* H\n** S\nText<point>"
  2194. (org-get-outline-path t))))
  2195. ;; Using cache is transparent to the user.
  2196. (should
  2197. (equal '("H")
  2198. (org-test-with-temp-text "* H\n** S<point>"
  2199. (setq org-outline-path-cache nil)
  2200. (org-get-outline-path nil t))))
  2201. ;; Do not corrupt cache when finding outline path in distant part of
  2202. ;; the buffer.
  2203. (should
  2204. (equal '("H2")
  2205. (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
  2206. (setq org-outline-path-cache nil)
  2207. (org-get-outline-path nil t)
  2208. (search-forward "S2")
  2209. (org-get-outline-path nil t))))
  2210. ;; Do not choke on empty headlines.
  2211. (should
  2212. (org-test-with-temp-text "* H\n** <point>"
  2213. (org-get-outline-path)))
  2214. (should
  2215. (org-test-with-temp-text "* \n** H<point>"
  2216. (org-get-outline-path))))
  2217. (ert-deftest test-org/format-outline-path ()
  2218. "Test `org-format-outline-path' specifications."
  2219. (should
  2220. (string= (org-format-outline-path (list "one" "two" "three"))
  2221. "one/two/three"))
  2222. ;; Empty path.
  2223. (should
  2224. (string= (org-format-outline-path '())
  2225. ""))
  2226. (should
  2227. (string= (org-format-outline-path '(nil))
  2228. ""))
  2229. ;; Empty path and prefix.
  2230. (should
  2231. (string= (org-format-outline-path '() nil ">>")
  2232. ">>"))
  2233. ;; Trailing whitespace in headings.
  2234. (should
  2235. (string= (org-format-outline-path (list "one\t" "tw o " "three "))
  2236. "one/tw o/three"))
  2237. ;; Non-default prefix and separators.
  2238. (should
  2239. (string= (org-format-outline-path (list "one" "two" "three") nil ">>" "|")
  2240. ">>|one|two|three"))
  2241. ;; Truncate.
  2242. (should
  2243. (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
  2244. "one/two/.."))
  2245. ;; Give a very narrow width.
  2246. (should
  2247. (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
  2248. "on"))
  2249. ;; Give a prefix that extends beyond the width.
  2250. (should
  2251. (string= (org-format-outline-path (list "one" "two" "three" "four") 10
  2252. ">>>>>>>>>>")
  2253. ">>>>>>>>..")))
  2254. (ert-deftest test-org/map-entries ()
  2255. "Test `org-map-entries' specifications."
  2256. ;; Full match.
  2257. (should
  2258. (equal '(1 11)
  2259. (org-test-with-temp-text "* Level 1\n** Level 2"
  2260. (org-map-entries #'point))))
  2261. ;; Level match.
  2262. (should
  2263. (equal '(1)
  2264. (org-test-with-temp-text "* Level 1\n** Level 2"
  2265. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL=1")))))
  2266. (should
  2267. (equal '(11)
  2268. (org-test-with-temp-text "* Level 1\n** Level 2"
  2269. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL>1")))))
  2270. ;; Tag match.
  2271. (should
  2272. (equal '(11)
  2273. (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
  2274. (org-map-entries #'point "yes"))))
  2275. (should
  2276. (equal '(14)
  2277. (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
  2278. (org-map-entries #'point "+yes-a"))))
  2279. (should
  2280. (equal '(11 23)
  2281. (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
  2282. (org-map-entries #'point "{yes?}"))))
  2283. ;; Priority match.
  2284. (should
  2285. (equal '(1)
  2286. (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
  2287. (org-map-entries #'point "PRIORITY=\"A\""))))
  2288. ;; Date match.
  2289. (should
  2290. (equal '(36)
  2291. (org-test-with-temp-text "
  2292. * H1
  2293. SCHEDULED: <2012-03-29 thu.>
  2294. * H2
  2295. SCHEDULED: <2014-03-04 tue.>"
  2296. (org-map-entries #'point "SCHEDULED=\"<2014-03-04 tue.>\""))))
  2297. (should
  2298. (equal '(2)
  2299. (org-test-with-temp-text "
  2300. * H1
  2301. SCHEDULED: <2012-03-29 thu.>
  2302. * H2
  2303. SCHEDULED: <2014-03-04 tue.>"
  2304. (org-map-entries #'point "SCHEDULED<\"<2013-01-01>\""))))
  2305. ;; Regular property match.
  2306. (should
  2307. (equal '(2)
  2308. (org-test-with-temp-text "
  2309. * H1
  2310. :PROPERTIES:
  2311. :TEST: 1
  2312. :END:
  2313. * H2
  2314. :PROPERTIES:
  2315. :TEST: 2
  2316. :END:"
  2317. (org-map-entries #'point "TEST=1"))))
  2318. ;; Multiple criteria.
  2319. (should
  2320. (equal '(23)
  2321. (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
  2322. (let (org-odd-levels-only
  2323. (org-use-tag-inheritance nil))
  2324. (org-map-entries #'point "yes+LEVEL=1")))))
  2325. ;; "or" criteria.
  2326. (should
  2327. (equal '(12 24)
  2328. (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
  2329. (let (org-odd-levels-only)
  2330. (org-map-entries #'point "LEVEL=2|no")))))
  2331. (should
  2332. (equal '(1 12)
  2333. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
  2334. (let (org-odd-levels-only)
  2335. (org-map-entries #'point "yes|no")))))
  2336. ;; "and" criteria.
  2337. (should
  2338. (equal '(22)
  2339. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
  2340. (let (org-odd-levels-only)
  2341. (org-map-entries #'point "yes&no"))))))
  2342. (ert-deftest test-org/edit-headline ()
  2343. "Test `org-edit-headline' specifications."
  2344. (should
  2345. (equal "* B"
  2346. (org-test-with-temp-text "* A"
  2347. (org-edit-headline "B")
  2348. (buffer-string))))
  2349. ;; Handle empty headings.
  2350. (should
  2351. (equal "* "
  2352. (org-test-with-temp-text "* A"
  2353. (org-edit-headline "")
  2354. (buffer-string))))
  2355. (should
  2356. (equal "* A"
  2357. (org-test-with-temp-text "* "
  2358. (org-edit-headline "A")
  2359. (buffer-string))))
  2360. ;; Handle TODO keywords and priority cookies.
  2361. (should
  2362. (equal "* TODO B"
  2363. (org-test-with-temp-text "* TODO A"
  2364. (org-edit-headline "B")
  2365. (buffer-string))))
  2366. (should
  2367. (equal "* [#A] B"
  2368. (org-test-with-temp-text "* [#A] A"
  2369. (org-edit-headline "B")
  2370. (buffer-string))))
  2371. (should
  2372. (equal "* TODO [#A] B"
  2373. (org-test-with-temp-text "* TODO [#A] A"
  2374. (org-edit-headline "B")
  2375. (buffer-string))))
  2376. ;; Handle tags.
  2377. (equal "* B :tag:"
  2378. (org-test-with-temp-text "* A :tag:"
  2379. (let ((org-tags-column 4)) (org-edit-headline "B"))
  2380. (buffer-string))))
  2381. ;;; Keywords
  2382. (ert-deftest test-org/set-regexps-and-options ()
  2383. "Test `org-set-regexps-and-options' specifications."
  2384. ;; TAGS keyword.
  2385. (should
  2386. (equal '(("A"))
  2387. (let ((org-tag-alist '(("A")))
  2388. (org-tag-persistent-alist nil))
  2389. (org-test-with-temp-text ""
  2390. (org-mode-restart)
  2391. org-current-tag-alist))))
  2392. (should
  2393. (equal '(("B"))
  2394. (let ((org-tag-alist '(("A")))
  2395. (org-tag-persistent-alist nil))
  2396. (org-test-with-temp-text "#+TAGS: B"
  2397. (org-mode-restart)
  2398. org-current-tag-alist))))
  2399. (should
  2400. (equal '(("C") ("B"))
  2401. (let ((org-tag-alist '(("A")))
  2402. (org-tag-persistent-alist '(("C"))))
  2403. (org-test-with-temp-text "#+TAGS: B"
  2404. (org-mode-restart)
  2405. org-current-tag-alist))))
  2406. (should
  2407. (equal '(("B"))
  2408. (let ((org-tag-alist '(("A")))
  2409. (org-tag-persistent-alist '(("C"))))
  2410. (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
  2411. (org-mode-restart)
  2412. org-current-tag-alist))))
  2413. (should
  2414. (equal '(("A" . ?a) ("B") ("C"))
  2415. (let ((org-tag-persistant-alist nil))
  2416. (org-test-with-temp-text "#+TAGS: A(a) B C"
  2417. (org-mode-restart)
  2418. org-current-tag-alist))))
  2419. (should
  2420. (equal '(("A") (:newline) ("B"))
  2421. (let ((org-tag-persistent-alist nil))
  2422. (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
  2423. (org-mode-restart)
  2424. org-current-tag-alist))))
  2425. (should
  2426. (equal '((:startgroup) ("A") ("B") (:endgroup) ("C"))
  2427. (let ((org-tag-persistent-alist nil))
  2428. (org-test-with-temp-text "#+TAGS: { A B } C"
  2429. (org-mode-restart)
  2430. org-current-tag-alist))))
  2431. (should
  2432. (equal '((:startgroup) ("A") (:grouptags) ("B") ("C") (:endgroup))
  2433. (let ((org-tag-persistent-alist nil))
  2434. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2435. (org-mode-restart)
  2436. org-current-tag-alist))))
  2437. (should
  2438. (equal '(("A" "B" "C"))
  2439. (let ((org-tag-persistent-alist nil))
  2440. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2441. (org-mode-restart)
  2442. org-tag-groups-alist))))
  2443. (should
  2444. (equal '((:startgrouptag) ("A") (:grouptags) ("B") ("C") (:endgrouptag))
  2445. (let ((org-tag-persistent-alist nil))
  2446. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2447. (org-mode-restart)
  2448. org-current-tag-alist))))
  2449. (should
  2450. (equal '(("A" "B" "C"))
  2451. (let ((org-tag-persistent-alist nil))
  2452. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2453. (org-mode-restart)
  2454. org-tag-groups-alist))))
  2455. (should-not
  2456. (let ((org-tag-alist '(("A"))))
  2457. (org-test-with-temp-text "#+TAGS:"
  2458. (org-mode-restart)
  2459. org-current-tag-alist)))
  2460. ;; FILETAGS keyword.
  2461. (should
  2462. (equal '("A" "B" "C")
  2463. (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
  2464. (org-mode-restart)
  2465. org-file-tags)))
  2466. ;; PROPERTY keyword. Property names are case-insensitive.
  2467. (should
  2468. (equal "foo=1"
  2469. (org-test-with-temp-text "#+PROPERTY: var foo=1"
  2470. (org-mode-restart)
  2471. (cdr (assoc "var" org-keyword-properties)))))
  2472. (should
  2473. (equal
  2474. "foo=1 bar=2"
  2475. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
  2476. (org-mode-restart)
  2477. (cdr (assoc "var" org-keyword-properties)))))
  2478. (should
  2479. (equal
  2480. "foo=1 bar=2"
  2481. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
  2482. (org-mode-restart)
  2483. (cdr (assoc "var" org-keyword-properties)))))
  2484. ;; ARCHIVE keyword.
  2485. (should
  2486. (equal "%s_done::"
  2487. (org-test-with-temp-text "#+ARCHIVE: %s_done::"
  2488. (org-mode-restart)
  2489. org-archive-location)))
  2490. ;; CATEGORY keyword.
  2491. (should
  2492. (eq 'test
  2493. (org-test-with-temp-text "#+CATEGORY: test"
  2494. (org-mode-restart)
  2495. org-category)))
  2496. (should
  2497. (equal "test"
  2498. (org-test-with-temp-text "#+CATEGORY: test"
  2499. (org-mode-restart)
  2500. (cdr (assoc "CATEGORY" org-keyword-properties)))))
  2501. ;; COLUMNS keyword.
  2502. (should
  2503. (equal "%25ITEM %TAGS %PRIORITY %TODO"
  2504. (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
  2505. (org-mode-restart)
  2506. org-columns-default-format)))
  2507. ;; CONSTANTS keyword. Constants names are case sensitive.
  2508. (should
  2509. (equal '("299792458." "3.14")
  2510. (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
  2511. (org-mode-restart)
  2512. (mapcar
  2513. (lambda (n) (cdr (assoc n org-table-formula-constants-local)))
  2514. '("c" "pi")))))
  2515. (should
  2516. (equal "3.14"
  2517. (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
  2518. (org-mode-restart)
  2519. (cdr (assoc "pi" org-table-formula-constants-local)))))
  2520. (should
  2521. (equal "22/7"
  2522. (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
  2523. (org-mode-restart)
  2524. (cdr (assoc "PI" org-table-formula-constants-local)))))
  2525. ;; LINK keyword.
  2526. (should
  2527. (equal
  2528. '("url1" "url2")
  2529. (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
  2530. (org-mode-restart)
  2531. (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local)))
  2532. '("a" "b")))))
  2533. ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
  2534. (should
  2535. (equal
  2536. '(?X ?Z ?Y)
  2537. (org-test-with-temp-text "#+PRIORITIES: X Z Y"
  2538. (org-mode-restart)
  2539. (list org-priority-highest org-priority-lowest org-priority-default))))
  2540. (should
  2541. (equal
  2542. '(?A ?C ?B)
  2543. (org-test-with-temp-text "#+PRIORITIES: X Z"
  2544. (org-mode-restart)
  2545. (list org-priority-highest org-priority-lowest org-priority-default))))
  2546. ;; STARTUP keyword.
  2547. (should
  2548. (equal '(t t)
  2549. (org-test-with-temp-text "#+STARTUP: fold odd"
  2550. (org-mode-restart)
  2551. (list org-startup-folded org-odd-levels-only))))
  2552. ;; TODO keywords.
  2553. (should
  2554. (equal '(("A" "B") ("C"))
  2555. (org-test-with-temp-text "#+TODO: A B | C"
  2556. (org-mode-restart)
  2557. (list org-not-done-keywords org-done-keywords))))
  2558. (should
  2559. (equal '(("A" "C") ("B" "D"))
  2560. (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
  2561. (org-mode-restart)
  2562. (list org-not-done-keywords org-done-keywords))))
  2563. (should
  2564. (equal '(("A" "B") ("C"))
  2565. (org-test-with-temp-text "#+TYP_TODO: A B | C"
  2566. (org-mode-restart)
  2567. (list org-not-done-keywords org-done-keywords))))
  2568. (should
  2569. (equal '((:startgroup) ("A" . ?a) (:endgroup))
  2570. (org-test-with-temp-text "#+TODO: A(a)"
  2571. (org-mode-restart)
  2572. org-todo-key-alist)))
  2573. (should
  2574. (equal '(("D" note nil) ("C" time nil) ("B" note time))
  2575. (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
  2576. (org-mode-restart)
  2577. org-todo-log-states)))
  2578. ;; Enter SETUPFILE keyword.
  2579. (should
  2580. (equal "1"
  2581. (org-test-with-temp-text
  2582. (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
  2583. (org-mode-restart)
  2584. (cdr (assoc "a" org-keyword-properties))))))
  2585. (ert-deftest test-org/collect-keywords ()
  2586. "Test `org-collect-keywords'."
  2587. (should-not
  2588. (org-test-with-temp-text "#+begin_example\n#+foo: bar\n#+end_example"
  2589. (org-collect-keywords '("FOO")))))
  2590. ;;; Links
  2591. ;;;; Coderefs
  2592. (ert-deftest test-org/coderef ()
  2593. "Test coderef links specifications."
  2594. (should
  2595. (org-test-with-temp-text "
  2596. #+BEGIN_SRC emacs-lisp
  2597. \(+ 1 1) (ref:sc)
  2598. #+END_SRC
  2599. \[[(sc)<point>]]"
  2600. (org-open-at-point)
  2601. (looking-at "(ref:sc)")))
  2602. ;; Find coderef even with alternate label format.
  2603. (should
  2604. (org-test-with-temp-text "
  2605. #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
  2606. \(+ 1 1) {ref:sc}
  2607. #+END_SRC
  2608. \[[(sc)<point>]]"
  2609. (org-open-at-point)
  2610. (looking-at "{ref:sc}"))))
  2611. ;;;; Custom ID
  2612. (ert-deftest test-org/custom-id ()
  2613. "Test custom ID links specifications."
  2614. (should
  2615. (org-test-with-temp-text
  2616. "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2617. (org-open-at-point)
  2618. (looking-at-p "\\* H1")))
  2619. ;; Handle escape characters.
  2620. (should
  2621. (org-test-with-temp-text
  2622. "* H1\n:PROPERTIES:\n:CUSTOM_ID: [%]\n:END:\n* H2\n[[#\\[%\\]<point>]]"
  2623. (org-open-at-point)
  2624. (looking-at-p "\\* H1")))
  2625. ;; Throw an error on false positives.
  2626. (should-error
  2627. (org-test-with-temp-text
  2628. "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2629. (org-open-at-point)
  2630. (looking-at-p "\\* H1"))))
  2631. ;;;; Fuzzy Links
  2632. ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
  2633. ;; a named element (#+name: text) and to headlines (* Text).
  2634. (ert-deftest test-org/fuzzy-links ()
  2635. "Test fuzzy links specifications."
  2636. ;; Fuzzy link goes in priority to a matching target.
  2637. (should
  2638. (org-test-with-temp-text
  2639. "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
  2640. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2641. (looking-at "<<Test>>")))
  2642. ;; Then fuzzy link points to an element with a given name.
  2643. (should
  2644. (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
  2645. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2646. (looking-at "#\\+NAME: Test")))
  2647. ;; A target still lead to a matching headline otherwise.
  2648. (should
  2649. (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
  2650. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2651. (looking-at "\\* Head2")))
  2652. ;; With a leading star in link, enforce heading match.
  2653. (should
  2654. (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
  2655. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2656. (looking-at "\\* Test")))
  2657. ;; With a leading star in link, enforce exact heading match, even
  2658. ;; with `org-link-search-must-match-exact-headline' set to nil.
  2659. (should-error
  2660. (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
  2661. (let ((org-link-search-must-match-exact-headline nil))
  2662. (org-open-at-point))))
  2663. ;; Handle non-nil `org-link-search-must-match-exact-headline'.
  2664. (should
  2665. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
  2666. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2667. (looking-at "\\* Test")))
  2668. (should
  2669. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
  2670. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2671. (looking-at "\\* Test")))
  2672. ;; Heading match should not care about spaces, cookies, TODO
  2673. ;; keywords, priorities, and tags. However, TODO keywords are
  2674. ;; case-sensitive.
  2675. (should
  2676. (let ((first-line
  2677. "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
  2678. (org-test-with-temp-text
  2679. (concat first-line "\nFoo Bar\n<point>[[*Test 1 2]]")
  2680. (let ((org-link-search-must-match-exact-headline nil)
  2681. (org-todo-regexp "TODO"))
  2682. (org-open-at-point))
  2683. (looking-at (regexp-quote first-line)))))
  2684. (should-error
  2685. (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
  2686. (let ((org-link-search-must-match-exact-headline nil)
  2687. (org-todo-regexp "TODO"))
  2688. (org-open-at-point))))
  2689. ;; Heading match should still be exact.
  2690. (should-error
  2691. (org-test-with-temp-text "
  2692. ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
  2693. Foo Bar
  2694. <point>[[*Test 1]]"
  2695. (let ((org-link-search-must-match-exact-headline nil)
  2696. (org-todo-regexp "TODO"))
  2697. (org-open-at-point))))
  2698. (should
  2699. (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
  2700. (let ((org-link-search-must-match-exact-headline nil)
  2701. (org-todo-regexp "TODO"))
  2702. (org-open-at-point))
  2703. (looking-at-p (regexp-quote "** Test 1 2"))))
  2704. ;; Heading match ignores COMMENT keyword.
  2705. (should
  2706. (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
  2707. (org-open-at-point)
  2708. (looking-at "\\* COMMENT Test")))
  2709. (should
  2710. (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
  2711. (org-open-at-point)
  2712. (looking-at "\\* TODO COMMENT Test")))
  2713. ;; Correctly un-escape fuzzy links.
  2714. (should
  2715. (org-test-with-temp-text "* [foo]\n[[*\\[foo\\]][With escaped characters]]"
  2716. (org-open-at-point)
  2717. (bobp)))
  2718. ;; Match search strings containing newline characters, including
  2719. ;; blank lines.
  2720. (should
  2721. (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
  2722. (let ((file (buffer-file-name)))
  2723. (goto-char (point-max))
  2724. (insert (format "[[file:%s::line1 line2]]" file))
  2725. (beginning-of-line)
  2726. (let ((org-link-search-must-match-exact-headline nil))
  2727. (org-open-at-point 0))
  2728. (looking-at-p "line1"))))
  2729. (should
  2730. (org-test-with-temp-text-in-file "Paragraph\n\nline1\n\nline2\n\n"
  2731. (let ((file (buffer-file-name)))
  2732. (goto-char (point-max))
  2733. (insert (format "[[file:%s::line1 line2]]" file))
  2734. (beginning-of-line)
  2735. (let ((org-link-search-must-match-exact-headline nil))
  2736. (org-open-at-point 0))
  2737. (looking-at-p "line1")))))
  2738. ;;;; Open at point
  2739. (ert-deftest test-org/open-at-point/keyword ()
  2740. "Does `org-open-at-point' open link in a keyword line?"
  2741. (should
  2742. (org-test-with-temp-text
  2743. "<<top>>\n#+KEYWORD: <point>[[top]]"
  2744. (org-open-at-point) t))
  2745. (should
  2746. (org-test-with-temp-text
  2747. "* H\n<<top>>\n#+KEYWORD: <point>[[top]]"
  2748. (org-open-at-point) t)))
  2749. (ert-deftest test-org/open-at-point/property ()
  2750. "Does `org-open-at-point' open link in property drawer?"
  2751. (should
  2752. (org-test-with-temp-text
  2753. "* Headline
  2754. :PROPERTIES:
  2755. :URL: <point>[[*Headline]]
  2756. :END:"
  2757. (org-open-at-point) t)))
  2758. (ert-deftest test-org/open-at-point/comment ()
  2759. "Does `org-open-at-point' open link in a commented line?"
  2760. (should
  2761. (org-test-with-temp-text
  2762. "<<top>>\n# <point>[[top]]"
  2763. (org-open-at-point) t))
  2764. (should
  2765. (org-test-with-temp-text
  2766. "* H\n<<top>>\n# <point>[[top]]"
  2767. (org-open-at-point) t)))
  2768. (ert-deftest test-org/open-at-point/inline-image ()
  2769. "Test `org-open-at-point' on nested links."
  2770. (should
  2771. (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
  2772. (org-open-at-point)
  2773. (bobp))))
  2774. (ert-deftest test-org/open-at-point/radio-target ()
  2775. "Test `org-open-at-point' on radio targets."
  2776. (should
  2777. (org-test-with-temp-text "<<<target>>> <point>target"
  2778. (org-update-radio-target-regexp)
  2779. (org-open-at-point)
  2780. (eq (org-element-type (org-element-context)) 'radio-target))))
  2781. (ert-deftest test-org/open-at-point/tag ()
  2782. "Test `org-open-at-point' on tags."
  2783. (should
  2784. (org-test-with-temp-text "* H :<point>tag:"
  2785. (catch :result
  2786. (cl-letf (((symbol-function 'org-tags-view)
  2787. (lambda (&rest args) (throw :result t))))
  2788. (org-open-at-point)
  2789. nil))))
  2790. (should-not
  2791. (org-test-with-temp-text-in-file "* H<point> :tag:"
  2792. (catch :result
  2793. (cl-letf (((symbol-function 'org-tags-view)
  2794. (lambda (&rest args) (throw :result t))))
  2795. ;; When point isn't on a tag it's going to try other things,
  2796. ;; possibly trying to open attachments which will return an
  2797. ;; error if there isn't an attachment. Suppress that error.
  2798. (ignore-errors
  2799. (org-open-at-point))
  2800. nil)))))
  2801. ;;; Node Properties
  2802. (ert-deftest test-org/accumulated-properties-in-drawers ()
  2803. "Ensure properties accumulate in subtree drawers."
  2804. (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
  2805. (org-babel-next-src-block)
  2806. (should (equal '(2 1) (org-babel-execute-src-block)))))
  2807. (ert-deftest test-org/custom-properties ()
  2808. "Test custom properties specifications."
  2809. ;; Standard test.
  2810. (should
  2811. (let ((org-custom-properties '("FOO")))
  2812. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2813. (org-toggle-custom-properties-visibility)
  2814. (org-invisible-p2))))
  2815. ;; Properties are case-insensitive.
  2816. (should
  2817. (let ((org-custom-properties '("FOO")))
  2818. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
  2819. (org-toggle-custom-properties-visibility)
  2820. (org-invisible-p2))))
  2821. (should
  2822. (let ((org-custom-properties '("foo")))
  2823. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2824. (org-toggle-custom-properties-visibility)
  2825. (org-invisible-p2))))
  2826. ;; Multiple custom properties in the same drawer.
  2827. (should
  2828. (let ((org-custom-properties '("FOO" "BAR")))
  2829. (org-test-with-temp-text
  2830. "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
  2831. (org-toggle-custom-properties-visibility)
  2832. (and (org-invisible-p2)
  2833. (not (progn (forward-line) (org-invisible-p2)))
  2834. (progn (forward-line) (org-invisible-p2))))))
  2835. ;; Hide custom properties with an empty value.
  2836. (should
  2837. (let ((org-custom-properties '("FOO")))
  2838. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
  2839. (org-toggle-custom-properties-visibility)
  2840. (org-invisible-p2))))
  2841. ;; Do not hide fake properties.
  2842. (should-not
  2843. (let ((org-custom-properties '("FOO")))
  2844. (org-test-with-temp-text ":FOO: val\n"
  2845. (org-toggle-custom-properties-visibility)
  2846. (org-invisible-p2))))
  2847. (should-not
  2848. (let ((org-custom-properties '("A")))
  2849. (org-test-with-temp-text
  2850. "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
  2851. (org-toggle-custom-properties-visibility)
  2852. (org-invisible-p2)))))
  2853. ;;; Mark Region
  2854. (ert-deftest test-org/mark-element ()
  2855. "Test `org-mark-element' specifications."
  2856. ;; Mark beginning and end of element.
  2857. (should
  2858. (equal '(t t)
  2859. (org-test-with-temp-text "Para<point>graph"
  2860. (org-mark-element)
  2861. (list (bobp) (= (mark) (point-max))))))
  2862. (should
  2863. (equal '(t t)
  2864. (org-test-with-temp-text "P1\n\nPara<point>graph\n\nP2"
  2865. (org-mark-element)
  2866. (list (looking-at "Paragraph")
  2867. (org-with-point-at (mark) (looking-at "P2"))))))
  2868. ;; Do not set mark past (point-max).
  2869. (should
  2870. (org-test-with-temp-text "Para<point>graph"
  2871. (narrow-to-region 2 6)
  2872. (org-mark-element)
  2873. (= 6 (mark)))))
  2874. (ert-deftest test-org/mark-subtree ()
  2875. "Test `org-mark-subtree' specifications."
  2876. ;; Error when point is before first headline.
  2877. (should-error
  2878. (org-test-with-temp-text "Paragraph\n* Headline\nBody"
  2879. (progn (transient-mark-mode 1)
  2880. (org-mark-subtree))))
  2881. ;; Without argument, mark current subtree.
  2882. (should
  2883. (equal
  2884. '(12 32)
  2885. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  2886. (progn (transient-mark-mode 1)
  2887. (forward-line 2)
  2888. (org-mark-subtree)
  2889. (list (region-beginning) (region-end))))))
  2890. ;; With an argument, move ARG up.
  2891. (should
  2892. (equal
  2893. '(1 32)
  2894. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  2895. (progn (transient-mark-mode 1)
  2896. (forward-line 2)
  2897. (org-mark-subtree 1)
  2898. (list (region-beginning) (region-end))))))
  2899. ;; Do not get fooled by inlinetasks.
  2900. (when (featurep 'org-inlinetask)
  2901. (should
  2902. (= 1
  2903. (org-test-with-temp-text "* Headline\n*************** Task\nContents"
  2904. (progn (transient-mark-mode 1)
  2905. (forward-line 1)
  2906. (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
  2907. (region-beginning)))))))
  2908. ;;; Miscellaneous
  2909. (ert-deftest test-org/sort-entries ()
  2910. "Test `org-sort-entries'."
  2911. ;; Sort alphabetically.
  2912. (should
  2913. (equal "\n* abc\n* def\n* xyz\n"
  2914. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  2915. (org-sort-entries nil ?a)
  2916. (buffer-string))))
  2917. (should
  2918. (equal "\n* xyz\n* def\n* abc\n"
  2919. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  2920. (org-sort-entries nil ?A)
  2921. (buffer-string))))
  2922. (should
  2923. (equal "\n* \n* klm\n* xyz\n"
  2924. (org-test-with-temp-text "\n* xyz\n* \n* klm\n"
  2925. (org-sort-entries nil ?a)
  2926. (buffer-string))))
  2927. ;; Sort numerically.
  2928. (should
  2929. (equal "\n* 1\n* 2\n* 10\n"
  2930. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  2931. (org-sort-entries nil ?n)
  2932. (buffer-string))))
  2933. (should
  2934. (equal "\n* 10\n* 2\n* 1\n"
  2935. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  2936. (org-sort-entries nil ?N)
  2937. (buffer-string))))
  2938. (should
  2939. (equal "\n* \n* 1\n* 2\n"
  2940. (org-test-with-temp-text "\n* 1\n* \n* 2\n"
  2941. (org-sort-entries nil ?n)
  2942. (buffer-string))))
  2943. ;; Sort by custom function.
  2944. (should
  2945. (equal "\n* b\n* aa\n* ccc\n"
  2946. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  2947. (org-sort-entries nil ?f
  2948. (lambda ()
  2949. (length (buffer-substring (point-at-bol)
  2950. (point-at-eol))))
  2951. #'<)
  2952. (buffer-string))))
  2953. (should
  2954. (equal "\n* ccc\n* aa\n* b\n"
  2955. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  2956. (org-sort-entries nil ?F
  2957. (lambda ()
  2958. (length (buffer-substring (point-at-bol)
  2959. (point-at-eol))))
  2960. #'<)
  2961. (buffer-string))))
  2962. ;; Sort by TODO keyword.
  2963. (should
  2964. (equal "\n* TODO h1\n* TODO h3\n* DONE h2\n"
  2965. (org-test-with-temp-text
  2966. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  2967. (org-sort-entries nil ?o)
  2968. (buffer-string))))
  2969. (should
  2970. (equal "\n* DONE h2\n* TODO h1\n* TODO h3\n"
  2971. (org-test-with-temp-text
  2972. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  2973. (org-sort-entries nil ?O)
  2974. (buffer-string))))
  2975. ;; Sort by priority.
  2976. (should
  2977. (equal "\n* [#A] h2\n* [#B] h3\n* [#C] h1\n"
  2978. (org-test-with-temp-text
  2979. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  2980. (org-sort-entries nil ?p)
  2981. (buffer-string))))
  2982. (should
  2983. (equal "\n* [#C] h1\n* [#B] h3\n* [#A] h2\n"
  2984. (org-test-with-temp-text
  2985. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  2986. (org-sort-entries nil ?P)
  2987. (buffer-string))))
  2988. ;; Sort by creation time.
  2989. (should
  2990. (equal "
  2991. * h3
  2992. [2017-05-08 Mon]
  2993. * h2
  2994. [2017-05-09 Tue]
  2995. * h1
  2996. [2018-05-09 Wed]
  2997. "
  2998. (org-test-with-temp-text
  2999. "
  3000. * h1
  3001. [2018-05-09 Wed]
  3002. * h2
  3003. [2017-05-09 Tue]
  3004. * h3
  3005. [2017-05-08 Mon]
  3006. "
  3007. (org-sort-entries nil ?c)
  3008. (buffer-string))))
  3009. ;; Sort by scheduled date.
  3010. (should
  3011. (equal "
  3012. * TODO h4
  3013. SCHEDULED: <2017-05-06 Sat>
  3014. * TODO h3
  3015. SCHEDULED: <2017-05-08 Mon>
  3016. * TODO h2
  3017. DEADLINE: <2017-05-09 Tue>
  3018. * TODO h1
  3019. DEADLINE: <2017-05-07 Sun>
  3020. "
  3021. (org-test-with-temp-text
  3022. "
  3023. * TODO h2
  3024. DEADLINE: <2017-05-09 Tue>
  3025. * TODO h1
  3026. DEADLINE: <2017-05-07 Sun>
  3027. * TODO h3
  3028. SCHEDULED: <2017-05-08 Mon>
  3029. * TODO h4
  3030. SCHEDULED: <2017-05-06 Sat>
  3031. "
  3032. (org-sort-entries nil ?s)
  3033. (buffer-string))))
  3034. ;; Sort by deadline date.
  3035. (should
  3036. (equal "
  3037. * TODO h1
  3038. DEADLINE: <2017-05-07 Sun>
  3039. * TODO h2
  3040. DEADLINE: <2017-05-09 Tue>
  3041. * TODO h3
  3042. SCHEDULED: <2017-05-08 Mon>
  3043. * TODO h4
  3044. SCHEDULED: <2017-05-06 Sat>
  3045. "
  3046. (org-test-with-temp-text
  3047. "
  3048. * TODO h2
  3049. DEADLINE: <2017-05-09 Tue>
  3050. * TODO h1
  3051. DEADLINE: <2017-05-07 Sun>
  3052. * TODO h3
  3053. SCHEDULED: <2017-05-08 Mon>
  3054. * TODO h4
  3055. SCHEDULED: <2017-05-06 Sat>
  3056. "
  3057. (org-sort-entries nil ?d)
  3058. (buffer-string))))
  3059. ;; Sort by any date/time
  3060. (should
  3061. (equal "
  3062. * TODO h4
  3063. SCHEDULED: <2017-05-06 Sat>
  3064. * TODO h1
  3065. DEADLINE: <2017-05-07 Sun>
  3066. * TODO h3
  3067. SCHEDULED: <2017-05-08 Mon>
  3068. * TODO h2
  3069. DEADLINE: <2017-05-09 Tue>
  3070. "
  3071. (org-test-with-temp-text
  3072. "
  3073. * TODO h2
  3074. DEADLINE: <2017-05-09 Tue>
  3075. * TODO h1
  3076. DEADLINE: <2017-05-07 Sun>
  3077. * TODO h3
  3078. SCHEDULED: <2017-05-08 Mon>
  3079. * TODO h4
  3080. SCHEDULED: <2017-05-06 Sat>
  3081. "
  3082. (org-sort-entries nil ?t)
  3083. (buffer-string))))
  3084. ;; Sort by clocking time.
  3085. (should
  3086. (equal "
  3087. * clocked h2
  3088. :LOGBOOK:
  3089. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3090. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  3091. :END:
  3092. * clocked h1
  3093. :LOGBOOK:
  3094. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3095. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  3096. :END:
  3097. "
  3098. (org-test-with-temp-text
  3099. "
  3100. * clocked h1
  3101. :LOGBOOK:
  3102. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3103. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  3104. :END:
  3105. * clocked h2
  3106. :LOGBOOK:
  3107. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3108. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  3109. :END:
  3110. "
  3111. (org-sort-entries nil ?k)
  3112. (buffer-string))))
  3113. ;; Preserve file local variables when sorting.
  3114. (should
  3115. (equal "\n* A\n* B\n# Local Variables:\n# foo: t\n# End:\n"
  3116. (org-test-with-temp-text
  3117. "\n* B\n* A\n# Local Variables:\n# foo: t\n# End:"
  3118. (org-sort-entries nil ?a)
  3119. (buffer-string)))))
  3120. (ert-deftest test-org/string-collate-greaterp ()
  3121. "Test `org-string-collate-greaterp' specifications."
  3122. (should (org-string-collate-greaterp "def" "abc"))
  3123. (should-not (org-string-collate-greaterp "abc" "def")))
  3124. (ert-deftest test-org/file-contents ()
  3125. "Test `org-file-contents' specifications."
  3126. ;; Open files.
  3127. (should
  3128. (string= "#+BIND: variable value
  3129. #+DESCRIPTION: l2
  3130. #+LANGUAGE: en
  3131. #+SELECT_TAGS: b
  3132. #+TITLE: b
  3133. #+PROPERTY: a 1
  3134. " (org-file-contents (expand-file-name "setupfile3.org"
  3135. (concat org-test-dir "examples/")))))
  3136. ;; Throw error when trying to access an invalid file.
  3137. (should-error (org-file-contents "this-file-must-not-exist"))
  3138. ;; Try to access an invalid file, but do not throw an error.
  3139. (should
  3140. (progn (org-file-contents "this-file-must-not-exist" :noerror) t))
  3141. ;; Open URL.
  3142. (should
  3143. (string= "foo"
  3144. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3145. (unwind-protect
  3146. ;; Simulate successful retrieval of a URL.
  3147. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3148. (lambda (&rest_)
  3149. (with-current-buffer buffer
  3150. (insert "HTTP/1.1 200 OK\n\nfoo"))
  3151. buffer)))
  3152. (org-file-contents "http://some-valid-url"))
  3153. (kill-buffer buffer)))))
  3154. ;; Throw error when trying to access an invalid URL.
  3155. (should-error
  3156. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3157. (unwind-protect
  3158. ;; Simulate unsuccessful retrieval of a URL.
  3159. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3160. (lambda (&rest_)
  3161. (with-current-buffer buffer
  3162. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3163. buffer)))
  3164. (org-file-contents "http://this-url-must-not-exist"))
  3165. (kill-buffer buffer))))
  3166. ;; Try to access an invalid URL, but do not throw an error.
  3167. (should-error
  3168. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3169. (unwind-protect
  3170. ;; Simulate unsuccessful retrieval of a URL.
  3171. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3172. (lambda (&rest_)
  3173. (with-current-buffer buffer
  3174. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3175. buffer)))
  3176. (org-file-contents "http://this-url-must-not-exist"))
  3177. (kill-buffer buffer))))
  3178. (should
  3179. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3180. (unwind-protect
  3181. ;; Simulate unsuccessful retrieval of a URL.
  3182. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3183. (lambda (&rest_)
  3184. (with-current-buffer buffer
  3185. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3186. buffer)))
  3187. (org-file-contents "http://this-url-must-not-exist" :noerror))
  3188. (kill-buffer buffer))
  3189. t)))
  3190. ;;; Navigation
  3191. (ert-deftest test-org/next-visible-heading ()
  3192. "Test `org-next-visible-heading' specifications."
  3193. ;; Move to the beginning of the next headline, taking into
  3194. ;; consideration ARG.
  3195. (should
  3196. (org-test-with-temp-text "* H1\n* H2"
  3197. (org-next-visible-heading 1)
  3198. (looking-at "\\* H2")))
  3199. (should
  3200. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3201. (org-next-visible-heading 2)
  3202. (looking-at "\\* H3")))
  3203. ;; Ignore invisible headlines.
  3204. (should
  3205. (org-test-with-temp-text "* H1\n** H2\n* H3"
  3206. (org-cycle)
  3207. (org-next-visible-heading 1)
  3208. (looking-at "\\* H3")))
  3209. ;; Move point between headlines, not on blank lines between.
  3210. (should
  3211. (org-test-with-temp-text "* H1\n** H2\n\n\n\n* H3"
  3212. (let ((org-cycle-separator-lines 1))
  3213. (org-cycle)
  3214. (org-next-visible-heading 1))
  3215. (looking-at "\\* H3")))
  3216. ;; Move at end of buffer when there is no more headline.
  3217. (should
  3218. (org-test-with-temp-text "* H1"
  3219. (org-next-visible-heading 1)
  3220. (eobp)))
  3221. (should
  3222. (org-test-with-temp-text "* H1\n* H2"
  3223. (org-next-visible-heading 2)
  3224. (eobp)))
  3225. ;; With a negative argument, move backwards.
  3226. (should
  3227. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3228. (org-next-visible-heading -1)
  3229. (looking-at "\\* H2")))
  3230. (should
  3231. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3232. (org-next-visible-heading -2)
  3233. (looking-at "\\* H1"))))
  3234. (ert-deftest test-org/previous-visible-heading ()
  3235. "Test `org-previous-visible-heading' specifications."
  3236. ;; Move to the beginning of the next headline, taking into
  3237. ;; consideration ARG.
  3238. (should
  3239. (org-test-with-temp-text "* H1\n<point>* H2"
  3240. (org-previous-visible-heading 1)
  3241. (looking-at "\\* H1")))
  3242. (should
  3243. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3244. (org-previous-visible-heading 2)
  3245. (looking-at "\\* H1")))
  3246. ;; Ignore invisible headlines.
  3247. (should
  3248. (org-test-with-temp-text "* H1\n** H2\n<point>* H3"
  3249. (org-overview)
  3250. (org-previous-visible-heading 1)
  3251. (looking-at "\\* H1")))
  3252. ;; Move point between headlines, not on blank lines between.
  3253. (should
  3254. (org-test-with-temp-text "* H1\n\n\n\n** H2\n<point>* H3"
  3255. (let ((org-cycle-separator-lines 1))
  3256. (org-overview)
  3257. (org-previous-visible-heading 1))
  3258. (looking-at "\\* H1")))
  3259. ;; Move at end of buffer when there is no more headline.
  3260. (should
  3261. (org-test-with-temp-text "* H1"
  3262. (org-previous-visible-heading 1)
  3263. (bobp)))
  3264. (should
  3265. (org-test-with-temp-text "* H1\n* <point>H2"
  3266. (org-previous-visible-heading 2)
  3267. (bobp)))
  3268. ;; Invisible parts may not start at a headline, i.e., when revealing
  3269. ;; parts of the buffer. Handle this.
  3270. (should
  3271. (org-test-with-temp-text "* Main\n** H1\nFoo\n** H2\nBar\n** H3\nBaz"
  3272. (org-overview)
  3273. (search-forward "H1")
  3274. (org-show-context 'minimal)
  3275. (org-cycle)
  3276. (search-forward "H3")
  3277. (org-show-context 'minimal)
  3278. ;; At this point, buffer displays, with point at "|",
  3279. ;;
  3280. ;; * Main
  3281. ;; ** H1
  3282. ;; Foo
  3283. ;; ** H3|
  3284. (org-previous-visible-heading 1)
  3285. (looking-at "\\*+ H1"))))
  3286. (ert-deftest test-org/forward-heading-same-level ()
  3287. "Test `org-forward-heading-same-level' specifications."
  3288. ;; Test navigation at top level, forward and backward.
  3289. (should
  3290. (equal "* H2"
  3291. (org-test-with-temp-text "* H1\n* H2"
  3292. (org-forward-heading-same-level 1)
  3293. (buffer-substring-no-properties (point) (line-end-position)))))
  3294. (should
  3295. (equal "* H1"
  3296. (org-test-with-temp-text "* H1\n<point>* H2"
  3297. (org-forward-heading-same-level -1)
  3298. (buffer-substring-no-properties (point) (line-end-position)))))
  3299. ;; Test navigation in a sub-tree, forward and backward.
  3300. (should
  3301. (equal "* H2"
  3302. (org-test-with-temp-text "* H1\n** H11\n** H12\n* H2"
  3303. (org-forward-heading-same-level 1)
  3304. (buffer-substring-no-properties (point) (line-end-position)))))
  3305. (should
  3306. (equal "* H1"
  3307. (org-test-with-temp-text "* H1\n** H11\n** H12\n<point>* H2"
  3308. (org-forward-heading-same-level -1)
  3309. (buffer-substring-no-properties (point) (line-end-position)))))
  3310. ;; Stop at first or last sub-heading.
  3311. (should-not
  3312. (equal "* H2"
  3313. (org-test-with-temp-text "* H1\n** H11\n<point>** H12\n* H2"
  3314. (org-forward-heading-same-level 1)
  3315. (buffer-substring-no-properties (point) (line-end-position)))))
  3316. (should-not
  3317. (equal "* H2"
  3318. (org-test-with-temp-text "* H1\n<point>** H11\n** H12\n* H2"
  3319. (org-forward-heading-same-level -1)
  3320. (buffer-substring-no-properties (point) (line-end-position)))))
  3321. ;; Allow multiple moves.
  3322. (should
  3323. (equal "* H3"
  3324. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3325. (org-forward-heading-same-level 2)
  3326. (buffer-substring-no-properties (point) (line-end-position)))))
  3327. (should
  3328. (equal "* H1"
  3329. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3330. (org-forward-heading-same-level -2)
  3331. (buffer-substring-no-properties (point) (line-end-position)))))
  3332. ;; Ignore spurious moves when first (or last) sibling is reached.
  3333. (should
  3334. (equal "** H3"
  3335. (org-test-with-temp-text "* First\n<point>** H1\n** H2\n** H3\n* Last"
  3336. (org-forward-heading-same-level 100)
  3337. (buffer-substring-no-properties (point) (line-end-position)))))
  3338. (should
  3339. (equal "** H1"
  3340. (org-test-with-temp-text "* First\n** H1\n** H2\n<point>** H3\n* Last"
  3341. (org-forward-heading-same-level -100)
  3342. (buffer-substring-no-properties (point) (line-end-position))))))
  3343. (ert-deftest test-org/end-of-meta-data ()
  3344. "Test `org-end-of-meta-data' specifications."
  3345. ;; Skip planning line.
  3346. (should
  3347. (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
  3348. (org-end-of-meta-data)
  3349. (eobp)))
  3350. ;; Skip properties drawer.
  3351. (should
  3352. (org-test-with-temp-text
  3353. "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
  3354. (org-end-of-meta-data)
  3355. (eobp)))
  3356. ;; Skip both.
  3357. (should
  3358. (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
  3359. (org-end-of-meta-data)
  3360. (eobp)))
  3361. ;; Nothing to skip, go to first line.
  3362. (should
  3363. (org-test-with-temp-text "* Headline\nContents"
  3364. (org-end-of-meta-data)
  3365. (looking-at "Contents")))
  3366. ;; With option argument, skip empty lines, regular drawers and
  3367. ;; clocking lines.
  3368. (should
  3369. (org-test-with-temp-text "* Headline\n\nContents"
  3370. (org-end-of-meta-data t)
  3371. (looking-at "Contents")))
  3372. (should
  3373. (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
  3374. (org-end-of-meta-data t)
  3375. (looking-at "Contents")))
  3376. (should
  3377. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
  3378. (org-end-of-meta-data t)
  3379. (looking-at "Contents")))
  3380. ;; Special case: do not skip incomplete drawers.
  3381. (should
  3382. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
  3383. (org-end-of-meta-data t)
  3384. (looking-at ":LOGBOOK:")))
  3385. ;; Special case: Be careful about consecutive headlines.
  3386. (should-not
  3387. (org-test-with-temp-text "* H1\n*H2\nContents"
  3388. (org-end-of-meta-data t)
  3389. (looking-at "Contents"))))
  3390. (ert-deftest test-org/shiftright-heading ()
  3391. "Test `org-shiftright' on headings."
  3392. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  3393. (should
  3394. (equal "* TODO a1\n** a2\n* DONE b1\n"
  3395. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3396. (org-shiftright)
  3397. (buffer-string))))
  3398. (should
  3399. (equal "* TODO a1\n** TODO a2\n* b1\n"
  3400. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3401. (let ((org-loop-over-headlines-in-active-region t))
  3402. (transient-mark-mode 1)
  3403. (push-mark (point) t t)
  3404. (search-forward "* DONE b1")
  3405. (org-shiftright))
  3406. (buffer-string))))
  3407. (should
  3408. (equal "* TODO a1\n** a2\n* b1\n"
  3409. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3410. (let ((org-loop-over-headlines-in-active-region 'start-level))
  3411. (transient-mark-mode 1)
  3412. (push-mark (point) t t)
  3413. (search-forward "* DONE b1")
  3414. (org-shiftright))
  3415. (buffer-string))))))
  3416. (ert-deftest test-org/beginning-of-line ()
  3417. "Test `org-beginning-of-line' specifications."
  3418. ;; Move to beginning of line. If current line in invisible, move to
  3419. ;; beginning of visible line instead.
  3420. (should
  3421. (org-test-with-temp-text "Some text\nSome other text<point>"
  3422. (org-beginning-of-line)
  3423. (bolp)))
  3424. (should
  3425. (org-test-with-temp-text "* H1\n** H2<point>"
  3426. (org-overview)
  3427. (org-beginning-of-line)
  3428. (= (line-beginning-position) 1)))
  3429. ;; With `visual-line-mode' active, move to beginning of visual line.
  3430. (should-not
  3431. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3432. (visual-line-mode)
  3433. (dotimes (i 1000) (insert "very "))
  3434. (org-beginning-of-line)
  3435. (bolp)))
  3436. ;; In a wide headline, with `visual-line-mode', prefer going to the
  3437. ;; beginning of a visual line than to the logical beginning of line,
  3438. ;; even if special movement is active.
  3439. (should-not
  3440. (org-test-with-temp-text "* A <point>long headline"
  3441. (visual-line-mode)
  3442. (dotimes (i 1000) (insert "very "))
  3443. (goto-char (point-max))
  3444. (org-beginning-of-line)
  3445. (bobp)))
  3446. (should-not
  3447. (org-test-with-temp-text "* A <point>long headline"
  3448. (visual-line-mode)
  3449. (dotimes (i 1000) (insert "very "))
  3450. (goto-char (point-max))
  3451. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line))
  3452. (bobp)))
  3453. ;; At an headline with special movement, first move at beginning of
  3454. ;; title, then at the beginning of line, rinse, repeat.
  3455. (should
  3456. (org-test-with-temp-text "* TODO Headline<point>"
  3457. (let ((org-special-ctrl-a/e t))
  3458. (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
  3459. (progn (org-beginning-of-line) (bolp))
  3460. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3461. (should
  3462. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3463. (let ((org-special-ctrl-a/e t))
  3464. (org-beginning-of-line)
  3465. (looking-at "Headline"))))
  3466. (should
  3467. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3468. (let ((org-special-ctrl-a/e '(t . nil)))
  3469. (org-beginning-of-line)
  3470. (looking-at "Headline"))))
  3471. (should-not
  3472. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3473. (let ((org-special-ctrl-a/e '(nil . nil)))
  3474. (org-beginning-of-line)
  3475. (looking-at "Headline"))))
  3476. ;; At an headline with reversed movement, first move to beginning of
  3477. ;; line, then to the beginning of title.
  3478. (should
  3479. (org-test-with-temp-text "* TODO Headline<point>"
  3480. (let ((org-special-ctrl-a/e 'reversed)
  3481. (this-command last-command))
  3482. (and (progn (org-beginning-of-line) (bolp))
  3483. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3484. (should
  3485. (org-test-with-temp-text "* TODO Headline<point>"
  3486. (let ((org-special-ctrl-a/e '(reversed . nil))
  3487. (this-command last-command))
  3488. (and (progn (org-beginning-of-line) (bolp))
  3489. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3490. (should-not
  3491. (org-test-with-temp-text "* TODO Headline<point>"
  3492. (let ((org-special-ctrl-a/e '(t . nil))
  3493. (this-command last-command))
  3494. (and (progn (org-beginning-of-line) (bolp))
  3495. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3496. ;; At an item with special movement, first move after to beginning
  3497. ;; of title, then to the beginning of line, rinse, repeat.
  3498. (should
  3499. (org-test-with-temp-text "- [ ] Item<point>"
  3500. (let ((org-special-ctrl-a/e t))
  3501. (and (progn (org-beginning-of-line) (looking-at-p "Item"))
  3502. (progn (org-beginning-of-line) (bolp))
  3503. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3504. ;; At an item with reversed movement, first move to beginning of
  3505. ;; line, then to the beginning of title.
  3506. (should
  3507. (org-test-with-temp-text "- [X] Item<point>"
  3508. (let ((org-special-ctrl-a/e 'reversed)
  3509. (this-command last-command))
  3510. (and (progn (org-beginning-of-line) (bolp))
  3511. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3512. ;; Leave point before invisible characters at column 0.
  3513. (should
  3514. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3515. (let ((org-special-ctrl-a/e nil))
  3516. (org-beginning-of-line)
  3517. (bolp))))
  3518. (should
  3519. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3520. (let ((org-special-ctrl-a/e t))
  3521. (org-beginning-of-line)
  3522. (bolp))))
  3523. (should
  3524. (org-test-with-temp-text "[[http<point>://orgmode.org]]"
  3525. (visual-line-mode)
  3526. (org-beginning-of-line)
  3527. (bolp)))
  3528. ;; Special case: Do not error when the buffer contains only a single
  3529. ;; asterisk.
  3530. (should
  3531. (org-test-with-temp-text "*<point>"
  3532. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line) t)))
  3533. (should
  3534. (org-test-with-temp-text "*<point>"
  3535. (let ((org-special-ctrl-a/e nil)) (org-beginning-of-line) t))))
  3536. (ert-deftest test-org/end-of-line ()
  3537. "Test `org-end-of-line' specifications."
  3538. ;; Standard test.
  3539. (should
  3540. (org-test-with-temp-text "Some text\nSome other text"
  3541. (org-end-of-line)
  3542. (eolp)))
  3543. ;; With `visual-line-mode' active, move to end of visible line.
  3544. ;; However, never go past ellipsis.
  3545. (should-not
  3546. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3547. (visual-line-mode)
  3548. (dotimes (i 1000) (insert "very "))
  3549. (goto-char (point-min))
  3550. (org-end-of-line)
  3551. (eolp)))
  3552. (should-not
  3553. (org-test-with-temp-text "* A short headline\nSome contents"
  3554. (visual-line-mode)
  3555. (org-overview)
  3556. (org-end-of-line)
  3557. (eobp)))
  3558. ;; In a wide headline, with `visual-line-mode', prefer going to end
  3559. ;; of visible line if tags, or end of line, are farther.
  3560. (should-not
  3561. (org-test-with-temp-text "* A <point>long headline"
  3562. (visual-line-mode)
  3563. (dotimes (i 1000) (insert "very "))
  3564. (goto-char (point-min))
  3565. (org-end-of-line)
  3566. (eolp)))
  3567. (should-not
  3568. (org-test-with-temp-text "* A <point>long headline :tag:"
  3569. (visual-line-mode)
  3570. (dotimes (i 1000) (insert "very "))
  3571. (goto-char (point-min))
  3572. (org-end-of-line)
  3573. (eolp)))
  3574. ;; At an headline without special movement, go to end of line.
  3575. ;; However, never go past ellipsis.
  3576. (should
  3577. (org-test-with-temp-text "* Headline2b :tag:\n"
  3578. (let ((org-special-ctrl-a/e nil))
  3579. (and (progn (org-end-of-line) (eolp))
  3580. (progn (org-end-of-line) (eolp))))))
  3581. (should
  3582. (org-test-with-temp-text "* Headline2b :tag:\n"
  3583. (let ((org-special-ctrl-a/e '(t . nil)))
  3584. (and (progn (org-end-of-line) (eolp))
  3585. (progn (org-end-of-line) (eolp))))))
  3586. (should
  3587. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3588. (org-overview)
  3589. (let ((org-special-ctrl-a/e nil))
  3590. (org-end-of-line)
  3591. (= 1 (line-beginning-position)))))
  3592. ;; At an headline with special movement, first move before tags,
  3593. ;; then at the end of line, rinse, repeat. However, never go past
  3594. ;; ellipsis.
  3595. (should
  3596. (org-test-with-temp-text "* Headline1 :tag:\n"
  3597. (let ((org-special-ctrl-a/e t))
  3598. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3599. (progn (org-end-of-line) (eolp))
  3600. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3601. (should
  3602. (org-test-with-temp-text "* Headline1 :tag:\n"
  3603. (let ((org-special-ctrl-a/e '(nil . t)))
  3604. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3605. (progn (org-end-of-line) (eolp))
  3606. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3607. (should-not
  3608. (org-test-with-temp-text "* Headline1 :tag:\n"
  3609. (let ((org-special-ctrl-a/e '(nil . nil)))
  3610. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3611. (progn (org-end-of-line) (eolp))
  3612. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3613. (should
  3614. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3615. (org-overview)
  3616. (let ((org-special-ctrl-a/e t))
  3617. (org-end-of-line)
  3618. (org-end-of-line)
  3619. (= 1 (line-beginning-position)))))
  3620. ;; At an headline, with reversed movement, first go to end of line,
  3621. ;; then before tags. However, never go past ellipsis.
  3622. (should
  3623. (org-test-with-temp-text "* Headline3 :tag:\n"
  3624. (let ((org-special-ctrl-a/e 'reversed)
  3625. (this-command last-command))
  3626. (and (progn (org-end-of-line) (eolp))
  3627. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3628. (should
  3629. (org-test-with-temp-text "* Headline3 :tag:\n"
  3630. (let ((org-special-ctrl-a/e '(nil . reversed))
  3631. (this-command last-command))
  3632. (and (progn (org-end-of-line) (eolp))
  3633. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3634. (should-not
  3635. (org-test-with-temp-text "* Headline3 :tag:\n"
  3636. (let ((org-special-ctrl-a/e '(nil . t))
  3637. (this-command last-command))
  3638. (and (progn (org-end-of-line) (eolp))
  3639. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3640. (should
  3641. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3642. (org-overview)
  3643. (let ((org-special-ctrl-a/e 'reversed))
  3644. (org-end-of-line)
  3645. (= 1 (line-beginning-position)))))
  3646. ;; At a block without hidden contents.
  3647. (should
  3648. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3649. (progn (org-end-of-line) (eolp))))
  3650. ;; At a block with hidden contents.
  3651. (should-not
  3652. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3653. (let ((org-special-ctrl-a/e t))
  3654. (org-hide-block-toggle)
  3655. (org-end-of-line)
  3656. (eobp))))
  3657. ;; Get past invisible characters at the end of line.
  3658. (should
  3659. (org-test-with-temp-text "[[https://orgmode.org]]"
  3660. (org-end-of-line)
  3661. (eolp))))
  3662. (ert-deftest test-org/open-line ()
  3663. "Test `org-open-line' specifications."
  3664. ;; Call `open-line' outside of tables.
  3665. (should
  3666. (equal "\nText"
  3667. (org-test-with-temp-text "Text"
  3668. (org-open-line 1)
  3669. (buffer-string))))
  3670. ;; At a table, create a row above.
  3671. (should
  3672. (equal "\n| |\n| a |"
  3673. (org-test-with-temp-text "\n<point>| a |"
  3674. (org-open-line 1)
  3675. (buffer-string))))
  3676. ;; At the very first character of the buffer, also call `open-line'.
  3677. (should
  3678. (equal "\n| a |"
  3679. (org-test-with-temp-text "| a |"
  3680. (org-open-line 1)
  3681. (buffer-string))))
  3682. ;; Narrowing does not count.
  3683. (should
  3684. (equal "Text\n| |\n| a |"
  3685. (org-test-with-temp-text "Text\n<point>| a |"
  3686. (narrow-to-region (point) (point-max))
  3687. (org-open-line 1)
  3688. (widen)
  3689. (buffer-string)))))
  3690. (ert-deftest test-org/forward-sentence ()
  3691. "Test `org-forward-sentence' specifications."
  3692. ;; At the end of a table cell, move to the end of the next one.
  3693. (should
  3694. (org-test-with-temp-text "| a<point> | b |"
  3695. (org-forward-sentence)
  3696. (looking-at " |$")))
  3697. ;; Elsewhere in a cell, move to its end.
  3698. (should
  3699. (org-test-with-temp-text "| a<point>c | b |"
  3700. (org-forward-sentence)
  3701. (looking-at " | b |$")))
  3702. ;; Otherwise, simply call `forward-sentence'.
  3703. (should
  3704. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3705. (org-forward-sentence)
  3706. (looking-at " Sentence 2.")))
  3707. (should
  3708. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3709. (org-forward-sentence)
  3710. (org-forward-sentence)
  3711. (eobp)))
  3712. ;; At the end of an element, jump to the next one, without stopping
  3713. ;; on blank lines in-between.
  3714. (should
  3715. (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
  3716. (org-forward-sentence)
  3717. (eobp)))
  3718. ;; Headlines are considered to be sentences by themselves, even if
  3719. ;; they do not end with a full stop.
  3720. (should
  3721. (equal
  3722. "* Headline"
  3723. (org-test-with-temp-text "* <point>Headline\nSentence."
  3724. (org-forward-sentence)
  3725. (buffer-substring-no-properties (line-beginning-position) (point)))))
  3726. (should
  3727. (org-test-with-temp-text "* Headline<point>\nSentence."
  3728. (org-forward-sentence)
  3729. (eobp)))
  3730. (should
  3731. (org-test-with-temp-text "Sentence.<point>\n\n* Headline\n\nSentence 2."
  3732. (org-forward-sentence)
  3733. (and (org-at-heading-p) (eolp)))))
  3734. (ert-deftest test-org/backward-sentence ()
  3735. "Test `org-backward-sentence' specifications."
  3736. ;; At the beginning of a table cell, move to the beginning of the
  3737. ;; previous one.
  3738. (should
  3739. (org-test-with-temp-text "| a | <point>b |"
  3740. (org-backward-sentence)
  3741. (looking-at "a | b |$")))
  3742. ;; Elsewhere in a cell, move to its beginning.
  3743. (should
  3744. (org-test-with-temp-text "| a | b<point>c |"
  3745. (org-backward-sentence)
  3746. (looking-at "bc |$")))
  3747. ;; Otherwise, simply call `backward-sentence'.
  3748. (should
  3749. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3750. (org-backward-sentence)
  3751. (looking-at "Sentence 2.")))
  3752. (should
  3753. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3754. (org-backward-sentence)
  3755. (org-backward-sentence)
  3756. (bobp)))
  3757. ;; Make sure to hit the beginning of a sentence on the same line as
  3758. ;; an item.
  3759. (should
  3760. (org-test-with-temp-text "- Line 1\n line <point>2."
  3761. (org-backward-sentence)
  3762. (looking-at "Line 1"))))
  3763. (ert-deftest test-org/forward-paragraph ()
  3764. "Test `org-forward-paragraph' specifications."
  3765. ;; At end of buffer, do not return an error.
  3766. (should
  3767. (org-test-with-temp-text "Paragraph"
  3768. (goto-char (point-max))
  3769. (org-forward-paragraph)
  3770. t))
  3771. ;; Standard test.
  3772. (should
  3773. (= 2
  3774. (org-test-with-temp-text "P1\n\nP2"
  3775. (org-forward-paragraph)
  3776. (org-current-line))))
  3777. (should
  3778. (= 2
  3779. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  3780. (org-forward-paragraph)
  3781. (org-current-line))))
  3782. ;; Enter greater elements.
  3783. (should
  3784. (= 2
  3785. (org-test-with-temp-text "#+begin_center\nP1\n#+end_center\nP2"
  3786. (org-forward-paragraph)
  3787. (org-current-line))))
  3788. ;; Do not enter elements with invisible contents.
  3789. (should
  3790. (= 4
  3791. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  3792. (org-cycle)
  3793. (org-forward-paragraph)
  3794. (org-current-line))))
  3795. (should
  3796. (= 6
  3797. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\nP3"
  3798. (org-hide-block-toggle)
  3799. (org-forward-paragraph)
  3800. (org-current-line))))
  3801. ;; On an item or a footnote definition, move past the first element
  3802. ;; inside, if any.
  3803. (should
  3804. (= 2
  3805. (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
  3806. (org-forward-paragraph)
  3807. (org-current-line))))
  3808. (should
  3809. (= 2
  3810. (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
  3811. (org-forward-paragraph)
  3812. (org-current-line))))
  3813. ;; On a table (resp. a property drawer) do not move through table
  3814. ;; rows (resp. node properties).
  3815. (should
  3816. (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
  3817. (org-forward-paragraph)
  3818. (looking-at "Paragraph")))
  3819. (should
  3820. (org-test-with-temp-text
  3821. "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
  3822. (org-forward-paragraph)
  3823. (looking-at "Paragraph")))
  3824. ;; Skip consecutive keywords, clocks and diary S-exps.
  3825. (should
  3826. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n"
  3827. (org-forward-paragraph)
  3828. (eobp)))
  3829. (should
  3830. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n"
  3831. (org-forward-paragraph)
  3832. (eobp)))
  3833. (should
  3834. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n"
  3835. (org-forward-paragraph)
  3836. (eobp)))
  3837. (should-not
  3838. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n"
  3839. (org-forward-paragraph)
  3840. (eobp)))
  3841. (should-not
  3842. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n"
  3843. (org-forward-paragraph)
  3844. (eobp)))
  3845. ;; In a plain list with one item every line, skip the whole list,
  3846. ;; even with point in the middle of the list.
  3847. (should
  3848. (org-test-with-temp-text "- A\n - B\n- C\n"
  3849. (org-forward-paragraph)
  3850. (eobp)))
  3851. (should
  3852. (org-test-with-temp-text "- A\n - <point>B\n- C\n"
  3853. (org-forward-paragraph)
  3854. (eobp)))
  3855. ;; On a comment, verse or source block, stop at "contents"
  3856. ;; boundaries and blank lines.
  3857. (should
  3858. (= 2
  3859. (org-test-with-temp-text "#+begin_src emacs-lisp\nL1\n\nL2\n#+end_src"
  3860. (org-forward-paragraph)
  3861. (org-current-line))))
  3862. (should
  3863. (= 3
  3864. (org-test-with-temp-text "#+begin_verse\n<point>L1\n\nL2\n#+end_verse"
  3865. (org-forward-paragraph)
  3866. (org-current-line))))
  3867. (should
  3868. (= 5
  3869. (org-test-with-temp-text "#+begin_comment\nL1\n\n<point>L2\n#+end_comment"
  3870. (org-forward-paragraph)
  3871. (org-current-line))))
  3872. ;; Being on an affiliated keyword shouldn't make any difference.
  3873. (should
  3874. (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
  3875. (org-forward-paragraph)
  3876. (eobp))))
  3877. (ert-deftest test-org/backward-paragraph ()
  3878. "Test `org-backward-paragraph' specifications."
  3879. ;; Do not error at beginning of buffer.
  3880. (should
  3881. (org-test-with-temp-text "Paragraph"
  3882. (org-backward-paragraph)
  3883. t))
  3884. ;; At blank lines at the very beginning of a buffer, move to
  3885. ;; point-min.
  3886. (should
  3887. (org-test-with-temp-text "\n\n<point>\n\nParagraph"
  3888. (org-backward-paragraph)
  3889. (bobp)))
  3890. ;; Regular test.
  3891. (should
  3892. (= 2
  3893. (org-test-with-temp-text "P1\n\nP2<point>"
  3894. (org-backward-paragraph)
  3895. (org-current-line))))
  3896. (should
  3897. (= 4
  3898. (org-test-with-temp-text "P1\n\nP2\n\nP3<point>"
  3899. (org-backward-paragraph)
  3900. (org-current-line))))
  3901. ;; Try to move on the line above current element.
  3902. (should
  3903. (= 2
  3904. (org-test-with-temp-text "\n\n<point>Paragraph"
  3905. (org-backward-paragraph)
  3906. (org-current-line))))
  3907. ;; Do not leave point in an invisible area.
  3908. (should
  3909. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  3910. (org-cycle)
  3911. (goto-char (point-max))
  3912. (beginning-of-line)
  3913. (org-backward-paragraph)
  3914. (bobp)))
  3915. (should
  3916. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\n"
  3917. (org-hide-block-toggle)
  3918. (goto-char (point-max))
  3919. (org-backward-paragraph)
  3920. (bobp)))
  3921. ;; On the first element in an item or a footnote definition, jump
  3922. ;; before the footnote or the item.
  3923. (should
  3924. (org-test-with-temp-text "- line1<point>"
  3925. (org-backward-paragraph)
  3926. (bobp)))
  3927. (should
  3928. (org-test-with-temp-text "[fn:1] line1n<point>"
  3929. (org-backward-paragraph)
  3930. (bobp)))
  3931. ;; On the second element in an item or a footnote definition, jump
  3932. ;; to item or the definition.
  3933. (should
  3934. (= 2
  3935. (org-test-with-temp-text "- line1\n\n<point> line2"
  3936. (org-backward-paragraph)
  3937. (org-current-line))))
  3938. (should
  3939. (= 2
  3940. (org-test-with-temp-text "[fn:1] line1\n\n<point> line2"
  3941. (org-backward-paragraph)
  3942. (org-current-line))))
  3943. ;; On a table (resp. a property drawer), ignore table rows
  3944. ;; (resp. node properties).
  3945. (should
  3946. (org-test-with-temp-text "| a | b |\n| c | d |\n<point>P1"
  3947. (org-backward-paragraph)
  3948. (bobp)))
  3949. (should
  3950. (= 2
  3951. (org-test-with-temp-text
  3952. "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
  3953. (org-backward-paragraph)
  3954. (org-current-line))))
  3955. ;; In a plain list with one item every line, skip the whole list,
  3956. ;; even with point in the middle of the list.
  3957. (should
  3958. (org-test-with-temp-text "- A\n - B\n- C\n<point>"
  3959. (org-backward-paragraph)
  3960. (bobp)))
  3961. (should
  3962. (org-test-with-temp-text "- A\n - B\n- <point>C\n"
  3963. (org-backward-paragraph)
  3964. (bobp)))
  3965. ;; Skip consecutive keywords, clocks and diary S-exps.
  3966. (should
  3967. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n<point>"
  3968. (org-backward-paragraph)
  3969. (bobp)))
  3970. (should
  3971. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n<point>"
  3972. (org-backward-paragraph)
  3973. (bobp)))
  3974. (should
  3975. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n<point>"
  3976. (org-backward-paragraph)
  3977. (bobp)))
  3978. (should-not
  3979. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n<point>"
  3980. (org-backward-paragraph)
  3981. (bobp)))
  3982. (should-not
  3983. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n<point>"
  3984. (org-backward-paragraph)
  3985. (bobp)))
  3986. ;; On a comment, example, source and verse blocks, stop at blank
  3987. ;; lines.
  3988. (should
  3989. (= 1
  3990. (org-test-with-temp-text
  3991. "#+begin_comment\n<point>L1\n\nL2\n\nL3\n#+end_comment"
  3992. (org-backward-paragraph)
  3993. (org-current-line))))
  3994. (should
  3995. (= 2
  3996. (org-test-with-temp-text
  3997. "#+begin_verse\nL1\n\n<point>L2\n\nL3\n#+end_verse"
  3998. (org-backward-paragraph)
  3999. (org-current-line))))
  4000. (should
  4001. (= 3
  4002. (org-test-with-temp-text
  4003. "#+begin_src emacs-lisp\nL1\n\nL2\n\n<point>L3\n#+end_src"
  4004. (org-backward-paragraph)
  4005. (org-current-line))))
  4006. ;; When called from the opening line itself, however, move to
  4007. ;; beginning of block.
  4008. (should
  4009. (org-test-with-temp-text "#+begin_<point>example\nL1\n#+end_example"
  4010. (org-backward-paragraph)
  4011. (bobp)))
  4012. ;; On an empty heading, move above it.
  4013. (should
  4014. (org-test-with-temp-text "\n* <point>"
  4015. (org-backward-paragraph)
  4016. (bobp)))
  4017. (should
  4018. (org-test-with-temp-text "\n* \n<point>"
  4019. (org-backward-paragraph)
  4020. (bobp))))
  4021. (ert-deftest test-org/forward-element ()
  4022. "Test `org-forward-element' specifications."
  4023. ;; 1. At EOB: should error.
  4024. (org-test-with-temp-text "Some text\n"
  4025. (goto-char (point-max))
  4026. (should-error (org-forward-element)))
  4027. ;; 2. Standard move: expected to ignore blank lines.
  4028. (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
  4029. (org-forward-element)
  4030. (should (looking-at (regexp-quote "Second paragraph."))))
  4031. ;; 3. Headline tests.
  4032. (org-test-with-temp-text "
  4033. * Head 1
  4034. ** Head 1.1
  4035. *** Head 1.1.1
  4036. ** Head 1.2"
  4037. ;; 3.1. At an headline beginning: move to next headline at the
  4038. ;; same level.
  4039. (goto-line 3)
  4040. (org-forward-element)
  4041. (should (looking-at (regexp-quote "** Head 1.2")))
  4042. ;; 3.2. At an headline beginning: move to parent headline if no
  4043. ;; headline at the same level.
  4044. (goto-line 3)
  4045. (org-forward-element)
  4046. (should (looking-at (regexp-quote "** Head 1.2"))))
  4047. ;; 4. Greater element tests.
  4048. (org-test-with-temp-text
  4049. "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
  4050. ;; 4.1. At a greater element: expected to skip contents.
  4051. (org-forward-element)
  4052. (should (looking-at (regexp-quote "Outside.")))
  4053. ;; 4.2. At the end of greater element contents: expected to skip
  4054. ;; to the end of the greater element.
  4055. (goto-line 2)
  4056. (org-forward-element)
  4057. (should (looking-at (regexp-quote "Outside."))))
  4058. ;; 5. List tests.
  4059. (org-test-with-temp-text "
  4060. - item1
  4061. - sub1
  4062. - sub2
  4063. - sub3
  4064. Inner paragraph.
  4065. - item2
  4066. Outside."
  4067. ;; 5.1. At list top point: expected to move to the element after
  4068. ;; the list.
  4069. (goto-line 2)
  4070. (org-forward-element)
  4071. (should (looking-at (regexp-quote "Outside.")))
  4072. ;; 5.2. Special case: at the first line of a sub-list, but not at
  4073. ;; beginning of line, move to next item.
  4074. (goto-line 2)
  4075. (forward-char)
  4076. (org-forward-element)
  4077. (should (looking-at "- item2"))
  4078. (goto-line 4)
  4079. (forward-char)
  4080. (org-forward-element)
  4081. (should (looking-at " - sub2"))
  4082. ;; 5.3 At sub-list beginning: expected to move after the sub-list.
  4083. (goto-line 4)
  4084. (org-forward-element)
  4085. (should (looking-at (regexp-quote " Inner paragraph.")))
  4086. ;; 5.4. At sub-list end: expected to move outside the sub-list.
  4087. (goto-line 8)
  4088. (org-forward-element)
  4089. (should (looking-at (regexp-quote " Inner paragraph.")))
  4090. ;; 5.5. At an item: expected to move to next item, if any.
  4091. (goto-line 6)
  4092. (org-forward-element)
  4093. (should (looking-at " - sub3"))))
  4094. (ert-deftest test-org/backward-element ()
  4095. "Test `org-backward-element' specifications."
  4096. ;; 1. Should error at BOB.
  4097. (org-test-with-temp-text " \nParagraph."
  4098. (should-error (org-backward-element)))
  4099. ;; 2. Should move at BOB when called on the first element in buffer.
  4100. (should
  4101. (org-test-with-temp-text "\n#+TITLE: test"
  4102. (progn (forward-line)
  4103. (org-backward-element)
  4104. (bobp))))
  4105. ;; 3. Not at the beginning of an element: move at its beginning.
  4106. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  4107. (goto-line 3)
  4108. (end-of-line)
  4109. (org-backward-element)
  4110. (should (looking-at (regexp-quote "Paragraph2."))))
  4111. ;; 4. Headline tests.
  4112. (org-test-with-temp-text "
  4113. * Head 1
  4114. ** Head 1.1
  4115. *** Head 1.1.1
  4116. ** Head 1.2"
  4117. ;; 4.1. At an headline beginning: move to previous headline at the
  4118. ;; same level.
  4119. (goto-line 5)
  4120. (org-backward-element)
  4121. (should (looking-at (regexp-quote "** Head 1.1")))
  4122. ;; 4.2. At an headline beginning: move to parent headline if no
  4123. ;; headline at the same level.
  4124. (goto-line 3)
  4125. (org-backward-element)
  4126. (should (looking-at (regexp-quote "* Head 1")))
  4127. ;; 4.3. At the first top-level headline: should error.
  4128. (goto-line 2)
  4129. (should-error (org-backward-element)))
  4130. ;; 5. At beginning of first element inside a greater element:
  4131. ;; expected to move to greater element's beginning.
  4132. (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
  4133. (goto-line 3)
  4134. (org-backward-element)
  4135. (should (looking-at "#\\+BEGIN_CENTER")))
  4136. ;; 6. At the beginning of the first element in a section: should
  4137. ;; move back to headline, if any.
  4138. (should
  4139. (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
  4140. (progn (goto-char (point-max))
  4141. (beginning-of-line)
  4142. (org-backward-element)
  4143. (org-at-heading-p))))
  4144. ;; 7. List tests.
  4145. (org-test-with-temp-text "
  4146. - item1
  4147. - sub1
  4148. - sub2
  4149. - sub3
  4150. Inner paragraph.
  4151. - item2
  4152. Outside."
  4153. ;; 7.1. At beginning of sub-list: expected to move to the
  4154. ;; paragraph before it.
  4155. (goto-line 4)
  4156. (org-backward-element)
  4157. (should (looking-at "item1"))
  4158. ;; 7.2. At an item in a list: expected to move at previous item.
  4159. (goto-line 8)
  4160. (org-backward-element)
  4161. (should (looking-at " - sub2"))
  4162. (goto-line 12)
  4163. (org-backward-element)
  4164. (should (looking-at "- item1"))
  4165. ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
  4166. ;; beginning.
  4167. (goto-line 10)
  4168. (org-backward-element)
  4169. (should (looking-at " - sub1"))
  4170. (goto-line 15)
  4171. (org-backward-element)
  4172. (should (looking-at "- item1"))
  4173. ;; 7.4. At blank-lines before list end: expected to move to top
  4174. ;; item.
  4175. (goto-line 14)
  4176. (org-backward-element)
  4177. (should (looking-at "- item1"))))
  4178. (ert-deftest test-org/up-element ()
  4179. "Test `org-up-element' specifications."
  4180. ;; 1. At BOB or with no surrounding element: should error.
  4181. (org-test-with-temp-text "Paragraph."
  4182. (should-error (org-up-element)))
  4183. (org-test-with-temp-text "* Head1\n* Head2"
  4184. (goto-line 2)
  4185. (should-error (org-up-element)))
  4186. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  4187. (goto-line 3)
  4188. (should-error (org-up-element)))
  4189. ;; 2. At an headline: move to parent headline.
  4190. (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
  4191. (goto-line 3)
  4192. (org-up-element)
  4193. (should (looking-at "\\* Head1")))
  4194. ;; 3. Inside a greater element: move to greater element beginning.
  4195. (org-test-with-temp-text
  4196. "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
  4197. (goto-line 3)
  4198. (org-up-element)
  4199. (should (looking-at "#\\+BEGIN_CENTER")))
  4200. ;; 4. List tests.
  4201. (org-test-with-temp-text "* Top
  4202. - item1
  4203. - sub1
  4204. - sub2
  4205. Paragraph within sub2.
  4206. - item2"
  4207. ;; 4.1. Within an item: move to the item beginning.
  4208. (goto-line 8)
  4209. (org-up-element)
  4210. (should (looking-at " - sub2"))
  4211. ;; 4.2. At an item in a sub-list: move to parent item.
  4212. (goto-line 4)
  4213. (org-up-element)
  4214. (should (looking-at "- item1"))
  4215. ;; 4.3. At an item in top list: move to beginning of whole list.
  4216. (goto-line 10)
  4217. (org-up-element)
  4218. (should (looking-at "- item1"))
  4219. ;; 4.4. Special case. At very top point: should move to parent of
  4220. ;; list.
  4221. (goto-line 2)
  4222. (org-up-element)
  4223. (should (looking-at "\\* Top"))))
  4224. (ert-deftest test-org/down-element ()
  4225. "Test `org-down-element' specifications."
  4226. ;; Error when the element hasn't got a recursive type.
  4227. (org-test-with-temp-text "Paragraph."
  4228. (should-error (org-down-element)))
  4229. ;; Error when the element has no contents
  4230. (org-test-with-temp-text "* Headline"
  4231. (should-error (org-down-element)))
  4232. ;; When at a plain-list, move to first item.
  4233. (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
  4234. (goto-line 2)
  4235. (org-down-element)
  4236. (should (looking-at " - Item 1.1")))
  4237. (org-test-with-temp-text "#+NAME: list\n- Item 1"
  4238. (org-down-element)
  4239. (should (looking-at " Item 1")))
  4240. ;; When at a table, move to first row
  4241. (org-test-with-temp-text "#+NAME: table\n| a | b |"
  4242. (org-down-element)
  4243. (should (looking-at " a | b |")))
  4244. ;; Otherwise, move inside the greater element.
  4245. (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
  4246. (org-down-element)
  4247. (should (looking-at "Paragraph"))))
  4248. (ert-deftest test-org/drag-element-backward ()
  4249. "Test `org-drag-element-backward' specifications."
  4250. ;; Standard test.
  4251. (should
  4252. (equal
  4253. "#+key2: val2\n#+key1: val1\n#+key3: val3"
  4254. (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
  4255. (org-drag-element-backward)
  4256. (buffer-string))))
  4257. (should
  4258. (equal
  4259. "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
  4260. (org-test-with-temp-text
  4261. "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
  4262. (org-drag-element-backward)
  4263. (buffer-string))))
  4264. ;; Preserve blank lines.
  4265. (should
  4266. (equal "Paragraph 2\n\n\nPara1\n\nPara3"
  4267. (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
  4268. (org-drag-element-backward)
  4269. (buffer-string))))
  4270. ;; Preserve column.
  4271. (should
  4272. (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
  4273. (org-drag-element-backward)
  4274. (looking-at-p "2")))
  4275. ;; Error when trying to move first element of buffer.
  4276. (should-error
  4277. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4278. (org-drag-element-backward))
  4279. :type 'user-error)
  4280. ;; Error when trying to swap nested elements.
  4281. (should-error
  4282. (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
  4283. (org-drag-element-backward))
  4284. :type 'user-error)
  4285. ;; Error when trying to swap an headline element and a non-headline
  4286. ;; element.
  4287. (should-error
  4288. (org-test-with-temp-text "Test.\n<point>* Head 1"
  4289. (org-drag-element-backward))
  4290. :type 'error)
  4291. ;; Error when called before first element.
  4292. (should-error
  4293. (org-test-with-temp-text "\n<point>"
  4294. (org-drag-element-backward))
  4295. :type 'user-error)
  4296. ;; Preserve visibility of elements and their contents.
  4297. (should
  4298. (equal '((63 . 82) (26 . 48))
  4299. (org-test-with-temp-text "
  4300. #+BEGIN_CENTER
  4301. Text.
  4302. #+END_CENTER
  4303. - item 1
  4304. #+BEGIN_QUOTE
  4305. Text.
  4306. #+END_QUOTE"
  4307. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4308. (search-backward "- item 1")
  4309. (org-drag-element-backward)
  4310. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4311. (overlays-in (point-min) (point-max))))))
  4312. ;; Pathological case: handle call with point in blank lines right
  4313. ;; after a headline.
  4314. (should
  4315. (equal "* H2\n\n* H1\nText\n"
  4316. (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
  4317. (org-drag-element-backward)
  4318. (buffer-string)))))
  4319. (ert-deftest test-org/drag-element-forward ()
  4320. "Test `org-drag-element-forward' specifications."
  4321. ;; 1. Error when trying to move first element of buffer.
  4322. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4323. (goto-line 3)
  4324. (should-error (org-drag-element-forward)))
  4325. ;; 2. Error when trying to swap nested elements.
  4326. (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
  4327. (forward-line)
  4328. (should-error (org-drag-element-forward)))
  4329. ;; 3. Error when trying to swap a non-headline element and an
  4330. ;; headline.
  4331. (org-test-with-temp-text "Test.\n* Head 1"
  4332. (should-error (org-drag-element-forward)))
  4333. ;; 4. Error when called before first element.
  4334. (should-error
  4335. (org-test-with-temp-text "\n"
  4336. (forward-line)
  4337. (org-drag-element-backward))
  4338. :type 'user-error)
  4339. ;; 5. Otherwise, swap elements, preserving column and blank lines
  4340. ;; between elements.
  4341. (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
  4342. (search-forward "graph")
  4343. (org-drag-element-forward)
  4344. (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
  4345. (should (looking-at " 1")))
  4346. ;; 5. Preserve visibility of elements and their contents.
  4347. (org-test-with-temp-text "
  4348. #+BEGIN_CENTER
  4349. Text.
  4350. #+END_CENTER
  4351. - item 1
  4352. #+BEGIN_QUOTE
  4353. Text.
  4354. #+END_QUOTE"
  4355. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4356. (search-backward "#+BEGIN_CENTER")
  4357. (org-drag-element-forward)
  4358. (should
  4359. (equal
  4360. '((63 . 82) (26 . 48))
  4361. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4362. (overlays-in (point-min) (point-max)))))))
  4363. (ert-deftest test-org/next-block ()
  4364. "Test `org-next-block' specifications."
  4365. ;; Regular test.
  4366. (should
  4367. (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  4368. (org-next-block 1)
  4369. (looking-at "#\\+BEGIN_CENTER")))
  4370. ;; Ignore case.
  4371. (should
  4372. (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
  4373. (let ((case-fold-search nil))
  4374. (org-next-block 1)
  4375. (looking-at "#\\+begin_center"))))
  4376. ;; Ignore current line.
  4377. (should
  4378. (org-test-with-temp-text
  4379. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
  4380. (org-next-block 1)
  4381. (looking-at "#\\+BEGIN_CENTER")))
  4382. ;; Throw an error when no block is found.
  4383. (should-error
  4384. (org-test-with-temp-text "Paragraph"
  4385. (org-next-block 1)))
  4386. ;; With an argument, skip many blocks at once.
  4387. (should
  4388. (org-test-with-temp-text
  4389. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4390. (org-next-block 2)
  4391. (looking-at "#\\+BEGIN_QUOTE")))
  4392. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4393. (should
  4394. (org-test-with-temp-text
  4395. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4396. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4397. (looking-at "#\\+BEGIN_QUOTE")))
  4398. ;; Optional argument is also case-insensitive.
  4399. (should
  4400. (org-test-with-temp-text
  4401. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
  4402. (let ((case-fold-search nil))
  4403. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4404. (looking-at "#\\+begin_quote")))))
  4405. (ert-deftest test-org/insert-structure-template ()
  4406. "Test `org-insert-structure-template'."
  4407. ;; Test in empty buffer.
  4408. (should
  4409. (string= "#+begin_foo\n#+end_foo\n"
  4410. (org-test-with-temp-text ""
  4411. (org-insert-structure-template "foo")
  4412. (buffer-string))))
  4413. ;; Test with multiple lines in buffer.
  4414. (should
  4415. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4416. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4417. (transient-mark-mode 1)
  4418. (org-mark-element)
  4419. (org-insert-structure-template "foo")
  4420. (buffer-string))))
  4421. ;; Mark only the current line.
  4422. (should
  4423. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4424. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4425. (transient-mark-mode 1)
  4426. (set-mark (point-min))
  4427. (end-of-line)
  4428. (org-insert-structure-template "foo")
  4429. (buffer-string))))
  4430. ;; Middle of paragraph.
  4431. (should
  4432. (string= "p1\n#+begin_foo\np2\n#+end_foo\np3"
  4433. (org-test-with-temp-text "p1\n<point>p2\np3"
  4434. (set-mark (line-beginning-position))
  4435. (end-of-line)
  4436. (activate-mark)
  4437. (org-insert-structure-template "foo")
  4438. (buffer-string))))
  4439. ;; Test with text in buffer, no region, no final newline.
  4440. (should
  4441. (string= "#+begin_foo\nI'm a paragraph.\n#+end_foo\n"
  4442. (org-test-with-temp-text "I'm a paragraph."
  4443. (org-mark-element)
  4444. (org-insert-structure-template "foo")
  4445. (buffer-string))))
  4446. ;; Test with text in buffer and region set.
  4447. (should
  4448. (string= "#+begin_foo\nI'm a paragraph\n\nI'm a second paragrah\n#+end_foo\n"
  4449. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragrah"
  4450. (set-mark (point))
  4451. (goto-char (point-max))
  4452. (org-insert-structure-template "foo")
  4453. (buffer-string))))
  4454. ;; Test with example escaping.
  4455. (should
  4456. (string= "#+begin_example\n,* Heading\n#+end_example\n"
  4457. (org-test-with-temp-text "* Heading"
  4458. (org-mark-element)
  4459. (org-insert-structure-template "example")
  4460. (buffer-string))))
  4461. ;; Test with indentation.
  4462. (should
  4463. (string= " #+begin_foo\n This is a paragraph\n #+end_foo\n"
  4464. (org-test-with-temp-text " This is a paragraph"
  4465. (org-mark-element)
  4466. (org-insert-structure-template "foo")
  4467. (buffer-string))))
  4468. (should
  4469. (string= " #+begin_foo\n Line 1\n Line2\n #+end_foo\n"
  4470. (org-test-with-temp-text " Line 1\n Line2"
  4471. (org-mark-element)
  4472. (org-insert-structure-template "foo")
  4473. (buffer-string))))
  4474. ;; Test point location.
  4475. (should
  4476. (string= "#+begin_foo\n"
  4477. (org-test-with-temp-text ""
  4478. (org-insert-structure-template "foo")
  4479. (buffer-substring (point-min) (point)))))
  4480. (should
  4481. (string= "#+begin_src "
  4482. (org-test-with-temp-text ""
  4483. (org-insert-structure-template "src")
  4484. (buffer-substring (point-min) (point))))))
  4485. (ert-deftest test-org/previous-block ()
  4486. "Test `org-previous-block' specifications."
  4487. ;; Regular test.
  4488. (should
  4489. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
  4490. (org-previous-block 1)
  4491. (looking-at "#\\+BEGIN_CENTER")))
  4492. ;; Ignore case.
  4493. (should
  4494. (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
  4495. (let ((case-fold-search nil))
  4496. (org-previous-block 1)
  4497. (looking-at "#\\+begin_center"))))
  4498. ;; Ignore current line.
  4499. (should
  4500. (org-test-with-temp-text
  4501. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
  4502. (org-previous-block 1)
  4503. (looking-at "#\\+BEGIN_QUOTE")))
  4504. ;; Throw an error when no block is found.
  4505. (should-error
  4506. (org-test-with-temp-text "Paragraph<point>"
  4507. (org-previous-block 1)))
  4508. ;; With an argument, skip many blocks at once.
  4509. (should
  4510. (org-test-with-temp-text
  4511. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4512. (org-previous-block 2)
  4513. (looking-at "#\\+BEGIN_CENTER")))
  4514. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4515. (should
  4516. (org-test-with-temp-text
  4517. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4518. (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4519. (looking-at "#\\+BEGIN_QUOTE")))
  4520. ;; Optional argument is also case-insensitive.
  4521. (should
  4522. (org-test-with-temp-text
  4523. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
  4524. (let ((case-fold-search nil))
  4525. (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4526. (looking-at "#\\+begin_quote")))))
  4527. ;;; Outline structure
  4528. (ert-deftest test-org/demote ()
  4529. "Test `org-demote' specifications."
  4530. ;; Add correct number of stars according to `org-odd-levels-only'.
  4531. (should
  4532. (= 2
  4533. (org-test-with-temp-text "* H"
  4534. (let ((org-odd-levels-only nil)) (org-demote))
  4535. (org-current-level))))
  4536. (should
  4537. (= 3
  4538. (org-test-with-temp-text "* H"
  4539. (let ((org-odd-levels-only t)) (org-demote))
  4540. (org-current-level))))
  4541. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4542. (should
  4543. (org-test-with-temp-text "* H :tag:"
  4544. (let ((org-tags-column 10)
  4545. (org-auto-align-tags t)
  4546. (org-odd-levels-only nil))
  4547. (org-demote))
  4548. (org-move-to-column 10)
  4549. (looking-at-p ":tag:$")))
  4550. (should-not
  4551. (org-test-with-temp-text "* H :tag:"
  4552. (let ((org-tags-column 10)
  4553. (org-auto-align-tags nil)
  4554. (org-odd-levels-only nil))
  4555. (org-demote))
  4556. (org-move-to-column 10)
  4557. (looking-at-p ":tag:$")))
  4558. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4559. ;; info and property drawers accordingly.
  4560. (should
  4561. (= 3
  4562. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4563. (let ((org-odd-levels-only nil)
  4564. (org-adapt-indentation t))
  4565. (org-demote))
  4566. (forward-line)
  4567. (org-get-indentation))))
  4568. (should
  4569. (= 3
  4570. (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4571. (let ((org-odd-levels-only nil)
  4572. (org-adapt-indentation t))
  4573. (org-demote))
  4574. (forward-line)
  4575. (org-get-indentation))))
  4576. (should-not
  4577. (= 3
  4578. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4579. (let ((org-odd-levels-only nil)
  4580. (org-adapt-indentation nil))
  4581. (org-demote))
  4582. (forward-line)
  4583. (org-get-indentation))))
  4584. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4585. ;; section accordingly. Ignore, however, footnote definitions and
  4586. ;; inlinetasks boundaries.
  4587. (should
  4588. (= 3
  4589. (org-test-with-temp-text "* H\n Paragraph"
  4590. (let ((org-odd-levels-only nil)
  4591. (org-adapt-indentation t))
  4592. (org-demote))
  4593. (forward-line)
  4594. (org-get-indentation))))
  4595. (should
  4596. (= 2
  4597. (org-test-with-temp-text "* H\n Paragraph"
  4598. (let ((org-odd-levels-only nil)
  4599. (org-adapt-indentation nil))
  4600. (org-demote))
  4601. (forward-line)
  4602. (org-get-indentation))))
  4603. (should
  4604. (zerop
  4605. (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
  4606. (let ((org-odd-levels-only nil)
  4607. (org-adapt-indentation t))
  4608. (org-demote))
  4609. (goto-char (point-max))
  4610. (org-get-indentation))))
  4611. (should
  4612. (= 3
  4613. (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
  4614. (let ((org-odd-levels-only nil)
  4615. (org-adapt-indentation t))
  4616. (org-demote))
  4617. (goto-char (point-max))
  4618. (org-get-indentation))))
  4619. (when (featurep 'org-inlinetask)
  4620. (should
  4621. (zerop
  4622. (let ((org-inlinetask-min-level 5)
  4623. (org-adapt-indentation t))
  4624. (org-test-with-temp-text "* H\n***** I\n***** END"
  4625. (org-demote)
  4626. (forward-line)
  4627. (org-get-indentation))))))
  4628. (when (featurep 'org-inlinetask)
  4629. (should
  4630. (= 3
  4631. (let ((org-inlinetask-min-level 5)
  4632. (org-adapt-indentation t))
  4633. (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
  4634. (org-demote)
  4635. (forward-line 2)
  4636. (org-get-indentation))))))
  4637. ;; When `org-adapt-indentation' is non-nil, log drawers are
  4638. ;; adjusted.
  4639. (should
  4640. (equal
  4641. "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4642. (org-test-with-temp-text "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4643. (let ((org-odd-levels-only nil)
  4644. (org-adapt-indentation t))
  4645. (org-demote))
  4646. (buffer-string))))
  4647. (should
  4648. (equal
  4649. "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4650. (org-test-with-temp-text "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4651. (let ((org-odd-levels-only nil)
  4652. (org-adapt-indentation 'headline-data))
  4653. (org-demote))
  4654. (buffer-string))))
  4655. (should
  4656. (equal
  4657. "** H\n :LOGBOOK:\n - a\n :END:"
  4658. (org-test-with-temp-text "* H\n:LOGBOOK:\n- a\n:END:"
  4659. (let ((org-odd-levels-only nil)
  4660. (org-adapt-indentation t))
  4661. (org-demote))
  4662. (buffer-string))))
  4663. ;; Ignore contents of source blocks or example blocks when
  4664. ;; indentation should be preserved (through
  4665. ;; `org-src-preserve-indentation' or "-i" flag).
  4666. (should-not
  4667. (zerop
  4668. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4669. (let ((org-adapt-indentation t)
  4670. (org-src-preserve-indentation nil))
  4671. (org-demote))
  4672. (forward-line 2)
  4673. (org-get-indentation))))
  4674. (should
  4675. (zerop
  4676. (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
  4677. (let ((org-adapt-indentation t)
  4678. (org-src-preserve-indentation t))
  4679. (org-demote))
  4680. (forward-line 2)
  4681. (org-get-indentation))))
  4682. (should
  4683. (zerop
  4684. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4685. (let ((org-adapt-indentation t)
  4686. (org-src-preserve-indentation t))
  4687. (org-demote))
  4688. (forward-line 2)
  4689. (org-get-indentation))))
  4690. (should
  4691. (zerop
  4692. (org-test-with-temp-text
  4693. "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
  4694. (let ((org-adapt-indentation t)
  4695. (org-src-preserve-indentation nil))
  4696. (org-demote))
  4697. (forward-line 2)
  4698. (org-get-indentation)))))
  4699. (ert-deftest test-org/promote ()
  4700. "Test `org-promote' specifications."
  4701. ;; Return an error if headline is to be promoted to level 0, unless
  4702. ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
  4703. ;; headline becomes a comment.
  4704. (should-error
  4705. (org-test-with-temp-text "* H"
  4706. (let ((org-allow-promoting-top-level-subtree nil)) (org-promote))))
  4707. (should
  4708. (equal "# H"
  4709. (org-test-with-temp-text "* H"
  4710. (let ((org-allow-promoting-top-level-subtree t)) (org-promote))
  4711. (buffer-string))))
  4712. ;; Remove correct number of stars according to
  4713. ;; `org-odd-levels-only'.
  4714. (should
  4715. (= 2
  4716. (org-test-with-temp-text "*** H"
  4717. (let ((org-odd-levels-only nil)) (org-promote))
  4718. (org-current-level))))
  4719. (should
  4720. (= 1
  4721. (org-test-with-temp-text "*** H"
  4722. (let ((org-odd-levels-only t)) (org-promote))
  4723. (org-current-level))))
  4724. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4725. (should
  4726. (org-test-with-temp-text "** H :tag:"
  4727. (let ((org-tags-column 10)
  4728. (org-auto-align-tags t)
  4729. (org-odd-levels-only nil))
  4730. (org-promote))
  4731. (org-move-to-column 10)
  4732. (looking-at-p ":tag:$")))
  4733. (should-not
  4734. (org-test-with-temp-text "** H :tag:"
  4735. (let ((org-tags-column 10)
  4736. (org-auto-align-tags nil)
  4737. (org-odd-levels-only nil))
  4738. (org-promote))
  4739. (org-move-to-column 10)
  4740. (looking-at-p ":tag:$")))
  4741. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4742. ;; info and property drawers.
  4743. (should
  4744. (= 2
  4745. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4746. (let ((org-odd-levels-only nil)
  4747. (org-adapt-indentation t))
  4748. (org-promote))
  4749. (forward-line)
  4750. (org-get-indentation))))
  4751. (should
  4752. (= 2
  4753. (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4754. (let ((org-odd-levels-only nil)
  4755. (org-adapt-indentation t))
  4756. (org-promote))
  4757. (forward-line)
  4758. (org-get-indentation))))
  4759. (should-not
  4760. (= 2
  4761. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4762. (let ((org-odd-levels-only nil)
  4763. (org-adapt-indentation nil))
  4764. (org-promote))
  4765. (forward-line)
  4766. (org-get-indentation))))
  4767. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4768. ;; section accordingly. Ignore, however, footnote definitions and
  4769. ;; inlinetasks boundaries.
  4770. (should
  4771. (= 2
  4772. (org-test-with-temp-text "** H\n Paragraph"
  4773. (let ((org-odd-levels-only nil)
  4774. (org-adapt-indentation t))
  4775. (org-promote))
  4776. (forward-line)
  4777. (org-get-indentation))))
  4778. (should-not
  4779. (= 2
  4780. (org-test-with-temp-text "** H\n Paragraph"
  4781. (let ((org-odd-levels-only nil)
  4782. (org-adapt-indentation nil))
  4783. (org-promote))
  4784. (forward-line)
  4785. (org-get-indentation))))
  4786. (should
  4787. (= 2
  4788. (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
  4789. (let ((org-odd-levels-only nil)
  4790. (org-adapt-indentation t))
  4791. (org-promote))
  4792. (forward-line)
  4793. (org-get-indentation))))
  4794. (when (featurep 'org-inlinetask)
  4795. (should
  4796. (zerop
  4797. (let ((org-inlinetask-min-level 5)
  4798. (org-adapt-indentation t))
  4799. (org-test-with-temp-text "** H\n***** I\n***** END"
  4800. (org-promote)
  4801. (forward-line)
  4802. (org-get-indentation))))))
  4803. (when (featurep 'org-inlinetask)
  4804. (should
  4805. (= 2
  4806. (let ((org-inlinetask-min-level 5)
  4807. (org-adapt-indentation t))
  4808. (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
  4809. (org-promote)
  4810. (forward-line 2)
  4811. (org-get-indentation))))))
  4812. ;; Give up shifting if it would break document's structure
  4813. ;; otherwise.
  4814. (should
  4815. (= 3
  4816. (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
  4817. (let ((org-odd-levels-only nil)
  4818. (org-adapt-indentation t))
  4819. (org-promote))
  4820. (forward-line)
  4821. (org-get-indentation))))
  4822. (should
  4823. (= 3
  4824. (org-test-with-temp-text "** H\n Paragraph\n * list."
  4825. (let ((org-odd-levels-only nil)
  4826. (org-adapt-indentation t))
  4827. (org-promote))
  4828. (forward-line)
  4829. (org-get-indentation))))
  4830. ;; When `org-adapt-indentation' is non-nil, log drawers are
  4831. ;; adjusted.
  4832. (should
  4833. (equal
  4834. "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4835. (org-test-with-temp-text "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4836. (let ((org-odd-levels-only nil)
  4837. (org-adapt-indentation t))
  4838. (org-promote))
  4839. (buffer-string))))
  4840. (should
  4841. (equal
  4842. "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4843. (org-test-with-temp-text "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4844. (let ((org-odd-levels-only nil)
  4845. (org-adapt-indentation 'headline-data))
  4846. (org-promote))
  4847. (buffer-string))))
  4848. (should
  4849. (equal
  4850. "* H\n:LOGBOOK:\n- a\n:END:"
  4851. (org-test-with-temp-text "** H\n:LOGBOOK:\n- a\n:END:"
  4852. (let ((org-odd-levels-only nil)
  4853. (org-adapt-indentation t))
  4854. (org-promote))
  4855. (buffer-string))))
  4856. (should
  4857. (equal
  4858. "# H\n:LOGBOOK:\n- a\n:END:"
  4859. (org-test-with-temp-text "* H\n:LOGBOOK:\n- a\n:END:"
  4860. (let ((org-odd-levels-only nil)
  4861. (org-allow-promoting-top-level-subtree t)
  4862. (org-adapt-indentation t))
  4863. (org-promote))
  4864. (buffer-string))))
  4865. ;; Ignore contents of source blocks or example blocks when
  4866. ;; indentation should be preserved (through
  4867. ;; `org-src-preserve-indentation' or "-i" flag).
  4868. (should-not
  4869. (zerop
  4870. (org-test-with-temp-text
  4871. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  4872. (let ((org-adapt-indentation t)
  4873. (org-src-preserve-indentation nil)
  4874. (org-odd-levels-only nil))
  4875. (org-promote))
  4876. (forward-line)
  4877. (org-get-indentation))))
  4878. (should
  4879. (zerop
  4880. (org-test-with-temp-text
  4881. "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
  4882. (let ((org-adapt-indentation t)
  4883. (org-src-preserve-indentation t)
  4884. (org-odd-levels-only nil))
  4885. (org-promote))
  4886. (forward-line)
  4887. (org-get-indentation))))
  4888. (should
  4889. (zerop
  4890. (org-test-with-temp-text
  4891. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  4892. (let ((org-adapt-indentation t)
  4893. (org-src-preserve-indentation t)
  4894. (org-odd-levels-only nil))
  4895. (org-promote))
  4896. (forward-line)
  4897. (org-get-indentation))))
  4898. (should
  4899. (zerop
  4900. (org-test-with-temp-text
  4901. "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
  4902. (let ((org-adapt-indentation t)
  4903. (org-src-preserve-indentation nil)
  4904. (org-odd-levels-only nil))
  4905. (org-promote))
  4906. (forward-line)
  4907. (org-get-indentation)))))
  4908. (ert-deftest test-org/org-get-valid-level ()
  4909. "Test function `org-get-valid-level' specifications."
  4910. (let ((org-odd-levels-only nil))
  4911. (should (equal 1 (org-get-valid-level 0 0)))
  4912. (should (equal 1 (org-get-valid-level 0 1)))
  4913. (should (equal 2 (org-get-valid-level 0 2)))
  4914. (should (equal 3 (org-get-valid-level 0 3)))
  4915. (should (equal 1 (org-get-valid-level 1 0)))
  4916. (should (equal 2 (org-get-valid-level 1 1)))
  4917. (should (equal 23 (org-get-valid-level 1 22)))
  4918. (should (equal 1 (org-get-valid-level 1 -1)))
  4919. (should (equal 1 (org-get-valid-level 2 -1))))
  4920. (let ((org-odd-levels-only t))
  4921. (should (equal 1 (org-get-valid-level 0 0)))
  4922. (should (equal 1 (org-get-valid-level 0 1)))
  4923. (should (equal 3 (org-get-valid-level 0 2)))
  4924. (should (equal 5 (org-get-valid-level 0 3)))
  4925. (should (equal 1 (org-get-valid-level 1 0)))
  4926. (should (equal 3 (org-get-valid-level 1 1)))
  4927. (should (equal 3 (org-get-valid-level 2 1)))
  4928. (should (equal 5 (org-get-valid-level 3 1)))
  4929. (should (equal 5 (org-get-valid-level 4 1)))
  4930. (should (equal 43 (org-get-valid-level 1 21)))
  4931. (should (equal 1 (org-get-valid-level 1 -1)))
  4932. (should (equal 1 (org-get-valid-level 2 -1)))
  4933. (should (equal 1 (org-get-valid-level 3 -1)))
  4934. (should (equal 3 (org-get-valid-level 4 -1)))
  4935. (should (equal 3 (org-get-valid-level 5 -1)))))
  4936. ;;; Planning
  4937. (ert-deftest test-org/at-planning-p ()
  4938. "Test `org-at-planning-p' specifications."
  4939. ;; Regular test.
  4940. (should
  4941. (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
  4942. (org-at-planning-p)))
  4943. (should-not
  4944. (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
  4945. (org-at-planning-p)))
  4946. ;; Correctly find planning attached to inlinetasks.
  4947. (when (featurep 'org-inlinetask)
  4948. (should
  4949. (org-test-with-temp-text
  4950. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
  4951. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4952. (should-not
  4953. (org-test-with-temp-text
  4954. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  4955. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4956. (should-not
  4957. (org-test-with-temp-text
  4958. "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  4959. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4960. (should-not
  4961. (org-test-with-temp-text
  4962. "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
  4963. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
  4964. (ert-deftest test-org/add-planning-info ()
  4965. "Test `org-add-planning-info'."
  4966. ;; Create deadline when `org-adapt-indentation' is non-nil.
  4967. (should
  4968. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4969. (org-test-with-temp-text "* H\nParagraph<point>"
  4970. (let ((org-adapt-indentation t))
  4971. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4972. (replace-regexp-in-string
  4973. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4974. nil nil 1))))
  4975. ;; Create deadline when `org-adapt-indentation' is nil.
  4976. (should
  4977. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  4978. (org-test-with-temp-text "* H\nParagraph<point>"
  4979. (let ((org-adapt-indentation nil))
  4980. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4981. (replace-regexp-in-string
  4982. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4983. nil nil 1))))
  4984. ;; Update deadline when `org-adapt-indentation' is non-nil.
  4985. (should
  4986. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4987. (org-test-with-temp-text "\
  4988. * H
  4989. DEADLINE: <2015-06-24 Wed>
  4990. Paragraph<point>"
  4991. (let ((org-adapt-indentation t))
  4992. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4993. (replace-regexp-in-string
  4994. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4995. nil nil 1))))
  4996. ;; Update deadline when `org-adapt-indentation' is nil.
  4997. (should
  4998. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  4999. (org-test-with-temp-text "\
  5000. * H
  5001. DEADLINE: <2015-06-24 Wed>
  5002. Paragraph<point>"
  5003. (let ((org-adapt-indentation nil))
  5004. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5005. (replace-regexp-in-string
  5006. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5007. nil nil 1))))
  5008. ;; Schedule when `org-adapt-indentation' is non-nil.
  5009. (should
  5010. (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
  5011. (org-test-with-temp-text "* H\nParagraph<point>"
  5012. (let ((org-adapt-indentation t))
  5013. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  5014. (replace-regexp-in-string
  5015. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5016. nil nil 1))))
  5017. ;; Schedule when `org-adapt-indentation' is nil.
  5018. (should
  5019. (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
  5020. (org-test-with-temp-text "* H\nParagraph<point>"
  5021. (let ((org-adapt-indentation nil))
  5022. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  5023. (replace-regexp-in-string
  5024. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5025. nil nil 1))))
  5026. ;; Add deadline when scheduled.
  5027. (should
  5028. (equal "\
  5029. * H
  5030. DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
  5031. Paragraph"
  5032. (org-test-with-temp-text "\
  5033. * H
  5034. SCHEDULED: <2015-06-24 Wed>
  5035. Paragraph<point>"
  5036. (let ((org-adapt-indentation t))
  5037. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5038. (replace-regexp-in-string
  5039. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5040. nil nil 1))))
  5041. ;; Remove middle entry.
  5042. (should
  5043. (equal "\
  5044. * H
  5045. CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
  5046. Paragraph"
  5047. (org-test-with-temp-text "\
  5048. * H
  5049. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  5050. Paragraph<point>"
  5051. (let ((org-adapt-indentation t))
  5052. (org-add-planning-info nil nil 'deadline))
  5053. (replace-regexp-in-string
  5054. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  5055. nil nil 1))))
  5056. ;; Remove last entry and then middle entry (order should not
  5057. ;; matter).
  5058. (should
  5059. (equal "\
  5060. * H
  5061. CLOSED: [2015-06-24]
  5062. Paragraph"
  5063. (org-test-with-temp-text "\
  5064. * H
  5065. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  5066. Paragraph<point>"
  5067. (let ((org-adapt-indentation t))
  5068. (org-add-planning-info nil nil 'scheduled 'deadline))
  5069. (replace-regexp-in-string
  5070. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  5071. nil nil 1))))
  5072. ;; Remove closed when `org-adapt-indentation' is non-nil.
  5073. (should
  5074. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5075. (org-test-with-temp-text "\
  5076. * H
  5077. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  5078. Paragraph<point>"
  5079. (let ((org-adapt-indentation t))
  5080. (org-add-planning-info nil nil 'closed))
  5081. (replace-regexp-in-string
  5082. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5083. nil nil 1))))
  5084. (should
  5085. (equal "* H\n Paragraph"
  5086. (org-test-with-temp-text "\
  5087. * H
  5088. CLOSED: [2015-06-25 Thu]
  5089. Paragraph<point>"
  5090. (let ((org-adapt-indentation t))
  5091. (org-add-planning-info nil nil 'closed))
  5092. (replace-regexp-in-string
  5093. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5094. nil nil 1))))
  5095. ;; Remove closed when `org-adapt-indentation' is nil.
  5096. (should
  5097. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  5098. (org-test-with-temp-text "\
  5099. * H
  5100. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  5101. Paragraph<point>"
  5102. (let ((org-adapt-indentation nil))
  5103. (org-add-planning-info nil nil 'closed))
  5104. (replace-regexp-in-string
  5105. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5106. nil nil 1))))
  5107. (should
  5108. (equal "* H\nParagraph"
  5109. (org-test-with-temp-text "\
  5110. * H
  5111. CLOSED: [2015-06-25 Thu]
  5112. Paragraph<point>"
  5113. (let ((org-adapt-indentation nil))
  5114. (org-add-planning-info nil nil 'closed))
  5115. (replace-regexp-in-string
  5116. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5117. nil nil 1))))
  5118. ;; Remove closed entry and delete empty line.
  5119. (should
  5120. (equal "\
  5121. * H
  5122. Paragraph"
  5123. (org-test-with-temp-text "\
  5124. * H
  5125. CLOSED: [2015-06-24 Wed]
  5126. Paragraph<point>"
  5127. (let ((org-adapt-indentation t))
  5128. (org-add-planning-info nil nil 'closed))
  5129. (replace-regexp-in-string
  5130. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5131. nil nil 1))))
  5132. ;; Remove one entry and update another.
  5133. (should
  5134. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5135. (org-test-with-temp-text "\
  5136. * H
  5137. SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
  5138. Paragraph<point>"
  5139. (let ((org-adapt-indentation t))
  5140. (org-add-planning-info 'deadline "<2015-06-25 Thu>" 'scheduled))
  5141. (replace-regexp-in-string
  5142. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5143. nil nil 1)))))
  5144. (ert-deftest test-org/deadline ()
  5145. "Test `org-deadline' specifications."
  5146. ;; Insert a new value or replace existing one.
  5147. (should
  5148. (equal "* H\nDEADLINE: <2012-03-29>"
  5149. (org-test-with-temp-text "* H"
  5150. (let ((org-adapt-indentation nil)
  5151. (org-last-inserted-timestamp nil))
  5152. (org-deadline nil "<2012-03-29 Tue>"))
  5153. (replace-regexp-in-string
  5154. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5155. nil nil 1))))
  5156. (should
  5157. (equal "* H\nDEADLINE: <2014-03-04>"
  5158. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5159. (let ((org-adapt-indentation nil)
  5160. (org-last-inserted-timestamp nil))
  5161. (org-deadline nil "<2014-03-04 Thu>"))
  5162. (replace-regexp-in-string
  5163. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5164. nil nil 1))))
  5165. ;; Accept delta time, e.g., "+2d".
  5166. (should
  5167. (equal "* H\nDEADLINE: <2015-03-04>"
  5168. (org-test-at-time "2014-03-04"
  5169. (org-test-with-temp-text "* H"
  5170. (let ((org-adapt-indentation nil)
  5171. (org-last-inserted-timestamp nil))
  5172. (org-deadline nil "+1y"))
  5173. (replace-regexp-in-string
  5174. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5175. ;; Preserve repeater.
  5176. (should
  5177. (equal "* H\nDEADLINE: <2012-03-29 +2y>"
  5178. (org-test-with-temp-text "* H"
  5179. (let ((org-adapt-indentation nil)
  5180. (org-last-inserted-timestamp nil))
  5181. (org-deadline nil "<2012-03-29 Tue +2y>"))
  5182. (replace-regexp-in-string
  5183. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5184. ;; Remove CLOSED keyword, if any.
  5185. (should
  5186. (equal "* H\nDEADLINE: <2012-03-29>"
  5187. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  5188. (let ((org-adapt-indentation nil)
  5189. (org-last-inserted-timestamp nil))
  5190. (org-deadline nil "<2012-03-29 Tue>"))
  5191. (replace-regexp-in-string
  5192. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5193. ;; With C-u argument, remove DEADLINE keyword.
  5194. (should
  5195. (equal "* H\n"
  5196. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5197. (let ((org-adapt-indentation nil)
  5198. (org-last-inserted-timestamp nil))
  5199. (org-deadline '(4)))
  5200. (buffer-string))))
  5201. (should
  5202. (equal "* H"
  5203. (org-test-with-temp-text "* H"
  5204. (let ((org-adapt-indentation nil)
  5205. (org-last-inserted-timestamp nil))
  5206. (org-deadline '(4)))
  5207. (buffer-string))))
  5208. ;; With C-u C-u argument, prompt for a delay cookie.
  5209. (should
  5210. (equal "* H\nDEADLINE: <2012-03-29 -705d>"
  5211. (cl-letf (((symbol-function 'org-read-date)
  5212. (lambda (&rest args)
  5213. (apply #'encode-time
  5214. (org-parse-time-string "2014-03-04")))))
  5215. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5216. (let ((org-adapt-indentation nil)
  5217. (org-last-inserted-timestamp nil))
  5218. (org-deadline '(16)))
  5219. (buffer-string)))))
  5220. (should-error
  5221. (cl-letf (((symbol-function 'org-read-date)
  5222. (lambda (&rest args)
  5223. (apply #'encode-time
  5224. (org-parse-time-string "2014-03-04")))))
  5225. (org-test-with-temp-text "* H"
  5226. (let ((org-adapt-indentation nil)
  5227. (org-last-inserted-timestamp nil))
  5228. (org-deadline '(16)))
  5229. (buffer-string))))
  5230. ;; When a region is active and
  5231. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5232. ;; same value in all headlines in region.
  5233. (should
  5234. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5235. (org-test-with-temp-text "* H1\n* H2"
  5236. (let ((org-adapt-indentation nil)
  5237. (org-last-inserted-timestamp nil)
  5238. (org-loop-over-headlines-in-active-region t))
  5239. (transient-mark-mode 1)
  5240. (push-mark (point) t t)
  5241. (goto-char (point-max))
  5242. (org-deadline nil "2012-03-29"))
  5243. (replace-regexp-in-string
  5244. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5245. (should-not
  5246. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5247. (org-test-with-temp-text "* H1\n* H2"
  5248. (let ((org-adapt-indentation nil)
  5249. (org-last-inserted-timestamp nil)
  5250. (org-loop-over-headlines-in-active-region nil))
  5251. (transient-mark-mode 1)
  5252. (push-mark (point) t t)
  5253. (goto-char (point-max))
  5254. (org-deadline nil "2012-03-29"))
  5255. (replace-regexp-in-string
  5256. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5257. (ert-deftest test-org/schedule ()
  5258. "Test `org-schedule' specifications."
  5259. ;; Insert a new value or replace existing one.
  5260. (should
  5261. (equal "* H\nSCHEDULED: <2012-03-29>"
  5262. (org-test-with-temp-text "* H"
  5263. (let ((org-adapt-indentation nil)
  5264. (org-last-inserted-timestamp nil))
  5265. (org-schedule nil "<2012-03-29 Tue>"))
  5266. (replace-regexp-in-string
  5267. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5268. nil nil 1))))
  5269. (should
  5270. (equal "* H\nSCHEDULED: <2014-03-04>"
  5271. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5272. (let ((org-adapt-indentation nil)
  5273. (org-last-inserted-timestamp nil))
  5274. (org-schedule nil "<2014-03-04 Thu>"))
  5275. (replace-regexp-in-string
  5276. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5277. nil nil 1))))
  5278. ;; Accept delta time, e.g., "+2d".
  5279. (should
  5280. (equal "* H\nSCHEDULED: <2015-03-04>"
  5281. (org-test-at-time "2014-03-04"
  5282. (org-test-with-temp-text "* H"
  5283. (let ((org-adapt-indentation nil)
  5284. (org-last-inserted-timestamp nil))
  5285. (org-schedule nil "+1y"))
  5286. (replace-regexp-in-string
  5287. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5288. ;; Preserve repeater.
  5289. (should
  5290. (equal "* H\nSCHEDULED: <2012-03-29 +2y>"
  5291. (org-test-with-temp-text "* H"
  5292. (let ((org-adapt-indentation nil)
  5293. (org-last-inserted-timestamp nil))
  5294. (org-schedule nil "<2012-03-29 Tue +2y>"))
  5295. (replace-regexp-in-string
  5296. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5297. ;; Remove CLOSED keyword, if any.
  5298. (should
  5299. (equal "* H\nSCHEDULED: <2012-03-29>"
  5300. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  5301. (let ((org-adapt-indentation nil)
  5302. (org-last-inserted-timestamp nil))
  5303. (org-schedule nil "<2012-03-29 Tue>"))
  5304. (replace-regexp-in-string
  5305. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5306. ;; With C-u argument, remove SCHEDULED keyword.
  5307. (should
  5308. (equal "* H\n"
  5309. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5310. (let ((org-adapt-indentation nil)
  5311. (org-last-inserted-timestamp nil))
  5312. (org-schedule '(4)))
  5313. (buffer-string))))
  5314. (should
  5315. (equal "* H"
  5316. (org-test-with-temp-text "* H"
  5317. (let ((org-adapt-indentation nil)
  5318. (org-last-inserted-timestamp nil))
  5319. (org-schedule '(4)))
  5320. (buffer-string))))
  5321. ;; With C-u C-u argument, prompt for a delay cookie.
  5322. (should
  5323. (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
  5324. (cl-letf (((symbol-function 'org-read-date)
  5325. (lambda (&rest args)
  5326. (apply #'encode-time
  5327. (org-parse-time-string "2014-03-04")))))
  5328. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5329. (let ((org-adapt-indentation nil)
  5330. (org-last-inserted-timestamp nil))
  5331. (org-schedule '(16)))
  5332. (buffer-string)))))
  5333. (should-error
  5334. (cl-letf (((symbol-function 'org-read-date)
  5335. (lambda (&rest args)
  5336. (apply #'encode-time
  5337. (org-parse-time-string "2014-03-04")))))
  5338. (org-test-with-temp-text "* H"
  5339. (let ((org-adapt-indentation nil)
  5340. (org-last-inserted-timestamp nil))
  5341. (org-schedule '(16)))
  5342. (buffer-string))))
  5343. ;; When a region is active and
  5344. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5345. ;; same value in all headlines in region.
  5346. (should
  5347. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5348. (org-test-with-temp-text "* H1\n* H2"
  5349. (let ((org-adapt-indentation nil)
  5350. (org-last-inserted-timestamp nil)
  5351. (org-loop-over-headlines-in-active-region t))
  5352. (transient-mark-mode 1)
  5353. (push-mark (point) t t)
  5354. (goto-char (point-max))
  5355. (org-schedule nil "2012-03-29"))
  5356. (replace-regexp-in-string
  5357. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5358. (should-not
  5359. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5360. (org-test-with-temp-text "* H1\n* H2"
  5361. (let ((org-adapt-indentation nil)
  5362. (org-last-inserted-timestamp nil)
  5363. (org-loop-over-headlines-in-active-region nil))
  5364. (transient-mark-mode 1)
  5365. (push-mark (point) t t)
  5366. (goto-char (point-max))
  5367. (org-schedule nil "2012-03-29"))
  5368. (replace-regexp-in-string
  5369. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5370. (should
  5371. ;; check if a repeater survives re-scheduling.
  5372. (string-match-p
  5373. "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
  5374. (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
  5375. (let ((org-adapt-indentation nil)
  5376. (org-last-inserted-timestamp nil))
  5377. (org-schedule nil "2017-02-01"))
  5378. (buffer-string)))))
  5379. ;;; Property API
  5380. (ert-deftest test-org/buffer-property-keys ()
  5381. "Test `org-buffer-property-keys' specifications."
  5382. ;; Retrieve properties across siblings.
  5383. (should
  5384. (equal '("A" "B")
  5385. (org-test-with-temp-text "
  5386. * H1
  5387. :PROPERTIES:
  5388. :A: 1
  5389. :END:
  5390. * H2
  5391. :PROPERTIES:
  5392. :B: 1
  5393. :END:"
  5394. (org-buffer-property-keys))))
  5395. ;; Retrieve properties across children.
  5396. (should
  5397. (equal '("A" "B")
  5398. (org-test-with-temp-text "
  5399. * H1
  5400. :PROPERTIES:
  5401. :A: 1
  5402. :END:
  5403. ** H2
  5404. :PROPERTIES:
  5405. :B: 1
  5406. :END:"
  5407. (org-buffer-property-keys))))
  5408. ;; Retrieve muliple properties in the same drawer.
  5409. (should
  5410. (equal '("A" "B")
  5411. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5412. (org-buffer-property-keys))))
  5413. ;; Ignore extension symbol in property name.
  5414. (should
  5415. (equal '("A")
  5416. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5417. (org-buffer-property-keys))))
  5418. ;; Add bare property if xxx_ALL property is there
  5419. (should
  5420. (equal '("A" "B" "B_ALL")
  5421. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B_ALL: foo bar\n:END:"
  5422. (org-buffer-property-keys))))
  5423. ;; Add bare property if xxx_ALL property is there - check dupes
  5424. (should
  5425. (equal '("A" "B" "B_ALL")
  5426. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:B_ALL: foo bar\n:END:"
  5427. (org-buffer-property-keys))))
  5428. ;; Retrieve properties from #+PROPERTY keyword lines
  5429. (should
  5430. (equal '("A" "C")
  5431. (org-test-with-temp-text "#+PROPERTY: C foo\n* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5432. (org-buffer-property-keys))))
  5433. ;; Retrieve properties from #+PROPERTY keyword lines - make sure an _ALL property also
  5434. ;; adds the bare property
  5435. (should
  5436. (equal '("A" "C" "C_ALL")
  5437. (org-test-with-temp-text "#+PROPERTY: C_ALL foo bar\n* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5438. (org-buffer-property-keys))))
  5439. ;; With non-nil COLUMNS, extract property names from columns.
  5440. (should
  5441. (equal '("A" "B")
  5442. (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
  5443. (org-buffer-property-keys nil nil t))))
  5444. (should
  5445. (equal '("A" "B" "COLUMNS")
  5446. (org-test-with-temp-text
  5447. "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
  5448. (org-buffer-property-keys nil nil t))))
  5449. ;; In COLUMNS, ignore title and summary-type.
  5450. (should
  5451. (equal '("A")
  5452. (org-test-with-temp-text "#+COLUMNS: %A(Foo)"
  5453. (org-buffer-property-keys nil nil t))))
  5454. (should
  5455. (equal '("A")
  5456. (org-test-with-temp-text "#+COLUMNS: %A{Foo}"
  5457. (org-buffer-property-keys nil nil t))))
  5458. (should
  5459. (equal '("A")
  5460. (org-test-with-temp-text "#+COLUMNS: %A(Foo){Bar}"
  5461. (org-buffer-property-keys nil nil t)))))
  5462. (ert-deftest test-org/property-values ()
  5463. "Test `org-property-values' specifications."
  5464. ;; Regular test.
  5465. (should
  5466. (equal '("2" "1")
  5467. (org-test-with-temp-text
  5468. "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
  5469. (org-property-values "A"))))
  5470. ;; Ignore empty values.
  5471. (should-not
  5472. (org-test-with-temp-text
  5473. "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
  5474. (org-property-values "A")))
  5475. ;; Take into consideration extended values.
  5476. (should
  5477. (equal '("1 2")
  5478. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5479. (org-property-values "A")))))
  5480. (ert-deftest test-org/set-property ()
  5481. "Test `org-set-property' specifications."
  5482. (should
  5483. (equal
  5484. ":PROPERTIES:\n:TEST: t\n:END:\n"
  5485. (org-test-with-temp-text ""
  5486. (let ((org-property-format "%s %s"))
  5487. (org-set-property "TEST" "t"))
  5488. (buffer-string))))
  5489. (should
  5490. (equal
  5491. "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5492. (org-test-with-temp-text "* H"
  5493. (let ((org-adapt-indentation nil)
  5494. (org-property-format "%s %s"))
  5495. (org-set-property "TEST" "t"))
  5496. (buffer-string)))))
  5497. (ert-deftest test-org/delete-property ()
  5498. "Test `org-delete-property' specifications."
  5499. (should
  5500. (equal
  5501. ""
  5502. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5503. (org-delete-property "TEST")
  5504. (buffer-string))))
  5505. (should
  5506. (equal
  5507. ":PROPERTIES:\n:TEST1: t\n:END:\n"
  5508. (org-test-with-temp-text ":PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5509. (org-delete-property "TEST2")
  5510. (buffer-string))))
  5511. (should
  5512. (equal
  5513. "* H\n"
  5514. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5515. (org-delete-property "TEST")
  5516. (buffer-string))))
  5517. (should
  5518. (equal
  5519. "* H\n:PROPERTIES:\n:TEST1: t\n:END:\n"
  5520. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5521. (org-delete-property "TEST2")
  5522. (buffer-string)))))
  5523. (ert-deftest test-org/delete-property-globally ()
  5524. "Test `org-delete-property-global' specifications."
  5525. (should
  5526. (equal
  5527. ""
  5528. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5529. (org-delete-property-globally "TEST")
  5530. (buffer-string))))
  5531. (should
  5532. (equal
  5533. "* H\n"
  5534. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n* H\n:PROPERTIES:\n:TEST: nil\n:END:"
  5535. (org-delete-property-globally "TEST")
  5536. (buffer-string)))))
  5537. (ert-deftest test-org/find-property ()
  5538. "Test `org-find-property' specifications."
  5539. ;; Regular test.
  5540. (should
  5541. (= 1
  5542. (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
  5543. (org-find-property "prop"))))
  5544. ;; Find properties in top-level property drawer.
  5545. (should
  5546. (= 1
  5547. (org-test-with-temp-text ":PROPERTIES:\n:PROP: value\n:END:"
  5548. (org-find-property "prop"))))
  5549. ;; Ignore false positives.
  5550. (should
  5551. (= 27
  5552. (org-test-with-temp-text
  5553. "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
  5554. (org-find-property "A"))))
  5555. ;; Return first entry found in buffer.
  5556. (should
  5557. (= 1
  5558. (org-test-with-temp-text
  5559. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5560. (org-find-property "A"))))
  5561. ;; Only search visible part of the buffer.
  5562. (should
  5563. (= 31
  5564. (org-test-with-temp-text
  5565. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5566. (org-narrow-to-subtree)
  5567. (org-find-property "A"))))
  5568. ;; With optional argument, only find entries with a specific value.
  5569. (should-not
  5570. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5571. (org-find-property "A" "2")))
  5572. (should
  5573. (= 31
  5574. (org-test-with-temp-text
  5575. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
  5576. (org-find-property "A" "2"))))
  5577. ;; Use "nil" for explicit nil values.
  5578. (should
  5579. (= 31
  5580. (org-test-with-temp-text
  5581. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
  5582. (org-find-property "A" "nil")))))
  5583. (ert-deftest test-org/entry-delete ()
  5584. "Test `org-entry-delete' specifications."
  5585. ;; Regular test.
  5586. (should
  5587. (string-match
  5588. " *:PROPERTIES:\n *:B: +2\n *:END:"
  5589. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5590. (org-entry-delete (point) "A")
  5591. (buffer-string))))
  5592. ;; Also remove accumulated properties.
  5593. (should-not
  5594. (string-match
  5595. ":A"
  5596. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
  5597. (org-entry-delete (point) "A")
  5598. (buffer-string))))
  5599. ;; When last property is removed, remove the property drawer.
  5600. (should-not
  5601. (string-match
  5602. ":PROPERTIES:"
  5603. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
  5604. (org-entry-delete (point) "A")
  5605. (buffer-string))))
  5606. ;; Return a non-nil value when some property was removed.
  5607. (should
  5608. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5609. (org-entry-delete (point) "A")))
  5610. (should-not
  5611. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5612. (org-entry-delete (point) "C")))
  5613. ;; Special properties cannot be located in a drawer. Allow to
  5614. ;; remove them anyway, in case of user error.
  5615. (should
  5616. (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
  5617. (org-entry-delete (point) "SCHEDULED"))))
  5618. (ert-deftest test-org/entry-get ()
  5619. "Test `org-entry-get' specifications."
  5620. ;; Regular test.
  5621. (should
  5622. (equal "1"
  5623. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:"
  5624. (org-entry-get (point) "A"))))
  5625. (should
  5626. (equal "1"
  5627. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5628. (org-entry-get (point) "A"))))
  5629. ;; Ignore case.
  5630. (should
  5631. (equal "1"
  5632. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5633. (org-entry-get (point) "a"))))
  5634. ;; Handle extended values, both before and after base value.
  5635. (should
  5636. (equal "1 2 3"
  5637. (org-test-with-temp-text
  5638. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5639. (org-entry-get (point) "A"))))
  5640. ;; Empty values are returned as the empty string.
  5641. (should
  5642. (equal ""
  5643. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
  5644. (org-entry-get (point) "A"))))
  5645. ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
  5646. ;; otherwise, return nil.
  5647. (should-not
  5648. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5649. (org-entry-get (point) "A")))
  5650. (should
  5651. (equal "nil"
  5652. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5653. (org-entry-get (point) "A" nil t))))
  5654. ;; Return nil when no property is found, independently on the
  5655. ;; LITERAL-NIL argument.
  5656. (should-not
  5657. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5658. (org-entry-get (point) "B")))
  5659. (should-not
  5660. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5661. (org-entry-get (point) "B" nil t)))
  5662. ;; Handle inheritance, when allowed. Include extended values and
  5663. ;; possibly global values.
  5664. (should
  5665. (equal
  5666. "1"
  5667. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:\n* H"
  5668. (org-entry-get (point-max) "A" t))))
  5669. (should
  5670. (equal
  5671. "1"
  5672. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5673. (org-entry-get (point-max) "A" t))))
  5674. (should
  5675. (equal
  5676. "1"
  5677. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5678. (let ((org-use-property-inheritance t))
  5679. (org-entry-get (point-max) "A" 'selective)))))
  5680. (should-not
  5681. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5682. (let ((org-use-property-inheritance nil))
  5683. (org-entry-get (point-max) "A" 'selective))))
  5684. (should
  5685. (equal
  5686. "1 2"
  5687. (org-test-with-temp-text
  5688. ":PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5689. (org-entry-get (point-max) "A" t))))
  5690. (should
  5691. (equal
  5692. "1 2"
  5693. (org-test-with-temp-text
  5694. "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5695. (org-entry-get (point-max) "A" t))))
  5696. (should
  5697. (equal
  5698. "1 2"
  5699. (org-test-with-temp-text
  5700. ":PROPERTIES:\n:A: 1\n:END:\n* H1\n* H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5701. (org-entry-get (point-max) "A" t))))
  5702. (should
  5703. (equal
  5704. "1 2"
  5705. (org-test-with-temp-text
  5706. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2.1\n** H2.2\n:PROPERTIES:\n:A+: 2\n:END:"
  5707. (org-entry-get (point-max) "A" t))))
  5708. (should
  5709. (equal "1"
  5710. (org-test-with-temp-text
  5711. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
  5712. (org-mode-restart)
  5713. (org-entry-get (point-max) "A" t))))
  5714. (should
  5715. (equal "0 1"
  5716. (org-test-with-temp-text
  5717. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
  5718. (org-mode-restart)
  5719. (org-entry-get (point-max) "A" t))))
  5720. ;; document level property-drawer has precedance over
  5721. ;; global-property by PROPERTY-keyword.
  5722. (should
  5723. (equal "0 2"
  5724. (org-test-with-temp-text
  5725. ":PROPERTIES:\n:A: 0\n:END:\n#+PROPERTY: A 1\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5726. (org-mode-restart)
  5727. (org-entry-get (point-max) "A" t)))))
  5728. (ert-deftest test-org/entry-properties ()
  5729. "Test `org-entry-properties' specifications."
  5730. ;; Get "ITEM" property.
  5731. (should
  5732. (equal "H"
  5733. (org-test-with-temp-text "* TODO H"
  5734. (cdr (assoc "ITEM" (org-entry-properties nil "ITEM"))))))
  5735. (should
  5736. (equal "H"
  5737. (org-test-with-temp-text "* TODO H"
  5738. (cdr (assoc "ITEM" (org-entry-properties))))))
  5739. ;; Get "TODO" property. TODO keywords are case sensitive.
  5740. (should
  5741. (equal "TODO"
  5742. (org-test-with-temp-text "* TODO H"
  5743. (cdr (assoc "TODO" (org-entry-properties nil "TODO"))))))
  5744. (should
  5745. (equal "TODO"
  5746. (org-test-with-temp-text "* TODO H"
  5747. (cdr (assoc "TODO" (org-entry-properties))))))
  5748. (should-not
  5749. (org-test-with-temp-text "* H"
  5750. (assoc "TODO" (org-entry-properties nil "TODO"))))
  5751. (should-not
  5752. (org-test-with-temp-text "* todo H"
  5753. (assoc "TODO" (org-entry-properties nil "TODO"))))
  5754. ;; Get "PRIORITY" property.
  5755. (should
  5756. (equal "A"
  5757. (org-test-with-temp-text "* [#A] H"
  5758. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  5759. (should
  5760. (equal "A"
  5761. (org-test-with-temp-text "* [#A] H"
  5762. (cdr (assoc "PRIORITY" (org-entry-properties))))))
  5763. (should
  5764. (equal (char-to-string org-priority-default)
  5765. (org-test-with-temp-text "* H"
  5766. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  5767. ;; Get "FILE" property.
  5768. (should
  5769. (org-test-with-temp-text-in-file "* H\nParagraph"
  5770. (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil "FILE")))
  5771. (buffer-file-name))))
  5772. (should
  5773. (org-test-with-temp-text-in-file "* H\nParagraph"
  5774. (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
  5775. (buffer-file-name))))
  5776. (should-not
  5777. (org-test-with-temp-text "* H\nParagraph"
  5778. (cdr (assoc "FILE" (org-entry-properties nil "FILE")))))
  5779. ;; Get "TAGS" property.
  5780. (should
  5781. (equal ":tag1:tag2:"
  5782. (org-test-with-temp-text "* H :tag1:tag2:"
  5783. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS"))))))
  5784. (should
  5785. (equal ":tag1:tag2:"
  5786. (org-test-with-temp-text "* H :tag1:tag2:"
  5787. (cdr (assoc "TAGS" (org-entry-properties))))))
  5788. (should-not
  5789. (org-test-with-temp-text "* H"
  5790. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS")))))
  5791. ;; Get "ALLTAGS" property.
  5792. (should
  5793. (equal ":tag1:tag2:"
  5794. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  5795. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS"))))))
  5796. (should
  5797. (equal ":tag1:tag2:"
  5798. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  5799. (cdr (assoc "ALLTAGS" (org-entry-properties))))))
  5800. (should-not
  5801. (org-test-with-temp-text "* H"
  5802. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS")))))
  5803. ;; Get "BLOCKED" property.
  5804. (should
  5805. (equal "t"
  5806. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  5807. (let ((org-enforce-todo-dependencies t)
  5808. (org-blocker-hook
  5809. '(org-block-todo-from-children-or-siblings-or-parent)))
  5810. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  5811. (should
  5812. (equal ""
  5813. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  5814. (let ((org-enforce-todo-dependencies t)
  5815. (org-blocker-hook
  5816. '(org-block-todo-from-children-or-siblings-or-parent)))
  5817. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  5818. ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
  5819. (should
  5820. (equal
  5821. "[2012-03-29 thu.]"
  5822. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  5823. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED"))))))
  5824. (should
  5825. (equal
  5826. "[2012-03-29 thu.]"
  5827. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  5828. (cdr (assoc "CLOSED" (org-entry-properties))))))
  5829. (should-not
  5830. (org-test-with-temp-text "* H"
  5831. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED")))))
  5832. (should
  5833. (equal
  5834. "<2014-03-04 tue.>"
  5835. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5836. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE"))))))
  5837. (should
  5838. (equal
  5839. "<2014-03-04 tue.>"
  5840. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5841. (cdr (assoc "DEADLINE" (org-entry-properties))))))
  5842. (should-not
  5843. (org-test-with-temp-text "* H"
  5844. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE")))))
  5845. (should
  5846. (equal
  5847. "<2014-03-04 tue.>"
  5848. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5849. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED"))))))
  5850. (should
  5851. (equal
  5852. "<2014-03-04 tue.>"
  5853. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5854. (cdr (assoc "SCHEDULED" (org-entry-properties))))))
  5855. (should-not
  5856. (org-test-with-temp-text "* H"
  5857. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED")))))
  5858. ;; Get "CATEGORY"
  5859. (should
  5860. (equal "cat"
  5861. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  5862. (cdr (assoc "CATEGORY" (org-entry-properties))))))
  5863. (should
  5864. (equal "cat"
  5865. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  5866. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5867. (should
  5868. (equal "cat"
  5869. (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
  5870. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5871. (should
  5872. (equal "cat2"
  5873. (org-test-with-temp-text
  5874. (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  5875. "\n"
  5876. "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
  5877. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5878. ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
  5879. (should
  5880. (equal "<2012-03-29 thu.>"
  5881. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
  5882. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  5883. (should
  5884. (equal "[2012-03-29 thu.]"
  5885. (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
  5886. (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
  5887. (should
  5888. (equal "<2012-03-29 thu.>"
  5889. (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
  5890. (cdr (assoc "TIMESTAMP" (org-entry-properties nil "TIMESTAMP"))))))
  5891. (should
  5892. (equal "[2014-03-04 tue.]"
  5893. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
  5894. (cdr (assoc "TIMESTAMP_IA"
  5895. (org-entry-properties nil "TIMESTAMP_IA"))))))
  5896. (should-not
  5897. (equal "<2012-03-29 thu.>"
  5898. (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
  5899. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  5900. ;; Get standard properties.
  5901. (should
  5902. (equal "1"
  5903. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5904. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5905. ;; Handle extended properties.
  5906. (should
  5907. (equal "1 2 3"
  5908. (org-test-with-temp-text
  5909. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5910. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5911. (should
  5912. (equal "1 2 3"
  5913. (org-test-with-temp-text
  5914. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
  5915. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5916. ;; Ignore forbidden (special) properties.
  5917. (should-not
  5918. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
  5919. (cdr (assoc "TODO" (org-entry-properties nil 'standard))))))
  5920. (ert-deftest test-org/entry-put ()
  5921. "Test `org-entry-put' specifications."
  5922. ;; Error when not a string or nil.
  5923. (should-error
  5924. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5925. (org-entry-put 1 "test" 2)))
  5926. ;; Error when property name is invalid.
  5927. (should-error
  5928. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5929. (org-entry-put 1 "no space" "value")))
  5930. (should-error
  5931. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5932. (org-entry-put 1 "" "value")))
  5933. ;; Set "TODO" property.
  5934. (should
  5935. (string-match (regexp-quote " TODO H")
  5936. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  5937. (org-entry-put (point) "TODO" "TODO")
  5938. (buffer-string))))
  5939. (should
  5940. (string-match (regexp-quote "* H")
  5941. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  5942. (org-entry-put (point) "TODO" nil)
  5943. (buffer-string))))
  5944. ;; Set "PRIORITY" property.
  5945. (should
  5946. (equal "* [#A] H"
  5947. (org-test-with-temp-text "* [#B] H"
  5948. (org-entry-put (point) "PRIORITY" "A")
  5949. (buffer-string))))
  5950. (should
  5951. (equal "* H"
  5952. (org-test-with-temp-text "* [#B] H"
  5953. (org-entry-put (point) "PRIORITY" nil)
  5954. (buffer-string))))
  5955. ;; Set "SCHEDULED" property.
  5956. (should
  5957. (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
  5958. (org-test-with-temp-text "* H"
  5959. (org-entry-put (point) "SCHEDULED" "2014-03-04")
  5960. (buffer-string))))
  5961. (should
  5962. (string= "* H\n"
  5963. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5964. (org-entry-put (point) "SCHEDULED" nil)
  5965. (buffer-string))))
  5966. (should
  5967. (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
  5968. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5969. (org-entry-put (point) "SCHEDULED" "earlier")
  5970. (buffer-string))))
  5971. (should
  5972. (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
  5973. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5974. (org-entry-put (point) "SCHEDULED" "later")
  5975. (buffer-string))))
  5976. ;; Set "DEADLINE" property.
  5977. (should
  5978. (string-match "^ *DEADLINE: <2014-03-04 .*?>"
  5979. (org-test-with-temp-text "* H"
  5980. (org-entry-put (point) "DEADLINE" "2014-03-04")
  5981. (buffer-string))))
  5982. (should
  5983. (string= "* H\n"
  5984. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5985. (org-entry-put (point) "DEADLINE" nil)
  5986. (buffer-string))))
  5987. (should
  5988. (string-match "^ *DEADLINE: <2014-03-03 .*?>"
  5989. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5990. (org-entry-put (point) "DEADLINE" "earlier")
  5991. (buffer-string))))
  5992. (should
  5993. (string-match "^ *DEADLINE: <2014-03-05 .*?>"
  5994. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5995. (org-entry-put (point) "DEADLINE" "later")
  5996. (buffer-string))))
  5997. ;; Set "CATEGORY" property
  5998. (should
  5999. (string-match "^ *:CATEGORY: cat"
  6000. (org-test-with-temp-text "* H"
  6001. (org-entry-put (point) "CATEGORY" "cat")
  6002. (buffer-string))))
  6003. ;; Regular properties, with or without pre-existing drawer.
  6004. (should
  6005. (string-match "^ *:A: +2$"
  6006. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6007. (org-entry-put (point) "A" "2")
  6008. (buffer-string))))
  6009. (should
  6010. (string-match "^ *:A: +1$"
  6011. (org-test-with-temp-text "* H"
  6012. (org-entry-put (point) "A" "1")
  6013. (buffer-string))))
  6014. ;; Special case: two consecutive headlines.
  6015. (should
  6016. (string-match "\\* A\n *:PROPERTIES:"
  6017. (org-test-with-temp-text "* A\n** B"
  6018. (org-entry-put (point) "A" "1")
  6019. (buffer-string)))))
  6020. (ert-deftest test-org/refresh-properties ()
  6021. "Test `org-refresh-properties' specifications."
  6022. (should
  6023. (equal "1"
  6024. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6025. (org-refresh-properties "A" 'org-test)
  6026. (get-text-property (point) 'org-test))))
  6027. (should-not
  6028. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6029. (org-refresh-properties "B" 'org-test)
  6030. (get-text-property (point) 'org-test)))
  6031. ;; Handle properties only defined with extension syntax, i.e.,
  6032. ;; "PROPERTY+".
  6033. (should
  6034. (equal "1"
  6035. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
  6036. (org-refresh-properties "A" 'org-test)
  6037. (get-text-property (point) 'org-test))))
  6038. ;; When property is inherited, add text property to the whole
  6039. ;; sub-tree.
  6040. (should
  6041. (equal "1"
  6042. (org-test-with-temp-text
  6043. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
  6044. (let ((org-use-property-inheritance t))
  6045. (org-refresh-properties "A" 'org-test))
  6046. (get-text-property (point) 'org-test))))
  6047. ;; When a document level property-drawer is used, those properties
  6048. ;; should work exactly like headline-properties as if at a
  6049. ;; headline-level 0.
  6050. (should
  6051. (equal "1"
  6052. (org-test-with-temp-text
  6053. ":PROPERTIES:\n:A: 1\n:END:\n"
  6054. (org-mode-restart)
  6055. (let ((org-use-property-inheritance t))
  6056. (org-refresh-properties "A" 'org-test))
  6057. (get-text-property (point) 'org-test))))
  6058. (should-not
  6059. (equal "1"
  6060. (org-test-with-temp-text
  6061. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  6062. (org-mode-restart)
  6063. (let ((org-use-property-inheritance nil))
  6064. (org-refresh-properties "A" 'org-test))
  6065. (get-text-property (point) 'org-test))))
  6066. (should
  6067. (equal "1"
  6068. (org-test-with-temp-text
  6069. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  6070. (org-mode-restart)
  6071. (let ((org-use-property-inheritance t))
  6072. (org-refresh-properties "A" 'org-test))
  6073. (get-text-property (point) 'org-test))))
  6074. (should
  6075. (equal "2"
  6076. (org-test-with-temp-text
  6077. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1\n:PROPERTIES:\n:A: 2\n:END:"
  6078. (org-mode-restart)
  6079. (let ((org-use-property-inheritance t))
  6080. (org-refresh-properties "A" 'org-test))
  6081. (get-text-property (point) 'org-test))))
  6082. ;; When property is inherited, use global value across the whole
  6083. ;; buffer. However local values have precedence, as well as the
  6084. ;; document level property-drawer.
  6085. (should-not
  6086. (equal "1"
  6087. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  6088. (org-mode-restart)
  6089. (let ((org-use-property-inheritance nil))
  6090. (org-refresh-properties "A" 'org-test))
  6091. (get-text-property (point) 'org-test))))
  6092. (should
  6093. (equal "1"
  6094. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  6095. (org-mode-restart)
  6096. (let ((org-use-property-inheritance t))
  6097. (org-refresh-properties "A" 'org-test))
  6098. (get-text-property (point) 'org-test))))
  6099. (should
  6100. (equal "2"
  6101. (org-test-with-temp-text
  6102. "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
  6103. (org-mode-restart)
  6104. (let ((org-use-property-inheritance t))
  6105. (org-refresh-properties "A" 'org-test))
  6106. (get-text-property (point) 'org-test))))
  6107. ;; When both keyword-property and document-level property-block is
  6108. ;; defined, the property-block has precedance.
  6109. (should
  6110. (equal "1"
  6111. (org-test-with-temp-text
  6112. ":PROPERTIES:\n:A: 1\n:END:\n#+PROPERTY: A 2\n<point>* H1"
  6113. (org-mode-restart)
  6114. (let ((org-use-property-inheritance t))
  6115. (org-refresh-properties "A" 'org-test))
  6116. (get-text-property (point) 'org-test)))))
  6117. (ert-deftest test-org/refresh-category-properties ()
  6118. "Test `org-refresh-category-properties' specifications"
  6119. (should
  6120. (equal "cat1"
  6121. (org-test-with-temp-text
  6122. ":PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6123. (org-refresh-category-properties)
  6124. (org-get-category))))
  6125. (should
  6126. (equal "cat1"
  6127. (org-test-with-temp-text
  6128. "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6129. (org-refresh-category-properties)
  6130. (org-get-category))))
  6131. ;; Even though property-inheritance is deactivated, category
  6132. ;; property should be inherited. As described in
  6133. ;; `org-use-property-inheritance'.
  6134. (should
  6135. (equal "cat1"
  6136. (org-test-with-temp-text
  6137. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  6138. (org-mode-restart)
  6139. (let ((org-use-property-inheritance nil))
  6140. (org-refresh-category-properties))
  6141. (org-get-category))))
  6142. (should
  6143. (equal "cat1"
  6144. (org-test-with-temp-text
  6145. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  6146. (org-mode-restart)
  6147. (let ((org-use-property-inheritance t))
  6148. (org-refresh-category-properties))
  6149. (org-get-category))))
  6150. (should
  6151. (equal "cat2"
  6152. (org-test-with-temp-text
  6153. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H\n:PROPERTIES:\n:CATEGORY: cat2\n:END:\n"
  6154. (org-mode-restart)
  6155. (let ((org-use-property-inheritance t))
  6156. (org-refresh-category-properties))
  6157. (org-get-category)))))
  6158. ;;; Refile
  6159. (ert-deftest test-org/refile-get-targets ()
  6160. "Test `org-refile-get-targets' specifications."
  6161. ;; :maxlevel includes all headings above specified value.
  6162. (should
  6163. (equal '("H1" "H2" "H3")
  6164. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6165. (let ((org-refile-use-outline-path nil)
  6166. (org-refile-targets `((nil :maxlevel . 3))))
  6167. (mapcar #'car (org-refile-get-targets))))))
  6168. (should
  6169. (equal '("H1" "H2")
  6170. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6171. (let ((org-refile-use-outline-path nil)
  6172. (org-refile-targets `((nil :maxlevel . 2))))
  6173. (mapcar #'car (org-refile-get-targets))))))
  6174. ;; :level limits targets to headlines with the specified level.
  6175. (should
  6176. (equal '("H2")
  6177. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6178. (let ((org-refile-use-outline-path nil)
  6179. (org-refile-targets `((nil :level . 2))))
  6180. (mapcar #'car (org-refile-get-targets))))))
  6181. ;; :tag limits targets to headlines with specified tag.
  6182. (should
  6183. (equal '("H1")
  6184. (org-test-with-temp-text "* H1 :foo:\n** H2\n*** H3 :bar:"
  6185. (let ((org-refile-use-outline-path nil)
  6186. (org-refile-targets `((nil :tag . "foo"))))
  6187. (mapcar #'car (org-refile-get-targets))))))
  6188. ;; :todo limits targets to headlines with specified TODO keyword.
  6189. (should
  6190. (equal '("H2")
  6191. (org-test-with-temp-text "* H1\n** TODO H2\n*** DONE H3"
  6192. (let ((org-refile-use-outline-path nil)
  6193. (org-refile-targets `((nil :todo . "TODO"))))
  6194. (mapcar #'car (org-refile-get-targets))))))
  6195. ;; :regexp filters targets matching provided regexp.
  6196. (should
  6197. (equal '("F2" "F3")
  6198. (org-test-with-temp-text "* H1\n** F2\n*** F3"
  6199. (let ((org-refile-use-outline-path nil)
  6200. (org-refile-targets `((nil :regexp . "F"))))
  6201. (mapcar #'car (org-refile-get-targets))))))
  6202. ;; A nil `org-refile-targets' includes only top level headlines in
  6203. ;; current buffer.
  6204. (should
  6205. (equal '("H1" "H2")
  6206. (org-test-with-temp-text "* H1\n** S1\n* H2"
  6207. (let ((org-refile-use-outline-path nil)
  6208. (org-refile-targets nil))
  6209. (mapcar #'car (org-refile-get-targets))))))
  6210. ;; Return value is the union of the targets according to all the
  6211. ;; defined rules. However, prevent duplicates.
  6212. (should
  6213. (equal '("F2" "F3" "H1")
  6214. (org-test-with-temp-text "* TODO H1\n** F2\n*** F3"
  6215. (let ((org-refile-use-outline-path nil)
  6216. (org-refile-targets `((nil :regexp . "F")
  6217. (nil :todo . "TODO"))))
  6218. (mapcar #'car (org-refile-get-targets))))))
  6219. (should
  6220. (equal '("F2" "F3" "H1")
  6221. (org-test-with-temp-text "* TODO H1\n** TODO F2\n*** F3"
  6222. (let ((org-refile-use-outline-path nil)
  6223. (org-refile-targets `((nil :regexp . "F")
  6224. (nil :todo . "TODO"))))
  6225. (mapcar #'car (org-refile-get-targets))))))
  6226. ;; When `org-refile-use-outline-path' is non-nil, provide targets as
  6227. ;; paths.
  6228. (should
  6229. (equal '("H1" "H1/H2" "H1/H2/H3")
  6230. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6231. (let ((org-refile-use-outline-path t)
  6232. (org-refile-targets `((nil :maxlevel . 3))))
  6233. (mapcar #'car (org-refile-get-targets))))))
  6234. ;; When providing targets as paths, escape forward slashes in
  6235. ;; headings with backslashes.
  6236. (should
  6237. (equal '("H1\\/foo")
  6238. (org-test-with-temp-text "* H1/foo"
  6239. (let ((org-refile-use-outline-path t)
  6240. (org-refile-targets `((nil :maxlevel . 1))))
  6241. (mapcar #'car (org-refile-get-targets))))))
  6242. ;; When `org-refile-use-outline-path' is `file', include file name
  6243. ;; without directory in targets.
  6244. (should
  6245. (org-test-with-temp-text-in-file "* H1"
  6246. (let* ((filename (buffer-file-name))
  6247. (org-refile-use-outline-path 'file)
  6248. (org-refile-targets `(((,filename) :level . 1))))
  6249. (member (file-name-nondirectory filename)
  6250. (mapcar #'car (org-refile-get-targets))))))
  6251. ;; When `org-refile-use-outline-path' is `full-file-path', include
  6252. ;; full file name.
  6253. (should
  6254. (org-test-with-temp-text-in-file "* H1"
  6255. (let* ((filename (file-truename (buffer-file-name)))
  6256. (org-refile-use-outline-path 'full-file-path)
  6257. (org-refile-targets `(((,filename) :level . 1))))
  6258. (member filename (mapcar #'car (org-refile-get-targets))))))
  6259. ;; When `org-refile-use-outline-path' is `buffer-name', include
  6260. ;; buffer name.
  6261. (should
  6262. (org-test-with-temp-text "* H1"
  6263. (let* ((org-refile-use-outline-path 'buffer-name)
  6264. (org-refile-targets `((nil :level . 1))))
  6265. (member (buffer-name) (mapcar #'car (org-refile-get-targets)))))))
  6266. ;;; Sparse trees
  6267. (ert-deftest test-org/match-sparse-tree ()
  6268. "Test `org-match-sparse-tree' specifications."
  6269. ;; Match tags.
  6270. (should-not
  6271. (org-test-with-temp-text "* H\n** H1 :tag:"
  6272. (org-match-sparse-tree nil "tag")
  6273. (search-forward "H1")
  6274. (org-invisible-p2)))
  6275. (should
  6276. (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
  6277. (org-match-sparse-tree nil "tag")
  6278. (search-forward "H2")
  6279. (org-invisible-p2)))
  6280. ;; "-" operator for tags.
  6281. (should-not
  6282. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6283. (org-match-sparse-tree nil "tag1-tag2")
  6284. (search-forward "H1")
  6285. (org-invisible-p2)))
  6286. (should
  6287. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6288. (org-match-sparse-tree nil "tag1-tag2")
  6289. (search-forward "H2")
  6290. (org-invisible-p2)))
  6291. ;; "&" operator for tags.
  6292. (should
  6293. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6294. (org-match-sparse-tree nil "tag1&tag2")
  6295. (search-forward "H1")
  6296. (org-invisible-p2)))
  6297. (should-not
  6298. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6299. (org-match-sparse-tree nil "tag1&tag2")
  6300. (search-forward "H2")
  6301. (org-invisible-p2)))
  6302. ;; "|" operator for tags.
  6303. (should-not
  6304. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6305. (org-match-sparse-tree nil "tag1|tag2")
  6306. (search-forward "H1")
  6307. (org-invisible-p2)))
  6308. (should-not
  6309. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6310. (org-match-sparse-tree nil "tag1|tag2")
  6311. (search-forward "H2")
  6312. (org-invisible-p2)))
  6313. ;; Regexp match on tags.
  6314. (should-not
  6315. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6316. (org-match-sparse-tree nil "{^tag.*}")
  6317. (search-forward "H1")
  6318. (org-invisible-p2)))
  6319. (should
  6320. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6321. (org-match-sparse-tree nil "{^tag.*}")
  6322. (search-forward "H2")
  6323. (org-invisible-p2)))
  6324. ;; Match group tags.
  6325. (should-not
  6326. (org-test-with-temp-text
  6327. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6328. (org-match-sparse-tree nil "work")
  6329. (search-forward "H1")
  6330. (org-invisible-p2)))
  6331. (should-not
  6332. (org-test-with-temp-text
  6333. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6334. (org-match-sparse-tree nil "work")
  6335. (search-forward "H2")
  6336. (org-invisible-p2)))
  6337. ;; Match group tags with hard brackets.
  6338. (should-not
  6339. (org-test-with-temp-text
  6340. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6341. (org-match-sparse-tree nil "work")
  6342. (search-forward "H1")
  6343. (org-invisible-p2)))
  6344. (should-not
  6345. (org-test-with-temp-text
  6346. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6347. (org-match-sparse-tree nil "work")
  6348. (search-forward "H2")
  6349. (org-invisible-p2)))
  6350. ;; Match tags in hierarchies
  6351. (should-not
  6352. (org-test-with-temp-text
  6353. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6354. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6355. #+TAGS: { Lev_3 : Lev_4 }\n
  6356. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6357. (org-match-sparse-tree nil "Lev_1")
  6358. (search-forward "H4")
  6359. (org-invisible-p2)))
  6360. (should-not
  6361. (org-test-with-temp-text
  6362. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6363. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6364. #+TAGS: { Lev_3 : Lev_4 }\n
  6365. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6366. (org-match-sparse-tree nil "Lev_1+Lev_3")
  6367. (search-forward "H4")
  6368. (org-invisible-p2)))
  6369. ;; Match regular expressions in tags
  6370. (should-not
  6371. (org-test-with-temp-text
  6372. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
  6373. (org-match-sparse-tree nil "Lev")
  6374. (search-forward "H1")
  6375. (org-invisible-p2)))
  6376. (should
  6377. (org-test-with-temp-text
  6378. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
  6379. (org-match-sparse-tree nil "Lev")
  6380. (search-forward "H1")
  6381. (org-invisible-p2)))
  6382. ;; Match properties.
  6383. (should
  6384. (org-test-with-temp-text
  6385. "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
  6386. (org-match-sparse-tree nil "A=\"1\"")
  6387. (search-forward "H2")
  6388. (org-invisible-p2)))
  6389. (should-not
  6390. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6391. (org-match-sparse-tree nil "A=\"1\"")
  6392. (search-forward "H2")
  6393. (org-invisible-p2)))
  6394. ;; Case is not significant when matching properties.
  6395. (should-not
  6396. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6397. (org-match-sparse-tree nil "a=\"1\"")
  6398. (search-forward "H2")
  6399. (org-invisible-p2)))
  6400. (should-not
  6401. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
  6402. (org-match-sparse-tree nil "A=\"1\"")
  6403. (search-forward "H2")
  6404. (org-invisible-p2)))
  6405. ;; Match special LEVEL property.
  6406. (should-not
  6407. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6408. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6409. (search-forward "H1")
  6410. (org-invisible-p2)))
  6411. (should
  6412. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6413. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6414. (search-forward "H2")
  6415. (org-invisible-p2)))
  6416. ;; Comparison operators when matching properties.
  6417. (should
  6418. (org-test-with-temp-text
  6419. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6420. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6421. (search-forward "H1")
  6422. (org-invisible-p2)))
  6423. (should-not
  6424. (org-test-with-temp-text
  6425. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6426. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6427. (search-forward "H2")
  6428. (org-invisible-p2)))
  6429. ;; Regexp match on properties values.
  6430. (should-not
  6431. (org-test-with-temp-text
  6432. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6433. (org-match-sparse-tree nil "A={f.*}")
  6434. (search-forward "H1")
  6435. (org-invisible-p2)))
  6436. (should
  6437. (org-test-with-temp-text
  6438. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6439. (org-match-sparse-tree nil "A={f.*}")
  6440. (search-forward "H2")
  6441. (org-invisible-p2)))
  6442. ;; With an optional argument, limit match to TODO entries.
  6443. (should-not
  6444. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6445. (org-match-sparse-tree t "tag")
  6446. (search-forward "H1")
  6447. (org-invisible-p2)))
  6448. (should
  6449. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6450. (org-match-sparse-tree t "tag")
  6451. (search-forward "H2")
  6452. (org-invisible-p2))))
  6453. (ert-deftest test-org/occur ()
  6454. "Test `org-occur' specifications."
  6455. ;; Count number of matches.
  6456. (should
  6457. (= 1
  6458. (org-test-with-temp-text "* H\nA\n* H2"
  6459. (org-occur "A"))))
  6460. (should
  6461. (= 2
  6462. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6463. (org-occur "A"))))
  6464. ;; Test CALLBACK optional argument.
  6465. (should
  6466. (= 0
  6467. (org-test-with-temp-text "* H\nA\n* H2"
  6468. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6469. (should
  6470. (= 1
  6471. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6472. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6473. ;; Case-fold searches according to `org-occur-case-fold-search'.
  6474. (should
  6475. (= 2
  6476. (org-test-with-temp-text "Aa"
  6477. (let ((org-occur-case-fold-search t)) (org-occur "A")))))
  6478. (should
  6479. (= 2
  6480. (org-test-with-temp-text "Aa"
  6481. (let ((org-occur-case-fold-search t)) (org-occur "a")))))
  6482. (should
  6483. (= 1
  6484. (org-test-with-temp-text "Aa"
  6485. (let ((org-occur-case-fold-search nil)) (org-occur "A")))))
  6486. (should
  6487. (= 1
  6488. (org-test-with-temp-text "Aa"
  6489. (let ((org-occur-case-fold-search nil)) (org-occur "a")))))
  6490. (should
  6491. (= 1
  6492. (org-test-with-temp-text "Aa"
  6493. (let ((org-occur-case-fold-search 'smart)) (org-occur "A")))))
  6494. (should
  6495. (= 2
  6496. (org-test-with-temp-text "Aa"
  6497. (let ((org-occur-case-fold-search 'smart)) (org-occur "a"))))))
  6498. ;;; Tags
  6499. (ert-deftest test-org/tag-string-to-alist ()
  6500. "Test `org-tag-string-to-alist' specifications."
  6501. ;; Tag without selection key.
  6502. (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
  6503. ;; Tag with selection key.
  6504. (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t))))
  6505. ;; Tag group.
  6506. (should
  6507. (equal
  6508. (org-tag-string-to-alist "[ group : t1 t2 ]")
  6509. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag))))
  6510. ;; Mutually exclusive tags.
  6511. (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
  6512. '((:startgroup) ("tag1") ("tag2") (:endgroup))))
  6513. (should
  6514. (equal
  6515. (org-tag-string-to-alist "{ group : tag1 tag2 }")
  6516. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))))
  6517. (ert-deftest test-org/tag-alist-to-string ()
  6518. "Test `org-tag-alist-to-string' specifications."
  6519. (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
  6520. (should (equal (org-tag-alist-to-string '(("tag1" . ?t))) "tag1(t)"))
  6521. (should
  6522. (equal
  6523. (org-tag-alist-to-string
  6524. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6525. "[ group : t1 t2 ]"))
  6526. (should
  6527. (equal (org-tag-alist-to-string
  6528. '((:startgroup) ("tag1") ("tag2") (:endgroup)))
  6529. "{ tag1 tag2 }"))
  6530. (should
  6531. (equal
  6532. (org-tag-alist-to-string
  6533. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))
  6534. "{ group : tag1 tag2 }")))
  6535. (ert-deftest test-org/tag-alist-to-groups ()
  6536. "Test `org-tag-alist-to-groups' specifications."
  6537. (should
  6538. (equal (org-tag-alist-to-groups
  6539. '((:startgroup) ("group") (:grouptags) ("t1") ("t2") (:endgroup)))
  6540. '(("group" "t1" "t2"))))
  6541. (should
  6542. (equal
  6543. (org-tag-alist-to-groups
  6544. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6545. '(("group" "t1" "t2"))))
  6546. (should-not
  6547. (org-tag-alist-to-groups
  6548. '((:startgroup) ("group") ("t1") ("t2") (:endgroup)))))
  6549. (ert-deftest test-org/tag-align ()
  6550. "Test tags alignment."
  6551. ;; Test aligning tags with different display width.
  6552. (should
  6553. ;; 12345678901234567890
  6554. (equal "* Test :abc:"
  6555. (org-test-with-temp-text "* Test :abc:"
  6556. (let ((org-tags-column -20)
  6557. (indent-tabs-mode nil))
  6558. (org-fix-tags-on-the-fly))
  6559. (buffer-string))))
  6560. (should
  6561. ;; 12345678901234567890
  6562. (equal "* Test :日本語:"
  6563. (org-test-with-temp-text "* Test :日本語:"
  6564. (let ((org-tags-column -20)
  6565. (indent-tabs-mode nil))
  6566. (org-fix-tags-on-the-fly))
  6567. (buffer-string))))
  6568. ;; Make sure aligning tags do not skip invisible text.
  6569. (should
  6570. (equal "* [[linkx]] :tag:"
  6571. (org-test-with-temp-text "* [[link<point>]] :tag:"
  6572. (let ((org-tags-column 0))
  6573. (org-fix-tags-on-the-fly)
  6574. (insert "x")
  6575. (buffer-string)))))
  6576. ;; Aligning tags preserve position.
  6577. (should
  6578. (= 6 (org-test-with-temp-text "* 345 <point> :tag:"
  6579. (let ((org-tags-column 78)
  6580. (indent-tabs-mode nil))
  6581. (org-fix-tags-on-the-fly))
  6582. (current-column))))
  6583. ;; Aligning all tags in visible buffer.
  6584. (should
  6585. ;; 12345678901234567890
  6586. (equal (concat "* Level 1 :abc:\n"
  6587. "** Level 2 :def:")
  6588. (org-test-with-temp-text (concat "* Level 1 :abc:\n"
  6589. "** Level 2 :def:")
  6590. (let ((org-tags-column -20)
  6591. (indent-tabs-mode nil))
  6592. ;; (org-align-tags :all) must work even when the point
  6593. ;; is at the end of the buffer.
  6594. (goto-char (point-max))
  6595. (org-align-tags :all))
  6596. (buffer-string)))))
  6597. (ert-deftest test-org/get-tags ()
  6598. "Test `org-get-tags' specifications."
  6599. ;; Standard test.
  6600. (should
  6601. (equal '("foo")
  6602. (org-test-with-temp-text "* Test :foo:" (org-get-tags))))
  6603. (should
  6604. (equal '("foo" "bar")
  6605. (org-test-with-temp-text "* Test :foo:bar:" (org-get-tags))))
  6606. ;; Return nil when there is no tag.
  6607. (should-not
  6608. (org-test-with-temp-text "* Test" (org-get-tags)))
  6609. ;; Tags are inherited from parent headlines.
  6610. (should
  6611. (equal '("tag")
  6612. (let ((org-use-tag-inheritance t))
  6613. (org-test-with-temp-text "* H0 :foo:\n* H1 :tag:\n<point>** H2"
  6614. (org-get-tags)))))
  6615. ;; Tags are inherited from `org-file-tags'.
  6616. (should
  6617. (equal '("tag")
  6618. (org-test-with-temp-text "* H1"
  6619. (let ((org-file-tags '("tag"))
  6620. (org-use-tag-inheritance t))
  6621. (org-get-tags)))))
  6622. ;; Only inherited tags have the `inherited' text property.
  6623. (should
  6624. (get-text-property 0 'inherited
  6625. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6626. (let ((org-use-tag-inheritance t))
  6627. (assoc-string "foo" (org-get-tags))))))
  6628. (should-not
  6629. (get-text-property 0 'inherited
  6630. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6631. (let ((org-use-tag-inheritance t))
  6632. (assoc-string "bar" (org-get-tags))))))
  6633. ;; Obey to `org-use-tag-inheritance'.
  6634. (should-not
  6635. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6636. (let ((org-use-tag-inheritance nil))
  6637. (assoc-string "foo" (org-get-tags)))))
  6638. (should-not
  6639. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6640. (let ((org-use-tag-inheritance nil)
  6641. (org-file-tags '("foo")))
  6642. (assoc-string "foo" (org-get-tags)))))
  6643. (should-not
  6644. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6645. (let ((org-use-tag-inheritance '("bar")))
  6646. (assoc-string "foo" (org-get-tags)))))
  6647. (should
  6648. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6649. (let ((org-use-tag-inheritance '("bar")))
  6650. (assoc-string "bar" (org-get-tags)))))
  6651. (should-not
  6652. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6653. (let ((org-use-tag-inheritance "b.*"))
  6654. (assoc-string "foo" (org-get-tags)))))
  6655. (should
  6656. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6657. (let ((org-use-tag-inheritance "b.*"))
  6658. (assoc-string "bar" (org-get-tags)))))
  6659. ;; When optional argument LOCAL is non-nil, ignore tag inheritance.
  6660. (should
  6661. (equal '("baz")
  6662. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6663. (let ((org-use-tag-inheritance t))
  6664. (org-get-tags nil t)))))
  6665. ;; When optional argument POS is non-nil, get tags there instead.
  6666. (should
  6667. (equal '("foo")
  6668. (org-test-with-temp-text "* H1 :foo:\n* <point>H2 :bar:"
  6669. (org-get-tags 1))))
  6670. ;; Make sure tags excluded from inheritance are returned if local
  6671. (should
  6672. (equal '("foo")
  6673. (org-test-with-temp-text "* Test :foo:"
  6674. (let ((org-use-tag-inheritance t)
  6675. (org-tags-exclude-from-inheritance '("foo")))
  6676. (org-get-tags)))))
  6677. ;; Test the collection of tags from #+filetags and parent tags.
  6678. (should
  6679. (equal '("a" "b" "c" "d")
  6680. (org-test-with-temp-text (concat "#+filetags: a\n"
  6681. "* Level 1 :b:\n"
  6682. "** Level 2 :c:\n"
  6683. "*** Level 3 :d:\n"
  6684. "<point>")
  6685. (let ((org-use-tag-inheritance t))
  6686. (org-mode-restart) ;So that `org-file-tags' get populated from #+filetags
  6687. (org-get-tags)))))
  6688. ;; Pathological case: tagged headline with an empty body.
  6689. (should (org-test-with-temp-text "* :tag:" (org-get-tags))))
  6690. (ert-deftest test-org/set-tags ()
  6691. "Test `org-set-tags' specifications."
  6692. ;; Throw an error on invalid data.
  6693. (should-error
  6694. (org-test-with-temp-text "* H"
  6695. (org-set-tags 'foo)))
  6696. ;; `nil', an empty, and a blank string remove all tags.
  6697. (should
  6698. (equal "* H"
  6699. (org-test-with-temp-text "* H :tag1:tag2:"
  6700. (org-set-tags nil)
  6701. (buffer-string))))
  6702. (should
  6703. (equal "* H"
  6704. (org-test-with-temp-text "* H :tag1:tag2:"
  6705. (org-set-tags "")
  6706. (buffer-string))))
  6707. (should
  6708. (equal "* H"
  6709. (org-test-with-temp-text "* H :tag1:tag2:"
  6710. (org-set-tags " ")
  6711. (buffer-string))))
  6712. ;; If there's nothing to remove, just bail out.
  6713. (should
  6714. (equal "* H"
  6715. (org-test-with-temp-text "* H"
  6716. (org-set-tags nil)
  6717. (buffer-string))))
  6718. (should
  6719. (equal "* "
  6720. (org-test-with-temp-text "* "
  6721. (org-set-tags nil)
  6722. (buffer-string))))
  6723. ;; If DATA is a tag string, set current tags to it, even if it means
  6724. ;; replacing old tags.
  6725. (should
  6726. (equal "* H :tag0:"
  6727. (org-test-with-temp-text "* H :tag1:tag2:"
  6728. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  6729. (buffer-string))))
  6730. (should
  6731. (equal "* H :tag0:"
  6732. (org-test-with-temp-text "* H"
  6733. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  6734. (buffer-string))))
  6735. ;; If DATA is a list, set tags to this list, even if it means
  6736. ;; replacing old tags.
  6737. (should
  6738. (equal "* H :tag0:"
  6739. (org-test-with-temp-text "* H :tag1:tag2:"
  6740. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6741. (buffer-string))))
  6742. (should
  6743. (equal "* H :tag0:"
  6744. (org-test-with-temp-text "* H"
  6745. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6746. (buffer-string))))
  6747. ;; When set, apply `org-tags-sort-function'.
  6748. (should
  6749. (equal "* H :a:b:"
  6750. (org-test-with-temp-text "* H"
  6751. (let ((org-tags-column 1)
  6752. (org-tags-sort-function #'string<))
  6753. (org-set-tags '("b" "a"))
  6754. (buffer-string)))))
  6755. ;; When new tags are identical to the previous ones, still align.
  6756. (should
  6757. (equal "* H :foo:"
  6758. (org-test-with-temp-text "* H :foo:"
  6759. (let ((org-tags-column 1))
  6760. (org-set-tags '("foo"))
  6761. (buffer-string)))))
  6762. ;; When tags have been changed, run `org-after-tags-change-hook'.
  6763. (should
  6764. (catch :return
  6765. (org-test-with-temp-text "* H :foo:"
  6766. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  6767. (org-set-tags '("bar"))
  6768. nil))))
  6769. (should-not
  6770. (catch :return
  6771. (org-test-with-temp-text "* H :foo:"
  6772. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  6773. (org-set-tags '("foo"))
  6774. nil))))
  6775. ;; Special case: handle empty headlines.
  6776. (should
  6777. (equal "* :tag0:"
  6778. (org-test-with-temp-text "* "
  6779. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6780. (buffer-string))))
  6781. ;; Modify buffer only when a tag change happens or alignment is
  6782. ;; done.
  6783. (should-not
  6784. (org-test-with-temp-text "* H :foo:"
  6785. (set-buffer-modified-p nil)
  6786. (let ((org-tags-column 1)) (org-set-tags '("foo")))
  6787. (buffer-modified-p)))
  6788. (should
  6789. (org-test-with-temp-text "* H :foo:"
  6790. (set-buffer-modified-p nil)
  6791. (let ((org-tags-column 10)) (org-set-tags '("foo")))
  6792. (buffer-modified-p)))
  6793. (should
  6794. (org-test-with-temp-text "* H :foo:"
  6795. (set-buffer-modified-p nil)
  6796. (let ((org-tags-column 10)) (org-set-tags '("bar")))
  6797. (buffer-modified-p)))
  6798. ;; Pathological case: when setting tags of a folded headline, do not
  6799. ;; let new tags being sucked into invisibility.
  6800. (should-not
  6801. (org-test-with-temp-text "* H1\nContent\n* H2\n\n Other Content"
  6802. ;; Show only headlines
  6803. (org-content)
  6804. ;; Set NEXT tag on current entry
  6805. (org-set-tags ":NEXT:")
  6806. ;; Move point to that NEXT tag
  6807. (search-forward "NEXT") (backward-word)
  6808. ;; And it should be visible (i.e. no overlays)
  6809. (overlays-at (point)))))
  6810. (ert-deftest test-org/set-tags-command ()
  6811. "Test `org-set-tags-command' specifications"
  6812. ;; Set tags at current headline.
  6813. (should
  6814. (equal "* H1 :foo:"
  6815. (org-test-with-temp-text "* H1"
  6816. (cl-letf (((symbol-function 'completing-read-multiple)
  6817. (lambda (&rest args) '("foo"))))
  6818. (let ((org-use-fast-tag-selection nil)
  6819. (org-tags-column 1))
  6820. (org-set-tags-command)))
  6821. (buffer-string))))
  6822. ;; Preserve position when called from the section below.
  6823. (should
  6824. (equal "* H1 :foo:\nContents"
  6825. (org-test-with-temp-text "* H1\n<point>Contents"
  6826. (cl-letf (((symbol-function 'completing-read-multiple)
  6827. (lambda (&rest args) '("foo"))))
  6828. (let ((org-use-fast-tag-selection nil)
  6829. (org-tags-column 1))
  6830. (org-set-tags-command)))
  6831. (buffer-string))))
  6832. (should-not
  6833. (equal "* H1 :foo:\nContents2"
  6834. (org-test-with-temp-text "* H1\n<point>Contents2"
  6835. (cl-letf (((symbol-function 'completing-read-multiple)
  6836. (lambda (&rest args) '("foo"))))
  6837. (let ((org-use-fast-tag-selection nil)
  6838. (org-tags-column 1))
  6839. (org-set-tags-command)))
  6840. (org-at-heading-p))))
  6841. ;; When a region is active and
  6842. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  6843. ;; same value in all headlines in region.
  6844. (should
  6845. (equal "* H1 :foo:\nContents\n* H2 :foo:"
  6846. (org-test-with-temp-text "* H1\nContents\n* H2"
  6847. (cl-letf (((symbol-function 'completing-read-multiple)
  6848. (lambda (&rest args) '("foo"))))
  6849. (let ((org-use-fast-tag-selection nil)
  6850. (org-loop-over-headlines-in-active-region t)
  6851. (org-tags-column 1))
  6852. (transient-mark-mode 1)
  6853. (push-mark (point) t t)
  6854. (goto-char (point-max))
  6855. (org-set-tags-command)))
  6856. (buffer-string))))
  6857. (should
  6858. (equal "* H1\nContents\n* H2 :foo:"
  6859. (org-test-with-temp-text "* H1\nContents\n* H2"
  6860. (cl-letf (((symbol-function 'completing-read-multiple)
  6861. (lambda (&rest args) '("foo"))))
  6862. (let ((org-use-fast-tag-selection nil)
  6863. (org-loop-over-headlines-in-active-region nil)
  6864. (org-tags-column 1))
  6865. (transient-mark-mode 1)
  6866. (push-mark (point) t t)
  6867. (goto-char (point-max))
  6868. (org-set-tags-command)))
  6869. (buffer-string))))
  6870. ;; With a C-u prefix argument, align all tags in the buffer.
  6871. (should
  6872. (equal "* H1 :foo:\n* H2 :bar:"
  6873. (org-test-with-temp-text "* H1 :foo:\n* H2 :bar:"
  6874. (let ((org-tags-column 1)) (org-set-tags-command '(4)))
  6875. (buffer-string))))
  6876. ;; Point does not move with empty headline.
  6877. (should
  6878. (equal ":foo:"
  6879. (org-test-with-temp-text "* <point>"
  6880. (cl-letf (((symbol-function 'completing-read-multiple)
  6881. (lambda (&rest args) '("foo"))))
  6882. (let ((org-use-fast-tag-selection nil)
  6883. (org-tags-column 1))
  6884. (org-set-tags-command)))
  6885. (buffer-substring (point) (line-end-position)))))
  6886. ;; Point does not move at start of line.
  6887. (should
  6888. (equal "* H1 :foo:"
  6889. (org-test-with-temp-text "* H1"
  6890. (cl-letf (((symbol-function 'completing-read-multiple)
  6891. (lambda (&rest args) '("foo"))))
  6892. (let ((org-use-fast-tag-selection nil)
  6893. (org-tags-column 1))
  6894. (org-set-tags-command)))
  6895. (buffer-substring (point) (line-end-position)))))
  6896. ;; Point does not move when within *'s.
  6897. (should
  6898. (equal "* H1 :foo:"
  6899. (org-test-with-temp-text "*<point>* H1"
  6900. (cl-letf (((symbol-function 'completing-read-multiple)
  6901. (lambda (&rest args) '("foo"))))
  6902. (let ((org-use-fast-tag-selection nil)
  6903. (org-tags-column 1))
  6904. (org-set-tags-command)))
  6905. (buffer-substring (point) (line-end-position)))))
  6906. ;; Point workaround does not get fooled when looking at a space.
  6907. (should
  6908. (equal " b :foo:"
  6909. (org-test-with-temp-text "* a<point> b"
  6910. (cl-letf (((symbol-function 'completing-read-multiple)
  6911. (lambda (&rest args) '("foo"))))
  6912. (let ((org-use-fast-tag-selection nil)
  6913. (org-tags-column 1))
  6914. (org-set-tags-command)))
  6915. (buffer-substring (point) (line-end-position)))))
  6916. ;; Handle tags both set locally and inherited.
  6917. (should
  6918. (equal "b :foo:"
  6919. (org-test-with-temp-text "* a :foo:\n** <point>b :foo:"
  6920. (cl-letf (((symbol-function 'completing-read-multiple)
  6921. (lambda (prompt coll &optional pred req initial &rest args)
  6922. (list initial))))
  6923. (let ((org-use-fast-tag-selection nil)
  6924. (org-tags-column 1))
  6925. (org-set-tags-command)))
  6926. (buffer-substring (point) (line-end-position))))))
  6927. (ert-deftest test-org/toggle-tag ()
  6928. "Test `org-toggle-tag' specifications."
  6929. ;; Insert missing tag.
  6930. (should
  6931. (equal "* H :tag:"
  6932. (org-test-with-temp-text "* H"
  6933. (let ((org-tags-column 1)) (org-toggle-tag "tag"))
  6934. (buffer-string))))
  6935. (should
  6936. (equal "* H :tag1:tag2:"
  6937. (org-test-with-temp-text "* H :tag1:"
  6938. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  6939. (buffer-string))))
  6940. ;; Remove existing tag.
  6941. (should
  6942. (equal "* H"
  6943. (org-test-with-temp-text "* H :tag:"
  6944. (org-toggle-tag "tag")
  6945. (buffer-string))))
  6946. (should
  6947. (equal "* H :tag1:"
  6948. (org-test-with-temp-text "* H :tag1:tag2:"
  6949. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  6950. (buffer-string))))
  6951. (should
  6952. (equal "* H :tag2:"
  6953. (org-test-with-temp-text "* H :tag1:tag2:"
  6954. (let ((org-tags-column 1)) (org-toggle-tag "tag1"))
  6955. (buffer-string))))
  6956. ;; With optional argument ONOFF set to `on', try to insert the tag,
  6957. ;; even if its already there.
  6958. (should
  6959. (equal "* H :tag:"
  6960. (org-test-with-temp-text "* H"
  6961. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  6962. (buffer-string))))
  6963. (should
  6964. (equal "* H :tag:"
  6965. (org-test-with-temp-text "* H :tag:"
  6966. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  6967. (buffer-string))))
  6968. ;; With optional argument ONOFF set to `off', try to remove the tag,
  6969. ;; even if its not there.
  6970. (should
  6971. (equal "* H"
  6972. (org-test-with-temp-text "* H :tag:"
  6973. (org-toggle-tag "tag" 'off)
  6974. (buffer-string))))
  6975. (should
  6976. (equal "* H :tag:"
  6977. (org-test-with-temp-text "* H :tag:"
  6978. (let ((org-tags-column 1)) (org-toggle-tag "foo" 'off))
  6979. (buffer-string))))
  6980. ;; Special case: Handle properly tag inheritance. In particular, do
  6981. ;; not set inherited tags.
  6982. (should
  6983. (equal "* H1 :tag:\n** H2 :tag2:tag:"
  6984. (org-test-with-temp-text "* H1 :tag:\n** <point>H2 :tag2:"
  6985. (let ((org-use-tag-inheritance t)
  6986. (org-tags-column 1))
  6987. (org-toggle-tag "tag"))
  6988. (buffer-string))))
  6989. (should
  6990. (equal "* H1 :tag1:tag2:\n** H2 :foo:"
  6991. (org-test-with-temp-text "* H1 :tag1:tag2:\n** <point>H2"
  6992. (let ((org-use-tag-inheritance t)
  6993. (org-tags-column 1))
  6994. (org-toggle-tag "foo"))
  6995. (buffer-string)))))
  6996. (ert-deftest test-org/tags-expand ()
  6997. "Test `org-tags-expand' specifications."
  6998. ;; Expand tag groups as a regexp enclosed within curly brackets.
  6999. (should
  7000. (equal "{\\<[ABC]\\>}"
  7001. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7002. (org-mode-restart)
  7003. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  7004. (should
  7005. (equal "{\\<\\(?:Aa\\|Bb\\|Cc\\)\\>}"
  7006. (org-test-with-temp-text "#+TAGS: [ Aa : Bb Cc ]"
  7007. (org-mode-restart)
  7008. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "Aa")))))
  7009. ;; Preserve operator before the regexp.
  7010. (should
  7011. (equal "+{\\<[ABC]\\>}"
  7012. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7013. (org-mode-restart)
  7014. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "+A")))))
  7015. (should
  7016. (equal "-{\\<[ABC]\\>}"
  7017. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7018. (org-mode-restart)
  7019. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "-A")))))
  7020. ;; Handle "|" syntax.
  7021. (should
  7022. (equal "{\\<[ABC]\\>}|D"
  7023. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7024. (org-mode-restart)
  7025. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|D")))))
  7026. ;; Handle nested groups.
  7027. (should
  7028. (equal "{\\<[A-D]\\>}"
  7029. (org-test-with-temp-text "#+TAGS: [ A : B C ]\n#+TAGS: [ B : D ]"
  7030. (org-mode-restart)
  7031. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  7032. ;; Expand multiple occurrences of the same group.
  7033. (should
  7034. (equal "{\\<[ABC]\\>}|{\\<[ABC]\\>}"
  7035. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7036. (org-mode-restart)
  7037. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|A")))))
  7038. ;; Preserve regexp matches.
  7039. (should
  7040. (equal "{A+}"
  7041. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7042. (org-mode-restart)
  7043. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "{A+}"))))))
  7044. ;;; TODO keywords
  7045. (ert-deftest test-org/auto-repeat-maybe ()
  7046. "Test `org-auto-repeat-maybe' specifications."
  7047. ;; Do not auto repeat when there is no valid time stamp with
  7048. ;; a repeater in the entry.
  7049. (should-not
  7050. (string-prefix-p
  7051. "* TODO H"
  7052. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7053. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
  7054. (org-todo "DONE")
  7055. (buffer-string)))))
  7056. (should-not
  7057. (string-prefix-p
  7058. "* TODO H"
  7059. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7060. (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
  7061. (org-todo "DONE")
  7062. (buffer-string)))))
  7063. ;; When switching to DONE state, switch back to first TODO keyword
  7064. ;; in sequence, or the same keyword if they have different types.
  7065. (should
  7066. (string-prefix-p
  7067. "* TODO H"
  7068. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7069. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7070. (org-todo "DONE")
  7071. (buffer-string)))))
  7072. (should
  7073. (string-prefix-p
  7074. "* KWD1 H"
  7075. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  7076. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  7077. (org-todo "DONE")
  7078. (buffer-string)))))
  7079. (should
  7080. (string-prefix-p
  7081. "* KWD2 H"
  7082. (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
  7083. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  7084. (org-todo "DONE")
  7085. (buffer-string)))))
  7086. ;; If there was no TODO keyword in the first place, do not insert
  7087. ;; any either.
  7088. (should
  7089. (string-prefix-p
  7090. "* H"
  7091. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7092. (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
  7093. (org-todo "DONE")
  7094. (buffer-string)))))
  7095. ;; Revert to REPEAT_TO_STATE, if set.
  7096. (should
  7097. (string-prefix-p
  7098. "* KWD2 H"
  7099. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  7100. (org-test-with-temp-text
  7101. "* KWD2 H
  7102. :PROPERTIES:
  7103. :REPEAT_TO_STATE: KWD2
  7104. :END:
  7105. <2012-03-29 Thu +2y>"
  7106. (org-todo "DONE")
  7107. (buffer-string)))))
  7108. ;; When switching to DONE state, update base date. If there are
  7109. ;; multiple repeated time stamps, update them all.
  7110. (should
  7111. (string-match-p
  7112. "<2014-03-29 .* \\+2y>"
  7113. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7114. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7115. (org-todo "DONE")
  7116. (buffer-string)))))
  7117. (should
  7118. (string-match-p
  7119. "<2015-03-04 .* \\+1y>"
  7120. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7121. (org-test-with-temp-text
  7122. "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
  7123. (org-todo "DONE")
  7124. (buffer-string)))))
  7125. ;; Throw an error if repeater unit is the hour and no time is
  7126. ;; provided in the time-stamp.
  7127. (should-error
  7128. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7129. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
  7130. (org-todo "DONE")
  7131. (buffer-string))))
  7132. ;; Handle every repeater type using hours step.
  7133. (should
  7134. (string-match-p
  7135. "2014-03-04 .* 02:00"
  7136. (org-test-at-time "<2014-03-04 02:35>"
  7137. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 +8h>"
  7138. (org-todo "DONE")
  7139. (buffer-string)))))
  7140. (should
  7141. (string-match-p
  7142. "2014-03-04 .* 10:00"
  7143. (org-test-at-time "<2014-03-04 02:35>"
  7144. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 ++8h>"
  7145. (org-todo "DONE")
  7146. (buffer-string)))))
  7147. (should
  7148. (string-match-p
  7149. "2014-03-04 .* 10:35"
  7150. (org-test-at-time "<2014-03-04 02:35>"
  7151. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 .+8h>"
  7152. (org-todo "DONE")
  7153. (buffer-string)))))
  7154. ;; Do not repeat inactive time stamps with a repeater.
  7155. (should-not
  7156. (string-match-p
  7157. "\\[2014-03-29 .* \\+2y\\]"
  7158. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7159. (org-test-with-temp-text
  7160. "* TODO H\n[2012-03-29 Thu. +2y]"
  7161. (org-todo "DONE")
  7162. (buffer-string)))))
  7163. ;; Do not repeat commented time stamps.
  7164. (should-not
  7165. (string-prefix-p
  7166. "<2015-03-04 .* \\+1y>"
  7167. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7168. (org-test-with-temp-text
  7169. "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
  7170. (org-todo "DONE")
  7171. (buffer-string)))))
  7172. (should-not
  7173. (string-prefix-p
  7174. "<2015-03-04 .* \\+1y>"
  7175. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7176. (org-test-with-temp-text
  7177. "* TODO H
  7178. <2012-03-29 Thu. +2y>
  7179. #+BEGIN_EXAMPLE
  7180. <2014-03-04 Tue +1y>
  7181. #+END_EXAMPLE"
  7182. (org-todo "DONE")
  7183. (buffer-string)))))
  7184. ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
  7185. ;; entry, record time of last repeat.
  7186. (should-not
  7187. (string-match-p
  7188. ":LAST_REPEAT:"
  7189. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  7190. (org-log-repeat nil))
  7191. (cl-letf (((symbol-function 'org-add-log-setup)
  7192. (lambda (&rest args) nil)))
  7193. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  7194. (org-todo "DONE")
  7195. (buffer-string))))))
  7196. (should
  7197. (string-match-p
  7198. ":LAST_REPEAT:"
  7199. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  7200. (org-log-repeat t))
  7201. (cl-letf (((symbol-function 'org-add-log-setup)
  7202. (lambda (&rest args) nil)))
  7203. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  7204. (org-todo "DONE")
  7205. (buffer-string))))))
  7206. (should
  7207. (string-match-p
  7208. ":LAST_REPEAT:"
  7209. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7210. (cl-letf (((symbol-function 'org-add-log-setup)
  7211. (lambda (&rest args) nil)))
  7212. (org-test-with-temp-text
  7213. "* TODO H\n<2012-03-29 Thu +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
  7214. (org-todo "DONE")
  7215. (buffer-string))))))
  7216. ;; When a SCHEDULED entry has no repeater, remove it upon repeating
  7217. ;; the entry as it is no longer relevant.
  7218. (should-not
  7219. (string-match-p
  7220. "^SCHEDULED:"
  7221. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7222. (org-test-with-temp-text
  7223. "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
  7224. (org-todo "DONE")
  7225. (buffer-string)))))
  7226. ;; Properly advance repeater even when a clock entry is specified
  7227. ;; and `org-log-repeat' is nil.
  7228. (should
  7229. (string-match-p
  7230. "SCHEDULED: <2014-03-29"
  7231. (let ((org-log-repeat nil)
  7232. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7233. (org-test-with-temp-text
  7234. "* TODO H
  7235. SCHEDULED: <2012-03-29 Thu +2y>
  7236. CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] => 6:40"
  7237. (org-todo "DONE")
  7238. (buffer-string)))))
  7239. ;; Make sure that logbook state change record does not get
  7240. ;; duplicated when `org-log-repeat' `org-log-done' are non-nil.
  7241. (should
  7242. (string-match-p
  7243. (rx "* TODO Read book
  7244. SCHEDULED: <2021-06-16 Wed +1d>
  7245. :PROPERTIES:
  7246. :LAST_REPEAT:" (1+ nonl) "
  7247. :END:
  7248. - State \"DONE\" from \"TODO\"" (1+ nonl) buffer-end)
  7249. (let ((org-log-repeat 'time)
  7250. (org-todo-keywords '((sequence "TODO" "|" "DONE(d!)")))
  7251. (org-log-into-drawer nil))
  7252. (org-test-with-temp-text
  7253. "* TODO Read book
  7254. SCHEDULED: <2021-06-15 Tue +1d>"
  7255. (org-todo "DONE")
  7256. (when (memq 'org-add-log-note post-command-hook)
  7257. (org-add-log-note))
  7258. (buffer-string))))))
  7259. (ert-deftest test-org/org-log-done ()
  7260. "Test `org-log-done' specifications."
  7261. ;; nil value.
  7262. (should
  7263. (string=
  7264. "* DONE task"
  7265. (let ((org-log-done nil)
  7266. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7267. (org-test-with-temp-text
  7268. "* TODO task"
  7269. (org-todo "DONE")
  7270. (when (memq 'org-add-log-note post-command-hook)
  7271. (org-add-log-note))
  7272. (buffer-string)))))
  7273. ;; `time' value.
  7274. (should
  7275. (string=
  7276. (format
  7277. "* DONE task
  7278. CLOSED: %s"
  7279. (org-test-with-temp-text ""
  7280. (org-insert-time-stamp (current-time) t t)
  7281. (buffer-string)))
  7282. (let ((org-log-done 'time)
  7283. (org-log-done-with-time t)
  7284. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7285. (org-test-with-temp-text
  7286. "* TODO task"
  7287. (org-todo "DONE")
  7288. (when (memq 'org-add-log-note post-command-hook)
  7289. (org-add-log-note))
  7290. (buffer-string)))))
  7291. (should
  7292. (string=
  7293. (format
  7294. "* DONE task
  7295. CLOSED: %s"
  7296. (org-test-with-temp-text ""
  7297. (org-insert-time-stamp (current-time) nil t)
  7298. (buffer-string)))
  7299. (let ((org-log-done 'time)
  7300. (org-log-done-with-time nil)
  7301. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7302. (org-test-with-temp-text
  7303. "* TODO task"
  7304. (org-todo "DONE")
  7305. (when (memq 'org-add-log-note post-command-hook)
  7306. (org-add-log-note))
  7307. (buffer-string)))))
  7308. ;; TODO: Test `note' value.
  7309. ;; Test startup overrides.
  7310. (should
  7311. (string=
  7312. "#+STARTUP: nologdone
  7313. * DONE task"
  7314. (let ((org-log-done 'time)
  7315. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7316. (org-test-with-temp-text
  7317. "#+STARTUP: nologdone
  7318. <point>* TODO task"
  7319. (org-set-regexps-and-options)
  7320. (org-todo "DONE")
  7321. (when (memq 'org-add-log-note post-command-hook)
  7322. (org-add-log-note))
  7323. (buffer-string)))))
  7324. (should
  7325. (string=
  7326. (format
  7327. "#+STARTUP: logdone
  7328. * DONE task
  7329. CLOSED: %s"
  7330. (org-test-with-temp-text ""
  7331. (org-insert-time-stamp (current-time) t t)
  7332. (buffer-string)))
  7333. (let ((org-log-done nil)
  7334. (org-log-done-with-time t)
  7335. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7336. (org-test-with-temp-text
  7337. "#+STARTUP: logdone
  7338. <point>* TODO task"
  7339. (org-set-regexps-and-options)
  7340. (org-todo "DONE")
  7341. (when (memq 'org-add-log-note post-command-hook)
  7342. (org-add-log-note))
  7343. (buffer-string)))))
  7344. ;; Test local property overrides.
  7345. (should
  7346. (string=
  7347. "* DONE task
  7348. :PROPERTIES:
  7349. :LOGGING: nil
  7350. :END:"
  7351. (let ((org-log-done 'time)
  7352. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7353. (org-test-with-temp-text
  7354. "* TODO task
  7355. :PROPERTIES:
  7356. :LOGGING: nil
  7357. :END:"
  7358. (org-todo "DONE")
  7359. (when (memq 'org-add-log-note post-command-hook)
  7360. (org-add-log-note))
  7361. (buffer-string)))))
  7362. (should
  7363. (string=
  7364. (format
  7365. "* DONE task
  7366. CLOSED: %s
  7367. :PROPERTIES:
  7368. :LOGGING: logdone
  7369. :END:"
  7370. (org-test-with-temp-text ""
  7371. (org-insert-time-stamp (current-time) t t)
  7372. (buffer-string)))
  7373. (let ((org-log-done nil)
  7374. (org-log-done-with-time t)
  7375. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7376. (org-test-with-temp-text
  7377. "* TODO task
  7378. :PROPERTIES:
  7379. :LOGGING: logdone
  7380. :END:"
  7381. (org-todo "DONE")
  7382. (when (memq 'org-add-log-note post-command-hook)
  7383. (org-add-log-note))
  7384. (buffer-string))))))
  7385. ;;; Timestamps API
  7386. (ert-deftest test-org/at-timestamp-p ()
  7387. "Test `org-at-timestamp-p' specifications."
  7388. (should
  7389. (org-test-with-temp-text "<2012-03-29 Thu>"
  7390. (org-at-timestamp-p)))
  7391. (should-not
  7392. (org-test-with-temp-text "2012-03-29 Thu"
  7393. (org-at-timestamp-p)))
  7394. ;; Test return values.
  7395. (should
  7396. (eq 'bracket
  7397. (org-test-with-temp-text "<2012-03-29 Thu>"
  7398. (org-at-timestamp-p))))
  7399. (should
  7400. (eq 'year
  7401. (org-test-with-temp-text "<<point>2012-03-29 Thu>"
  7402. (org-at-timestamp-p))))
  7403. (should
  7404. (eq 'month
  7405. (org-test-with-temp-text "<2012-<point>03-29 Thu>"
  7406. (org-at-timestamp-p))))
  7407. (should
  7408. (eq 'day
  7409. (org-test-with-temp-text "<2012-03-<point>29 Thu>"
  7410. (org-at-timestamp-p))))
  7411. (should
  7412. (eq 'day
  7413. (org-test-with-temp-text "<2012-03-29 T<point>hu>"
  7414. (org-at-timestamp-p))))
  7415. (should
  7416. (wholenump
  7417. (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
  7418. (org-at-timestamp-p))))
  7419. (should
  7420. (eq 'bracket
  7421. (org-test-with-temp-text "<2012-03-29 Thu<point>>"
  7422. (org-at-timestamp-p))))
  7423. (should
  7424. (eq 'after
  7425. (org-test-with-temp-text "<2012-03-29 Thu><point>»"
  7426. (org-at-timestamp-p))))
  7427. ;; Test `inactive' optional argument.
  7428. (should
  7429. (org-test-with-temp-text "[2012-03-29 Thu]"
  7430. (org-at-timestamp-p 'inactive)))
  7431. (should-not
  7432. (org-test-with-temp-text "[2012-03-29 Thu]"
  7433. (org-at-timestamp-p)))
  7434. ;; When optional argument is `agenda', recognize time-stamps in
  7435. ;; planning info line, property drawers and clocks.
  7436. (should
  7437. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7438. (org-at-timestamp-p 'agenda)))
  7439. (should-not
  7440. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7441. (org-at-timestamp-p)))
  7442. (should
  7443. (org-test-with-temp-text
  7444. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7445. (org-at-timestamp-p 'agenda)))
  7446. (should-not
  7447. (org-test-with-temp-text
  7448. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7449. (org-at-timestamp-p)))
  7450. (should
  7451. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7452. (let ((org-agenda-include-inactive-timestamps t))
  7453. (org-at-timestamp-p 'agenda))))
  7454. (should-not
  7455. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7456. (let ((org-agenda-include-inactive-timestamps t))
  7457. (org-at-timestamp-p))))
  7458. (should-not
  7459. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7460. (let ((org-agenda-include-inactive-timestamps t))
  7461. (org-at-timestamp-p 'inactive))))
  7462. ;; When optional argument is `lax', match any part of the document
  7463. ;; with Org timestamp syntax.
  7464. (should
  7465. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7466. (org-at-timestamp-p 'lax)))
  7467. (should-not
  7468. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7469. (org-at-timestamp-p)))
  7470. (should
  7471. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7472. (org-at-timestamp-p 'lax)))
  7473. (should-not
  7474. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7475. (org-at-timestamp-p)))
  7476. (should
  7477. (org-test-with-temp-text
  7478. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7479. (org-at-timestamp-p 'lax)))
  7480. (should-not
  7481. (org-test-with-temp-text
  7482. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7483. (org-at-timestamp-p)))
  7484. ;; Optional argument `lax' also matches inactive timestamps.
  7485. (should
  7486. (org-test-with-temp-text "# [2012-03-29 Thu]<point>"
  7487. (org-at-timestamp-p 'lax))))
  7488. (ert-deftest test-org/time-stamp ()
  7489. "Test `org-time-stamp' specifications."
  7490. ;; Insert chosen time stamp at point.
  7491. (should
  7492. (string-match
  7493. "Te<2014-03-04 .*?>xt"
  7494. (org-test-with-temp-text "Te<point>xt"
  7495. (cl-letf (((symbol-function 'org-read-date)
  7496. (lambda (&rest args)
  7497. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7498. (org-time-stamp nil)
  7499. (buffer-string)))))
  7500. ;; With a prefix argument, also insert time.
  7501. (should
  7502. (string-match
  7503. "Te<2014-03-04 .*? 00:41>xt"
  7504. (org-test-with-temp-text "Te<point>xt"
  7505. (cl-letf (((symbol-function 'org-read-date)
  7506. (lambda (&rest args)
  7507. (apply #'encode-time
  7508. (org-parse-time-string "2014-03-04 00:41")))))
  7509. (org-time-stamp '(4))
  7510. (buffer-string)))))
  7511. ;; With two universal prefix arguments, insert an active timestamp
  7512. ;; with the current time without prompting the user.
  7513. (should
  7514. (string-match
  7515. "Te<2014-03-04 .*? 00:41>xt"
  7516. (org-test-with-temp-text "Te<point>xt"
  7517. (org-test-at-time "2014-03-04 00:41"
  7518. (org-time-stamp '(16))
  7519. (buffer-string)))))
  7520. ;; When optional argument is non-nil, insert an inactive timestamp.
  7521. (should
  7522. (string-match
  7523. "Te\\[2014-03-04 .*?\\]xt"
  7524. (org-test-with-temp-text "Te<point>xt"
  7525. (cl-letf (((symbol-function 'org-read-date)
  7526. (lambda (&rest args)
  7527. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7528. (org-time-stamp nil t)
  7529. (buffer-string)))))
  7530. ;; When called from a timestamp, replace existing one.
  7531. (should
  7532. (string-match
  7533. "<2014-03-04 .*?>"
  7534. (org-test-with-temp-text "<2012-03-29<point> thu.>"
  7535. (cl-letf (((symbol-function 'org-read-date)
  7536. (lambda (&rest args)
  7537. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7538. (org-time-stamp nil)
  7539. (buffer-string)))))
  7540. (should
  7541. (string-match
  7542. "<2014-03-04 .*?>--<2014-03-04 .*?>"
  7543. (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
  7544. (cl-letf (((symbol-function 'org-read-date)
  7545. (lambda (&rest args)
  7546. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7547. (org-time-stamp nil)
  7548. (buffer-string)))))
  7549. ;; When replacing a timestamp, preserve repeater, if any.
  7550. (should
  7551. (string-match
  7552. "<2014-03-04 .*? \\+2y>"
  7553. (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
  7554. (cl-letf (((symbol-function 'org-read-date)
  7555. (lambda (&rest args)
  7556. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7557. (org-time-stamp nil)
  7558. (buffer-string)))))
  7559. ;; When called twice in a raw, build a date range.
  7560. (should
  7561. (string-match
  7562. "<2012-03-29 .*?>--<2014-03-04 .*?>"
  7563. (org-test-with-temp-text "<2012-03-29 thu.><point>"
  7564. (cl-letf (((symbol-function 'org-read-date)
  7565. (lambda (&rest args)
  7566. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7567. (let ((last-command 'org-time-stamp)
  7568. (this-command 'org-time-stamp))
  7569. (org-time-stamp nil))
  7570. (buffer-string))))))
  7571. (ert-deftest test-org/timestamp-has-time-p ()
  7572. "Test `org-timestamp-has-time-p' specifications."
  7573. ;; With time.
  7574. (should
  7575. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7576. (org-timestamp-has-time-p (org-element-context))))
  7577. ;; Without time.
  7578. (should-not
  7579. (org-test-with-temp-text "<2012-03-29 Thu>"
  7580. (org-timestamp-has-time-p (org-element-context)))))
  7581. (ert-deftest test-org/get-repeat ()
  7582. "Test `org-get-repeat' specifications."
  7583. (should
  7584. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
  7585. (org-get-repeat)))
  7586. (should-not
  7587. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
  7588. (org-get-repeat)))
  7589. ;; Return proper repeat string.
  7590. (should
  7591. (equal "+2y"
  7592. (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
  7593. (org-get-repeat))))
  7594. ;; Prevent false positive (commented or verbatim time stamps)
  7595. (should-not
  7596. (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
  7597. (org-get-repeat)))
  7598. (should-not
  7599. (org-test-with-temp-text
  7600. "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
  7601. (org-get-repeat)))
  7602. ;; Return nil when called before first heading.
  7603. (should-not
  7604. (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
  7605. (org-get-repeat)))
  7606. ;; When called with an optional argument, extract repeater from that
  7607. ;; string instead.
  7608. (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
  7609. (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
  7610. (ert-deftest test-org/timestamp-format ()
  7611. "Test `org-timestamp-format' specifications."
  7612. ;; Regular test.
  7613. (should
  7614. (equal
  7615. "2012-03-29 16:40"
  7616. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7617. (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
  7618. ;; Range end.
  7619. (should
  7620. (equal
  7621. "2012-03-29"
  7622. (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
  7623. (org-timestamp-format (org-element-context) "%Y-%m-%d" t)))))
  7624. (ert-deftest test-org/timestamp-split-range ()
  7625. "Test `org-timestamp-split-range' specifications."
  7626. ;; Extract range start (active).
  7627. (should
  7628. (equal '(2012 3 29)
  7629. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7630. (let ((ts (org-timestamp-split-range (org-element-context))))
  7631. (mapcar (lambda (p) (org-element-property p ts))
  7632. '(:year-end :month-end :day-end))))))
  7633. ;; Extract range start (inactive)
  7634. (should
  7635. (equal '(2012 3 29)
  7636. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7637. (let ((ts (org-timestamp-split-range (org-element-context))))
  7638. (mapcar (lambda (p) (org-element-property p ts))
  7639. '(:year-end :month-end :day-end))))))
  7640. ;; Extract range end (active).
  7641. (should
  7642. (equal '(2012 3 30)
  7643. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7644. (let ((ts (org-timestamp-split-range
  7645. (org-element-context) t)))
  7646. (mapcar (lambda (p) (org-element-property p ts))
  7647. '(:year-end :month-end :day-end))))))
  7648. ;; Extract range end (inactive)
  7649. (should
  7650. (equal '(2012 3 30)
  7651. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7652. (let ((ts (org-timestamp-split-range
  7653. (org-element-context) t)))
  7654. (mapcar (lambda (p) (org-element-property p ts))
  7655. '(:year-end :month-end :day-end))))))
  7656. ;; Return the timestamp if not a range.
  7657. (should
  7658. (org-test-with-temp-text "[2012-03-29 Thu]"
  7659. (let* ((ts-orig (org-element-context))
  7660. (ts-copy (org-timestamp-split-range ts-orig)))
  7661. (eq ts-orig ts-copy))))
  7662. (should
  7663. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7664. (let* ((ts-orig (org-element-context))
  7665. (ts-copy (org-timestamp-split-range ts-orig)))
  7666. (eq ts-orig ts-copy)))))
  7667. (ert-deftest test-org/timestamp-translate ()
  7668. "Test `org-timestamp-translate' specifications."
  7669. ;; Translate whole date range.
  7670. (should
  7671. (equal "<29>--<30>"
  7672. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7673. (let ((org-display-custom-times t)
  7674. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7675. (org-timestamp-translate (org-element-context))))))
  7676. ;; Translate date range start.
  7677. (should
  7678. (equal "<29>"
  7679. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7680. (let ((org-display-custom-times t)
  7681. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7682. (org-timestamp-translate (org-element-context) 'start)))))
  7683. ;; Translate date range end.
  7684. (should
  7685. (equal "<30>"
  7686. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7687. (let ((org-display-custom-times t)
  7688. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7689. (org-timestamp-translate (org-element-context) 'end)))))
  7690. ;; Translate time range.
  7691. (should
  7692. (equal "<08>--<16>"
  7693. (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
  7694. (let ((org-display-custom-times t)
  7695. (org-time-stamp-custom-formats '("<%d>" . "<%H>")))
  7696. (org-timestamp-translate (org-element-context))))))
  7697. ;; Translate non-range timestamp.
  7698. (should
  7699. (equal "<29>"
  7700. (org-test-with-temp-text "<2012-03-29 Thu>"
  7701. (let ((org-display-custom-times t)
  7702. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7703. (org-timestamp-translate (org-element-context))))))
  7704. ;; Do not change `diary' timestamps.
  7705. (should
  7706. (equal "<%%(org-float t 4 2)>"
  7707. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7708. (let ((org-display-custom-times t)
  7709. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7710. (org-timestamp-translate (org-element-context)))))))
  7711. (ert-deftest test-org/timestamp-from-string ()
  7712. "Test `org-timestamp-from-string' specifications."
  7713. ;; Return nil if argument is not a valid Org timestamp.
  7714. (should-not (org-timestamp-from-string ""))
  7715. (should-not (org-timestamp-from-string nil))
  7716. (should-not (org-timestamp-from-string "<2012-03-29"))
  7717. ;; Otherwise, return a valid Org timestamp object.
  7718. (should
  7719. (string-match-p "<2012-03-29 .+>"
  7720. (org-element-interpret-data
  7721. (org-timestamp-from-string "<2012-03-29 Thu>"))))
  7722. (should
  7723. (string-match-p "[2014-03-04 .+]"
  7724. (org-element-interpret-data
  7725. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  7726. (ert-deftest test-org/timestamp-from-time ()
  7727. "Test `org-timestamp-from-time' specifications."
  7728. ;; Standard test.
  7729. (should
  7730. (string-match-p
  7731. "<2012-03-29 .+>"
  7732. (org-element-interpret-data
  7733. (org-timestamp-from-time
  7734. (apply #'encode-time
  7735. (org-parse-time-string "<2012-03-29 Thu 16:40>"))))))
  7736. ;; When optional argument WITH-TIME is non-nil, provide time
  7737. ;; information.
  7738. (should
  7739. (string-match-p
  7740. "<2012-03-29 .+ 16:40>"
  7741. (org-element-interpret-data
  7742. (org-timestamp-from-time
  7743. (apply #'encode-time
  7744. (org-parse-time-string "<2012-03-29 Thu 16:40>"))
  7745. t))))
  7746. ;; When optional argument INACTIVE is non-nil, return an inactive
  7747. ;; timestamp.
  7748. (should
  7749. (string-match-p
  7750. "[2012-03-29 .+]"
  7751. (org-element-interpret-data
  7752. (org-timestamp-from-time
  7753. (apply #'encode-time
  7754. (org-parse-time-string "<2012-03-29 Thu 16:40>"))
  7755. nil t)))))
  7756. (ert-deftest test-org/timestamp-to-time ()
  7757. "Test `org-timestamp-to-time' specifications."
  7758. (should
  7759. (equal "2014-03-04"
  7760. (format-time-string
  7761. "%Y-%m-%d"
  7762. (org-timestamp-to-time
  7763. (org-timestamp-from-string "<2014-03-04 Tue>")))))
  7764. (should
  7765. (equal "2014-03-04"
  7766. (format-time-string
  7767. "%Y-%m-%d"
  7768. (org-timestamp-to-time
  7769. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  7770. (should
  7771. (equal "2012-03-29 08:30"
  7772. (format-time-string
  7773. "%Y-%m-%d %H:%M"
  7774. (org-timestamp-to-time
  7775. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")))))
  7776. (should
  7777. (equal "2012-03-29"
  7778. (format-time-string
  7779. "%Y-%m-%d"
  7780. (org-timestamp-to-time
  7781. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")))))
  7782. (should
  7783. (equal "2012-03-29"
  7784. (format-time-string
  7785. "%Y-%m-%d"
  7786. (org-timestamp-to-time
  7787. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")))))
  7788. ;; When optional argument END is non-nil, use end of date range or
  7789. ;; time range.
  7790. (should
  7791. (equal "2012-03-29 16:40"
  7792. (format-time-string
  7793. "%Y-%m-%d %H:%M"
  7794. (org-timestamp-to-time
  7795. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")
  7796. t))))
  7797. (should
  7798. (equal "2014-03-04"
  7799. (format-time-string
  7800. "%Y-%m-%d"
  7801. (org-timestamp-to-time
  7802. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")
  7803. t))))
  7804. (should
  7805. (equal "2014-03-04"
  7806. (format-time-string
  7807. "%Y-%m-%d"
  7808. (org-timestamp-to-time
  7809. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")
  7810. t)))))
  7811. ;;; Visibility
  7812. (ert-deftest test-org/hide-drawer-toggle ()
  7813. "Test `org-hide-drawer-toggle' specifications."
  7814. ;; Error when not at a drawer.
  7815. (should-error
  7816. (org-test-with-temp-text ":fake-drawer:\ncontents"
  7817. (org-hide-drawer-toggle 'off)
  7818. (get-char-property (line-end-position) 'invisible)))
  7819. (should-error
  7820. (org-test-with-temp-text
  7821. "#+begin_example\n<point>:D:\nc\n:END:\n#+end_example"
  7822. (org-hide-drawer-toggle t)))
  7823. ;; Hide drawer.
  7824. (should
  7825. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7826. (org-hide-drawer-toggle)
  7827. (get-char-property (line-end-position) 'invisible)))
  7828. ;; Show drawer unconditionally when optional argument is `off'.
  7829. (should-not
  7830. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7831. (org-hide-drawer-toggle)
  7832. (org-hide-drawer-toggle 'off)
  7833. (get-char-property (line-end-position) 'invisible)))
  7834. ;; Hide drawer unconditionally when optional argument is non-nil.
  7835. (should
  7836. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7837. (org-hide-drawer-toggle t)
  7838. (get-char-property (line-end-position) 'invisible)))
  7839. ;; Do not hide drawer when called from final blank lines.
  7840. (should-not
  7841. (org-test-with-temp-text ":drawer:\ncontents\n:end:\n\n<point>"
  7842. (org-hide-drawer-toggle)
  7843. (goto-char (point-min))
  7844. (get-char-property (line-end-position) 'invisible)))
  7845. ;; Don't leave point in an invisible part of the buffer when hiding
  7846. ;; a drawer away.
  7847. (should-not
  7848. (org-test-with-temp-text ":drawer:\ncontents\n<point>:end:"
  7849. (org-hide-drawer-toggle)
  7850. (get-char-property (point) 'invisible))))
  7851. (ert-deftest test-org/hide-block-toggle ()
  7852. "Test `org-hide-block-toggle' specifications."
  7853. ;; Error when not at a block.
  7854. (should-error
  7855. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
  7856. (org-hide-block-toggle 'off)
  7857. (get-char-property (line-end-position) 'invisible)))
  7858. ;; Hide block.
  7859. (should
  7860. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  7861. (org-hide-block-toggle)
  7862. (get-char-property (line-end-position) 'invisible)))
  7863. (should
  7864. (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
  7865. (org-hide-block-toggle)
  7866. (get-char-property (line-end-position) 'invisible)))
  7867. ;; Show block unconditionally when optional argument is `off'.
  7868. (should-not
  7869. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7870. (org-hide-block-toggle)
  7871. (org-hide-block-toggle 'off)
  7872. (get-char-property (line-end-position) 'invisible)))
  7873. (should-not
  7874. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7875. (org-hide-block-toggle 'off)
  7876. (get-char-property (line-end-position) 'invisible)))
  7877. ;; Hide block unconditionally when optional argument is non-nil.
  7878. (should
  7879. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7880. (org-hide-block-toggle t)
  7881. (get-char-property (line-end-position) 'invisible)))
  7882. (should
  7883. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7884. (org-hide-block-toggle)
  7885. (org-hide-block-toggle t)
  7886. (get-char-property (line-end-position) 'invisible)))
  7887. ;; Do not hide block when called from final blank lines.
  7888. (should-not
  7889. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
  7890. (org-hide-block-toggle)
  7891. (goto-char (point-min))
  7892. (get-char-property (line-end-position) 'invisible)))
  7893. ;; Don't leave point in an invisible part of the buffer when hiding
  7894. ;; a block away.
  7895. (should-not
  7896. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
  7897. (org-hide-block-toggle)
  7898. (get-char-property (point) 'invisible))))
  7899. (ert-deftest test-org/hide-block-toggle-maybe ()
  7900. "Test `org-hide-block-toggle-maybe' specifications."
  7901. (should
  7902. (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
  7903. (org-hide-block-toggle-maybe)))
  7904. (should-not
  7905. (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
  7906. (ert-deftest test-org/show-set-visibility ()
  7907. "Test `org-show-set-visibility' specifications."
  7908. ;; Do not throw an error before first heading.
  7909. (should
  7910. (org-test-with-temp-text "Preamble\n* Headline"
  7911. (org-show-set-visibility 'tree)
  7912. t))
  7913. ;; Test all visibility spans, both on headline and in entry.
  7914. (let ((list-visible-lines
  7915. (lambda (state headerp)
  7916. (org-test-with-temp-text "* Grandmother (0)
  7917. ** Uncle (1)
  7918. *** Heir (2)
  7919. ** Father (3)
  7920. Ancestor text (4)
  7921. *** Sister (5)
  7922. Sibling text (6)
  7923. *** Self (7)
  7924. Match (8)
  7925. **** First born (9)
  7926. Child text (10)
  7927. **** The other child (11)
  7928. *** Brother (12)
  7929. ** Aunt (13)
  7930. "
  7931. (org-cycle t)
  7932. (search-forward (if headerp "Self" "Match"))
  7933. (org-show-set-visibility state)
  7934. (goto-char (point-min))
  7935. (let (result (line 0))
  7936. (while (not (eobp))
  7937. (unless (org-invisible-p2) (push line result))
  7938. (cl-incf line)
  7939. (forward-line))
  7940. (nreverse result))))))
  7941. (should (equal '(0 7) (funcall list-visible-lines 'minimal t)))
  7942. (should (equal '(0 7 8) (funcall list-visible-lines 'minimal nil)))
  7943. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local t)))
  7944. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local nil)))
  7945. (should (equal '(0 3 7) (funcall list-visible-lines 'ancestors t)))
  7946. (should (equal '(0 3 7 8) (funcall list-visible-lines 'ancestors nil)))
  7947. (should (equal '(0 3 7 8 9 10 11)
  7948. (funcall list-visible-lines 'ancestors-full t)))
  7949. (should (equal '(0 3 7 8 9 10 11)
  7950. (funcall list-visible-lines 'ancestors-full nil)))
  7951. (should (equal '(0 3 5 7 12) (funcall list-visible-lines 'lineage t)))
  7952. (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines 'lineage nil)))
  7953. (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines 'tree t)))
  7954. (should (equal '(0 1 3 5 7 8 9 11 12 13)
  7955. (funcall list-visible-lines 'tree nil)))
  7956. (should (equal '(0 1 3 4 5 7 12 13)
  7957. (funcall list-visible-lines 'canonical t)))
  7958. (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
  7959. (funcall list-visible-lines 'canonical nil))))
  7960. ;; When point is hidden in a drawer or a block, make sure to make it
  7961. ;; visible.
  7962. (should-not
  7963. (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
  7964. (org-hide-block-toggle)
  7965. (search-forward "Text")
  7966. (org-show-set-visibility 'minimal)
  7967. (org-invisible-p2)))
  7968. (should-not
  7969. (org-test-with-temp-text ":DRAWER:\nText\n:END:"
  7970. (org-hide-drawer-toggle)
  7971. (search-forward "Text")
  7972. (org-show-set-visibility 'minimal)
  7973. (org-invisible-p2)))
  7974. (should-not
  7975. (org-test-with-temp-text
  7976. "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
  7977. (org-hide-drawer-toggle)
  7978. (forward-line -1)
  7979. (org-hide-block-toggle)
  7980. (search-forward "Text")
  7981. (org-show-set-visibility 'minimal)
  7982. (org-invisible-p2))))
  7983. (defun test-org/copy-visible ()
  7984. "Test `org-copy-visible' specifications."
  7985. (should
  7986. (equal "Foo"
  7987. (org-test-with-temp-text "Foo"
  7988. (let ((kill-ring nil))
  7989. (org-copy-visible (point-min) (point-max))
  7990. (current-kill 0 t)))))
  7991. ;; Skip invisible characters by text property.
  7992. (should
  7993. (equal "Foo"
  7994. (org-test-with-temp-text #("F<hidden>oo" 1 7 (invisible t))
  7995. (let ((kill-ring nil))
  7996. (org-copy-visible (point-min) (point-max))
  7997. (current-kill 0 t)))))
  7998. ;; Skip invisible characters by overlay.
  7999. (should
  8000. (equal "Foo"
  8001. (org-test-with-temp-text "F<hidden>oo"
  8002. (let ((o (make-overlay 2 10)))
  8003. (overlay-put o 'invisible t))
  8004. (let ((kill-ring nil))
  8005. (org-copy-visible (point-min) (point-max))
  8006. (current-kill 0 t)))))
  8007. ;; Handle invisible characters at the beginning and the end of the
  8008. ;; buffer.
  8009. (should
  8010. (equal "Foo"
  8011. (org-test-with-temp-text #("<hidden>Foo" 0 8 (invisible t))
  8012. (let ((kill-ring nil))
  8013. (org-copy-visible (point-min) (point-max))
  8014. (current-kill 0 t)))))
  8015. (should
  8016. (equal "Foo"
  8017. (org-test-with-temp-text #("Foo<hidden>" 3 11 (invisible t))
  8018. (let ((kill-ring nil))
  8019. (org-copy-visible (point-min) (point-max))
  8020. (current-kill 0 t)))))
  8021. ;; Handle multiple visible parts.
  8022. (should
  8023. (equal "abc"
  8024. (org-test-with-temp-text
  8025. #("aXbXc" 1 2 (invisible t) 3 4 (invisible t))
  8026. (let ((kill-ring nil))
  8027. (org-copy-visible (point-min) (point-max))
  8028. (current-kill 0 t))))))
  8029. (ert-deftest test-org/set-visibility-according-to-property ()
  8030. "Test `org-set-visibility-according-to-property' specifications."
  8031. ;; "folded" state.
  8032. (should
  8033. (org-test-with-temp-text
  8034. "
  8035. * a
  8036. :PROPERTIES:
  8037. :VISIBILITY: folded
  8038. :END:
  8039. ** <point>b"
  8040. (org-set-visibility-according-to-property)
  8041. (invisible-p (point))))
  8042. ;; "children" state.
  8043. (should
  8044. (org-test-with-temp-text
  8045. "
  8046. * a
  8047. :PROPERTIES:
  8048. :VISIBILITY: children
  8049. :END:
  8050. ** b
  8051. <point>Contents
  8052. ** c"
  8053. (org-set-visibility-according-to-property)
  8054. (invisible-p (point))))
  8055. (should
  8056. (org-test-with-temp-text
  8057. "
  8058. * a
  8059. :PROPERTIES:
  8060. :VISIBILITY: children
  8061. :END:
  8062. ** b
  8063. Contents
  8064. *** <point>c"
  8065. (org-set-visibility-according-to-property)
  8066. (invisible-p (point))))
  8067. ;; "content" state.
  8068. (should
  8069. (org-test-with-temp-text
  8070. "
  8071. * a
  8072. :PROPERTIES:
  8073. :VISIBILITY: content
  8074. :END:
  8075. ** b
  8076. <point>Contents
  8077. *** c"
  8078. (org-set-visibility-according-to-property)
  8079. (invisible-p (point))))
  8080. (should
  8081. (org-test-with-temp-text
  8082. "
  8083. * a
  8084. :PROPERTIES:
  8085. :VISIBILITY: content
  8086. :END:
  8087. ** b
  8088. Contents
  8089. *** <point>c"
  8090. (org-set-visibility-according-to-property)
  8091. (not (invisible-p (point)))))
  8092. ;; "showall" state.
  8093. (should
  8094. (org-test-with-temp-text
  8095. "
  8096. * a
  8097. :PROPERTIES:
  8098. :VISIBILITY: showall
  8099. :END:
  8100. ** b
  8101. <point>Contents
  8102. *** c"
  8103. (org-set-visibility-according-to-property)
  8104. (not (invisible-p (point)))))
  8105. (should
  8106. (org-test-with-temp-text
  8107. "
  8108. * a
  8109. :PROPERTIES:
  8110. :VISIBILITY: showall
  8111. :END:
  8112. ** b
  8113. Contents
  8114. *** <point>c"
  8115. (org-set-visibility-according-to-property)
  8116. (not (invisible-p (point)))))
  8117. ;; When VISIBILITY properties are nested, ignore inner ones.
  8118. (should
  8119. (org-test-with-temp-text
  8120. "
  8121. * A
  8122. :PROPERTIES:
  8123. :VISIBILITY: folded
  8124. :END:
  8125. ** <point>B
  8126. :PROPERTIES:
  8127. :VISIBILITY: folded
  8128. :END:"
  8129. (org-set-visibility-according-to-property)
  8130. (invisible-p (point)))))
  8131. (ert-deftest test-org/visibility-show-branches ()
  8132. "Test visibility of inline archived subtrees."
  8133. (org-test-with-temp-text
  8134. "* Foo<point>
  8135. ** Bar :ARCHIVE:
  8136. *** Baz
  8137. "
  8138. (org-kill-note-or-show-branches)
  8139. (should (org-invisible-p (- (point-max) 2)))))
  8140. ;;; Yank and Kill
  8141. (ert-deftest test-org/paste-subtree ()
  8142. "Test `org-paste-subtree' specifications."
  8143. ;; Return an error if text to yank is not a set of subtrees.
  8144. (should-error (org-paste-subtree nil "Text"))
  8145. ;; Adjust level according to current one.
  8146. (should
  8147. (equal "* H\n* Text\n"
  8148. (org-test-with-temp-text "* H\n<point>"
  8149. (org-paste-subtree nil "* Text")
  8150. (buffer-string))))
  8151. (should
  8152. (equal "* H1\n** H2\n** Text\n"
  8153. (org-test-with-temp-text "* H1\n** H2\n<point>"
  8154. (org-paste-subtree nil "* Text")
  8155. (buffer-string))))
  8156. ;; When not on a heading, move to next heading before yanking.
  8157. (should
  8158. (equal "* H1\nParagraph\n* Text\n* H2"
  8159. (org-test-with-temp-text "* H1\n<point>Paragraph\n* H2"
  8160. (org-paste-subtree nil "* Text")
  8161. (buffer-string))))
  8162. ;; If point is between two headings, use the deepest level.
  8163. (should
  8164. (equal "* H1\n\n* Text\n* H2"
  8165. (org-test-with-temp-text "* H1\n<point>\n* H2"
  8166. (org-paste-subtree nil "* Text")
  8167. (buffer-string))))
  8168. (should
  8169. (equal "** H1\n\n** Text\n* H2"
  8170. (org-test-with-temp-text "** H1\n<point>\n* H2"
  8171. (org-paste-subtree nil "* Text")
  8172. (buffer-string))))
  8173. (should
  8174. (equal "* H1\n\n** Text\n** H2"
  8175. (org-test-with-temp-text "* H1\n<point>\n** H2"
  8176. (org-paste-subtree nil "* Text")
  8177. (buffer-string))))
  8178. ;; When on an empty heading, after the stars, deduce the new level
  8179. ;; from the number of stars.
  8180. (should
  8181. (equal "*** Text\n"
  8182. (org-test-with-temp-text "*** <point>"
  8183. (org-paste-subtree nil "* Text")
  8184. (buffer-string))))
  8185. ;; Optional argument LEVEL forces a level for the subtree.
  8186. (should
  8187. (equal "* H\n*** Text\n"
  8188. (org-test-with-temp-text "* H<point>"
  8189. (org-paste-subtree 3 "* Text")
  8190. (buffer-string)))))
  8191. (ert-deftest test-org/cut-and-paste-subtree ()
  8192. "Test `org-cut-subtree' and `org-paste-subtree'."
  8193. (should
  8194. (equal
  8195. "* Two
  8196. two
  8197. * One
  8198. "
  8199. (org-test-with-temp-text
  8200. "* One
  8201. <point>* Two
  8202. two
  8203. "
  8204. (call-interactively #'org-cut-subtree)
  8205. (goto-char (point-min))
  8206. (call-interactively #'org-paste-subtree)
  8207. (buffer-string))))
  8208. (should
  8209. (equal
  8210. "* One
  8211. * Two
  8212. "
  8213. (org-test-with-temp-text
  8214. "* One
  8215. <point>* Two
  8216. "
  8217. (call-interactively #'org-cut-subtree)
  8218. (backward-char)
  8219. (call-interactively #'org-paste-subtree)
  8220. (buffer-string)))))
  8221. (provide 'test-org)
  8222. ;;; test-org.el ends here