test-org.el 273 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426
  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. (ert-deftest test-org/get-property-block ()
  395. "Test `org-get-property-block' specifications."
  396. (should
  397. (equal '(14 . 14)
  398. (org-test-with-temp-text ":PROPERTIES:\n:END:\n* H\n"
  399. (org-get-property-block))))
  400. (should
  401. (equal '(14 . 14)
  402. (org-test-with-temp-text ":PROPERTIES:\n:END:\n"
  403. (org-get-property-block))))
  404. ;; Comments above a document property block is ok.
  405. (should
  406. (equal '(18 . 18)
  407. (org-test-with-temp-text "# C\n:PROPERTIES:\n:END:\n"
  408. (org-get-property-block))))
  409. ;; Keywords above a document property block is ok.
  410. (should
  411. (equal '(22 . 22)
  412. (org-test-with-temp-text "# C\n# C\n:PROPERTIES:\n:END:\n"
  413. (org-get-property-block))))
  414. ;; Comments and keywords are allowed before a document property block.
  415. (should
  416. (equal '(18 . 27)
  417. (org-test-with-temp-text "# C\n:PROPERTIES:\n:KEY: V:\n:END:\n"
  418. (org-get-property-block))))
  419. ;; A document property block will not be valid if there are lines
  420. ;; with whitespace above it
  421. (should-not
  422. (org-test-with-temp-text "\n:PROPERTIES:\n:END:\n"
  423. (org-get-property-block)))
  424. (should
  425. (equal '(18 . 18)
  426. (org-test-with-temp-text "* H\n:PROPERTIES:\n:END:\n<point>"
  427. (org-get-property-block))))
  428. (should
  429. (equal "* H\n:PROPERTIES:\n:END:\n"
  430. (org-test-with-temp-text "* H"
  431. (let ((org-adapt-indentation nil))
  432. (org-get-property-block nil 'force))
  433. (buffer-string))))
  434. (should
  435. (equal ":PROPERTIES:\n:END:\n"
  436. (org-test-with-temp-text ""
  437. (org-get-property-block nil 'force)
  438. (buffer-string))))
  439. (should
  440. (equal "* H1\n :PROPERTIES:\n :END:\n* H2"
  441. (org-test-with-temp-text "* H1\n* H2"
  442. (let ((org-adapt-indentation t))
  443. (org-get-property-block nil 'force))
  444. (buffer-string)))))
  445. (ert-deftest test-org/insert-property-drawer ()
  446. "Test `org-insert-property-drawer' specifications."
  447. ;; Insert drawer in empty buffer
  448. (should
  449. (equal ":PROPERTIES:\n:END:\n"
  450. (org-test-with-temp-text ""
  451. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  452. (buffer-string))))
  453. ;; Insert drawer in document header with existing comment and
  454. ;; keyword.
  455. (should
  456. (equal "# C\n:PROPERTIES:\n:END:\n#+TITLE: T"
  457. (org-test-with-temp-text "# C\n#+TITLE: T"
  458. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  459. (buffer-string))))
  460. ;; Insert drawer in document header with existing keyword.
  461. (should
  462. (equal ":PROPERTIES:\n:END:\n#+TITLE: T"
  463. (org-test-with-temp-text "#+TITLE: T"
  464. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  465. (buffer-string))))
  466. (should
  467. (equal ":PROPERTIES:\n:END:"
  468. (org-test-with-temp-text ":PROPERTIES:\n:END:"
  469. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  470. (buffer-string))))
  471. ;; Insert drawer in document header with one existing heading in buffer.
  472. (should
  473. (equal ":PROPERTIES:\n:END:\n\n* T\n"
  474. (org-test-with-temp-text "\n* T\n"
  475. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  476. (buffer-string))))
  477. ;; Insert drawer right after headline if there is no planning line,
  478. ;; or after it otherwise.
  479. (should
  480. (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
  481. (org-test-with-temp-text "* H\nParagraph<point>"
  482. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  483. (buffer-string))))
  484. (should
  485. (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
  486. (org-test-with-temp-text
  487. "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
  488. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  489. (buffer-string))))
  490. ;; Indent inserted drawer.
  491. (should
  492. (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
  493. (org-test-with-temp-text "* H\nParagraph<point>"
  494. (let ((org-adapt-indentation t)) (org-insert-property-drawer))
  495. (buffer-string))))
  496. ;; Handle insertion at eob.
  497. (should
  498. (equal "* H\n:PROPERTIES:\n:END:\n"
  499. (org-test-with-temp-text "* H"
  500. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  501. (buffer-string))))
  502. ;; Skip inlinetasks before point.
  503. (when (featurep 'org-inlinetask)
  504. (should
  505. (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
  506. (org-test-with-temp-text
  507. "* H\n*************** I\n*************** END\nP<point>"
  508. (let ((org-adapt-indentation nil)
  509. (org-inlinetask-min-level 15))
  510. (org-insert-property-drawer))
  511. (buffer-string)))))
  512. ;; Correctly set drawer in an inlinetask.
  513. (when (featurep 'org-inlinetask)
  514. (should
  515. (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
  516. (org-test-with-temp-text
  517. "* H\n*************** I\nP<point>\n*************** END"
  518. (let ((org-adapt-indentation nil)
  519. (org-inlinetask-min-level 15))
  520. (org-insert-property-drawer))
  521. (buffer-string))))))
  522. ;;; Filling
  523. (ert-deftest test-org/fill-element ()
  524. "Test `org-fill-element' specifications."
  525. ;; At an Org table, align it.
  526. (should
  527. (equal "| a |\n"
  528. (org-test-with-temp-text "|a|"
  529. (org-fill-element)
  530. (buffer-string))))
  531. (should
  532. (equal "#+name: table\n| a |\n"
  533. (org-test-with-temp-text "#+name: table\n| a |\n"
  534. (org-fill-element)
  535. (buffer-string))))
  536. ;; At a paragraph, preserve line breaks.
  537. (org-test-with-temp-text "some \\\\\nlong\ntext"
  538. (let ((fill-column 20))
  539. (org-fill-element)
  540. (should (equal (buffer-string) "some \\\\\nlong text"))))
  541. ;; Correctly fill a paragraph when point is at its very end.
  542. (should
  543. (equal "A B"
  544. (org-test-with-temp-text "A\nB"
  545. (let ((fill-column 20))
  546. (goto-char (point-max))
  547. (org-fill-element)
  548. (buffer-string)))))
  549. ;; Correctly fill the last paragraph of a greater element.
  550. (should
  551. (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
  552. (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
  553. (let ((fill-column 8))
  554. (forward-line)
  555. (end-of-line)
  556. (org-fill-element)
  557. (buffer-string)))))
  558. ;; Correctly fill an element in a narrowed buffer.
  559. (should
  560. (equal "01234\n6"
  561. (org-test-with-temp-text "01234 6789"
  562. (let ((fill-column 5))
  563. (narrow-to-region 1 8)
  564. (org-fill-element)
  565. (buffer-string)))))
  566. ;; Handle `adaptive-fill-regexp' in paragraphs.
  567. (should
  568. (equal "> a b"
  569. (org-test-with-temp-text "> a\n> b"
  570. (let ((fill-column 5)
  571. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  572. (org-fill-element)
  573. (buffer-string)))))
  574. ;; Special case: Fill first paragraph when point is at an item or
  575. ;; a plain-list or a footnote reference.
  576. (should
  577. (equal "- A B"
  578. (org-test-with-temp-text "- A\n B"
  579. (let ((fill-column 20))
  580. (org-fill-element)
  581. (buffer-string)))))
  582. (should
  583. (equal "[fn:1] A B"
  584. (org-test-with-temp-text "[fn:1] A\nB"
  585. (let ((fill-column 20))
  586. (org-fill-element)
  587. (buffer-string)))))
  588. (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
  589. (let ((fill-column 20))
  590. (org-fill-element)
  591. (should (equal (buffer-string)
  592. "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
  593. ;; Fill contents of `comment-block' elements.
  594. (should
  595. (equal
  596. (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
  597. (let ((fill-column 20))
  598. (forward-line)
  599. (org-fill-element)
  600. (buffer-string)))
  601. "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
  602. ;; Fill `comment' elements.
  603. (should
  604. (equal " # A B"
  605. (org-test-with-temp-text " # A\n # B"
  606. (let ((fill-column 20))
  607. (org-fill-element)
  608. (buffer-string)))))
  609. ;; Do not mix consecutive comments when filling one of them.
  610. (should
  611. (equal "# A B\n\n# C"
  612. (org-test-with-temp-text "# A\n# B\n\n# C"
  613. (let ((fill-column 20))
  614. (org-fill-element)
  615. (buffer-string)))))
  616. ;; Use commented empty lines as separators when filling comments.
  617. (should
  618. (equal "# A B\n#\n# C"
  619. (org-test-with-temp-text "# A\n# B\n#\n# C"
  620. (let ((fill-column 20))
  621. (org-fill-element)
  622. (buffer-string)))))
  623. ;; Handle `adaptive-fill-regexp' in comments.
  624. (should
  625. (equal "# > a b"
  626. (org-test-with-temp-text "# > a\n# > b"
  627. (let ((fill-column 20)
  628. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  629. (org-fill-element)
  630. (buffer-string)))))
  631. ;; Do nothing at affiliated keywords.
  632. (should
  633. (equal "#+NAME: para\nSome\ntext."
  634. (org-test-with-temp-text "#+NAME: para\nSome\ntext."
  635. (let ((fill-column 20))
  636. (org-fill-element)
  637. (buffer-string)))))
  638. ;; Do not move point after table when filling a table.
  639. (should-not
  640. (org-test-with-temp-text "| a | b |\n| c | d |\n"
  641. (forward-char)
  642. (org-fill-element)
  643. (eobp)))
  644. ;; Do not fill "n" macro, with or without arguments, followed by
  645. ;; a dot or a closing parenthesis since it could be confused with
  646. ;; a numbered bullet.
  647. (should-not
  648. (equal "123456789\n{{{n}}}."
  649. (org-test-with-temp-text "123456789 {{{n}}}."
  650. (let ((fill-column 10))
  651. (org-fill-element)
  652. (buffer-string)))))
  653. (should-not
  654. (equal "123456789\n{{{n}}}\)"
  655. (org-test-with-temp-text "123456789 {{{n}}}\)"
  656. (let ((fill-column 10))
  657. (org-fill-element)
  658. (buffer-string)))))
  659. (should-not
  660. (equal "123456789\n{{{n()}}}."
  661. (org-test-with-temp-text "123456789 {{{n()}}}."
  662. (let ((fill-column 10))
  663. (org-fill-element)
  664. (buffer-string)))))
  665. (should-not
  666. (equal "123456789\n{{{n(counter)}}}."
  667. (org-test-with-temp-text "123456789 {{{n(counter)}}}."
  668. (let ((fill-column 10))
  669. (org-fill-element)
  670. (buffer-string))))))
  671. (ert-deftest test-org/fill-paragraph ()
  672. "Test `org-fill-paragraph' specifications."
  673. ;; Regular test.
  674. (should
  675. (equal "012345678\n9"
  676. (org-test-with-temp-text "012345678 9"
  677. (let ((fill-column 10))
  678. (org-fill-paragraph)
  679. (buffer-string)))))
  680. ;; Fill paragraph even at end of buffer.
  681. (should
  682. (equal "012345678\n9\n"
  683. (org-test-with-temp-text "012345678 9\n<point>"
  684. (let ((fill-column 10))
  685. (org-fill-paragraph)
  686. (buffer-string)))))
  687. ;; Between two paragraphs, fill the next one.
  688. (should
  689. (equal "012345678 9\n\n012345678\n9"
  690. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  691. (let ((fill-column 10))
  692. (org-fill-paragraph)
  693. (buffer-string)))))
  694. (should
  695. (equal "012345678\n9\n\n012345678 9"
  696. (org-test-with-temp-text "012345678 9<point>\n\n012345678 9"
  697. (let ((fill-column 10))
  698. (org-fill-paragraph)
  699. (buffer-string)))))
  700. ;; Fill paragraph in a comment block.
  701. (should
  702. (equal "#+begin_comment\n012345678\n9\n#+end_comment"
  703. (org-test-with-temp-text
  704. "#+begin_comment\n<point>012345678 9\n#+end_comment"
  705. (let ((fill-column 10))
  706. (org-fill-paragraph)
  707. (buffer-string)))))
  708. ;; When a region is selected, fill every paragraph in the region.
  709. (should
  710. (equal "012345678\n9\n\n012345678\n9"
  711. (org-test-with-temp-text "012345678 9\n\n012345678 9"
  712. (let ((fill-column 10))
  713. (transient-mark-mode 1)
  714. (push-mark (point-min) t t)
  715. (goto-char (point-max))
  716. (call-interactively #'org-fill-paragraph)
  717. (buffer-string)))))
  718. (should
  719. (equal "012345678\n9\n\n012345678 9"
  720. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  721. (let ((fill-column 10))
  722. (transient-mark-mode 1)
  723. (push-mark (point) t t)
  724. (goto-char (point-min))
  725. (call-interactively #'org-fill-paragraph)
  726. (buffer-string)))))
  727. (should
  728. (equal "012345678 9\n\n012345678\n9"
  729. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  730. (let ((fill-column 10))
  731. (transient-mark-mode 1)
  732. (push-mark (point) t t)
  733. (goto-char (point-max))
  734. (call-interactively #'org-fill-paragraph)
  735. (buffer-string))))))
  736. (ert-deftest test-org/auto-fill-function ()
  737. "Test auto-filling features."
  738. ;; Auto fill paragraph.
  739. (should
  740. (equal "12345\n7890"
  741. (org-test-with-temp-text "12345 7890"
  742. (let ((fill-column 5))
  743. (end-of-line)
  744. (org-auto-fill-function)
  745. (buffer-string)))))
  746. ;; Auto fill first paragraph in an item.
  747. (should
  748. (equal "- 12345\n 7890"
  749. (org-test-with-temp-text "- 12345 7890"
  750. (let ((fill-column 7))
  751. (end-of-line)
  752. (org-auto-fill-function)
  753. (buffer-string)))))
  754. ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
  755. (should
  756. (equal "> 12345\n 7890"
  757. (org-test-with-temp-text "> 12345 7890"
  758. (let ((fill-column 10)
  759. (adaptive-fill-regexp "[ \t]*>+[ \t]*")
  760. (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
  761. (end-of-line)
  762. (org-auto-fill-function)
  763. (buffer-string)))))
  764. (should
  765. (equal "> 12345\n> 12345\n> 7890"
  766. (org-test-with-temp-text "> 12345\n> 12345 7890"
  767. (let ((fill-column 10)
  768. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  769. (goto-char (point-max))
  770. (org-auto-fill-function)
  771. (buffer-string)))))
  772. (should-not
  773. (equal " 12345\n *12345\n *12345"
  774. (org-test-with-temp-text " 12345\n *12345 12345"
  775. (let ((fill-column 10)
  776. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  777. (goto-char (point-max))
  778. (org-auto-fill-function)
  779. (buffer-string)))))
  780. ;; Auto fill comments.
  781. (should
  782. (equal " # 12345\n # 7890"
  783. (org-test-with-temp-text " # 12345 7890"
  784. (let ((fill-column 10))
  785. (end-of-line)
  786. (org-auto-fill-function)
  787. (buffer-string)))))
  788. ;; A hash within a line isn't a comment.
  789. (should-not
  790. (equal "12345 # 7890\n# 1"
  791. (org-test-with-temp-text "12345 # 7890 1"
  792. (let ((fill-column 12))
  793. (end-of-line)
  794. (org-auto-fill-function)
  795. (buffer-string)))))
  796. ;; Correctly interpret empty prefix.
  797. (should-not
  798. (equal "# a\n# b\nRegular\n# paragraph"
  799. (org-test-with-temp-text "# a\n# b\nRegular paragraph"
  800. (let ((fill-column 12))
  801. (end-of-line 3)
  802. (org-auto-fill-function)
  803. (buffer-string)))))
  804. ;; Comment block: auto fill contents.
  805. (should
  806. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  807. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  808. (let ((fill-column 5))
  809. (forward-line)
  810. (end-of-line)
  811. (org-auto-fill-function)
  812. (buffer-string)))))
  813. (should
  814. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  815. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  816. (let ((fill-column 5))
  817. (forward-line)
  818. (end-of-line)
  819. (org-auto-fill-function)
  820. (buffer-string)))))
  821. ;; Do not fill if a new item could be created.
  822. (should-not
  823. (equal "12345\n- 90"
  824. (org-test-with-temp-text "12345 - 90"
  825. (let ((fill-column 5))
  826. (end-of-line)
  827. (org-auto-fill-function)
  828. (buffer-string)))))
  829. ;; Do not fill if a line break could be introduced.
  830. (should-not
  831. (equal "123\\\\\n7890"
  832. (org-test-with-temp-text "123\\\\ 7890"
  833. (let ((fill-column 6))
  834. (end-of-line)
  835. (org-auto-fill-function)
  836. (buffer-string)))))
  837. ;; Do not fill affiliated keywords.
  838. (should-not
  839. (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
  840. (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
  841. (let ((fill-column 20))
  842. (end-of-line)
  843. (org-auto-fill-function)
  844. (buffer-string))))))
  845. ;;; Indentation
  846. (ert-deftest test-org/indent-line ()
  847. "Test `org-indent-line' specifications."
  848. ;; Do not indent diary sexps, footnote definitions or headlines.
  849. (should
  850. (zerop
  851. (org-test-with-temp-text "%%(org-calendar-holiday)"
  852. (org-indent-line)
  853. (org-get-indentation))))
  854. (should
  855. (zerop
  856. (org-test-with-temp-text "[fn:1] fn"
  857. (let ((org-adapt-indentation t)) (org-indent-line))
  858. (org-get-indentation))))
  859. (should
  860. (zerop
  861. (org-test-with-temp-text "* H"
  862. (org-indent-line)
  863. (org-get-indentation))))
  864. ;; Do not indent before first headline.
  865. (should
  866. (zerop
  867. (org-test-with-temp-text ""
  868. (org-indent-line)
  869. (org-get-indentation))))
  870. ;; Indent according to headline level otherwise, unless
  871. ;; `org-adapt-indentation' is nil.
  872. (should
  873. (= 2
  874. (org-test-with-temp-text "* H\n<point>A"
  875. (let ((org-adapt-indentation t)) (org-indent-line))
  876. (org-get-indentation))))
  877. (should
  878. (= 2
  879. (org-test-with-temp-text "* H\n<point>\nA"
  880. (let ((org-adapt-indentation t)) (org-indent-line))
  881. (org-get-indentation))))
  882. (should
  883. (zerop
  884. (org-test-with-temp-text "* H\n<point>A"
  885. (let ((org-adapt-indentation nil)) (org-indent-line))
  886. (org-get-indentation))))
  887. ;; Indenting preserves point position.
  888. (should
  889. (org-test-with-temp-text "* H\nA<point>B"
  890. (let ((org-adapt-indentation t)) (org-indent-line))
  891. (looking-at "B")))
  892. ;; Do not change indentation at an item or a LaTeX environment.
  893. (should
  894. (= 1
  895. (org-test-with-temp-text "* H\n<point> - A"
  896. (let ((org-adapt-indentation t)) (org-indent-line))
  897. (org-get-indentation))))
  898. (should
  899. (= 1
  900. (org-test-with-temp-text
  901. "\\begin{equation}\n <point>1+1=2\n\\end{equation}"
  902. (org-indent-line)
  903. (org-get-indentation))))
  904. ;; On blank lines at the end of a list, indent like last element
  905. ;; within it if the line is still in the list. If the last element
  906. ;; is an item, indent like its contents. Otherwise, indent like the
  907. ;; whole list.
  908. (should
  909. (= 4
  910. (org-test-with-temp-text "* H\n- A\n - AA\n<point>"
  911. (let ((org-adapt-indentation t)) (org-indent-line))
  912. (org-get-indentation))))
  913. (should
  914. (= 4
  915. (org-test-with-temp-text "* H\n- A\n -\n\n<point>"
  916. (let ((org-adapt-indentation t)) (org-indent-line))
  917. (org-get-indentation))))
  918. (should
  919. (zerop
  920. (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n<point>"
  921. (let ((org-adapt-indentation t)) (org-indent-line))
  922. (org-get-indentation))))
  923. (should
  924. (= 4
  925. (org-test-with-temp-text "* H\n- A\n - \n<point>"
  926. (let ((org-adapt-indentation t)) (org-indent-line))
  927. (org-get-indentation))))
  928. (should
  929. (= 4
  930. (org-test-with-temp-text
  931. "* H\n - \n #+BEGIN_SRC emacs-lisp\n t\n #+END_SRC\n<point>"
  932. (let ((org-adapt-indentation t)) (org-indent-line))
  933. (org-get-indentation))))
  934. (should
  935. (= 2
  936. (org-test-with-temp-text "- A\n B\n\n<point>"
  937. (let ((org-adapt-indentation nil)) (org-indent-line))
  938. (org-get-indentation))))
  939. (should
  940. (= 2
  941. (org-test-with-temp-text
  942. "- A\n \begin{cases} 1 + 1\n \end{cases}\n\n<point>"
  943. (let ((org-adapt-indentation nil)) (org-indent-line))
  944. (org-get-indentation))))
  945. ;; Likewise, on a blank line at the end of a footnote definition,
  946. ;; indent at column 0 if line belongs to the definition. Otherwise,
  947. ;; indent like the definition itself.
  948. (should
  949. (zerop
  950. (org-test-with-temp-text "* H\n[fn:1] Definition\n<point>"
  951. (let ((org-adapt-indentation t)) (org-indent-line))
  952. (org-get-indentation))))
  953. (should
  954. (zerop
  955. (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n<point>"
  956. (let ((org-adapt-indentation t)) (org-indent-line))
  957. (org-get-indentation))))
  958. ;; After the end of the contents of a greater element, indent like
  959. ;; the beginning of the element.
  960. (should
  961. (= 1
  962. (org-test-with-temp-text
  963. " #+BEGIN_CENTER\n Contents\n<point>#+END_CENTER"
  964. (org-indent-line)
  965. (org-get-indentation))))
  966. ;; On blank lines after a paragraph, indent like its last non-empty
  967. ;; line.
  968. (should
  969. (= 1
  970. (org-test-with-temp-text " Paragraph\n\n<point>"
  971. (org-indent-line)
  972. (org-get-indentation))))
  973. ;; At the first line of an element, indent like previous element's
  974. ;; first line, ignoring footnotes definitions and inline tasks, or
  975. ;; according to parent.
  976. (let ((org-adapt-indentation t))
  977. (should
  978. (= 2
  979. (org-test-with-temp-text "A\n\n B\n\nC<point>"
  980. (org-indent-line)
  981. (org-get-indentation))))
  982. (should
  983. (= 1
  984. (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC<point>"
  985. (org-indent-line)
  986. (org-get-indentation))))
  987. (should
  988. (= 1
  989. (org-test-with-temp-text
  990. " #+BEGIN_CENTER\n<point> Contents\n#+END_CENTER"
  991. (org-indent-line)
  992. (org-get-indentation)))))
  993. ;; Within code part of a source block, use language major mode if
  994. ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
  995. ;; according to line above.
  996. (should
  997. (= 6
  998. (org-test-with-temp-text
  999. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  1000. (let ((org-src-tab-acts-natively t)
  1001. (org-edit-src-content-indentation 0))
  1002. (org-indent-line))
  1003. (org-get-indentation))))
  1004. (should
  1005. (= 1
  1006. (org-test-with-temp-text
  1007. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  1008. (let ((org-src-tab-acts-natively nil)
  1009. (org-edit-src-content-indentation 0))
  1010. (org-indent-line))
  1011. (org-get-indentation))))
  1012. ;; Otherwise, indent like the first non-blank line above.
  1013. (should
  1014. (zerop
  1015. (org-test-with-temp-text
  1016. "#+BEGIN_CENTER\nline1\n\n<point> line2\n#+END_CENTER"
  1017. (org-indent-line)
  1018. (org-get-indentation))))
  1019. ;; Align node properties according to `org-property-format'. Handle
  1020. ;; nicely empty values.
  1021. (should
  1022. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1023. (org-test-with-temp-text
  1024. "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
  1025. (let ((org-property-format "%-10s %s")) (org-indent-line))
  1026. (buffer-string))))
  1027. (should
  1028. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1029. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
  1030. (let ((org-property-format "%-10s %s")) (org-indent-line))
  1031. (buffer-string)))))
  1032. (ert-deftest test-org/indent-region ()
  1033. "Test `org-indent-region' specifications."
  1034. ;; Indent paragraph.
  1035. (let ((org-adapt-indentation t))
  1036. (should
  1037. (equal "A\nB\nC"
  1038. (org-test-with-temp-text " A\nB\n C"
  1039. (org-indent-region (point-min) (point-max))
  1040. (buffer-string)))))
  1041. ;; Indent greater elements along with their contents.
  1042. (should
  1043. (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
  1044. (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
  1045. (org-indent-region (point-min) (point-max))
  1046. (buffer-string))))
  1047. ;; Ignore contents of verse blocks. Only indent block delimiters.
  1048. (should
  1049. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1050. (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1051. (org-indent-region (point-min) (point-max))
  1052. (buffer-string))))
  1053. (let ((org-adapt-indentation t))
  1054. (should
  1055. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1056. (org-test-with-temp-text " #+BEGIN_VERSE\n A\n B\n #+END_VERSE"
  1057. (org-indent-region (point-min) (point-max))
  1058. (buffer-string)))))
  1059. ;; Indent example blocks as a single block, unless indentation
  1060. ;; should be preserved. In this case only indent the block markers.
  1061. (should
  1062. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1063. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1064. (org-indent-region (point-min) (point-max))
  1065. (buffer-string))))
  1066. (let ((org-adapt-indentation t))
  1067. (should
  1068. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1069. (org-test-with-temp-text " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1070. (org-indent-region (point-min) (point-max))
  1071. (buffer-string))))
  1072. (should
  1073. (equal "#+BEGIN_EXAMPLE -i\n A\n B\n#+END_EXAMPLE"
  1074. (org-test-with-temp-text
  1075. " #+BEGIN_EXAMPLE -i\n A\n B\n #+END_EXAMPLE"
  1076. (org-indent-region (point-min) (point-max))
  1077. (buffer-string))))
  1078. (should
  1079. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1080. (org-test-with-temp-text
  1081. " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1082. (let ((org-src-preserve-indentation t))
  1083. (org-indent-region (point-min) (point-max)))
  1084. (buffer-string)))))
  1085. ;; Treat export blocks as a whole.
  1086. (should
  1087. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1088. (org-test-with-temp-text "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1089. (org-indent-region (point-min) (point-max))
  1090. (buffer-string))))
  1091. (let ((org-adapt-indentation t))
  1092. (should
  1093. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1094. (org-test-with-temp-text
  1095. " #+BEGIN_EXPORT latex\n A\n B\n #+END_EXPORT"
  1096. (org-indent-region (point-min) (point-max))
  1097. (buffer-string)))))
  1098. ;; Indent according to mode if `org-src-tab-acts-natively' is
  1099. ;; non-nil. Otherwise, do not indent code at all.
  1100. (should
  1101. (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
  1102. (org-test-with-temp-text
  1103. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1104. (let ((org-src-tab-acts-natively t)
  1105. (org-edit-src-content-indentation 0))
  1106. (org-indent-region (point-min) (point-max)))
  1107. (buffer-string))))
  1108. (should
  1109. (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1110. (org-test-with-temp-text
  1111. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1112. (let ((org-src-tab-acts-natively nil)
  1113. (org-edit-src-content-indentation 0))
  1114. (org-indent-region (point-min) (point-max)))
  1115. (buffer-string))))
  1116. ;; Align node properties according to `org-property-format'. Handle
  1117. ;; nicely empty values.
  1118. (should
  1119. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1120. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
  1121. (let ((org-property-format "%-10s %s")
  1122. (org-adapt-indentation nil))
  1123. (org-indent-region (point) (point-max)))
  1124. (buffer-string))))
  1125. (should
  1126. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1127. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
  1128. (let ((org-property-format "%-10s %s")
  1129. (org-adapt-indentation nil))
  1130. (org-indent-region (point) (point-max)))
  1131. (buffer-string))))
  1132. ;; Indent plain lists.
  1133. (let ((org-adapt-indentation t))
  1134. (should
  1135. (equal "- A\n B\n - C\n\n D"
  1136. (org-test-with-temp-text "- A\n B\n - C\n\n D"
  1137. (org-indent-region (point-min) (point-max))
  1138. (buffer-string))))
  1139. (should
  1140. (equal "- A\n\n- B"
  1141. (org-test-with-temp-text " - A\n\n - B"
  1142. (org-indent-region (point-min) (point-max))
  1143. (buffer-string)))))
  1144. ;; Indent footnote definitions.
  1145. (should
  1146. (equal "[fn:1] Definition\n\nDefinition"
  1147. (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
  1148. (org-indent-region (point-min) (point-max))
  1149. (buffer-string))))
  1150. ;; Special case: Start indenting on a blank line.
  1151. (should
  1152. (equal "\nParagraph"
  1153. (org-test-with-temp-text "\n Paragraph"
  1154. (org-indent-region (point-min) (point-max))
  1155. (buffer-string)))))
  1156. ;;; Editing
  1157. (ert-deftest test-org/delete-indentation ()
  1158. "Test `org-delete-indentation' specifications."
  1159. ;; Regular test.
  1160. (should (equal "foo bar"
  1161. (org-test-with-temp-text
  1162. "foo \n bar<point>"
  1163. (org-delete-indentation)
  1164. (buffer-string))))
  1165. ;; With optional argument.
  1166. (should (equal "foo bar"
  1167. (org-test-with-temp-text
  1168. "foo<point> \n bar"
  1169. (org-delete-indentation t)
  1170. (buffer-string))))
  1171. ;; At headline text should be appended to the headline text.
  1172. (should
  1173. (equal"* foo bar :tag:"
  1174. (let (org-auto-align-tags)
  1175. (org-test-with-temp-text
  1176. "* foo :tag:\n bar<point>"
  1177. (org-delete-indentation)
  1178. (buffer-string)))))
  1179. (should
  1180. (equal "* foo bar :tag:"
  1181. (let (org-auto-align-tags)
  1182. (org-test-with-temp-text
  1183. "* foo <point>:tag:\n bar"
  1184. (org-delete-indentation t)
  1185. (buffer-string))))))
  1186. (ert-deftest test-org/return ()
  1187. "Test `org-return' specifications."
  1188. ;; Regular test.
  1189. (should
  1190. (equal "Para\ngraph"
  1191. (org-test-with-temp-text "Para<point>graph"
  1192. (org-return)
  1193. (buffer-string))))
  1194. ;; With optional argument, indent line.
  1195. (should
  1196. (equal " Para\n graph"
  1197. (org-test-with-temp-text " Para<point>graph"
  1198. (org-return t)
  1199. (buffer-string))))
  1200. ;; On a table, call `org-table-next-row'.
  1201. (should
  1202. (org-test-with-temp-text "| <point>a |\n| b |"
  1203. (org-return)
  1204. (looking-at-p "b")))
  1205. ;; Open link or timestamp under point when `org-return-follows-link'
  1206. ;; is non-nil.
  1207. (should
  1208. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1209. (let ((org-return-follows-link t)
  1210. (org-link-search-must-match-exact-headline nil))
  1211. (org-return))
  1212. (looking-at-p "<<target>>")))
  1213. (should-not
  1214. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1215. (let ((org-return-follows-link nil)) (org-return))
  1216. (looking-at-p "<<target>>")))
  1217. (should
  1218. (org-test-with-temp-text "* [[b][a<point>]]\n* b"
  1219. (let ((org-return-follows-link t)) (org-return))
  1220. (looking-at-p "* b")))
  1221. (should
  1222. (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
  1223. (let ((org-return-follows-link t)
  1224. (org-link-search-must-match-exact-headline nil))
  1225. (org-return))
  1226. (looking-at-p "<<target>>")))
  1227. (should-not
  1228. (org-test-with-temp-text "Link [[target]]<point> <<target>>"
  1229. (let ((org-return-follows-link t)
  1230. (org-link-search-must-match-exact-headline nil))
  1231. (org-return))
  1232. (looking-at-p "<<target>>")))
  1233. ;; When `org-return-follows-link' is non-nil, tolerate links and
  1234. ;; timestamps in comments, node properties, etc.
  1235. (should
  1236. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1237. (let ((org-return-follows-link t)
  1238. (org-link-search-must-match-exact-headline nil))
  1239. (org-return))
  1240. (looking-at-p "<<target>>")))
  1241. (should-not
  1242. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1243. (let ((org-return-follows-link nil)) (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 t)
  1248. (org-link-search-must-match-exact-headline nil))
  1249. (org-return))
  1250. (looking-at-p "<<target>>")))
  1251. ;; Non-nil `org-return-follows-link' ignores read-only state of
  1252. ;; a buffer.
  1253. (should
  1254. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1255. (let ((org-return-follows-link t)
  1256. (org-link-search-must-match-exact-headline nil))
  1257. (setq buffer-read-only t)
  1258. (call-interactively #'org-return))
  1259. (looking-at-p "<<target>>")))
  1260. ;; `org-return-follows-link' handle multi-line lines.
  1261. (should
  1262. (org-test-with-temp-text
  1263. "[[target][This is a very\n long description<point>]]\n <<target>>"
  1264. (let ((org-return-follows-link t)
  1265. (org-link-search-must-match-exact-headline nil))
  1266. (org-return))
  1267. (looking-at-p "<<target>>")))
  1268. (should-not
  1269. (org-test-with-temp-text
  1270. "[[target][This is a very\n long description]]<point>\n <<target>>"
  1271. (let ((org-return-follows-link t)
  1272. (org-link-search-must-match-exact-headline nil))
  1273. (org-return))
  1274. (looking-at-p "<<target>>")))
  1275. ;; However, do not open link when point is in a table.
  1276. (should
  1277. (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
  1278. (let ((org-return-follows-link t)) (org-return))
  1279. (looking-at-p "between")))
  1280. ;; Special case: in a list, when indenting, do not break structure.
  1281. (should
  1282. (equal "- A\n B"
  1283. (org-test-with-temp-text "- A <point>B"
  1284. (org-return t)
  1285. (buffer-string))))
  1286. (should
  1287. (equal "- A\n\n- B"
  1288. (org-test-with-temp-text "- A\n<point>- B"
  1289. (org-return t)
  1290. (buffer-string))))
  1291. ;; On tags part of a headline, add a newline below it instead of
  1292. ;; breaking it.
  1293. (should
  1294. (equal "* H :tag:\n"
  1295. (org-test-with-temp-text "* H :<point>tag:"
  1296. (org-return)
  1297. (buffer-string))))
  1298. ;; Before headline text, add a newline below it instead of breaking
  1299. ;; it.
  1300. (should
  1301. (equal "* TODO H :tag:\n"
  1302. (org-test-with-temp-text "* <point>TODO H :tag:"
  1303. (org-return)
  1304. (buffer-string))))
  1305. (should
  1306. (equal "* TODO [#B] H :tag:\n"
  1307. (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
  1308. (org-return)
  1309. (buffer-string))))
  1310. (should ;TODO are case-sensitive
  1311. (equal "* \nTodo"
  1312. (org-test-with-temp-text "* <point>Todo"
  1313. (org-return)
  1314. (buffer-string))))
  1315. ;; At headline text, break headline text but preserve tags.
  1316. (should
  1317. (equal "* TODO [#B] foo :tag:\nbar"
  1318. (let (org-auto-align-tags)
  1319. (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
  1320. (org-return)
  1321. (buffer-string)))))
  1322. ;; At bol of headline insert newline.
  1323. (should
  1324. (equal "\n* h"
  1325. (org-test-with-temp-text "<point>* h"
  1326. (org-return)
  1327. (buffer-string))))
  1328. ;; Refuse to leave invalid headline in buffer.
  1329. (should
  1330. (equal "* h\n"
  1331. (org-test-with-temp-text "*<point> h"
  1332. (org-return)
  1333. (buffer-string))))
  1334. ;; Before first column or after last one in a table, split the
  1335. ;; table.
  1336. (should
  1337. (equal "| a |\n\n| b |"
  1338. (org-test-with-temp-text "| a |\n<point>| b |"
  1339. (org-return)
  1340. (buffer-string))))
  1341. (should
  1342. (equal "| a |\n\n| b |"
  1343. (org-test-with-temp-text "| a |<point>\n| b |"
  1344. (org-return)
  1345. (buffer-string))))
  1346. ;; Do not auto-fill on hitting <RET> inside a property drawer.
  1347. (should
  1348. (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:"
  1349. (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:"
  1350. (setq-local fill-column 10)
  1351. (auto-fill-mode 1)
  1352. (org-return)
  1353. (buffer-string)))))
  1354. (ert-deftest test-org/with-electric-indent ()
  1355. "Test RET and C-j specifications with `electric-indent-mode' on."
  1356. ;; Call commands interactively, since this is how `newline' knows it
  1357. ;; must run `post-self-insert-hook'.
  1358. ;;
  1359. ;; RET, like `newline', should indent.
  1360. (should
  1361. (equal " Para\n graph"
  1362. (org-test-with-temp-text " Para<point>graph"
  1363. (electric-indent-local-mode 1)
  1364. (call-interactively 'org-return)
  1365. (buffer-string))))
  1366. (should
  1367. (equal "- item1\n item2"
  1368. (org-test-with-temp-text "- item1<point>item2"
  1369. (electric-indent-local-mode 1)
  1370. (call-interactively 'org-return)
  1371. (buffer-string))))
  1372. ;; TODO: test more values of `org-adapt-indentation'.
  1373. (let ((org-adapt-indentation t))
  1374. (should
  1375. (equal "* heading\n body"
  1376. (org-test-with-temp-text "* heading<point>body"
  1377. (electric-indent-local-mode 1)
  1378. (call-interactively 'org-return)
  1379. (buffer-string)))))
  1380. ;; C-j, like `electric-newline-and-maybe-indent', should not indent.
  1381. (should
  1382. (equal " Para\ngraph"
  1383. (org-test-with-temp-text " Para<point>graph"
  1384. (electric-indent-local-mode 1)
  1385. (call-interactively 'org-return-and-maybe-indent)
  1386. (buffer-string))))
  1387. (should
  1388. (equal "- item1\nitem2"
  1389. (org-test-with-temp-text "- item1<point>item2"
  1390. (electric-indent-local-mode 1)
  1391. (call-interactively 'org-return-and-maybe-indent)
  1392. (buffer-string))))
  1393. ;; TODO: test more values of `org-adapt-indentation'.
  1394. (let ((org-adapt-indentation t))
  1395. (should
  1396. (equal "* heading\nbody"
  1397. (org-test-with-temp-text "* heading<point>body"
  1398. (electric-indent-local-mode 1)
  1399. (call-interactively 'org-return-and-maybe-indent)
  1400. (buffer-string))))))
  1401. (ert-deftest test-org/without-electric-indent ()
  1402. "Test RET and C-j specifications with `electric-indent-mode' off."
  1403. ;; Call commands interactively, since this is how `newline' knows it
  1404. ;; must run `post-self-insert-hook'.
  1405. ;;
  1406. ;; RET, like `newline', should not indent.
  1407. (should
  1408. (equal " Para\ngraph"
  1409. (org-test-with-temp-text " Para<point>graph"
  1410. (electric-indent-local-mode 0)
  1411. (call-interactively 'org-return)
  1412. (buffer-string))))
  1413. (should
  1414. (equal "- item1\nitem2"
  1415. (org-test-with-temp-text "- item1<point>item2"
  1416. (electric-indent-local-mode 0)
  1417. (call-interactively 'org-return)
  1418. (buffer-string))))
  1419. (should
  1420. (equal "* heading\nbody"
  1421. (org-test-with-temp-text "* heading<point>body"
  1422. (electric-indent-local-mode 0)
  1423. (call-interactively 'org-return)
  1424. (buffer-string))))
  1425. ;; C-j, like `electric-newline-and-maybe-indent', should indent.
  1426. (should
  1427. (equal " Para\n graph"
  1428. (org-test-with-temp-text " Para<point>graph"
  1429. (electric-indent-local-mode 0)
  1430. (call-interactively 'org-return-and-maybe-indent)
  1431. (buffer-string))))
  1432. (should
  1433. (equal "- item1\n item2"
  1434. (org-test-with-temp-text "- item1<point>item2"
  1435. (electric-indent-local-mode 0)
  1436. (call-interactively 'org-return-and-maybe-indent)
  1437. (buffer-string))))
  1438. ;; TODO: test more values of `org-adapt-indentation'.
  1439. (let ((org-adapt-indentation t))
  1440. (should
  1441. (equal "* heading\n body"
  1442. (org-test-with-temp-text "* heading<point>body"
  1443. (electric-indent-local-mode 0)
  1444. (call-interactively 'org-return-and-maybe-indent)
  1445. (buffer-string))))))
  1446. (ert-deftest test-org/meta-return ()
  1447. "Test M-RET (`org-meta-return') specifications."
  1448. ;; In a table field insert a row above.
  1449. (should
  1450. (org-test-with-temp-text "| a |"
  1451. (forward-char)
  1452. (org-meta-return)
  1453. (forward-line -1)
  1454. (looking-at "| |$")))
  1455. ;; In a paragraph change current line into a header.
  1456. (should
  1457. (org-test-with-temp-text "a"
  1458. (org-meta-return)
  1459. (beginning-of-line)
  1460. (looking-at "\* a$")))
  1461. ;; In an item insert an item, in this case above.
  1462. (should
  1463. (org-test-with-temp-text "- a"
  1464. (org-meta-return)
  1465. (beginning-of-line)
  1466. (looking-at "- $")))
  1467. ;; In a drawer and item insert an item, in this case above.
  1468. (should
  1469. (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
  1470. (forward-line)
  1471. (org-meta-return)
  1472. (beginning-of-line)
  1473. (looking-at "- $"))))
  1474. (ert-deftest test-org/insert-heading ()
  1475. "Test `org-insert-heading' specifications."
  1476. ;; In an empty buffer, insert a new headline.
  1477. (should
  1478. (equal "* "
  1479. (org-test-with-temp-text ""
  1480. (org-insert-heading)
  1481. (buffer-string))))
  1482. ;; At the beginning of a line, turn it into a headline.
  1483. (should
  1484. (equal "* P"
  1485. (org-test-with-temp-text "<point>P"
  1486. (org-insert-heading)
  1487. (buffer-string))))
  1488. ;; In the middle of a line, split the line if allowed, otherwise,
  1489. ;; insert the headline at its end.
  1490. (should
  1491. (equal "Para\n* graph"
  1492. (org-test-with-temp-text "Para<point>graph"
  1493. (let ((org-M-RET-may-split-line '((default . t))))
  1494. (org-insert-heading))
  1495. (buffer-string))))
  1496. (should
  1497. (equal "Paragraph\n* "
  1498. (org-test-with-temp-text "Para<point>graph"
  1499. (let ((org-M-RET-may-split-line '((default . nil))))
  1500. (org-insert-heading))
  1501. (buffer-string))))
  1502. ;; At the beginning of a headline, create one above.
  1503. (should
  1504. (equal "* \n* H"
  1505. (org-test-with-temp-text "* H"
  1506. (org-insert-heading)
  1507. (buffer-string))))
  1508. ;; In the middle of a headline, split it if allowed.
  1509. (should
  1510. (equal "* H\n* 1"
  1511. (org-test-with-temp-text "* H<point>1"
  1512. (let ((org-M-RET-may-split-line '((headline . t))))
  1513. (org-insert-heading))
  1514. (buffer-string))))
  1515. (should
  1516. (equal "* H1\n* "
  1517. (org-test-with-temp-text "* H<point>1"
  1518. (let ((org-M-RET-may-split-line '((headline . nil))))
  1519. (org-insert-heading))
  1520. (buffer-string))))
  1521. ;; However, splitting cannot happen on TODO keywords, priorities or
  1522. ;; tags.
  1523. (should
  1524. (equal "* TODO H1\n* "
  1525. (org-test-with-temp-text "* TO<point>DO H1"
  1526. (let ((org-M-RET-may-split-line '((headline . t))))
  1527. (org-insert-heading))
  1528. (buffer-string))))
  1529. (should
  1530. (equal "* [#A] H1\n* "
  1531. (org-test-with-temp-text "* [#<point>A] H1"
  1532. (let ((org-M-RET-may-split-line '((headline . t))))
  1533. (org-insert-heading))
  1534. (buffer-string))))
  1535. (should
  1536. (equal "* H1 :tag:\n* "
  1537. (org-test-with-temp-text "* H1 :ta<point>g:"
  1538. (let ((org-M-RET-may-split-line '((headline . t))))
  1539. (org-insert-heading))
  1540. (buffer-string))))
  1541. ;; New headline level depends on the level of the headline above.
  1542. (should
  1543. (equal "** H\n** P"
  1544. (org-test-with-temp-text "** H\n<point>P"
  1545. (org-insert-heading)
  1546. (buffer-string))))
  1547. (should
  1548. (equal "** H\nPara\n** graph"
  1549. (org-test-with-temp-text "** H\nPara<point>graph"
  1550. (let ((org-M-RET-may-split-line '((default . t))))
  1551. (org-insert-heading))
  1552. (buffer-string))))
  1553. (should
  1554. (equal "** \n** H"
  1555. (org-test-with-temp-text "** H"
  1556. (org-insert-heading)
  1557. (buffer-string))))
  1558. ;; When called with one universal argument, insert a new headline at
  1559. ;; the end of the current subtree, independently on the position of
  1560. ;; point.
  1561. (should
  1562. (equal
  1563. "* "
  1564. (org-test-with-temp-text ""
  1565. (let ((org-insert-heading-respect-content nil))
  1566. (org-insert-heading '(4)))
  1567. (buffer-string))))
  1568. (should
  1569. (equal
  1570. "entry
  1571. * "
  1572. (org-test-with-temp-text "entry"
  1573. (let ((org-insert-heading-respect-content nil))
  1574. (org-insert-heading '(4)))
  1575. (buffer-string))))
  1576. (should
  1577. (equal
  1578. "* H1\n** H2\n* "
  1579. (org-test-with-temp-text "* H1\n** H2"
  1580. (let ((org-insert-heading-respect-content nil))
  1581. (org-insert-heading '(4)))
  1582. (buffer-string))))
  1583. (should
  1584. (equal
  1585. "* H1\n** H2\n* "
  1586. (org-test-with-temp-text "* H<point>1\n** H2"
  1587. (let ((org-insert-heading-respect-content nil))
  1588. (org-insert-heading '(4)))
  1589. (buffer-string))))
  1590. ;; When called with two universal arguments, insert a new headline
  1591. ;; at the end of the grandparent subtree.
  1592. (should
  1593. (equal "* H1\n** H3\n- item\n** H2\n** "
  1594. (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
  1595. (let ((org-insert-heading-respect-content nil))
  1596. (org-insert-heading '(16)))
  1597. (buffer-string))))
  1598. ;; When optional TOP-LEVEL argument is non-nil, always insert
  1599. ;; a level 1 heading.
  1600. (should
  1601. (equal "* H1\n** H2\n* "
  1602. (org-test-with-temp-text "* H1\n** H2<point>"
  1603. (org-insert-heading nil nil t)
  1604. (buffer-string))))
  1605. (should
  1606. (equal "* H1\n- item\n* "
  1607. (org-test-with-temp-text "* H1\n- item<point>"
  1608. (org-insert-heading nil nil t)
  1609. (buffer-string))))
  1610. ;; Obey `org-blank-before-new-entry'.
  1611. (should
  1612. (equal "* H1\n\n* "
  1613. (org-test-with-temp-text "* H1<point>"
  1614. (let ((org-blank-before-new-entry '((heading . t))))
  1615. (org-insert-heading))
  1616. (buffer-string))))
  1617. (should
  1618. (equal "* H1\n* "
  1619. (org-test-with-temp-text "* H1<point>"
  1620. (let ((org-blank-before-new-entry '((heading . nil))))
  1621. (org-insert-heading))
  1622. (buffer-string))))
  1623. (should
  1624. (equal "* H1\n* H2\n* "
  1625. (org-test-with-temp-text "* H1\n* H2<point>"
  1626. (let ((org-blank-before-new-entry '((heading . auto))))
  1627. (org-insert-heading))
  1628. (buffer-string))))
  1629. (should
  1630. (equal "* H1\n\n* H2\n\n* "
  1631. (org-test-with-temp-text "* H1\n\n* H2<point>"
  1632. (let ((org-blank-before-new-entry '((heading . auto))))
  1633. (org-insert-heading))
  1634. (buffer-string))))
  1635. ;; Corner case: correctly insert a headline after an empty one.
  1636. (should
  1637. (equal "* \n* "
  1638. (org-test-with-temp-text "* <point>"
  1639. (org-insert-heading)
  1640. (buffer-string))))
  1641. (should
  1642. (org-test-with-temp-text "* <point>\n"
  1643. (org-insert-heading)
  1644. (looking-at-p "\n\\'")))
  1645. ;; Do not insert spurious headlines when inserting a new headline.
  1646. (should
  1647. (equal "* H1\n* H2\n* \n"
  1648. (org-test-with-temp-text "* H1\n* H2<point>\n"
  1649. (org-insert-heading)
  1650. (buffer-string))))
  1651. ;; Preserve visibility at beginning of line. In particular, when
  1652. ;; removing spurious blank lines, do not visually merge heading with
  1653. ;; the line visible above.
  1654. (should-not
  1655. (org-test-with-temp-text "* H1<point>\nContents\n\n* H2\n"
  1656. (org-overview)
  1657. (let ((org-blank-before-new-entry '((heading . nil))))
  1658. (org-insert-heading '(4)))
  1659. (invisible-p (line-end-position 0))))
  1660. ;; Properly handle empty lines when forcing a headline below current
  1661. ;; one.
  1662. (should
  1663. (equal "* H1\n\n* H\n\n* "
  1664. (org-test-with-temp-text "* H1\n\n* H<point>"
  1665. (let ((org-blank-before-new-entry '((heading . t))))
  1666. (org-insert-heading '(4))
  1667. (buffer-string))))))
  1668. (ert-deftest test-org/insert-todo-heading-respect-content ()
  1669. "Test `org-insert-todo-heading-respect-content' specifications."
  1670. ;; Create a TODO heading.
  1671. (should
  1672. (org-test-with-temp-text "* H1\n Body"
  1673. (org-insert-todo-heading-respect-content)
  1674. (nth 2 (org-heading-components))))
  1675. ;; Add headline at the end of the first subtree
  1676. (should
  1677. (equal
  1678. "* TODO "
  1679. (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
  1680. (org-insert-todo-heading-respect-content)
  1681. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1682. ;; In a list, do not create a new item.
  1683. (should
  1684. (equal
  1685. "* TODO "
  1686. (org-test-with-temp-text "* H\n- an item\n- another one"
  1687. (search-forward "an ")
  1688. (org-insert-todo-heading-respect-content)
  1689. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1690. ;; Use the same TODO keyword as current heading.
  1691. (should
  1692. (equal
  1693. "* TODO \n"
  1694. (org-test-with-temp-text "* TODO\n** WAITING\n"
  1695. (org-insert-todo-heading-respect-content)
  1696. (buffer-substring-no-properties (line-beginning-position) (point-max))))))
  1697. (ert-deftest test-org/clone-with-time-shift ()
  1698. "Test `org-clone-subtree-with-time-shift'."
  1699. ;; Raise an error before first heading.
  1700. (should-error
  1701. (org-test-with-temp-text ""
  1702. (org-clone-subtree-with-time-shift 1)))
  1703. ;; Raise an error on invalid number of clones.
  1704. (should-error
  1705. (org-test-with-temp-text "* Clone me"
  1706. (org-clone-subtree-with-time-shift -1)))
  1707. ;; Clone non-repeating once.
  1708. (should
  1709. (equal "\
  1710. * H1\n<2015-06-21>
  1711. * H1\n<2015-06-23>
  1712. "
  1713. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1714. (org-clone-subtree-with-time-shift 1 "+2d")
  1715. (replace-regexp-in-string
  1716. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1717. nil nil 1))))
  1718. ;; Clone repeating once.
  1719. (should
  1720. (equal "\
  1721. * H1\n<2015-06-21>
  1722. * H1\n<2015-06-23>
  1723. * H1\n<2015-06-25 +1w>
  1724. "
  1725. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1726. (org-clone-subtree-with-time-shift 1 "+2d")
  1727. (replace-regexp-in-string
  1728. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1729. nil nil 1))))
  1730. ;; Clone repeating once in backward.
  1731. (should
  1732. (equal "\
  1733. * H1\n<2015-06-21>
  1734. * H1\n<2015-06-19>
  1735. * H1\n<2015-06-17 +1w>
  1736. "
  1737. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1738. (org-clone-subtree-with-time-shift 1 "-2d")
  1739. (replace-regexp-in-string
  1740. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1741. nil nil 1))))
  1742. ;; Clone non-repeating zero times.
  1743. (should
  1744. (equal "\
  1745. * H1\n<2015-06-21>
  1746. "
  1747. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1748. (org-clone-subtree-with-time-shift 0 "+2d")
  1749. (replace-regexp-in-string
  1750. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1751. nil nil 1))))
  1752. ;; Clone repeating "zero" times.
  1753. (should
  1754. (equal "\
  1755. * H1\n<2015-06-21>
  1756. * H1\n<2015-06-23 +1w>
  1757. "
  1758. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1759. (org-clone-subtree-with-time-shift 0 "+2d")
  1760. (replace-regexp-in-string
  1761. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1762. nil nil 1))))
  1763. ;; Clone with blank SHIFT argument.
  1764. (should
  1765. (string-prefix-p
  1766. "* H <2012-03-29"
  1767. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1768. (org-clone-subtree-with-time-shift 1 "")
  1769. (buffer-substring-no-properties (line-beginning-position 2)
  1770. (line-end-position 2)))))
  1771. ;; Find time stamps before point. If SHIFT is not specified, ask
  1772. ;; for a time shift.
  1773. (should
  1774. (string-prefix-p
  1775. "* H <2012-03-30"
  1776. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1777. (org-clone-subtree-with-time-shift 1 "+1d")
  1778. (buffer-substring-no-properties (line-beginning-position 2)
  1779. (line-end-position 2)))))
  1780. (should
  1781. (string-prefix-p
  1782. "* H <2014-03-05"
  1783. (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
  1784. (cl-letf (((symbol-function 'read-from-minibuffer)
  1785. (lambda (&rest args) "+1d")))
  1786. (org-clone-subtree-with-time-shift 1))
  1787. (buffer-substring-no-properties (line-beginning-position 2)
  1788. (line-end-position 2)))))
  1789. ;; Hour shift.
  1790. (should
  1791. (equal "\
  1792. * H1\n<2015-06-21 20:00>
  1793. * H1\n<2015-06-21 23:00>
  1794. * H1\n<2015-06-22 02:00>
  1795. "
  1796. (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>"
  1797. (org-clone-subtree-with-time-shift 2 "+3h")
  1798. (replace-regexp-in-string
  1799. "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" ""
  1800. (buffer-substring-no-properties (point-min) (point-max))
  1801. nil nil 1))))
  1802. (should
  1803. (equal "\
  1804. * H1\n<2015-06-21 20:00>
  1805. * H1\n<2015-06-21 18:00>
  1806. "
  1807. (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>"
  1808. (org-clone-subtree-with-time-shift 1 "-2h")
  1809. (replace-regexp-in-string
  1810. "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" ""
  1811. (buffer-substring-no-properties (point-min) (point-max))
  1812. nil nil 1)))))
  1813. ;;; Fixed-Width Areas
  1814. (ert-deftest test-org/toggle-fixed-width ()
  1815. "Test `org-toggle-fixed-width' specifications."
  1816. ;; No region: Toggle on fixed-width marker in paragraphs.
  1817. (should
  1818. (equal ": A"
  1819. (org-test-with-temp-text "A"
  1820. (org-toggle-fixed-width)
  1821. (buffer-string))))
  1822. ;; No region: Toggle off fixed-width markers in fixed-width areas.
  1823. (should
  1824. (equal "A"
  1825. (org-test-with-temp-text ": A"
  1826. (org-toggle-fixed-width)
  1827. (buffer-string))))
  1828. ;; No region: Toggle on marker in blank lines after elements or just
  1829. ;; after a headline.
  1830. (should
  1831. (equal "* H\n: "
  1832. (org-test-with-temp-text "* H\n"
  1833. (forward-line)
  1834. (org-toggle-fixed-width)
  1835. (buffer-string))))
  1836. (should
  1837. (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
  1838. (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
  1839. (goto-char (point-max))
  1840. (org-toggle-fixed-width)
  1841. (buffer-string))))
  1842. ;; No region: Toggle on marker in front of one line elements (e.g.,
  1843. ;; headlines, clocks)
  1844. (should
  1845. (equal ": * Headline"
  1846. (org-test-with-temp-text "* Headline"
  1847. (org-toggle-fixed-width)
  1848. (buffer-string))))
  1849. (should
  1850. (equal ": #+KEYWORD: value"
  1851. (org-test-with-temp-text "#+KEYWORD: value"
  1852. (org-toggle-fixed-width)
  1853. (buffer-string))))
  1854. ;; No region: error in other situations.
  1855. (should-error
  1856. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
  1857. (forward-line)
  1858. (org-toggle-fixed-width)
  1859. (buffer-string)))
  1860. ;; No region: Indentation is preserved.
  1861. (should
  1862. (equal "- A\n : B"
  1863. (org-test-with-temp-text "- A\n B"
  1864. (forward-line)
  1865. (org-toggle-fixed-width)
  1866. (buffer-string))))
  1867. ;; Region: If it contains only fixed-width elements and blank lines,
  1868. ;; toggle off fixed-width markup.
  1869. (should
  1870. (equal "A\n\nB"
  1871. (org-test-with-temp-text ": A\n\n: B"
  1872. (transient-mark-mode 1)
  1873. (push-mark (point) t t)
  1874. (goto-char (point-max))
  1875. (org-toggle-fixed-width)
  1876. (buffer-string))))
  1877. ;; Region: If it contains anything else, toggle on fixed-width but
  1878. ;; not on fixed-width areas.
  1879. (should
  1880. (equal ": A\n: \n: B\n: \n: C"
  1881. (org-test-with-temp-text "A\n\n: B\n\nC"
  1882. (transient-mark-mode 1)
  1883. (push-mark (point) t t)
  1884. (goto-char (point-max))
  1885. (org-toggle-fixed-width)
  1886. (buffer-string))))
  1887. ;; Region: Ignore blank lines at its end, unless it contains only
  1888. ;; such lines.
  1889. (should
  1890. (equal ": A\n\n"
  1891. (org-test-with-temp-text "A\n\n"
  1892. (transient-mark-mode 1)
  1893. (push-mark (point) t t)
  1894. (goto-char (point-max))
  1895. (org-toggle-fixed-width)
  1896. (buffer-string))))
  1897. (should
  1898. (equal ": \n: \n"
  1899. (org-test-with-temp-text "\n\n"
  1900. (transient-mark-mode 1)
  1901. (push-mark (point) t t)
  1902. (goto-char (point-max))
  1903. (org-toggle-fixed-width)
  1904. (buffer-string)))))
  1905. (ert-deftest test-org/kill-line ()
  1906. "Test `org-kill-line' specifications."
  1907. ;; At the beginning of a line, kill whole line.
  1908. (should
  1909. (equal ""
  1910. (org-test-with-temp-text "abc"
  1911. (org-kill-line)
  1912. (buffer-string))))
  1913. ;; In the middle of a line, kill line until its end.
  1914. (should
  1915. (equal "a"
  1916. (org-test-with-temp-text "a<point>bc"
  1917. (org-kill-line)
  1918. (buffer-string))))
  1919. ;; Do not kill newline character.
  1920. (should
  1921. (equal "\n123"
  1922. (org-test-with-temp-text "abc\n123"
  1923. (org-kill-line)
  1924. (buffer-string))))
  1925. (should
  1926. (equal "a\n123"
  1927. (org-test-with-temp-text "a<point>bc\n123"
  1928. (org-kill-line)
  1929. (buffer-string))))
  1930. ;; When `org-special-ctrl-k' is non-nil and point is at a headline,
  1931. ;; kill until tags.
  1932. (should
  1933. (equal "* A :tag:"
  1934. (org-test-with-temp-text "* A<point>B :tag:"
  1935. (let ((org-special-ctrl-k t)
  1936. (org-tags-column 0))
  1937. (org-kill-line))
  1938. (buffer-string))))
  1939. ;; If point is on tags, only kill part left until the end of line.
  1940. (should
  1941. (equal "* A :tag:"
  1942. (org-test-with-temp-text "* A :tag:<point>tag2:"
  1943. (let ((org-special-ctrl-k t)
  1944. (org-tags-column 0))
  1945. (org-kill-line))
  1946. (buffer-string))))
  1947. ;; However, if point is at the beginning of the line, kill whole
  1948. ;; headline.
  1949. (should
  1950. (equal ""
  1951. (org-test-with-temp-text "* AB :tag:"
  1952. (let ((org-special-ctrl-k t)
  1953. (org-tags-column 0))
  1954. (org-kill-line))
  1955. (buffer-string))))
  1956. ;; When `org-ctrl-k-protect-subtree' is non-nil, and point is in
  1957. ;; invisible text, ask before removing it. When set to `error',
  1958. ;; throw an error.
  1959. (should-error
  1960. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  1961. (org-overview)
  1962. (let ((org-special-ctrl-k nil)
  1963. (org-ctrl-k-protect-subtree t))
  1964. (cl-letf (((symbol-function 'y-or-n-p) 'ignore))
  1965. (org-kill-line)))))
  1966. (should-error
  1967. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  1968. (org-overview)
  1969. (let ((org-special-ctrl-k nil)
  1970. (org-ctrl-k-protect-subtree 'error))
  1971. (org-kill-line)))))
  1972. ;;; Headline
  1973. (ert-deftest test-org/get-heading ()
  1974. "Test `org-get-heading' specifications."
  1975. ;; Return current heading, even if point is not on it.
  1976. (should
  1977. (equal "H"
  1978. (org-test-with-temp-text "* H"
  1979. (org-get-heading))))
  1980. (should
  1981. (equal "H"
  1982. (org-test-with-temp-text "* H\nText<point>"
  1983. (org-get-heading))))
  1984. ;; Without any optional argument, return TODO keyword, priority
  1985. ;; cookie, COMMENT keyword and tags.
  1986. (should
  1987. (equal "TODO H"
  1988. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  1989. (org-get-heading))))
  1990. (should
  1991. (equal "[#A] H"
  1992. (org-test-with-temp-text "* [#A] H"
  1993. (org-get-heading))))
  1994. (should
  1995. (equal "COMMENT H"
  1996. (org-test-with-temp-text "* COMMENT H"
  1997. (org-get-heading))))
  1998. (should
  1999. (equal "H :tag:"
  2000. (org-test-with-temp-text "* H :tag:"
  2001. (org-get-heading))))
  2002. ;; With NO-TAGS argument, ignore tags.
  2003. (should
  2004. (equal "TODO H"
  2005. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2006. (org-get-heading t))))
  2007. (should
  2008. (equal "H"
  2009. (org-test-with-temp-text "* H :tag:"
  2010. (org-get-heading t))))
  2011. ;; With NO-TODO, ignore TODO keyword.
  2012. (should
  2013. (equal "H"
  2014. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2015. (org-get-heading nil t))))
  2016. (should
  2017. (equal "H :tag:"
  2018. (org-test-with-temp-text "* H :tag:"
  2019. (org-get-heading nil t))))
  2020. ;; TODO keywords are case-sensitive.
  2021. (should
  2022. (equal "Todo H"
  2023. (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
  2024. (org-get-heading nil t))))
  2025. ;; With NO-PRIORITY, ignore priority.
  2026. (should
  2027. (equal "H"
  2028. (org-test-with-temp-text "* [#A] H"
  2029. (org-get-heading nil nil t))))
  2030. (should
  2031. (equal "H"
  2032. (org-test-with-temp-text "* H"
  2033. (org-get-heading nil nil t))))
  2034. (should
  2035. (equal "TODO H"
  2036. (org-test-with-temp-text "* TODO [#A] H"
  2037. (org-get-heading nil nil t))))
  2038. ;; With NO-COMMENT, ignore COMMENT keyword.
  2039. (should
  2040. (equal "H"
  2041. (org-test-with-temp-text "* COMMENT H"
  2042. (org-get-heading nil nil nil t))))
  2043. (should
  2044. (equal "H"
  2045. (org-test-with-temp-text "* H"
  2046. (org-get-heading nil nil nil t))))
  2047. (should
  2048. (equal "TODO [#A] H"
  2049. (org-test-with-temp-text "* TODO [#A] COMMENT H"
  2050. (org-get-heading nil nil nil t))))
  2051. ;; On an empty headline, return value is consistent.
  2052. (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
  2053. (should (equal "" (org-test-with-temp-text "* " (org-get-heading t))))
  2054. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t))))
  2055. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t))))
  2056. (should
  2057. (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t)))))
  2058. (ert-deftest test-org/in-commented-heading-p ()
  2059. "Test `org-in-commented-heading-p' specifications."
  2060. ;; Commented headline.
  2061. (should
  2062. (org-test-with-temp-text "* COMMENT Headline\nBody"
  2063. (goto-char (point-max))
  2064. (org-in-commented-heading-p)))
  2065. ;; Commented ancestor.
  2066. (should
  2067. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  2068. (goto-char (point-max))
  2069. (org-in-commented-heading-p)))
  2070. ;; Comment keyword is case-sensitive.
  2071. (should-not
  2072. (org-test-with-temp-text "* Comment Headline\nBody"
  2073. (goto-char (point-max))
  2074. (org-in-commented-heading-p)))
  2075. ;; Keyword is standalone.
  2076. (should-not
  2077. (org-test-with-temp-text "* COMMENTHeadline\nBody"
  2078. (goto-char (point-max))
  2079. (org-in-commented-heading-p)))
  2080. ;; Optional argument.
  2081. (should-not
  2082. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  2083. (goto-char (point-max))
  2084. (org-in-commented-heading-p t))))
  2085. (ert-deftest test-org/in-archived-heading-p ()
  2086. "Test `org-in-archived-heading-p' specifications."
  2087. ;; Archived headline.
  2088. (should
  2089. (org-test-with-temp-text "* Headline :ARCHIVE:\nBody"
  2090. (goto-char (point-max))
  2091. (org-in-archived-heading-p)))
  2092. ;; Archived ancestor.
  2093. (should
  2094. (org-test-with-temp-text "* Headline :ARCHIVE:\n** Level 2\nBody"
  2095. (goto-char (point-max))
  2096. (org-in-archived-heading-p)))
  2097. ;; Optional argument.
  2098. (should-not
  2099. (org-test-with-temp-text "* Headline :ARCHIVE:\n** Level 2\nBody"
  2100. (goto-char (point-max))
  2101. (org-in-archived-heading-p t)))
  2102. ;; Archive tag containing ARCHIVE as substring
  2103. (should-not
  2104. (org-test-with-temp-text "* Headline :NOARCHIVE:\n** Level 2\nBody"
  2105. (goto-char (point-max))
  2106. (org-in-archived-heading-p))))
  2107. (ert-deftest test-org/entry-blocked-p ()
  2108. ;; Check other dependencies.
  2109. (should
  2110. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  2111. (let ((org-enforce-todo-dependencies t)
  2112. (org-blocker-hook
  2113. '(org-block-todo-from-children-or-siblings-or-parent)))
  2114. (org-entry-blocked-p))))
  2115. (should-not
  2116. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  2117. (let ((org-enforce-todo-dependencies t)
  2118. (org-blocker-hook
  2119. '(org-block-todo-from-children-or-siblings-or-parent)))
  2120. (org-entry-blocked-p))))
  2121. ;; Entry without a TODO keyword or with a DONE keyword cannot be
  2122. ;; blocked.
  2123. (should-not
  2124. (org-test-with-temp-text "* Blocked\n** TODO one"
  2125. (let ((org-enforce-todo-dependencies t)
  2126. (org-blocker-hook
  2127. '(org-block-todo-from-children-or-siblings-or-parent)))
  2128. (org-entry-blocked-p))))
  2129. (should-not
  2130. (org-test-with-temp-text "* DONE Blocked\n** TODO one"
  2131. (let ((org-enforce-todo-dependencies t)
  2132. (org-blocker-hook
  2133. '(org-block-todo-from-children-or-siblings-or-parent)))
  2134. (org-entry-blocked-p))))
  2135. ;; Follow :ORDERED: specifications.
  2136. (should
  2137. (org-test-with-temp-text
  2138. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
  2139. (let ((org-enforce-todo-dependencies t)
  2140. (org-blocker-hook
  2141. '(org-block-todo-from-children-or-siblings-or-parent)))
  2142. (org-entry-blocked-p))))
  2143. (should-not
  2144. (org-test-with-temp-text
  2145. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
  2146. (let ((org-enforce-todo-dependencies t)
  2147. (org-blocker-hook
  2148. '(org-block-todo-from-children-or-siblings-or-parent)))
  2149. (org-entry-blocked-p)))))
  2150. (ert-deftest test-org/get-outline-path ()
  2151. "Test `org-get-outline-path' specifications."
  2152. ;; Top-level headlines have no outline path.
  2153. (should-not
  2154. (org-test-with-temp-text "* H"
  2155. (org-get-outline-path)))
  2156. ;; Otherwise, outline path is the path leading to the headline.
  2157. (should
  2158. (equal '("H")
  2159. (org-test-with-temp-text "* H\n** S<point>"
  2160. (org-get-outline-path))))
  2161. ;; Find path even when point is not on a headline.
  2162. (should
  2163. (equal '("H")
  2164. (org-test-with-temp-text "* H\n** S\nText<point>"
  2165. (org-get-outline-path))))
  2166. ;; TODO keywords, tags and statistics cookies are ignored.
  2167. (should
  2168. (equal '("H")
  2169. (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
  2170. (org-get-outline-path))))
  2171. ;; Links are replaced with their description or their path.
  2172. (should
  2173. (equal '("Org")
  2174. (org-test-with-temp-text
  2175. "* [[https://orgmode.org][Org]]\n** S<point>"
  2176. (org-get-outline-path))))
  2177. (should
  2178. (equal '("https://orgmode.org")
  2179. (org-test-with-temp-text
  2180. "* [[https://orgmode.org]]\n** S<point>"
  2181. (org-get-outline-path))))
  2182. ;; When WITH-SELF is non-nil, include current heading.
  2183. (should
  2184. (equal '("H")
  2185. (org-test-with-temp-text "* H"
  2186. (org-get-outline-path t))))
  2187. (should
  2188. (equal '("H" "S")
  2189. (org-test-with-temp-text "* H\n** S\nText<point>"
  2190. (org-get-outline-path t))))
  2191. ;; Using cache is transparent to the user.
  2192. (should
  2193. (equal '("H")
  2194. (org-test-with-temp-text "* H\n** S<point>"
  2195. (setq org-outline-path-cache nil)
  2196. (org-get-outline-path nil t))))
  2197. ;; Do not corrupt cache when finding outline path in distant part of
  2198. ;; the buffer.
  2199. (should
  2200. (equal '("H2")
  2201. (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
  2202. (setq org-outline-path-cache nil)
  2203. (org-get-outline-path nil t)
  2204. (search-forward "S2")
  2205. (org-get-outline-path nil t))))
  2206. ;; Do not choke on empty headlines.
  2207. (should
  2208. (org-test-with-temp-text "* H\n** <point>"
  2209. (org-get-outline-path)))
  2210. (should
  2211. (org-test-with-temp-text "* \n** H<point>"
  2212. (org-get-outline-path))))
  2213. (ert-deftest test-org/format-outline-path ()
  2214. "Test `org-format-outline-path' specifications."
  2215. (should
  2216. (string= (org-format-outline-path (list "one" "two" "three"))
  2217. "one/two/three"))
  2218. ;; Empty path.
  2219. (should
  2220. (string= (org-format-outline-path '())
  2221. ""))
  2222. (should
  2223. (string= (org-format-outline-path '(nil))
  2224. ""))
  2225. ;; Empty path and prefix.
  2226. (should
  2227. (string= (org-format-outline-path '() nil ">>")
  2228. ">>"))
  2229. ;; Trailing whitespace in headings.
  2230. (should
  2231. (string= (org-format-outline-path (list "one\t" "tw o " "three "))
  2232. "one/tw o/three"))
  2233. ;; Non-default prefix and separators.
  2234. (should
  2235. (string= (org-format-outline-path (list "one" "two" "three") nil ">>" "|")
  2236. ">>|one|two|three"))
  2237. ;; Truncate.
  2238. (should
  2239. (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
  2240. "one/two/.."))
  2241. ;; Give a very narrow width.
  2242. (should
  2243. (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
  2244. "on"))
  2245. ;; Give a prefix that extends beyond the width.
  2246. (should
  2247. (string= (org-format-outline-path (list "one" "two" "three" "four") 10
  2248. ">>>>>>>>>>")
  2249. ">>>>>>>>..")))
  2250. (ert-deftest test-org/map-entries ()
  2251. "Test `org-map-entries' specifications."
  2252. ;; Full match.
  2253. (should
  2254. (equal '(1 11)
  2255. (org-test-with-temp-text "* Level 1\n** Level 2"
  2256. (org-map-entries #'point))))
  2257. ;; Level match.
  2258. (should
  2259. (equal '(1)
  2260. (org-test-with-temp-text "* Level 1\n** Level 2"
  2261. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL=1")))))
  2262. (should
  2263. (equal '(11)
  2264. (org-test-with-temp-text "* Level 1\n** Level 2"
  2265. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL>1")))))
  2266. ;; Tag match.
  2267. (should
  2268. (equal '(11)
  2269. (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
  2270. (org-map-entries #'point "yes"))))
  2271. (should
  2272. (equal '(14)
  2273. (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
  2274. (org-map-entries #'point "+yes-a"))))
  2275. (should
  2276. (equal '(11 23)
  2277. (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
  2278. (org-map-entries #'point "{yes?}"))))
  2279. ;; Priority match.
  2280. (should
  2281. (equal '(1)
  2282. (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
  2283. (org-map-entries #'point "PRIORITY=\"A\""))))
  2284. ;; Date match.
  2285. (should
  2286. (equal '(36)
  2287. (org-test-with-temp-text "
  2288. * H1
  2289. SCHEDULED: <2012-03-29 thu.>
  2290. * H2
  2291. SCHEDULED: <2014-03-04 tue.>"
  2292. (org-map-entries #'point "SCHEDULED=\"<2014-03-04 tue.>\""))))
  2293. (should
  2294. (equal '(2)
  2295. (org-test-with-temp-text "
  2296. * H1
  2297. SCHEDULED: <2012-03-29 thu.>
  2298. * H2
  2299. SCHEDULED: <2014-03-04 tue.>"
  2300. (org-map-entries #'point "SCHEDULED<\"<2013-01-01>\""))))
  2301. ;; Regular property match.
  2302. (should
  2303. (equal '(2)
  2304. (org-test-with-temp-text "
  2305. * H1
  2306. :PROPERTIES:
  2307. :TEST: 1
  2308. :END:
  2309. * H2
  2310. :PROPERTIES:
  2311. :TEST: 2
  2312. :END:"
  2313. (org-map-entries #'point "TEST=1"))))
  2314. ;; Multiple criteria.
  2315. (should
  2316. (equal '(23)
  2317. (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
  2318. (let (org-odd-levels-only
  2319. (org-use-tag-inheritance nil))
  2320. (org-map-entries #'point "yes+LEVEL=1")))))
  2321. ;; "or" criteria.
  2322. (should
  2323. (equal '(12 24)
  2324. (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
  2325. (let (org-odd-levels-only)
  2326. (org-map-entries #'point "LEVEL=2|no")))))
  2327. (should
  2328. (equal '(1 12)
  2329. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
  2330. (let (org-odd-levels-only)
  2331. (org-map-entries #'point "yes|no")))))
  2332. ;; "and" criteria.
  2333. (should
  2334. (equal '(22)
  2335. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
  2336. (let (org-odd-levels-only)
  2337. (org-map-entries #'point "yes&no"))))))
  2338. (ert-deftest test-org/edit-headline ()
  2339. "Test `org-edit-headline' specifications."
  2340. (should
  2341. (equal "* B"
  2342. (org-test-with-temp-text "* A"
  2343. (org-edit-headline "B")
  2344. (buffer-string))))
  2345. ;; Handle empty headings.
  2346. (should
  2347. (equal "* "
  2348. (org-test-with-temp-text "* A"
  2349. (org-edit-headline "")
  2350. (buffer-string))))
  2351. (should
  2352. (equal "* A"
  2353. (org-test-with-temp-text "* "
  2354. (org-edit-headline "A")
  2355. (buffer-string))))
  2356. ;; Handle TODO keywords and priority cookies.
  2357. (should
  2358. (equal "* TODO B"
  2359. (org-test-with-temp-text "* TODO A"
  2360. (org-edit-headline "B")
  2361. (buffer-string))))
  2362. (should
  2363. (equal "* [#A] B"
  2364. (org-test-with-temp-text "* [#A] A"
  2365. (org-edit-headline "B")
  2366. (buffer-string))))
  2367. (should
  2368. (equal "* TODO [#A] B"
  2369. (org-test-with-temp-text "* TODO [#A] A"
  2370. (org-edit-headline "B")
  2371. (buffer-string))))
  2372. ;; Handle tags.
  2373. (equal "* B :tag:"
  2374. (org-test-with-temp-text "* A :tag:"
  2375. (let ((org-tags-column 4)) (org-edit-headline "B"))
  2376. (buffer-string))))
  2377. ;;; Keywords
  2378. (ert-deftest test-org/set-regexps-and-options ()
  2379. "Test `org-set-regexps-and-options' specifications."
  2380. ;; TAGS keyword.
  2381. (should
  2382. (equal '(("A"))
  2383. (let ((org-tag-alist '(("A")))
  2384. (org-tag-persistent-alist nil))
  2385. (org-test-with-temp-text ""
  2386. (org-mode-restart)
  2387. org-current-tag-alist))))
  2388. (should
  2389. (equal '(("B"))
  2390. (let ((org-tag-alist '(("A")))
  2391. (org-tag-persistent-alist nil))
  2392. (org-test-with-temp-text "#+TAGS: B"
  2393. (org-mode-restart)
  2394. org-current-tag-alist))))
  2395. (should
  2396. (equal '(("C") ("B"))
  2397. (let ((org-tag-alist '(("A")))
  2398. (org-tag-persistent-alist '(("C"))))
  2399. (org-test-with-temp-text "#+TAGS: B"
  2400. (org-mode-restart)
  2401. org-current-tag-alist))))
  2402. (should
  2403. (equal '(("B"))
  2404. (let ((org-tag-alist '(("A")))
  2405. (org-tag-persistent-alist '(("C"))))
  2406. (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
  2407. (org-mode-restart)
  2408. org-current-tag-alist))))
  2409. (should
  2410. (equal '(("A" . ?a) ("B") ("C"))
  2411. (let ((org-tag-persistant-alist nil))
  2412. (org-test-with-temp-text "#+TAGS: A(a) B C"
  2413. (org-mode-restart)
  2414. org-current-tag-alist))))
  2415. (should
  2416. (equal '(("A") (:newline) ("B"))
  2417. (let ((org-tag-persistent-alist nil))
  2418. (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
  2419. (org-mode-restart)
  2420. org-current-tag-alist))))
  2421. (should
  2422. (equal '((:startgroup) ("A") ("B") (:endgroup) ("C"))
  2423. (let ((org-tag-persistent-alist nil))
  2424. (org-test-with-temp-text "#+TAGS: { A B } C"
  2425. (org-mode-restart)
  2426. org-current-tag-alist))))
  2427. (should
  2428. (equal '((:startgroup) ("A") (:grouptags) ("B") ("C") (:endgroup))
  2429. (let ((org-tag-persistent-alist nil))
  2430. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2431. (org-mode-restart)
  2432. org-current-tag-alist))))
  2433. (should
  2434. (equal '(("A" "B" "C"))
  2435. (let ((org-tag-persistent-alist nil))
  2436. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2437. (org-mode-restart)
  2438. org-tag-groups-alist))))
  2439. (should
  2440. (equal '((:startgrouptag) ("A") (:grouptags) ("B") ("C") (:endgrouptag))
  2441. (let ((org-tag-persistent-alist nil))
  2442. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2443. (org-mode-restart)
  2444. org-current-tag-alist))))
  2445. (should
  2446. (equal '(("A" "B" "C"))
  2447. (let ((org-tag-persistent-alist nil))
  2448. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2449. (org-mode-restart)
  2450. org-tag-groups-alist))))
  2451. (should-not
  2452. (let ((org-tag-alist '(("A"))))
  2453. (org-test-with-temp-text "#+TAGS:"
  2454. (org-mode-restart)
  2455. org-current-tag-alist)))
  2456. ;; FILETAGS keyword.
  2457. (should
  2458. (equal '("A" "B" "C")
  2459. (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
  2460. (org-mode-restart)
  2461. org-file-tags)))
  2462. ;; PROPERTY keyword. Property names are case-insensitive.
  2463. (should
  2464. (equal "foo=1"
  2465. (org-test-with-temp-text "#+PROPERTY: var foo=1"
  2466. (org-mode-restart)
  2467. (cdr (assoc "var" org-keyword-properties)))))
  2468. (should
  2469. (equal
  2470. "foo=1 bar=2"
  2471. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
  2472. (org-mode-restart)
  2473. (cdr (assoc "var" org-keyword-properties)))))
  2474. (should
  2475. (equal
  2476. "foo=1 bar=2"
  2477. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
  2478. (org-mode-restart)
  2479. (cdr (assoc "var" org-keyword-properties)))))
  2480. ;; ARCHIVE keyword.
  2481. (should
  2482. (equal "%s_done::"
  2483. (org-test-with-temp-text "#+ARCHIVE: %s_done::"
  2484. (org-mode-restart)
  2485. org-archive-location)))
  2486. ;; CATEGORY keyword.
  2487. (should
  2488. (eq 'test
  2489. (org-test-with-temp-text "#+CATEGORY: test"
  2490. (org-mode-restart)
  2491. org-category)))
  2492. (should
  2493. (equal "test"
  2494. (org-test-with-temp-text "#+CATEGORY: test"
  2495. (org-mode-restart)
  2496. (cdr (assoc "CATEGORY" org-keyword-properties)))))
  2497. ;; COLUMNS keyword.
  2498. (should
  2499. (equal "%25ITEM %TAGS %PRIORITY %TODO"
  2500. (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
  2501. (org-mode-restart)
  2502. org-columns-default-format)))
  2503. ;; CONSTANTS keyword. Constants names are case sensitive.
  2504. (should
  2505. (equal '("299792458." "3.14")
  2506. (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
  2507. (org-mode-restart)
  2508. (mapcar
  2509. (lambda (n) (cdr (assoc n org-table-formula-constants-local)))
  2510. '("c" "pi")))))
  2511. (should
  2512. (equal "3.14"
  2513. (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
  2514. (org-mode-restart)
  2515. (cdr (assoc "pi" org-table-formula-constants-local)))))
  2516. (should
  2517. (equal "22/7"
  2518. (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
  2519. (org-mode-restart)
  2520. (cdr (assoc "PI" org-table-formula-constants-local)))))
  2521. ;; LINK keyword.
  2522. (should
  2523. (equal
  2524. '("url1" "url2")
  2525. (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
  2526. (org-mode-restart)
  2527. (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local)))
  2528. '("a" "b")))))
  2529. ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
  2530. (should
  2531. (equal
  2532. '(?X ?Z ?Y)
  2533. (org-test-with-temp-text "#+PRIORITIES: X Z Y"
  2534. (org-mode-restart)
  2535. (list org-priority-highest org-priority-lowest org-priority-default))))
  2536. (should
  2537. (equal
  2538. '(?A ?C ?B)
  2539. (org-test-with-temp-text "#+PRIORITIES: X Z"
  2540. (org-mode-restart)
  2541. (list org-priority-highest org-priority-lowest org-priority-default))))
  2542. ;; STARTUP keyword.
  2543. (should
  2544. (equal '(t t)
  2545. (org-test-with-temp-text "#+STARTUP: fold odd"
  2546. (org-mode-restart)
  2547. (list org-startup-folded org-odd-levels-only))))
  2548. ;; TODO keywords.
  2549. (should
  2550. (equal '(("A" "B") ("C"))
  2551. (org-test-with-temp-text "#+TODO: A B | C"
  2552. (org-mode-restart)
  2553. (list org-not-done-keywords org-done-keywords))))
  2554. (should
  2555. (equal '(("A" "C") ("B" "D"))
  2556. (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
  2557. (org-mode-restart)
  2558. (list org-not-done-keywords org-done-keywords))))
  2559. (should
  2560. (equal '(("A" "B") ("C"))
  2561. (org-test-with-temp-text "#+TYP_TODO: A B | C"
  2562. (org-mode-restart)
  2563. (list org-not-done-keywords org-done-keywords))))
  2564. (should
  2565. (equal '((:startgroup) ("A" . ?a) (:endgroup))
  2566. (org-test-with-temp-text "#+TODO: A(a)"
  2567. (org-mode-restart)
  2568. org-todo-key-alist)))
  2569. (should
  2570. (equal '(("D" note nil) ("C" time nil) ("B" note time))
  2571. (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
  2572. (org-mode-restart)
  2573. org-todo-log-states)))
  2574. ;; Enter SETUPFILE keyword.
  2575. (should
  2576. (equal "1"
  2577. (org-test-with-temp-text
  2578. (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
  2579. (org-mode-restart)
  2580. (cdr (assoc "a" org-keyword-properties))))))
  2581. ;;; Links
  2582. ;;;; Coderefs
  2583. (ert-deftest test-org/coderef ()
  2584. "Test coderef links specifications."
  2585. (should
  2586. (org-test-with-temp-text "
  2587. #+BEGIN_SRC emacs-lisp
  2588. \(+ 1 1) (ref:sc)
  2589. #+END_SRC
  2590. \[[(sc)<point>]]"
  2591. (org-open-at-point)
  2592. (looking-at "(ref:sc)")))
  2593. ;; Find coderef even with alternate label format.
  2594. (should
  2595. (org-test-with-temp-text "
  2596. #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
  2597. \(+ 1 1) {ref:sc}
  2598. #+END_SRC
  2599. \[[(sc)<point>]]"
  2600. (org-open-at-point)
  2601. (looking-at "{ref:sc}"))))
  2602. ;;;; Custom ID
  2603. (ert-deftest test-org/custom-id ()
  2604. "Test custom ID links specifications."
  2605. (should
  2606. (org-test-with-temp-text
  2607. "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2608. (org-open-at-point)
  2609. (looking-at-p "\\* H1")))
  2610. ;; Handle escape characters.
  2611. (should
  2612. (org-test-with-temp-text
  2613. "* H1\n:PROPERTIES:\n:CUSTOM_ID: [%]\n:END:\n* H2\n[[#\\[%\\]<point>]]"
  2614. (org-open-at-point)
  2615. (looking-at-p "\\* H1")))
  2616. ;; Throw an error on false positives.
  2617. (should-error
  2618. (org-test-with-temp-text
  2619. "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2620. (org-open-at-point)
  2621. (looking-at-p "\\* H1"))))
  2622. ;;;; Fuzzy Links
  2623. ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
  2624. ;; a named element (#+name: text) and to headlines (* Text).
  2625. (ert-deftest test-org/fuzzy-links ()
  2626. "Test fuzzy links specifications."
  2627. ;; Fuzzy link goes in priority to a matching target.
  2628. (should
  2629. (org-test-with-temp-text
  2630. "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
  2631. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2632. (looking-at "<<Test>>")))
  2633. ;; Then fuzzy link points to an element with a given name.
  2634. (should
  2635. (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
  2636. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2637. (looking-at "#\\+NAME: Test")))
  2638. ;; A target still lead to a matching headline otherwise.
  2639. (should
  2640. (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
  2641. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2642. (looking-at "\\* Head2")))
  2643. ;; With a leading star in link, enforce heading match.
  2644. (should
  2645. (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
  2646. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2647. (looking-at "\\* Test")))
  2648. ;; With a leading star in link, enforce exact heading match, even
  2649. ;; with `org-link-search-must-match-exact-headline' set to nil.
  2650. (should-error
  2651. (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
  2652. (let ((org-link-search-must-match-exact-headline nil))
  2653. (org-open-at-point))))
  2654. ;; Handle non-nil `org-link-search-must-match-exact-headline'.
  2655. (should
  2656. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
  2657. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2658. (looking-at "\\* Test")))
  2659. (should
  2660. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
  2661. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2662. (looking-at "\\* Test")))
  2663. ;; Heading match should not care about spaces, cookies, TODO
  2664. ;; keywords, priorities, and tags. However, TODO keywords are
  2665. ;; case-sensitive.
  2666. (should
  2667. (let ((first-line
  2668. "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
  2669. (org-test-with-temp-text
  2670. (concat first-line "\nFoo Bar\n<point>[[*Test 1 2]]")
  2671. (let ((org-link-search-must-match-exact-headline nil)
  2672. (org-todo-regexp "TODO"))
  2673. (org-open-at-point))
  2674. (looking-at (regexp-quote first-line)))))
  2675. (should-error
  2676. (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
  2677. (let ((org-link-search-must-match-exact-headline nil)
  2678. (org-todo-regexp "TODO"))
  2679. (org-open-at-point))))
  2680. ;; Heading match should still be exact.
  2681. (should-error
  2682. (org-test-with-temp-text "
  2683. ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
  2684. Foo Bar
  2685. <point>[[*Test 1]]"
  2686. (let ((org-link-search-must-match-exact-headline nil)
  2687. (org-todo-regexp "TODO"))
  2688. (org-open-at-point))))
  2689. (should
  2690. (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
  2691. (let ((org-link-search-must-match-exact-headline nil)
  2692. (org-todo-regexp "TODO"))
  2693. (org-open-at-point))
  2694. (looking-at-p (regexp-quote "** Test 1 2"))))
  2695. ;; Heading match ignores COMMENT keyword.
  2696. (should
  2697. (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
  2698. (org-open-at-point)
  2699. (looking-at "\\* COMMENT Test")))
  2700. (should
  2701. (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
  2702. (org-open-at-point)
  2703. (looking-at "\\* TODO COMMENT Test")))
  2704. ;; Correctly un-escape fuzzy links.
  2705. (should
  2706. (org-test-with-temp-text "* [foo]\n[[*\\[foo\\]][With escaped characters]]"
  2707. (org-open-at-point)
  2708. (bobp)))
  2709. ;; Match search strings containing newline characters, including
  2710. ;; blank lines.
  2711. (should
  2712. (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
  2713. (let ((file (buffer-file-name)))
  2714. (goto-char (point-max))
  2715. (insert (format "[[file:%s::line1 line2]]" file))
  2716. (beginning-of-line)
  2717. (let ((org-link-search-must-match-exact-headline nil))
  2718. (org-open-at-point 0))
  2719. (looking-at-p "line1"))))
  2720. (should
  2721. (org-test-with-temp-text-in-file "Paragraph\n\nline1\n\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. ;;;; Open at point
  2730. (ert-deftest test-org/open-at-point/keyword ()
  2731. "Does `org-open-at-point' open link in a keyword line?"
  2732. (should
  2733. (org-test-with-temp-text
  2734. "<<top>>\n#+KEYWORD: <point>[[top]]"
  2735. (org-open-at-point) t))
  2736. (should
  2737. (org-test-with-temp-text
  2738. "* H\n<<top>>\n#+KEYWORD: <point>[[top]]"
  2739. (org-open-at-point) t)))
  2740. (ert-deftest test-org/open-at-point/property ()
  2741. "Does `org-open-at-point' open link in property drawer?"
  2742. (should
  2743. (org-test-with-temp-text
  2744. "* Headline
  2745. :PROPERTIES:
  2746. :URL: <point>[[*Headline]]
  2747. :END:"
  2748. (org-open-at-point) t)))
  2749. (ert-deftest test-org/open-at-point/comment ()
  2750. "Does `org-open-at-point' open link in a commented line?"
  2751. (should
  2752. (org-test-with-temp-text
  2753. "<<top>>\n# <point>[[top]]"
  2754. (org-open-at-point) t))
  2755. (should
  2756. (org-test-with-temp-text
  2757. "* H\n<<top>>\n# <point>[[top]]"
  2758. (org-open-at-point) t)))
  2759. (ert-deftest test-org/open-at-point/inline-image ()
  2760. "Test `org-open-at-point' on nested links."
  2761. (should
  2762. (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
  2763. (org-open-at-point)
  2764. (bobp))))
  2765. (ert-deftest test-org/open-at-point/radio-target ()
  2766. "Test `org-open-at-point' on radio targets."
  2767. (should
  2768. (org-test-with-temp-text "<<<target>>> <point>target"
  2769. (org-update-radio-target-regexp)
  2770. (org-open-at-point)
  2771. (eq (org-element-type (org-element-context)) 'radio-target))))
  2772. (ert-deftest test-org/open-at-point/tag ()
  2773. "Test `org-open-at-point' on tags."
  2774. (should
  2775. (org-test-with-temp-text "* H :<point>tag:"
  2776. (catch :result
  2777. (cl-letf (((symbol-function 'org-tags-view)
  2778. (lambda (&rest args) (throw :result t))))
  2779. (org-open-at-point)
  2780. nil))))
  2781. (should-not
  2782. (org-test-with-temp-text-in-file "* H<point> :tag:"
  2783. (catch :result
  2784. (cl-letf (((symbol-function 'org-tags-view)
  2785. (lambda (&rest args) (throw :result t))))
  2786. ;; When point isn't on a tag it's going to try other things,
  2787. ;; possibly trying to open attachments which will return an
  2788. ;; error if there isn't an attachment. Suppress that error.
  2789. (ignore-errors
  2790. (org-open-at-point))
  2791. nil)))))
  2792. ;;; Node Properties
  2793. (ert-deftest test-org/accumulated-properties-in-drawers ()
  2794. "Ensure properties accumulate in subtree drawers."
  2795. (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
  2796. (org-babel-next-src-block)
  2797. (should (equal '(2 1) (org-babel-execute-src-block)))))
  2798. (ert-deftest test-org/custom-properties ()
  2799. "Test custom properties specifications."
  2800. ;; Standard test.
  2801. (should
  2802. (let ((org-custom-properties '("FOO")))
  2803. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2804. (org-toggle-custom-properties-visibility)
  2805. (org-invisible-p2))))
  2806. ;; Properties are case-insensitive.
  2807. (should
  2808. (let ((org-custom-properties '("FOO")))
  2809. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
  2810. (org-toggle-custom-properties-visibility)
  2811. (org-invisible-p2))))
  2812. (should
  2813. (let ((org-custom-properties '("foo")))
  2814. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2815. (org-toggle-custom-properties-visibility)
  2816. (org-invisible-p2))))
  2817. ;; Multiple custom properties in the same drawer.
  2818. (should
  2819. (let ((org-custom-properties '("FOO" "BAR")))
  2820. (org-test-with-temp-text
  2821. "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
  2822. (org-toggle-custom-properties-visibility)
  2823. (and (org-invisible-p2)
  2824. (not (progn (forward-line) (org-invisible-p2)))
  2825. (progn (forward-line) (org-invisible-p2))))))
  2826. ;; Hide custom properties with an empty value.
  2827. (should
  2828. (let ((org-custom-properties '("FOO")))
  2829. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
  2830. (org-toggle-custom-properties-visibility)
  2831. (org-invisible-p2))))
  2832. ;; Do not hide fake properties.
  2833. (should-not
  2834. (let ((org-custom-properties '("FOO")))
  2835. (org-test-with-temp-text ":FOO: val\n"
  2836. (org-toggle-custom-properties-visibility)
  2837. (org-invisible-p2))))
  2838. (should-not
  2839. (let ((org-custom-properties '("A")))
  2840. (org-test-with-temp-text
  2841. "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
  2842. (org-toggle-custom-properties-visibility)
  2843. (org-invisible-p2)))))
  2844. ;;; Mark Region
  2845. (ert-deftest test-org/mark-element ()
  2846. "Test `org-mark-element' specifications."
  2847. ;; Mark beginning and end of element.
  2848. (should
  2849. (equal '(t t)
  2850. (org-test-with-temp-text "Para<point>graph"
  2851. (org-mark-element)
  2852. (list (bobp) (= (mark) (point-max))))))
  2853. (should
  2854. (equal '(t t)
  2855. (org-test-with-temp-text "P1\n\nPara<point>graph\n\nP2"
  2856. (org-mark-element)
  2857. (list (looking-at "Paragraph")
  2858. (org-with-point-at (mark) (looking-at "P2"))))))
  2859. ;; Do not set mark past (point-max).
  2860. (should
  2861. (org-test-with-temp-text "Para<point>graph"
  2862. (narrow-to-region 2 6)
  2863. (org-mark-element)
  2864. (= 6 (mark)))))
  2865. (ert-deftest test-org/mark-subtree ()
  2866. "Test `org-mark-subtree' specifications."
  2867. ;; Error when point is before first headline.
  2868. (should-error
  2869. (org-test-with-temp-text "Paragraph\n* Headline\nBody"
  2870. (progn (transient-mark-mode 1)
  2871. (org-mark-subtree))))
  2872. ;; Without argument, mark current subtree.
  2873. (should
  2874. (equal
  2875. '(12 32)
  2876. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  2877. (progn (transient-mark-mode 1)
  2878. (forward-line 2)
  2879. (org-mark-subtree)
  2880. (list (region-beginning) (region-end))))))
  2881. ;; With an argument, move ARG up.
  2882. (should
  2883. (equal
  2884. '(1 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 1)
  2889. (list (region-beginning) (region-end))))))
  2890. ;; Do not get fooled by inlinetasks.
  2891. (when (featurep 'org-inlinetask)
  2892. (should
  2893. (= 1
  2894. (org-test-with-temp-text "* Headline\n*************** Task\nContents"
  2895. (progn (transient-mark-mode 1)
  2896. (forward-line 1)
  2897. (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
  2898. (region-beginning)))))))
  2899. ;;; Miscellaneous
  2900. (ert-deftest test-org/sort-entries ()
  2901. "Test `org-sort-entries'."
  2902. ;; Sort alphabetically.
  2903. (should
  2904. (equal "\n* abc\n* def\n* xyz\n"
  2905. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  2906. (org-sort-entries nil ?a)
  2907. (buffer-string))))
  2908. (should
  2909. (equal "\n* xyz\n* def\n* abc\n"
  2910. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  2911. (org-sort-entries nil ?A)
  2912. (buffer-string))))
  2913. (should
  2914. (equal "\n* \n* klm\n* xyz\n"
  2915. (org-test-with-temp-text "\n* xyz\n* \n* klm\n"
  2916. (org-sort-entries nil ?a)
  2917. (buffer-string))))
  2918. ;; Sort numerically.
  2919. (should
  2920. (equal "\n* 1\n* 2\n* 10\n"
  2921. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  2922. (org-sort-entries nil ?n)
  2923. (buffer-string))))
  2924. (should
  2925. (equal "\n* 10\n* 2\n* 1\n"
  2926. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  2927. (org-sort-entries nil ?N)
  2928. (buffer-string))))
  2929. (should
  2930. (equal "\n* \n* 1\n* 2\n"
  2931. (org-test-with-temp-text "\n* 1\n* \n* 2\n"
  2932. (org-sort-entries nil ?n)
  2933. (buffer-string))))
  2934. ;; Sort by custom function.
  2935. (should
  2936. (equal "\n* b\n* aa\n* ccc\n"
  2937. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  2938. (org-sort-entries nil ?f
  2939. (lambda ()
  2940. (length (buffer-substring (point-at-bol)
  2941. (point-at-eol))))
  2942. #'<)
  2943. (buffer-string))))
  2944. (should
  2945. (equal "\n* ccc\n* aa\n* b\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. ;; Sort by TODO keyword.
  2954. (should
  2955. (equal "\n* TODO h1\n* TODO h3\n* DONE h2\n"
  2956. (org-test-with-temp-text
  2957. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  2958. (org-sort-entries nil ?o)
  2959. (buffer-string))))
  2960. (should
  2961. (equal "\n* DONE h2\n* TODO h1\n* TODO h3\n"
  2962. (org-test-with-temp-text
  2963. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  2964. (org-sort-entries nil ?O)
  2965. (buffer-string))))
  2966. ;; Sort by priority.
  2967. (should
  2968. (equal "\n* [#A] h2\n* [#B] h3\n* [#C] h1\n"
  2969. (org-test-with-temp-text
  2970. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  2971. (org-sort-entries nil ?p)
  2972. (buffer-string))))
  2973. (should
  2974. (equal "\n* [#C] h1\n* [#B] h3\n* [#A] h2\n"
  2975. (org-test-with-temp-text
  2976. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  2977. (org-sort-entries nil ?P)
  2978. (buffer-string))))
  2979. ;; Sort by creation time.
  2980. (should
  2981. (equal "
  2982. * h3
  2983. [2017-05-08 Mon]
  2984. * h2
  2985. [2017-05-09 Tue]
  2986. * h1
  2987. [2018-05-09 Wed]
  2988. "
  2989. (org-test-with-temp-text
  2990. "
  2991. * h1
  2992. [2018-05-09 Wed]
  2993. * h2
  2994. [2017-05-09 Tue]
  2995. * h3
  2996. [2017-05-08 Mon]
  2997. "
  2998. (org-sort-entries nil ?c)
  2999. (buffer-string))))
  3000. ;; Sort by scheduled date.
  3001. (should
  3002. (equal "
  3003. * TODO h4
  3004. SCHEDULED: <2017-05-06 Sat>
  3005. * TODO h3
  3006. SCHEDULED: <2017-05-08 Mon>
  3007. * TODO h2
  3008. DEADLINE: <2017-05-09 Tue>
  3009. * TODO h1
  3010. DEADLINE: <2017-05-07 Sun>
  3011. "
  3012. (org-test-with-temp-text
  3013. "
  3014. * TODO h2
  3015. DEADLINE: <2017-05-09 Tue>
  3016. * TODO h1
  3017. DEADLINE: <2017-05-07 Sun>
  3018. * TODO h3
  3019. SCHEDULED: <2017-05-08 Mon>
  3020. * TODO h4
  3021. SCHEDULED: <2017-05-06 Sat>
  3022. "
  3023. (org-sort-entries nil ?s)
  3024. (buffer-string))))
  3025. ;; Sort by deadline date.
  3026. (should
  3027. (equal "
  3028. * TODO h1
  3029. DEADLINE: <2017-05-07 Sun>
  3030. * TODO h2
  3031. DEADLINE: <2017-05-09 Tue>
  3032. * TODO h3
  3033. SCHEDULED: <2017-05-08 Mon>
  3034. * TODO h4
  3035. SCHEDULED: <2017-05-06 Sat>
  3036. "
  3037. (org-test-with-temp-text
  3038. "
  3039. * TODO h2
  3040. DEADLINE: <2017-05-09 Tue>
  3041. * TODO h1
  3042. DEADLINE: <2017-05-07 Sun>
  3043. * TODO h3
  3044. SCHEDULED: <2017-05-08 Mon>
  3045. * TODO h4
  3046. SCHEDULED: <2017-05-06 Sat>
  3047. "
  3048. (org-sort-entries nil ?d)
  3049. (buffer-string))))
  3050. ;; Sort by any date/time
  3051. (should
  3052. (equal "
  3053. * TODO h4
  3054. SCHEDULED: <2017-05-06 Sat>
  3055. * TODO h1
  3056. DEADLINE: <2017-05-07 Sun>
  3057. * TODO h3
  3058. SCHEDULED: <2017-05-08 Mon>
  3059. * TODO h2
  3060. DEADLINE: <2017-05-09 Tue>
  3061. "
  3062. (org-test-with-temp-text
  3063. "
  3064. * TODO h2
  3065. DEADLINE: <2017-05-09 Tue>
  3066. * TODO h1
  3067. DEADLINE: <2017-05-07 Sun>
  3068. * TODO h3
  3069. SCHEDULED: <2017-05-08 Mon>
  3070. * TODO h4
  3071. SCHEDULED: <2017-05-06 Sat>
  3072. "
  3073. (org-sort-entries nil ?t)
  3074. (buffer-string))))
  3075. ;; Sort by clocking time.
  3076. (should
  3077. (equal "
  3078. * clocked h2
  3079. :LOGBOOK:
  3080. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3081. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  3082. :END:
  3083. * clocked h1
  3084. :LOGBOOK:
  3085. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3086. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  3087. :END:
  3088. "
  3089. (org-test-with-temp-text
  3090. "
  3091. * clocked h1
  3092. :LOGBOOK:
  3093. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3094. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  3095. :END:
  3096. * clocked h2
  3097. :LOGBOOK:
  3098. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3099. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  3100. :END:
  3101. "
  3102. (org-sort-entries nil ?k)
  3103. (buffer-string))))
  3104. ;; Preserve file local variables when sorting.
  3105. (should
  3106. (equal "\n* A\n* B\n# Local Variables:\n# foo: t\n# End:\n"
  3107. (org-test-with-temp-text
  3108. "\n* B\n* A\n# Local Variables:\n# foo: t\n# End:"
  3109. (org-sort-entries nil ?a)
  3110. (buffer-string)))))
  3111. (ert-deftest test-org/string-collate-greaterp ()
  3112. "Test `org-string-collate-greaterp' specifications."
  3113. (should (org-string-collate-greaterp "def" "abc"))
  3114. (should-not (org-string-collate-greaterp "abc" "def")))
  3115. (ert-deftest test-org/file-contents ()
  3116. "Test `org-file-contents' specifications."
  3117. ;; Open files.
  3118. (should
  3119. (string= "#+BIND: variable value
  3120. #+DESCRIPTION: l2
  3121. #+LANGUAGE: en
  3122. #+SELECT_TAGS: b
  3123. #+TITLE: b
  3124. #+PROPERTY: a 1
  3125. " (org-file-contents (expand-file-name "setupfile3.org"
  3126. (concat org-test-dir "examples/")))))
  3127. ;; Throw error when trying to access an invalid file.
  3128. (should-error (org-file-contents "this-file-must-not-exist"))
  3129. ;; Try to access an invalid file, but do not throw an error.
  3130. (should
  3131. (progn (org-file-contents "this-file-must-not-exist" :noerror) t))
  3132. ;; Open URL.
  3133. (should
  3134. (string= "foo"
  3135. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3136. (unwind-protect
  3137. ;; Simulate successful retrieval of a URL.
  3138. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3139. (lambda (&rest_)
  3140. (with-current-buffer buffer
  3141. (insert "HTTP/1.1 200 OK\n\nfoo"))
  3142. buffer)))
  3143. (org-file-contents "http://some-valid-url"))
  3144. (kill-buffer buffer)))))
  3145. ;; Throw error when trying to access an invalid URL.
  3146. (should-error
  3147. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3148. (unwind-protect
  3149. ;; Simulate unsuccessful retrieval of a URL.
  3150. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3151. (lambda (&rest_)
  3152. (with-current-buffer buffer
  3153. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3154. buffer)))
  3155. (org-file-contents "http://this-url-must-not-exist"))
  3156. (kill-buffer buffer))))
  3157. ;; Try to access an invalid URL, but do not throw an error.
  3158. (should-error
  3159. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3160. (unwind-protect
  3161. ;; Simulate unsuccessful retrieval of a URL.
  3162. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3163. (lambda (&rest_)
  3164. (with-current-buffer buffer
  3165. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3166. buffer)))
  3167. (org-file-contents "http://this-url-must-not-exist"))
  3168. (kill-buffer buffer))))
  3169. (should
  3170. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3171. (unwind-protect
  3172. ;; Simulate unsuccessful retrieval of a URL.
  3173. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3174. (lambda (&rest_)
  3175. (with-current-buffer buffer
  3176. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3177. buffer)))
  3178. (org-file-contents "http://this-url-must-not-exist" :noerror))
  3179. (kill-buffer buffer))
  3180. t)))
  3181. ;;; Navigation
  3182. (ert-deftest test-org/next-visible-heading ()
  3183. "Test `org-next-visible-heading' specifications."
  3184. ;; Move to the beginning of the next headline, taking into
  3185. ;; consideration ARG.
  3186. (should
  3187. (org-test-with-temp-text "* H1\n* H2"
  3188. (org-next-visible-heading 1)
  3189. (looking-at "\\* H2")))
  3190. (should
  3191. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3192. (org-next-visible-heading 2)
  3193. (looking-at "\\* H3")))
  3194. ;; Ignore invisible headlines.
  3195. (should
  3196. (org-test-with-temp-text "* H1\n** H2\n* H3"
  3197. (org-cycle)
  3198. (org-next-visible-heading 1)
  3199. (looking-at "\\* H3")))
  3200. ;; Move point between headlines, not on blank lines between.
  3201. (should
  3202. (org-test-with-temp-text "* H1\n** H2\n\n\n\n* H3"
  3203. (let ((org-cycle-separator-lines 1))
  3204. (org-cycle)
  3205. (org-next-visible-heading 1))
  3206. (looking-at "\\* H3")))
  3207. ;; Move at end of buffer when there is no more headline.
  3208. (should
  3209. (org-test-with-temp-text "* H1"
  3210. (org-next-visible-heading 1)
  3211. (eobp)))
  3212. (should
  3213. (org-test-with-temp-text "* H1\n* H2"
  3214. (org-next-visible-heading 2)
  3215. (eobp)))
  3216. ;; With a negative argument, move backwards.
  3217. (should
  3218. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3219. (org-next-visible-heading -1)
  3220. (looking-at "\\* H2")))
  3221. (should
  3222. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3223. (org-next-visible-heading -2)
  3224. (looking-at "\\* H1"))))
  3225. (ert-deftest test-org/previous-visible-heading ()
  3226. "Test `org-previous-visible-heading' specifications."
  3227. ;; Move to the beginning of the next headline, taking into
  3228. ;; consideration ARG.
  3229. (should
  3230. (org-test-with-temp-text "* H1\n<point>* H2"
  3231. (org-previous-visible-heading 1)
  3232. (looking-at "\\* H1")))
  3233. (should
  3234. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3235. (org-previous-visible-heading 2)
  3236. (looking-at "\\* H1")))
  3237. ;; Ignore invisible headlines.
  3238. (should
  3239. (org-test-with-temp-text "* H1\n** H2\n<point>* H3"
  3240. (org-overview)
  3241. (org-previous-visible-heading 1)
  3242. (looking-at "\\* H1")))
  3243. ;; Move point between headlines, not on blank lines between.
  3244. (should
  3245. (org-test-with-temp-text "* H1\n\n\n\n** H2\n<point>* H3"
  3246. (let ((org-cycle-separator-lines 1))
  3247. (org-overview)
  3248. (org-previous-visible-heading 1))
  3249. (looking-at "\\* H1")))
  3250. ;; Move at end of buffer when there is no more headline.
  3251. (should
  3252. (org-test-with-temp-text "* H1"
  3253. (org-previous-visible-heading 1)
  3254. (bobp)))
  3255. (should
  3256. (org-test-with-temp-text "* H1\n* <point>H2"
  3257. (org-previous-visible-heading 2)
  3258. (bobp)))
  3259. ;; Invisible parts may not start at a headline, i.e., when revealing
  3260. ;; parts of the buffer. Handle this.
  3261. (should
  3262. (org-test-with-temp-text "* Main\n** H1\nFoo\n** H2\nBar\n** H3\nBaz"
  3263. (org-overview)
  3264. (search-forward "H1")
  3265. (org-show-context 'minimal)
  3266. (org-cycle)
  3267. (search-forward "H3")
  3268. (org-show-context 'minimal)
  3269. ;; At this point, buffer displays, with point at "|",
  3270. ;;
  3271. ;; * Main
  3272. ;; ** H1
  3273. ;; Foo
  3274. ;; ** H3|
  3275. (org-previous-visible-heading 1)
  3276. (looking-at "\\*+ H1"))))
  3277. (ert-deftest test-org/forward-heading-same-level ()
  3278. "Test `org-forward-heading-same-level' specifications."
  3279. ;; Test navigation at top level, forward and backward.
  3280. (should
  3281. (equal "* H2"
  3282. (org-test-with-temp-text "* H1\n* H2"
  3283. (org-forward-heading-same-level 1)
  3284. (buffer-substring-no-properties (point) (line-end-position)))))
  3285. (should
  3286. (equal "* H1"
  3287. (org-test-with-temp-text "* H1\n<point>* H2"
  3288. (org-forward-heading-same-level -1)
  3289. (buffer-substring-no-properties (point) (line-end-position)))))
  3290. ;; Test navigation in a sub-tree, forward and backward.
  3291. (should
  3292. (equal "* H2"
  3293. (org-test-with-temp-text "* H1\n** H11\n** H12\n* H2"
  3294. (org-forward-heading-same-level 1)
  3295. (buffer-substring-no-properties (point) (line-end-position)))))
  3296. (should
  3297. (equal "* H1"
  3298. (org-test-with-temp-text "* H1\n** H11\n** H12\n<point>* H2"
  3299. (org-forward-heading-same-level -1)
  3300. (buffer-substring-no-properties (point) (line-end-position)))))
  3301. ;; Stop at first or last sub-heading.
  3302. (should-not
  3303. (equal "* H2"
  3304. (org-test-with-temp-text "* H1\n** H11\n<point>** H12\n* H2"
  3305. (org-forward-heading-same-level 1)
  3306. (buffer-substring-no-properties (point) (line-end-position)))))
  3307. (should-not
  3308. (equal "* H2"
  3309. (org-test-with-temp-text "* H1\n<point>** H11\n** H12\n* H2"
  3310. (org-forward-heading-same-level -1)
  3311. (buffer-substring-no-properties (point) (line-end-position)))))
  3312. ;; Allow multiple moves.
  3313. (should
  3314. (equal "* H3"
  3315. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3316. (org-forward-heading-same-level 2)
  3317. (buffer-substring-no-properties (point) (line-end-position)))))
  3318. (should
  3319. (equal "* H1"
  3320. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3321. (org-forward-heading-same-level -2)
  3322. (buffer-substring-no-properties (point) (line-end-position)))))
  3323. ;; Ignore spurious moves when first (or last) sibling is reached.
  3324. (should
  3325. (equal "** H3"
  3326. (org-test-with-temp-text "* First\n<point>** H1\n** H2\n** H3\n* Last"
  3327. (org-forward-heading-same-level 100)
  3328. (buffer-substring-no-properties (point) (line-end-position)))))
  3329. (should
  3330. (equal "** H1"
  3331. (org-test-with-temp-text "* First\n** H1\n** H2\n<point>** H3\n* Last"
  3332. (org-forward-heading-same-level -100)
  3333. (buffer-substring-no-properties (point) (line-end-position))))))
  3334. (ert-deftest test-org/end-of-meta-data ()
  3335. "Test `org-end-of-meta-data' specifications."
  3336. ;; Skip planning line.
  3337. (should
  3338. (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
  3339. (org-end-of-meta-data)
  3340. (eobp)))
  3341. ;; Skip properties drawer.
  3342. (should
  3343. (org-test-with-temp-text
  3344. "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
  3345. (org-end-of-meta-data)
  3346. (eobp)))
  3347. ;; Skip both.
  3348. (should
  3349. (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
  3350. (org-end-of-meta-data)
  3351. (eobp)))
  3352. ;; Nothing to skip, go to first line.
  3353. (should
  3354. (org-test-with-temp-text "* Headline\nContents"
  3355. (org-end-of-meta-data)
  3356. (looking-at "Contents")))
  3357. ;; With option argument, skip empty lines, regular drawers and
  3358. ;; clocking lines.
  3359. (should
  3360. (org-test-with-temp-text "* Headline\n\nContents"
  3361. (org-end-of-meta-data t)
  3362. (looking-at "Contents")))
  3363. (should
  3364. (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
  3365. (org-end-of-meta-data t)
  3366. (looking-at "Contents")))
  3367. (should
  3368. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
  3369. (org-end-of-meta-data t)
  3370. (looking-at "Contents")))
  3371. ;; Special case: do not skip incomplete drawers.
  3372. (should
  3373. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
  3374. (org-end-of-meta-data t)
  3375. (looking-at ":LOGBOOK:")))
  3376. ;; Special case: Be careful about consecutive headlines.
  3377. (should-not
  3378. (org-test-with-temp-text "* H1\n*H2\nContents"
  3379. (org-end-of-meta-data t)
  3380. (looking-at "Contents"))))
  3381. (ert-deftest test-org/shiftright-heading ()
  3382. "Test `org-shiftright' on headings."
  3383. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  3384. (should
  3385. (equal "* TODO a1\n** a2\n* DONE b1\n"
  3386. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3387. (org-shiftright)
  3388. (buffer-string))))
  3389. (should
  3390. (equal "* TODO a1\n** TODO a2\n* b1\n"
  3391. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3392. (let ((org-loop-over-headlines-in-active-region t))
  3393. (transient-mark-mode 1)
  3394. (push-mark (point) t t)
  3395. (search-forward "* DONE b1")
  3396. (org-shiftright))
  3397. (buffer-string))))
  3398. (should
  3399. (equal "* TODO a1\n** 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 'start-level))
  3402. (transient-mark-mode 1)
  3403. (push-mark (point) t t)
  3404. (search-forward "* DONE b1")
  3405. (org-shiftright))
  3406. (buffer-string))))))
  3407. (ert-deftest test-org/beginning-of-line ()
  3408. "Test `org-beginning-of-line' specifications."
  3409. ;; Move to beginning of line. If current line in invisible, move to
  3410. ;; beginning of visible line instead.
  3411. (should
  3412. (org-test-with-temp-text "Some text\nSome other text<point>"
  3413. (org-beginning-of-line)
  3414. (bolp)))
  3415. (should
  3416. (org-test-with-temp-text "* H1\n** H2<point>"
  3417. (org-overview)
  3418. (org-beginning-of-line)
  3419. (= (line-beginning-position) 1)))
  3420. ;; With `visual-line-mode' active, move to beginning of visual line.
  3421. (should-not
  3422. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3423. (visual-line-mode)
  3424. (dotimes (i 1000) (insert "very "))
  3425. (org-beginning-of-line)
  3426. (bolp)))
  3427. ;; In a wide headline, with `visual-line-mode', prefer going to the
  3428. ;; beginning of a visual line than to the logical beginning of line,
  3429. ;; even if special movement is active.
  3430. (should-not
  3431. (org-test-with-temp-text "* A <point>long headline"
  3432. (visual-line-mode)
  3433. (dotimes (i 1000) (insert "very "))
  3434. (goto-char (point-max))
  3435. (org-beginning-of-line)
  3436. (bobp)))
  3437. (should-not
  3438. (org-test-with-temp-text "* A <point>long headline"
  3439. (visual-line-mode)
  3440. (dotimes (i 1000) (insert "very "))
  3441. (goto-char (point-max))
  3442. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line))
  3443. (bobp)))
  3444. ;; At an headline with special movement, first move at beginning of
  3445. ;; title, then at the beginning of line, rinse, repeat.
  3446. (should
  3447. (org-test-with-temp-text "* TODO Headline<point>"
  3448. (let ((org-special-ctrl-a/e t))
  3449. (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
  3450. (progn (org-beginning-of-line) (bolp))
  3451. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3452. (should
  3453. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3454. (let ((org-special-ctrl-a/e t))
  3455. (org-beginning-of-line)
  3456. (looking-at "Headline"))))
  3457. (should
  3458. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3459. (let ((org-special-ctrl-a/e '(t . nil)))
  3460. (org-beginning-of-line)
  3461. (looking-at "Headline"))))
  3462. (should-not
  3463. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3464. (let ((org-special-ctrl-a/e '(nil . nil)))
  3465. (org-beginning-of-line)
  3466. (looking-at "Headline"))))
  3467. ;; At an headline with reversed movement, first move to beginning of
  3468. ;; line, then to the beginning of title.
  3469. (should
  3470. (org-test-with-temp-text "* TODO Headline<point>"
  3471. (let ((org-special-ctrl-a/e 'reversed)
  3472. (this-command last-command))
  3473. (and (progn (org-beginning-of-line) (bolp))
  3474. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3475. (should
  3476. (org-test-with-temp-text "* TODO Headline<point>"
  3477. (let ((org-special-ctrl-a/e '(reversed . nil))
  3478. (this-command last-command))
  3479. (and (progn (org-beginning-of-line) (bolp))
  3480. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3481. (should-not
  3482. (org-test-with-temp-text "* TODO Headline<point>"
  3483. (let ((org-special-ctrl-a/e '(t . nil))
  3484. (this-command last-command))
  3485. (and (progn (org-beginning-of-line) (bolp))
  3486. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3487. ;; At an item with special movement, first move after to beginning
  3488. ;; of title, then to the beginning of line, rinse, repeat.
  3489. (should
  3490. (org-test-with-temp-text "- [ ] Item<point>"
  3491. (let ((org-special-ctrl-a/e t))
  3492. (and (progn (org-beginning-of-line) (looking-at-p "Item"))
  3493. (progn (org-beginning-of-line) (bolp))
  3494. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3495. ;; At an item with reversed movement, first move to beginning of
  3496. ;; line, then to the beginning of title.
  3497. (should
  3498. (org-test-with-temp-text "- [X] Item<point>"
  3499. (let ((org-special-ctrl-a/e 'reversed)
  3500. (this-command last-command))
  3501. (and (progn (org-beginning-of-line) (bolp))
  3502. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3503. ;; Leave point before invisible characters at column 0.
  3504. (should
  3505. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3506. (let ((org-special-ctrl-a/e nil))
  3507. (org-beginning-of-line)
  3508. (bolp))))
  3509. (should
  3510. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3511. (let ((org-special-ctrl-a/e t))
  3512. (org-beginning-of-line)
  3513. (bolp))))
  3514. (should
  3515. (org-test-with-temp-text "[[http<point>://orgmode.org]]"
  3516. (visual-line-mode)
  3517. (org-beginning-of-line)
  3518. (bolp)))
  3519. ;; Special case: Do not error when the buffer contains only a single
  3520. ;; asterisk.
  3521. (should
  3522. (org-test-with-temp-text "*<point>"
  3523. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line) t)))
  3524. (should
  3525. (org-test-with-temp-text "*<point>"
  3526. (let ((org-special-ctrl-a/e nil)) (org-beginning-of-line) t))))
  3527. (ert-deftest test-org/end-of-line ()
  3528. "Test `org-end-of-line' specifications."
  3529. ;; Standard test.
  3530. (should
  3531. (org-test-with-temp-text "Some text\nSome other text"
  3532. (org-end-of-line)
  3533. (eolp)))
  3534. ;; With `visual-line-mode' active, move to end of visible line.
  3535. ;; However, never go past ellipsis.
  3536. (should-not
  3537. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3538. (visual-line-mode)
  3539. (dotimes (i 1000) (insert "very "))
  3540. (goto-char (point-min))
  3541. (org-end-of-line)
  3542. (eolp)))
  3543. (should-not
  3544. (org-test-with-temp-text "* A short headline\nSome contents"
  3545. (visual-line-mode)
  3546. (org-overview)
  3547. (org-end-of-line)
  3548. (eobp)))
  3549. ;; In a wide headline, with `visual-line-mode', prefer going to end
  3550. ;; of visible line if tags, or end of line, are farther.
  3551. (should-not
  3552. (org-test-with-temp-text "* A <point>long headline"
  3553. (visual-line-mode)
  3554. (dotimes (i 1000) (insert "very "))
  3555. (goto-char (point-min))
  3556. (org-end-of-line)
  3557. (eolp)))
  3558. (should-not
  3559. (org-test-with-temp-text "* A <point>long headline :tag:"
  3560. (visual-line-mode)
  3561. (dotimes (i 1000) (insert "very "))
  3562. (goto-char (point-min))
  3563. (org-end-of-line)
  3564. (eolp)))
  3565. ;; At an headline without special movement, go to end of line.
  3566. ;; However, never go past ellipsis.
  3567. (should
  3568. (org-test-with-temp-text "* Headline2b :tag:\n"
  3569. (let ((org-special-ctrl-a/e nil))
  3570. (and (progn (org-end-of-line) (eolp))
  3571. (progn (org-end-of-line) (eolp))))))
  3572. (should
  3573. (org-test-with-temp-text "* Headline2b :tag:\n"
  3574. (let ((org-special-ctrl-a/e '(t . nil)))
  3575. (and (progn (org-end-of-line) (eolp))
  3576. (progn (org-end-of-line) (eolp))))))
  3577. (should
  3578. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3579. (org-overview)
  3580. (let ((org-special-ctrl-a/e nil))
  3581. (org-end-of-line)
  3582. (= 1 (line-beginning-position)))))
  3583. ;; At an headline with special movement, first move before tags,
  3584. ;; then at the end of line, rinse, repeat. However, never go past
  3585. ;; ellipsis.
  3586. (should
  3587. (org-test-with-temp-text "* Headline1 :tag:\n"
  3588. (let ((org-special-ctrl-a/e t))
  3589. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3590. (progn (org-end-of-line) (eolp))
  3591. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3592. (should
  3593. (org-test-with-temp-text "* Headline1 :tag:\n"
  3594. (let ((org-special-ctrl-a/e '(nil . t)))
  3595. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3596. (progn (org-end-of-line) (eolp))
  3597. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3598. (should-not
  3599. (org-test-with-temp-text "* Headline1 :tag:\n"
  3600. (let ((org-special-ctrl-a/e '(nil . nil)))
  3601. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3602. (progn (org-end-of-line) (eolp))
  3603. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3604. (should
  3605. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3606. (org-overview)
  3607. (let ((org-special-ctrl-a/e t))
  3608. (org-end-of-line)
  3609. (org-end-of-line)
  3610. (= 1 (line-beginning-position)))))
  3611. ;; At an headline, with reversed movement, first go to end of line,
  3612. ;; then before tags. However, never go past ellipsis.
  3613. (should
  3614. (org-test-with-temp-text "* Headline3 :tag:\n"
  3615. (let ((org-special-ctrl-a/e 'reversed)
  3616. (this-command last-command))
  3617. (and (progn (org-end-of-line) (eolp))
  3618. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3619. (should
  3620. (org-test-with-temp-text "* Headline3 :tag:\n"
  3621. (let ((org-special-ctrl-a/e '(nil . reversed))
  3622. (this-command last-command))
  3623. (and (progn (org-end-of-line) (eolp))
  3624. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3625. (should-not
  3626. (org-test-with-temp-text "* Headline3 :tag:\n"
  3627. (let ((org-special-ctrl-a/e '(nil . t))
  3628. (this-command last-command))
  3629. (and (progn (org-end-of-line) (eolp))
  3630. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3631. (should
  3632. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3633. (org-overview)
  3634. (let ((org-special-ctrl-a/e 'reversed))
  3635. (org-end-of-line)
  3636. (= 1 (line-beginning-position)))))
  3637. ;; At a block without hidden contents.
  3638. (should
  3639. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3640. (progn (org-end-of-line) (eolp))))
  3641. ;; At a block with hidden contents.
  3642. (should-not
  3643. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3644. (let ((org-special-ctrl-a/e t))
  3645. (org-hide-block-toggle)
  3646. (org-end-of-line)
  3647. (eobp))))
  3648. ;; Get past invisible characters at the end of line.
  3649. (should
  3650. (org-test-with-temp-text "[[https://orgmode.org]]"
  3651. (org-end-of-line)
  3652. (eolp))))
  3653. (ert-deftest test-org/open-line ()
  3654. "Test `org-open-line' specifications."
  3655. ;; Call `open-line' outside of tables.
  3656. (should
  3657. (equal "\nText"
  3658. (org-test-with-temp-text "Text"
  3659. (org-open-line 1)
  3660. (buffer-string))))
  3661. ;; At a table, create a row above.
  3662. (should
  3663. (equal "\n| |\n| a |"
  3664. (org-test-with-temp-text "\n<point>| a |"
  3665. (org-open-line 1)
  3666. (buffer-string))))
  3667. ;; At the very first character of the buffer, also call `open-line'.
  3668. (should
  3669. (equal "\n| a |"
  3670. (org-test-with-temp-text "| a |"
  3671. (org-open-line 1)
  3672. (buffer-string))))
  3673. ;; Narrowing does not count.
  3674. (should
  3675. (equal "Text\n| |\n| a |"
  3676. (org-test-with-temp-text "Text\n<point>| a |"
  3677. (narrow-to-region (point) (point-max))
  3678. (org-open-line 1)
  3679. (widen)
  3680. (buffer-string)))))
  3681. (ert-deftest test-org/forward-sentence ()
  3682. "Test `org-forward-sentence' specifications."
  3683. ;; At the end of a table cell, move to the end of the next one.
  3684. (should
  3685. (org-test-with-temp-text "| a<point> | b |"
  3686. (org-forward-sentence)
  3687. (looking-at " |$")))
  3688. ;; Elsewhere in a cell, move to its end.
  3689. (should
  3690. (org-test-with-temp-text "| a<point>c | b |"
  3691. (org-forward-sentence)
  3692. (looking-at " | b |$")))
  3693. ;; Otherwise, simply call `forward-sentence'.
  3694. (should
  3695. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3696. (org-forward-sentence)
  3697. (looking-at " Sentence 2.")))
  3698. (should
  3699. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3700. (org-forward-sentence)
  3701. (org-forward-sentence)
  3702. (eobp)))
  3703. ;; At the end of an element, jump to the next one, without stopping
  3704. ;; on blank lines in-between.
  3705. (should
  3706. (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
  3707. (org-forward-sentence)
  3708. (eobp)))
  3709. ;; Headlines are considered to be sentences by themselves, even if
  3710. ;; they do not end with a full stop.
  3711. (should
  3712. (equal
  3713. "* Headline"
  3714. (org-test-with-temp-text "* <point>Headline\nSentence."
  3715. (org-forward-sentence)
  3716. (buffer-substring-no-properties (line-beginning-position) (point)))))
  3717. (should
  3718. (org-test-with-temp-text "* Headline<point>\nSentence."
  3719. (org-forward-sentence)
  3720. (eobp)))
  3721. (should
  3722. (org-test-with-temp-text "Sentence.<point>\n\n* Headline\n\nSentence 2."
  3723. (org-forward-sentence)
  3724. (and (org-at-heading-p) (eolp)))))
  3725. (ert-deftest test-org/backward-sentence ()
  3726. "Test `org-backward-sentence' specifications."
  3727. ;; At the beginning of a table cell, move to the beginning of the
  3728. ;; previous one.
  3729. (should
  3730. (org-test-with-temp-text "| a | <point>b |"
  3731. (org-backward-sentence)
  3732. (looking-at "a | b |$")))
  3733. ;; Elsewhere in a cell, move to its beginning.
  3734. (should
  3735. (org-test-with-temp-text "| a | b<point>c |"
  3736. (org-backward-sentence)
  3737. (looking-at "bc |$")))
  3738. ;; Otherwise, simply call `backward-sentence'.
  3739. (should
  3740. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3741. (org-backward-sentence)
  3742. (looking-at "Sentence 2.")))
  3743. (should
  3744. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3745. (org-backward-sentence)
  3746. (org-backward-sentence)
  3747. (bobp)))
  3748. ;; Make sure to hit the beginning of a sentence on the same line as
  3749. ;; an item.
  3750. (should
  3751. (org-test-with-temp-text "- Line 1\n line <point>2."
  3752. (org-backward-sentence)
  3753. (looking-at "Line 1"))))
  3754. (ert-deftest test-org/forward-paragraph ()
  3755. "Test `org-forward-paragraph' specifications."
  3756. ;; At end of buffer, do not return an error.
  3757. (should
  3758. (org-test-with-temp-text "Paragraph"
  3759. (goto-char (point-max))
  3760. (org-forward-paragraph)
  3761. t))
  3762. ;; Standard test.
  3763. (should
  3764. (= 2
  3765. (org-test-with-temp-text "P1\n\nP2"
  3766. (org-forward-paragraph)
  3767. (org-current-line))))
  3768. (should
  3769. (= 2
  3770. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  3771. (org-forward-paragraph)
  3772. (org-current-line))))
  3773. ;; Enter greater elements.
  3774. (should
  3775. (= 2
  3776. (org-test-with-temp-text "#+begin_center\nP1\n#+end_center\nP2"
  3777. (org-forward-paragraph)
  3778. (org-current-line))))
  3779. ;; Do not enter elements with invisible contents.
  3780. (should
  3781. (= 4
  3782. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  3783. (org-cycle)
  3784. (org-forward-paragraph)
  3785. (org-current-line))))
  3786. (should
  3787. (= 6
  3788. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\nP3"
  3789. (org-hide-block-toggle)
  3790. (org-forward-paragraph)
  3791. (org-current-line))))
  3792. ;; On an item or a footnote definition, move past the first element
  3793. ;; inside, if any.
  3794. (should
  3795. (= 2
  3796. (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
  3797. (org-forward-paragraph)
  3798. (org-current-line))))
  3799. (should
  3800. (= 2
  3801. (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
  3802. (org-forward-paragraph)
  3803. (org-current-line))))
  3804. ;; On a table (resp. a property drawer) do not move through table
  3805. ;; rows (resp. node properties).
  3806. (should
  3807. (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
  3808. (org-forward-paragraph)
  3809. (looking-at "Paragraph")))
  3810. (should
  3811. (org-test-with-temp-text
  3812. "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
  3813. (org-forward-paragraph)
  3814. (looking-at "Paragraph")))
  3815. ;; Skip consecutive keywords, clocks and diary S-exps.
  3816. (should
  3817. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n"
  3818. (org-forward-paragraph)
  3819. (eobp)))
  3820. (should
  3821. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n"
  3822. (org-forward-paragraph)
  3823. (eobp)))
  3824. (should
  3825. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n"
  3826. (org-forward-paragraph)
  3827. (eobp)))
  3828. (should-not
  3829. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n"
  3830. (org-forward-paragraph)
  3831. (eobp)))
  3832. (should-not
  3833. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n"
  3834. (org-forward-paragraph)
  3835. (eobp)))
  3836. ;; In a plain list with one item every line, skip the whole list,
  3837. ;; even with point in the middle of the list.
  3838. (should
  3839. (org-test-with-temp-text "- A\n - B\n- C\n"
  3840. (org-forward-paragraph)
  3841. (eobp)))
  3842. (should
  3843. (org-test-with-temp-text "- A\n - <point>B\n- C\n"
  3844. (org-forward-paragraph)
  3845. (eobp)))
  3846. ;; On a comment, verse or source block, stop at "contents"
  3847. ;; boundaries and blank lines.
  3848. (should
  3849. (= 2
  3850. (org-test-with-temp-text "#+begin_src emacs-lisp\nL1\n\nL2\n#+end_src"
  3851. (org-forward-paragraph)
  3852. (org-current-line))))
  3853. (should
  3854. (= 3
  3855. (org-test-with-temp-text "#+begin_verse\n<point>L1\n\nL2\n#+end_verse"
  3856. (org-forward-paragraph)
  3857. (org-current-line))))
  3858. (should
  3859. (= 5
  3860. (org-test-with-temp-text "#+begin_comment\nL1\n\n<point>L2\n#+end_comment"
  3861. (org-forward-paragraph)
  3862. (org-current-line))))
  3863. ;; Being on an affiliated keyword shouldn't make any difference.
  3864. (should
  3865. (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
  3866. (org-forward-paragraph)
  3867. (eobp))))
  3868. (ert-deftest test-org/backward-paragraph ()
  3869. "Test `org-backward-paragraph' specifications."
  3870. ;; Do not error at beginning of buffer.
  3871. (should
  3872. (org-test-with-temp-text "Paragraph"
  3873. (org-backward-paragraph)
  3874. t))
  3875. ;; At blank lines at the very beginning of a buffer, move to
  3876. ;; point-min.
  3877. (should
  3878. (org-test-with-temp-text "\n\n<point>\n\nParagraph"
  3879. (org-backward-paragraph)
  3880. (bobp)))
  3881. ;; Regular test.
  3882. (should
  3883. (= 2
  3884. (org-test-with-temp-text "P1\n\nP2<point>"
  3885. (org-backward-paragraph)
  3886. (org-current-line))))
  3887. (should
  3888. (= 4
  3889. (org-test-with-temp-text "P1\n\nP2\n\nP3<point>"
  3890. (org-backward-paragraph)
  3891. (org-current-line))))
  3892. ;; Try to move on the line above current element.
  3893. (should
  3894. (= 2
  3895. (org-test-with-temp-text "\n\n<point>Paragraph"
  3896. (org-backward-paragraph)
  3897. (org-current-line))))
  3898. ;; Do not leave point in an invisible area.
  3899. (should
  3900. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  3901. (org-cycle)
  3902. (goto-char (point-max))
  3903. (beginning-of-line)
  3904. (org-backward-paragraph)
  3905. (bobp)))
  3906. (should
  3907. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\n"
  3908. (org-hide-block-toggle)
  3909. (goto-char (point-max))
  3910. (org-backward-paragraph)
  3911. (bobp)))
  3912. ;; On the first element in an item or a footnote definition, jump
  3913. ;; before the footnote or the item.
  3914. (should
  3915. (org-test-with-temp-text "- line1<point>"
  3916. (org-backward-paragraph)
  3917. (bobp)))
  3918. (should
  3919. (org-test-with-temp-text "[fn:1] line1n<point>"
  3920. (org-backward-paragraph)
  3921. (bobp)))
  3922. ;; On the second element in an item or a footnote definition, jump
  3923. ;; to item or the definition.
  3924. (should
  3925. (= 2
  3926. (org-test-with-temp-text "- line1\n\n<point> line2"
  3927. (org-backward-paragraph)
  3928. (org-current-line))))
  3929. (should
  3930. (= 2
  3931. (org-test-with-temp-text "[fn:1] line1\n\n<point> line2"
  3932. (org-backward-paragraph)
  3933. (org-current-line))))
  3934. ;; On a table (resp. a property drawer), ignore table rows
  3935. ;; (resp. node properties).
  3936. (should
  3937. (org-test-with-temp-text "| a | b |\n| c | d |\n<point>P1"
  3938. (org-backward-paragraph)
  3939. (bobp)))
  3940. (should
  3941. (= 2
  3942. (org-test-with-temp-text
  3943. "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
  3944. (org-backward-paragraph)
  3945. (org-current-line))))
  3946. ;; In a plain list with one item every line, skip the whole list,
  3947. ;; even with point in the middle of the list.
  3948. (should
  3949. (org-test-with-temp-text "- A\n - B\n- C\n<point>"
  3950. (org-backward-paragraph)
  3951. (bobp)))
  3952. (should
  3953. (org-test-with-temp-text "- A\n - B\n- <point>C\n"
  3954. (org-backward-paragraph)
  3955. (bobp)))
  3956. ;; Skip consecutive keywords, clocks and diary S-exps.
  3957. (should
  3958. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n<point>"
  3959. (org-backward-paragraph)
  3960. (bobp)))
  3961. (should
  3962. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n<point>"
  3963. (org-backward-paragraph)
  3964. (bobp)))
  3965. (should
  3966. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n<point>"
  3967. (org-backward-paragraph)
  3968. (bobp)))
  3969. (should-not
  3970. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n<point>"
  3971. (org-backward-paragraph)
  3972. (bobp)))
  3973. (should-not
  3974. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n<point>"
  3975. (org-backward-paragraph)
  3976. (bobp)))
  3977. ;; On a comment, example, source and verse blocks, stop at blank
  3978. ;; lines.
  3979. (should
  3980. (= 1
  3981. (org-test-with-temp-text
  3982. "#+begin_comment\n<point>L1\n\nL2\n\nL3\n#+end_comment"
  3983. (org-backward-paragraph)
  3984. (org-current-line))))
  3985. (should
  3986. (= 2
  3987. (org-test-with-temp-text
  3988. "#+begin_verse\nL1\n\n<point>L2\n\nL3\n#+end_verse"
  3989. (org-backward-paragraph)
  3990. (org-current-line))))
  3991. (should
  3992. (= 3
  3993. (org-test-with-temp-text
  3994. "#+begin_src emacs-lisp\nL1\n\nL2\n\n<point>L3\n#+end_src"
  3995. (org-backward-paragraph)
  3996. (org-current-line))))
  3997. ;; When called from the opening line itself, however, move to
  3998. ;; beginning of block.
  3999. (should
  4000. (org-test-with-temp-text "#+begin_<point>example\nL1\n#+end_example"
  4001. (org-backward-paragraph)
  4002. (bobp)))
  4003. ;; On an empty heading, move above it.
  4004. (should
  4005. (org-test-with-temp-text "\n* <point>"
  4006. (org-backward-paragraph)
  4007. (bobp)))
  4008. (should
  4009. (org-test-with-temp-text "\n* \n<point>"
  4010. (org-backward-paragraph)
  4011. (bobp))))
  4012. (ert-deftest test-org/forward-element ()
  4013. "Test `org-forward-element' specifications."
  4014. ;; 1. At EOB: should error.
  4015. (org-test-with-temp-text "Some text\n"
  4016. (goto-char (point-max))
  4017. (should-error (org-forward-element)))
  4018. ;; 2. Standard move: expected to ignore blank lines.
  4019. (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
  4020. (org-forward-element)
  4021. (should (looking-at (regexp-quote "Second paragraph."))))
  4022. ;; 3. Headline tests.
  4023. (org-test-with-temp-text "
  4024. * Head 1
  4025. ** Head 1.1
  4026. *** Head 1.1.1
  4027. ** Head 1.2"
  4028. ;; 3.1. At an headline beginning: move to next headline at the
  4029. ;; same level.
  4030. (goto-line 3)
  4031. (org-forward-element)
  4032. (should (looking-at (regexp-quote "** Head 1.2")))
  4033. ;; 3.2. At an headline beginning: move to parent headline if no
  4034. ;; headline at the same level.
  4035. (goto-line 3)
  4036. (org-forward-element)
  4037. (should (looking-at (regexp-quote "** Head 1.2"))))
  4038. ;; 4. Greater element tests.
  4039. (org-test-with-temp-text
  4040. "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
  4041. ;; 4.1. At a greater element: expected to skip contents.
  4042. (org-forward-element)
  4043. (should (looking-at (regexp-quote "Outside.")))
  4044. ;; 4.2. At the end of greater element contents: expected to skip
  4045. ;; to the end of the greater element.
  4046. (goto-line 2)
  4047. (org-forward-element)
  4048. (should (looking-at (regexp-quote "Outside."))))
  4049. ;; 5. List tests.
  4050. (org-test-with-temp-text "
  4051. - item1
  4052. - sub1
  4053. - sub2
  4054. - sub3
  4055. Inner paragraph.
  4056. - item2
  4057. Outside."
  4058. ;; 5.1. At list top point: expected to move to the element after
  4059. ;; the list.
  4060. (goto-line 2)
  4061. (org-forward-element)
  4062. (should (looking-at (regexp-quote "Outside.")))
  4063. ;; 5.2. Special case: at the first line of a sub-list, but not at
  4064. ;; beginning of line, move to next item.
  4065. (goto-line 2)
  4066. (forward-char)
  4067. (org-forward-element)
  4068. (should (looking-at "- item2"))
  4069. (goto-line 4)
  4070. (forward-char)
  4071. (org-forward-element)
  4072. (should (looking-at " - sub2"))
  4073. ;; 5.3 At sub-list beginning: expected to move after the sub-list.
  4074. (goto-line 4)
  4075. (org-forward-element)
  4076. (should (looking-at (regexp-quote " Inner paragraph.")))
  4077. ;; 5.4. At sub-list end: expected to move outside the sub-list.
  4078. (goto-line 8)
  4079. (org-forward-element)
  4080. (should (looking-at (regexp-quote " Inner paragraph.")))
  4081. ;; 5.5. At an item: expected to move to next item, if any.
  4082. (goto-line 6)
  4083. (org-forward-element)
  4084. (should (looking-at " - sub3"))))
  4085. (ert-deftest test-org/backward-element ()
  4086. "Test `org-backward-element' specifications."
  4087. ;; 1. Should error at BOB.
  4088. (org-test-with-temp-text " \nParagraph."
  4089. (should-error (org-backward-element)))
  4090. ;; 2. Should move at BOB when called on the first element in buffer.
  4091. (should
  4092. (org-test-with-temp-text "\n#+TITLE: test"
  4093. (progn (forward-line)
  4094. (org-backward-element)
  4095. (bobp))))
  4096. ;; 3. Not at the beginning of an element: move at its beginning.
  4097. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  4098. (goto-line 3)
  4099. (end-of-line)
  4100. (org-backward-element)
  4101. (should (looking-at (regexp-quote "Paragraph2."))))
  4102. ;; 4. Headline tests.
  4103. (org-test-with-temp-text "
  4104. * Head 1
  4105. ** Head 1.1
  4106. *** Head 1.1.1
  4107. ** Head 1.2"
  4108. ;; 4.1. At an headline beginning: move to previous headline at the
  4109. ;; same level.
  4110. (goto-line 5)
  4111. (org-backward-element)
  4112. (should (looking-at (regexp-quote "** Head 1.1")))
  4113. ;; 4.2. At an headline beginning: move to parent headline if no
  4114. ;; headline at the same level.
  4115. (goto-line 3)
  4116. (org-backward-element)
  4117. (should (looking-at (regexp-quote "* Head 1")))
  4118. ;; 4.3. At the first top-level headline: should error.
  4119. (goto-line 2)
  4120. (should-error (org-backward-element)))
  4121. ;; 5. At beginning of first element inside a greater element:
  4122. ;; expected to move to greater element's beginning.
  4123. (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
  4124. (goto-line 3)
  4125. (org-backward-element)
  4126. (should (looking-at "#\\+BEGIN_CENTER")))
  4127. ;; 6. At the beginning of the first element in a section: should
  4128. ;; move back to headline, if any.
  4129. (should
  4130. (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
  4131. (progn (goto-char (point-max))
  4132. (beginning-of-line)
  4133. (org-backward-element)
  4134. (org-at-heading-p))))
  4135. ;; 7. List tests.
  4136. (org-test-with-temp-text "
  4137. - item1
  4138. - sub1
  4139. - sub2
  4140. - sub3
  4141. Inner paragraph.
  4142. - item2
  4143. Outside."
  4144. ;; 7.1. At beginning of sub-list: expected to move to the
  4145. ;; paragraph before it.
  4146. (goto-line 4)
  4147. (org-backward-element)
  4148. (should (looking-at "item1"))
  4149. ;; 7.2. At an item in a list: expected to move at previous item.
  4150. (goto-line 8)
  4151. (org-backward-element)
  4152. (should (looking-at " - sub2"))
  4153. (goto-line 12)
  4154. (org-backward-element)
  4155. (should (looking-at "- item1"))
  4156. ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
  4157. ;; beginning.
  4158. (goto-line 10)
  4159. (org-backward-element)
  4160. (should (looking-at " - sub1"))
  4161. (goto-line 15)
  4162. (org-backward-element)
  4163. (should (looking-at "- item1"))
  4164. ;; 7.4. At blank-lines before list end: expected to move to top
  4165. ;; item.
  4166. (goto-line 14)
  4167. (org-backward-element)
  4168. (should (looking-at "- item1"))))
  4169. (ert-deftest test-org/up-element ()
  4170. "Test `org-up-element' specifications."
  4171. ;; 1. At BOB or with no surrounding element: should error.
  4172. (org-test-with-temp-text "Paragraph."
  4173. (should-error (org-up-element)))
  4174. (org-test-with-temp-text "* Head1\n* Head2"
  4175. (goto-line 2)
  4176. (should-error (org-up-element)))
  4177. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  4178. (goto-line 3)
  4179. (should-error (org-up-element)))
  4180. ;; 2. At an headline: move to parent headline.
  4181. (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
  4182. (goto-line 3)
  4183. (org-up-element)
  4184. (should (looking-at "\\* Head1")))
  4185. ;; 3. Inside a greater element: move to greater element beginning.
  4186. (org-test-with-temp-text
  4187. "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
  4188. (goto-line 3)
  4189. (org-up-element)
  4190. (should (looking-at "#\\+BEGIN_CENTER")))
  4191. ;; 4. List tests.
  4192. (org-test-with-temp-text "* Top
  4193. - item1
  4194. - sub1
  4195. - sub2
  4196. Paragraph within sub2.
  4197. - item2"
  4198. ;; 4.1. Within an item: move to the item beginning.
  4199. (goto-line 8)
  4200. (org-up-element)
  4201. (should (looking-at " - sub2"))
  4202. ;; 4.2. At an item in a sub-list: move to parent item.
  4203. (goto-line 4)
  4204. (org-up-element)
  4205. (should (looking-at "- item1"))
  4206. ;; 4.3. At an item in top list: move to beginning of whole list.
  4207. (goto-line 10)
  4208. (org-up-element)
  4209. (should (looking-at "- item1"))
  4210. ;; 4.4. Special case. At very top point: should move to parent of
  4211. ;; list.
  4212. (goto-line 2)
  4213. (org-up-element)
  4214. (should (looking-at "\\* Top"))))
  4215. (ert-deftest test-org/down-element ()
  4216. "Test `org-down-element' specifications."
  4217. ;; Error when the element hasn't got a recursive type.
  4218. (org-test-with-temp-text "Paragraph."
  4219. (should-error (org-down-element)))
  4220. ;; Error when the element has no contents
  4221. (org-test-with-temp-text "* Headline"
  4222. (should-error (org-down-element)))
  4223. ;; When at a plain-list, move to first item.
  4224. (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
  4225. (goto-line 2)
  4226. (org-down-element)
  4227. (should (looking-at " - Item 1.1")))
  4228. (org-test-with-temp-text "#+NAME: list\n- Item 1"
  4229. (org-down-element)
  4230. (should (looking-at " Item 1")))
  4231. ;; When at a table, move to first row
  4232. (org-test-with-temp-text "#+NAME: table\n| a | b |"
  4233. (org-down-element)
  4234. (should (looking-at " a | b |")))
  4235. ;; Otherwise, move inside the greater element.
  4236. (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
  4237. (org-down-element)
  4238. (should (looking-at "Paragraph"))))
  4239. (ert-deftest test-org/drag-element-backward ()
  4240. "Test `org-drag-element-backward' specifications."
  4241. ;; Standard test.
  4242. (should
  4243. (equal
  4244. "#+key2: val2\n#+key1: val1\n#+key3: val3"
  4245. (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
  4246. (org-drag-element-backward)
  4247. (buffer-string))))
  4248. (should
  4249. (equal
  4250. "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
  4251. (org-test-with-temp-text
  4252. "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
  4253. (org-drag-element-backward)
  4254. (buffer-string))))
  4255. ;; Preserve blank lines.
  4256. (should
  4257. (equal "Paragraph 2\n\n\nPara1\n\nPara3"
  4258. (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
  4259. (org-drag-element-backward)
  4260. (buffer-string))))
  4261. ;; Preserve column.
  4262. (should
  4263. (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
  4264. (org-drag-element-backward)
  4265. (looking-at-p "2")))
  4266. ;; Error when trying to move first element of buffer.
  4267. (should-error
  4268. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4269. (org-drag-element-backward))
  4270. :type 'user-error)
  4271. ;; Error when trying to swap nested elements.
  4272. (should-error
  4273. (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
  4274. (org-drag-element-backward))
  4275. :type 'user-error)
  4276. ;; Error when trying to swap an headline element and a non-headline
  4277. ;; element.
  4278. (should-error
  4279. (org-test-with-temp-text "Test.\n<point>* Head 1"
  4280. (org-drag-element-backward))
  4281. :type 'error)
  4282. ;; Error when called before first element.
  4283. (should-error
  4284. (org-test-with-temp-text "\n<point>"
  4285. (org-drag-element-backward))
  4286. :type 'user-error)
  4287. ;; Preserve visibility of elements and their contents.
  4288. (should
  4289. (equal '((63 . 82) (26 . 48))
  4290. (org-test-with-temp-text "
  4291. #+BEGIN_CENTER
  4292. Text.
  4293. #+END_CENTER
  4294. - item 1
  4295. #+BEGIN_QUOTE
  4296. Text.
  4297. #+END_QUOTE"
  4298. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4299. (search-backward "- item 1")
  4300. (org-drag-element-backward)
  4301. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4302. (overlays-in (point-min) (point-max))))))
  4303. ;; Pathological case: handle call with point in blank lines right
  4304. ;; after a headline.
  4305. (should
  4306. (equal "* H2\n\n* H1\nText\n"
  4307. (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
  4308. (org-drag-element-backward)
  4309. (buffer-string)))))
  4310. (ert-deftest test-org/drag-element-forward ()
  4311. "Test `org-drag-element-forward' specifications."
  4312. ;; 1. Error when trying to move first element of buffer.
  4313. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4314. (goto-line 3)
  4315. (should-error (org-drag-element-forward)))
  4316. ;; 2. Error when trying to swap nested elements.
  4317. (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
  4318. (forward-line)
  4319. (should-error (org-drag-element-forward)))
  4320. ;; 3. Error when trying to swap a non-headline element and an
  4321. ;; headline.
  4322. (org-test-with-temp-text "Test.\n* Head 1"
  4323. (should-error (org-drag-element-forward)))
  4324. ;; 4. Error when called before first element.
  4325. (should-error
  4326. (org-test-with-temp-text "\n"
  4327. (forward-line)
  4328. (org-drag-element-backward))
  4329. :type 'user-error)
  4330. ;; 5. Otherwise, swap elements, preserving column and blank lines
  4331. ;; between elements.
  4332. (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
  4333. (search-forward "graph")
  4334. (org-drag-element-forward)
  4335. (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
  4336. (should (looking-at " 1")))
  4337. ;; 5. Preserve visibility of elements and their contents.
  4338. (org-test-with-temp-text "
  4339. #+BEGIN_CENTER
  4340. Text.
  4341. #+END_CENTER
  4342. - item 1
  4343. #+BEGIN_QUOTE
  4344. Text.
  4345. #+END_QUOTE"
  4346. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4347. (search-backward "#+BEGIN_CENTER")
  4348. (org-drag-element-forward)
  4349. (should
  4350. (equal
  4351. '((63 . 82) (26 . 48))
  4352. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4353. (overlays-in (point-min) (point-max)))))))
  4354. (ert-deftest test-org/next-block ()
  4355. "Test `org-next-block' specifications."
  4356. ;; Regular test.
  4357. (should
  4358. (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  4359. (org-next-block 1)
  4360. (looking-at "#\\+BEGIN_CENTER")))
  4361. ;; Ignore case.
  4362. (should
  4363. (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
  4364. (let ((case-fold-search nil))
  4365. (org-next-block 1)
  4366. (looking-at "#\\+begin_center"))))
  4367. ;; Ignore current line.
  4368. (should
  4369. (org-test-with-temp-text
  4370. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
  4371. (org-next-block 1)
  4372. (looking-at "#\\+BEGIN_CENTER")))
  4373. ;; Throw an error when no block is found.
  4374. (should-error
  4375. (org-test-with-temp-text "Paragraph"
  4376. (org-next-block 1)))
  4377. ;; With an argument, skip many blocks at once.
  4378. (should
  4379. (org-test-with-temp-text
  4380. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4381. (org-next-block 2)
  4382. (looking-at "#\\+BEGIN_QUOTE")))
  4383. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4384. (should
  4385. (org-test-with-temp-text
  4386. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4387. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4388. (looking-at "#\\+BEGIN_QUOTE")))
  4389. ;; Optional argument is also case-insensitive.
  4390. (should
  4391. (org-test-with-temp-text
  4392. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
  4393. (let ((case-fold-search nil))
  4394. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4395. (looking-at "#\\+begin_quote")))))
  4396. (ert-deftest test-org/insert-structure-template ()
  4397. "Test `org-insert-structure-template'."
  4398. ;; Test in empty buffer.
  4399. (should
  4400. (string= "#+begin_foo\n#+end_foo\n"
  4401. (org-test-with-temp-text ""
  4402. (org-insert-structure-template "foo")
  4403. (buffer-string))))
  4404. ;; Test with multiple lines in buffer.
  4405. (should
  4406. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4407. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4408. (transient-mark-mode 1)
  4409. (org-mark-element)
  4410. (org-insert-structure-template "foo")
  4411. (buffer-string))))
  4412. ;; Mark only the current line.
  4413. (should
  4414. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4415. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4416. (transient-mark-mode 1)
  4417. (set-mark (point-min))
  4418. (end-of-line)
  4419. (org-insert-structure-template "foo")
  4420. (buffer-string))))
  4421. ;; Middle of paragraph.
  4422. (should
  4423. (string= "p1\n#+begin_foo\np2\n#+end_foo\np3"
  4424. (org-test-with-temp-text "p1\n<point>p2\np3"
  4425. (set-mark (line-beginning-position))
  4426. (end-of-line)
  4427. (activate-mark)
  4428. (org-insert-structure-template "foo")
  4429. (buffer-string))))
  4430. ;; Test with text in buffer, no region, no final newline.
  4431. (should
  4432. (string= "#+begin_foo\nI'm a paragraph.\n#+end_foo\n"
  4433. (org-test-with-temp-text "I'm a paragraph."
  4434. (org-mark-element)
  4435. (org-insert-structure-template "foo")
  4436. (buffer-string))))
  4437. ;; Test with text in buffer and region set.
  4438. (should
  4439. (string= "#+begin_foo\nI'm a paragraph\n\nI'm a second paragrah\n#+end_foo\n"
  4440. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragrah"
  4441. (set-mark (point))
  4442. (goto-char (point-max))
  4443. (org-insert-structure-template "foo")
  4444. (buffer-string))))
  4445. ;; Test with example escaping.
  4446. (should
  4447. (string= "#+begin_example\n,* Heading\n#+end_example\n"
  4448. (org-test-with-temp-text "* Heading"
  4449. (org-mark-element)
  4450. (org-insert-structure-template "example")
  4451. (buffer-string))))
  4452. ;; Test with indentation.
  4453. (should
  4454. (string= " #+begin_foo\n This is a paragraph\n #+end_foo\n"
  4455. (org-test-with-temp-text " This is a paragraph"
  4456. (org-mark-element)
  4457. (org-insert-structure-template "foo")
  4458. (buffer-string))))
  4459. (should
  4460. (string= " #+begin_foo\n Line 1\n Line2\n #+end_foo\n"
  4461. (org-test-with-temp-text " Line 1\n Line2"
  4462. (org-mark-element)
  4463. (org-insert-structure-template "foo")
  4464. (buffer-string))))
  4465. ;; Test point location.
  4466. (should
  4467. (string= "#+begin_foo\n"
  4468. (org-test-with-temp-text ""
  4469. (org-insert-structure-template "foo")
  4470. (buffer-substring (point-min) (point)))))
  4471. (should
  4472. (string= "#+begin_src "
  4473. (org-test-with-temp-text ""
  4474. (org-insert-structure-template "src")
  4475. (buffer-substring (point-min) (point))))))
  4476. (ert-deftest test-org/previous-block ()
  4477. "Test `org-previous-block' specifications."
  4478. ;; Regular test.
  4479. (should
  4480. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
  4481. (org-previous-block 1)
  4482. (looking-at "#\\+BEGIN_CENTER")))
  4483. ;; Ignore case.
  4484. (should
  4485. (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
  4486. (let ((case-fold-search nil))
  4487. (org-previous-block 1)
  4488. (looking-at "#\\+begin_center"))))
  4489. ;; Ignore current line.
  4490. (should
  4491. (org-test-with-temp-text
  4492. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
  4493. (org-previous-block 1)
  4494. (looking-at "#\\+BEGIN_QUOTE")))
  4495. ;; Throw an error when no block is found.
  4496. (should-error
  4497. (org-test-with-temp-text "Paragraph<point>"
  4498. (org-previous-block 1)))
  4499. ;; With an argument, skip many blocks at once.
  4500. (should
  4501. (org-test-with-temp-text
  4502. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4503. (org-previous-block 2)
  4504. (looking-at "#\\+BEGIN_CENTER")))
  4505. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4506. (should
  4507. (org-test-with-temp-text
  4508. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4509. (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4510. (looking-at "#\\+BEGIN_QUOTE")))
  4511. ;; Optional argument is also case-insensitive.
  4512. (should
  4513. (org-test-with-temp-text
  4514. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
  4515. (let ((case-fold-search nil))
  4516. (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4517. (looking-at "#\\+begin_quote")))))
  4518. ;;; Outline structure
  4519. (ert-deftest test-org/demote ()
  4520. "Test `org-demote' specifications."
  4521. ;; Add correct number of stars according to `org-odd-levels-only'.
  4522. (should
  4523. (= 2
  4524. (org-test-with-temp-text "* H"
  4525. (let ((org-odd-levels-only nil)) (org-demote))
  4526. (org-current-level))))
  4527. (should
  4528. (= 3
  4529. (org-test-with-temp-text "* H"
  4530. (let ((org-odd-levels-only t)) (org-demote))
  4531. (org-current-level))))
  4532. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4533. (should
  4534. (org-test-with-temp-text "* H :tag:"
  4535. (let ((org-tags-column 10)
  4536. (org-auto-align-tags t)
  4537. (org-odd-levels-only nil))
  4538. (org-demote))
  4539. (org-move-to-column 10)
  4540. (looking-at-p ":tag:$")))
  4541. (should-not
  4542. (org-test-with-temp-text "* H :tag:"
  4543. (let ((org-tags-column 10)
  4544. (org-auto-align-tags nil)
  4545. (org-odd-levels-only nil))
  4546. (org-demote))
  4547. (org-move-to-column 10)
  4548. (looking-at-p ":tag:$")))
  4549. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4550. ;; info and property drawers accordingly.
  4551. (should
  4552. (= 3
  4553. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4554. (let ((org-odd-levels-only nil)
  4555. (org-adapt-indentation t))
  4556. (org-demote))
  4557. (forward-line)
  4558. (org-get-indentation))))
  4559. (should
  4560. (= 3
  4561. (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4562. (let ((org-odd-levels-only nil)
  4563. (org-adapt-indentation t))
  4564. (org-demote))
  4565. (forward-line)
  4566. (org-get-indentation))))
  4567. (should-not
  4568. (= 3
  4569. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4570. (let ((org-odd-levels-only nil)
  4571. (org-adapt-indentation nil))
  4572. (org-demote))
  4573. (forward-line)
  4574. (org-get-indentation))))
  4575. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4576. ;; section accordingly. Ignore, however, footnote definitions and
  4577. ;; inlinetasks boundaries.
  4578. (should
  4579. (= 3
  4580. (org-test-with-temp-text "* H\n Paragraph"
  4581. (let ((org-odd-levels-only nil)
  4582. (org-adapt-indentation t))
  4583. (org-demote))
  4584. (forward-line)
  4585. (org-get-indentation))))
  4586. (should
  4587. (= 2
  4588. (org-test-with-temp-text "* H\n Paragraph"
  4589. (let ((org-odd-levels-only nil)
  4590. (org-adapt-indentation nil))
  4591. (org-demote))
  4592. (forward-line)
  4593. (org-get-indentation))))
  4594. (should
  4595. (zerop
  4596. (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
  4597. (let ((org-odd-levels-only nil)
  4598. (org-adapt-indentation t))
  4599. (org-demote))
  4600. (goto-char (point-max))
  4601. (org-get-indentation))))
  4602. (should
  4603. (= 3
  4604. (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
  4605. (let ((org-odd-levels-only nil)
  4606. (org-adapt-indentation t))
  4607. (org-demote))
  4608. (goto-char (point-max))
  4609. (org-get-indentation))))
  4610. (when (featurep 'org-inlinetask)
  4611. (should
  4612. (zerop
  4613. (let ((org-inlinetask-min-level 5)
  4614. (org-adapt-indentation t))
  4615. (org-test-with-temp-text "* H\n***** I\n***** END"
  4616. (org-demote)
  4617. (forward-line)
  4618. (org-get-indentation))))))
  4619. (when (featurep 'org-inlinetask)
  4620. (should
  4621. (= 3
  4622. (let ((org-inlinetask-min-level 5)
  4623. (org-adapt-indentation t))
  4624. (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
  4625. (org-demote)
  4626. (forward-line 2)
  4627. (org-get-indentation))))))
  4628. ;; When `org-adapt-indentation' is non-nil, log drawers are
  4629. ;; adjusted.
  4630. (should
  4631. (equal
  4632. "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4633. (org-test-with-temp-text "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4634. (let ((org-odd-levels-only nil)
  4635. (org-adapt-indentation t))
  4636. (org-demote))
  4637. (buffer-string))))
  4638. (should
  4639. (equal
  4640. "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4641. (org-test-with-temp-text "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4642. (let ((org-odd-levels-only nil)
  4643. (org-adapt-indentation 'headline-data))
  4644. (org-demote))
  4645. (buffer-string))))
  4646. (should
  4647. (equal
  4648. "** H\n :LOGBOOK:\n - a\n :END:"
  4649. (org-test-with-temp-text "* H\n:LOGBOOK:\n- a\n:END:"
  4650. (let ((org-odd-levels-only nil)
  4651. (org-adapt-indentation t))
  4652. (org-demote))
  4653. (buffer-string))))
  4654. ;; Ignore contents of source blocks or example blocks when
  4655. ;; indentation should be preserved (through
  4656. ;; `org-src-preserve-indentation' or "-i" flag).
  4657. (should-not
  4658. (zerop
  4659. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4660. (let ((org-adapt-indentation t)
  4661. (org-src-preserve-indentation nil))
  4662. (org-demote))
  4663. (forward-line 2)
  4664. (org-get-indentation))))
  4665. (should
  4666. (zerop
  4667. (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
  4668. (let ((org-adapt-indentation t)
  4669. (org-src-preserve-indentation t))
  4670. (org-demote))
  4671. (forward-line 2)
  4672. (org-get-indentation))))
  4673. (should
  4674. (zerop
  4675. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4676. (let ((org-adapt-indentation t)
  4677. (org-src-preserve-indentation t))
  4678. (org-demote))
  4679. (forward-line 2)
  4680. (org-get-indentation))))
  4681. (should
  4682. (zerop
  4683. (org-test-with-temp-text
  4684. "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
  4685. (let ((org-adapt-indentation t)
  4686. (org-src-preserve-indentation nil))
  4687. (org-demote))
  4688. (forward-line 2)
  4689. (org-get-indentation)))))
  4690. (ert-deftest test-org/promote ()
  4691. "Test `org-promote' specifications."
  4692. ;; Return an error if headline is to be promoted to level 0, unless
  4693. ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
  4694. ;; headline becomes a comment.
  4695. (should-error
  4696. (org-test-with-temp-text "* H"
  4697. (let ((org-allow-promoting-top-level-subtree nil)) (org-promote))))
  4698. (should
  4699. (equal "# H"
  4700. (org-test-with-temp-text "* H"
  4701. (let ((org-allow-promoting-top-level-subtree t)) (org-promote))
  4702. (buffer-string))))
  4703. ;; Remove correct number of stars according to
  4704. ;; `org-odd-levels-only'.
  4705. (should
  4706. (= 2
  4707. (org-test-with-temp-text "*** H"
  4708. (let ((org-odd-levels-only nil)) (org-promote))
  4709. (org-current-level))))
  4710. (should
  4711. (= 1
  4712. (org-test-with-temp-text "*** H"
  4713. (let ((org-odd-levels-only t)) (org-promote))
  4714. (org-current-level))))
  4715. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4716. (should
  4717. (org-test-with-temp-text "** H :tag:"
  4718. (let ((org-tags-column 10)
  4719. (org-auto-align-tags t)
  4720. (org-odd-levels-only nil))
  4721. (org-promote))
  4722. (org-move-to-column 10)
  4723. (looking-at-p ":tag:$")))
  4724. (should-not
  4725. (org-test-with-temp-text "** H :tag:"
  4726. (let ((org-tags-column 10)
  4727. (org-auto-align-tags nil)
  4728. (org-odd-levels-only nil))
  4729. (org-promote))
  4730. (org-move-to-column 10)
  4731. (looking-at-p ":tag:$")))
  4732. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4733. ;; info and property drawers.
  4734. (should
  4735. (= 2
  4736. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4737. (let ((org-odd-levels-only nil)
  4738. (org-adapt-indentation t))
  4739. (org-promote))
  4740. (forward-line)
  4741. (org-get-indentation))))
  4742. (should
  4743. (= 2
  4744. (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4745. (let ((org-odd-levels-only nil)
  4746. (org-adapt-indentation t))
  4747. (org-promote))
  4748. (forward-line)
  4749. (org-get-indentation))))
  4750. (should-not
  4751. (= 2
  4752. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4753. (let ((org-odd-levels-only nil)
  4754. (org-adapt-indentation nil))
  4755. (org-promote))
  4756. (forward-line)
  4757. (org-get-indentation))))
  4758. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4759. ;; section accordingly. Ignore, however, footnote definitions and
  4760. ;; inlinetasks boundaries.
  4761. (should
  4762. (= 2
  4763. (org-test-with-temp-text "** H\n Paragraph"
  4764. (let ((org-odd-levels-only nil)
  4765. (org-adapt-indentation t))
  4766. (org-promote))
  4767. (forward-line)
  4768. (org-get-indentation))))
  4769. (should-not
  4770. (= 2
  4771. (org-test-with-temp-text "** H\n Paragraph"
  4772. (let ((org-odd-levels-only nil)
  4773. (org-adapt-indentation nil))
  4774. (org-promote))
  4775. (forward-line)
  4776. (org-get-indentation))))
  4777. (should
  4778. (= 2
  4779. (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
  4780. (let ((org-odd-levels-only nil)
  4781. (org-adapt-indentation t))
  4782. (org-promote))
  4783. (forward-line)
  4784. (org-get-indentation))))
  4785. (when (featurep 'org-inlinetask)
  4786. (should
  4787. (zerop
  4788. (let ((org-inlinetask-min-level 5)
  4789. (org-adapt-indentation t))
  4790. (org-test-with-temp-text "** H\n***** I\n***** END"
  4791. (org-promote)
  4792. (forward-line)
  4793. (org-get-indentation))))))
  4794. (when (featurep 'org-inlinetask)
  4795. (should
  4796. (= 2
  4797. (let ((org-inlinetask-min-level 5)
  4798. (org-adapt-indentation t))
  4799. (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
  4800. (org-promote)
  4801. (forward-line 2)
  4802. (org-get-indentation))))))
  4803. ;; Give up shifting if it would break document's structure
  4804. ;; otherwise.
  4805. (should
  4806. (= 3
  4807. (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
  4808. (let ((org-odd-levels-only nil)
  4809. (org-adapt-indentation t))
  4810. (org-promote))
  4811. (forward-line)
  4812. (org-get-indentation))))
  4813. (should
  4814. (= 3
  4815. (org-test-with-temp-text "** H\n Paragraph\n * list."
  4816. (let ((org-odd-levels-only nil)
  4817. (org-adapt-indentation t))
  4818. (org-promote))
  4819. (forward-line)
  4820. (org-get-indentation))))
  4821. ;; When `org-adapt-indentation' is non-nil, log drawers are
  4822. ;; adjusted.
  4823. (should
  4824. (equal
  4825. "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4826. (org-test-with-temp-text "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4827. (let ((org-odd-levels-only nil)
  4828. (org-adapt-indentation t))
  4829. (org-promote))
  4830. (buffer-string))))
  4831. (should
  4832. (equal
  4833. "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4834. (org-test-with-temp-text "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4835. (let ((org-odd-levels-only nil)
  4836. (org-adapt-indentation 'headline-data))
  4837. (org-promote))
  4838. (buffer-string))))
  4839. (should
  4840. (equal
  4841. "* H\n:LOGBOOK:\n- a\n:END:"
  4842. (org-test-with-temp-text "** H\n:LOGBOOK:\n- a\n:END:"
  4843. (let ((org-odd-levels-only nil)
  4844. (org-adapt-indentation t))
  4845. (org-promote))
  4846. (buffer-string))))
  4847. (should
  4848. (equal
  4849. "# H\n:LOGBOOK:\n- a\n:END:"
  4850. (org-test-with-temp-text "* H\n:LOGBOOK:\n- a\n:END:"
  4851. (let ((org-odd-levels-only nil)
  4852. (org-allow-promoting-top-level-subtree t)
  4853. (org-adapt-indentation t))
  4854. (org-promote))
  4855. (buffer-string))))
  4856. ;; Ignore contents of source blocks or example blocks when
  4857. ;; indentation should be preserved (through
  4858. ;; `org-src-preserve-indentation' or "-i" flag).
  4859. (should-not
  4860. (zerop
  4861. (org-test-with-temp-text
  4862. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  4863. (let ((org-adapt-indentation t)
  4864. (org-src-preserve-indentation nil)
  4865. (org-odd-levels-only nil))
  4866. (org-promote))
  4867. (forward-line)
  4868. (org-get-indentation))))
  4869. (should
  4870. (zerop
  4871. (org-test-with-temp-text
  4872. "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
  4873. (let ((org-adapt-indentation t)
  4874. (org-src-preserve-indentation t)
  4875. (org-odd-levels-only nil))
  4876. (org-promote))
  4877. (forward-line)
  4878. (org-get-indentation))))
  4879. (should
  4880. (zerop
  4881. (org-test-with-temp-text
  4882. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  4883. (let ((org-adapt-indentation t)
  4884. (org-src-preserve-indentation t)
  4885. (org-odd-levels-only nil))
  4886. (org-promote))
  4887. (forward-line)
  4888. (org-get-indentation))))
  4889. (should
  4890. (zerop
  4891. (org-test-with-temp-text
  4892. "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
  4893. (let ((org-adapt-indentation t)
  4894. (org-src-preserve-indentation nil)
  4895. (org-odd-levels-only nil))
  4896. (org-promote))
  4897. (forward-line)
  4898. (org-get-indentation)))))
  4899. (ert-deftest test-org/org-get-valid-level ()
  4900. "Test function `org-get-valid-level' specifications."
  4901. (let ((org-odd-levels-only nil))
  4902. (should (equal 1 (org-get-valid-level 0 0)))
  4903. (should (equal 1 (org-get-valid-level 0 1)))
  4904. (should (equal 2 (org-get-valid-level 0 2)))
  4905. (should (equal 3 (org-get-valid-level 0 3)))
  4906. (should (equal 1 (org-get-valid-level 1 0)))
  4907. (should (equal 2 (org-get-valid-level 1 1)))
  4908. (should (equal 23 (org-get-valid-level 1 22)))
  4909. (should (equal 1 (org-get-valid-level 1 -1)))
  4910. (should (equal 1 (org-get-valid-level 2 -1))))
  4911. (let ((org-odd-levels-only t))
  4912. (should (equal 1 (org-get-valid-level 0 0)))
  4913. (should (equal 1 (org-get-valid-level 0 1)))
  4914. (should (equal 3 (org-get-valid-level 0 2)))
  4915. (should (equal 5 (org-get-valid-level 0 3)))
  4916. (should (equal 1 (org-get-valid-level 1 0)))
  4917. (should (equal 3 (org-get-valid-level 1 1)))
  4918. (should (equal 3 (org-get-valid-level 2 1)))
  4919. (should (equal 5 (org-get-valid-level 3 1)))
  4920. (should (equal 5 (org-get-valid-level 4 1)))
  4921. (should (equal 43 (org-get-valid-level 1 21)))
  4922. (should (equal 1 (org-get-valid-level 1 -1)))
  4923. (should (equal 1 (org-get-valid-level 2 -1)))
  4924. (should (equal 1 (org-get-valid-level 3 -1)))
  4925. (should (equal 3 (org-get-valid-level 4 -1)))
  4926. (should (equal 3 (org-get-valid-level 5 -1)))))
  4927. ;;; Planning
  4928. (ert-deftest test-org/at-planning-p ()
  4929. "Test `org-at-planning-p' specifications."
  4930. ;; Regular test.
  4931. (should
  4932. (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
  4933. (org-at-planning-p)))
  4934. (should-not
  4935. (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
  4936. (org-at-planning-p)))
  4937. ;; Correctly find planning attached to inlinetasks.
  4938. (when (featurep 'org-inlinetask)
  4939. (should
  4940. (org-test-with-temp-text
  4941. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
  4942. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4943. (should-not
  4944. (org-test-with-temp-text
  4945. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  4946. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4947. (should-not
  4948. (org-test-with-temp-text
  4949. "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  4950. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4951. (should-not
  4952. (org-test-with-temp-text
  4953. "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
  4954. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
  4955. (ert-deftest test-org/add-planning-info ()
  4956. "Test `org-add-planning-info'."
  4957. ;; Create deadline when `org-adapt-indentation' is non-nil.
  4958. (should
  4959. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4960. (org-test-with-temp-text "* H\nParagraph<point>"
  4961. (let ((org-adapt-indentation t))
  4962. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4963. (replace-regexp-in-string
  4964. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4965. nil nil 1))))
  4966. ;; Create deadline when `org-adapt-indentation' is nil.
  4967. (should
  4968. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  4969. (org-test-with-temp-text "* H\nParagraph<point>"
  4970. (let ((org-adapt-indentation nil))
  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. ;; Update deadline when `org-adapt-indentation' is non-nil.
  4976. (should
  4977. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4978. (org-test-with-temp-text "\
  4979. * H
  4980. DEADLINE: <2015-06-24 Wed>
  4981. Paragraph<point>"
  4982. (let ((org-adapt-indentation t))
  4983. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4984. (replace-regexp-in-string
  4985. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4986. nil nil 1))))
  4987. ;; Update deadline when `org-adapt-indentation' is nil.
  4988. (should
  4989. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  4990. (org-test-with-temp-text "\
  4991. * H
  4992. DEADLINE: <2015-06-24 Wed>
  4993. Paragraph<point>"
  4994. (let ((org-adapt-indentation nil))
  4995. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4996. (replace-regexp-in-string
  4997. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4998. nil nil 1))))
  4999. ;; Schedule when `org-adapt-indentation' is non-nil.
  5000. (should
  5001. (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
  5002. (org-test-with-temp-text "* H\nParagraph<point>"
  5003. (let ((org-adapt-indentation t))
  5004. (org-add-planning-info 'scheduled "<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 nil.
  5009. (should
  5010. (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
  5011. (org-test-with-temp-text "* H\nParagraph<point>"
  5012. (let ((org-adapt-indentation nil))
  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. ;; Add deadline when scheduled.
  5018. (should
  5019. (equal "\
  5020. * H
  5021. DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
  5022. Paragraph"
  5023. (org-test-with-temp-text "\
  5024. * H
  5025. SCHEDULED: <2015-06-24 Wed>
  5026. Paragraph<point>"
  5027. (let ((org-adapt-indentation t))
  5028. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5029. (replace-regexp-in-string
  5030. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5031. nil nil 1))))
  5032. ;; Remove middle entry.
  5033. (should
  5034. (equal "\
  5035. * H
  5036. CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
  5037. Paragraph"
  5038. (org-test-with-temp-text "\
  5039. * H
  5040. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  5041. Paragraph<point>"
  5042. (let ((org-adapt-indentation t))
  5043. (org-add-planning-info nil nil 'deadline))
  5044. (replace-regexp-in-string
  5045. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  5046. nil nil 1))))
  5047. ;; Remove last entry and then middle entry (order should not
  5048. ;; matter).
  5049. (should
  5050. (equal "\
  5051. * H
  5052. CLOSED: [2015-06-24]
  5053. Paragraph"
  5054. (org-test-with-temp-text "\
  5055. * H
  5056. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  5057. Paragraph<point>"
  5058. (let ((org-adapt-indentation t))
  5059. (org-add-planning-info nil nil 'scheduled 'deadline))
  5060. (replace-regexp-in-string
  5061. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  5062. nil nil 1))))
  5063. ;; Remove closed when `org-adapt-indentation' is non-nil.
  5064. (should
  5065. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5066. (org-test-with-temp-text "\
  5067. * H
  5068. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  5069. Paragraph<point>"
  5070. (let ((org-adapt-indentation t))
  5071. (org-add-planning-info nil nil 'closed))
  5072. (replace-regexp-in-string
  5073. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5074. nil nil 1))))
  5075. (should
  5076. (equal "* H\n Paragraph"
  5077. (org-test-with-temp-text "\
  5078. * H
  5079. CLOSED: [2015-06-25 Thu]
  5080. Paragraph<point>"
  5081. (let ((org-adapt-indentation t))
  5082. (org-add-planning-info nil nil 'closed))
  5083. (replace-regexp-in-string
  5084. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5085. nil nil 1))))
  5086. ;; Remove closed when `org-adapt-indentation' is nil.
  5087. (should
  5088. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  5089. (org-test-with-temp-text "\
  5090. * H
  5091. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  5092. Paragraph<point>"
  5093. (let ((org-adapt-indentation nil))
  5094. (org-add-planning-info nil nil 'closed))
  5095. (replace-regexp-in-string
  5096. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5097. nil nil 1))))
  5098. (should
  5099. (equal "* H\nParagraph"
  5100. (org-test-with-temp-text "\
  5101. * H
  5102. CLOSED: [2015-06-25 Thu]
  5103. Paragraph<point>"
  5104. (let ((org-adapt-indentation nil))
  5105. (org-add-planning-info nil nil 'closed))
  5106. (replace-regexp-in-string
  5107. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5108. nil nil 1))))
  5109. ;; Remove closed entry and delete empty line.
  5110. (should
  5111. (equal "\
  5112. * H
  5113. Paragraph"
  5114. (org-test-with-temp-text "\
  5115. * H
  5116. CLOSED: [2015-06-24 Wed]
  5117. Paragraph<point>"
  5118. (let ((org-adapt-indentation t))
  5119. (org-add-planning-info nil nil 'closed))
  5120. (replace-regexp-in-string
  5121. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5122. nil nil 1))))
  5123. ;; Remove one entry and update another.
  5124. (should
  5125. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5126. (org-test-with-temp-text "\
  5127. * H
  5128. SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
  5129. Paragraph<point>"
  5130. (let ((org-adapt-indentation t))
  5131. (org-add-planning-info 'deadline "<2015-06-25 Thu>" 'scheduled))
  5132. (replace-regexp-in-string
  5133. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5134. nil nil 1)))))
  5135. (ert-deftest test-org/deadline ()
  5136. "Test `org-deadline' specifications."
  5137. ;; Insert a new value or replace existing one.
  5138. (should
  5139. (equal "* H\nDEADLINE: <2012-03-29>"
  5140. (org-test-with-temp-text "* H"
  5141. (let ((org-adapt-indentation nil)
  5142. (org-last-inserted-timestamp nil))
  5143. (org-deadline nil "<2012-03-29 Tue>"))
  5144. (replace-regexp-in-string
  5145. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5146. nil nil 1))))
  5147. (should
  5148. (equal "* H\nDEADLINE: <2014-03-04>"
  5149. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5150. (let ((org-adapt-indentation nil)
  5151. (org-last-inserted-timestamp nil))
  5152. (org-deadline nil "<2014-03-04 Thu>"))
  5153. (replace-regexp-in-string
  5154. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5155. nil nil 1))))
  5156. ;; Accept delta time, e.g., "+2d".
  5157. (should
  5158. (equal "* H\nDEADLINE: <2015-03-04>"
  5159. (org-test-at-time "2014-03-04"
  5160. (org-test-with-temp-text "* H"
  5161. (let ((org-adapt-indentation nil)
  5162. (org-last-inserted-timestamp nil))
  5163. (org-deadline nil "+1y"))
  5164. (replace-regexp-in-string
  5165. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5166. ;; Preserve repeater.
  5167. (should
  5168. (equal "* H\nDEADLINE: <2012-03-29 +2y>"
  5169. (org-test-with-temp-text "* H"
  5170. (let ((org-adapt-indentation nil)
  5171. (org-last-inserted-timestamp nil))
  5172. (org-deadline nil "<2012-03-29 Tue +2y>"))
  5173. (replace-regexp-in-string
  5174. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5175. ;; Remove CLOSED keyword, if any.
  5176. (should
  5177. (equal "* H\nDEADLINE: <2012-03-29>"
  5178. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  5179. (let ((org-adapt-indentation nil)
  5180. (org-last-inserted-timestamp nil))
  5181. (org-deadline nil "<2012-03-29 Tue>"))
  5182. (replace-regexp-in-string
  5183. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5184. ;; With C-u argument, remove DEADLINE keyword.
  5185. (should
  5186. (equal "* H\n"
  5187. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5188. (let ((org-adapt-indentation nil)
  5189. (org-last-inserted-timestamp nil))
  5190. (org-deadline '(4)))
  5191. (buffer-string))))
  5192. (should
  5193. (equal "* H"
  5194. (org-test-with-temp-text "* H"
  5195. (let ((org-adapt-indentation nil)
  5196. (org-last-inserted-timestamp nil))
  5197. (org-deadline '(4)))
  5198. (buffer-string))))
  5199. ;; With C-u C-u argument, prompt for a delay cookie.
  5200. (should
  5201. (equal "* H\nDEADLINE: <2012-03-29 -705d>"
  5202. (cl-letf (((symbol-function 'org-read-date)
  5203. (lambda (&rest args)
  5204. (apply #'encode-time
  5205. (org-parse-time-string "2014-03-04")))))
  5206. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5207. (let ((org-adapt-indentation nil)
  5208. (org-last-inserted-timestamp nil))
  5209. (org-deadline '(16)))
  5210. (buffer-string)))))
  5211. (should-error
  5212. (cl-letf (((symbol-function 'org-read-date)
  5213. (lambda (&rest args)
  5214. (apply #'encode-time
  5215. (org-parse-time-string "2014-03-04")))))
  5216. (org-test-with-temp-text "* H"
  5217. (let ((org-adapt-indentation nil)
  5218. (org-last-inserted-timestamp nil))
  5219. (org-deadline '(16)))
  5220. (buffer-string))))
  5221. ;; When a region is active and
  5222. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5223. ;; same value in all headlines in region.
  5224. (should
  5225. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5226. (org-test-with-temp-text "* H1\n* H2"
  5227. (let ((org-adapt-indentation nil)
  5228. (org-last-inserted-timestamp nil)
  5229. (org-loop-over-headlines-in-active-region t))
  5230. (transient-mark-mode 1)
  5231. (push-mark (point) t t)
  5232. (goto-char (point-max))
  5233. (org-deadline nil "2012-03-29"))
  5234. (replace-regexp-in-string
  5235. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5236. (should-not
  5237. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5238. (org-test-with-temp-text "* H1\n* H2"
  5239. (let ((org-adapt-indentation nil)
  5240. (org-last-inserted-timestamp nil)
  5241. (org-loop-over-headlines-in-active-region nil))
  5242. (transient-mark-mode 1)
  5243. (push-mark (point) t t)
  5244. (goto-char (point-max))
  5245. (org-deadline nil "2012-03-29"))
  5246. (replace-regexp-in-string
  5247. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5248. (ert-deftest test-org/schedule ()
  5249. "Test `org-schedule' specifications."
  5250. ;; Insert a new value or replace existing one.
  5251. (should
  5252. (equal "* H\nSCHEDULED: <2012-03-29>"
  5253. (org-test-with-temp-text "* H"
  5254. (let ((org-adapt-indentation nil)
  5255. (org-last-inserted-timestamp nil))
  5256. (org-schedule nil "<2012-03-29 Tue>"))
  5257. (replace-regexp-in-string
  5258. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5259. nil nil 1))))
  5260. (should
  5261. (equal "* H\nSCHEDULED: <2014-03-04>"
  5262. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5263. (let ((org-adapt-indentation nil)
  5264. (org-last-inserted-timestamp nil))
  5265. (org-schedule nil "<2014-03-04 Thu>"))
  5266. (replace-regexp-in-string
  5267. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5268. nil nil 1))))
  5269. ;; Accept delta time, e.g., "+2d".
  5270. (should
  5271. (equal "* H\nSCHEDULED: <2015-03-04>"
  5272. (org-test-at-time "2014-03-04"
  5273. (org-test-with-temp-text "* H"
  5274. (let ((org-adapt-indentation nil)
  5275. (org-last-inserted-timestamp nil))
  5276. (org-schedule nil "+1y"))
  5277. (replace-regexp-in-string
  5278. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5279. ;; Preserve repeater.
  5280. (should
  5281. (equal "* H\nSCHEDULED: <2012-03-29 +2y>"
  5282. (org-test-with-temp-text "* H"
  5283. (let ((org-adapt-indentation nil)
  5284. (org-last-inserted-timestamp nil))
  5285. (org-schedule nil "<2012-03-29 Tue +2y>"))
  5286. (replace-regexp-in-string
  5287. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5288. ;; Remove CLOSED keyword, if any.
  5289. (should
  5290. (equal "* H\nSCHEDULED: <2012-03-29>"
  5291. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  5292. (let ((org-adapt-indentation nil)
  5293. (org-last-inserted-timestamp nil))
  5294. (org-schedule nil "<2012-03-29 Tue>"))
  5295. (replace-regexp-in-string
  5296. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5297. ;; With C-u argument, remove SCHEDULED keyword.
  5298. (should
  5299. (equal "* H\n"
  5300. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5301. (let ((org-adapt-indentation nil)
  5302. (org-last-inserted-timestamp nil))
  5303. (org-schedule '(4)))
  5304. (buffer-string))))
  5305. (should
  5306. (equal "* H"
  5307. (org-test-with-temp-text "* H"
  5308. (let ((org-adapt-indentation nil)
  5309. (org-last-inserted-timestamp nil))
  5310. (org-schedule '(4)))
  5311. (buffer-string))))
  5312. ;; With C-u C-u argument, prompt for a delay cookie.
  5313. (should
  5314. (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
  5315. (cl-letf (((symbol-function 'org-read-date)
  5316. (lambda (&rest args)
  5317. (apply #'encode-time
  5318. (org-parse-time-string "2014-03-04")))))
  5319. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5320. (let ((org-adapt-indentation nil)
  5321. (org-last-inserted-timestamp nil))
  5322. (org-schedule '(16)))
  5323. (buffer-string)))))
  5324. (should-error
  5325. (cl-letf (((symbol-function 'org-read-date)
  5326. (lambda (&rest args)
  5327. (apply #'encode-time
  5328. (org-parse-time-string "2014-03-04")))))
  5329. (org-test-with-temp-text "* H"
  5330. (let ((org-adapt-indentation nil)
  5331. (org-last-inserted-timestamp nil))
  5332. (org-schedule '(16)))
  5333. (buffer-string))))
  5334. ;; When a region is active and
  5335. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5336. ;; same value in all headlines in region.
  5337. (should
  5338. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5339. (org-test-with-temp-text "* H1\n* H2"
  5340. (let ((org-adapt-indentation nil)
  5341. (org-last-inserted-timestamp nil)
  5342. (org-loop-over-headlines-in-active-region t))
  5343. (transient-mark-mode 1)
  5344. (push-mark (point) t t)
  5345. (goto-char (point-max))
  5346. (org-schedule nil "2012-03-29"))
  5347. (replace-regexp-in-string
  5348. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5349. (should-not
  5350. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5351. (org-test-with-temp-text "* H1\n* H2"
  5352. (let ((org-adapt-indentation nil)
  5353. (org-last-inserted-timestamp nil)
  5354. (org-loop-over-headlines-in-active-region nil))
  5355. (transient-mark-mode 1)
  5356. (push-mark (point) t t)
  5357. (goto-char (point-max))
  5358. (org-schedule nil "2012-03-29"))
  5359. (replace-regexp-in-string
  5360. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5361. (should
  5362. ;; check if a repeater survives re-scheduling.
  5363. (string-match-p
  5364. "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
  5365. (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
  5366. (let ((org-adapt-indentation nil)
  5367. (org-last-inserted-timestamp nil))
  5368. (org-schedule nil "2017-02-01"))
  5369. (buffer-string)))))
  5370. ;;; Property API
  5371. (ert-deftest test-org/buffer-property-keys ()
  5372. "Test `org-buffer-property-keys' specifications."
  5373. ;; Retrieve properties across siblings.
  5374. (should
  5375. (equal '("A" "B")
  5376. (org-test-with-temp-text "
  5377. * H1
  5378. :PROPERTIES:
  5379. :A: 1
  5380. :END:
  5381. * H2
  5382. :PROPERTIES:
  5383. :B: 1
  5384. :END:"
  5385. (org-buffer-property-keys))))
  5386. ;; Retrieve properties across children.
  5387. (should
  5388. (equal '("A" "B")
  5389. (org-test-with-temp-text "
  5390. * H1
  5391. :PROPERTIES:
  5392. :A: 1
  5393. :END:
  5394. ** H2
  5395. :PROPERTIES:
  5396. :B: 1
  5397. :END:"
  5398. (org-buffer-property-keys))))
  5399. ;; Retrieve muliple properties in the same drawer.
  5400. (should
  5401. (equal '("A" "B")
  5402. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5403. (org-buffer-property-keys))))
  5404. ;; Ignore extension symbol in property name.
  5405. (should
  5406. (equal '("A")
  5407. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5408. (org-buffer-property-keys))))
  5409. ;; Add bare property if xxx_ALL property is there
  5410. (should
  5411. (equal '("A" "B" "B_ALL")
  5412. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B_ALL: foo bar\n:END:"
  5413. (org-buffer-property-keys))))
  5414. ;; Add bare property if xxx_ALL property is there - check dupes
  5415. (should
  5416. (equal '("A" "B" "B_ALL")
  5417. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:B_ALL: foo bar\n:END:"
  5418. (org-buffer-property-keys))))
  5419. ;; Retrieve properties from #+PROPERTY keyword lines
  5420. (should
  5421. (equal '("A" "C")
  5422. (org-test-with-temp-text "#+PROPERTY: C foo\n* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5423. (org-buffer-property-keys))))
  5424. ;; Retrieve properties from #+PROPERTY keyword lines - make sure an _ALL property also
  5425. ;; adds the bare property
  5426. (should
  5427. (equal '("A" "C" "C_ALL")
  5428. (org-test-with-temp-text "#+PROPERTY: C_ALL foo bar\n* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5429. (org-buffer-property-keys))))
  5430. ;; With non-nil COLUMNS, extract property names from columns.
  5431. (should
  5432. (equal '("A" "B")
  5433. (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
  5434. (org-buffer-property-keys nil nil t))))
  5435. (should
  5436. (equal '("A" "B" "COLUMNS")
  5437. (org-test-with-temp-text
  5438. "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
  5439. (org-buffer-property-keys nil nil t))))
  5440. ;; In COLUMNS, ignore title and summary-type.
  5441. (should
  5442. (equal '("A")
  5443. (org-test-with-temp-text "#+COLUMNS: %A(Foo)"
  5444. (org-buffer-property-keys nil nil t))))
  5445. (should
  5446. (equal '("A")
  5447. (org-test-with-temp-text "#+COLUMNS: %A{Foo}"
  5448. (org-buffer-property-keys nil nil t))))
  5449. (should
  5450. (equal '("A")
  5451. (org-test-with-temp-text "#+COLUMNS: %A(Foo){Bar}"
  5452. (org-buffer-property-keys nil nil t)))))
  5453. (ert-deftest test-org/property-values ()
  5454. "Test `org-property-values' specifications."
  5455. ;; Regular test.
  5456. (should
  5457. (equal '("2" "1")
  5458. (org-test-with-temp-text
  5459. "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
  5460. (org-property-values "A"))))
  5461. ;; Ignore empty values.
  5462. (should-not
  5463. (org-test-with-temp-text
  5464. "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
  5465. (org-property-values "A")))
  5466. ;; Take into consideration extended values.
  5467. (should
  5468. (equal '("1 2")
  5469. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5470. (org-property-values "A")))))
  5471. (ert-deftest test-org/set-property ()
  5472. "Test `org-set-property' specifications."
  5473. (should
  5474. (equal
  5475. ":PROPERTIES:\n:TEST: t\n:END:\n"
  5476. (org-test-with-temp-text ""
  5477. (let ((org-property-format "%s %s"))
  5478. (org-set-property "TEST" "t"))
  5479. (buffer-string))))
  5480. (should
  5481. (equal
  5482. "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5483. (org-test-with-temp-text "* H"
  5484. (let ((org-adapt-indentation nil)
  5485. (org-property-format "%s %s"))
  5486. (org-set-property "TEST" "t"))
  5487. (buffer-string)))))
  5488. (ert-deftest test-org/delete-property ()
  5489. "Test `org-delete-property' specifications."
  5490. (should
  5491. (equal
  5492. ""
  5493. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5494. (org-delete-property "TEST")
  5495. (buffer-string))))
  5496. (should
  5497. (equal
  5498. ":PROPERTIES:\n:TEST1: t\n:END:\n"
  5499. (org-test-with-temp-text ":PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5500. (org-delete-property "TEST2")
  5501. (buffer-string))))
  5502. (should
  5503. (equal
  5504. "* H\n"
  5505. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5506. (org-delete-property "TEST")
  5507. (buffer-string))))
  5508. (should
  5509. (equal
  5510. "* H\n:PROPERTIES:\n:TEST1: t\n:END:\n"
  5511. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5512. (org-delete-property "TEST2")
  5513. (buffer-string)))))
  5514. (ert-deftest test-org/delete-property-globally ()
  5515. "Test `org-delete-property-global' specifications."
  5516. (should
  5517. (equal
  5518. ""
  5519. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5520. (org-delete-property-globally "TEST")
  5521. (buffer-string))))
  5522. (should
  5523. (equal
  5524. "* H\n"
  5525. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n* H\n:PROPERTIES:\n:TEST: nil\n:END:"
  5526. (org-delete-property-globally "TEST")
  5527. (buffer-string)))))
  5528. (ert-deftest test-org/find-property ()
  5529. "Test `org-find-property' specifications."
  5530. ;; Regular test.
  5531. (should
  5532. (= 1
  5533. (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
  5534. (org-find-property "prop"))))
  5535. ;; Find properties in top-level property drawer.
  5536. (should
  5537. (= 1
  5538. (org-test-with-temp-text ":PROPERTIES:\n:PROP: value\n:END:"
  5539. (org-find-property "prop"))))
  5540. ;; Ignore false positives.
  5541. (should
  5542. (= 27
  5543. (org-test-with-temp-text
  5544. "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
  5545. (org-find-property "A"))))
  5546. ;; Return first entry found in buffer.
  5547. (should
  5548. (= 1
  5549. (org-test-with-temp-text
  5550. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5551. (org-find-property "A"))))
  5552. ;; Only search visible part of the buffer.
  5553. (should
  5554. (= 31
  5555. (org-test-with-temp-text
  5556. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5557. (org-narrow-to-subtree)
  5558. (org-find-property "A"))))
  5559. ;; With optional argument, only find entries with a specific value.
  5560. (should-not
  5561. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5562. (org-find-property "A" "2")))
  5563. (should
  5564. (= 31
  5565. (org-test-with-temp-text
  5566. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
  5567. (org-find-property "A" "2"))))
  5568. ;; Use "nil" for explicit nil values.
  5569. (should
  5570. (= 31
  5571. (org-test-with-temp-text
  5572. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
  5573. (org-find-property "A" "nil")))))
  5574. (ert-deftest test-org/entry-delete ()
  5575. "Test `org-entry-delete' specifications."
  5576. ;; Regular test.
  5577. (should
  5578. (string-match
  5579. " *:PROPERTIES:\n *:B: +2\n *:END:"
  5580. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5581. (org-entry-delete (point) "A")
  5582. (buffer-string))))
  5583. ;; Also remove accumulated properties.
  5584. (should-not
  5585. (string-match
  5586. ":A"
  5587. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
  5588. (org-entry-delete (point) "A")
  5589. (buffer-string))))
  5590. ;; When last property is removed, remove the property drawer.
  5591. (should-not
  5592. (string-match
  5593. ":PROPERTIES:"
  5594. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
  5595. (org-entry-delete (point) "A")
  5596. (buffer-string))))
  5597. ;; Return a non-nil value when some property was removed.
  5598. (should
  5599. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5600. (org-entry-delete (point) "A")))
  5601. (should-not
  5602. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5603. (org-entry-delete (point) "C")))
  5604. ;; Special properties cannot be located in a drawer. Allow to
  5605. ;; remove them anyway, in case of user error.
  5606. (should
  5607. (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
  5608. (org-entry-delete (point) "SCHEDULED"))))
  5609. (ert-deftest test-org/entry-get ()
  5610. "Test `org-entry-get' specifications."
  5611. ;; Regular test.
  5612. (should
  5613. (equal "1"
  5614. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:"
  5615. (org-entry-get (point) "A"))))
  5616. (should
  5617. (equal "1"
  5618. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5619. (org-entry-get (point) "A"))))
  5620. ;; Ignore case.
  5621. (should
  5622. (equal "1"
  5623. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5624. (org-entry-get (point) "a"))))
  5625. ;; Handle extended values, both before and after base value.
  5626. (should
  5627. (equal "1 2 3"
  5628. (org-test-with-temp-text
  5629. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5630. (org-entry-get (point) "A"))))
  5631. ;; Empty values are returned as the empty string.
  5632. (should
  5633. (equal ""
  5634. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
  5635. (org-entry-get (point) "A"))))
  5636. ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
  5637. ;; otherwise, return nil.
  5638. (should-not
  5639. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5640. (org-entry-get (point) "A")))
  5641. (should
  5642. (equal "nil"
  5643. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5644. (org-entry-get (point) "A" nil t))))
  5645. ;; Return nil when no property is found, independently on the
  5646. ;; LITERAL-NIL argument.
  5647. (should-not
  5648. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5649. (org-entry-get (point) "B")))
  5650. (should-not
  5651. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5652. (org-entry-get (point) "B" nil t)))
  5653. ;; Handle inheritance, when allowed. Include extended values and
  5654. ;; possibly global values.
  5655. (should
  5656. (equal
  5657. "1"
  5658. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:\n* H"
  5659. (org-entry-get (point-max) "A" t))))
  5660. (should
  5661. (equal
  5662. "1"
  5663. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5664. (org-entry-get (point-max) "A" t))))
  5665. (should
  5666. (equal
  5667. "1"
  5668. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5669. (let ((org-use-property-inheritance t))
  5670. (org-entry-get (point-max) "A" 'selective)))))
  5671. (should-not
  5672. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5673. (let ((org-use-property-inheritance nil))
  5674. (org-entry-get (point-max) "A" 'selective))))
  5675. (should
  5676. (equal
  5677. "1 2"
  5678. (org-test-with-temp-text
  5679. ":PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5680. (org-entry-get (point-max) "A" t))))
  5681. (should
  5682. (equal
  5683. "1 2"
  5684. (org-test-with-temp-text
  5685. "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5686. (org-entry-get (point-max) "A" t))))
  5687. (should
  5688. (equal
  5689. "1 2"
  5690. (org-test-with-temp-text
  5691. ":PROPERTIES:\n:A: 1\n:END:\n* H1\n* H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5692. (org-entry-get (point-max) "A" t))))
  5693. (should
  5694. (equal
  5695. "1 2"
  5696. (org-test-with-temp-text
  5697. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2.1\n* H2.2\n:PROPERTIES:\n:A+: 2\n:END:"
  5698. (org-entry-get (point-max) "A" t))))
  5699. (should
  5700. (equal "1"
  5701. (org-test-with-temp-text
  5702. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
  5703. (org-mode-restart)
  5704. (org-entry-get (point-max) "A" t))))
  5705. (should
  5706. (equal "0 1"
  5707. (org-test-with-temp-text
  5708. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
  5709. (org-mode-restart)
  5710. (org-entry-get (point-max) "A" t))))
  5711. ;; document level property-drawer has precedance over
  5712. ;; global-property by PROPERTY-keyword.
  5713. (should
  5714. (equal "0 2"
  5715. (org-test-with-temp-text
  5716. ":PROPERTIES:\n:A: 0\n:END:\n#+PROPERTY: A 1\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5717. (org-mode-restart)
  5718. (org-entry-get (point-max) "A" t)))))
  5719. (ert-deftest test-org/entry-properties ()
  5720. "Test `org-entry-properties' specifications."
  5721. ;; Get "ITEM" property.
  5722. (should
  5723. (equal "H"
  5724. (org-test-with-temp-text "* TODO H"
  5725. (cdr (assoc "ITEM" (org-entry-properties nil "ITEM"))))))
  5726. (should
  5727. (equal "H"
  5728. (org-test-with-temp-text "* TODO H"
  5729. (cdr (assoc "ITEM" (org-entry-properties))))))
  5730. ;; Get "TODO" property. TODO keywords are case sensitive.
  5731. (should
  5732. (equal "TODO"
  5733. (org-test-with-temp-text "* TODO H"
  5734. (cdr (assoc "TODO" (org-entry-properties nil "TODO"))))))
  5735. (should
  5736. (equal "TODO"
  5737. (org-test-with-temp-text "* TODO H"
  5738. (cdr (assoc "TODO" (org-entry-properties))))))
  5739. (should-not
  5740. (org-test-with-temp-text "* H"
  5741. (assoc "TODO" (org-entry-properties nil "TODO"))))
  5742. (should-not
  5743. (org-test-with-temp-text "* todo H"
  5744. (assoc "TODO" (org-entry-properties nil "TODO"))))
  5745. ;; Get "PRIORITY" property.
  5746. (should
  5747. (equal "A"
  5748. (org-test-with-temp-text "* [#A] H"
  5749. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  5750. (should
  5751. (equal "A"
  5752. (org-test-with-temp-text "* [#A] H"
  5753. (cdr (assoc "PRIORITY" (org-entry-properties))))))
  5754. (should
  5755. (equal (char-to-string org-priority-default)
  5756. (org-test-with-temp-text "* H"
  5757. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  5758. ;; Get "FILE" property.
  5759. (should
  5760. (org-test-with-temp-text-in-file "* H\nParagraph"
  5761. (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil "FILE")))
  5762. (buffer-file-name))))
  5763. (should
  5764. (org-test-with-temp-text-in-file "* H\nParagraph"
  5765. (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
  5766. (buffer-file-name))))
  5767. (should-not
  5768. (org-test-with-temp-text "* H\nParagraph"
  5769. (cdr (assoc "FILE" (org-entry-properties nil "FILE")))))
  5770. ;; Get "TAGS" property.
  5771. (should
  5772. (equal ":tag1:tag2:"
  5773. (org-test-with-temp-text "* H :tag1:tag2:"
  5774. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS"))))))
  5775. (should
  5776. (equal ":tag1:tag2:"
  5777. (org-test-with-temp-text "* H :tag1:tag2:"
  5778. (cdr (assoc "TAGS" (org-entry-properties))))))
  5779. (should-not
  5780. (org-test-with-temp-text "* H"
  5781. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS")))))
  5782. ;; Get "ALLTAGS" property.
  5783. (should
  5784. (equal ":tag1:tag2:"
  5785. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  5786. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS"))))))
  5787. (should
  5788. (equal ":tag1:tag2:"
  5789. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  5790. (cdr (assoc "ALLTAGS" (org-entry-properties))))))
  5791. (should-not
  5792. (org-test-with-temp-text "* H"
  5793. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS")))))
  5794. ;; Get "BLOCKED" property.
  5795. (should
  5796. (equal "t"
  5797. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  5798. (let ((org-enforce-todo-dependencies t)
  5799. (org-blocker-hook
  5800. '(org-block-todo-from-children-or-siblings-or-parent)))
  5801. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  5802. (should
  5803. (equal ""
  5804. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  5805. (let ((org-enforce-todo-dependencies t)
  5806. (org-blocker-hook
  5807. '(org-block-todo-from-children-or-siblings-or-parent)))
  5808. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  5809. ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
  5810. (should
  5811. (equal
  5812. "[2012-03-29 thu.]"
  5813. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  5814. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED"))))))
  5815. (should
  5816. (equal
  5817. "[2012-03-29 thu.]"
  5818. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  5819. (cdr (assoc "CLOSED" (org-entry-properties))))))
  5820. (should-not
  5821. (org-test-with-temp-text "* H"
  5822. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED")))))
  5823. (should
  5824. (equal
  5825. "<2014-03-04 tue.>"
  5826. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5827. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE"))))))
  5828. (should
  5829. (equal
  5830. "<2014-03-04 tue.>"
  5831. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5832. (cdr (assoc "DEADLINE" (org-entry-properties))))))
  5833. (should-not
  5834. (org-test-with-temp-text "* H"
  5835. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE")))))
  5836. (should
  5837. (equal
  5838. "<2014-03-04 tue.>"
  5839. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5840. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED"))))))
  5841. (should
  5842. (equal
  5843. "<2014-03-04 tue.>"
  5844. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5845. (cdr (assoc "SCHEDULED" (org-entry-properties))))))
  5846. (should-not
  5847. (org-test-with-temp-text "* H"
  5848. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED")))))
  5849. ;; Get "CATEGORY"
  5850. (should
  5851. (equal "cat"
  5852. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  5853. (cdr (assoc "CATEGORY" (org-entry-properties))))))
  5854. (should
  5855. (equal "cat"
  5856. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  5857. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5858. (should
  5859. (equal "cat"
  5860. (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
  5861. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5862. (should
  5863. (equal "cat2"
  5864. (org-test-with-temp-text
  5865. (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  5866. "\n"
  5867. "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
  5868. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5869. ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
  5870. (should
  5871. (equal "<2012-03-29 thu.>"
  5872. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
  5873. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  5874. (should
  5875. (equal "[2012-03-29 thu.]"
  5876. (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
  5877. (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
  5878. (should
  5879. (equal "<2012-03-29 thu.>"
  5880. (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
  5881. (cdr (assoc "TIMESTAMP" (org-entry-properties nil "TIMESTAMP"))))))
  5882. (should
  5883. (equal "[2014-03-04 tue.]"
  5884. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
  5885. (cdr (assoc "TIMESTAMP_IA"
  5886. (org-entry-properties nil "TIMESTAMP_IA"))))))
  5887. (should-not
  5888. (equal "<2012-03-29 thu.>"
  5889. (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
  5890. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  5891. ;; Get standard properties.
  5892. (should
  5893. (equal "1"
  5894. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5895. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5896. ;; Handle extended properties.
  5897. (should
  5898. (equal "1 2 3"
  5899. (org-test-with-temp-text
  5900. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5901. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5902. (should
  5903. (equal "1 2 3"
  5904. (org-test-with-temp-text
  5905. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
  5906. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5907. ;; Ignore forbidden (special) properties.
  5908. (should-not
  5909. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
  5910. (cdr (assoc "TODO" (org-entry-properties nil 'standard))))))
  5911. (ert-deftest test-org/entry-put ()
  5912. "Test `org-entry-put' specifications."
  5913. ;; Error when not a string or nil.
  5914. (should-error
  5915. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5916. (org-entry-put 1 "test" 2)))
  5917. ;; Error when property name is invalid.
  5918. (should-error
  5919. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5920. (org-entry-put 1 "no space" "value")))
  5921. (should-error
  5922. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5923. (org-entry-put 1 "" "value")))
  5924. ;; Set "TODO" property.
  5925. (should
  5926. (string-match (regexp-quote " TODO H")
  5927. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  5928. (org-entry-put (point) "TODO" "TODO")
  5929. (buffer-string))))
  5930. (should
  5931. (string-match (regexp-quote "* H")
  5932. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  5933. (org-entry-put (point) "TODO" nil)
  5934. (buffer-string))))
  5935. ;; Set "PRIORITY" property.
  5936. (should
  5937. (equal "* [#A] H"
  5938. (org-test-with-temp-text "* [#B] H"
  5939. (org-entry-put (point) "PRIORITY" "A")
  5940. (buffer-string))))
  5941. (should
  5942. (equal "* H"
  5943. (org-test-with-temp-text "* [#B] H"
  5944. (org-entry-put (point) "PRIORITY" nil)
  5945. (buffer-string))))
  5946. ;; Set "SCHEDULED" property.
  5947. (should
  5948. (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
  5949. (org-test-with-temp-text "* H"
  5950. (org-entry-put (point) "SCHEDULED" "2014-03-04")
  5951. (buffer-string))))
  5952. (should
  5953. (string= "* H\n"
  5954. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5955. (org-entry-put (point) "SCHEDULED" nil)
  5956. (buffer-string))))
  5957. (should
  5958. (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
  5959. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5960. (org-entry-put (point) "SCHEDULED" "earlier")
  5961. (buffer-string))))
  5962. (should
  5963. (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
  5964. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5965. (org-entry-put (point) "SCHEDULED" "later")
  5966. (buffer-string))))
  5967. ;; Set "DEADLINE" property.
  5968. (should
  5969. (string-match "^ *DEADLINE: <2014-03-04 .*?>"
  5970. (org-test-with-temp-text "* H"
  5971. (org-entry-put (point) "DEADLINE" "2014-03-04")
  5972. (buffer-string))))
  5973. (should
  5974. (string= "* H\n"
  5975. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5976. (org-entry-put (point) "DEADLINE" nil)
  5977. (buffer-string))))
  5978. (should
  5979. (string-match "^ *DEADLINE: <2014-03-03 .*?>"
  5980. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5981. (org-entry-put (point) "DEADLINE" "earlier")
  5982. (buffer-string))))
  5983. (should
  5984. (string-match "^ *DEADLINE: <2014-03-05 .*?>"
  5985. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5986. (org-entry-put (point) "DEADLINE" "later")
  5987. (buffer-string))))
  5988. ;; Set "CATEGORY" property
  5989. (should
  5990. (string-match "^ *:CATEGORY: cat"
  5991. (org-test-with-temp-text "* H"
  5992. (org-entry-put (point) "CATEGORY" "cat")
  5993. (buffer-string))))
  5994. ;; Regular properties, with or without pre-existing drawer.
  5995. (should
  5996. (string-match "^ *:A: +2$"
  5997. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5998. (org-entry-put (point) "A" "2")
  5999. (buffer-string))))
  6000. (should
  6001. (string-match "^ *:A: +1$"
  6002. (org-test-with-temp-text "* H"
  6003. (org-entry-put (point) "A" "1")
  6004. (buffer-string))))
  6005. ;; Special case: two consecutive headlines.
  6006. (should
  6007. (string-match "\\* A\n *:PROPERTIES:"
  6008. (org-test-with-temp-text "* A\n** B"
  6009. (org-entry-put (point) "A" "1")
  6010. (buffer-string)))))
  6011. (ert-deftest test-org/refresh-properties ()
  6012. "Test `org-refresh-properties' specifications."
  6013. (should
  6014. (equal "1"
  6015. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6016. (org-refresh-properties "A" 'org-test)
  6017. (get-text-property (point) 'org-test))))
  6018. (should-not
  6019. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6020. (org-refresh-properties "B" 'org-test)
  6021. (get-text-property (point) 'org-test)))
  6022. ;; Handle properties only defined with extension syntax, i.e.,
  6023. ;; "PROPERTY+".
  6024. (should
  6025. (equal "1"
  6026. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
  6027. (org-refresh-properties "A" 'org-test)
  6028. (get-text-property (point) 'org-test))))
  6029. ;; When property is inherited, add text property to the whole
  6030. ;; sub-tree.
  6031. (should
  6032. (equal "1"
  6033. (org-test-with-temp-text
  6034. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
  6035. (let ((org-use-property-inheritance t))
  6036. (org-refresh-properties "A" 'org-test))
  6037. (get-text-property (point) 'org-test))))
  6038. ;; When a document level property-drawer is used, those properties
  6039. ;; should work exactly like headline-properties as if at a
  6040. ;; headline-level 0.
  6041. (should
  6042. (equal "1"
  6043. (org-test-with-temp-text
  6044. ":PROPERTIES:\n:A: 1\n:END:\n"
  6045. (org-mode-restart)
  6046. (let ((org-use-property-inheritance t))
  6047. (org-refresh-properties "A" 'org-test))
  6048. (get-text-property (point) 'org-test))))
  6049. (should-not
  6050. (equal "1"
  6051. (org-test-with-temp-text
  6052. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  6053. (org-mode-restart)
  6054. (let ((org-use-property-inheritance nil))
  6055. (org-refresh-properties "A" 'org-test))
  6056. (get-text-property (point) 'org-test))))
  6057. (should
  6058. (equal "1"
  6059. (org-test-with-temp-text
  6060. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  6061. (org-mode-restart)
  6062. (let ((org-use-property-inheritance t))
  6063. (org-refresh-properties "A" 'org-test))
  6064. (get-text-property (point) 'org-test))))
  6065. (should
  6066. (equal "2"
  6067. (org-test-with-temp-text
  6068. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1\n:PROPERTIES:\n:A: 2\n:END:"
  6069. (org-mode-restart)
  6070. (let ((org-use-property-inheritance t))
  6071. (org-refresh-properties "A" 'org-test))
  6072. (get-text-property (point) 'org-test))))
  6073. ;; When property is inherited, use global value across the whole
  6074. ;; buffer. However local values have precedence, as well as the
  6075. ;; document level property-drawer.
  6076. (should-not
  6077. (equal "1"
  6078. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  6079. (org-mode-restart)
  6080. (let ((org-use-property-inheritance nil))
  6081. (org-refresh-properties "A" 'org-test))
  6082. (get-text-property (point) 'org-test))))
  6083. (should
  6084. (equal "1"
  6085. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  6086. (org-mode-restart)
  6087. (let ((org-use-property-inheritance t))
  6088. (org-refresh-properties "A" 'org-test))
  6089. (get-text-property (point) 'org-test))))
  6090. (should
  6091. (equal "2"
  6092. (org-test-with-temp-text
  6093. "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
  6094. (org-mode-restart)
  6095. (let ((org-use-property-inheritance t))
  6096. (org-refresh-properties "A" 'org-test))
  6097. (get-text-property (point) 'org-test))))
  6098. ;; When both keyword-property and document-level property-block is
  6099. ;; defined, the property-block has precedance.
  6100. (should
  6101. (equal "1"
  6102. (org-test-with-temp-text
  6103. ":PROPERTIES:\n:A: 1\n:END:\n#+PROPERTY: A 2\n<point>* H1"
  6104. (org-mode-restart)
  6105. (let ((org-use-property-inheritance t))
  6106. (org-refresh-properties "A" 'org-test))
  6107. (get-text-property (point) 'org-test)))))
  6108. (ert-deftest test-org/refresh-category-properties ()
  6109. "Test `org-refresh-category-properties' specifications"
  6110. (should
  6111. (equal "cat1"
  6112. (org-test-with-temp-text
  6113. ":PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6114. (org-refresh-category-properties)
  6115. (get-text-property (point) 'org-category))))
  6116. (should
  6117. (equal "cat1"
  6118. (org-test-with-temp-text
  6119. "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6120. (org-refresh-category-properties)
  6121. (get-text-property (point) 'org-category))))
  6122. ;; Even though property-inheritance is deactivated, category
  6123. ;; property should be inherited. As described in
  6124. ;; `org-use-property-inheritance'.
  6125. (should
  6126. (equal "cat1"
  6127. (org-test-with-temp-text
  6128. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  6129. (org-mode-restart)
  6130. (let ((org-use-property-inheritance nil))
  6131. (org-refresh-category-properties))
  6132. (get-text-property (point) 'org-category))))
  6133. (should
  6134. (equal "cat1"
  6135. (org-test-with-temp-text
  6136. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  6137. (org-mode-restart)
  6138. (let ((org-use-property-inheritance t))
  6139. (org-refresh-category-properties))
  6140. (get-text-property (point) 'org-category))))
  6141. (should
  6142. (equal "cat2"
  6143. (org-test-with-temp-text
  6144. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H\n:PROPERTIES:\n:CATEGORY: cat2\n:END:\n"
  6145. (org-mode-restart)
  6146. (let ((org-use-property-inheritance t))
  6147. (org-refresh-category-properties))
  6148. (get-text-property (point) 'org-category)))))
  6149. ;;; Refile
  6150. (ert-deftest test-org/refile-get-targets ()
  6151. "Test `org-refile-get-targets' specifications."
  6152. ;; :maxlevel includes all headings above specified value.
  6153. (should
  6154. (equal '("H1" "H2" "H3")
  6155. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6156. (let ((org-refile-use-outline-path nil)
  6157. (org-refile-targets `((nil :maxlevel . 3))))
  6158. (mapcar #'car (org-refile-get-targets))))))
  6159. (should
  6160. (equal '("H1" "H2")
  6161. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6162. (let ((org-refile-use-outline-path nil)
  6163. (org-refile-targets `((nil :maxlevel . 2))))
  6164. (mapcar #'car (org-refile-get-targets))))))
  6165. ;; :level limits targets to headlines with the specified level.
  6166. (should
  6167. (equal '("H2")
  6168. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6169. (let ((org-refile-use-outline-path nil)
  6170. (org-refile-targets `((nil :level . 2))))
  6171. (mapcar #'car (org-refile-get-targets))))))
  6172. ;; :tag limits targets to headlines with specified tag.
  6173. (should
  6174. (equal '("H1")
  6175. (org-test-with-temp-text "* H1 :foo:\n** H2\n*** H3 :bar:"
  6176. (let ((org-refile-use-outline-path nil)
  6177. (org-refile-targets `((nil :tag . "foo"))))
  6178. (mapcar #'car (org-refile-get-targets))))))
  6179. ;; :todo limits targets to headlines with specified TODO keyword.
  6180. (should
  6181. (equal '("H2")
  6182. (org-test-with-temp-text "* H1\n** TODO H2\n*** DONE H3"
  6183. (let ((org-refile-use-outline-path nil)
  6184. (org-refile-targets `((nil :todo . "TODO"))))
  6185. (mapcar #'car (org-refile-get-targets))))))
  6186. ;; :regexp filters targets matching provided regexp.
  6187. (should
  6188. (equal '("F2" "F3")
  6189. (org-test-with-temp-text "* H1\n** F2\n*** F3"
  6190. (let ((org-refile-use-outline-path nil)
  6191. (org-refile-targets `((nil :regexp . "F"))))
  6192. (mapcar #'car (org-refile-get-targets))))))
  6193. ;; A nil `org-refile-targets' includes only top level headlines in
  6194. ;; current buffer.
  6195. (should
  6196. (equal '("H1" "H2")
  6197. (org-test-with-temp-text "* H1\n** S1\n* H2"
  6198. (let ((org-refile-use-outline-path nil)
  6199. (org-refile-targets nil))
  6200. (mapcar #'car (org-refile-get-targets))))))
  6201. ;; Return value is the union of the targets according to all the
  6202. ;; defined rules. However, prevent duplicates.
  6203. (should
  6204. (equal '("F2" "F3" "H1")
  6205. (org-test-with-temp-text "* TODO H1\n** F2\n*** F3"
  6206. (let ((org-refile-use-outline-path nil)
  6207. (org-refile-targets `((nil :regexp . "F")
  6208. (nil :todo . "TODO"))))
  6209. (mapcar #'car (org-refile-get-targets))))))
  6210. (should
  6211. (equal '("F2" "F3" "H1")
  6212. (org-test-with-temp-text "* TODO H1\n** TODO F2\n*** F3"
  6213. (let ((org-refile-use-outline-path nil)
  6214. (org-refile-targets `((nil :regexp . "F")
  6215. (nil :todo . "TODO"))))
  6216. (mapcar #'car (org-refile-get-targets))))))
  6217. ;; When `org-refile-use-outline-path' is non-nil, provide targets as
  6218. ;; paths.
  6219. (should
  6220. (equal '("H1" "H1/H2" "H1/H2/H3")
  6221. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6222. (let ((org-refile-use-outline-path t)
  6223. (org-refile-targets `((nil :maxlevel . 3))))
  6224. (mapcar #'car (org-refile-get-targets))))))
  6225. ;; When providing targets as paths, escape forward slashes in
  6226. ;; headings with backslashes.
  6227. (should
  6228. (equal '("H1\\/foo")
  6229. (org-test-with-temp-text "* H1/foo"
  6230. (let ((org-refile-use-outline-path t)
  6231. (org-refile-targets `((nil :maxlevel . 1))))
  6232. (mapcar #'car (org-refile-get-targets))))))
  6233. ;; When `org-refile-use-outline-path' is `file', include file name
  6234. ;; without directory in targets.
  6235. (should
  6236. (org-test-with-temp-text-in-file "* H1"
  6237. (let* ((filename (buffer-file-name))
  6238. (org-refile-use-outline-path 'file)
  6239. (org-refile-targets `(((,filename) :level . 1))))
  6240. (member (file-name-nondirectory filename)
  6241. (mapcar #'car (org-refile-get-targets))))))
  6242. ;; When `org-refile-use-outline-path' is `full-file-path', include
  6243. ;; full file name.
  6244. (should
  6245. (org-test-with-temp-text-in-file "* H1"
  6246. (let* ((filename (file-truename (buffer-file-name)))
  6247. (org-refile-use-outline-path 'full-file-path)
  6248. (org-refile-targets `(((,filename) :level . 1))))
  6249. (member filename (mapcar #'car (org-refile-get-targets))))))
  6250. ;; When `org-refile-use-outline-path' is `buffer-name', include
  6251. ;; buffer name.
  6252. (should
  6253. (org-test-with-temp-text "* H1"
  6254. (let* ((org-refile-use-outline-path 'buffer-name)
  6255. (org-refile-targets `((nil :level . 1))))
  6256. (member (buffer-name) (mapcar #'car (org-refile-get-targets)))))))
  6257. ;;; Sparse trees
  6258. (ert-deftest test-org/match-sparse-tree ()
  6259. "Test `org-match-sparse-tree' specifications."
  6260. ;; Match tags.
  6261. (should-not
  6262. (org-test-with-temp-text "* H\n** H1 :tag:"
  6263. (org-match-sparse-tree nil "tag")
  6264. (search-forward "H1")
  6265. (org-invisible-p2)))
  6266. (should
  6267. (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
  6268. (org-match-sparse-tree nil "tag")
  6269. (search-forward "H2")
  6270. (org-invisible-p2)))
  6271. ;; "-" operator for tags.
  6272. (should-not
  6273. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6274. (org-match-sparse-tree nil "tag1-tag2")
  6275. (search-forward "H1")
  6276. (org-invisible-p2)))
  6277. (should
  6278. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6279. (org-match-sparse-tree nil "tag1-tag2")
  6280. (search-forward "H2")
  6281. (org-invisible-p2)))
  6282. ;; "&" operator for tags.
  6283. (should
  6284. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6285. (org-match-sparse-tree nil "tag1&tag2")
  6286. (search-forward "H1")
  6287. (org-invisible-p2)))
  6288. (should-not
  6289. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6290. (org-match-sparse-tree nil "tag1&tag2")
  6291. (search-forward "H2")
  6292. (org-invisible-p2)))
  6293. ;; "|" operator for tags.
  6294. (should-not
  6295. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6296. (org-match-sparse-tree nil "tag1|tag2")
  6297. (search-forward "H1")
  6298. (org-invisible-p2)))
  6299. (should-not
  6300. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6301. (org-match-sparse-tree nil "tag1|tag2")
  6302. (search-forward "H2")
  6303. (org-invisible-p2)))
  6304. ;; Regexp match on tags.
  6305. (should-not
  6306. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6307. (org-match-sparse-tree nil "{^tag.*}")
  6308. (search-forward "H1")
  6309. (org-invisible-p2)))
  6310. (should
  6311. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6312. (org-match-sparse-tree nil "{^tag.*}")
  6313. (search-forward "H2")
  6314. (org-invisible-p2)))
  6315. ;; Match group tags.
  6316. (should-not
  6317. (org-test-with-temp-text
  6318. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6319. (org-match-sparse-tree nil "work")
  6320. (search-forward "H1")
  6321. (org-invisible-p2)))
  6322. (should-not
  6323. (org-test-with-temp-text
  6324. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6325. (org-match-sparse-tree nil "work")
  6326. (search-forward "H2")
  6327. (org-invisible-p2)))
  6328. ;; Match group tags with hard brackets.
  6329. (should-not
  6330. (org-test-with-temp-text
  6331. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6332. (org-match-sparse-tree nil "work")
  6333. (search-forward "H1")
  6334. (org-invisible-p2)))
  6335. (should-not
  6336. (org-test-with-temp-text
  6337. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6338. (org-match-sparse-tree nil "work")
  6339. (search-forward "H2")
  6340. (org-invisible-p2)))
  6341. ;; Match tags in hierarchies
  6342. (should-not
  6343. (org-test-with-temp-text
  6344. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6345. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6346. #+TAGS: { Lev_3 : Lev_4 }\n
  6347. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6348. (org-match-sparse-tree nil "Lev_1")
  6349. (search-forward "H4")
  6350. (org-invisible-p2)))
  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+Lev_3")
  6358. (search-forward "H4")
  6359. (org-invisible-p2)))
  6360. ;; Match regular expressions in tags
  6361. (should-not
  6362. (org-test-with-temp-text
  6363. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
  6364. (org-match-sparse-tree nil "Lev")
  6365. (search-forward "H1")
  6366. (org-invisible-p2)))
  6367. (should
  6368. (org-test-with-temp-text
  6369. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
  6370. (org-match-sparse-tree nil "Lev")
  6371. (search-forward "H1")
  6372. (org-invisible-p2)))
  6373. ;; Match properties.
  6374. (should
  6375. (org-test-with-temp-text
  6376. "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
  6377. (org-match-sparse-tree nil "A=\"1\"")
  6378. (search-forward "H2")
  6379. (org-invisible-p2)))
  6380. (should-not
  6381. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6382. (org-match-sparse-tree nil "A=\"1\"")
  6383. (search-forward "H2")
  6384. (org-invisible-p2)))
  6385. ;; Case is not significant when matching properties.
  6386. (should-not
  6387. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6388. (org-match-sparse-tree nil "a=\"1\"")
  6389. (search-forward "H2")
  6390. (org-invisible-p2)))
  6391. (should-not
  6392. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
  6393. (org-match-sparse-tree nil "A=\"1\"")
  6394. (search-forward "H2")
  6395. (org-invisible-p2)))
  6396. ;; Match special LEVEL property.
  6397. (should-not
  6398. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6399. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6400. (search-forward "H1")
  6401. (org-invisible-p2)))
  6402. (should
  6403. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6404. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6405. (search-forward "H2")
  6406. (org-invisible-p2)))
  6407. ;; Comparison operators when matching properties.
  6408. (should
  6409. (org-test-with-temp-text
  6410. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6411. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6412. (search-forward "H1")
  6413. (org-invisible-p2)))
  6414. (should-not
  6415. (org-test-with-temp-text
  6416. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6417. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6418. (search-forward "H2")
  6419. (org-invisible-p2)))
  6420. ;; Regexp match on properties values.
  6421. (should-not
  6422. (org-test-with-temp-text
  6423. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6424. (org-match-sparse-tree nil "A={f.*}")
  6425. (search-forward "H1")
  6426. (org-invisible-p2)))
  6427. (should
  6428. (org-test-with-temp-text
  6429. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6430. (org-match-sparse-tree nil "A={f.*}")
  6431. (search-forward "H2")
  6432. (org-invisible-p2)))
  6433. ;; With an optional argument, limit match to TODO entries.
  6434. (should-not
  6435. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6436. (org-match-sparse-tree t "tag")
  6437. (search-forward "H1")
  6438. (org-invisible-p2)))
  6439. (should
  6440. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6441. (org-match-sparse-tree t "tag")
  6442. (search-forward "H2")
  6443. (org-invisible-p2))))
  6444. (ert-deftest test-org/occur ()
  6445. "Test `org-occur' specifications."
  6446. ;; Count number of matches.
  6447. (should
  6448. (= 1
  6449. (org-test-with-temp-text "* H\nA\n* H2"
  6450. (org-occur "A"))))
  6451. (should
  6452. (= 2
  6453. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6454. (org-occur "A"))))
  6455. ;; Test CALLBACK optional argument.
  6456. (should
  6457. (= 0
  6458. (org-test-with-temp-text "* H\nA\n* H2"
  6459. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6460. (should
  6461. (= 1
  6462. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6463. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6464. ;; Case-fold searches according to `org-occur-case-fold-search'.
  6465. (should
  6466. (= 2
  6467. (org-test-with-temp-text "Aa"
  6468. (let ((org-occur-case-fold-search t)) (org-occur "A")))))
  6469. (should
  6470. (= 2
  6471. (org-test-with-temp-text "Aa"
  6472. (let ((org-occur-case-fold-search t)) (org-occur "a")))))
  6473. (should
  6474. (= 1
  6475. (org-test-with-temp-text "Aa"
  6476. (let ((org-occur-case-fold-search nil)) (org-occur "A")))))
  6477. (should
  6478. (= 1
  6479. (org-test-with-temp-text "Aa"
  6480. (let ((org-occur-case-fold-search nil)) (org-occur "a")))))
  6481. (should
  6482. (= 1
  6483. (org-test-with-temp-text "Aa"
  6484. (let ((org-occur-case-fold-search 'smart)) (org-occur "A")))))
  6485. (should
  6486. (= 2
  6487. (org-test-with-temp-text "Aa"
  6488. (let ((org-occur-case-fold-search 'smart)) (org-occur "a"))))))
  6489. ;;; Tags
  6490. (ert-deftest test-org/tag-string-to-alist ()
  6491. "Test `org-tag-string-to-alist' specifications."
  6492. ;; Tag without selection key.
  6493. (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
  6494. ;; Tag with selection key.
  6495. (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t))))
  6496. ;; Tag group.
  6497. (should
  6498. (equal
  6499. (org-tag-string-to-alist "[ group : t1 t2 ]")
  6500. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag))))
  6501. ;; Mutually exclusive tags.
  6502. (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
  6503. '((:startgroup) ("tag1") ("tag2") (:endgroup))))
  6504. (should
  6505. (equal
  6506. (org-tag-string-to-alist "{ group : tag1 tag2 }")
  6507. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))))
  6508. (ert-deftest test-org/tag-alist-to-string ()
  6509. "Test `org-tag-alist-to-string' specifications."
  6510. (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
  6511. (should (equal (org-tag-alist-to-string '(("tag1" . ?t))) "tag1(t)"))
  6512. (should
  6513. (equal
  6514. (org-tag-alist-to-string
  6515. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6516. "[ group : t1 t2 ]"))
  6517. (should
  6518. (equal (org-tag-alist-to-string
  6519. '((:startgroup) ("tag1") ("tag2") (:endgroup)))
  6520. "{ tag1 tag2 }"))
  6521. (should
  6522. (equal
  6523. (org-tag-alist-to-string
  6524. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))
  6525. "{ group : tag1 tag2 }")))
  6526. (ert-deftest test-org/tag-alist-to-groups ()
  6527. "Test `org-tag-alist-to-groups' specifications."
  6528. (should
  6529. (equal (org-tag-alist-to-groups
  6530. '((:startgroup) ("group") (:grouptags) ("t1") ("t2") (:endgroup)))
  6531. '(("group" "t1" "t2"))))
  6532. (should
  6533. (equal
  6534. (org-tag-alist-to-groups
  6535. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6536. '(("group" "t1" "t2"))))
  6537. (should-not
  6538. (org-tag-alist-to-groups
  6539. '((:startgroup) ("group") ("t1") ("t2") (:endgroup)))))
  6540. (ert-deftest test-org/tag-align ()
  6541. "Test tags alignment."
  6542. ;; Test aligning tags with different display width.
  6543. (should
  6544. ;; 12345678901234567890
  6545. (equal "* Test :abc:"
  6546. (org-test-with-temp-text "* Test :abc:"
  6547. (let ((org-tags-column -20)
  6548. (indent-tabs-mode nil))
  6549. (org-fix-tags-on-the-fly))
  6550. (buffer-string))))
  6551. (should
  6552. ;; 12345678901234567890
  6553. (equal "* Test :日本語:"
  6554. (org-test-with-temp-text "* Test :日本語:"
  6555. (let ((org-tags-column -20)
  6556. (indent-tabs-mode nil))
  6557. (org-fix-tags-on-the-fly))
  6558. (buffer-string))))
  6559. ;; Make sure aligning tags do not skip invisible text.
  6560. (should
  6561. (equal "* [[linkx]] :tag:"
  6562. (org-test-with-temp-text "* [[link<point>]] :tag:"
  6563. (let ((org-tags-column 0))
  6564. (org-fix-tags-on-the-fly)
  6565. (insert "x")
  6566. (buffer-string)))))
  6567. ;; Aligning tags preserve position.
  6568. (should
  6569. (= 6 (org-test-with-temp-text "* 345 <point> :tag:"
  6570. (let ((org-tags-column 78)
  6571. (indent-tabs-mode nil))
  6572. (org-fix-tags-on-the-fly))
  6573. (current-column))))
  6574. ;; Aligning all tags in visible buffer.
  6575. (should
  6576. ;; 12345678901234567890
  6577. (equal (concat "* Level 1 :abc:\n"
  6578. "** Level 2 :def:")
  6579. (org-test-with-temp-text (concat "* Level 1 :abc:\n"
  6580. "** Level 2 :def:")
  6581. (let ((org-tags-column -20)
  6582. (indent-tabs-mode nil))
  6583. ;; (org-align-tags :all) must work even when the point
  6584. ;; is at the end of the buffer.
  6585. (goto-char (point-max))
  6586. (org-align-tags :all))
  6587. (buffer-string)))))
  6588. (ert-deftest test-org/get-tags ()
  6589. "Test `org-get-tags' specifications."
  6590. ;; Standard test.
  6591. (should
  6592. (equal '("foo")
  6593. (org-test-with-temp-text "* Test :foo:" (org-get-tags))))
  6594. (should
  6595. (equal '("foo" "bar")
  6596. (org-test-with-temp-text "* Test :foo:bar:" (org-get-tags))))
  6597. ;; Return nil when there is no tag.
  6598. (should-not
  6599. (org-test-with-temp-text "* Test" (org-get-tags)))
  6600. ;; Tags are inherited from parent headlines.
  6601. (should
  6602. (equal '("tag")
  6603. (let ((org-use-tag-inheritance t))
  6604. (org-test-with-temp-text "* H0 :foo:\n* H1 :tag:\n<point>** H2"
  6605. (org-get-tags)))))
  6606. ;; Tags are inherited from `org-file-tags'.
  6607. (should
  6608. (equal '("tag")
  6609. (org-test-with-temp-text "* H1"
  6610. (let ((org-file-tags '("tag"))
  6611. (org-use-tag-inheritance t))
  6612. (org-get-tags)))))
  6613. ;; Only inherited tags have the `inherited' text property.
  6614. (should
  6615. (get-text-property 0 'inherited
  6616. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6617. (let ((org-use-tag-inheritance t))
  6618. (assoc-string "foo" (org-get-tags))))))
  6619. (should-not
  6620. (get-text-property 0 'inherited
  6621. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6622. (let ((org-use-tag-inheritance t))
  6623. (assoc-string "bar" (org-get-tags))))))
  6624. ;; Obey to `org-use-tag-inheritance'.
  6625. (should-not
  6626. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6627. (let ((org-use-tag-inheritance nil))
  6628. (assoc-string "foo" (org-get-tags)))))
  6629. (should-not
  6630. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6631. (let ((org-use-tag-inheritance nil)
  6632. (org-file-tags '("foo")))
  6633. (assoc-string "foo" (org-get-tags)))))
  6634. (should-not
  6635. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6636. (let ((org-use-tag-inheritance '("bar")))
  6637. (assoc-string "foo" (org-get-tags)))))
  6638. (should
  6639. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6640. (let ((org-use-tag-inheritance '("bar")))
  6641. (assoc-string "bar" (org-get-tags)))))
  6642. (should-not
  6643. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6644. (let ((org-use-tag-inheritance "b.*"))
  6645. (assoc-string "foo" (org-get-tags)))))
  6646. (should
  6647. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6648. (let ((org-use-tag-inheritance "b.*"))
  6649. (assoc-string "bar" (org-get-tags)))))
  6650. ;; When optional argument LOCAL is non-nil, ignore tag inheritance.
  6651. (should
  6652. (equal '("baz")
  6653. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6654. (let ((org-use-tag-inheritance t))
  6655. (org-get-tags nil t)))))
  6656. ;; When optional argument POS is non-nil, get tags there instead.
  6657. (should
  6658. (equal '("foo")
  6659. (org-test-with-temp-text "* H1 :foo:\n* <point>H2 :bar:"
  6660. (org-get-tags 1))))
  6661. ;; Make sure tags excluded from inheritance are returned if local
  6662. (should
  6663. (equal '("foo")
  6664. (org-test-with-temp-text "* Test :foo:"
  6665. (let ((org-use-tag-inheritance t)
  6666. (org-tags-exclude-from-inheritance '("foo")))
  6667. (org-get-tags)))))
  6668. ;; Test the collection of tags from #+filetags and parent tags.
  6669. (should
  6670. (equal '("a" "b" "c" "d")
  6671. (org-test-with-temp-text (concat "#+filetags: a\n"
  6672. "* Level 1 :b:\n"
  6673. "** Level 2 :c:\n"
  6674. "*** Level 3 :d:\n"
  6675. "<point>")
  6676. (let ((org-use-tag-inheritance t))
  6677. (org-mode-restart) ;So that `org-file-tags' get populated from #+filetags
  6678. (org-get-tags)))))
  6679. ;; Pathological case: tagged headline with an empty body.
  6680. (should (org-test-with-temp-text "* :tag:" (org-get-tags))))
  6681. (ert-deftest test-org/set-tags ()
  6682. "Test `org-set-tags' specifications."
  6683. ;; Throw an error on invalid data.
  6684. (should-error
  6685. (org-test-with-temp-text "* H"
  6686. (org-set-tags 'foo)))
  6687. ;; `nil', an empty, and a blank string remove all tags.
  6688. (should
  6689. (equal "* H"
  6690. (org-test-with-temp-text "* H :tag1:tag2:"
  6691. (org-set-tags nil)
  6692. (buffer-string))))
  6693. (should
  6694. (equal "* H"
  6695. (org-test-with-temp-text "* H :tag1:tag2:"
  6696. (org-set-tags "")
  6697. (buffer-string))))
  6698. (should
  6699. (equal "* H"
  6700. (org-test-with-temp-text "* H :tag1:tag2:"
  6701. (org-set-tags " ")
  6702. (buffer-string))))
  6703. ;; If there's nothing to remove, just bail out.
  6704. (should
  6705. (equal "* H"
  6706. (org-test-with-temp-text "* H"
  6707. (org-set-tags nil)
  6708. (buffer-string))))
  6709. (should
  6710. (equal "* "
  6711. (org-test-with-temp-text "* "
  6712. (org-set-tags nil)
  6713. (buffer-string))))
  6714. ;; If DATA is a tag string, set current tags to it, even if it means
  6715. ;; replacing old tags.
  6716. (should
  6717. (equal "* H :tag0:"
  6718. (org-test-with-temp-text "* H :tag1:tag2:"
  6719. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  6720. (buffer-string))))
  6721. (should
  6722. (equal "* H :tag0:"
  6723. (org-test-with-temp-text "* H"
  6724. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  6725. (buffer-string))))
  6726. ;; If DATA is a list, set tags to this list, even if it means
  6727. ;; replacing old tags.
  6728. (should
  6729. (equal "* H :tag0:"
  6730. (org-test-with-temp-text "* H :tag1:tag2:"
  6731. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6732. (buffer-string))))
  6733. (should
  6734. (equal "* H :tag0:"
  6735. (org-test-with-temp-text "* H"
  6736. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6737. (buffer-string))))
  6738. ;; When set, apply `org-tags-sort-function'.
  6739. (should
  6740. (equal "* H :a:b:"
  6741. (org-test-with-temp-text "* H"
  6742. (let ((org-tags-column 1)
  6743. (org-tags-sort-function #'string<))
  6744. (org-set-tags '("b" "a"))
  6745. (buffer-string)))))
  6746. ;; When new tags are identical to the previous ones, still align.
  6747. (should
  6748. (equal "* H :foo:"
  6749. (org-test-with-temp-text "* H :foo:"
  6750. (let ((org-tags-column 1))
  6751. (org-set-tags '("foo"))
  6752. (buffer-string)))))
  6753. ;; When tags have been changed, run `org-after-tags-change-hook'.
  6754. (should
  6755. (catch :return
  6756. (org-test-with-temp-text "* H :foo:"
  6757. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  6758. (org-set-tags '("bar"))
  6759. nil))))
  6760. (should-not
  6761. (catch :return
  6762. (org-test-with-temp-text "* H :foo:"
  6763. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  6764. (org-set-tags '("foo"))
  6765. nil))))
  6766. ;; Special case: handle empty headlines.
  6767. (should
  6768. (equal "* :tag0:"
  6769. (org-test-with-temp-text "* "
  6770. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6771. (buffer-string))))
  6772. ;; Modify buffer only when a tag change happens or alignment is
  6773. ;; done.
  6774. (should-not
  6775. (org-test-with-temp-text "* H :foo:"
  6776. (set-buffer-modified-p nil)
  6777. (let ((org-tags-column 1)) (org-set-tags '("foo")))
  6778. (buffer-modified-p)))
  6779. (should
  6780. (org-test-with-temp-text "* H :foo:"
  6781. (set-buffer-modified-p nil)
  6782. (let ((org-tags-column 10)) (org-set-tags '("foo")))
  6783. (buffer-modified-p)))
  6784. (should
  6785. (org-test-with-temp-text "* H :foo:"
  6786. (set-buffer-modified-p nil)
  6787. (let ((org-tags-column 10)) (org-set-tags '("bar")))
  6788. (buffer-modified-p)))
  6789. ;; Pathological case: when setting tags of a folded headline, do not
  6790. ;; let new tags being sucked into invisibility.
  6791. (should-not
  6792. (org-test-with-temp-text "* H1\nContent\n* H2\n\n Other Content"
  6793. ;; Show only headlines
  6794. (org-content)
  6795. ;; Set NEXT tag on current entry
  6796. (org-set-tags ":NEXT:")
  6797. ;; Move point to that NEXT tag
  6798. (search-forward "NEXT") (backward-word)
  6799. ;; And it should be visible (i.e. no overlays)
  6800. (overlays-at (point)))))
  6801. (ert-deftest test-org/set-tags-command ()
  6802. "Test `org-set-tags-command' specifications"
  6803. ;; Set tags at current headline.
  6804. (should
  6805. (equal "* H1 :foo:"
  6806. (org-test-with-temp-text "* H1"
  6807. (cl-letf (((symbol-function 'completing-read-multiple)
  6808. (lambda (&rest args) '("foo"))))
  6809. (let ((org-use-fast-tag-selection nil)
  6810. (org-tags-column 1))
  6811. (org-set-tags-command)))
  6812. (buffer-string))))
  6813. ;; Preserve position when called from the section below.
  6814. (should
  6815. (equal "* H1 :foo:\nContents"
  6816. (org-test-with-temp-text "* H1\n<point>Contents"
  6817. (cl-letf (((symbol-function 'completing-read-multiple)
  6818. (lambda (&rest args) '("foo"))))
  6819. (let ((org-use-fast-tag-selection nil)
  6820. (org-tags-column 1))
  6821. (org-set-tags-command)))
  6822. (buffer-string))))
  6823. (should-not
  6824. (equal "* H1 :foo:\nContents2"
  6825. (org-test-with-temp-text "* H1\n<point>Contents2"
  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. (org-at-heading-p))))
  6832. ;; When a region is active and
  6833. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  6834. ;; same value in all headlines in region.
  6835. (should
  6836. (equal "* H1 :foo:\nContents\n* H2 :foo:"
  6837. (org-test-with-temp-text "* H1\nContents\n* H2"
  6838. (cl-letf (((symbol-function 'completing-read-multiple)
  6839. (lambda (&rest args) '("foo"))))
  6840. (let ((org-use-fast-tag-selection nil)
  6841. (org-loop-over-headlines-in-active-region t)
  6842. (org-tags-column 1))
  6843. (transient-mark-mode 1)
  6844. (push-mark (point) t t)
  6845. (goto-char (point-max))
  6846. (org-set-tags-command)))
  6847. (buffer-string))))
  6848. (should
  6849. (equal "* H1\nContents\n* H2 :foo:"
  6850. (org-test-with-temp-text "* H1\nContents\n* H2"
  6851. (cl-letf (((symbol-function 'completing-read-multiple)
  6852. (lambda (&rest args) '("foo"))))
  6853. (let ((org-use-fast-tag-selection nil)
  6854. (org-loop-over-headlines-in-active-region nil)
  6855. (org-tags-column 1))
  6856. (transient-mark-mode 1)
  6857. (push-mark (point) t t)
  6858. (goto-char (point-max))
  6859. (org-set-tags-command)))
  6860. (buffer-string))))
  6861. ;; With a C-u prefix argument, align all tags in the buffer.
  6862. (should
  6863. (equal "* H1 :foo:\n* H2 :bar:"
  6864. (org-test-with-temp-text "* H1 :foo:\n* H2 :bar:"
  6865. (let ((org-tags-column 1)) (org-set-tags-command '(4)))
  6866. (buffer-string))))
  6867. ;; Point does not move with empty headline.
  6868. (should
  6869. (equal ":foo:"
  6870. (org-test-with-temp-text "* <point>"
  6871. (cl-letf (((symbol-function 'completing-read-multiple)
  6872. (lambda (&rest args) '("foo"))))
  6873. (let ((org-use-fast-tag-selection nil)
  6874. (org-tags-column 1))
  6875. (org-set-tags-command)))
  6876. (buffer-substring (point) (line-end-position)))))
  6877. ;; Point does not move at start of line.
  6878. (should
  6879. (equal "* H1 :foo:"
  6880. (org-test-with-temp-text "* H1"
  6881. (cl-letf (((symbol-function 'completing-read-multiple)
  6882. (lambda (&rest args) '("foo"))))
  6883. (let ((org-use-fast-tag-selection nil)
  6884. (org-tags-column 1))
  6885. (org-set-tags-command)))
  6886. (buffer-substring (point) (line-end-position)))))
  6887. ;; Point does not move when within *'s.
  6888. (should
  6889. (equal "* H1 :foo:"
  6890. (org-test-with-temp-text "*<point>* H1"
  6891. (cl-letf (((symbol-function 'completing-read-multiple)
  6892. (lambda (&rest args) '("foo"))))
  6893. (let ((org-use-fast-tag-selection nil)
  6894. (org-tags-column 1))
  6895. (org-set-tags-command)))
  6896. (buffer-substring (point) (line-end-position)))))
  6897. ;; Point workaround does not get fooled when looking at a space.
  6898. (should
  6899. (equal " b :foo:"
  6900. (org-test-with-temp-text "* a<point> b"
  6901. (cl-letf (((symbol-function 'completing-read-multiple)
  6902. (lambda (&rest args) '("foo"))))
  6903. (let ((org-use-fast-tag-selection nil)
  6904. (org-tags-column 1))
  6905. (org-set-tags-command)))
  6906. (buffer-substring (point) (line-end-position)))))
  6907. ;; Handle tags both set locally and inherited.
  6908. (should
  6909. (equal "b :foo:"
  6910. (org-test-with-temp-text "* a :foo:\n** <point>b :foo:"
  6911. (cl-letf (((symbol-function 'completing-read-multiple)
  6912. (lambda (prompt coll &optional pred req initial &rest args)
  6913. (list initial))))
  6914. (let ((org-use-fast-tag-selection nil)
  6915. (org-tags-column 1))
  6916. (org-set-tags-command)))
  6917. (buffer-substring (point) (line-end-position))))))
  6918. (ert-deftest test-org/toggle-tag ()
  6919. "Test `org-toggle-tag' specifications."
  6920. ;; Insert missing tag.
  6921. (should
  6922. (equal "* H :tag:"
  6923. (org-test-with-temp-text "* H"
  6924. (let ((org-tags-column 1)) (org-toggle-tag "tag"))
  6925. (buffer-string))))
  6926. (should
  6927. (equal "* H :tag1:tag2:"
  6928. (org-test-with-temp-text "* H :tag1:"
  6929. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  6930. (buffer-string))))
  6931. ;; Remove existing tag.
  6932. (should
  6933. (equal "* H"
  6934. (org-test-with-temp-text "* H :tag:"
  6935. (org-toggle-tag "tag")
  6936. (buffer-string))))
  6937. (should
  6938. (equal "* H :tag1:"
  6939. (org-test-with-temp-text "* H :tag1:tag2:"
  6940. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  6941. (buffer-string))))
  6942. (should
  6943. (equal "* H :tag2:"
  6944. (org-test-with-temp-text "* H :tag1:tag2:"
  6945. (let ((org-tags-column 1)) (org-toggle-tag "tag1"))
  6946. (buffer-string))))
  6947. ;; With optional argument ONOFF set to `on', try to insert the tag,
  6948. ;; even if its already there.
  6949. (should
  6950. (equal "* H :tag:"
  6951. (org-test-with-temp-text "* H"
  6952. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  6953. (buffer-string))))
  6954. (should
  6955. (equal "* H :tag:"
  6956. (org-test-with-temp-text "* H :tag:"
  6957. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  6958. (buffer-string))))
  6959. ;; With optional argument ONOFF set to `off', try to remove the tag,
  6960. ;; even if its not there.
  6961. (should
  6962. (equal "* H"
  6963. (org-test-with-temp-text "* H :tag:"
  6964. (org-toggle-tag "tag" 'off)
  6965. (buffer-string))))
  6966. (should
  6967. (equal "* H :tag:"
  6968. (org-test-with-temp-text "* H :tag:"
  6969. (let ((org-tags-column 1)) (org-toggle-tag "foo" 'off))
  6970. (buffer-string))))
  6971. ;; Special case: Handle properly tag inheritance. In particular, do
  6972. ;; not set inherited tags.
  6973. (should
  6974. (equal "* H1 :tag:\n** H2 :tag2:tag:"
  6975. (org-test-with-temp-text "* H1 :tag:\n** <point>H2 :tag2:"
  6976. (let ((org-use-tag-inheritance t)
  6977. (org-tags-column 1))
  6978. (org-toggle-tag "tag"))
  6979. (buffer-string))))
  6980. (should
  6981. (equal "* H1 :tag1:tag2:\n** H2 :foo:"
  6982. (org-test-with-temp-text "* H1 :tag1:tag2:\n** <point>H2"
  6983. (let ((org-use-tag-inheritance t)
  6984. (org-tags-column 1))
  6985. (org-toggle-tag "foo"))
  6986. (buffer-string)))))
  6987. (ert-deftest test-org/tags-expand ()
  6988. "Test `org-tags-expand' specifications."
  6989. ;; Expand tag groups as a regexp enclosed within curly brackets.
  6990. (should
  6991. (equal "{\\<[ABC]\\>}"
  6992. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6993. (org-mode-restart)
  6994. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  6995. (should
  6996. (equal "{\\<\\(?:Aa\\|Bb\\|Cc\\)\\>}"
  6997. (org-test-with-temp-text "#+TAGS: [ Aa : Bb Cc ]"
  6998. (org-mode-restart)
  6999. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "Aa")))))
  7000. ;; Preserve operator before the regexp.
  7001. (should
  7002. (equal "+{\\<[ABC]\\>}"
  7003. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7004. (org-mode-restart)
  7005. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "+A")))))
  7006. (should
  7007. (equal "-{\\<[ABC]\\>}"
  7008. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7009. (org-mode-restart)
  7010. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "-A")))))
  7011. ;; Handle "|" syntax.
  7012. (should
  7013. (equal "{\\<[ABC]\\>}|D"
  7014. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7015. (org-mode-restart)
  7016. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|D")))))
  7017. ;; Handle nested groups.
  7018. (should
  7019. (equal "{\\<[A-D]\\>}"
  7020. (org-test-with-temp-text "#+TAGS: [ A : B C ]\n#+TAGS: [ B : D ]"
  7021. (org-mode-restart)
  7022. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  7023. ;; Expand multiple occurrences of the same group.
  7024. (should
  7025. (equal "{\\<[ABC]\\>}|{\\<[ABC]\\>}"
  7026. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7027. (org-mode-restart)
  7028. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|A")))))
  7029. ;; Preserve regexp matches.
  7030. (should
  7031. (equal "{A+}"
  7032. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7033. (org-mode-restart)
  7034. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "{A+}"))))))
  7035. ;;; TODO keywords
  7036. (ert-deftest test-org/auto-repeat-maybe ()
  7037. "Test `org-auto-repeat-maybe' specifications."
  7038. ;; Do not auto repeat when there is no valid time stamp with
  7039. ;; a repeater in the entry.
  7040. (should-not
  7041. (string-prefix-p
  7042. "* TODO H"
  7043. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7044. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
  7045. (org-todo "DONE")
  7046. (buffer-string)))))
  7047. (should-not
  7048. (string-prefix-p
  7049. "* TODO H"
  7050. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7051. (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
  7052. (org-todo "DONE")
  7053. (buffer-string)))))
  7054. ;; When switching to DONE state, switch back to first TODO keyword
  7055. ;; in sequence, or the same keyword if they have different types.
  7056. (should
  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 +2y>"
  7061. (org-todo "DONE")
  7062. (buffer-string)))))
  7063. (should
  7064. (string-prefix-p
  7065. "* KWD1 H"
  7066. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  7067. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  7068. (org-todo "DONE")
  7069. (buffer-string)))))
  7070. (should
  7071. (string-prefix-p
  7072. "* KWD2 H"
  7073. (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
  7074. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  7075. (org-todo "DONE")
  7076. (buffer-string)))))
  7077. ;; If there was no TODO keyword in the first place, do not insert
  7078. ;; any either.
  7079. (should
  7080. (string-prefix-p
  7081. "* H"
  7082. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7083. (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
  7084. (org-todo "DONE")
  7085. (buffer-string)))))
  7086. ;; Revert to REPEAT_TO_STATE, if set.
  7087. (should
  7088. (string-prefix-p
  7089. "* KWD2 H"
  7090. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  7091. (org-test-with-temp-text
  7092. "* KWD2 H
  7093. :PROPERTIES:
  7094. :REPEAT_TO_STATE: KWD2
  7095. :END:
  7096. <2012-03-29 Thu +2y>"
  7097. (org-todo "DONE")
  7098. (buffer-string)))))
  7099. ;; When switching to DONE state, update base date. If there are
  7100. ;; multiple repeated time stamps, update them all.
  7101. (should
  7102. (string-match-p
  7103. "<2014-03-29 .* \\+2y>"
  7104. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7105. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7106. (org-todo "DONE")
  7107. (buffer-string)))))
  7108. (should
  7109. (string-match-p
  7110. "<2015-03-04 .* \\+1y>"
  7111. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7112. (org-test-with-temp-text
  7113. "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
  7114. (org-todo "DONE")
  7115. (buffer-string)))))
  7116. ;; Throw an error if repeater unit is the hour and no time is
  7117. ;; provided in the time-stamp.
  7118. (should-error
  7119. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7120. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
  7121. (org-todo "DONE")
  7122. (buffer-string))))
  7123. ;; Handle every repeater type using hours step.
  7124. (should
  7125. (string-match-p
  7126. "2014-03-04 .* 02:00"
  7127. (org-test-at-time "<2014-03-04 02:35>"
  7128. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 +8h>"
  7129. (org-todo "DONE")
  7130. (buffer-string)))))
  7131. (should
  7132. (string-match-p
  7133. "2014-03-04 .* 10:00"
  7134. (org-test-at-time "<2014-03-04 02:35>"
  7135. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 ++8h>"
  7136. (org-todo "DONE")
  7137. (buffer-string)))))
  7138. (should
  7139. (string-match-p
  7140. "2014-03-04 .* 10:35"
  7141. (org-test-at-time "<2014-03-04 02:35>"
  7142. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 .+8h>"
  7143. (org-todo "DONE")
  7144. (buffer-string)))))
  7145. ;; Do not repeat inactive time stamps with a repeater.
  7146. (should-not
  7147. (string-match-p
  7148. "\\[2014-03-29 .* \\+2y\\]"
  7149. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7150. (org-test-with-temp-text
  7151. "* TODO H\n[2012-03-29 Thu. +2y]"
  7152. (org-todo "DONE")
  7153. (buffer-string)))))
  7154. ;; Do not repeat commented time stamps.
  7155. (should-not
  7156. (string-prefix-p
  7157. "<2015-03-04 .* \\+1y>"
  7158. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7159. (org-test-with-temp-text
  7160. "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
  7161. (org-todo "DONE")
  7162. (buffer-string)))))
  7163. (should-not
  7164. (string-prefix-p
  7165. "<2015-03-04 .* \\+1y>"
  7166. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7167. (org-test-with-temp-text
  7168. "* TODO H
  7169. <2012-03-29 Thu. +2y>
  7170. #+BEGIN_EXAMPLE
  7171. <2014-03-04 Tue +1y>
  7172. #+END_EXAMPLE"
  7173. (org-todo "DONE")
  7174. (buffer-string)))))
  7175. ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
  7176. ;; entry, record time of last repeat.
  7177. (should-not
  7178. (string-match-p
  7179. ":LAST_REPEAT:"
  7180. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  7181. (org-log-repeat nil))
  7182. (cl-letf (((symbol-function 'org-add-log-setup)
  7183. (lambda (&rest args) nil)))
  7184. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  7185. (org-todo "DONE")
  7186. (buffer-string))))))
  7187. (should
  7188. (string-match-p
  7189. ":LAST_REPEAT:"
  7190. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  7191. (org-log-repeat t))
  7192. (cl-letf (((symbol-function 'org-add-log-setup)
  7193. (lambda (&rest args) nil)))
  7194. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  7195. (org-todo "DONE")
  7196. (buffer-string))))))
  7197. (should
  7198. (string-match-p
  7199. ":LAST_REPEAT:"
  7200. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7201. (cl-letf (((symbol-function 'org-add-log-setup)
  7202. (lambda (&rest args) nil)))
  7203. (org-test-with-temp-text
  7204. "* TODO H\n<2012-03-29 Thu +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
  7205. (org-todo "DONE")
  7206. (buffer-string))))))
  7207. ;; When a SCHEDULED entry has no repeater, remove it upon repeating
  7208. ;; the entry as it is no longer relevant.
  7209. (should-not
  7210. (string-match-p
  7211. "^SCHEDULED:"
  7212. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7213. (org-test-with-temp-text
  7214. "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
  7215. (org-todo "DONE")
  7216. (buffer-string)))))
  7217. ;; Properly advance repeater even when a clock entry is specified
  7218. ;; and `org-log-repeat' is nil.
  7219. (should
  7220. (string-match-p
  7221. "SCHEDULED: <2014-03-29"
  7222. (let ((org-log-repeat nil)
  7223. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7224. (org-test-with-temp-text
  7225. "* TODO H
  7226. SCHEDULED: <2012-03-29 Thu +2y>
  7227. CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] => 6:40"
  7228. (org-todo "DONE")
  7229. (buffer-string)))))
  7230. ;; Make sure that logbook state change record does not get
  7231. ;; duplicated when `org-log-repeat' `org-log-done' are non-nil.
  7232. (should
  7233. (string-match-p
  7234. (rx "* TODO Read book
  7235. SCHEDULED: <2021-06-16 Wed +1d>
  7236. :PROPERTIES:
  7237. :LAST_REPEAT:" (1+ nonl) "
  7238. :END:
  7239. - State \"DONE\" from \"TODO\"" (1+ nonl) buffer-end)
  7240. (let ((org-log-repeat 'time)
  7241. (org-todo-keywords '((sequence "TODO" "|" "DONE(d!)")))
  7242. (org-log-into-drawer nil))
  7243. (org-test-with-temp-text
  7244. "* TODO Read book
  7245. SCHEDULED: <2021-06-15 Tue +1d>"
  7246. (org-todo "DONE")
  7247. (when (memq 'org-add-log-note post-command-hook)
  7248. (org-add-log-note))
  7249. (buffer-string))))))
  7250. (ert-deftest test-org/org-log-done ()
  7251. "Test `org-log-done' specifications."
  7252. ;; nil value.
  7253. (should
  7254. (string=
  7255. "* DONE task"
  7256. (let ((org-log-done nil)
  7257. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7258. (org-test-with-temp-text
  7259. "* TODO task"
  7260. (org-todo "DONE")
  7261. (when (memq 'org-add-log-note post-command-hook)
  7262. (org-add-log-note))
  7263. (buffer-string)))))
  7264. ;; `time' value.
  7265. (should
  7266. (string=
  7267. (format
  7268. "* DONE task
  7269. CLOSED: %s"
  7270. (org-test-with-temp-text ""
  7271. (org-insert-time-stamp (current-time) t t)
  7272. (buffer-string)))
  7273. (let ((org-log-done 'time)
  7274. (org-log-done-with-time t)
  7275. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7276. (org-test-with-temp-text
  7277. "* TODO task"
  7278. (org-todo "DONE")
  7279. (when (memq 'org-add-log-note post-command-hook)
  7280. (org-add-log-note))
  7281. (buffer-string)))))
  7282. (should
  7283. (string=
  7284. (format
  7285. "* DONE task
  7286. CLOSED: %s"
  7287. (org-test-with-temp-text ""
  7288. (org-insert-time-stamp (current-time) nil t)
  7289. (buffer-string)))
  7290. (let ((org-log-done 'time)
  7291. (org-log-done-with-time nil)
  7292. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7293. (org-test-with-temp-text
  7294. "* TODO task"
  7295. (org-todo "DONE")
  7296. (when (memq 'org-add-log-note post-command-hook)
  7297. (org-add-log-note))
  7298. (buffer-string)))))
  7299. ;; TODO: Test `note' value.
  7300. ;; Test startup overrides.
  7301. (should
  7302. (string=
  7303. "#+STARTUP: nologdone
  7304. * DONE task"
  7305. (let ((org-log-done 'time)
  7306. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7307. (org-test-with-temp-text
  7308. "#+STARTUP: nologdone
  7309. <point>* TODO task"
  7310. (org-set-regexps-and-options)
  7311. (org-todo "DONE")
  7312. (when (memq 'org-add-log-note post-command-hook)
  7313. (org-add-log-note))
  7314. (buffer-string)))))
  7315. (should
  7316. (string=
  7317. (format
  7318. "#+STARTUP: logdone
  7319. * DONE task
  7320. CLOSED: %s"
  7321. (org-test-with-temp-text ""
  7322. (org-insert-time-stamp (current-time) t t)
  7323. (buffer-string)))
  7324. (let ((org-log-done nil)
  7325. (org-log-done-with-time t)
  7326. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7327. (org-test-with-temp-text
  7328. "#+STARTUP: logdone
  7329. <point>* TODO task"
  7330. (org-set-regexps-and-options)
  7331. (org-todo "DONE")
  7332. (when (memq 'org-add-log-note post-command-hook)
  7333. (org-add-log-note))
  7334. (buffer-string)))))
  7335. ;; Test local property overrides.
  7336. (should
  7337. (string=
  7338. "* DONE task
  7339. :PROPERTIES:
  7340. :LOGGING: nil
  7341. :END:"
  7342. (let ((org-log-done 'time)
  7343. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7344. (org-test-with-temp-text
  7345. "* TODO task
  7346. :PROPERTIES:
  7347. :LOGGING: nil
  7348. :END:"
  7349. (org-todo "DONE")
  7350. (when (memq 'org-add-log-note post-command-hook)
  7351. (org-add-log-note))
  7352. (buffer-string)))))
  7353. (should
  7354. (string=
  7355. (format
  7356. "* DONE task
  7357. CLOSED: %s
  7358. :PROPERTIES:
  7359. :LOGGING: logdone
  7360. :END:"
  7361. (org-test-with-temp-text ""
  7362. (org-insert-time-stamp (current-time) t t)
  7363. (buffer-string)))
  7364. (let ((org-log-done nil)
  7365. (org-log-done-with-time t)
  7366. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7367. (org-test-with-temp-text
  7368. "* TODO task
  7369. :PROPERTIES:
  7370. :LOGGING: logdone
  7371. :END:"
  7372. (org-todo "DONE")
  7373. (when (memq 'org-add-log-note post-command-hook)
  7374. (org-add-log-note))
  7375. (buffer-string))))))
  7376. ;;; Timestamps API
  7377. (ert-deftest test-org/at-timestamp-p ()
  7378. "Test `org-at-timestamp-p' specifications."
  7379. (should
  7380. (org-test-with-temp-text "<2012-03-29 Thu>"
  7381. (org-at-timestamp-p)))
  7382. (should-not
  7383. (org-test-with-temp-text "2012-03-29 Thu"
  7384. (org-at-timestamp-p)))
  7385. ;; Test return values.
  7386. (should
  7387. (eq 'bracket
  7388. (org-test-with-temp-text "<2012-03-29 Thu>"
  7389. (org-at-timestamp-p))))
  7390. (should
  7391. (eq 'year
  7392. (org-test-with-temp-text "<<point>2012-03-29 Thu>"
  7393. (org-at-timestamp-p))))
  7394. (should
  7395. (eq 'month
  7396. (org-test-with-temp-text "<2012-<point>03-29 Thu>"
  7397. (org-at-timestamp-p))))
  7398. (should
  7399. (eq 'day
  7400. (org-test-with-temp-text "<2012-03-<point>29 Thu>"
  7401. (org-at-timestamp-p))))
  7402. (should
  7403. (eq 'day
  7404. (org-test-with-temp-text "<2012-03-29 T<point>hu>"
  7405. (org-at-timestamp-p))))
  7406. (should
  7407. (wholenump
  7408. (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
  7409. (org-at-timestamp-p))))
  7410. (should
  7411. (eq 'bracket
  7412. (org-test-with-temp-text "<2012-03-29 Thu<point>>"
  7413. (org-at-timestamp-p))))
  7414. (should
  7415. (eq 'after
  7416. (org-test-with-temp-text "<2012-03-29 Thu><point>»"
  7417. (org-at-timestamp-p))))
  7418. ;; Test `inactive' optional argument.
  7419. (should
  7420. (org-test-with-temp-text "[2012-03-29 Thu]"
  7421. (org-at-timestamp-p 'inactive)))
  7422. (should-not
  7423. (org-test-with-temp-text "[2012-03-29 Thu]"
  7424. (org-at-timestamp-p)))
  7425. ;; When optional argument is `agenda', recognize time-stamps in
  7426. ;; planning info line, property drawers and clocks.
  7427. (should
  7428. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7429. (org-at-timestamp-p 'agenda)))
  7430. (should-not
  7431. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7432. (org-at-timestamp-p)))
  7433. (should
  7434. (org-test-with-temp-text
  7435. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7436. (org-at-timestamp-p 'agenda)))
  7437. (should-not
  7438. (org-test-with-temp-text
  7439. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7440. (org-at-timestamp-p)))
  7441. (should
  7442. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7443. (let ((org-agenda-include-inactive-timestamps t))
  7444. (org-at-timestamp-p 'agenda))))
  7445. (should-not
  7446. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7447. (let ((org-agenda-include-inactive-timestamps t))
  7448. (org-at-timestamp-p))))
  7449. (should-not
  7450. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7451. (let ((org-agenda-include-inactive-timestamps t))
  7452. (org-at-timestamp-p 'inactive))))
  7453. ;; When optional argument is `lax', match any part of the document
  7454. ;; with Org timestamp syntax.
  7455. (should
  7456. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7457. (org-at-timestamp-p 'lax)))
  7458. (should-not
  7459. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7460. (org-at-timestamp-p)))
  7461. (should
  7462. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7463. (org-at-timestamp-p 'lax)))
  7464. (should-not
  7465. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7466. (org-at-timestamp-p)))
  7467. (should
  7468. (org-test-with-temp-text
  7469. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7470. (org-at-timestamp-p 'lax)))
  7471. (should-not
  7472. (org-test-with-temp-text
  7473. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7474. (org-at-timestamp-p)))
  7475. ;; Optional argument `lax' also matches inactive timestamps.
  7476. (should
  7477. (org-test-with-temp-text "# [2012-03-29 Thu]<point>"
  7478. (org-at-timestamp-p 'lax))))
  7479. (ert-deftest test-org/time-stamp ()
  7480. "Test `org-time-stamp' specifications."
  7481. ;; Insert chosen time stamp at point.
  7482. (should
  7483. (string-match
  7484. "Te<2014-03-04 .*?>xt"
  7485. (org-test-with-temp-text "Te<point>xt"
  7486. (cl-letf (((symbol-function 'org-read-date)
  7487. (lambda (&rest args)
  7488. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7489. (org-time-stamp nil)
  7490. (buffer-string)))))
  7491. ;; With a prefix argument, also insert time.
  7492. (should
  7493. (string-match
  7494. "Te<2014-03-04 .*? 00:41>xt"
  7495. (org-test-with-temp-text "Te<point>xt"
  7496. (cl-letf (((symbol-function 'org-read-date)
  7497. (lambda (&rest args)
  7498. (apply #'encode-time
  7499. (org-parse-time-string "2014-03-04 00:41")))))
  7500. (org-time-stamp '(4))
  7501. (buffer-string)))))
  7502. ;; With two universal prefix arguments, insert an active timestamp
  7503. ;; with the current time without prompting the user.
  7504. (should
  7505. (string-match
  7506. "Te<2014-03-04 .*? 00:41>xt"
  7507. (org-test-with-temp-text "Te<point>xt"
  7508. (org-test-at-time "2014-03-04 00:41"
  7509. (org-time-stamp '(16))
  7510. (buffer-string)))))
  7511. ;; When optional argument is non-nil, insert an inactive timestamp.
  7512. (should
  7513. (string-match
  7514. "Te\\[2014-03-04 .*?\\]xt"
  7515. (org-test-with-temp-text "Te<point>xt"
  7516. (cl-letf (((symbol-function 'org-read-date)
  7517. (lambda (&rest args)
  7518. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7519. (org-time-stamp nil t)
  7520. (buffer-string)))))
  7521. ;; When called from a timestamp, replace existing one.
  7522. (should
  7523. (string-match
  7524. "<2014-03-04 .*?>"
  7525. (org-test-with-temp-text "<2012-03-29<point> thu.>"
  7526. (cl-letf (((symbol-function 'org-read-date)
  7527. (lambda (&rest args)
  7528. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7529. (org-time-stamp nil)
  7530. (buffer-string)))))
  7531. (should
  7532. (string-match
  7533. "<2014-03-04 .*?>--<2014-03-04 .*?>"
  7534. (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
  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. ;; When replacing a timestamp, preserve repeater, if any.
  7541. (should
  7542. (string-match
  7543. "<2014-03-04 .*? \\+2y>"
  7544. (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
  7545. (cl-letf (((symbol-function 'org-read-date)
  7546. (lambda (&rest args)
  7547. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7548. (org-time-stamp nil)
  7549. (buffer-string)))))
  7550. ;; When called twice in a raw, build a date range.
  7551. (should
  7552. (string-match
  7553. "<2012-03-29 .*?>--<2014-03-04 .*?>"
  7554. (org-test-with-temp-text "<2012-03-29 thu.><point>"
  7555. (cl-letf (((symbol-function 'org-read-date)
  7556. (lambda (&rest args)
  7557. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7558. (let ((last-command 'org-time-stamp)
  7559. (this-command 'org-time-stamp))
  7560. (org-time-stamp nil))
  7561. (buffer-string))))))
  7562. (ert-deftest test-org/timestamp-has-time-p ()
  7563. "Test `org-timestamp-has-time-p' specifications."
  7564. ;; With time.
  7565. (should
  7566. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7567. (org-timestamp-has-time-p (org-element-context))))
  7568. ;; Without time.
  7569. (should-not
  7570. (org-test-with-temp-text "<2012-03-29 Thu>"
  7571. (org-timestamp-has-time-p (org-element-context)))))
  7572. (ert-deftest test-org/get-repeat ()
  7573. "Test `org-get-repeat' specifications."
  7574. (should
  7575. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
  7576. (org-get-repeat)))
  7577. (should-not
  7578. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
  7579. (org-get-repeat)))
  7580. ;; Return proper repeat string.
  7581. (should
  7582. (equal "+2y"
  7583. (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
  7584. (org-get-repeat))))
  7585. ;; Prevent false positive (commented or verbatim time stamps)
  7586. (should-not
  7587. (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
  7588. (org-get-repeat)))
  7589. (should-not
  7590. (org-test-with-temp-text
  7591. "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
  7592. (org-get-repeat)))
  7593. ;; Return nil when called before first heading.
  7594. (should-not
  7595. (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
  7596. (org-get-repeat)))
  7597. ;; When called with an optional argument, extract repeater from that
  7598. ;; string instead.
  7599. (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
  7600. (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
  7601. (ert-deftest test-org/timestamp-format ()
  7602. "Test `org-timestamp-format' specifications."
  7603. ;; Regular test.
  7604. (should
  7605. (equal
  7606. "2012-03-29 16:40"
  7607. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7608. (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
  7609. ;; Range end.
  7610. (should
  7611. (equal
  7612. "2012-03-29"
  7613. (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
  7614. (org-timestamp-format (org-element-context) "%Y-%m-%d" t)))))
  7615. (ert-deftest test-org/timestamp-split-range ()
  7616. "Test `org-timestamp-split-range' specifications."
  7617. ;; Extract range start (active).
  7618. (should
  7619. (equal '(2012 3 29)
  7620. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7621. (let ((ts (org-timestamp-split-range (org-element-context))))
  7622. (mapcar (lambda (p) (org-element-property p ts))
  7623. '(:year-end :month-end :day-end))))))
  7624. ;; Extract range start (inactive)
  7625. (should
  7626. (equal '(2012 3 29)
  7627. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7628. (let ((ts (org-timestamp-split-range (org-element-context))))
  7629. (mapcar (lambda (p) (org-element-property p ts))
  7630. '(:year-end :month-end :day-end))))))
  7631. ;; Extract range end (active).
  7632. (should
  7633. (equal '(2012 3 30)
  7634. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7635. (let ((ts (org-timestamp-split-range
  7636. (org-element-context) t)))
  7637. (mapcar (lambda (p) (org-element-property p ts))
  7638. '(:year-end :month-end :day-end))))))
  7639. ;; Extract range end (inactive)
  7640. (should
  7641. (equal '(2012 3 30)
  7642. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7643. (let ((ts (org-timestamp-split-range
  7644. (org-element-context) t)))
  7645. (mapcar (lambda (p) (org-element-property p ts))
  7646. '(:year-end :month-end :day-end))))))
  7647. ;; Return the timestamp if not a range.
  7648. (should
  7649. (org-test-with-temp-text "[2012-03-29 Thu]"
  7650. (let* ((ts-orig (org-element-context))
  7651. (ts-copy (org-timestamp-split-range ts-orig)))
  7652. (eq ts-orig ts-copy))))
  7653. (should
  7654. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7655. (let* ((ts-orig (org-element-context))
  7656. (ts-copy (org-timestamp-split-range ts-orig)))
  7657. (eq ts-orig ts-copy)))))
  7658. (ert-deftest test-org/timestamp-translate ()
  7659. "Test `org-timestamp-translate' specifications."
  7660. ;; Translate whole date range.
  7661. (should
  7662. (equal "<29>--<30>"
  7663. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7664. (let ((org-display-custom-times t)
  7665. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7666. (org-timestamp-translate (org-element-context))))))
  7667. ;; Translate date range start.
  7668. (should
  7669. (equal "<29>"
  7670. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7671. (let ((org-display-custom-times t)
  7672. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7673. (org-timestamp-translate (org-element-context) 'start)))))
  7674. ;; Translate date range end.
  7675. (should
  7676. (equal "<30>"
  7677. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7678. (let ((org-display-custom-times t)
  7679. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7680. (org-timestamp-translate (org-element-context) 'end)))))
  7681. ;; Translate time range.
  7682. (should
  7683. (equal "<08>--<16>"
  7684. (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
  7685. (let ((org-display-custom-times t)
  7686. (org-time-stamp-custom-formats '("<%d>" . "<%H>")))
  7687. (org-timestamp-translate (org-element-context))))))
  7688. ;; Translate non-range timestamp.
  7689. (should
  7690. (equal "<29>"
  7691. (org-test-with-temp-text "<2012-03-29 Thu>"
  7692. (let ((org-display-custom-times t)
  7693. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7694. (org-timestamp-translate (org-element-context))))))
  7695. ;; Do not change `diary' timestamps.
  7696. (should
  7697. (equal "<%%(org-float t 4 2)>"
  7698. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7699. (let ((org-display-custom-times t)
  7700. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7701. (org-timestamp-translate (org-element-context)))))))
  7702. (ert-deftest test-org/timestamp-from-string ()
  7703. "Test `org-timestamp-from-string' specifications."
  7704. ;; Return nil if argument is not a valid Org timestamp.
  7705. (should-not (org-timestamp-from-string ""))
  7706. (should-not (org-timestamp-from-string nil))
  7707. (should-not (org-timestamp-from-string "<2012-03-29"))
  7708. ;; Otherwise, return a valid Org timestamp object.
  7709. (should
  7710. (string-match-p "<2012-03-29 .+>"
  7711. (org-element-interpret-data
  7712. (org-timestamp-from-string "<2012-03-29 Thu>"))))
  7713. (should
  7714. (string-match-p "[2014-03-04 .+]"
  7715. (org-element-interpret-data
  7716. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  7717. (ert-deftest test-org/timestamp-from-time ()
  7718. "Test `org-timestamp-from-time' specifications."
  7719. ;; Standard test.
  7720. (should
  7721. (string-match-p
  7722. "<2012-03-29 .+>"
  7723. (org-element-interpret-data
  7724. (org-timestamp-from-time
  7725. (apply #'encode-time
  7726. (org-parse-time-string "<2012-03-29 Thu 16:40>"))))))
  7727. ;; When optional argument WITH-TIME is non-nil, provide time
  7728. ;; information.
  7729. (should
  7730. (string-match-p
  7731. "<2012-03-29 .+ 16:40>"
  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. t))))
  7737. ;; When optional argument INACTIVE is non-nil, return an inactive
  7738. ;; timestamp.
  7739. (should
  7740. (string-match-p
  7741. "[2012-03-29 .+]"
  7742. (org-element-interpret-data
  7743. (org-timestamp-from-time
  7744. (apply #'encode-time
  7745. (org-parse-time-string "<2012-03-29 Thu 16:40>"))
  7746. nil t)))))
  7747. (ert-deftest test-org/timestamp-to-time ()
  7748. "Test `org-timestamp-to-time' specifications."
  7749. (should
  7750. (equal "2014-03-04"
  7751. (format-time-string
  7752. "%Y-%m-%d"
  7753. (org-timestamp-to-time
  7754. (org-timestamp-from-string "<2014-03-04 Tue>")))))
  7755. (should
  7756. (equal "2014-03-04"
  7757. (format-time-string
  7758. "%Y-%m-%d"
  7759. (org-timestamp-to-time
  7760. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  7761. (should
  7762. (equal "2012-03-29 08:30"
  7763. (format-time-string
  7764. "%Y-%m-%d %H:%M"
  7765. (org-timestamp-to-time
  7766. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")))))
  7767. (should
  7768. (equal "2012-03-29"
  7769. (format-time-string
  7770. "%Y-%m-%d"
  7771. (org-timestamp-to-time
  7772. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")))))
  7773. (should
  7774. (equal "2012-03-29"
  7775. (format-time-string
  7776. "%Y-%m-%d"
  7777. (org-timestamp-to-time
  7778. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")))))
  7779. ;; When optional argument END is non-nil, use end of date range or
  7780. ;; time range.
  7781. (should
  7782. (equal "2012-03-29 16:40"
  7783. (format-time-string
  7784. "%Y-%m-%d %H:%M"
  7785. (org-timestamp-to-time
  7786. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")
  7787. t))))
  7788. (should
  7789. (equal "2014-03-04"
  7790. (format-time-string
  7791. "%Y-%m-%d"
  7792. (org-timestamp-to-time
  7793. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")
  7794. t))))
  7795. (should
  7796. (equal "2014-03-04"
  7797. (format-time-string
  7798. "%Y-%m-%d"
  7799. (org-timestamp-to-time
  7800. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")
  7801. t)))))
  7802. ;;; Visibility
  7803. (ert-deftest test-org/hide-drawer-toggle ()
  7804. "Test `org-hide-drawer-toggle' specifications."
  7805. ;; Error when not at a drawer.
  7806. (should-error
  7807. (org-test-with-temp-text ":fake-drawer:\ncontents"
  7808. (org-hide-drawer-toggle 'off)
  7809. (get-char-property (line-end-position) 'invisible)))
  7810. (should-error
  7811. (org-test-with-temp-text
  7812. "#+begin_example\n<point>:D:\nc\n:END:\n#+end_example"
  7813. (org-hide-drawer-toggle t)))
  7814. ;; Hide drawer.
  7815. (should
  7816. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7817. (org-hide-drawer-toggle)
  7818. (get-char-property (line-end-position) 'invisible)))
  7819. ;; Show drawer unconditionally when optional argument is `off'.
  7820. (should-not
  7821. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7822. (org-hide-drawer-toggle)
  7823. (org-hide-drawer-toggle 'off)
  7824. (get-char-property (line-end-position) 'invisible)))
  7825. ;; Hide drawer unconditionally when optional argument is non-nil.
  7826. (should
  7827. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7828. (org-hide-drawer-toggle t)
  7829. (get-char-property (line-end-position) 'invisible)))
  7830. ;; Do not hide drawer when called from final blank lines.
  7831. (should-not
  7832. (org-test-with-temp-text ":drawer:\ncontents\n:end:\n\n<point>"
  7833. (org-hide-drawer-toggle)
  7834. (goto-char (point-min))
  7835. (get-char-property (line-end-position) 'invisible)))
  7836. ;; Don't leave point in an invisible part of the buffer when hiding
  7837. ;; a drawer away.
  7838. (should-not
  7839. (org-test-with-temp-text ":drawer:\ncontents\n<point>:end:"
  7840. (org-hide-drawer-toggle)
  7841. (get-char-property (point) 'invisible))))
  7842. (ert-deftest test-org/hide-block-toggle ()
  7843. "Test `org-hide-block-toggle' specifications."
  7844. ;; Error when not at a block.
  7845. (should-error
  7846. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
  7847. (org-hide-block-toggle 'off)
  7848. (get-char-property (line-end-position) 'invisible)))
  7849. ;; Hide block.
  7850. (should
  7851. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  7852. (org-hide-block-toggle)
  7853. (get-char-property (line-end-position) 'invisible)))
  7854. (should
  7855. (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
  7856. (org-hide-block-toggle)
  7857. (get-char-property (line-end-position) 'invisible)))
  7858. ;; Show block unconditionally when optional argument is `off'.
  7859. (should-not
  7860. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7861. (org-hide-block-toggle)
  7862. (org-hide-block-toggle 'off)
  7863. (get-char-property (line-end-position) 'invisible)))
  7864. (should-not
  7865. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7866. (org-hide-block-toggle 'off)
  7867. (get-char-property (line-end-position) 'invisible)))
  7868. ;; Hide block unconditionally when optional argument is non-nil.
  7869. (should
  7870. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7871. (org-hide-block-toggle t)
  7872. (get-char-property (line-end-position) 'invisible)))
  7873. (should
  7874. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7875. (org-hide-block-toggle)
  7876. (org-hide-block-toggle t)
  7877. (get-char-property (line-end-position) 'invisible)))
  7878. ;; Do not hide block when called from final blank lines.
  7879. (should-not
  7880. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
  7881. (org-hide-block-toggle)
  7882. (goto-char (point-min))
  7883. (get-char-property (line-end-position) 'invisible)))
  7884. ;; Don't leave point in an invisible part of the buffer when hiding
  7885. ;; a block away.
  7886. (should-not
  7887. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
  7888. (org-hide-block-toggle)
  7889. (get-char-property (point) 'invisible))))
  7890. (ert-deftest test-org/hide-block-toggle-maybe ()
  7891. "Test `org-hide-block-toggle-maybe' specifications."
  7892. (should
  7893. (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
  7894. (org-hide-block-toggle-maybe)))
  7895. (should-not
  7896. (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
  7897. (ert-deftest test-org/show-set-visibility ()
  7898. "Test `org-show-set-visibility' specifications."
  7899. ;; Do not throw an error before first heading.
  7900. (should
  7901. (org-test-with-temp-text "Preamble\n* Headline"
  7902. (org-show-set-visibility 'tree)
  7903. t))
  7904. ;; Test all visibility spans, both on headline and in entry.
  7905. (let ((list-visible-lines
  7906. (lambda (state headerp)
  7907. (org-test-with-temp-text "* Grandmother (0)
  7908. ** Uncle (1)
  7909. *** Heir (2)
  7910. ** Father (3)
  7911. Ancestor text (4)
  7912. *** Sister (5)
  7913. Sibling text (6)
  7914. *** Self (7)
  7915. Match (8)
  7916. **** First born (9)
  7917. Child text (10)
  7918. **** The other child (11)
  7919. *** Brother (12)
  7920. ** Aunt (13)
  7921. "
  7922. (org-cycle t)
  7923. (search-forward (if headerp "Self" "Match"))
  7924. (org-show-set-visibility state)
  7925. (goto-char (point-min))
  7926. (let (result (line 0))
  7927. (while (not (eobp))
  7928. (unless (org-invisible-p2) (push line result))
  7929. (cl-incf line)
  7930. (forward-line))
  7931. (nreverse result))))))
  7932. (should (equal '(0 7) (funcall list-visible-lines 'minimal t)))
  7933. (should (equal '(0 7 8) (funcall list-visible-lines 'minimal nil)))
  7934. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local t)))
  7935. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local nil)))
  7936. (should (equal '(0 3 7) (funcall list-visible-lines 'ancestors t)))
  7937. (should (equal '(0 3 7 8) (funcall list-visible-lines 'ancestors nil)))
  7938. (should (equal '(0 3 7 8 9 10 11)
  7939. (funcall list-visible-lines 'ancestors-full t)))
  7940. (should (equal '(0 3 7 8 9 10 11)
  7941. (funcall list-visible-lines 'ancestors-full nil)))
  7942. (should (equal '(0 3 5 7 12) (funcall list-visible-lines 'lineage t)))
  7943. (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines 'lineage nil)))
  7944. (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines 'tree t)))
  7945. (should (equal '(0 1 3 5 7 8 9 11 12 13)
  7946. (funcall list-visible-lines 'tree nil)))
  7947. (should (equal '(0 1 3 4 5 7 12 13)
  7948. (funcall list-visible-lines 'canonical t)))
  7949. (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
  7950. (funcall list-visible-lines 'canonical nil))))
  7951. ;; When point is hidden in a drawer or a block, make sure to make it
  7952. ;; visible.
  7953. (should-not
  7954. (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
  7955. (org-hide-block-toggle)
  7956. (search-forward "Text")
  7957. (org-show-set-visibility 'minimal)
  7958. (org-invisible-p2)))
  7959. (should-not
  7960. (org-test-with-temp-text ":DRAWER:\nText\n:END:"
  7961. (org-hide-drawer-toggle)
  7962. (search-forward "Text")
  7963. (org-show-set-visibility 'minimal)
  7964. (org-invisible-p2)))
  7965. (should-not
  7966. (org-test-with-temp-text
  7967. "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
  7968. (org-hide-drawer-toggle)
  7969. (forward-line -1)
  7970. (org-hide-block-toggle)
  7971. (search-forward "Text")
  7972. (org-show-set-visibility 'minimal)
  7973. (org-invisible-p2))))
  7974. (defun test-org/copy-visible ()
  7975. "Test `org-copy-visible' specifications."
  7976. (should
  7977. (equal "Foo"
  7978. (org-test-with-temp-text "Foo"
  7979. (let ((kill-ring nil))
  7980. (org-copy-visible (point-min) (point-max))
  7981. (current-kill 0 t)))))
  7982. ;; Skip invisible characters by text property.
  7983. (should
  7984. (equal "Foo"
  7985. (org-test-with-temp-text #("F<hidden>oo" 1 7 (invisible t))
  7986. (let ((kill-ring nil))
  7987. (org-copy-visible (point-min) (point-max))
  7988. (current-kill 0 t)))))
  7989. ;; Skip invisible characters by overlay.
  7990. (should
  7991. (equal "Foo"
  7992. (org-test-with-temp-text "F<hidden>oo"
  7993. (let ((o (make-overlay 2 10)))
  7994. (overlay-put o 'invisible t))
  7995. (let ((kill-ring nil))
  7996. (org-copy-visible (point-min) (point-max))
  7997. (current-kill 0 t)))))
  7998. ;; Handle invisible characters at the beginning and the end of the
  7999. ;; buffer.
  8000. (should
  8001. (equal "Foo"
  8002. (org-test-with-temp-text #("<hidden>Foo" 0 8 (invisible t))
  8003. (let ((kill-ring nil))
  8004. (org-copy-visible (point-min) (point-max))
  8005. (current-kill 0 t)))))
  8006. (should
  8007. (equal "Foo"
  8008. (org-test-with-temp-text #("Foo<hidden>" 3 11 (invisible t))
  8009. (let ((kill-ring nil))
  8010. (org-copy-visible (point-min) (point-max))
  8011. (current-kill 0 t)))))
  8012. ;; Handle multiple visible parts.
  8013. (should
  8014. (equal "abc"
  8015. (org-test-with-temp-text
  8016. #("aXbXc" 1 2 (invisible t) 3 4 (invisible t))
  8017. (let ((kill-ring nil))
  8018. (org-copy-visible (point-min) (point-max))
  8019. (current-kill 0 t))))))
  8020. (ert-deftest test-org/set-visibility-according-to-property ()
  8021. "Test `org-set-visibility-according-to-property' specifications."
  8022. ;; "folded" state.
  8023. (should
  8024. (org-test-with-temp-text
  8025. "
  8026. * a
  8027. :PROPERTIES:
  8028. :VISIBILITY: folded
  8029. :END:
  8030. ** <point>b"
  8031. (org-set-visibility-according-to-property)
  8032. (invisible-p (point))))
  8033. ;; "children" state.
  8034. (should
  8035. (org-test-with-temp-text
  8036. "
  8037. * a
  8038. :PROPERTIES:
  8039. :VISIBILITY: children
  8040. :END:
  8041. ** b
  8042. <point>Contents
  8043. ** c"
  8044. (org-set-visibility-according-to-property)
  8045. (invisible-p (point))))
  8046. (should
  8047. (org-test-with-temp-text
  8048. "
  8049. * a
  8050. :PROPERTIES:
  8051. :VISIBILITY: children
  8052. :END:
  8053. ** b
  8054. Contents
  8055. *** <point>c"
  8056. (org-set-visibility-according-to-property)
  8057. (invisible-p (point))))
  8058. ;; "content" state.
  8059. (should
  8060. (org-test-with-temp-text
  8061. "
  8062. * a
  8063. :PROPERTIES:
  8064. :VISIBILITY: content
  8065. :END:
  8066. ** b
  8067. <point>Contents
  8068. *** c"
  8069. (org-set-visibility-according-to-property)
  8070. (invisible-p (point))))
  8071. (should
  8072. (org-test-with-temp-text
  8073. "
  8074. * a
  8075. :PROPERTIES:
  8076. :VISIBILITY: content
  8077. :END:
  8078. ** b
  8079. Contents
  8080. *** <point>c"
  8081. (org-set-visibility-according-to-property)
  8082. (not (invisible-p (point)))))
  8083. ;; "showall" state.
  8084. (should
  8085. (org-test-with-temp-text
  8086. "
  8087. * a
  8088. :PROPERTIES:
  8089. :VISIBILITY: showall
  8090. :END:
  8091. ** b
  8092. <point>Contents
  8093. *** c"
  8094. (org-set-visibility-according-to-property)
  8095. (not (invisible-p (point)))))
  8096. (should
  8097. (org-test-with-temp-text
  8098. "
  8099. * a
  8100. :PROPERTIES:
  8101. :VISIBILITY: showall
  8102. :END:
  8103. ** b
  8104. Contents
  8105. *** <point>c"
  8106. (org-set-visibility-according-to-property)
  8107. (not (invisible-p (point)))))
  8108. ;; When VISIBILITY properties are nested, ignore inner ones.
  8109. (should
  8110. (org-test-with-temp-text
  8111. "
  8112. * A
  8113. :PROPERTIES:
  8114. :VISIBILITY: folded
  8115. :END:
  8116. ** <point>B
  8117. :PROPERTIES:
  8118. :VISIBILITY: folded
  8119. :END:"
  8120. (org-set-visibility-according-to-property)
  8121. (invisible-p (point)))))
  8122. (ert-deftest test-org/visibility-show-branches ()
  8123. "Test visibility of inline archived subtrees."
  8124. (org-test-with-temp-text
  8125. "* Foo<point>
  8126. ** Bar :ARCHIVE:
  8127. *** Baz
  8128. "
  8129. (org-kill-note-or-show-branches)
  8130. (should (org-invisible-p (- (point-max) 2)))))
  8131. ;;; Yank and Kill
  8132. (ert-deftest test-org/paste-subtree ()
  8133. "Test `org-paste-subtree' specifications."
  8134. ;; Return an error if text to yank is not a set of subtrees.
  8135. (should-error (org-paste-subtree nil "Text"))
  8136. ;; Adjust level according to current one.
  8137. (should
  8138. (equal "* H\n* Text\n"
  8139. (org-test-with-temp-text "* H\n<point>"
  8140. (org-paste-subtree nil "* Text")
  8141. (buffer-string))))
  8142. (should
  8143. (equal "* H1\n** H2\n** Text\n"
  8144. (org-test-with-temp-text "* H1\n** H2\n<point>"
  8145. (org-paste-subtree nil "* Text")
  8146. (buffer-string))))
  8147. ;; When not on a heading, move to next heading before yanking.
  8148. (should
  8149. (equal "* H1\nParagraph\n* Text\n* H2"
  8150. (org-test-with-temp-text "* H1\n<point>Paragraph\n* H2"
  8151. (org-paste-subtree nil "* Text")
  8152. (buffer-string))))
  8153. ;; If point is between two headings, use the deepest level.
  8154. (should
  8155. (equal "* H1\n\n* Text\n* H2"
  8156. (org-test-with-temp-text "* H1\n<point>\n* H2"
  8157. (org-paste-subtree nil "* Text")
  8158. (buffer-string))))
  8159. (should
  8160. (equal "** H1\n\n** Text\n* H2"
  8161. (org-test-with-temp-text "** H1\n<point>\n* H2"
  8162. (org-paste-subtree nil "* Text")
  8163. (buffer-string))))
  8164. (should
  8165. (equal "* H1\n\n** Text\n** H2"
  8166. (org-test-with-temp-text "* H1\n<point>\n** H2"
  8167. (org-paste-subtree nil "* Text")
  8168. (buffer-string))))
  8169. ;; When on an empty heading, after the stars, deduce the new level
  8170. ;; from the number of stars.
  8171. (should
  8172. (equal "*** Text\n"
  8173. (org-test-with-temp-text "*** <point>"
  8174. (org-paste-subtree nil "* Text")
  8175. (buffer-string))))
  8176. ;; Optional argument LEVEL forces a level for the subtree.
  8177. (should
  8178. (equal "* H\n*** Text\n"
  8179. (org-test-with-temp-text "* H<point>"
  8180. (org-paste-subtree 3 "* Text")
  8181. (buffer-string)))))
  8182. (ert-deftest test-org/cut-and-paste-subtree ()
  8183. "Test `org-cut-subtree' and `org-paste-subtree'."
  8184. (should
  8185. (equal
  8186. "* Two
  8187. two
  8188. * One
  8189. "
  8190. (org-test-with-temp-text
  8191. "* One
  8192. <point>* Two
  8193. two
  8194. "
  8195. (call-interactively #'org-cut-subtree)
  8196. (goto-char (point-min))
  8197. (call-interactively #'org-paste-subtree)
  8198. (buffer-string))))
  8199. (should
  8200. (equal
  8201. "* One
  8202. * Two
  8203. "
  8204. (org-test-with-temp-text
  8205. "* One
  8206. <point>* Two
  8207. "
  8208. (call-interactively #'org-cut-subtree)
  8209. (backward-char)
  8210. (call-interactively #'org-paste-subtree)
  8211. (buffer-string)))))
  8212. (provide 'test-org)
  8213. ;;; test-org.el ends here