test-org.el 276 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504
  1. ;;; test-org.el --- tests for org.el
  2. ;; Copyright (c) David Maus
  3. ;; Authors: David Maus
  4. ;; This file is not part of GNU Emacs.
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. ;; Template test file for Org tests
  16. ;;; Code:
  17. (eval-and-compile (require 'cl-lib))
  18. ;;; Comments
  19. (ert-deftest test-org/toggle-comment ()
  20. "Test `org-toggle-comment' specifications."
  21. ;; Simple headline.
  22. (should
  23. (equal "* Test"
  24. (org-test-with-temp-text "* COMMENT Test"
  25. (org-toggle-comment)
  26. (buffer-string))))
  27. (should
  28. (equal "* COMMENT Test"
  29. (org-test-with-temp-text "* Test"
  30. (org-toggle-comment)
  31. (buffer-string))))
  32. ;; Headline with a regular keyword.
  33. (should
  34. (equal "* TODO Test"
  35. (org-test-with-temp-text "* TODO COMMENT Test"
  36. (org-toggle-comment)
  37. (buffer-string))))
  38. (should
  39. (equal "* TODO COMMENT Test"
  40. (org-test-with-temp-text "* TODO Test"
  41. (org-toggle-comment)
  42. (buffer-string))))
  43. ;; Empty headline.
  44. (should
  45. (equal "* "
  46. (org-test-with-temp-text "* COMMENT"
  47. (org-toggle-comment)
  48. (buffer-string))))
  49. (should
  50. (equal "* COMMENT"
  51. (org-test-with-temp-text "* "
  52. (org-toggle-comment)
  53. (buffer-string))))
  54. ;; Headline with a single keyword.
  55. (should
  56. (equal "* TODO "
  57. (org-test-with-temp-text "* TODO COMMENT"
  58. (org-toggle-comment)
  59. (buffer-string))))
  60. (should
  61. (equal "* TODO COMMENT"
  62. (org-test-with-temp-text "* TODO"
  63. (org-toggle-comment)
  64. (buffer-string))))
  65. ;; Headline with a keyword, a priority cookie and contents.
  66. (should
  67. (equal "* TODO [#A] Headline"
  68. (org-test-with-temp-text "* TODO [#A] COMMENT Headline"
  69. (org-toggle-comment)
  70. (buffer-string))))
  71. (should
  72. (equal "* TODO [#A] COMMENT Headline"
  73. (org-test-with-temp-text "* TODO [#A] Headline"
  74. (org-toggle-comment)
  75. (buffer-string)))))
  76. (ert-deftest test-org/comment-dwim ()
  77. "Test `comment-dwim' behaviour in an Org buffer."
  78. ;; No region selected, no comment on current line and line not
  79. ;; empty: insert comment on line above.
  80. (should
  81. (equal "# \nComment"
  82. (org-test-with-temp-text "Comment"
  83. (call-interactively #'org-comment-dwim)
  84. (buffer-string))))
  85. ;; No region selected, no comment on current line and line empty:
  86. ;; insert comment on this line.
  87. (should
  88. (equal "# \nParagraph"
  89. (org-test-with-temp-text "\nParagraph"
  90. (call-interactively #'org-comment-dwim)
  91. (buffer-string))))
  92. ;; No region selected, and a comment on this line: indent it.
  93. (should
  94. (equal "* Headline\n # Comment"
  95. (org-test-with-temp-text "* Headline\n# <point>Comment"
  96. (let ((org-adapt-indentation t))
  97. (call-interactively #'org-comment-dwim))
  98. (buffer-string))))
  99. ;; Also recognize single # at column 0 as comments.
  100. (should
  101. (equal "# Comment"
  102. (org-test-with-temp-text "# Comment"
  103. (call-interactively #'org-comment-dwim)
  104. (buffer-string))))
  105. ;; Region selected and only comments and blank lines within it:
  106. ;; un-comment all commented lines.
  107. (should
  108. (equal "Comment 1\n\nComment 2"
  109. (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
  110. (transient-mark-mode 1)
  111. (push-mark (point) t t)
  112. (goto-char (point-max))
  113. (call-interactively #'org-comment-dwim)
  114. (buffer-string))))
  115. ;; Region selected without comments: comment all lines if
  116. ;; `comment-empty-lines' is non-nil, only non-blank lines otherwise.
  117. (should
  118. (equal "# Comment 1\n\n# Comment 2"
  119. (org-test-with-temp-text "Comment 1\n\nComment 2"
  120. (transient-mark-mode 1)
  121. (push-mark (point) t t)
  122. (goto-char (point-max))
  123. (let ((comment-empty-lines nil))
  124. (call-interactively #'org-comment-dwim))
  125. (buffer-string))))
  126. (should
  127. (equal "# Comment 1\n# \n# Comment 2"
  128. (org-test-with-temp-text "Comment 1\n\nComment 2"
  129. (transient-mark-mode 1)
  130. (push-mark (point) t t)
  131. (goto-char (point-max))
  132. (let ((comment-empty-lines t))
  133. (call-interactively #'org-comment-dwim))
  134. (buffer-string))))
  135. ;; In front of a keyword without region, insert a new comment.
  136. (should
  137. (equal "# \n#+KEYWORD: value"
  138. (org-test-with-temp-text "#+KEYWORD: value"
  139. (call-interactively #'org-comment-dwim)
  140. (buffer-string))))
  141. ;; Comment a heading
  142. (should
  143. (equal "* COMMENT Test"
  144. (org-test-with-temp-text "* Test"
  145. (call-interactively #'org-comment-dwim)
  146. (buffer-string))))
  147. ;; In a source block, use appropriate syntax.
  148. (should
  149. (equal " ;; "
  150. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n<point>\n#+END_SRC"
  151. (let ((org-edit-src-content-indentation 2))
  152. (call-interactively #'org-comment-dwim))
  153. (buffer-substring-no-properties (line-beginning-position)
  154. (point)))))
  155. (should
  156. (equal "#+BEGIN_SRC emacs-lisp\n ;; a\n ;; b\n#+END_SRC"
  157. (org-test-with-temp-text
  158. "#+BEGIN_SRC emacs-lisp\n<point>a\nb\n#+END_SRC"
  159. (transient-mark-mode 1)
  160. (push-mark (point) t t)
  161. (forward-line 2)
  162. (let ((org-edit-src-content-indentation 2))
  163. (call-interactively #'org-comment-dwim))
  164. (buffer-string)))))
  165. ;;; Date and time analysis
  166. (ert-deftest test-org/org-read-date ()
  167. "Test `org-read-date' specifications."
  168. ;; Parse ISO date with abbreviated year and month.
  169. (should (equal "2012-03-29 16:40"
  170. (let ((org-time-was-given t))
  171. (org-read-date t nil "12-3-29 16:40"))))
  172. ;; Parse Europeans dates.
  173. (should (equal "2012-03-29 16:40"
  174. (let ((org-time-was-given t))
  175. (org-read-date t nil "29.03.2012 16:40"))))
  176. ;; Parse Europeans dates without year.
  177. (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
  178. (let ((org-time-was-given t))
  179. (org-read-date t nil "29.03. 16:40"))))
  180. ;; Relative date applied to current time if there is single
  181. ;; plus/minus, or to default date when there are two of them.
  182. (should
  183. (equal
  184. "2015-03-04"
  185. (org-test-at-time "2014-03-04"
  186. (org-read-date
  187. t nil "+1y" nil
  188. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))
  189. (should
  190. (equal
  191. "2013-03-29"
  192. (org-test-at-time "2014-03-04"
  193. (org-read-date
  194. t nil "++1y" nil
  195. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))
  196. ;; When `org-read-date-prefer-future' is non-nil, prefer future
  197. ;; dates (relatively to now) when incomplete. Otherwise, use
  198. ;; default date.
  199. (should
  200. (equal
  201. "2014-04-01"
  202. (org-test-at-time "2014-03-04"
  203. (let ((org-read-date-prefer-future t))
  204. (org-read-date t nil "1")))))
  205. (should
  206. (equal
  207. "2013-03-04"
  208. (org-test-at-time "2012-03-29"
  209. (let ((org-read-date-prefer-future t))
  210. (org-read-date t nil "3-4")))))
  211. (should
  212. (equal
  213. "2012-03-04"
  214. (org-test-at-time "2012-03-29"
  215. (let ((org-read-date-prefer-future nil))
  216. (org-read-date t nil "3-4")))))
  217. ;; When set to `org-read-date-prefer-future' is set to `time', read
  218. ;; day is moved to tomorrow if specified hour is before current
  219. ;; time. However, it only happens in no other part of the date is
  220. ;; specified.
  221. (should
  222. (equal
  223. "2012-03-30"
  224. (org-test-at-time "2012-03-29 16:40"
  225. (let ((org-read-date-prefer-future 'time))
  226. (org-read-date t nil "00:40" nil)))))
  227. (should-not
  228. (equal
  229. "2012-03-30"
  230. (org-test-at-time "2012-03-29 16:40"
  231. (let ((org-read-date-prefer-future 'time))
  232. (org-read-date t nil "29 00:40" nil)))))
  233. ;; Caveat: `org-read-date-prefer-future' always refers to current
  234. ;; time, not default time, when they differ.
  235. (should
  236. (equal
  237. "2014-04-01"
  238. (org-test-at-time "2014-03-04"
  239. (let ((org-read-date-prefer-future t))
  240. (org-read-date
  241. t nil "1" nil
  242. (apply #'encode-time (org-parse-time-string "2012-03-29")))))))
  243. (should
  244. (equal
  245. "2014-03-25"
  246. (org-test-at-time "2014-03-04"
  247. (let ((org-read-date-prefer-future t))
  248. (org-read-date
  249. t nil "25" nil
  250. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))))
  251. (ert-deftest test-org/org-parse-time-string ()
  252. "Test `org-parse-time-string'."
  253. (should (equal (org-parse-time-string "2012-03-29 16:40")
  254. '(0 40 16 29 3 2012 nil nil nil)))
  255. (should (equal (org-parse-time-string "[2012-03-29 16:40]")
  256. '(0 40 16 29 3 2012 nil nil nil)))
  257. (should (equal (org-parse-time-string "<2012-03-29 16:40>")
  258. '(0 40 16 29 3 2012 nil nil nil)))
  259. (should (equal (org-parse-time-string "<2012-03-29>")
  260. '(0 0 0 29 3 2012 nil nil nil)))
  261. (should (equal (org-parse-time-string "<2012-03-29>" t)
  262. '(0 nil nil 29 3 2012 nil nil nil))))
  263. (ert-deftest test-org/closest-date ()
  264. "Test `org-closest-date' specifications."
  265. (require 'calendar)
  266. ;; Time stamps without a repeater are returned unchanged.
  267. (should
  268. (equal
  269. '(3 29 2012)
  270. (calendar-gregorian-from-absolute
  271. (org-closest-date "<2012-03-29>" "<2014-03-04>" nil))))
  272. ;; Time stamps with a null repeater are returned unchanged.
  273. (should
  274. (equal
  275. '(3 29 2012)
  276. (calendar-gregorian-from-absolute
  277. (org-closest-date "<2012-03-29 +0d>" "<2014-03-04>" nil))))
  278. ;; if PREFER is set to `past' always return a date before, or equal
  279. ;; to CURRENT.
  280. (should
  281. (equal
  282. '(3 1 2014)
  283. (calendar-gregorian-from-absolute
  284. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'past))))
  285. (should
  286. (equal
  287. '(3 4 2014)
  288. (calendar-gregorian-from-absolute
  289. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'past))))
  290. ;; if PREFER is set to `future' always return a date before, or equal
  291. ;; to CURRENT.
  292. (should
  293. (equal
  294. '(3 29 2014)
  295. (calendar-gregorian-from-absolute
  296. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'future))))
  297. (should
  298. (equal
  299. '(3 4 2014)
  300. (calendar-gregorian-from-absolute
  301. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'future))))
  302. ;; If PREFER is neither `past' nor `future', select closest date.
  303. (should
  304. (equal
  305. '(3 1 2014)
  306. (calendar-gregorian-from-absolute
  307. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" nil))))
  308. (should
  309. (equal
  310. '(5 4 2014)
  311. (calendar-gregorian-from-absolute
  312. (org-closest-date "<2012-03-04 +1m>" "<2014-04-28>" nil))))
  313. ;; Test "day" repeater.
  314. (should
  315. (equal '(3 8 2014)
  316. (calendar-gregorian-from-absolute
  317. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'past))))
  318. (should
  319. (equal '(3 10 2014)
  320. (calendar-gregorian-from-absolute
  321. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'future))))
  322. ;; Test "month" repeater.
  323. (should
  324. (equal '(1 5 2015)
  325. (calendar-gregorian-from-absolute
  326. (org-closest-date "<2014-03-05 +2m>" "<2015-02-04>" 'past))))
  327. (should
  328. (equal '(3 29 2014)
  329. (calendar-gregorian-from-absolute
  330. (org-closest-date "<2012-03-29 +2m>" "<2014-03-04>" 'future))))
  331. ;; Test "year" repeater.
  332. (should
  333. (equal '(3 5 2014)
  334. (calendar-gregorian-from-absolute
  335. (org-closest-date "<2014-03-05 +2y>" "<2015-02-04>" 'past))))
  336. (should
  337. (equal '(3 29 2014)
  338. (calendar-gregorian-from-absolute
  339. (org-closest-date "<2012-03-29 +2y>" "<2014-03-04>" 'future)))))
  340. (ert-deftest test-org/deadline-close-p ()
  341. "Test `org-deadline-close-p' specifications."
  342. (org-test-at-time "2016-06-03 Fri 01:43"
  343. ;; Timestamps are close if they are within `ndays' of lead time.
  344. (org-test-with-temp-text "* Heading"
  345. (should (org-deadline-close-p "2016-06-03 Fri" 0))
  346. (should (org-deadline-close-p "2016-06-02 Thu" 0))
  347. (should-not (org-deadline-close-p "2016-06-04 Sat" 0))
  348. (should (org-deadline-close-p "2016-06-04 Sat" 1))
  349. (should (org-deadline-close-p "2016-06-03 Fri 12:00" 0)))
  350. ;; Read `ndays' from timestamp if argument not given.
  351. (org-test-with-temp-text "* H"
  352. (should (org-deadline-close-p "2016-06-04 Sat -1d"))
  353. (should-not (org-deadline-close-p "2016-06-04 Sat -0d"))
  354. (should (org-deadline-close-p "2016-06-10 Fri -1w"))
  355. (should-not (org-deadline-close-p "2016-06-11 Sat -1w")))
  356. ;; Prefer `ndays' argument over lead time in timestamp.
  357. (org-test-with-temp-text "* H"
  358. (should (org-deadline-close-p "2016-06-04 Sat -0d" 1))
  359. (should-not (org-deadline-close-p "2016-06-04 Sat -0d" 0)))
  360. ;; Completed tasks are never close.
  361. (let ((org-todo-keywords '(("TODO" "|" "DONE"))))
  362. (org-test-with-temp-text "* TODO Heading"
  363. (should (org-deadline-close-p "2016-06-03")))
  364. (org-test-with-temp-text "* DONE Heading"
  365. (should-not (org-deadline-close-p "2016-06-03"))))))
  366. ;;; Drawers
  367. (ert-deftest test-org/at-property-p ()
  368. "Test `org-at-property-p' specifications."
  369. (should
  370. (equal 't
  371. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:PROP: t\n:END:\n"
  372. (org-at-property-p))))
  373. (should
  374. (equal 't
  375. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n:END:\n"
  376. (org-at-property-p)))))
  377. (ert-deftest test-org/at-property-drawer-p ()
  378. "Test `org-at-property-drawer-p' specifications."
  379. (should
  380. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:PROP: t\n:END:\n"
  381. (org-at-property-drawer-p)))
  382. (should
  383. (org-test-with-temp-text ":PROPERTIES:\n:PROP: t\n:END:\n"
  384. (org-at-property-drawer-p)))
  385. ;; The function only returns t if point is at the first line of
  386. ;; a property block.
  387. (should-not
  388. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n:END:\n"
  389. (org-at-property-drawer-p)))
  390. ;; The function ignores incomplete drawers.
  391. (should-not
  392. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n"
  393. (org-at-property-drawer-p)))
  394. ;; tab separating the value.
  395. (should
  396. (org-test-with-temp-text ":PROPERTIES:\n:PROP: t\n:END:\n"
  397. (org-at-property-drawer-p))))
  398. (ert-deftest test-org/get-property-block ()
  399. "Test `org-get-property-block' specifications."
  400. (should
  401. (equal '(14 . 14)
  402. (org-test-with-temp-text ":PROPERTIES:\n:END:\n* H\n"
  403. (org-get-property-block))))
  404. (should
  405. (equal '(14 . 14)
  406. (org-test-with-temp-text ":PROPERTIES:\n:END:\n"
  407. (org-get-property-block))))
  408. ;; Comments above a document property block is ok.
  409. (should
  410. (equal '(18 . 18)
  411. (org-test-with-temp-text "# C\n:PROPERTIES:\n:END:\n"
  412. (org-get-property-block))))
  413. ;; Keywords above a document property block is ok.
  414. (should
  415. (equal '(22 . 22)
  416. (org-test-with-temp-text "# C\n# C\n:PROPERTIES:\n:END:\n"
  417. (org-get-property-block))))
  418. ;; Comments and keywords are allowed before a document property block.
  419. (should
  420. (equal '(18 . 27)
  421. (org-test-with-temp-text "# C\n:PROPERTIES:\n:KEY: V:\n:END:\n"
  422. (org-get-property-block))))
  423. ;; A document property block will not be valid if there are lines
  424. ;; with whitespace above it
  425. (should-not
  426. (org-test-with-temp-text "\n:PROPERTIES:\n:END:\n"
  427. (org-get-property-block)))
  428. (should
  429. (equal '(18 . 18)
  430. (org-test-with-temp-text "* H\n:PROPERTIES:\n:END:\n<point>"
  431. (org-get-property-block))))
  432. (should
  433. (equal "* H\n:PROPERTIES:\n:END:\n"
  434. (org-test-with-temp-text "* H"
  435. (let ((org-adapt-indentation nil))
  436. (org-get-property-block nil 'force))
  437. (buffer-string))))
  438. (should
  439. (equal ":PROPERTIES:\n:END:\n"
  440. (org-test-with-temp-text ""
  441. (org-get-property-block nil 'force)
  442. (buffer-string))))
  443. (should
  444. (equal "* H1\n :PROPERTIES:\n :END:\n* H2"
  445. (org-test-with-temp-text "* H1\n* H2"
  446. (let ((org-adapt-indentation t))
  447. (org-get-property-block nil 'force))
  448. (buffer-string)))))
  449. (ert-deftest test-org/insert-property-drawer ()
  450. "Test `org-insert-property-drawer' specifications."
  451. ;; Insert drawer in empty buffer
  452. (should
  453. (equal ":PROPERTIES:\n:END:\n"
  454. (org-test-with-temp-text ""
  455. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  456. (buffer-string))))
  457. ;; Insert drawer in document header with existing comment and
  458. ;; keyword.
  459. (should
  460. (equal "# C\n:PROPERTIES:\n:END:\n#+TITLE: T"
  461. (org-test-with-temp-text "# C\n#+TITLE: T"
  462. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  463. (buffer-string))))
  464. ;; Insert drawer in document header with existing keyword.
  465. (should
  466. (equal ":PROPERTIES:\n:END:\n#+TITLE: T"
  467. (org-test-with-temp-text "#+TITLE: T"
  468. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  469. (buffer-string))))
  470. (should
  471. (equal ":PROPERTIES:\n:END:"
  472. (org-test-with-temp-text ":PROPERTIES:\n:END:"
  473. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  474. (buffer-string))))
  475. ;; Insert drawer in document header with one existing heading in buffer.
  476. (should
  477. (equal ":PROPERTIES:\n:END:\n\n* T\n"
  478. (org-test-with-temp-text "\n* T\n"
  479. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  480. (buffer-string))))
  481. ;; Insert drawer right after headline if there is no planning line,
  482. ;; or after it otherwise.
  483. (should
  484. (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
  485. (org-test-with-temp-text "* H\nParagraph<point>"
  486. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  487. (buffer-string))))
  488. (should
  489. (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
  490. (org-test-with-temp-text
  491. "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
  492. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  493. (buffer-string))))
  494. ;; Indent inserted drawer.
  495. (should
  496. (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
  497. (org-test-with-temp-text "* H\nParagraph<point>"
  498. (let ((org-adapt-indentation t)) (org-insert-property-drawer))
  499. (buffer-string))))
  500. ;; Handle insertion at eob.
  501. (should
  502. (equal "* H\n:PROPERTIES:\n:END:\n"
  503. (org-test-with-temp-text "* H"
  504. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  505. (buffer-string))))
  506. ;; Skip inlinetasks before point.
  507. (when (featurep 'org-inlinetask)
  508. (should
  509. (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
  510. (org-test-with-temp-text
  511. "* H\n*************** I\n*************** END\nP<point>"
  512. (let ((org-adapt-indentation nil)
  513. (org-inlinetask-min-level 15))
  514. (org-insert-property-drawer))
  515. (buffer-string)))))
  516. ;; Correctly set drawer in an inlinetask.
  517. (when (featurep 'org-inlinetask)
  518. (should
  519. (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
  520. (org-test-with-temp-text
  521. "* H\n*************** I\nP<point>\n*************** END"
  522. (let ((org-adapt-indentation nil)
  523. (org-inlinetask-min-level 15))
  524. (org-insert-property-drawer))
  525. (buffer-string))))))
  526. ;;; Filling
  527. (ert-deftest test-org/fill-element ()
  528. "Test `org-fill-element' specifications."
  529. ;; At an Org table, align it.
  530. (should
  531. (equal "| a |\n"
  532. (org-test-with-temp-text "|a|"
  533. (org-fill-element)
  534. (buffer-string))))
  535. (should
  536. (equal "#+name: table\n| a |\n"
  537. (org-test-with-temp-text "#+name: table\n| a |\n"
  538. (org-fill-element)
  539. (buffer-string))))
  540. ;; At a paragraph, preserve line breaks.
  541. (org-test-with-temp-text "some \\\\\nlong\ntext"
  542. (let ((fill-column 20))
  543. (org-fill-element)
  544. (should (equal (buffer-string) "some \\\\\nlong text"))))
  545. ;; Correctly fill a paragraph when point is at its very end.
  546. (should
  547. (equal "A B"
  548. (org-test-with-temp-text "A\nB"
  549. (let ((fill-column 20))
  550. (goto-char (point-max))
  551. (org-fill-element)
  552. (buffer-string)))))
  553. ;; Correctly fill the last paragraph of a greater element.
  554. (should
  555. (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
  556. (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
  557. (let ((fill-column 8))
  558. (forward-line)
  559. (end-of-line)
  560. (org-fill-element)
  561. (buffer-string)))))
  562. ;; Correctly fill an element in a narrowed buffer.
  563. (should
  564. (equal "01234\n6"
  565. (org-test-with-temp-text "01234 6789"
  566. (let ((fill-column 5))
  567. (narrow-to-region 1 8)
  568. (org-fill-element)
  569. (buffer-string)))))
  570. ;; Handle `adaptive-fill-regexp' in paragraphs.
  571. (should
  572. (equal "> a b"
  573. (org-test-with-temp-text "> a\n> b"
  574. (let ((fill-column 5)
  575. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  576. (org-fill-element)
  577. (buffer-string)))))
  578. ;; Special case: Fill first paragraph when point is at an item or
  579. ;; a plain-list or a footnote reference.
  580. (should
  581. (equal "- A B"
  582. (org-test-with-temp-text "- A\n B"
  583. (let ((fill-column 20))
  584. (org-fill-element)
  585. (buffer-string)))))
  586. (should
  587. (equal "[fn:1] A B"
  588. (org-test-with-temp-text "[fn:1] A\nB"
  589. (let ((fill-column 20))
  590. (org-fill-element)
  591. (buffer-string)))))
  592. (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
  593. (let ((fill-column 20))
  594. (org-fill-element)
  595. (should (equal (buffer-string)
  596. "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
  597. ;; Fill contents of `comment-block' elements.
  598. (should
  599. (equal
  600. (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
  601. (let ((fill-column 20))
  602. (forward-line)
  603. (org-fill-element)
  604. (buffer-string)))
  605. "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
  606. ;; Fill `comment' elements.
  607. (should
  608. (equal " # A B"
  609. (org-test-with-temp-text " # A\n # B"
  610. (let ((fill-column 20))
  611. (org-fill-element)
  612. (buffer-string)))))
  613. ;; Do not mix consecutive comments when filling one of them.
  614. (should
  615. (equal "# A B\n\n# C"
  616. (org-test-with-temp-text "# A\n# B\n\n# C"
  617. (let ((fill-column 20))
  618. (org-fill-element)
  619. (buffer-string)))))
  620. ;; Use commented empty lines as separators when filling comments.
  621. (should
  622. (equal "# A B\n#\n# C"
  623. (org-test-with-temp-text "# A\n# B\n#\n# C"
  624. (let ((fill-column 20))
  625. (org-fill-element)
  626. (buffer-string)))))
  627. ;; Handle `adaptive-fill-regexp' in comments.
  628. (should
  629. (equal "# > a b"
  630. (org-test-with-temp-text "# > a\n# > b"
  631. (let ((fill-column 20)
  632. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  633. (org-fill-element)
  634. (buffer-string)))))
  635. ;; Do nothing at affiliated keywords.
  636. (should
  637. (equal "#+NAME: para\nSome\ntext."
  638. (org-test-with-temp-text "#+NAME: para\nSome\ntext."
  639. (let ((fill-column 20))
  640. (org-fill-element)
  641. (buffer-string)))))
  642. ;; Do not move point after table when filling a table.
  643. (should-not
  644. (org-test-with-temp-text "| a | b |\n| c | d |\n"
  645. (forward-char)
  646. (org-fill-element)
  647. (eobp)))
  648. ;; Do not fill "n" macro, with or without arguments, followed by
  649. ;; a dot or a closing parenthesis since it could be confused with
  650. ;; a numbered bullet.
  651. (should-not
  652. (equal "123456789\n{{{n}}}."
  653. (org-test-with-temp-text "123456789 {{{n}}}."
  654. (let ((fill-column 10))
  655. (org-fill-element)
  656. (buffer-string)))))
  657. (should-not
  658. (equal "123456789\n{{{n}}}\)"
  659. (org-test-with-temp-text "123456789 {{{n}}}\)"
  660. (let ((fill-column 10))
  661. (org-fill-element)
  662. (buffer-string)))))
  663. (should-not
  664. (equal "123456789\n{{{n()}}}."
  665. (org-test-with-temp-text "123456789 {{{n()}}}."
  666. (let ((fill-column 10))
  667. (org-fill-element)
  668. (buffer-string)))))
  669. (should-not
  670. (equal "123456789\n{{{n(counter)}}}."
  671. (org-test-with-temp-text "123456789 {{{n(counter)}}}."
  672. (let ((fill-column 10))
  673. (org-fill-element)
  674. (buffer-string))))))
  675. (ert-deftest test-org/fill-paragraph ()
  676. "Test `org-fill-paragraph' specifications."
  677. ;; Regular test.
  678. (should
  679. (equal "012345678\n9"
  680. (org-test-with-temp-text "012345678 9"
  681. (let ((fill-column 10))
  682. (org-fill-paragraph)
  683. (buffer-string)))))
  684. ;; Fill paragraph even at end of buffer.
  685. (should
  686. (equal "012345678\n9\n"
  687. (org-test-with-temp-text "012345678 9\n<point>"
  688. (let ((fill-column 10))
  689. (org-fill-paragraph)
  690. (buffer-string)))))
  691. ;; Between two paragraphs, fill the next one.
  692. (should
  693. (equal "012345678 9\n\n012345678\n9"
  694. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  695. (let ((fill-column 10))
  696. (org-fill-paragraph)
  697. (buffer-string)))))
  698. (should
  699. (equal "012345678\n9\n\n012345678 9"
  700. (org-test-with-temp-text "012345678 9<point>\n\n012345678 9"
  701. (let ((fill-column 10))
  702. (org-fill-paragraph)
  703. (buffer-string)))))
  704. ;; Fill paragraph in a comment block.
  705. (should
  706. (equal "#+begin_comment\n012345678\n9\n#+end_comment"
  707. (org-test-with-temp-text
  708. "#+begin_comment\n<point>012345678 9\n#+end_comment"
  709. (let ((fill-column 10))
  710. (org-fill-paragraph)
  711. (buffer-string)))))
  712. ;; When a region is selected, fill every paragraph in the region.
  713. (should
  714. (equal "012345678\n9\n\n012345678\n9"
  715. (org-test-with-temp-text "012345678 9\n\n012345678 9"
  716. (let ((fill-column 10))
  717. (transient-mark-mode 1)
  718. (push-mark (point-min) t t)
  719. (goto-char (point-max))
  720. (call-interactively #'org-fill-paragraph)
  721. (buffer-string)))))
  722. (should
  723. (equal "012345678\n9\n\n012345678 9"
  724. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  725. (let ((fill-column 10))
  726. (transient-mark-mode 1)
  727. (push-mark (point) t t)
  728. (goto-char (point-min))
  729. (call-interactively #'org-fill-paragraph)
  730. (buffer-string)))))
  731. (should
  732. (equal "012345678 9\n\n012345678\n9"
  733. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  734. (let ((fill-column 10))
  735. (transient-mark-mode 1)
  736. (push-mark (point) t t)
  737. (goto-char (point-max))
  738. (call-interactively #'org-fill-paragraph)
  739. (buffer-string))))))
  740. (ert-deftest test-org/auto-fill-function ()
  741. "Test auto-filling features."
  742. ;; Auto fill paragraph.
  743. (should
  744. (equal "12345\n7890"
  745. (org-test-with-temp-text "12345 7890"
  746. (let ((fill-column 5))
  747. (end-of-line)
  748. (org-auto-fill-function)
  749. (buffer-string)))))
  750. ;; Auto fill first paragraph in an item.
  751. (should
  752. (equal "- 12345\n 7890"
  753. (org-test-with-temp-text "- 12345 7890"
  754. (let ((fill-column 7))
  755. (end-of-line)
  756. (org-auto-fill-function)
  757. (buffer-string)))))
  758. ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
  759. (should
  760. (equal "> 12345\n 7890"
  761. (org-test-with-temp-text "> 12345 7890"
  762. (let ((fill-column 10)
  763. (adaptive-fill-regexp "[ \t]*>+[ \t]*")
  764. (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
  765. (end-of-line)
  766. (org-auto-fill-function)
  767. (buffer-string)))))
  768. (should
  769. (equal "> 12345\n> 12345\n> 7890"
  770. (org-test-with-temp-text "> 12345\n> 12345 7890"
  771. (let ((fill-column 10)
  772. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  773. (goto-char (point-max))
  774. (org-auto-fill-function)
  775. (buffer-string)))))
  776. (should-not
  777. (equal " 12345\n *12345\n *12345"
  778. (org-test-with-temp-text " 12345\n *12345 12345"
  779. (let ((fill-column 10)
  780. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  781. (goto-char (point-max))
  782. (org-auto-fill-function)
  783. (buffer-string)))))
  784. ;; Auto fill comments.
  785. (should
  786. (equal " # 12345\n # 7890"
  787. (org-test-with-temp-text " # 12345 7890"
  788. (let ((fill-column 10))
  789. (end-of-line)
  790. (org-auto-fill-function)
  791. (buffer-string)))))
  792. ;; A hash within a line isn't a comment.
  793. (should-not
  794. (equal "12345 # 7890\n# 1"
  795. (org-test-with-temp-text "12345 # 7890 1"
  796. (let ((fill-column 12))
  797. (end-of-line)
  798. (org-auto-fill-function)
  799. (buffer-string)))))
  800. ;; Correctly interpret empty prefix.
  801. (should-not
  802. (equal "# a\n# b\nRegular\n# paragraph"
  803. (org-test-with-temp-text "# a\n# b\nRegular paragraph"
  804. (let ((fill-column 12))
  805. (end-of-line 3)
  806. (org-auto-fill-function)
  807. (buffer-string)))))
  808. ;; Comment block: auto fill contents.
  809. (should
  810. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  811. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  812. (let ((fill-column 5))
  813. (forward-line)
  814. (end-of-line)
  815. (org-auto-fill-function)
  816. (buffer-string)))))
  817. (should
  818. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  819. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  820. (let ((fill-column 5))
  821. (forward-line)
  822. (end-of-line)
  823. (org-auto-fill-function)
  824. (buffer-string)))))
  825. ;; Do not fill if a new item could be created.
  826. (should-not
  827. (equal "12345\n- 90"
  828. (org-test-with-temp-text "12345 - 90"
  829. (let ((fill-column 5))
  830. (end-of-line)
  831. (org-auto-fill-function)
  832. (buffer-string)))))
  833. ;; Do not fill if a line break could be introduced.
  834. (should-not
  835. (equal "123\\\\\n7890"
  836. (org-test-with-temp-text "123\\\\ 7890"
  837. (let ((fill-column 6))
  838. (end-of-line)
  839. (org-auto-fill-function)
  840. (buffer-string)))))
  841. ;; Do not fill affiliated keywords.
  842. (should-not
  843. (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
  844. (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
  845. (let ((fill-column 20))
  846. (end-of-line)
  847. (org-auto-fill-function)
  848. (buffer-string))))))
  849. ;;; Indentation
  850. (ert-deftest test-org/indent-line ()
  851. "Test `org-indent-line' specifications."
  852. ;; Do not indent diary sexps, footnote definitions or headlines.
  853. (should
  854. (zerop
  855. (org-test-with-temp-text "%%(org-calendar-holiday)"
  856. (org-indent-line)
  857. (org-get-indentation))))
  858. (should
  859. (zerop
  860. (org-test-with-temp-text "[fn:1] fn"
  861. (let ((org-adapt-indentation t)) (org-indent-line))
  862. (org-get-indentation))))
  863. (should
  864. (zerop
  865. (org-test-with-temp-text "* H"
  866. (org-indent-line)
  867. (org-get-indentation))))
  868. ;; Do not indent before first headline.
  869. (should
  870. (zerop
  871. (org-test-with-temp-text ""
  872. (org-indent-line)
  873. (org-get-indentation))))
  874. ;; Indent according to headline level otherwise, unless
  875. ;; `org-adapt-indentation' is nil.
  876. (should
  877. (= 2
  878. (org-test-with-temp-text "* H\n<point>A"
  879. (let ((org-adapt-indentation t)) (org-indent-line))
  880. (org-get-indentation))))
  881. (should
  882. (= 2
  883. (org-test-with-temp-text "* H\n<point>\nA"
  884. (let ((org-adapt-indentation t)) (org-indent-line))
  885. (org-get-indentation))))
  886. (should
  887. (zerop
  888. (org-test-with-temp-text "* H\n<point>A"
  889. (let ((org-adapt-indentation nil)) (org-indent-line))
  890. (org-get-indentation))))
  891. ;; Indenting preserves point position.
  892. (should
  893. (org-test-with-temp-text "* H\nA<point>B"
  894. (let ((org-adapt-indentation t)) (org-indent-line))
  895. (looking-at "B")))
  896. ;; Do not change indentation at an item or a LaTeX environment.
  897. (should
  898. (= 1
  899. (org-test-with-temp-text "* H\n<point> - A"
  900. (let ((org-adapt-indentation t)) (org-indent-line))
  901. (org-get-indentation))))
  902. (should
  903. (= 1
  904. (org-test-with-temp-text
  905. "\\begin{equation}\n <point>1+1=2\n\\end{equation}"
  906. (org-indent-line)
  907. (org-get-indentation))))
  908. ;; On blank lines at the end of a list, indent like last element
  909. ;; within it if the line is still in the list. If the last element
  910. ;; is an item, indent like its contents. Otherwise, indent like the
  911. ;; whole list.
  912. (should
  913. (= 4
  914. (org-test-with-temp-text "* H\n- A\n - AA\n<point>"
  915. (let ((org-adapt-indentation t)) (org-indent-line))
  916. (org-get-indentation))))
  917. (should
  918. (= 4
  919. (org-test-with-temp-text "* H\n- A\n -\n\n<point>"
  920. (let ((org-adapt-indentation t)) (org-indent-line))
  921. (org-get-indentation))))
  922. (should
  923. (zerop
  924. (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n<point>"
  925. (let ((org-adapt-indentation t)) (org-indent-line))
  926. (org-get-indentation))))
  927. (should
  928. (= 4
  929. (org-test-with-temp-text "* H\n- A\n - \n<point>"
  930. (let ((org-adapt-indentation t)) (org-indent-line))
  931. (org-get-indentation))))
  932. (should
  933. (= 4
  934. (org-test-with-temp-text
  935. "* H\n - \n #+BEGIN_SRC emacs-lisp\n t\n #+END_SRC\n<point>"
  936. (let ((org-adapt-indentation t)) (org-indent-line))
  937. (org-get-indentation))))
  938. (should
  939. (= 2
  940. (org-test-with-temp-text "- A\n B\n\n<point>"
  941. (let ((org-adapt-indentation nil)) (org-indent-line))
  942. (org-get-indentation))))
  943. (should
  944. (= 2
  945. (org-test-with-temp-text
  946. "- A\n \begin{cases} 1 + 1\n \end{cases}\n\n<point>"
  947. (let ((org-adapt-indentation nil)) (org-indent-line))
  948. (org-get-indentation))))
  949. ;; Likewise, on a blank line at the end of a footnote definition,
  950. ;; indent at column 0 if line belongs to the definition. Otherwise,
  951. ;; indent like the definition itself.
  952. (should
  953. (zerop
  954. (org-test-with-temp-text "* H\n[fn:1] Definition\n<point>"
  955. (let ((org-adapt-indentation t)) (org-indent-line))
  956. (org-get-indentation))))
  957. (should
  958. (zerop
  959. (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n<point>"
  960. (let ((org-adapt-indentation t)) (org-indent-line))
  961. (org-get-indentation))))
  962. ;; After the end of the contents of a greater element, indent like
  963. ;; the beginning of the element.
  964. (should
  965. (= 1
  966. (org-test-with-temp-text
  967. " #+BEGIN_CENTER\n Contents\n<point>#+END_CENTER"
  968. (org-indent-line)
  969. (org-get-indentation))))
  970. ;; On blank lines after a paragraph, indent like its last non-empty
  971. ;; line.
  972. (should
  973. (= 1
  974. (org-test-with-temp-text " Paragraph\n\n<point>"
  975. (org-indent-line)
  976. (org-get-indentation))))
  977. ;; At the first line of an element, indent like previous element's
  978. ;; first line, ignoring footnotes definitions and inline tasks, or
  979. ;; according to parent.
  980. (let ((org-adapt-indentation t))
  981. (should
  982. (= 2
  983. (org-test-with-temp-text "A\n\n B\n\nC<point>"
  984. (org-indent-line)
  985. (org-get-indentation))))
  986. (should
  987. (= 1
  988. (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC<point>"
  989. (org-indent-line)
  990. (org-get-indentation))))
  991. (should
  992. (= 1
  993. (org-test-with-temp-text
  994. " #+BEGIN_CENTER\n<point> Contents\n#+END_CENTER"
  995. (org-indent-line)
  996. (org-get-indentation)))))
  997. ;; Within code part of a source block, use language major mode if
  998. ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
  999. ;; according to line above.
  1000. (should
  1001. (= 6
  1002. (org-test-with-temp-text
  1003. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  1004. (let ((org-src-tab-acts-natively t)
  1005. (org-edit-src-content-indentation 0))
  1006. (org-indent-line))
  1007. (org-get-indentation))))
  1008. (should
  1009. (= 1
  1010. (org-test-with-temp-text
  1011. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  1012. (let ((org-src-tab-acts-natively nil)
  1013. (org-edit-src-content-indentation 0))
  1014. (org-indent-line))
  1015. (org-get-indentation))))
  1016. ;; Otherwise, indent like the first non-blank line above.
  1017. (should
  1018. (zerop
  1019. (org-test-with-temp-text
  1020. "#+BEGIN_CENTER\nline1\n\n<point> line2\n#+END_CENTER"
  1021. (org-indent-line)
  1022. (org-get-indentation))))
  1023. ;; Align node properties according to `org-property-format'. Handle
  1024. ;; nicely empty values.
  1025. (should
  1026. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1027. (org-test-with-temp-text
  1028. "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
  1029. (let ((org-property-format "%-10s %s")) (org-indent-line))
  1030. (buffer-string))))
  1031. (should
  1032. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1033. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
  1034. (let ((org-property-format "%-10s %s")) (org-indent-line))
  1035. (buffer-string)))))
  1036. (ert-deftest test-org/indent-region ()
  1037. "Test `org-indent-region' specifications."
  1038. ;; Indent paragraph.
  1039. (let ((org-adapt-indentation t))
  1040. (should
  1041. (equal "A\nB\nC"
  1042. (org-test-with-temp-text " A\nB\n C"
  1043. (org-indent-region (point-min) (point-max))
  1044. (buffer-string)))))
  1045. ;; Indent greater elements along with their contents.
  1046. (should
  1047. (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
  1048. (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
  1049. (org-indent-region (point-min) (point-max))
  1050. (buffer-string))))
  1051. ;; Ignore contents of verse blocks. Only indent block delimiters.
  1052. (should
  1053. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1054. (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1055. (org-indent-region (point-min) (point-max))
  1056. (buffer-string))))
  1057. (let ((org-adapt-indentation t))
  1058. (should
  1059. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1060. (org-test-with-temp-text " #+BEGIN_VERSE\n A\n B\n #+END_VERSE"
  1061. (org-indent-region (point-min) (point-max))
  1062. (buffer-string)))))
  1063. ;; Indent example blocks as a single block, unless indentation
  1064. ;; should be preserved. In this case only indent the block markers.
  1065. (should
  1066. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1067. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1068. (org-indent-region (point-min) (point-max))
  1069. (buffer-string))))
  1070. (let ((org-adapt-indentation t))
  1071. (should
  1072. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1073. (org-test-with-temp-text " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1074. (org-indent-region (point-min) (point-max))
  1075. (buffer-string))))
  1076. (should
  1077. (equal "#+BEGIN_EXAMPLE -i\n A\n B\n#+END_EXAMPLE"
  1078. (org-test-with-temp-text
  1079. " #+BEGIN_EXAMPLE -i\n A\n B\n #+END_EXAMPLE"
  1080. (org-indent-region (point-min) (point-max))
  1081. (buffer-string))))
  1082. (should
  1083. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1084. (org-test-with-temp-text
  1085. " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1086. (let ((org-src-preserve-indentation t))
  1087. (org-indent-region (point-min) (point-max)))
  1088. (buffer-string)))))
  1089. ;; Treat export blocks as a whole.
  1090. (should
  1091. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1092. (org-test-with-temp-text "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1093. (org-indent-region (point-min) (point-max))
  1094. (buffer-string))))
  1095. (let ((org-adapt-indentation t))
  1096. (should
  1097. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1098. (org-test-with-temp-text
  1099. " #+BEGIN_EXPORT latex\n A\n B\n #+END_EXPORT"
  1100. (org-indent-region (point-min) (point-max))
  1101. (buffer-string)))))
  1102. ;; Indent according to mode if `org-src-tab-acts-natively' is
  1103. ;; non-nil. Otherwise, do not indent code at all.
  1104. (should
  1105. (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
  1106. (org-test-with-temp-text
  1107. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1108. (let ((org-src-tab-acts-natively t)
  1109. (org-edit-src-content-indentation 0))
  1110. (org-indent-region (point-min) (point-max)))
  1111. (buffer-string))))
  1112. (should
  1113. (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1114. (org-test-with-temp-text
  1115. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1116. (let ((org-src-tab-acts-natively nil)
  1117. (org-edit-src-content-indentation 0))
  1118. (org-indent-region (point-min) (point-max)))
  1119. (buffer-string))))
  1120. ;; Align node properties according to `org-property-format'. Handle
  1121. ;; nicely empty values.
  1122. (should
  1123. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1124. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
  1125. (let ((org-property-format "%-10s %s")
  1126. (org-adapt-indentation nil))
  1127. (org-indent-region (point) (point-max)))
  1128. (buffer-string))))
  1129. (should
  1130. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1131. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
  1132. (let ((org-property-format "%-10s %s")
  1133. (org-adapt-indentation nil))
  1134. (org-indent-region (point) (point-max)))
  1135. (buffer-string))))
  1136. ;; Indent property drawers according to `org-adapt-indentation'.
  1137. (let ((org-adapt-indentation 'headline-data))
  1138. (should
  1139. (equal "* H\n :PROPERTIES:\n :key:\n :END:"
  1140. (org-test-with-temp-text "* H\n:PROPERTIES:\n:key:\n:END:"
  1141. (org-indent-region (point-min) (point-max))
  1142. (buffer-string)))))
  1143. ;; Indent plain lists.
  1144. (let ((org-adapt-indentation t))
  1145. (should
  1146. (equal "- A\n B\n - C\n\n D"
  1147. (org-test-with-temp-text "- A\n B\n - C\n\n D"
  1148. (org-indent-region (point-min) (point-max))
  1149. (buffer-string))))
  1150. (should
  1151. (equal "- A\n\n- B"
  1152. (org-test-with-temp-text " - A\n\n - B"
  1153. (org-indent-region (point-min) (point-max))
  1154. (buffer-string)))))
  1155. ;; Indent footnote definitions.
  1156. (should
  1157. (equal "[fn:1] Definition\n\nDefinition"
  1158. (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
  1159. (org-indent-region (point-min) (point-max))
  1160. (buffer-string))))
  1161. ;; Special case: Start indenting on a blank line.
  1162. (should
  1163. (equal "\nParagraph"
  1164. (org-test-with-temp-text "\n Paragraph"
  1165. (org-indent-region (point-min) (point-max))
  1166. (buffer-string)))))
  1167. ;;; Editing
  1168. (ert-deftest test-org/delete-indentation ()
  1169. "Test `org-delete-indentation' specifications."
  1170. ;; Regular test.
  1171. (should (equal "foo bar"
  1172. (org-test-with-temp-text
  1173. "foo \n bar<point>"
  1174. (org-delete-indentation)
  1175. (buffer-string))))
  1176. ;; With optional argument.
  1177. (should (equal "foo bar"
  1178. (org-test-with-temp-text
  1179. "foo<point> \n bar"
  1180. (org-delete-indentation t)
  1181. (buffer-string))))
  1182. ;; At headline text should be appended to the headline text.
  1183. (should
  1184. (equal"* foo bar :tag:"
  1185. (let (org-auto-align-tags)
  1186. (org-test-with-temp-text
  1187. "* foo :tag:\n bar<point>"
  1188. (org-delete-indentation)
  1189. (buffer-string)))))
  1190. (should
  1191. (equal "* foo bar :tag:"
  1192. (let (org-auto-align-tags)
  1193. (org-test-with-temp-text
  1194. "* foo <point>:tag:\n bar"
  1195. (org-delete-indentation t)
  1196. (buffer-string))))))
  1197. (ert-deftest test-org/return ()
  1198. "Test `org-return' specifications."
  1199. ;; Regular test.
  1200. (should
  1201. (equal "Para\ngraph"
  1202. (org-test-with-temp-text "Para<point>graph"
  1203. (org-return)
  1204. (buffer-string))))
  1205. ;; With optional argument, indent line.
  1206. (should
  1207. (equal " Para\n graph"
  1208. (org-test-with-temp-text " Para<point>graph"
  1209. (org-return t)
  1210. (buffer-string))))
  1211. ;; On a table, call `org-table-next-row'.
  1212. (should
  1213. (org-test-with-temp-text "| <point>a |\n| b |"
  1214. (org-return)
  1215. (looking-at-p "b")))
  1216. ;; Open link or timestamp under point when `org-return-follows-link'
  1217. ;; is non-nil.
  1218. (should
  1219. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1220. (let ((org-return-follows-link t)
  1221. (org-link-search-must-match-exact-headline nil))
  1222. (org-return))
  1223. (looking-at-p "<<target>>")))
  1224. (should-not
  1225. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1226. (let ((org-return-follows-link nil)) (org-return))
  1227. (looking-at-p "<<target>>")))
  1228. (should
  1229. (org-test-with-temp-text "* [[b][a<point>]]\n* b"
  1230. (let ((org-return-follows-link t)) (org-return))
  1231. (looking-at-p "* b")))
  1232. (should
  1233. (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
  1234. (let ((org-return-follows-link t)
  1235. (org-link-search-must-match-exact-headline nil))
  1236. (org-return))
  1237. (looking-at-p "<<target>>")))
  1238. (should-not
  1239. (org-test-with-temp-text "Link [[target]]<point> <<target>>"
  1240. (let ((org-return-follows-link t)
  1241. (org-link-search-must-match-exact-headline nil))
  1242. (org-return))
  1243. (looking-at-p "<<target>>")))
  1244. ;; When `org-return-follows-link' is non-nil, tolerate links and
  1245. ;; timestamps in comments, node properties, etc.
  1246. (should
  1247. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1248. (let ((org-return-follows-link t)
  1249. (org-link-search-must-match-exact-headline nil))
  1250. (org-return))
  1251. (looking-at-p "<<target>>")))
  1252. (should-not
  1253. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1254. (let ((org-return-follows-link nil)) (org-return))
  1255. (looking-at-p "<<target>>")))
  1256. (should-not
  1257. (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
  1258. (let ((org-return-follows-link t)
  1259. (org-link-search-must-match-exact-headline nil))
  1260. (org-return))
  1261. (looking-at-p "<<target>>")))
  1262. ;; Non-nil `org-return-follows-link' ignores read-only state of
  1263. ;; a buffer.
  1264. (should
  1265. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1266. (let ((org-return-follows-link t)
  1267. (org-link-search-must-match-exact-headline nil))
  1268. (setq buffer-read-only t)
  1269. (call-interactively #'org-return))
  1270. (looking-at-p "<<target>>")))
  1271. ;; `org-return-follows-link' handle multi-line lines.
  1272. (should
  1273. (org-test-with-temp-text
  1274. "[[target][This is a very\n long description<point>]]\n <<target>>"
  1275. (let ((org-return-follows-link t)
  1276. (org-link-search-must-match-exact-headline nil))
  1277. (org-return))
  1278. (looking-at-p "<<target>>")))
  1279. (should-not
  1280. (org-test-with-temp-text
  1281. "[[target][This is a very\n long description]]<point>\n <<target>>"
  1282. (let ((org-return-follows-link t)
  1283. (org-link-search-must-match-exact-headline nil))
  1284. (org-return))
  1285. (looking-at-p "<<target>>")))
  1286. ;; However, do not open link when point is in a table.
  1287. (should
  1288. (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
  1289. (let ((org-return-follows-link t)) (org-return))
  1290. (looking-at-p "between")))
  1291. ;; Special case: in a list, when indenting, do not break structure.
  1292. (should
  1293. (equal "- A\n B"
  1294. (org-test-with-temp-text "- A <point>B"
  1295. (org-return t)
  1296. (buffer-string))))
  1297. (should
  1298. (equal "- A\n\n- B"
  1299. (org-test-with-temp-text "- A\n<point>- B"
  1300. (org-return t)
  1301. (buffer-string))))
  1302. ;; On tags part of a headline, add a newline below it instead of
  1303. ;; breaking it.
  1304. (should
  1305. (equal "* H :tag:\n"
  1306. (org-test-with-temp-text "* H :<point>tag:"
  1307. (org-return)
  1308. (buffer-string))))
  1309. ;; Before headline text, add a newline below it instead of breaking
  1310. ;; it.
  1311. (should
  1312. (equal "* TODO H :tag:\n"
  1313. (org-test-with-temp-text "* <point>TODO H :tag:"
  1314. (org-return)
  1315. (buffer-string))))
  1316. (should
  1317. (equal "* TODO [#B] H :tag:\n"
  1318. (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
  1319. (org-return)
  1320. (buffer-string))))
  1321. (should ;TODO are case-sensitive
  1322. (equal "* \nTodo"
  1323. (org-test-with-temp-text "* <point>Todo"
  1324. (org-return)
  1325. (buffer-string))))
  1326. ;; At headline text, break headline text but preserve tags.
  1327. (should
  1328. (equal "* TODO [#B] foo :tag:\nbar"
  1329. (let (org-auto-align-tags)
  1330. (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
  1331. (org-return)
  1332. (buffer-string)))))
  1333. ;; At bol of headline insert newline.
  1334. (should
  1335. (equal "\n* h"
  1336. (org-test-with-temp-text "<point>* h"
  1337. (org-return)
  1338. (buffer-string))))
  1339. ;; Refuse to leave invalid headline in buffer.
  1340. (should
  1341. (equal "* h\n"
  1342. (org-test-with-temp-text "*<point> h"
  1343. (org-return)
  1344. (buffer-string))))
  1345. ;; Before first column or after last one in a table, split the
  1346. ;; table.
  1347. (should
  1348. (equal "| a |\n\n| b |"
  1349. (org-test-with-temp-text "| a |\n<point>| b |"
  1350. (org-return)
  1351. (buffer-string))))
  1352. (should
  1353. (equal "| a |\n\n| b |"
  1354. (org-test-with-temp-text "| a |<point>\n| b |"
  1355. (org-return)
  1356. (buffer-string))))
  1357. ;; Do not auto-fill on hitting <RET> inside a property drawer.
  1358. (should
  1359. (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:"
  1360. (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:"
  1361. (setq-local fill-column 10)
  1362. (auto-fill-mode 1)
  1363. (org-return)
  1364. (buffer-string)))))
  1365. (ert-deftest test-org/with-electric-indent ()
  1366. "Test RET and C-j specifications with `electric-indent-mode' on."
  1367. ;; Call commands interactively, since this is how `newline' knows it
  1368. ;; must run `post-self-insert-hook'.
  1369. ;;
  1370. ;; RET, like `newline', should indent.
  1371. (should
  1372. (equal " Para\n graph"
  1373. (org-test-with-temp-text " Para<point>graph"
  1374. (electric-indent-local-mode 1)
  1375. (call-interactively 'org-return)
  1376. (buffer-string))))
  1377. (should
  1378. (equal "- item1\n item2"
  1379. (org-test-with-temp-text "- item1<point>item2"
  1380. (electric-indent-local-mode 1)
  1381. (call-interactively 'org-return)
  1382. (buffer-string))))
  1383. ;; TODO: test more values of `org-adapt-indentation'.
  1384. (let ((org-adapt-indentation t))
  1385. (should
  1386. (equal "* heading\n body"
  1387. (org-test-with-temp-text "* heading<point>body"
  1388. (electric-indent-local-mode 1)
  1389. (call-interactively 'org-return)
  1390. (buffer-string)))))
  1391. ;; C-j, like `electric-newline-and-maybe-indent', should not indent.
  1392. (should
  1393. (equal " Para\ngraph"
  1394. (org-test-with-temp-text " Para<point>graph"
  1395. (electric-indent-local-mode 1)
  1396. (call-interactively 'org-return-and-maybe-indent)
  1397. (buffer-string))))
  1398. (should
  1399. (equal "- item1\nitem2"
  1400. (org-test-with-temp-text "- item1<point>item2"
  1401. (electric-indent-local-mode 1)
  1402. (call-interactively 'org-return-and-maybe-indent)
  1403. (buffer-string))))
  1404. ;; TODO: test more values of `org-adapt-indentation'.
  1405. (let ((org-adapt-indentation t))
  1406. (should
  1407. (equal "* heading\nbody"
  1408. (org-test-with-temp-text "* heading<point>body"
  1409. (electric-indent-local-mode 1)
  1410. (call-interactively 'org-return-and-maybe-indent)
  1411. (buffer-string))))))
  1412. (ert-deftest test-org/without-electric-indent ()
  1413. "Test RET and C-j specifications with `electric-indent-mode' off."
  1414. ;; Call commands interactively, since this is how `newline' knows it
  1415. ;; must run `post-self-insert-hook'.
  1416. ;;
  1417. ;; RET, like `newline', should not indent.
  1418. (should
  1419. (equal " Para\ngraph"
  1420. (org-test-with-temp-text " Para<point>graph"
  1421. (electric-indent-local-mode 0)
  1422. (call-interactively 'org-return)
  1423. (buffer-string))))
  1424. (should
  1425. (equal "- item1\nitem2"
  1426. (org-test-with-temp-text "- item1<point>item2"
  1427. (electric-indent-local-mode 0)
  1428. (call-interactively 'org-return)
  1429. (buffer-string))))
  1430. (should
  1431. (equal "* heading\nbody"
  1432. (org-test-with-temp-text "* heading<point>body"
  1433. (electric-indent-local-mode 0)
  1434. (call-interactively 'org-return)
  1435. (buffer-string))))
  1436. ;; C-j, like `electric-newline-and-maybe-indent', should indent.
  1437. (should
  1438. (equal " Para\n graph"
  1439. (org-test-with-temp-text " Para<point>graph"
  1440. (electric-indent-local-mode 0)
  1441. (call-interactively 'org-return-and-maybe-indent)
  1442. (buffer-string))))
  1443. (should
  1444. (equal "- item1\n item2"
  1445. (org-test-with-temp-text "- item1<point>item2"
  1446. (electric-indent-local-mode 0)
  1447. (call-interactively 'org-return-and-maybe-indent)
  1448. (buffer-string))))
  1449. ;; TODO: test more values of `org-adapt-indentation'.
  1450. (let ((org-adapt-indentation t))
  1451. (should
  1452. (equal "* heading\n body"
  1453. (org-test-with-temp-text "* heading<point>body"
  1454. (electric-indent-local-mode 0)
  1455. (call-interactively 'org-return-and-maybe-indent)
  1456. (buffer-string))))))
  1457. (ert-deftest test-org/meta-return ()
  1458. "Test M-RET (`org-meta-return') specifications."
  1459. ;; In a table field insert a row above.
  1460. (should
  1461. (org-test-with-temp-text "| a |"
  1462. (forward-char)
  1463. (org-meta-return)
  1464. (forward-line -1)
  1465. (looking-at "| |$")))
  1466. ;; In a paragraph change current line into a header.
  1467. (should
  1468. (org-test-with-temp-text "a"
  1469. (org-meta-return)
  1470. (beginning-of-line)
  1471. (looking-at "\* a$")))
  1472. ;; In an item insert an item, in this case above.
  1473. (should
  1474. (org-test-with-temp-text "- a"
  1475. (org-meta-return)
  1476. (beginning-of-line)
  1477. (looking-at "- $")))
  1478. ;; In a drawer and item insert an item, in this case above.
  1479. (should
  1480. (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
  1481. (forward-line)
  1482. (org-meta-return)
  1483. (beginning-of-line)
  1484. (looking-at "- $"))))
  1485. (ert-deftest test-org/insert-heading ()
  1486. "Test `org-insert-heading' specifications."
  1487. ;; In an empty buffer, insert a new headline.
  1488. (should
  1489. (equal "* "
  1490. (org-test-with-temp-text ""
  1491. (org-insert-heading)
  1492. (buffer-string))))
  1493. ;; At the beginning of a line, turn it into a headline.
  1494. (should
  1495. (equal "* P"
  1496. (org-test-with-temp-text "<point>P"
  1497. (org-insert-heading)
  1498. (buffer-string))))
  1499. ;; In the middle of a line, split the line if allowed, otherwise,
  1500. ;; insert the headline at its end.
  1501. (should
  1502. (equal "Para\n* graph"
  1503. (org-test-with-temp-text "Para<point>graph"
  1504. (let ((org-M-RET-may-split-line '((default . t))))
  1505. (org-insert-heading))
  1506. (buffer-string))))
  1507. (should
  1508. (equal "Paragraph\n* "
  1509. (org-test-with-temp-text "Para<point>graph"
  1510. (let ((org-M-RET-may-split-line '((default . nil))))
  1511. (org-insert-heading))
  1512. (buffer-string))))
  1513. ;; At the beginning of a headline, create one above.
  1514. (should
  1515. (equal "* \n* H"
  1516. (org-test-with-temp-text "* H"
  1517. (org-insert-heading)
  1518. (buffer-string))))
  1519. ;; In the middle of a headline, split it if allowed.
  1520. (should
  1521. (equal "* H\n* 1"
  1522. (org-test-with-temp-text "* H<point>1"
  1523. (let ((org-M-RET-may-split-line '((headline . t))))
  1524. (org-insert-heading))
  1525. (buffer-string))))
  1526. (should
  1527. (equal "* H1\n* "
  1528. (org-test-with-temp-text "* H<point>1"
  1529. (let ((org-M-RET-may-split-line '((headline . nil))))
  1530. (org-insert-heading))
  1531. (buffer-string))))
  1532. ;; However, splitting cannot happen on TODO keywords, priorities or
  1533. ;; tags.
  1534. (should
  1535. (equal "* TODO H1\n* "
  1536. (org-test-with-temp-text "* TO<point>DO H1"
  1537. (let ((org-M-RET-may-split-line '((headline . t))))
  1538. (org-insert-heading))
  1539. (buffer-string))))
  1540. (should
  1541. (equal "* [#A] H1\n* "
  1542. (org-test-with-temp-text "* [#<point>A] H1"
  1543. (let ((org-M-RET-may-split-line '((headline . t))))
  1544. (org-insert-heading))
  1545. (buffer-string))))
  1546. (should
  1547. (equal "* H1 :tag:\n* "
  1548. (org-test-with-temp-text "* H1 :ta<point>g:"
  1549. (let ((org-M-RET-may-split-line '((headline . t))))
  1550. (org-insert-heading))
  1551. (buffer-string))))
  1552. ;; New headline level depends on the level of the headline above.
  1553. (should
  1554. (equal "** H\n** P"
  1555. (org-test-with-temp-text "** H\n<point>P"
  1556. (org-insert-heading)
  1557. (buffer-string))))
  1558. (should
  1559. (equal "** H\nPara\n** graph"
  1560. (org-test-with-temp-text "** H\nPara<point>graph"
  1561. (let ((org-M-RET-may-split-line '((default . t))))
  1562. (org-insert-heading))
  1563. (buffer-string))))
  1564. (should
  1565. (equal "** \n** H"
  1566. (org-test-with-temp-text "** H"
  1567. (org-insert-heading)
  1568. (buffer-string))))
  1569. ;; When called with one universal argument, insert a new headline at
  1570. ;; the end of the current subtree, independently on the position of
  1571. ;; point.
  1572. (should
  1573. (equal
  1574. "* "
  1575. (org-test-with-temp-text ""
  1576. (let ((org-insert-heading-respect-content nil))
  1577. (org-insert-heading '(4)))
  1578. (buffer-string))))
  1579. (should
  1580. (equal
  1581. "entry
  1582. * "
  1583. (org-test-with-temp-text "entry"
  1584. (let ((org-insert-heading-respect-content nil))
  1585. (org-insert-heading '(4)))
  1586. (buffer-string))))
  1587. (should
  1588. (equal
  1589. "* H1\n** H2\n* "
  1590. (org-test-with-temp-text "* H1\n** H2"
  1591. (let ((org-insert-heading-respect-content nil))
  1592. (org-insert-heading '(4)))
  1593. (buffer-string))))
  1594. (should
  1595. (equal
  1596. "* H1\n** H2\n* "
  1597. (org-test-with-temp-text "* H<point>1\n** H2"
  1598. (let ((org-insert-heading-respect-content nil))
  1599. (org-insert-heading '(4)))
  1600. (buffer-string))))
  1601. ;; When called with two universal arguments, insert a new headline
  1602. ;; at the end of the grandparent subtree.
  1603. (should
  1604. (equal "* H1\n** H3\n- item\n** H2\n** "
  1605. (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
  1606. (let ((org-insert-heading-respect-content nil))
  1607. (org-insert-heading '(16)))
  1608. (buffer-string))))
  1609. ;; When optional TOP-LEVEL argument is non-nil, always insert
  1610. ;; a level 1 heading.
  1611. (should
  1612. (equal "* H1\n** H2\n* "
  1613. (org-test-with-temp-text "* H1\n** H2<point>"
  1614. (org-insert-heading nil nil t)
  1615. (buffer-string))))
  1616. (should
  1617. (equal "* H1\n- item\n* "
  1618. (org-test-with-temp-text "* H1\n- item<point>"
  1619. (org-insert-heading nil nil t)
  1620. (buffer-string))))
  1621. ;; Obey `org-blank-before-new-entry'.
  1622. (should
  1623. (equal "* H1\n\n* "
  1624. (org-test-with-temp-text "* H1<point>"
  1625. (let ((org-blank-before-new-entry '((heading . t))))
  1626. (org-insert-heading))
  1627. (buffer-string))))
  1628. (should
  1629. (equal "* H1\n* "
  1630. (org-test-with-temp-text "* H1<point>"
  1631. (let ((org-blank-before-new-entry '((heading . nil))))
  1632. (org-insert-heading))
  1633. (buffer-string))))
  1634. (should
  1635. (equal "* H1\n* H2\n* "
  1636. (org-test-with-temp-text "* H1\n* H2<point>"
  1637. (let ((org-blank-before-new-entry '((heading . auto))))
  1638. (org-insert-heading))
  1639. (buffer-string))))
  1640. (should
  1641. (equal "* H1\n\n* H2\n\n* "
  1642. (org-test-with-temp-text "* H1\n\n* H2<point>"
  1643. (let ((org-blank-before-new-entry '((heading . auto))))
  1644. (org-insert-heading))
  1645. (buffer-string))))
  1646. ;; Corner case: correctly insert a headline after an empty one.
  1647. (should
  1648. (equal "* \n* "
  1649. (org-test-with-temp-text "* <point>"
  1650. (org-insert-heading)
  1651. (buffer-string))))
  1652. (should
  1653. (org-test-with-temp-text "* <point>\n"
  1654. (org-insert-heading)
  1655. (looking-at-p "\n\\'")))
  1656. ;; Do not insert spurious headlines when inserting a new headline.
  1657. (should
  1658. (equal "* H1\n* H2\n* \n"
  1659. (org-test-with-temp-text "* H1\n* H2<point>\n"
  1660. (org-insert-heading)
  1661. (buffer-string))))
  1662. ;; Preserve visibility at beginning of line. In particular, when
  1663. ;; removing spurious blank lines, do not visually merge heading with
  1664. ;; the line visible above.
  1665. (should-not
  1666. (org-test-with-temp-text "* H1<point>\nContents\n\n* H2\n"
  1667. (org-overview)
  1668. (let ((org-blank-before-new-entry '((heading . nil))))
  1669. (org-insert-heading '(4)))
  1670. (invisible-p (line-end-position 0))))
  1671. ;; Properly handle empty lines when forcing a headline below current
  1672. ;; one.
  1673. (should
  1674. (equal "* H1\n\n* H\n\n* "
  1675. (org-test-with-temp-text "* H1\n\n* H<point>"
  1676. (let ((org-blank-before-new-entry '((heading . t))))
  1677. (org-insert-heading '(4))
  1678. (buffer-string))))))
  1679. (ert-deftest test-org/insert-todo-heading-respect-content ()
  1680. "Test `org-insert-todo-heading-respect-content' specifications."
  1681. ;; Create a TODO heading.
  1682. (should
  1683. (org-test-with-temp-text "* H1\n Body"
  1684. (org-insert-todo-heading-respect-content)
  1685. (nth 2 (org-heading-components))))
  1686. ;; Add headline at the end of the first subtree
  1687. (should
  1688. (equal
  1689. "* TODO "
  1690. (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
  1691. (org-insert-todo-heading-respect-content)
  1692. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1693. ;; In a list, do not create a new item.
  1694. (should
  1695. (equal
  1696. "* TODO "
  1697. (org-test-with-temp-text "* H\n- an item\n- another one"
  1698. (search-forward "an ")
  1699. (org-insert-todo-heading-respect-content)
  1700. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1701. ;; Use the same TODO keyword as current heading.
  1702. (should
  1703. (equal
  1704. "* TODO \n"
  1705. (org-test-with-temp-text "* TODO\n** WAITING\n"
  1706. (org-insert-todo-heading-respect-content)
  1707. (buffer-substring-no-properties (line-beginning-position) (point-max))))))
  1708. (ert-deftest test-org/clone-with-time-shift ()
  1709. "Test `org-clone-subtree-with-time-shift'."
  1710. ;; Raise an error before first heading.
  1711. (should-error
  1712. (org-test-with-temp-text ""
  1713. (org-clone-subtree-with-time-shift 1)))
  1714. ;; Raise an error on invalid number of clones.
  1715. (should-error
  1716. (org-test-with-temp-text "* Clone me"
  1717. (org-clone-subtree-with-time-shift -1)))
  1718. ;; Clone non-repeating once.
  1719. (should
  1720. (equal "\
  1721. * H1\n<2015-06-21>
  1722. * H1\n<2015-06-23>
  1723. "
  1724. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1725. (org-clone-subtree-with-time-shift 1 "+2d")
  1726. (replace-regexp-in-string
  1727. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1728. nil nil 1))))
  1729. ;; Clone repeating once.
  1730. (should
  1731. (equal "\
  1732. * H1\n<2015-06-21>
  1733. * H1\n<2015-06-23>
  1734. * H1\n<2015-06-25 +1w>
  1735. "
  1736. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1737. (org-clone-subtree-with-time-shift 1 "+2d")
  1738. (replace-regexp-in-string
  1739. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1740. nil nil 1))))
  1741. ;; Clone repeating once in backward.
  1742. (should
  1743. (equal "\
  1744. * H1\n<2015-06-21>
  1745. * H1\n<2015-06-19>
  1746. * H1\n<2015-06-17 +1w>
  1747. "
  1748. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1749. (org-clone-subtree-with-time-shift 1 "-2d")
  1750. (replace-regexp-in-string
  1751. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1752. nil nil 1))))
  1753. ;; Clone non-repeating zero times.
  1754. (should
  1755. (equal "\
  1756. * H1\n<2015-06-21>
  1757. "
  1758. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  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 repeating "zero" times.
  1764. (should
  1765. (equal "\
  1766. * H1\n<2015-06-21>
  1767. * H1\n<2015-06-23 +1w>
  1768. "
  1769. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1770. (org-clone-subtree-with-time-shift 0 "+2d")
  1771. (replace-regexp-in-string
  1772. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1773. nil nil 1))))
  1774. ;; Clone with blank SHIFT argument.
  1775. (should
  1776. (string-prefix-p
  1777. "* H <2012-03-29"
  1778. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1779. (org-clone-subtree-with-time-shift 1 "")
  1780. (buffer-substring-no-properties (line-beginning-position 2)
  1781. (line-end-position 2)))))
  1782. ;; Find time stamps before point. If SHIFT is not specified, ask
  1783. ;; for a time shift.
  1784. (should
  1785. (string-prefix-p
  1786. "* H <2012-03-30"
  1787. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1788. (org-clone-subtree-with-time-shift 1 "+1d")
  1789. (buffer-substring-no-properties (line-beginning-position 2)
  1790. (line-end-position 2)))))
  1791. (should
  1792. (string-prefix-p
  1793. "* H <2014-03-05"
  1794. (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
  1795. (cl-letf (((symbol-function 'read-from-minibuffer)
  1796. (lambda (&rest args) "+1d")))
  1797. (org-clone-subtree-with-time-shift 1))
  1798. (buffer-substring-no-properties (line-beginning-position 2)
  1799. (line-end-position 2)))))
  1800. ;; Hour shift.
  1801. (should
  1802. (equal "\
  1803. * H1\n<2015-06-21 20:00>
  1804. * H1\n<2015-06-21 23:00>
  1805. * H1\n<2015-06-22 02:00>
  1806. "
  1807. (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>"
  1808. (org-clone-subtree-with-time-shift 2 "+3h")
  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. (should
  1814. (equal "\
  1815. * H1\n<2015-06-21 20:00>
  1816. * H1\n<2015-06-21 18:00>
  1817. "
  1818. (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>"
  1819. (org-clone-subtree-with-time-shift 1 "-2h")
  1820. (replace-regexp-in-string
  1821. "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" ""
  1822. (buffer-substring-no-properties (point-min) (point-max))
  1823. nil nil 1)))))
  1824. ;;; Fixed-Width Areas
  1825. (ert-deftest test-org/toggle-fixed-width ()
  1826. "Test `org-toggle-fixed-width' specifications."
  1827. ;; No region: Toggle on fixed-width marker in paragraphs.
  1828. (should
  1829. (equal ": A"
  1830. (org-test-with-temp-text "A"
  1831. (org-toggle-fixed-width)
  1832. (buffer-string))))
  1833. ;; No region: Toggle off fixed-width markers in fixed-width areas.
  1834. (should
  1835. (equal "A"
  1836. (org-test-with-temp-text ": A"
  1837. (org-toggle-fixed-width)
  1838. (buffer-string))))
  1839. ;; No region: Toggle on marker in blank lines after elements or just
  1840. ;; after a headline.
  1841. (should
  1842. (equal "* H\n: "
  1843. (org-test-with-temp-text "* H\n"
  1844. (forward-line)
  1845. (org-toggle-fixed-width)
  1846. (buffer-string))))
  1847. (should
  1848. (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
  1849. (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
  1850. (goto-char (point-max))
  1851. (org-toggle-fixed-width)
  1852. (buffer-string))))
  1853. ;; No region: Toggle on marker in front of one line elements (e.g.,
  1854. ;; headlines, clocks)
  1855. (should
  1856. (equal ": * Headline"
  1857. (org-test-with-temp-text "* Headline"
  1858. (org-toggle-fixed-width)
  1859. (buffer-string))))
  1860. (should
  1861. (equal ": #+KEYWORD: value"
  1862. (org-test-with-temp-text "#+KEYWORD: value"
  1863. (org-toggle-fixed-width)
  1864. (buffer-string))))
  1865. ;; No region: error in other situations.
  1866. (should-error
  1867. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
  1868. (forward-line)
  1869. (org-toggle-fixed-width)
  1870. (buffer-string)))
  1871. ;; No region: Indentation is preserved.
  1872. (should
  1873. (equal "- A\n : B"
  1874. (org-test-with-temp-text "- A\n B"
  1875. (forward-line)
  1876. (org-toggle-fixed-width)
  1877. (buffer-string))))
  1878. ;; Region: If it contains only fixed-width elements and blank lines,
  1879. ;; toggle off fixed-width markup.
  1880. (should
  1881. (equal "A\n\nB"
  1882. (org-test-with-temp-text ": A\n\n: B"
  1883. (transient-mark-mode 1)
  1884. (push-mark (point) t t)
  1885. (goto-char (point-max))
  1886. (org-toggle-fixed-width)
  1887. (buffer-string))))
  1888. ;; Region: If it contains anything else, toggle on fixed-width but
  1889. ;; not on fixed-width areas.
  1890. (should
  1891. (equal ": A\n: \n: B\n: \n: C"
  1892. (org-test-with-temp-text "A\n\n: B\n\nC"
  1893. (transient-mark-mode 1)
  1894. (push-mark (point) t t)
  1895. (goto-char (point-max))
  1896. (org-toggle-fixed-width)
  1897. (buffer-string))))
  1898. ;; Region: Ignore blank lines at its end, unless it contains only
  1899. ;; such lines.
  1900. (should
  1901. (equal ": A\n\n"
  1902. (org-test-with-temp-text "A\n\n"
  1903. (transient-mark-mode 1)
  1904. (push-mark (point) t t)
  1905. (goto-char (point-max))
  1906. (org-toggle-fixed-width)
  1907. (buffer-string))))
  1908. (should
  1909. (equal ": \n: \n"
  1910. (org-test-with-temp-text "\n\n"
  1911. (transient-mark-mode 1)
  1912. (push-mark (point) t t)
  1913. (goto-char (point-max))
  1914. (org-toggle-fixed-width)
  1915. (buffer-string)))))
  1916. (ert-deftest test-org/kill-line ()
  1917. "Test `org-kill-line' specifications."
  1918. ;; At the beginning of a line, kill whole line.
  1919. (should
  1920. (equal ""
  1921. (org-test-with-temp-text "abc"
  1922. (org-kill-line)
  1923. (buffer-string))))
  1924. ;; In the middle of a line, kill line until its end.
  1925. (should
  1926. (equal "a"
  1927. (org-test-with-temp-text "a<point>bc"
  1928. (org-kill-line)
  1929. (buffer-string))))
  1930. ;; Do not kill newline character.
  1931. (should
  1932. (equal "\n123"
  1933. (org-test-with-temp-text "abc\n123"
  1934. (org-kill-line)
  1935. (buffer-string))))
  1936. (should
  1937. (equal "a\n123"
  1938. (org-test-with-temp-text "a<point>bc\n123"
  1939. (org-kill-line)
  1940. (buffer-string))))
  1941. ;; When `org-special-ctrl-k' is non-nil and point is at a headline,
  1942. ;; kill until tags.
  1943. (should
  1944. (equal "* A :tag:"
  1945. (org-test-with-temp-text "* A<point>B :tag:"
  1946. (let ((org-special-ctrl-k t)
  1947. (org-tags-column 0))
  1948. (org-kill-line))
  1949. (buffer-string))))
  1950. ;; If point is on tags, only kill part left until the end of line.
  1951. (should
  1952. (equal "* A :tag:"
  1953. (org-test-with-temp-text "* A :tag:<point>tag2:"
  1954. (let ((org-special-ctrl-k t)
  1955. (org-tags-column 0))
  1956. (org-kill-line))
  1957. (buffer-string))))
  1958. ;; However, if point is at the beginning of the line, kill whole
  1959. ;; headline.
  1960. (should
  1961. (equal ""
  1962. (org-test-with-temp-text "* AB :tag:"
  1963. (let ((org-special-ctrl-k t)
  1964. (org-tags-column 0))
  1965. (org-kill-line))
  1966. (buffer-string))))
  1967. ;; When `org-ctrl-k-protect-subtree' is non-nil, and point is in
  1968. ;; invisible text, ask before removing it. When set to `error',
  1969. ;; throw an error.
  1970. (should-error
  1971. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  1972. (org-overview)
  1973. (let ((org-special-ctrl-k nil)
  1974. (org-ctrl-k-protect-subtree t))
  1975. (cl-letf (((symbol-function 'y-or-n-p) 'ignore))
  1976. (org-kill-line)))))
  1977. (should-error
  1978. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  1979. (org-overview)
  1980. (let ((org-special-ctrl-k nil)
  1981. (org-ctrl-k-protect-subtree 'error))
  1982. (org-kill-line)))))
  1983. ;;; Headline
  1984. (ert-deftest test-org/get-heading ()
  1985. "Test `org-get-heading' specifications."
  1986. ;; Return current heading, even if point is not on it.
  1987. (should
  1988. (equal "H"
  1989. (org-test-with-temp-text "* H"
  1990. (org-get-heading))))
  1991. (should
  1992. (equal "H"
  1993. (org-test-with-temp-text "* H\nText<point>"
  1994. (org-get-heading))))
  1995. ;; Without any optional argument, return TODO keyword, priority
  1996. ;; cookie, COMMENT keyword and tags.
  1997. (should
  1998. (equal "TODO H"
  1999. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2000. (org-get-heading))))
  2001. (should
  2002. (equal "[#A] H"
  2003. (org-test-with-temp-text "* [#A] H"
  2004. (org-get-heading))))
  2005. (should
  2006. (equal "COMMENT H"
  2007. (org-test-with-temp-text "* COMMENT H"
  2008. (org-get-heading))))
  2009. (should
  2010. (equal "H :tag:"
  2011. (org-test-with-temp-text "* H :tag:"
  2012. (org-get-heading))))
  2013. ;; With NO-TAGS argument, ignore tags.
  2014. (should
  2015. (equal "TODO H"
  2016. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2017. (org-get-heading t))))
  2018. (should
  2019. (equal "H"
  2020. (org-test-with-temp-text "* H :tag:"
  2021. (org-get-heading t))))
  2022. ;; With NO-TODO, ignore TODO keyword.
  2023. (should
  2024. (equal "H"
  2025. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2026. (org-get-heading nil t))))
  2027. (should
  2028. (equal "H :tag:"
  2029. (org-test-with-temp-text "* H :tag:"
  2030. (org-get-heading nil t))))
  2031. ;; TODO keywords are case-sensitive.
  2032. (should
  2033. (equal "Todo H"
  2034. (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
  2035. (org-get-heading nil t))))
  2036. ;; With NO-PRIORITY, ignore priority.
  2037. (should
  2038. (equal "H"
  2039. (org-test-with-temp-text "* [#A] H"
  2040. (org-get-heading nil nil t))))
  2041. (should
  2042. (equal "H"
  2043. (org-test-with-temp-text "* H"
  2044. (org-get-heading nil nil t))))
  2045. (should
  2046. (equal "TODO H"
  2047. (org-test-with-temp-text "* TODO [#A] H"
  2048. (org-get-heading nil nil t))))
  2049. ;; With NO-COMMENT, ignore COMMENT keyword.
  2050. (should
  2051. (equal "H"
  2052. (org-test-with-temp-text "* COMMENT H"
  2053. (org-get-heading nil nil nil t))))
  2054. (should
  2055. (equal "H"
  2056. (org-test-with-temp-text "* H"
  2057. (org-get-heading nil nil nil t))))
  2058. (should
  2059. (equal "TODO [#A] H"
  2060. (org-test-with-temp-text "* TODO [#A] COMMENT H"
  2061. (org-get-heading nil nil nil t))))
  2062. ;; On an empty headline, return value is consistent.
  2063. (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
  2064. (should (equal "" (org-test-with-temp-text "* " (org-get-heading t))))
  2065. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t))))
  2066. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t))))
  2067. (should
  2068. (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t)))))
  2069. (ert-deftest test-org/in-commented-heading-p ()
  2070. "Test `org-in-commented-heading-p' specifications."
  2071. ;; Commented headline.
  2072. (should
  2073. (org-test-with-temp-text "* COMMENT Headline\nBody"
  2074. (goto-char (point-max))
  2075. (org-in-commented-heading-p)))
  2076. ;; Commented ancestor.
  2077. (should
  2078. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  2079. (goto-char (point-max))
  2080. (org-in-commented-heading-p)))
  2081. ;; Comment keyword is case-sensitive.
  2082. (should-not
  2083. (org-test-with-temp-text "* Comment Headline\nBody"
  2084. (goto-char (point-max))
  2085. (org-in-commented-heading-p)))
  2086. ;; Keyword is standalone.
  2087. (should-not
  2088. (org-test-with-temp-text "* COMMENTHeadline\nBody"
  2089. (goto-char (point-max))
  2090. (org-in-commented-heading-p)))
  2091. ;; Optional argument.
  2092. (should-not
  2093. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  2094. (goto-char (point-max))
  2095. (org-in-commented-heading-p t))))
  2096. (ert-deftest test-org/in-archived-heading-p ()
  2097. "Test `org-in-archived-heading-p' specifications."
  2098. ;; Archived headline.
  2099. (should
  2100. (org-test-with-temp-text "* Headline :ARCHIVE:\nBody"
  2101. (goto-char (point-max))
  2102. (org-in-archived-heading-p)))
  2103. ;; Archived ancestor.
  2104. (should
  2105. (org-test-with-temp-text "* Headline :ARCHIVE:\n** Level 2\nBody"
  2106. (goto-char (point-max))
  2107. (org-in-archived-heading-p)))
  2108. ;; Optional argument.
  2109. (should-not
  2110. (org-test-with-temp-text "* Headline :ARCHIVE:\n** Level 2\nBody"
  2111. (goto-char (point-max))
  2112. (org-in-archived-heading-p t)))
  2113. ;; Archive tag containing ARCHIVE as substring
  2114. (should-not
  2115. (org-test-with-temp-text "* Headline :NOARCHIVE:\n** Level 2\nBody"
  2116. (goto-char (point-max))
  2117. (org-in-archived-heading-p))))
  2118. (ert-deftest test-org/entry-blocked-p ()
  2119. ;; Check other dependencies.
  2120. (should
  2121. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  2122. (let ((org-enforce-todo-dependencies t)
  2123. (org-blocker-hook
  2124. '(org-block-todo-from-children-or-siblings-or-parent)))
  2125. (org-entry-blocked-p))))
  2126. (should-not
  2127. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  2128. (let ((org-enforce-todo-dependencies t)
  2129. (org-blocker-hook
  2130. '(org-block-todo-from-children-or-siblings-or-parent)))
  2131. (org-entry-blocked-p))))
  2132. ;; Entry without a TODO keyword or with a DONE keyword cannot be
  2133. ;; blocked.
  2134. (should-not
  2135. (org-test-with-temp-text "* Blocked\n** TODO one"
  2136. (let ((org-enforce-todo-dependencies t)
  2137. (org-blocker-hook
  2138. '(org-block-todo-from-children-or-siblings-or-parent)))
  2139. (org-entry-blocked-p))))
  2140. (should-not
  2141. (org-test-with-temp-text "* DONE Blocked\n** TODO one"
  2142. (let ((org-enforce-todo-dependencies t)
  2143. (org-blocker-hook
  2144. '(org-block-todo-from-children-or-siblings-or-parent)))
  2145. (org-entry-blocked-p))))
  2146. ;; Follow :ORDERED: specifications.
  2147. (should
  2148. (org-test-with-temp-text
  2149. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
  2150. (let ((org-enforce-todo-dependencies t)
  2151. (org-blocker-hook
  2152. '(org-block-todo-from-children-or-siblings-or-parent)))
  2153. (org-entry-blocked-p))))
  2154. (should-not
  2155. (org-test-with-temp-text
  2156. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
  2157. (let ((org-enforce-todo-dependencies t)
  2158. (org-blocker-hook
  2159. '(org-block-todo-from-children-or-siblings-or-parent)))
  2160. (org-entry-blocked-p)))))
  2161. (ert-deftest test-org/get-outline-path ()
  2162. "Test `org-get-outline-path' specifications."
  2163. ;; Top-level headlines have no outline path.
  2164. (should-not
  2165. (org-test-with-temp-text "* H"
  2166. (org-get-outline-path)))
  2167. ;; Otherwise, outline path is the path leading to the headline.
  2168. (should
  2169. (equal '("H")
  2170. (org-test-with-temp-text "* H\n** S<point>"
  2171. (org-get-outline-path))))
  2172. ;; Find path even when point is not on a headline.
  2173. (should
  2174. (equal '("H")
  2175. (org-test-with-temp-text "* H\n** S\nText<point>"
  2176. (org-get-outline-path))))
  2177. ;; TODO keywords, tags and statistics cookies are ignored.
  2178. (should
  2179. (equal '("H")
  2180. (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
  2181. (org-get-outline-path))))
  2182. ;; Links are replaced with their description or their path.
  2183. (should
  2184. (equal '("Org")
  2185. (org-test-with-temp-text
  2186. "* [[https://orgmode.org][Org]]\n** S<point>"
  2187. (org-get-outline-path))))
  2188. (should
  2189. (equal '("https://orgmode.org")
  2190. (org-test-with-temp-text
  2191. "* [[https://orgmode.org]]\n** S<point>"
  2192. (org-get-outline-path))))
  2193. ;; When WITH-SELF is non-nil, include current heading.
  2194. (should
  2195. (equal '("H")
  2196. (org-test-with-temp-text "* H"
  2197. (org-get-outline-path t))))
  2198. (should
  2199. (equal '("H" "S")
  2200. (org-test-with-temp-text "* H\n** S\nText<point>"
  2201. (org-get-outline-path t))))
  2202. ;; Using cache is transparent to the user.
  2203. (should
  2204. (equal '("H")
  2205. (org-test-with-temp-text "* H\n** S<point>"
  2206. (setq org-outline-path-cache nil)
  2207. (org-get-outline-path nil t))))
  2208. ;; Do not corrupt cache when finding outline path in distant part of
  2209. ;; the buffer.
  2210. (should
  2211. (equal '("H2")
  2212. (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
  2213. (setq org-outline-path-cache nil)
  2214. (org-get-outline-path nil t)
  2215. (search-forward "S2")
  2216. (org-get-outline-path nil t))))
  2217. ;; Do not choke on empty headlines.
  2218. (should
  2219. (org-test-with-temp-text "* H\n** <point>"
  2220. (org-get-outline-path)))
  2221. (should
  2222. (org-test-with-temp-text "* \n** H<point>"
  2223. (org-get-outline-path))))
  2224. (ert-deftest test-org/format-outline-path ()
  2225. "Test `org-format-outline-path' specifications."
  2226. (should
  2227. (string= (org-format-outline-path (list "one" "two" "three"))
  2228. "one/two/three"))
  2229. ;; Empty path.
  2230. (should
  2231. (string= (org-format-outline-path '())
  2232. ""))
  2233. (should
  2234. (string= (org-format-outline-path '(nil))
  2235. ""))
  2236. ;; Empty path and prefix.
  2237. (should
  2238. (string= (org-format-outline-path '() nil ">>")
  2239. ">>"))
  2240. ;; Trailing whitespace in headings.
  2241. (should
  2242. (string= (org-format-outline-path (list "one\t" "tw o " "three "))
  2243. "one/tw o/three"))
  2244. ;; Non-default prefix and separators.
  2245. (should
  2246. (string= (org-format-outline-path (list "one" "two" "three") nil ">>" "|")
  2247. ">>|one|two|three"))
  2248. ;; Truncate.
  2249. (should
  2250. (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
  2251. "one/two/.."))
  2252. ;; Give a very narrow width.
  2253. (should
  2254. (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
  2255. "on"))
  2256. ;; Give a prefix that extends beyond the width.
  2257. (should
  2258. (string= (org-format-outline-path (list "one" "two" "three" "four") 10
  2259. ">>>>>>>>>>")
  2260. ">>>>>>>>..")))
  2261. (ert-deftest test-org/map-entries ()
  2262. "Test `org-map-entries' specifications."
  2263. ;; Full match.
  2264. (should
  2265. (equal '(1 11)
  2266. (org-test-with-temp-text "* Level 1\n** Level 2"
  2267. (org-map-entries #'point))))
  2268. ;; Level match.
  2269. (should
  2270. (equal '(1)
  2271. (org-test-with-temp-text "* Level 1\n** Level 2"
  2272. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL=1")))))
  2273. (should
  2274. (equal '(11)
  2275. (org-test-with-temp-text "* Level 1\n** Level 2"
  2276. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL>1")))))
  2277. ;; Tag match.
  2278. (should
  2279. (equal '(11)
  2280. (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
  2281. (org-map-entries #'point "yes"))))
  2282. (should
  2283. (equal '(14)
  2284. (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
  2285. (org-map-entries #'point "+yes-a"))))
  2286. (should
  2287. (equal '(11 23)
  2288. (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
  2289. (org-map-entries #'point "{yes?}"))))
  2290. ;; Priority match.
  2291. (should
  2292. (equal '(1)
  2293. (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
  2294. (org-map-entries #'point "PRIORITY=\"A\""))))
  2295. ;; Date match.
  2296. (should
  2297. (equal '(36)
  2298. (org-test-with-temp-text "
  2299. * H1
  2300. SCHEDULED: <2012-03-29 thu.>
  2301. * H2
  2302. SCHEDULED: <2014-03-04 tue.>"
  2303. (org-map-entries #'point "SCHEDULED=\"<2014-03-04 tue.>\""))))
  2304. (should
  2305. (equal '(2)
  2306. (org-test-with-temp-text "
  2307. * H1
  2308. SCHEDULED: <2012-03-29 thu.>
  2309. * H2
  2310. SCHEDULED: <2014-03-04 tue.>"
  2311. (org-map-entries #'point "SCHEDULED<\"<2013-01-01>\""))))
  2312. ;; Regular property match.
  2313. (should
  2314. (equal '(2)
  2315. (org-test-with-temp-text "
  2316. * H1
  2317. :PROPERTIES:
  2318. :TEST: 1
  2319. :END:
  2320. * H2
  2321. :PROPERTIES:
  2322. :TEST: 2
  2323. :END:"
  2324. (org-map-entries #'point "TEST=1"))))
  2325. ;; Multiple criteria.
  2326. (should
  2327. (equal '(23)
  2328. (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
  2329. (let (org-odd-levels-only
  2330. (org-use-tag-inheritance nil))
  2331. (org-map-entries #'point "yes+LEVEL=1")))))
  2332. ;; "or" criteria.
  2333. (should
  2334. (equal '(12 24)
  2335. (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
  2336. (let (org-odd-levels-only)
  2337. (org-map-entries #'point "LEVEL=2|no")))))
  2338. (should
  2339. (equal '(1 12)
  2340. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
  2341. (let (org-odd-levels-only)
  2342. (org-map-entries #'point "yes|no")))))
  2343. ;; "and" criteria.
  2344. (should
  2345. (equal '(22)
  2346. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
  2347. (let (org-odd-levels-only)
  2348. (org-map-entries #'point "yes&no")))))
  2349. ;; Setting `org-map-continue-from'
  2350. (should
  2351. (string= ""
  2352. (org-test-with-temp-text "* H1\n* H2\n* H3n* H4"
  2353. (org-map-entries
  2354. (lambda ()
  2355. (org-cut-subtree)
  2356. (setq org-map-continue-from (point))))
  2357. (buffer-string))))
  2358. (should
  2359. (string= "* H1\n* H2\n* H3\n"
  2360. (org-test-with-temp-text "* H1\n* H2\n* H3\n* H4"
  2361. (org-map-entries
  2362. (lambda ()
  2363. (when (string= "H4"
  2364. (org-element-property
  2365. :raw-value (org-element-at-point)))
  2366. (org-cut-subtree)
  2367. (setq org-map-continue-from
  2368. (org-element-property
  2369. :begin (org-element-at-point))))))
  2370. (buffer-string)))))
  2371. (ert-deftest test-org/edit-headline ()
  2372. "Test `org-edit-headline' specifications."
  2373. (should
  2374. (equal "* B"
  2375. (org-test-with-temp-text "* A"
  2376. (org-edit-headline "B")
  2377. (buffer-string))))
  2378. ;; Handle empty headings.
  2379. (should
  2380. (equal "* "
  2381. (org-test-with-temp-text "* A"
  2382. (org-edit-headline "")
  2383. (buffer-string))))
  2384. (should
  2385. (equal "* A"
  2386. (org-test-with-temp-text "* "
  2387. (org-edit-headline "A")
  2388. (buffer-string))))
  2389. ;; Handle TODO keywords and priority cookies.
  2390. (should
  2391. (equal "* TODO B"
  2392. (org-test-with-temp-text "* TODO A"
  2393. (org-edit-headline "B")
  2394. (buffer-string))))
  2395. (should
  2396. (equal "* [#A] B"
  2397. (org-test-with-temp-text "* [#A] A"
  2398. (org-edit-headline "B")
  2399. (buffer-string))))
  2400. (should
  2401. (equal "* TODO [#A] B"
  2402. (org-test-with-temp-text "* TODO [#A] A"
  2403. (org-edit-headline "B")
  2404. (buffer-string))))
  2405. ;; Handle tags.
  2406. (equal "* B :tag:"
  2407. (org-test-with-temp-text "* A :tag:"
  2408. (let ((org-tags-column 4)) (org-edit-headline "B"))
  2409. (buffer-string))))
  2410. ;;; Keywords
  2411. (ert-deftest test-org/set-regexps-and-options ()
  2412. "Test `org-set-regexps-and-options' specifications."
  2413. ;; TAGS keyword.
  2414. (should
  2415. (equal '(("A"))
  2416. (let ((org-tag-alist '(("A")))
  2417. (org-tag-persistent-alist nil))
  2418. (org-test-with-temp-text ""
  2419. (org-mode-restart)
  2420. org-current-tag-alist))))
  2421. (should
  2422. (equal '(("B"))
  2423. (let ((org-tag-alist '(("A")))
  2424. (org-tag-persistent-alist nil))
  2425. (org-test-with-temp-text "#+TAGS: B"
  2426. (org-mode-restart)
  2427. org-current-tag-alist))))
  2428. (should
  2429. (equal '(("C") ("B"))
  2430. (let ((org-tag-alist '(("A")))
  2431. (org-tag-persistent-alist '(("C"))))
  2432. (org-test-with-temp-text "#+TAGS: B"
  2433. (org-mode-restart)
  2434. org-current-tag-alist))))
  2435. (should
  2436. (equal '(("B"))
  2437. (let ((org-tag-alist '(("A")))
  2438. (org-tag-persistent-alist '(("C"))))
  2439. (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
  2440. (org-mode-restart)
  2441. org-current-tag-alist))))
  2442. (should
  2443. (equal '(("A" . ?a) ("B") ("C"))
  2444. (let ((org-tag-persistant-alist nil))
  2445. (org-test-with-temp-text "#+TAGS: A(a) B C"
  2446. (org-mode-restart)
  2447. org-current-tag-alist))))
  2448. (should
  2449. (equal '(("A") (:newline) ("B"))
  2450. (let ((org-tag-persistent-alist nil))
  2451. (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
  2452. (org-mode-restart)
  2453. org-current-tag-alist))))
  2454. (should
  2455. (equal '((:startgroup) ("A") ("B") (:endgroup) ("C"))
  2456. (let ((org-tag-persistent-alist nil))
  2457. (org-test-with-temp-text "#+TAGS: { A B } C"
  2458. (org-mode-restart)
  2459. org-current-tag-alist))))
  2460. (should
  2461. (equal '((:startgroup) ("A") (:grouptags) ("B") ("C") (:endgroup))
  2462. (let ((org-tag-persistent-alist nil))
  2463. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2464. (org-mode-restart)
  2465. org-current-tag-alist))))
  2466. (should
  2467. (equal '(("A" "B" "C"))
  2468. (let ((org-tag-persistent-alist nil))
  2469. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2470. (org-mode-restart)
  2471. org-tag-groups-alist))))
  2472. (should
  2473. (equal '((:startgrouptag) ("A") (:grouptags) ("B") ("C") (:endgrouptag))
  2474. (let ((org-tag-persistent-alist nil))
  2475. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2476. (org-mode-restart)
  2477. org-current-tag-alist))))
  2478. (should
  2479. (equal '(("A" "B" "C"))
  2480. (let ((org-tag-persistent-alist nil))
  2481. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2482. (org-mode-restart)
  2483. org-tag-groups-alist))))
  2484. (should-not
  2485. (let ((org-tag-alist '(("A"))))
  2486. (org-test-with-temp-text "#+TAGS:"
  2487. (org-mode-restart)
  2488. org-current-tag-alist)))
  2489. ;; FILETAGS keyword.
  2490. (should
  2491. (equal '("A" "B" "C")
  2492. (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
  2493. (org-mode-restart)
  2494. org-file-tags)))
  2495. ;; PROPERTY keyword. Property names are case-insensitive.
  2496. (should
  2497. (equal "foo=1"
  2498. (org-test-with-temp-text "#+PROPERTY: var foo=1"
  2499. (org-mode-restart)
  2500. (cdr (assoc "var" org-keyword-properties)))))
  2501. (should
  2502. (equal
  2503. "foo=1 bar=2"
  2504. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
  2505. (org-mode-restart)
  2506. (cdr (assoc "var" org-keyword-properties)))))
  2507. (should
  2508. (equal
  2509. "foo=1 bar=2"
  2510. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
  2511. (org-mode-restart)
  2512. (cdr (assoc "var" org-keyword-properties)))))
  2513. ;; ARCHIVE keyword.
  2514. (should
  2515. (equal "%s_done::"
  2516. (org-test-with-temp-text "#+ARCHIVE: %s_done::"
  2517. (org-mode-restart)
  2518. org-archive-location)))
  2519. ;; CATEGORY keyword.
  2520. (should
  2521. (eq 'test
  2522. (org-test-with-temp-text "#+CATEGORY: test"
  2523. (org-mode-restart)
  2524. org-category)))
  2525. (should
  2526. (equal "test"
  2527. (org-test-with-temp-text "#+CATEGORY: test"
  2528. (org-mode-restart)
  2529. (cdr (assoc "CATEGORY" org-keyword-properties)))))
  2530. ;; COLUMNS keyword.
  2531. (should
  2532. (equal "%25ITEM %TAGS %PRIORITY %TODO"
  2533. (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
  2534. (org-mode-restart)
  2535. org-columns-default-format)))
  2536. ;; CONSTANTS keyword. Constants names are case sensitive.
  2537. (should
  2538. (equal '("299792458." "3.14")
  2539. (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
  2540. (org-mode-restart)
  2541. (mapcar
  2542. (lambda (n) (cdr (assoc n org-table-formula-constants-local)))
  2543. '("c" "pi")))))
  2544. (should
  2545. (equal "3.14"
  2546. (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
  2547. (org-mode-restart)
  2548. (cdr (assoc "pi" org-table-formula-constants-local)))))
  2549. (should
  2550. (equal "22/7"
  2551. (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
  2552. (org-mode-restart)
  2553. (cdr (assoc "PI" org-table-formula-constants-local)))))
  2554. ;; LINK keyword.
  2555. (should
  2556. (equal
  2557. '("url1" "url2")
  2558. (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
  2559. (org-mode-restart)
  2560. (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local)))
  2561. '("a" "b")))))
  2562. ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
  2563. (should
  2564. (equal
  2565. '(?X ?Z ?Y)
  2566. (org-test-with-temp-text "#+PRIORITIES: X Z Y"
  2567. (org-mode-restart)
  2568. (list org-priority-highest org-priority-lowest org-priority-default))))
  2569. (should
  2570. (equal
  2571. '(?A ?C ?B)
  2572. (org-test-with-temp-text "#+PRIORITIES: X Z"
  2573. (org-mode-restart)
  2574. (list org-priority-highest org-priority-lowest org-priority-default))))
  2575. ;; STARTUP keyword.
  2576. (should
  2577. (equal '(t t)
  2578. (org-test-with-temp-text "#+STARTUP: fold odd"
  2579. (org-mode-restart)
  2580. (list org-startup-folded org-odd-levels-only))))
  2581. ;; TODO keywords.
  2582. (should
  2583. (equal '(("A" "B") ("C"))
  2584. (org-test-with-temp-text "#+TODO: A B | C"
  2585. (org-mode-restart)
  2586. (list org-not-done-keywords org-done-keywords))))
  2587. (should
  2588. (equal '(("A" "C") ("B" "D"))
  2589. (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
  2590. (org-mode-restart)
  2591. (list org-not-done-keywords org-done-keywords))))
  2592. (should
  2593. (equal '(("A" "B") ("C"))
  2594. (org-test-with-temp-text "#+TYP_TODO: A B | C"
  2595. (org-mode-restart)
  2596. (list org-not-done-keywords org-done-keywords))))
  2597. (should
  2598. (equal '((:startgroup) ("A" . ?a) (:endgroup))
  2599. (org-test-with-temp-text "#+TODO: A(a)"
  2600. (org-mode-restart)
  2601. org-todo-key-alist)))
  2602. (should
  2603. (equal '(("D" note nil) ("C" time nil) ("B" note time))
  2604. (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
  2605. (org-mode-restart)
  2606. org-todo-log-states)))
  2607. ;; Enter SETUPFILE keyword.
  2608. (should
  2609. (equal "1"
  2610. (org-test-with-temp-text
  2611. (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
  2612. (org-mode-restart)
  2613. (cdr (assoc "a" org-keyword-properties))))))
  2614. (ert-deftest test-org/collect-keywords ()
  2615. "Test `org-collect-keywords'."
  2616. (should-not
  2617. (org-test-with-temp-text "#+begin_example\n#+foo: bar\n#+end_example"
  2618. (org-collect-keywords '("FOO")))))
  2619. ;;; Links
  2620. ;;;; Coderefs
  2621. (ert-deftest test-org/coderef ()
  2622. "Test coderef links specifications."
  2623. (should
  2624. (org-test-with-temp-text "
  2625. #+BEGIN_SRC emacs-lisp
  2626. \(+ 1 1) (ref:sc)
  2627. #+END_SRC
  2628. \[[(sc)<point>]]"
  2629. (org-open-at-point)
  2630. (looking-at "(ref:sc)")))
  2631. ;; Find coderef even with alternate label format.
  2632. (should
  2633. (org-test-with-temp-text "
  2634. #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
  2635. \(+ 1 1) {ref:sc}
  2636. #+END_SRC
  2637. \[[(sc)<point>]]"
  2638. (org-open-at-point)
  2639. (looking-at "{ref:sc}"))))
  2640. ;;;; Custom ID
  2641. (ert-deftest test-org/custom-id ()
  2642. "Test custom ID links specifications."
  2643. (should
  2644. (org-test-with-temp-text
  2645. "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2646. (org-open-at-point)
  2647. (looking-at-p "\\* H1")))
  2648. ;; Handle escape characters.
  2649. (should
  2650. (org-test-with-temp-text
  2651. "* H1\n:PROPERTIES:\n:CUSTOM_ID: [%]\n:END:\n* H2\n[[#\\[%\\]<point>]]"
  2652. (org-open-at-point)
  2653. (looking-at-p "\\* H1")))
  2654. ;; Throw an error on false positives.
  2655. (should-error
  2656. (org-test-with-temp-text
  2657. "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2658. (org-open-at-point)
  2659. (looking-at-p "\\* H1"))))
  2660. ;;;; Fuzzy Links
  2661. ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
  2662. ;; a named element (#+name: text) and to headlines (* Text).
  2663. (ert-deftest test-org/fuzzy-links ()
  2664. "Test fuzzy links specifications."
  2665. ;; Fuzzy link goes in priority to a matching target.
  2666. (should
  2667. (org-test-with-temp-text
  2668. "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
  2669. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2670. (looking-at "<<Test>>")))
  2671. ;; Then fuzzy link points to an element with a given name.
  2672. (should
  2673. (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
  2674. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2675. (looking-at "#\\+NAME: Test")))
  2676. ;; A target still lead to a matching headline otherwise.
  2677. (should
  2678. (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
  2679. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2680. (looking-at "\\* Head2")))
  2681. ;; With a leading star in link, enforce heading match.
  2682. (should
  2683. (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
  2684. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2685. (looking-at "\\* Test")))
  2686. ;; With a leading star in link, enforce exact heading match, even
  2687. ;; with `org-link-search-must-match-exact-headline' set to nil.
  2688. (should-error
  2689. (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
  2690. (let ((org-link-search-must-match-exact-headline nil))
  2691. (org-open-at-point))))
  2692. ;; Handle non-nil `org-link-search-must-match-exact-headline'.
  2693. (should
  2694. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
  2695. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2696. (looking-at "\\* Test")))
  2697. (should
  2698. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
  2699. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2700. (looking-at "\\* Test")))
  2701. ;; Heading match should not care about spaces, cookies, TODO
  2702. ;; keywords, priorities, and tags. However, TODO keywords are
  2703. ;; case-sensitive.
  2704. (should
  2705. (let ((first-line
  2706. "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
  2707. (org-test-with-temp-text
  2708. (concat first-line "\nFoo Bar\n<point>[[*Test 1 2]]")
  2709. (let ((org-link-search-must-match-exact-headline nil)
  2710. (org-todo-regexp "TODO"))
  2711. (org-open-at-point))
  2712. (looking-at (regexp-quote first-line)))))
  2713. (should-error
  2714. (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
  2715. (let ((org-link-search-must-match-exact-headline nil)
  2716. (org-todo-regexp "TODO"))
  2717. (org-open-at-point))))
  2718. ;; Heading match should still be exact.
  2719. (should-error
  2720. (org-test-with-temp-text "
  2721. ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
  2722. Foo Bar
  2723. <point>[[*Test 1]]"
  2724. (let ((org-link-search-must-match-exact-headline nil)
  2725. (org-todo-regexp "TODO"))
  2726. (org-open-at-point))))
  2727. (should
  2728. (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
  2729. (let ((org-link-search-must-match-exact-headline nil)
  2730. (org-todo-regexp "TODO"))
  2731. (org-open-at-point))
  2732. (looking-at-p (regexp-quote "** Test 1 2"))))
  2733. ;; Heading match ignores COMMENT keyword.
  2734. (should
  2735. (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
  2736. (org-open-at-point)
  2737. (looking-at "\\* COMMENT Test")))
  2738. (should
  2739. (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
  2740. (org-open-at-point)
  2741. (looking-at "\\* TODO COMMENT Test")))
  2742. ;; Correctly un-escape fuzzy links.
  2743. (should
  2744. (org-test-with-temp-text "* [foo]\n[[*\\[foo\\]][With escaped characters]]"
  2745. (org-open-at-point)
  2746. (bobp)))
  2747. ;; Match search strings containing newline characters, including
  2748. ;; blank lines.
  2749. (should
  2750. (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
  2751. (let ((file (buffer-file-name)))
  2752. (goto-char (point-max))
  2753. (insert (format "[[file:%s::line1 line2]]" file))
  2754. (beginning-of-line)
  2755. (let ((org-link-search-must-match-exact-headline nil))
  2756. (org-open-at-point 0))
  2757. (looking-at-p "line1"))))
  2758. (should
  2759. (org-test-with-temp-text-in-file "Paragraph\n\nline1\n\nline2\n\n"
  2760. (let ((file (buffer-file-name)))
  2761. (goto-char (point-max))
  2762. (insert (format "[[file:%s::line1 line2]]" file))
  2763. (beginning-of-line)
  2764. (let ((org-link-search-must-match-exact-headline nil))
  2765. (org-open-at-point 0))
  2766. (looking-at-p "line1")))))
  2767. ;;;; Open at point
  2768. (ert-deftest test-org/open-at-point/keyword ()
  2769. "Does `org-open-at-point' open link in a keyword line?"
  2770. (should
  2771. (org-test-with-temp-text
  2772. "<<top>>\n#+KEYWORD: <point>[[top]]"
  2773. (org-open-at-point) t))
  2774. (should
  2775. (org-test-with-temp-text
  2776. "* H\n<<top>>\n#+KEYWORD: <point>[[top]]"
  2777. (org-open-at-point) t)))
  2778. (ert-deftest test-org/open-at-point/property ()
  2779. "Does `org-open-at-point' open link in property drawer?"
  2780. (should
  2781. (org-test-with-temp-text
  2782. "* Headline
  2783. :PROPERTIES:
  2784. :URL: <point>[[*Headline]]
  2785. :END:"
  2786. (org-open-at-point) t)))
  2787. (ert-deftest test-org/open-at-point/comment ()
  2788. "Does `org-open-at-point' open link in a commented line?"
  2789. (should
  2790. (org-test-with-temp-text
  2791. "<<top>>\n# <point>[[top]]"
  2792. (org-open-at-point) t))
  2793. (should
  2794. (org-test-with-temp-text
  2795. "* H\n<<top>>\n# <point>[[top]]"
  2796. (org-open-at-point) t)))
  2797. (ert-deftest test-org/open-at-point/inline-image ()
  2798. "Test `org-open-at-point' on nested links."
  2799. (should
  2800. (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
  2801. (org-open-at-point)
  2802. (bobp))))
  2803. (ert-deftest test-org/open-at-point/radio-target ()
  2804. "Test `org-open-at-point' on radio targets."
  2805. (should
  2806. (org-test-with-temp-text "<<<target>>> <point>target"
  2807. (org-update-radio-target-regexp)
  2808. (org-open-at-point)
  2809. (eq (org-element-type (org-element-context)) 'radio-target))))
  2810. (ert-deftest test-org/open-at-point/tag ()
  2811. "Test `org-open-at-point' on tags."
  2812. (should
  2813. (org-test-with-temp-text "* H :<point>tag:"
  2814. (catch :result
  2815. (cl-letf (((symbol-function 'org-tags-view)
  2816. (lambda (&rest args) (throw :result t))))
  2817. (org-open-at-point)
  2818. nil))))
  2819. (should-not
  2820. (org-test-with-temp-text-in-file "* H<point> :tag:"
  2821. (catch :result
  2822. (cl-letf (((symbol-function 'org-tags-view)
  2823. (lambda (&rest args) (throw :result t))))
  2824. ;; When point isn't on a tag it's going to try other things,
  2825. ;; possibly trying to open attachments which will return an
  2826. ;; error if there isn't an attachment. Suppress that error.
  2827. (ignore-errors
  2828. (org-open-at-point))
  2829. nil)))))
  2830. ;;; Node Properties
  2831. (ert-deftest test-org/accumulated-properties-in-drawers ()
  2832. "Ensure properties accumulate in subtree drawers."
  2833. (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
  2834. (org-babel-next-src-block)
  2835. (should (equal '(2 1) (org-babel-execute-src-block)))))
  2836. (ert-deftest test-org/custom-properties ()
  2837. "Test custom properties specifications."
  2838. ;; Standard test.
  2839. (should
  2840. (let ((org-custom-properties '("FOO")))
  2841. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2842. (org-toggle-custom-properties-visibility)
  2843. (org-invisible-p2))))
  2844. ;; Properties are case-insensitive.
  2845. (should
  2846. (let ((org-custom-properties '("FOO")))
  2847. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
  2848. (org-toggle-custom-properties-visibility)
  2849. (org-invisible-p2))))
  2850. (should
  2851. (let ((org-custom-properties '("foo")))
  2852. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2853. (org-toggle-custom-properties-visibility)
  2854. (org-invisible-p2))))
  2855. ;; Multiple custom properties in the same drawer.
  2856. (should
  2857. (let ((org-custom-properties '("FOO" "BAR")))
  2858. (org-test-with-temp-text
  2859. "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
  2860. (org-toggle-custom-properties-visibility)
  2861. (and (org-invisible-p2)
  2862. (not (progn (forward-line) (org-invisible-p2)))
  2863. (progn (forward-line) (org-invisible-p2))))))
  2864. ;; Hide custom properties with an empty value.
  2865. (should
  2866. (let ((org-custom-properties '("FOO")))
  2867. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
  2868. (org-toggle-custom-properties-visibility)
  2869. (org-invisible-p2))))
  2870. ;; Do not hide fake properties.
  2871. (should-not
  2872. (let ((org-custom-properties '("FOO")))
  2873. (org-test-with-temp-text ":FOO: val\n"
  2874. (org-toggle-custom-properties-visibility)
  2875. (org-invisible-p2))))
  2876. (should-not
  2877. (let ((org-custom-properties '("A")))
  2878. (org-test-with-temp-text
  2879. "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
  2880. (org-toggle-custom-properties-visibility)
  2881. (org-invisible-p2)))))
  2882. ;;; Mark Region
  2883. (ert-deftest test-org/mark-element ()
  2884. "Test `org-mark-element' specifications."
  2885. ;; Mark beginning and end of element.
  2886. (should
  2887. (equal '(t t)
  2888. (org-test-with-temp-text "Para<point>graph"
  2889. (org-mark-element)
  2890. (list (bobp) (= (mark) (point-max))))))
  2891. (should
  2892. (equal '(t t)
  2893. (org-test-with-temp-text "P1\n\nPara<point>graph\n\nP2"
  2894. (org-mark-element)
  2895. (list (looking-at "Paragraph")
  2896. (org-with-point-at (mark) (looking-at "P2"))))))
  2897. ;; Do not set mark past (point-max).
  2898. (should
  2899. (org-test-with-temp-text "Para<point>graph"
  2900. (narrow-to-region 2 6)
  2901. (org-mark-element)
  2902. (= 6 (mark)))))
  2903. (ert-deftest test-org/mark-subtree ()
  2904. "Test `org-mark-subtree' specifications."
  2905. ;; Error when point is before first headline.
  2906. (should-error
  2907. (org-test-with-temp-text "Paragraph\n* Headline\nBody"
  2908. (progn (transient-mark-mode 1)
  2909. (org-mark-subtree))))
  2910. ;; Without argument, mark current subtree.
  2911. (should
  2912. (equal
  2913. '(12 32)
  2914. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  2915. (progn (transient-mark-mode 1)
  2916. (forward-line 2)
  2917. (org-mark-subtree)
  2918. (list (region-beginning) (region-end))))))
  2919. ;; With an argument, move ARG up.
  2920. (should
  2921. (equal
  2922. '(1 32)
  2923. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  2924. (progn (transient-mark-mode 1)
  2925. (forward-line 2)
  2926. (org-mark-subtree 1)
  2927. (list (region-beginning) (region-end))))))
  2928. ;; Do not get fooled by inlinetasks.
  2929. (when (featurep 'org-inlinetask)
  2930. (should
  2931. (= 1
  2932. (org-test-with-temp-text "* Headline\n*************** Task\nContents"
  2933. (progn (transient-mark-mode 1)
  2934. (forward-line 1)
  2935. (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
  2936. (region-beginning)))))))
  2937. ;;; Miscellaneous
  2938. (ert-deftest test-org/sort-entries ()
  2939. "Test `org-sort-entries'."
  2940. ;; Sort alphabetically.
  2941. (should
  2942. (equal "\n* abc\n* def\n* xyz\n"
  2943. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  2944. (org-sort-entries nil ?a)
  2945. (buffer-string))))
  2946. (should
  2947. (equal "\n* xyz\n* def\n* abc\n"
  2948. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  2949. (org-sort-entries nil ?A)
  2950. (buffer-string))))
  2951. (should
  2952. (equal "\n* \n* klm\n* xyz\n"
  2953. (org-test-with-temp-text "\n* xyz\n* \n* klm\n"
  2954. (org-sort-entries nil ?a)
  2955. (buffer-string))))
  2956. ;; Sort numerically.
  2957. (should
  2958. (equal "\n* 1\n* 2\n* 10\n"
  2959. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  2960. (org-sort-entries nil ?n)
  2961. (buffer-string))))
  2962. (should
  2963. (equal "\n* 10\n* 2\n* 1\n"
  2964. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  2965. (org-sort-entries nil ?N)
  2966. (buffer-string))))
  2967. (should
  2968. (equal "\n* \n* 1\n* 2\n"
  2969. (org-test-with-temp-text "\n* 1\n* \n* 2\n"
  2970. (org-sort-entries nil ?n)
  2971. (buffer-string))))
  2972. ;; Sort by custom function.
  2973. (should
  2974. (equal "\n* b\n* aa\n* ccc\n"
  2975. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  2976. (org-sort-entries nil ?f
  2977. (lambda ()
  2978. (length (buffer-substring (point-at-bol)
  2979. (point-at-eol))))
  2980. #'<)
  2981. (buffer-string))))
  2982. (should
  2983. (equal "\n* ccc\n* aa\n* b\n"
  2984. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  2985. (org-sort-entries nil ?F
  2986. (lambda ()
  2987. (length (buffer-substring (point-at-bol)
  2988. (point-at-eol))))
  2989. #'<)
  2990. (buffer-string))))
  2991. ;; Sort by TODO keyword.
  2992. (should
  2993. (equal "\n* TODO h1\n* TODO h3\n* DONE h2\n"
  2994. (org-test-with-temp-text
  2995. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  2996. (org-sort-entries nil ?o)
  2997. (buffer-string))))
  2998. (should
  2999. (equal "\n* DONE h2\n* TODO h1\n* TODO h3\n"
  3000. (org-test-with-temp-text
  3001. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  3002. (org-sort-entries nil ?O)
  3003. (buffer-string))))
  3004. ;; Sort by priority.
  3005. (should
  3006. (equal "\n* [#A] h2\n* [#B] h3\n* [#C] h1\n"
  3007. (org-test-with-temp-text
  3008. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  3009. (org-sort-entries nil ?p)
  3010. (buffer-string))))
  3011. (should
  3012. (equal "\n* [#C] h1\n* [#B] h3\n* [#A] h2\n"
  3013. (org-test-with-temp-text
  3014. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  3015. (org-sort-entries nil ?P)
  3016. (buffer-string))))
  3017. ;; Sort by creation time.
  3018. (should
  3019. (equal "
  3020. * h3
  3021. [2017-05-08 Mon]
  3022. * h2
  3023. [2017-05-09 Tue]
  3024. * h1
  3025. [2018-05-09 Wed]
  3026. "
  3027. (org-test-with-temp-text
  3028. "
  3029. * h1
  3030. [2018-05-09 Wed]
  3031. * h2
  3032. [2017-05-09 Tue]
  3033. * h3
  3034. [2017-05-08 Mon]
  3035. "
  3036. (org-sort-entries nil ?c)
  3037. (buffer-string))))
  3038. ;; Sort by scheduled date.
  3039. (should
  3040. (equal "
  3041. * TODO h4
  3042. SCHEDULED: <2017-05-06 Sat>
  3043. * TODO h3
  3044. SCHEDULED: <2017-05-08 Mon>
  3045. * TODO h2
  3046. DEADLINE: <2017-05-09 Tue>
  3047. * TODO h1
  3048. DEADLINE: <2017-05-07 Sun>
  3049. "
  3050. (org-test-with-temp-text
  3051. "
  3052. * TODO h2
  3053. DEADLINE: <2017-05-09 Tue>
  3054. * TODO h1
  3055. DEADLINE: <2017-05-07 Sun>
  3056. * TODO h3
  3057. SCHEDULED: <2017-05-08 Mon>
  3058. * TODO h4
  3059. SCHEDULED: <2017-05-06 Sat>
  3060. "
  3061. (org-sort-entries nil ?s)
  3062. (buffer-string))))
  3063. ;; Sort by deadline date.
  3064. (should
  3065. (equal "
  3066. * TODO h1
  3067. DEADLINE: <2017-05-07 Sun>
  3068. * TODO h2
  3069. DEADLINE: <2017-05-09 Tue>
  3070. * TODO h3
  3071. SCHEDULED: <2017-05-08 Mon>
  3072. * TODO h4
  3073. SCHEDULED: <2017-05-06 Sat>
  3074. "
  3075. (org-test-with-temp-text
  3076. "
  3077. * TODO h2
  3078. DEADLINE: <2017-05-09 Tue>
  3079. * TODO h1
  3080. DEADLINE: <2017-05-07 Sun>
  3081. * TODO h3
  3082. SCHEDULED: <2017-05-08 Mon>
  3083. * TODO h4
  3084. SCHEDULED: <2017-05-06 Sat>
  3085. "
  3086. (org-sort-entries nil ?d)
  3087. (buffer-string))))
  3088. ;; Sort by any date/time
  3089. (should
  3090. (equal "
  3091. * TODO h4
  3092. SCHEDULED: <2017-05-06 Sat>
  3093. * TODO h1
  3094. DEADLINE: <2017-05-07 Sun>
  3095. * TODO h3
  3096. SCHEDULED: <2017-05-08 Mon>
  3097. * TODO h2
  3098. DEADLINE: <2017-05-09 Tue>
  3099. "
  3100. (org-test-with-temp-text
  3101. "
  3102. * TODO h2
  3103. DEADLINE: <2017-05-09 Tue>
  3104. * TODO h1
  3105. DEADLINE: <2017-05-07 Sun>
  3106. * TODO h3
  3107. SCHEDULED: <2017-05-08 Mon>
  3108. * TODO h4
  3109. SCHEDULED: <2017-05-06 Sat>
  3110. "
  3111. (org-sort-entries nil ?t)
  3112. (buffer-string))))
  3113. ;; Sort by clocking time.
  3114. (should
  3115. (equal "
  3116. * clocked h2
  3117. :LOGBOOK:
  3118. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3119. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  3120. :END:
  3121. * clocked h1
  3122. :LOGBOOK:
  3123. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3124. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  3125. :END:
  3126. "
  3127. (org-test-with-temp-text
  3128. "
  3129. * clocked h1
  3130. :LOGBOOK:
  3131. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3132. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  3133. :END:
  3134. * clocked h2
  3135. :LOGBOOK:
  3136. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3137. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  3138. :END:
  3139. "
  3140. (org-sort-entries nil ?k)
  3141. (buffer-string))))
  3142. ;; Preserve file local variables when sorting.
  3143. (should
  3144. (equal "\n* A\n* B\n# Local Variables:\n# foo: t\n# End:\n"
  3145. (org-test-with-temp-text
  3146. "\n* B\n* A\n# Local Variables:\n# foo: t\n# End:"
  3147. (org-sort-entries nil ?a)
  3148. (buffer-string)))))
  3149. (ert-deftest test-org/string-collate-greaterp ()
  3150. "Test `org-string-collate-greaterp' specifications."
  3151. (should (org-string-collate-greaterp "def" "abc"))
  3152. (should-not (org-string-collate-greaterp "abc" "def")))
  3153. (ert-deftest test-org/file-contents ()
  3154. "Test `org-file-contents' specifications."
  3155. ;; Open files.
  3156. (should
  3157. (string= "#+BIND: variable value
  3158. #+DESCRIPTION: l2
  3159. #+LANGUAGE: en
  3160. #+SELECT_TAGS: b
  3161. #+TITLE: b
  3162. #+PROPERTY: a 1
  3163. " (org-file-contents (expand-file-name "setupfile3.org"
  3164. (concat org-test-dir "examples/")))))
  3165. ;; Throw error when trying to access an invalid file.
  3166. (should-error (org-file-contents "this-file-must-not-exist"))
  3167. ;; Try to access an invalid file, but do not throw an error.
  3168. (should
  3169. (progn (org-file-contents "this-file-must-not-exist" :noerror) t))
  3170. ;; Open URL.
  3171. (should
  3172. (string= "foo"
  3173. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3174. (unwind-protect
  3175. ;; Simulate successful retrieval of a URL.
  3176. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3177. (lambda (&rest_)
  3178. (with-current-buffer buffer
  3179. (insert "HTTP/1.1 200 OK\n\nfoo"))
  3180. buffer)))
  3181. (org-file-contents "http://some-valid-url"))
  3182. (kill-buffer buffer)))))
  3183. ;; Throw error when trying to access an invalid URL.
  3184. (should-error
  3185. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3186. (unwind-protect
  3187. ;; Simulate unsuccessful retrieval of a URL.
  3188. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3189. (lambda (&rest_)
  3190. (with-current-buffer buffer
  3191. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3192. buffer)))
  3193. (org-file-contents "http://this-url-must-not-exist"))
  3194. (kill-buffer buffer))))
  3195. ;; Try to access an invalid URL, but do not throw an error.
  3196. (should-error
  3197. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3198. (unwind-protect
  3199. ;; Simulate unsuccessful retrieval of a URL.
  3200. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3201. (lambda (&rest_)
  3202. (with-current-buffer buffer
  3203. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3204. buffer)))
  3205. (org-file-contents "http://this-url-must-not-exist"))
  3206. (kill-buffer buffer))))
  3207. (should
  3208. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3209. (unwind-protect
  3210. ;; Simulate unsuccessful retrieval of a URL.
  3211. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3212. (lambda (&rest_)
  3213. (with-current-buffer buffer
  3214. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3215. buffer)))
  3216. (org-file-contents "http://this-url-must-not-exist" :noerror))
  3217. (kill-buffer buffer))
  3218. t)))
  3219. ;;; Navigation
  3220. (ert-deftest test-org/next-visible-heading ()
  3221. "Test `org-next-visible-heading' specifications."
  3222. ;; Move to the beginning of the next headline, taking into
  3223. ;; consideration ARG.
  3224. (should
  3225. (org-test-with-temp-text "* H1\n* H2"
  3226. (org-next-visible-heading 1)
  3227. (looking-at "\\* H2")))
  3228. (should
  3229. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3230. (org-next-visible-heading 2)
  3231. (looking-at "\\* H3")))
  3232. ;; Ignore invisible headlines.
  3233. (should
  3234. (org-test-with-temp-text "* H1\n** H2\n* H3"
  3235. (org-cycle)
  3236. (org-next-visible-heading 1)
  3237. (looking-at "\\* H3")))
  3238. ;; Move point between headlines, not on blank lines between.
  3239. (should
  3240. (org-test-with-temp-text "* H1\n** H2\n\n\n\n* H3"
  3241. (let ((org-cycle-separator-lines 1))
  3242. (org-cycle)
  3243. (org-next-visible-heading 1))
  3244. (looking-at "\\* H3")))
  3245. ;; Move at end of buffer when there is no more headline.
  3246. (should
  3247. (org-test-with-temp-text "* H1"
  3248. (org-next-visible-heading 1)
  3249. (eobp)))
  3250. (should
  3251. (org-test-with-temp-text "* H1\n* H2"
  3252. (org-next-visible-heading 2)
  3253. (eobp)))
  3254. ;; With a negative argument, move backwards.
  3255. (should
  3256. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3257. (org-next-visible-heading -1)
  3258. (looking-at "\\* H2")))
  3259. (should
  3260. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3261. (org-next-visible-heading -2)
  3262. (looking-at "\\* H1"))))
  3263. (ert-deftest test-org/previous-visible-heading ()
  3264. "Test `org-previous-visible-heading' specifications."
  3265. ;; Move to the beginning of the next headline, taking into
  3266. ;; consideration ARG.
  3267. (should
  3268. (org-test-with-temp-text "* H1\n<point>* H2"
  3269. (org-previous-visible-heading 1)
  3270. (looking-at "\\* H1")))
  3271. (should
  3272. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3273. (org-previous-visible-heading 2)
  3274. (looking-at "\\* H1")))
  3275. ;; Ignore invisible headlines.
  3276. (should
  3277. (org-test-with-temp-text "* H1\n** H2\n<point>* H3"
  3278. (org-overview)
  3279. (org-previous-visible-heading 1)
  3280. (looking-at "\\* H1")))
  3281. ;; Move point between headlines, not on blank lines between.
  3282. (should
  3283. (org-test-with-temp-text "* H1\n\n\n\n** H2\n<point>* H3"
  3284. (let ((org-cycle-separator-lines 1))
  3285. (org-overview)
  3286. (org-previous-visible-heading 1))
  3287. (looking-at "\\* H1")))
  3288. ;; Move at end of buffer when there is no more headline.
  3289. (should
  3290. (org-test-with-temp-text "* H1"
  3291. (org-previous-visible-heading 1)
  3292. (bobp)))
  3293. (should
  3294. (org-test-with-temp-text "* H1\n* <point>H2"
  3295. (org-previous-visible-heading 2)
  3296. (bobp)))
  3297. ;; Invisible parts may not start at a headline, i.e., when revealing
  3298. ;; parts of the buffer. Handle this.
  3299. (should
  3300. (org-test-with-temp-text "* Main\n** H1\nFoo\n** H2\nBar\n** H3\nBaz"
  3301. (org-overview)
  3302. (search-forward "H1")
  3303. (org-show-context 'minimal)
  3304. (org-cycle)
  3305. (search-forward "H3")
  3306. (org-show-context 'minimal)
  3307. ;; At this point, buffer displays, with point at "|",
  3308. ;;
  3309. ;; * Main
  3310. ;; ** H1
  3311. ;; Foo
  3312. ;; ** H3|
  3313. (org-previous-visible-heading 1)
  3314. (looking-at "\\*+ H1"))))
  3315. (ert-deftest test-org/forward-heading-same-level ()
  3316. "Test `org-forward-heading-same-level' specifications."
  3317. ;; Test navigation at top level, forward and backward.
  3318. (should
  3319. (equal "* H2"
  3320. (org-test-with-temp-text "* H1\n* H2"
  3321. (org-forward-heading-same-level 1)
  3322. (buffer-substring-no-properties (point) (line-end-position)))))
  3323. (should
  3324. (equal "* H1"
  3325. (org-test-with-temp-text "* H1\n<point>* H2"
  3326. (org-forward-heading-same-level -1)
  3327. (buffer-substring-no-properties (point) (line-end-position)))))
  3328. ;; Test navigation in a sub-tree, forward and backward.
  3329. (should
  3330. (equal "* H2"
  3331. (org-test-with-temp-text "* H1\n** H11\n** H12\n* H2"
  3332. (org-forward-heading-same-level 1)
  3333. (buffer-substring-no-properties (point) (line-end-position)))))
  3334. (should
  3335. (equal "* H1"
  3336. (org-test-with-temp-text "* H1\n** H11\n** H12\n<point>* H2"
  3337. (org-forward-heading-same-level -1)
  3338. (buffer-substring-no-properties (point) (line-end-position)))))
  3339. ;; Stop at first or last sub-heading.
  3340. (should-not
  3341. (equal "* H2"
  3342. (org-test-with-temp-text "* H1\n** H11\n<point>** H12\n* H2"
  3343. (org-forward-heading-same-level 1)
  3344. (buffer-substring-no-properties (point) (line-end-position)))))
  3345. (should-not
  3346. (equal "* H2"
  3347. (org-test-with-temp-text "* H1\n<point>** H11\n** H12\n* H2"
  3348. (org-forward-heading-same-level -1)
  3349. (buffer-substring-no-properties (point) (line-end-position)))))
  3350. ;; Allow multiple moves.
  3351. (should
  3352. (equal "* H3"
  3353. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3354. (org-forward-heading-same-level 2)
  3355. (buffer-substring-no-properties (point) (line-end-position)))))
  3356. (should
  3357. (equal "* H1"
  3358. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3359. (org-forward-heading-same-level -2)
  3360. (buffer-substring-no-properties (point) (line-end-position)))))
  3361. ;; Ignore spurious moves when first (or last) sibling is reached.
  3362. (should
  3363. (equal "** H3"
  3364. (org-test-with-temp-text "* First\n<point>** H1\n** H2\n** H3\n* Last"
  3365. (org-forward-heading-same-level 100)
  3366. (buffer-substring-no-properties (point) (line-end-position)))))
  3367. (should
  3368. (equal "** H1"
  3369. (org-test-with-temp-text "* First\n** H1\n** H2\n<point>** H3\n* Last"
  3370. (org-forward-heading-same-level -100)
  3371. (buffer-substring-no-properties (point) (line-end-position))))))
  3372. (ert-deftest test-org/end-of-meta-data ()
  3373. "Test `org-end-of-meta-data' specifications."
  3374. ;; Skip planning line.
  3375. (should
  3376. (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
  3377. (org-end-of-meta-data)
  3378. (eobp)))
  3379. ;; Skip properties drawer.
  3380. (should
  3381. (org-test-with-temp-text
  3382. "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
  3383. (org-end-of-meta-data)
  3384. (eobp)))
  3385. ;; Skip both.
  3386. (should
  3387. (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
  3388. (org-end-of-meta-data)
  3389. (eobp)))
  3390. ;; Nothing to skip, go to first line.
  3391. (should
  3392. (org-test-with-temp-text "* Headline\nContents"
  3393. (org-end-of-meta-data)
  3394. (looking-at "Contents")))
  3395. ;; With option argument, skip empty lines, regular drawers and
  3396. ;; clocking lines.
  3397. (should
  3398. (org-test-with-temp-text "* Headline\n\nContents"
  3399. (org-end-of-meta-data t)
  3400. (looking-at "Contents")))
  3401. (should
  3402. (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
  3403. (org-end-of-meta-data t)
  3404. (looking-at "Contents")))
  3405. (should
  3406. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
  3407. (org-end-of-meta-data t)
  3408. (looking-at "Contents")))
  3409. ;; Special case: do not skip incomplete drawers.
  3410. (should
  3411. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
  3412. (org-end-of-meta-data t)
  3413. (looking-at ":LOGBOOK:")))
  3414. ;; Special case: Be careful about consecutive headlines.
  3415. (should-not
  3416. (org-test-with-temp-text "* H1\n*H2\nContents"
  3417. (org-end-of-meta-data t)
  3418. (looking-at "Contents"))))
  3419. (ert-deftest test-org/shiftright-heading ()
  3420. "Test `org-shiftright' on headings."
  3421. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  3422. (should
  3423. (equal "* TODO a1\n** a2\n* DONE b1\n"
  3424. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3425. (org-shiftright)
  3426. (buffer-string))))
  3427. (should
  3428. (equal "* TODO a1\n** TODO a2\n* b1\n"
  3429. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3430. (let ((org-loop-over-headlines-in-active-region t))
  3431. (transient-mark-mode 1)
  3432. (push-mark (point) t t)
  3433. (search-forward "* DONE b1")
  3434. (org-shiftright))
  3435. (buffer-string))))
  3436. (should
  3437. (equal "* TODO a1\n** a2\n* b1\n"
  3438. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3439. (let ((org-loop-over-headlines-in-active-region 'start-level))
  3440. (transient-mark-mode 1)
  3441. (push-mark (point) t t)
  3442. (search-forward "* DONE b1")
  3443. (org-shiftright))
  3444. (buffer-string))))))
  3445. (ert-deftest test-org/beginning-of-line ()
  3446. "Test `org-beginning-of-line' specifications."
  3447. ;; Move to beginning of line. If current line in invisible, move to
  3448. ;; beginning of visible line instead.
  3449. (should
  3450. (org-test-with-temp-text "Some text\nSome other text<point>"
  3451. (org-beginning-of-line)
  3452. (bolp)))
  3453. (should
  3454. (org-test-with-temp-text "* H1\n** H2<point>"
  3455. (org-overview)
  3456. (org-beginning-of-line)
  3457. (= (line-beginning-position) 1)))
  3458. ;; With `visual-line-mode' active, move to beginning of visual line.
  3459. (should-not
  3460. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3461. (visual-line-mode)
  3462. (dotimes (i 1000) (insert "very "))
  3463. (org-beginning-of-line)
  3464. (bolp)))
  3465. ;; In a wide headline, with `visual-line-mode', prefer going to the
  3466. ;; beginning of a visual line than to the logical beginning of line,
  3467. ;; even if special movement is active.
  3468. (should-not
  3469. (org-test-with-temp-text "* A <point>long headline"
  3470. (visual-line-mode)
  3471. (dotimes (i 1000) (insert "very "))
  3472. (goto-char (point-max))
  3473. (org-beginning-of-line)
  3474. (bobp)))
  3475. (should-not
  3476. (org-test-with-temp-text "* A <point>long headline"
  3477. (visual-line-mode)
  3478. (dotimes (i 1000) (insert "very "))
  3479. (goto-char (point-max))
  3480. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line))
  3481. (bobp)))
  3482. ;; At an headline with special movement, first move at beginning of
  3483. ;; title, then at the beginning of line, rinse, repeat.
  3484. (should
  3485. (org-test-with-temp-text "* TODO Headline<point>"
  3486. (let ((org-special-ctrl-a/e t))
  3487. (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
  3488. (progn (org-beginning-of-line) (bolp))
  3489. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3490. (should
  3491. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3492. (let ((org-special-ctrl-a/e t))
  3493. (org-beginning-of-line)
  3494. (looking-at "Headline"))))
  3495. (should
  3496. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3497. (let ((org-special-ctrl-a/e '(t . nil)))
  3498. (org-beginning-of-line)
  3499. (looking-at "Headline"))))
  3500. (should-not
  3501. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3502. (let ((org-special-ctrl-a/e '(nil . nil)))
  3503. (org-beginning-of-line)
  3504. (looking-at "Headline"))))
  3505. ;; At an headline with reversed movement, first move to beginning of
  3506. ;; line, then to the beginning of title.
  3507. (should
  3508. (org-test-with-temp-text "* TODO Headline<point>"
  3509. (let ((org-special-ctrl-a/e 'reversed)
  3510. (this-command last-command))
  3511. (and (progn (org-beginning-of-line) (bolp))
  3512. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3513. (should
  3514. (org-test-with-temp-text "* TODO Headline<point>"
  3515. (let ((org-special-ctrl-a/e '(reversed . nil))
  3516. (this-command last-command))
  3517. (and (progn (org-beginning-of-line) (bolp))
  3518. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3519. (should-not
  3520. (org-test-with-temp-text "* TODO Headline<point>"
  3521. (let ((org-special-ctrl-a/e '(t . nil))
  3522. (this-command last-command))
  3523. (and (progn (org-beginning-of-line) (bolp))
  3524. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3525. ;; At an item with special movement, first move after to beginning
  3526. ;; of title, then to the beginning of line, rinse, repeat.
  3527. (should
  3528. (org-test-with-temp-text "- [ ] Item<point>"
  3529. (let ((org-special-ctrl-a/e t))
  3530. (and (progn (org-beginning-of-line) (looking-at-p "Item"))
  3531. (progn (org-beginning-of-line) (bolp))
  3532. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3533. ;; At an item with reversed movement, first move to beginning of
  3534. ;; line, then to the beginning of title.
  3535. (should
  3536. (org-test-with-temp-text "- [X] Item<point>"
  3537. (let ((org-special-ctrl-a/e 'reversed)
  3538. (this-command last-command))
  3539. (and (progn (org-beginning-of-line) (bolp))
  3540. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3541. ;; Leave point before invisible characters at column 0.
  3542. (should
  3543. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3544. (let ((org-special-ctrl-a/e nil))
  3545. (org-beginning-of-line)
  3546. (bolp))))
  3547. (should
  3548. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3549. (let ((org-special-ctrl-a/e t))
  3550. (org-beginning-of-line)
  3551. (bolp))))
  3552. (should
  3553. (org-test-with-temp-text "[[http<point>://orgmode.org]]"
  3554. (visual-line-mode)
  3555. (org-beginning-of-line)
  3556. (bolp)))
  3557. ;; Special case: Do not error when the buffer contains only a single
  3558. ;; asterisk.
  3559. (should
  3560. (org-test-with-temp-text "*<point>"
  3561. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line) t)))
  3562. (should
  3563. (org-test-with-temp-text "*<point>"
  3564. (let ((org-special-ctrl-a/e nil)) (org-beginning-of-line) t))))
  3565. (ert-deftest test-org/end-of-line ()
  3566. "Test `org-end-of-line' specifications."
  3567. ;; Standard test.
  3568. (should
  3569. (org-test-with-temp-text "Some text\nSome other text"
  3570. (org-end-of-line)
  3571. (eolp)))
  3572. ;; With `visual-line-mode' active, move to end of visible line.
  3573. ;; However, never go past ellipsis.
  3574. (should-not
  3575. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3576. (visual-line-mode)
  3577. (dotimes (i 1000) (insert "very "))
  3578. (goto-char (point-min))
  3579. (org-end-of-line)
  3580. (eolp)))
  3581. (should-not
  3582. (org-test-with-temp-text "* A short headline\nSome contents"
  3583. (visual-line-mode)
  3584. (org-overview)
  3585. (org-end-of-line)
  3586. (eobp)))
  3587. ;; In a wide headline, with `visual-line-mode', prefer going to end
  3588. ;; of visible line if tags, or end of line, are farther.
  3589. (should-not
  3590. (org-test-with-temp-text "* A <point>long headline"
  3591. (visual-line-mode)
  3592. (dotimes (i 1000) (insert "very "))
  3593. (goto-char (point-min))
  3594. (org-end-of-line)
  3595. (eolp)))
  3596. (should-not
  3597. (org-test-with-temp-text "* A <point>long headline :tag:"
  3598. (visual-line-mode)
  3599. (dotimes (i 1000) (insert "very "))
  3600. (goto-char (point-min))
  3601. (org-end-of-line)
  3602. (eolp)))
  3603. ;; At an headline without special movement, go to end of line.
  3604. ;; However, never go past ellipsis.
  3605. (should
  3606. (org-test-with-temp-text "* Headline2b :tag:\n"
  3607. (let ((org-special-ctrl-a/e nil))
  3608. (and (progn (org-end-of-line) (eolp))
  3609. (progn (org-end-of-line) (eolp))))))
  3610. (should
  3611. (org-test-with-temp-text "* Headline2b :tag:\n"
  3612. (let ((org-special-ctrl-a/e '(t . nil)))
  3613. (and (progn (org-end-of-line) (eolp))
  3614. (progn (org-end-of-line) (eolp))))))
  3615. (should
  3616. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3617. (org-overview)
  3618. (let ((org-special-ctrl-a/e nil))
  3619. (org-end-of-line)
  3620. (= 1 (line-beginning-position)))))
  3621. ;; At an headline with special movement, first move before tags,
  3622. ;; then at the end of line, rinse, repeat. However, never go past
  3623. ;; ellipsis.
  3624. (should
  3625. (org-test-with-temp-text "* Headline1 :tag:\n"
  3626. (let ((org-special-ctrl-a/e t))
  3627. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3628. (progn (org-end-of-line) (eolp))
  3629. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3630. (should
  3631. (org-test-with-temp-text "* Headline1 :tag:\n"
  3632. (let ((org-special-ctrl-a/e '(nil . t)))
  3633. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3634. (progn (org-end-of-line) (eolp))
  3635. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3636. (should-not
  3637. (org-test-with-temp-text "* Headline1 :tag:\n"
  3638. (let ((org-special-ctrl-a/e '(nil . nil)))
  3639. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3640. (progn (org-end-of-line) (eolp))
  3641. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3642. (should
  3643. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3644. (org-overview)
  3645. (let ((org-special-ctrl-a/e t))
  3646. (org-end-of-line)
  3647. (org-end-of-line)
  3648. (= 1 (line-beginning-position)))))
  3649. ;; At an headline, with reversed movement, first go to end of line,
  3650. ;; then before tags. However, never go past ellipsis.
  3651. (should
  3652. (org-test-with-temp-text "* Headline3 :tag:\n"
  3653. (let ((org-special-ctrl-a/e 'reversed)
  3654. (this-command last-command))
  3655. (and (progn (org-end-of-line) (eolp))
  3656. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3657. (should
  3658. (org-test-with-temp-text "* Headline3 :tag:\n"
  3659. (let ((org-special-ctrl-a/e '(nil . reversed))
  3660. (this-command last-command))
  3661. (and (progn (org-end-of-line) (eolp))
  3662. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3663. (should-not
  3664. (org-test-with-temp-text "* Headline3 :tag:\n"
  3665. (let ((org-special-ctrl-a/e '(nil . t))
  3666. (this-command last-command))
  3667. (and (progn (org-end-of-line) (eolp))
  3668. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3669. (should
  3670. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3671. (org-overview)
  3672. (let ((org-special-ctrl-a/e 'reversed))
  3673. (org-end-of-line)
  3674. (= 1 (line-beginning-position)))))
  3675. ;; At a block without hidden contents.
  3676. (should
  3677. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3678. (progn (org-end-of-line) (eolp))))
  3679. ;; At a block with hidden contents.
  3680. (should-not
  3681. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3682. (let ((org-special-ctrl-a/e t))
  3683. (org-hide-block-toggle)
  3684. (org-end-of-line)
  3685. (eobp))))
  3686. ;; Get past invisible characters at the end of line.
  3687. (should
  3688. (org-test-with-temp-text "[[https://orgmode.org]]"
  3689. (org-end-of-line)
  3690. (eolp))))
  3691. (ert-deftest test-org/open-line ()
  3692. "Test `org-open-line' specifications."
  3693. ;; Call `open-line' outside of tables.
  3694. (should
  3695. (equal "\nText"
  3696. (org-test-with-temp-text "Text"
  3697. (org-open-line 1)
  3698. (buffer-string))))
  3699. ;; At a table, create a row above.
  3700. (should
  3701. (equal "\n| |\n| a |"
  3702. (org-test-with-temp-text "\n<point>| a |"
  3703. (org-open-line 1)
  3704. (buffer-string))))
  3705. ;; At the very first character of the buffer, also call `open-line'.
  3706. (should
  3707. (equal "\n| a |"
  3708. (org-test-with-temp-text "| a |"
  3709. (org-open-line 1)
  3710. (buffer-string))))
  3711. ;; Narrowing does not count.
  3712. (should
  3713. (equal "Text\n| |\n| a |"
  3714. (org-test-with-temp-text "Text\n<point>| a |"
  3715. (narrow-to-region (point) (point-max))
  3716. (org-open-line 1)
  3717. (widen)
  3718. (buffer-string)))))
  3719. (ert-deftest test-org/forward-sentence ()
  3720. "Test `org-forward-sentence' specifications."
  3721. ;; At the end of a table cell, move to the end of the next one.
  3722. (should
  3723. (org-test-with-temp-text "| a<point> | b |"
  3724. (org-forward-sentence)
  3725. (looking-at " |$")))
  3726. ;; Elsewhere in a cell, move to its end.
  3727. (should
  3728. (org-test-with-temp-text "| a<point>c | b |"
  3729. (org-forward-sentence)
  3730. (looking-at " | b |$")))
  3731. ;; Otherwise, simply call `forward-sentence'.
  3732. (should
  3733. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3734. (org-forward-sentence)
  3735. (looking-at " Sentence 2.")))
  3736. (should
  3737. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3738. (org-forward-sentence)
  3739. (org-forward-sentence)
  3740. (eobp)))
  3741. ;; At the end of an element, jump to the next one, without stopping
  3742. ;; on blank lines in-between.
  3743. (should
  3744. (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
  3745. (org-forward-sentence)
  3746. (eobp)))
  3747. ;; Headlines are considered to be sentences by themselves, even if
  3748. ;; they do not end with a full stop.
  3749. (should
  3750. (equal
  3751. "* Headline"
  3752. (org-test-with-temp-text "* <point>Headline\nSentence."
  3753. (org-forward-sentence)
  3754. (buffer-substring-no-properties (line-beginning-position) (point)))))
  3755. (should
  3756. (org-test-with-temp-text "* Headline<point>\nSentence."
  3757. (org-forward-sentence)
  3758. (eobp)))
  3759. (should
  3760. (org-test-with-temp-text "Sentence.<point>\n\n* Headline\n\nSentence 2."
  3761. (org-forward-sentence)
  3762. (and (org-at-heading-p) (eolp)))))
  3763. (ert-deftest test-org/backward-sentence ()
  3764. "Test `org-backward-sentence' specifications."
  3765. ;; At the beginning of a table cell, move to the beginning of the
  3766. ;; previous one.
  3767. (should
  3768. (org-test-with-temp-text "| a | <point>b |"
  3769. (org-backward-sentence)
  3770. (looking-at "a | b |$")))
  3771. ;; Elsewhere in a cell, move to its beginning.
  3772. (should
  3773. (org-test-with-temp-text "| a | b<point>c |"
  3774. (org-backward-sentence)
  3775. (looking-at "bc |$")))
  3776. ;; Otherwise, simply call `backward-sentence'.
  3777. (should
  3778. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3779. (org-backward-sentence)
  3780. (looking-at "Sentence 2.")))
  3781. (should
  3782. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3783. (org-backward-sentence)
  3784. (org-backward-sentence)
  3785. (bobp)))
  3786. ;; Make sure to hit the beginning of a sentence on the same line as
  3787. ;; an item.
  3788. (should
  3789. (org-test-with-temp-text "- Line 1\n line <point>2."
  3790. (org-backward-sentence)
  3791. (looking-at "Line 1"))))
  3792. (ert-deftest test-org/forward-paragraph ()
  3793. "Test `org-forward-paragraph' specifications."
  3794. ;; At end of buffer, do not return an error.
  3795. (should
  3796. (org-test-with-temp-text "Paragraph"
  3797. (goto-char (point-max))
  3798. (org-forward-paragraph)
  3799. t))
  3800. ;; Standard test.
  3801. (should
  3802. (= 2
  3803. (org-test-with-temp-text "P1\n\nP2"
  3804. (org-forward-paragraph)
  3805. (org-current-line))))
  3806. (should
  3807. (= 2
  3808. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  3809. (org-forward-paragraph)
  3810. (org-current-line))))
  3811. ;; Enter greater elements.
  3812. (should
  3813. (= 2
  3814. (org-test-with-temp-text "#+begin_center\nP1\n#+end_center\nP2"
  3815. (org-forward-paragraph)
  3816. (org-current-line))))
  3817. ;; Do not enter elements with invisible contents.
  3818. (should
  3819. (= 4
  3820. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  3821. (org-cycle)
  3822. (org-forward-paragraph)
  3823. (org-current-line))))
  3824. (should
  3825. (= 6
  3826. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\nP3"
  3827. (org-hide-block-toggle)
  3828. (org-forward-paragraph)
  3829. (org-current-line))))
  3830. ;; On an item or a footnote definition, move past the first element
  3831. ;; inside, if any.
  3832. (should
  3833. (= 2
  3834. (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
  3835. (org-forward-paragraph)
  3836. (org-current-line))))
  3837. (should
  3838. (= 2
  3839. (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
  3840. (org-forward-paragraph)
  3841. (org-current-line))))
  3842. ;; On a table (resp. a property drawer) do not move through table
  3843. ;; rows (resp. node properties).
  3844. (should
  3845. (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
  3846. (org-forward-paragraph)
  3847. (looking-at "Paragraph")))
  3848. (should
  3849. (org-test-with-temp-text
  3850. "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
  3851. (org-forward-paragraph)
  3852. (looking-at "Paragraph")))
  3853. ;; Skip consecutive keywords, clocks and diary S-exps.
  3854. (should
  3855. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n"
  3856. (org-forward-paragraph)
  3857. (eobp)))
  3858. (should
  3859. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n"
  3860. (org-forward-paragraph)
  3861. (eobp)))
  3862. (should
  3863. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n"
  3864. (org-forward-paragraph)
  3865. (eobp)))
  3866. (should-not
  3867. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n"
  3868. (org-forward-paragraph)
  3869. (eobp)))
  3870. (should-not
  3871. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n"
  3872. (org-forward-paragraph)
  3873. (eobp)))
  3874. ;; In a plain list with one item every line, skip the whole list,
  3875. ;; even with point in the middle of the list.
  3876. (should
  3877. (org-test-with-temp-text "- A\n - B\n- C\n"
  3878. (org-forward-paragraph)
  3879. (eobp)))
  3880. (should
  3881. (org-test-with-temp-text "- A\n - <point>B\n- C\n"
  3882. (org-forward-paragraph)
  3883. (eobp)))
  3884. ;; On a comment, verse or source block, stop at "contents"
  3885. ;; boundaries and blank lines.
  3886. (should
  3887. (= 2
  3888. (org-test-with-temp-text "#+begin_src emacs-lisp\nL1\n\nL2\n#+end_src"
  3889. (org-forward-paragraph)
  3890. (org-current-line))))
  3891. (should
  3892. (= 3
  3893. (org-test-with-temp-text "#+begin_verse\n<point>L1\n\nL2\n#+end_verse"
  3894. (org-forward-paragraph)
  3895. (org-current-line))))
  3896. (should
  3897. (= 5
  3898. (org-test-with-temp-text "#+begin_comment\nL1\n\n<point>L2\n#+end_comment"
  3899. (org-forward-paragraph)
  3900. (org-current-line))))
  3901. ;; Being on an affiliated keyword shouldn't make any difference.
  3902. (should
  3903. (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
  3904. (org-forward-paragraph)
  3905. (eobp))))
  3906. (ert-deftest test-org/backward-paragraph ()
  3907. "Test `org-backward-paragraph' specifications."
  3908. ;; Do not error at beginning of buffer.
  3909. (should
  3910. (org-test-with-temp-text "Paragraph"
  3911. (org-backward-paragraph)
  3912. t))
  3913. ;; At blank lines at the very beginning of a buffer, move to
  3914. ;; point-min.
  3915. (should
  3916. (org-test-with-temp-text "\n\n<point>\n\nParagraph"
  3917. (org-backward-paragraph)
  3918. (bobp)))
  3919. ;; Regular test.
  3920. (should
  3921. (= 2
  3922. (org-test-with-temp-text "P1\n\nP2<point>"
  3923. (org-backward-paragraph)
  3924. (org-current-line))))
  3925. (should
  3926. (= 4
  3927. (org-test-with-temp-text "P1\n\nP2\n\nP3<point>"
  3928. (org-backward-paragraph)
  3929. (org-current-line))))
  3930. ;; Try to move on the line above current element.
  3931. (should
  3932. (= 2
  3933. (org-test-with-temp-text "\n\n<point>Paragraph"
  3934. (org-backward-paragraph)
  3935. (org-current-line))))
  3936. ;; Do not leave point in an invisible area.
  3937. (should
  3938. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  3939. (org-cycle)
  3940. (goto-char (point-max))
  3941. (beginning-of-line)
  3942. (org-backward-paragraph)
  3943. (bobp)))
  3944. (should
  3945. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\n"
  3946. (org-hide-block-toggle)
  3947. (goto-char (point-max))
  3948. (org-backward-paragraph)
  3949. (bobp)))
  3950. ;; On the first element in an item or a footnote definition, jump
  3951. ;; before the footnote or the item.
  3952. (should
  3953. (org-test-with-temp-text "- line1<point>"
  3954. (org-backward-paragraph)
  3955. (bobp)))
  3956. (should
  3957. (org-test-with-temp-text "[fn:1] line1n<point>"
  3958. (org-backward-paragraph)
  3959. (bobp)))
  3960. ;; On the second element in an item or a footnote definition, jump
  3961. ;; to item or the definition.
  3962. (should
  3963. (= 2
  3964. (org-test-with-temp-text "- line1\n\n<point> line2"
  3965. (org-backward-paragraph)
  3966. (org-current-line))))
  3967. (should
  3968. (= 2
  3969. (org-test-with-temp-text "[fn:1] line1\n\n<point> line2"
  3970. (org-backward-paragraph)
  3971. (org-current-line))))
  3972. ;; On a table (resp. a property drawer), ignore table rows
  3973. ;; (resp. node properties).
  3974. (should
  3975. (org-test-with-temp-text "| a | b |\n| c | d |\n<point>P1"
  3976. (org-backward-paragraph)
  3977. (bobp)))
  3978. (should
  3979. (= 2
  3980. (org-test-with-temp-text
  3981. "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
  3982. (org-backward-paragraph)
  3983. (org-current-line))))
  3984. ;; In a plain list with one item every line, skip the whole list,
  3985. ;; even with point in the middle of the list.
  3986. (should
  3987. (org-test-with-temp-text "- A\n - B\n- C\n<point>"
  3988. (org-backward-paragraph)
  3989. (bobp)))
  3990. (should
  3991. (org-test-with-temp-text "- A\n - B\n- <point>C\n"
  3992. (org-backward-paragraph)
  3993. (bobp)))
  3994. ;; Skip consecutive keywords, clocks and diary S-exps.
  3995. (should
  3996. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n<point>"
  3997. (org-backward-paragraph)
  3998. (bobp)))
  3999. (should
  4000. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n<point>"
  4001. (org-backward-paragraph)
  4002. (bobp)))
  4003. (should
  4004. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n<point>"
  4005. (org-backward-paragraph)
  4006. (bobp)))
  4007. (should-not
  4008. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n<point>"
  4009. (org-backward-paragraph)
  4010. (bobp)))
  4011. (should-not
  4012. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n<point>"
  4013. (org-backward-paragraph)
  4014. (bobp)))
  4015. ;; On a comment, example, source and verse blocks, stop at blank
  4016. ;; lines.
  4017. (should
  4018. (= 1
  4019. (org-test-with-temp-text
  4020. "#+begin_comment\n<point>L1\n\nL2\n\nL3\n#+end_comment"
  4021. (org-backward-paragraph)
  4022. (org-current-line))))
  4023. (should
  4024. (= 2
  4025. (org-test-with-temp-text
  4026. "#+begin_verse\nL1\n\n<point>L2\n\nL3\n#+end_verse"
  4027. (org-backward-paragraph)
  4028. (org-current-line))))
  4029. (should
  4030. (= 3
  4031. (org-test-with-temp-text
  4032. "#+begin_src emacs-lisp\nL1\n\nL2\n\n<point>L3\n#+end_src"
  4033. (org-backward-paragraph)
  4034. (org-current-line))))
  4035. ;; When called from the opening line itself, however, move to
  4036. ;; beginning of block.
  4037. (should
  4038. (org-test-with-temp-text "#+begin_<point>example\nL1\n#+end_example"
  4039. (org-backward-paragraph)
  4040. (bobp)))
  4041. ;; On an empty heading, move above it.
  4042. (should
  4043. (org-test-with-temp-text "\n* <point>"
  4044. (org-backward-paragraph)
  4045. (bobp)))
  4046. (should
  4047. (org-test-with-temp-text "\n* \n<point>"
  4048. (org-backward-paragraph)
  4049. (bobp))))
  4050. (ert-deftest test-org/forward-element ()
  4051. "Test `org-forward-element' specifications."
  4052. ;; 1. At EOB: should error.
  4053. (org-test-with-temp-text "Some text\n"
  4054. (goto-char (point-max))
  4055. (should-error (org-forward-element)))
  4056. ;; 2. Standard move: expected to ignore blank lines.
  4057. (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
  4058. (org-forward-element)
  4059. (should (looking-at (regexp-quote "Second paragraph."))))
  4060. ;; 3. Headline tests.
  4061. (org-test-with-temp-text "
  4062. * Head 1
  4063. ** Head 1.1
  4064. *** Head 1.1.1
  4065. ** Head 1.2"
  4066. ;; 3.1. At an headline beginning: move to next headline at the
  4067. ;; same level.
  4068. (goto-line 3)
  4069. (org-forward-element)
  4070. (should (looking-at (regexp-quote "** Head 1.2")))
  4071. ;; 3.2. At an headline beginning: move to parent headline if no
  4072. ;; headline at the same level.
  4073. (goto-line 3)
  4074. (org-forward-element)
  4075. (should (looking-at (regexp-quote "** Head 1.2"))))
  4076. ;; 4. Greater element tests.
  4077. (org-test-with-temp-text
  4078. "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
  4079. ;; 4.1. At a greater element: expected to skip contents.
  4080. (org-forward-element)
  4081. (should (looking-at (regexp-quote "Outside.")))
  4082. ;; 4.2. At the end of greater element contents: expected to skip
  4083. ;; to the end of the greater element.
  4084. (goto-line 2)
  4085. (org-forward-element)
  4086. (should (looking-at (regexp-quote "Outside."))))
  4087. ;; 5. List tests.
  4088. (org-test-with-temp-text "
  4089. - item1
  4090. - sub1
  4091. - sub2
  4092. - sub3
  4093. Inner paragraph.
  4094. - item2
  4095. Outside."
  4096. ;; 5.1. At list top point: expected to move to the element after
  4097. ;; the list.
  4098. (goto-line 2)
  4099. (org-forward-element)
  4100. (should (looking-at (regexp-quote "Outside.")))
  4101. ;; 5.2. Special case: at the first line of a sub-list, but not at
  4102. ;; beginning of line, move to next item.
  4103. (goto-line 2)
  4104. (forward-char)
  4105. (org-forward-element)
  4106. (should (looking-at "- item2"))
  4107. (goto-line 4)
  4108. (forward-char)
  4109. (org-forward-element)
  4110. (should (looking-at " - sub2"))
  4111. ;; 5.3 At sub-list beginning: expected to move after the sub-list.
  4112. (goto-line 4)
  4113. (org-forward-element)
  4114. (should (looking-at (regexp-quote " Inner paragraph.")))
  4115. ;; 5.4. At sub-list end: expected to move outside the sub-list.
  4116. (goto-line 8)
  4117. (org-forward-element)
  4118. (should (looking-at (regexp-quote " Inner paragraph.")))
  4119. ;; 5.5. At an item: expected to move to next item, if any.
  4120. (goto-line 6)
  4121. (org-forward-element)
  4122. (should (looking-at " - sub3"))))
  4123. (ert-deftest test-org/backward-element ()
  4124. "Test `org-backward-element' specifications."
  4125. ;; 1. Should error at BOB.
  4126. (org-test-with-temp-text " \nParagraph."
  4127. (should-error (org-backward-element)))
  4128. ;; 2. Should move at BOB when called on the first element in buffer.
  4129. (should
  4130. (org-test-with-temp-text "\n#+TITLE: test"
  4131. (progn (forward-line)
  4132. (org-backward-element)
  4133. (bobp))))
  4134. ;; 3. Not at the beginning of an element: move at its beginning.
  4135. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  4136. (goto-line 3)
  4137. (end-of-line)
  4138. (org-backward-element)
  4139. (should (looking-at (regexp-quote "Paragraph2."))))
  4140. ;; 4. Headline tests.
  4141. (org-test-with-temp-text "
  4142. * Head 1
  4143. ** Head 1.1
  4144. *** Head 1.1.1
  4145. ** Head 1.2"
  4146. ;; 4.1. At an headline beginning: move to previous headline at the
  4147. ;; same level.
  4148. (goto-line 5)
  4149. (org-backward-element)
  4150. (should (looking-at (regexp-quote "** Head 1.1")))
  4151. ;; 4.2. At an headline beginning: move to parent headline if no
  4152. ;; headline at the same level.
  4153. (goto-line 3)
  4154. (org-backward-element)
  4155. (should (looking-at (regexp-quote "* Head 1")))
  4156. ;; 4.3. At the first top-level headline: should error.
  4157. (goto-line 2)
  4158. (should-error (org-backward-element)))
  4159. ;; 5. At beginning of first element inside a greater element:
  4160. ;; expected to move to greater element's beginning.
  4161. (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
  4162. (goto-line 3)
  4163. (org-backward-element)
  4164. (should (looking-at "#\\+BEGIN_CENTER")))
  4165. ;; 6. At the beginning of the first element in a section: should
  4166. ;; move back to headline, if any.
  4167. (should
  4168. (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
  4169. (progn (goto-char (point-max))
  4170. (beginning-of-line)
  4171. (org-backward-element)
  4172. (org-at-heading-p))))
  4173. ;; 7. List tests.
  4174. (org-test-with-temp-text "
  4175. - item1
  4176. - sub1
  4177. - sub2
  4178. - sub3
  4179. Inner paragraph.
  4180. - item2
  4181. Outside."
  4182. ;; 7.1. At beginning of sub-list: expected to move to the
  4183. ;; paragraph before it.
  4184. (goto-line 4)
  4185. (org-backward-element)
  4186. (should (looking-at "item1"))
  4187. ;; 7.2. At an item in a list: expected to move at previous item.
  4188. (goto-line 8)
  4189. (org-backward-element)
  4190. (should (looking-at " - sub2"))
  4191. (goto-line 12)
  4192. (org-backward-element)
  4193. (should (looking-at "- item1"))
  4194. ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
  4195. ;; beginning.
  4196. (goto-line 10)
  4197. (org-backward-element)
  4198. (should (looking-at " - sub1"))
  4199. (goto-line 15)
  4200. (org-backward-element)
  4201. (should (looking-at "- item1"))
  4202. ;; 7.4. At blank-lines before list end: expected to move to top
  4203. ;; item.
  4204. (goto-line 14)
  4205. (org-backward-element)
  4206. (should (looking-at "- item1"))))
  4207. (ert-deftest test-org/up-element ()
  4208. "Test `org-up-element' specifications."
  4209. ;; 1. At BOB or with no surrounding element: should error.
  4210. (org-test-with-temp-text "Paragraph."
  4211. (should-error (org-up-element)))
  4212. (org-test-with-temp-text "* Head1\n* Head2"
  4213. (goto-line 2)
  4214. (should-error (org-up-element)))
  4215. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  4216. (goto-line 3)
  4217. (should-error (org-up-element)))
  4218. ;; 2. At an headline: move to parent headline.
  4219. (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
  4220. (goto-line 3)
  4221. (org-up-element)
  4222. (should (looking-at "\\* Head1")))
  4223. ;; 3. Inside a greater element: move to greater element beginning.
  4224. (org-test-with-temp-text
  4225. "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
  4226. (goto-line 3)
  4227. (org-up-element)
  4228. (should (looking-at "#\\+BEGIN_CENTER")))
  4229. ;; 4. List tests.
  4230. (org-test-with-temp-text "* Top
  4231. - item1
  4232. - sub1
  4233. - sub2
  4234. Paragraph within sub2.
  4235. - item2"
  4236. ;; 4.1. Within an item: move to the item beginning.
  4237. (goto-line 8)
  4238. (org-up-element)
  4239. (should (looking-at " - sub2"))
  4240. ;; 4.2. At an item in a sub-list: move to parent item.
  4241. (goto-line 4)
  4242. (org-up-element)
  4243. (should (looking-at "- item1"))
  4244. ;; 4.3. At an item in top list: move to beginning of whole list.
  4245. (goto-line 10)
  4246. (org-up-element)
  4247. (should (looking-at "- item1"))
  4248. ;; 4.4. Special case. At very top point: should move to parent of
  4249. ;; list.
  4250. (goto-line 2)
  4251. (org-up-element)
  4252. (should (looking-at "\\* Top"))))
  4253. (ert-deftest test-org/down-element ()
  4254. "Test `org-down-element' specifications."
  4255. ;; Error when the element hasn't got a recursive type.
  4256. (org-test-with-temp-text "Paragraph."
  4257. (should-error (org-down-element)))
  4258. ;; Error when the element has no contents
  4259. (org-test-with-temp-text "* Headline"
  4260. (should-error (org-down-element)))
  4261. ;; When at a plain-list, move to first item.
  4262. (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
  4263. (goto-line 2)
  4264. (org-down-element)
  4265. (should (looking-at " - Item 1.1")))
  4266. (org-test-with-temp-text "#+NAME: list\n- Item 1"
  4267. (org-down-element)
  4268. (should (looking-at " Item 1")))
  4269. ;; When at a table, move to first row
  4270. (org-test-with-temp-text "#+NAME: table\n| a | b |"
  4271. (org-down-element)
  4272. (should (looking-at " a | b |")))
  4273. ;; Otherwise, move inside the greater element.
  4274. (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
  4275. (org-down-element)
  4276. (should (looking-at "Paragraph"))))
  4277. (ert-deftest test-org/drag-element-backward ()
  4278. "Test `org-drag-element-backward' specifications."
  4279. ;; Standard test.
  4280. (should
  4281. (equal
  4282. "#+key2: val2\n#+key1: val1\n#+key3: val3"
  4283. (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
  4284. (org-drag-element-backward)
  4285. (buffer-string))))
  4286. (should
  4287. (equal
  4288. "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
  4289. (org-test-with-temp-text
  4290. "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
  4291. (org-drag-element-backward)
  4292. (buffer-string))))
  4293. ;; Preserve blank lines.
  4294. (should
  4295. (equal "Paragraph 2\n\n\nPara1\n\nPara3"
  4296. (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
  4297. (org-drag-element-backward)
  4298. (buffer-string))))
  4299. ;; Preserve column.
  4300. (should
  4301. (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
  4302. (org-drag-element-backward)
  4303. (looking-at-p "2")))
  4304. ;; Error when trying to move first element of buffer.
  4305. (should-error
  4306. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4307. (org-drag-element-backward))
  4308. :type 'user-error)
  4309. ;; Error when trying to swap nested elements.
  4310. (should-error
  4311. (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
  4312. (org-drag-element-backward))
  4313. :type 'user-error)
  4314. ;; Error when trying to swap an headline element and a non-headline
  4315. ;; element.
  4316. (should-error
  4317. (org-test-with-temp-text "Test.\n<point>* Head 1"
  4318. (org-drag-element-backward))
  4319. :type 'error)
  4320. ;; Error when called before first element.
  4321. (should-error
  4322. (org-test-with-temp-text "\n<point>"
  4323. (org-drag-element-backward))
  4324. :type 'user-error)
  4325. ;; Preserve visibility of elements and their contents.
  4326. (should
  4327. (equal '((63 . 82) (26 . 48))
  4328. (org-test-with-temp-text "
  4329. #+BEGIN_CENTER
  4330. Text.
  4331. #+END_CENTER
  4332. - item 1
  4333. #+BEGIN_QUOTE
  4334. Text.
  4335. #+END_QUOTE"
  4336. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4337. (search-backward "- item 1")
  4338. (org-drag-element-backward)
  4339. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4340. (overlays-in (point-min) (point-max))))))
  4341. ;; Pathological case: handle call with point in blank lines right
  4342. ;; after a headline.
  4343. (should
  4344. (equal "* H2\n\n* H1\nText\n"
  4345. (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
  4346. (org-drag-element-backward)
  4347. (buffer-string)))))
  4348. (ert-deftest test-org/drag-element-forward ()
  4349. "Test `org-drag-element-forward' specifications."
  4350. ;; 1. Error when trying to move first element of buffer.
  4351. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4352. (goto-line 3)
  4353. (should-error (org-drag-element-forward)))
  4354. ;; 2. Error when trying to swap nested elements.
  4355. (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
  4356. (forward-line)
  4357. (should-error (org-drag-element-forward)))
  4358. ;; 3. Error when trying to swap a non-headline element and an
  4359. ;; headline.
  4360. (org-test-with-temp-text "Test.\n* Head 1"
  4361. (should-error (org-drag-element-forward)))
  4362. ;; 4. Error when called before first element.
  4363. (should-error
  4364. (org-test-with-temp-text "\n"
  4365. (forward-line)
  4366. (org-drag-element-backward))
  4367. :type 'user-error)
  4368. ;; 5. Otherwise, swap elements, preserving column and blank lines
  4369. ;; between elements.
  4370. (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
  4371. (search-forward "graph")
  4372. (org-drag-element-forward)
  4373. (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
  4374. (should (looking-at " 1")))
  4375. ;; 5. Preserve visibility of elements and their contents.
  4376. (org-test-with-temp-text "
  4377. #+BEGIN_CENTER
  4378. Text.
  4379. #+END_CENTER
  4380. - item 1
  4381. #+BEGIN_QUOTE
  4382. Text.
  4383. #+END_QUOTE"
  4384. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4385. (search-backward "#+BEGIN_CENTER")
  4386. (org-drag-element-forward)
  4387. (should
  4388. (equal
  4389. '((63 . 82) (26 . 48))
  4390. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4391. (overlays-in (point-min) (point-max)))))))
  4392. (ert-deftest test-org/next-block ()
  4393. "Test `org-next-block' specifications."
  4394. ;; Regular test.
  4395. (should
  4396. (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  4397. (org-next-block 1)
  4398. (looking-at "#\\+BEGIN_CENTER")))
  4399. ;; Ignore case.
  4400. (should
  4401. (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
  4402. (let ((case-fold-search nil))
  4403. (org-next-block 1)
  4404. (looking-at "#\\+begin_center"))))
  4405. ;; Ignore current line.
  4406. (should
  4407. (org-test-with-temp-text
  4408. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
  4409. (org-next-block 1)
  4410. (looking-at "#\\+BEGIN_CENTER")))
  4411. ;; Throw an error when no block is found.
  4412. (should-error
  4413. (org-test-with-temp-text "Paragraph"
  4414. (org-next-block 1)))
  4415. ;; With an argument, skip many blocks at once.
  4416. (should
  4417. (org-test-with-temp-text
  4418. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4419. (org-next-block 2)
  4420. (looking-at "#\\+BEGIN_QUOTE")))
  4421. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4422. (should
  4423. (org-test-with-temp-text
  4424. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4425. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4426. (looking-at "#\\+BEGIN_QUOTE")))
  4427. ;; Optional argument is also case-insensitive.
  4428. (should
  4429. (org-test-with-temp-text
  4430. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
  4431. (let ((case-fold-search nil))
  4432. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4433. (looking-at "#\\+begin_quote")))))
  4434. (ert-deftest test-org/insert-structure-template ()
  4435. "Test `org-insert-structure-template'."
  4436. ;; Test in empty buffer.
  4437. (should
  4438. (string= "#+begin_foo\n#+end_foo\n"
  4439. (org-test-with-temp-text ""
  4440. (org-insert-structure-template "foo")
  4441. (buffer-string))))
  4442. ;; Test with multiple lines in buffer.
  4443. (should
  4444. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4445. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4446. (transient-mark-mode 1)
  4447. (org-mark-element)
  4448. (org-insert-structure-template "foo")
  4449. (buffer-string))))
  4450. ;; Mark only the current line.
  4451. (should
  4452. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4453. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4454. (transient-mark-mode 1)
  4455. (set-mark (point-min))
  4456. (end-of-line)
  4457. (org-insert-structure-template "foo")
  4458. (buffer-string))))
  4459. ;; Middle of paragraph.
  4460. (should
  4461. (string= "p1\n#+begin_foo\np2\n#+end_foo\np3"
  4462. (org-test-with-temp-text "p1\n<point>p2\np3"
  4463. (set-mark (line-beginning-position))
  4464. (end-of-line)
  4465. (activate-mark)
  4466. (org-insert-structure-template "foo")
  4467. (buffer-string))))
  4468. ;; Test with text in buffer, no region, no final newline.
  4469. (should
  4470. (string= "#+begin_foo\nI'm a paragraph.\n#+end_foo\n"
  4471. (org-test-with-temp-text "I'm a paragraph."
  4472. (org-mark-element)
  4473. (org-insert-structure-template "foo")
  4474. (buffer-string))))
  4475. ;; Test with text in buffer and region set.
  4476. (should
  4477. (string= "#+begin_foo\nI'm a paragraph\n\nI'm a second paragrah\n#+end_foo\n"
  4478. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragrah"
  4479. (set-mark (point))
  4480. (goto-char (point-max))
  4481. (org-insert-structure-template "foo")
  4482. (buffer-string))))
  4483. ;; Test with example escaping.
  4484. (should
  4485. (string= "#+begin_example\n,* Heading\n#+end_example\n"
  4486. (org-test-with-temp-text "* Heading"
  4487. (org-mark-element)
  4488. (org-insert-structure-template "example")
  4489. (buffer-string))))
  4490. ;; Test with indentation.
  4491. (should
  4492. (string= " #+begin_foo\n This is a paragraph\n #+end_foo\n"
  4493. (org-test-with-temp-text " This is a paragraph"
  4494. (org-mark-element)
  4495. (org-insert-structure-template "foo")
  4496. (buffer-string))))
  4497. (should
  4498. (string= " #+begin_foo\n Line 1\n Line2\n #+end_foo\n"
  4499. (org-test-with-temp-text " Line 1\n Line2"
  4500. (org-mark-element)
  4501. (org-insert-structure-template "foo")
  4502. (buffer-string))))
  4503. ;; Test point location.
  4504. (should
  4505. (string= "#+begin_foo\n"
  4506. (org-test-with-temp-text ""
  4507. (org-insert-structure-template "foo")
  4508. (buffer-substring (point-min) (point)))))
  4509. (should
  4510. (string= "#+begin_src "
  4511. (org-test-with-temp-text ""
  4512. (org-insert-structure-template "src")
  4513. (buffer-substring (point-min) (point))))))
  4514. (ert-deftest test-org/previous-block ()
  4515. "Test `org-previous-block' specifications."
  4516. ;; Regular test.
  4517. (should
  4518. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
  4519. (org-previous-block 1)
  4520. (looking-at "#\\+BEGIN_CENTER")))
  4521. ;; Ignore case.
  4522. (should
  4523. (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
  4524. (let ((case-fold-search nil))
  4525. (org-previous-block 1)
  4526. (looking-at "#\\+begin_center"))))
  4527. ;; Ignore current line.
  4528. (should
  4529. (org-test-with-temp-text
  4530. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
  4531. (org-previous-block 1)
  4532. (looking-at "#\\+BEGIN_QUOTE")))
  4533. ;; Throw an error when no block is found.
  4534. (should-error
  4535. (org-test-with-temp-text "Paragraph<point>"
  4536. (org-previous-block 1)))
  4537. ;; With an argument, skip many blocks at once.
  4538. (should
  4539. (org-test-with-temp-text
  4540. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4541. (org-previous-block 2)
  4542. (looking-at "#\\+BEGIN_CENTER")))
  4543. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4544. (should
  4545. (org-test-with-temp-text
  4546. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4547. (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4548. (looking-at "#\\+BEGIN_QUOTE")))
  4549. ;; Optional argument is also case-insensitive.
  4550. (should
  4551. (org-test-with-temp-text
  4552. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
  4553. (let ((case-fold-search nil))
  4554. (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4555. (looking-at "#\\+begin_quote")))))
  4556. ;;; Outline structure
  4557. (ert-deftest test-org/demote ()
  4558. "Test `org-demote' specifications."
  4559. ;; Add correct number of stars according to `org-odd-levels-only'.
  4560. (should
  4561. (= 2
  4562. (org-test-with-temp-text "* H"
  4563. (let ((org-odd-levels-only nil)) (org-demote))
  4564. (org-current-level))))
  4565. (should
  4566. (= 3
  4567. (org-test-with-temp-text "* H"
  4568. (let ((org-odd-levels-only t)) (org-demote))
  4569. (org-current-level))))
  4570. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4571. (should
  4572. (org-test-with-temp-text "* H :tag:"
  4573. (let ((org-tags-column 10)
  4574. (org-auto-align-tags t)
  4575. (org-odd-levels-only nil))
  4576. (org-demote))
  4577. (org-move-to-column 10)
  4578. (looking-at-p ":tag:$")))
  4579. (should-not
  4580. (org-test-with-temp-text "* H :tag:"
  4581. (let ((org-tags-column 10)
  4582. (org-auto-align-tags nil)
  4583. (org-odd-levels-only nil))
  4584. (org-demote))
  4585. (org-move-to-column 10)
  4586. (looking-at-p ":tag:$")))
  4587. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4588. ;; info and property drawers accordingly.
  4589. (should
  4590. (= 3
  4591. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4592. (let ((org-odd-levels-only nil)
  4593. (org-adapt-indentation t))
  4594. (org-demote))
  4595. (forward-line)
  4596. (org-get-indentation))))
  4597. (should
  4598. (= 3
  4599. (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4600. (let ((org-odd-levels-only nil)
  4601. (org-adapt-indentation t))
  4602. (org-demote))
  4603. (forward-line)
  4604. (org-get-indentation))))
  4605. (should-not
  4606. (= 3
  4607. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4608. (let ((org-odd-levels-only nil)
  4609. (org-adapt-indentation nil))
  4610. (org-demote))
  4611. (forward-line)
  4612. (org-get-indentation))))
  4613. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4614. ;; section accordingly. Ignore, however, footnote definitions and
  4615. ;; inlinetasks boundaries.
  4616. (should
  4617. (= 3
  4618. (org-test-with-temp-text "* H\n Paragraph"
  4619. (let ((org-odd-levels-only nil)
  4620. (org-adapt-indentation t))
  4621. (org-demote))
  4622. (forward-line)
  4623. (org-get-indentation))))
  4624. (should
  4625. (= 2
  4626. (org-test-with-temp-text "* H\n Paragraph"
  4627. (let ((org-odd-levels-only nil)
  4628. (org-adapt-indentation nil))
  4629. (org-demote))
  4630. (forward-line)
  4631. (org-get-indentation))))
  4632. (should
  4633. (zerop
  4634. (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
  4635. (let ((org-odd-levels-only nil)
  4636. (org-adapt-indentation t))
  4637. (org-demote))
  4638. (goto-char (point-max))
  4639. (org-get-indentation))))
  4640. (should
  4641. (= 3
  4642. (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
  4643. (let ((org-odd-levels-only nil)
  4644. (org-adapt-indentation t))
  4645. (org-demote))
  4646. (goto-char (point-max))
  4647. (org-get-indentation))))
  4648. (when (featurep 'org-inlinetask)
  4649. (should
  4650. (zerop
  4651. (let ((org-inlinetask-min-level 5)
  4652. (org-adapt-indentation t))
  4653. (org-test-with-temp-text "* H\n***** I\n***** END"
  4654. (org-demote)
  4655. (forward-line)
  4656. (org-get-indentation))))))
  4657. (when (featurep 'org-inlinetask)
  4658. (should
  4659. (= 3
  4660. (let ((org-inlinetask-min-level 5)
  4661. (org-adapt-indentation t))
  4662. (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
  4663. (org-demote)
  4664. (forward-line 2)
  4665. (org-get-indentation))))))
  4666. ;; When `org-adapt-indentation' is non-nil, log drawers are
  4667. ;; adjusted.
  4668. (should
  4669. (equal
  4670. "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4671. (org-test-with-temp-text "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4672. (let ((org-odd-levels-only nil)
  4673. (org-adapt-indentation t))
  4674. (org-demote))
  4675. (buffer-string))))
  4676. (should
  4677. (equal
  4678. "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4679. (org-test-with-temp-text "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4680. (let ((org-odd-levels-only nil)
  4681. (org-adapt-indentation 'headline-data))
  4682. (org-demote))
  4683. (buffer-string))))
  4684. (should
  4685. (equal
  4686. "** H\n :LOGBOOK:\n - a\n :END:"
  4687. (org-test-with-temp-text "* H\n:LOGBOOK:\n- a\n:END:"
  4688. (let ((org-odd-levels-only nil)
  4689. (org-adapt-indentation t))
  4690. (org-demote))
  4691. (buffer-string))))
  4692. ;; Ignore contents of source blocks or example blocks when
  4693. ;; indentation should be preserved (through
  4694. ;; `org-src-preserve-indentation' or "-i" flag).
  4695. (should-not
  4696. (zerop
  4697. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4698. (let ((org-adapt-indentation t)
  4699. (org-src-preserve-indentation nil))
  4700. (org-demote))
  4701. (forward-line 2)
  4702. (org-get-indentation))))
  4703. (should
  4704. (zerop
  4705. (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
  4706. (let ((org-adapt-indentation t)
  4707. (org-src-preserve-indentation t))
  4708. (org-demote))
  4709. (forward-line 2)
  4710. (org-get-indentation))))
  4711. (should
  4712. (zerop
  4713. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4714. (let ((org-adapt-indentation t)
  4715. (org-src-preserve-indentation t))
  4716. (org-demote))
  4717. (forward-line 2)
  4718. (org-get-indentation))))
  4719. (should
  4720. (zerop
  4721. (org-test-with-temp-text
  4722. "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
  4723. (let ((org-adapt-indentation t)
  4724. (org-src-preserve-indentation nil))
  4725. (org-demote))
  4726. (forward-line 2)
  4727. (org-get-indentation)))))
  4728. (ert-deftest test-org/promote ()
  4729. "Test `org-promote' specifications."
  4730. ;; Return an error if headline is to be promoted to level 0, unless
  4731. ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
  4732. ;; headline becomes a comment.
  4733. (should-error
  4734. (org-test-with-temp-text "* H"
  4735. (let ((org-allow-promoting-top-level-subtree nil)) (org-promote))))
  4736. (should
  4737. (equal "# H"
  4738. (org-test-with-temp-text "* H"
  4739. (let ((org-allow-promoting-top-level-subtree t)) (org-promote))
  4740. (buffer-string))))
  4741. ;; Remove correct number of stars according to
  4742. ;; `org-odd-levels-only'.
  4743. (should
  4744. (= 2
  4745. (org-test-with-temp-text "*** H"
  4746. (let ((org-odd-levels-only nil)) (org-promote))
  4747. (org-current-level))))
  4748. (should
  4749. (= 1
  4750. (org-test-with-temp-text "*** H"
  4751. (let ((org-odd-levels-only t)) (org-promote))
  4752. (org-current-level))))
  4753. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4754. (should
  4755. (org-test-with-temp-text "** H :tag:"
  4756. (let ((org-tags-column 10)
  4757. (org-auto-align-tags t)
  4758. (org-odd-levels-only nil))
  4759. (org-promote))
  4760. (org-move-to-column 10)
  4761. (looking-at-p ":tag:$")))
  4762. (should-not
  4763. (org-test-with-temp-text "** H :tag:"
  4764. (let ((org-tags-column 10)
  4765. (org-auto-align-tags nil)
  4766. (org-odd-levels-only nil))
  4767. (org-promote))
  4768. (org-move-to-column 10)
  4769. (looking-at-p ":tag:$")))
  4770. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4771. ;; info and property drawers.
  4772. (should
  4773. (= 2
  4774. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4775. (let ((org-odd-levels-only nil)
  4776. (org-adapt-indentation t))
  4777. (org-promote))
  4778. (forward-line)
  4779. (org-get-indentation))))
  4780. (should
  4781. (= 2
  4782. (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4783. (let ((org-odd-levels-only nil)
  4784. (org-adapt-indentation t))
  4785. (org-promote))
  4786. (forward-line)
  4787. (org-get-indentation))))
  4788. (should-not
  4789. (= 2
  4790. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4791. (let ((org-odd-levels-only nil)
  4792. (org-adapt-indentation nil))
  4793. (org-promote))
  4794. (forward-line)
  4795. (org-get-indentation))))
  4796. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4797. ;; section accordingly. Ignore, however, footnote definitions and
  4798. ;; inlinetasks boundaries.
  4799. (should
  4800. (= 2
  4801. (org-test-with-temp-text "** H\n Paragraph"
  4802. (let ((org-odd-levels-only nil)
  4803. (org-adapt-indentation t))
  4804. (org-promote))
  4805. (forward-line)
  4806. (org-get-indentation))))
  4807. (should-not
  4808. (= 2
  4809. (org-test-with-temp-text "** H\n Paragraph"
  4810. (let ((org-odd-levels-only nil)
  4811. (org-adapt-indentation nil))
  4812. (org-promote))
  4813. (forward-line)
  4814. (org-get-indentation))))
  4815. (should
  4816. (= 2
  4817. (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
  4818. (let ((org-odd-levels-only nil)
  4819. (org-adapt-indentation t))
  4820. (org-promote))
  4821. (forward-line)
  4822. (org-get-indentation))))
  4823. (when (featurep 'org-inlinetask)
  4824. (should
  4825. (zerop
  4826. (let ((org-inlinetask-min-level 5)
  4827. (org-adapt-indentation t))
  4828. (org-test-with-temp-text "** H\n***** I\n***** END"
  4829. (org-promote)
  4830. (forward-line)
  4831. (org-get-indentation))))))
  4832. (when (featurep 'org-inlinetask)
  4833. (should
  4834. (= 2
  4835. (let ((org-inlinetask-min-level 5)
  4836. (org-adapt-indentation t))
  4837. (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
  4838. (org-promote)
  4839. (forward-line 2)
  4840. (org-get-indentation))))))
  4841. ;; Give up shifting if it would break document's structure
  4842. ;; otherwise.
  4843. (should
  4844. (= 3
  4845. (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
  4846. (let ((org-odd-levels-only nil)
  4847. (org-adapt-indentation t))
  4848. (org-promote))
  4849. (forward-line)
  4850. (org-get-indentation))))
  4851. (should
  4852. (= 3
  4853. (org-test-with-temp-text "** H\n Paragraph\n * list."
  4854. (let ((org-odd-levels-only nil)
  4855. (org-adapt-indentation t))
  4856. (org-promote))
  4857. (forward-line)
  4858. (org-get-indentation))))
  4859. ;; When `org-adapt-indentation' is non-nil, log drawers are
  4860. ;; adjusted.
  4861. (should
  4862. (equal
  4863. "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4864. (org-test-with-temp-text "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4865. (let ((org-odd-levels-only nil)
  4866. (org-adapt-indentation t))
  4867. (org-promote))
  4868. (buffer-string))))
  4869. (should
  4870. (equal
  4871. "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4872. (org-test-with-temp-text "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4873. (let ((org-odd-levels-only nil)
  4874. (org-adapt-indentation 'headline-data))
  4875. (org-promote))
  4876. (buffer-string))))
  4877. (should
  4878. (equal
  4879. "* H\n:LOGBOOK:\n- a\n:END:"
  4880. (org-test-with-temp-text "** H\n:LOGBOOK:\n- a\n:END:"
  4881. (let ((org-odd-levels-only nil)
  4882. (org-adapt-indentation t))
  4883. (org-promote))
  4884. (buffer-string))))
  4885. (should
  4886. (equal
  4887. "# H\n:LOGBOOK:\n- a\n:END:"
  4888. (org-test-with-temp-text "* H\n:LOGBOOK:\n- a\n:END:"
  4889. (let ((org-odd-levels-only nil)
  4890. (org-allow-promoting-top-level-subtree t)
  4891. (org-adapt-indentation t))
  4892. (org-promote))
  4893. (buffer-string))))
  4894. ;; Ignore contents of source blocks or example blocks when
  4895. ;; indentation should be preserved (through
  4896. ;; `org-src-preserve-indentation' or "-i" flag).
  4897. (should-not
  4898. (zerop
  4899. (org-test-with-temp-text
  4900. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  4901. (let ((org-adapt-indentation t)
  4902. (org-src-preserve-indentation nil)
  4903. (org-odd-levels-only nil))
  4904. (org-promote))
  4905. (forward-line)
  4906. (org-get-indentation))))
  4907. (should
  4908. (zerop
  4909. (org-test-with-temp-text
  4910. "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
  4911. (let ((org-adapt-indentation t)
  4912. (org-src-preserve-indentation t)
  4913. (org-odd-levels-only nil))
  4914. (org-promote))
  4915. (forward-line)
  4916. (org-get-indentation))))
  4917. (should
  4918. (zerop
  4919. (org-test-with-temp-text
  4920. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  4921. (let ((org-adapt-indentation t)
  4922. (org-src-preserve-indentation t)
  4923. (org-odd-levels-only nil))
  4924. (org-promote))
  4925. (forward-line)
  4926. (org-get-indentation))))
  4927. (should
  4928. (zerop
  4929. (org-test-with-temp-text
  4930. "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
  4931. (let ((org-adapt-indentation t)
  4932. (org-src-preserve-indentation nil)
  4933. (org-odd-levels-only nil))
  4934. (org-promote))
  4935. (forward-line)
  4936. (org-get-indentation)))))
  4937. (ert-deftest test-org/org-get-valid-level ()
  4938. "Test function `org-get-valid-level' specifications."
  4939. (let ((org-odd-levels-only nil))
  4940. (should (equal 1 (org-get-valid-level 0 0)))
  4941. (should (equal 1 (org-get-valid-level 0 1)))
  4942. (should (equal 2 (org-get-valid-level 0 2)))
  4943. (should (equal 3 (org-get-valid-level 0 3)))
  4944. (should (equal 1 (org-get-valid-level 1 0)))
  4945. (should (equal 2 (org-get-valid-level 1 1)))
  4946. (should (equal 23 (org-get-valid-level 1 22)))
  4947. (should (equal 1 (org-get-valid-level 1 -1)))
  4948. (should (equal 1 (org-get-valid-level 2 -1))))
  4949. (let ((org-odd-levels-only t))
  4950. (should (equal 1 (org-get-valid-level 0 0)))
  4951. (should (equal 1 (org-get-valid-level 0 1)))
  4952. (should (equal 3 (org-get-valid-level 0 2)))
  4953. (should (equal 5 (org-get-valid-level 0 3)))
  4954. (should (equal 1 (org-get-valid-level 1 0)))
  4955. (should (equal 3 (org-get-valid-level 1 1)))
  4956. (should (equal 3 (org-get-valid-level 2 1)))
  4957. (should (equal 5 (org-get-valid-level 3 1)))
  4958. (should (equal 5 (org-get-valid-level 4 1)))
  4959. (should (equal 43 (org-get-valid-level 1 21)))
  4960. (should (equal 1 (org-get-valid-level 1 -1)))
  4961. (should (equal 1 (org-get-valid-level 2 -1)))
  4962. (should (equal 1 (org-get-valid-level 3 -1)))
  4963. (should (equal 3 (org-get-valid-level 4 -1)))
  4964. (should (equal 3 (org-get-valid-level 5 -1)))))
  4965. ;;; Planning
  4966. (ert-deftest test-org/at-planning-p ()
  4967. "Test `org-at-planning-p' specifications."
  4968. ;; Regular test.
  4969. (should
  4970. (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
  4971. (org-at-planning-p)))
  4972. (should-not
  4973. (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
  4974. (org-at-planning-p)))
  4975. ;; Correctly find planning attached to inlinetasks.
  4976. (when (featurep 'org-inlinetask)
  4977. (should
  4978. (org-test-with-temp-text
  4979. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
  4980. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4981. (should-not
  4982. (org-test-with-temp-text
  4983. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  4984. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4985. (should-not
  4986. (org-test-with-temp-text
  4987. "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  4988. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4989. (should-not
  4990. (org-test-with-temp-text
  4991. "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
  4992. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
  4993. (ert-deftest test-org/add-planning-info ()
  4994. "Test `org-add-planning-info'."
  4995. ;; Create deadline when `org-adapt-indentation' is non-nil.
  4996. (should
  4997. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4998. (org-test-with-temp-text "* H\nParagraph<point>"
  4999. (let ((org-adapt-indentation t))
  5000. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5001. (replace-regexp-in-string
  5002. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5003. nil nil 1))))
  5004. ;; Create deadline when `org-adapt-indentation' is nil.
  5005. (should
  5006. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  5007. (org-test-with-temp-text "* H\nParagraph<point>"
  5008. (let ((org-adapt-indentation nil))
  5009. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5010. (replace-regexp-in-string
  5011. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5012. nil nil 1))))
  5013. ;; Update deadline when `org-adapt-indentation' is non-nil.
  5014. (should
  5015. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5016. (org-test-with-temp-text "\
  5017. * H
  5018. DEADLINE: <2015-06-24 Wed>
  5019. Paragraph<point>"
  5020. (let ((org-adapt-indentation t))
  5021. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5022. (replace-regexp-in-string
  5023. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5024. nil nil 1))))
  5025. ;; Update deadline when `org-adapt-indentation' is nil.
  5026. (should
  5027. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  5028. (org-test-with-temp-text "\
  5029. * H
  5030. DEADLINE: <2015-06-24 Wed>
  5031. Paragraph<point>"
  5032. (let ((org-adapt-indentation nil))
  5033. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5034. (replace-regexp-in-string
  5035. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5036. nil nil 1))))
  5037. ;; Schedule when `org-adapt-indentation' is non-nil.
  5038. (should
  5039. (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
  5040. (org-test-with-temp-text "* H\nParagraph<point>"
  5041. (let ((org-adapt-indentation t))
  5042. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  5043. (replace-regexp-in-string
  5044. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5045. nil nil 1))))
  5046. ;; Schedule when `org-adapt-indentation' is nil.
  5047. (should
  5048. (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
  5049. (org-test-with-temp-text "* H\nParagraph<point>"
  5050. (let ((org-adapt-indentation nil))
  5051. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  5052. (replace-regexp-in-string
  5053. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5054. nil nil 1))))
  5055. ;; Add deadline when scheduled.
  5056. (should
  5057. (equal "\
  5058. * H
  5059. DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
  5060. Paragraph"
  5061. (org-test-with-temp-text "\
  5062. * H
  5063. SCHEDULED: <2015-06-24 Wed>
  5064. Paragraph<point>"
  5065. (let ((org-adapt-indentation t))
  5066. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5067. (replace-regexp-in-string
  5068. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5069. nil nil 1))))
  5070. ;; Remove middle entry.
  5071. (should
  5072. (equal "\
  5073. * H
  5074. CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
  5075. Paragraph"
  5076. (org-test-with-temp-text "\
  5077. * H
  5078. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  5079. Paragraph<point>"
  5080. (let ((org-adapt-indentation t))
  5081. (org-add-planning-info nil nil 'deadline))
  5082. (replace-regexp-in-string
  5083. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  5084. nil nil 1))))
  5085. ;; Remove last entry and then middle entry (order should not
  5086. ;; matter).
  5087. (should
  5088. (equal "\
  5089. * H
  5090. CLOSED: [2015-06-24]
  5091. Paragraph"
  5092. (org-test-with-temp-text "\
  5093. * H
  5094. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  5095. Paragraph<point>"
  5096. (let ((org-adapt-indentation t))
  5097. (org-add-planning-info nil nil 'scheduled 'deadline))
  5098. (replace-regexp-in-string
  5099. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  5100. nil nil 1))))
  5101. ;; Remove closed when `org-adapt-indentation' is non-nil.
  5102. (should
  5103. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5104. (org-test-with-temp-text "\
  5105. * H
  5106. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  5107. Paragraph<point>"
  5108. (let ((org-adapt-indentation t))
  5109. (org-add-planning-info nil nil 'closed))
  5110. (replace-regexp-in-string
  5111. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5112. nil nil 1))))
  5113. (should
  5114. (equal "* H\n Paragraph"
  5115. (org-test-with-temp-text "\
  5116. * H
  5117. CLOSED: [2015-06-25 Thu]
  5118. Paragraph<point>"
  5119. (let ((org-adapt-indentation t))
  5120. (org-add-planning-info nil nil 'closed))
  5121. (replace-regexp-in-string
  5122. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5123. nil nil 1))))
  5124. ;; Remove closed when `org-adapt-indentation' is nil.
  5125. (should
  5126. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  5127. (org-test-with-temp-text "\
  5128. * H
  5129. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  5130. Paragraph<point>"
  5131. (let ((org-adapt-indentation nil))
  5132. (org-add-planning-info nil nil 'closed))
  5133. (replace-regexp-in-string
  5134. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5135. nil nil 1))))
  5136. (should
  5137. (equal "* H\nParagraph"
  5138. (org-test-with-temp-text "\
  5139. * H
  5140. CLOSED: [2015-06-25 Thu]
  5141. Paragraph<point>"
  5142. (let ((org-adapt-indentation nil))
  5143. (org-add-planning-info nil nil 'closed))
  5144. (replace-regexp-in-string
  5145. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5146. nil nil 1))))
  5147. ;; Remove closed entry and delete empty line.
  5148. (should
  5149. (equal "\
  5150. * H
  5151. Paragraph"
  5152. (org-test-with-temp-text "\
  5153. * H
  5154. CLOSED: [2015-06-24 Wed]
  5155. Paragraph<point>"
  5156. (let ((org-adapt-indentation t))
  5157. (org-add-planning-info nil nil 'closed))
  5158. (replace-regexp-in-string
  5159. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5160. nil nil 1))))
  5161. ;; Remove one entry and update another.
  5162. (should
  5163. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5164. (org-test-with-temp-text "\
  5165. * H
  5166. SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
  5167. Paragraph<point>"
  5168. (let ((org-adapt-indentation t))
  5169. (org-add-planning-info 'deadline "<2015-06-25 Thu>" 'scheduled))
  5170. (replace-regexp-in-string
  5171. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5172. nil nil 1)))))
  5173. (ert-deftest test-org/deadline ()
  5174. "Test `org-deadline' specifications."
  5175. ;; Insert a new value or replace existing one.
  5176. (should
  5177. (equal "* H\nDEADLINE: <2012-03-29>"
  5178. (org-test-with-temp-text "* H"
  5179. (let ((org-adapt-indentation nil)
  5180. (org-last-inserted-timestamp nil))
  5181. (org-deadline nil "<2012-03-29 Tue>"))
  5182. (replace-regexp-in-string
  5183. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5184. nil nil 1))))
  5185. (should
  5186. (equal "* H\nDEADLINE: <2014-03-04>"
  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 nil "<2014-03-04 Thu>"))
  5191. (replace-regexp-in-string
  5192. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5193. nil nil 1))))
  5194. ;; Accept delta time, e.g., "+2d".
  5195. (should
  5196. (equal "* H\nDEADLINE: <2015-03-04>"
  5197. (org-test-at-time "2014-03-04"
  5198. (org-test-with-temp-text "* H"
  5199. (let ((org-adapt-indentation nil)
  5200. (org-last-inserted-timestamp nil))
  5201. (org-deadline nil "+1y"))
  5202. (replace-regexp-in-string
  5203. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5204. ;; Preserve repeater.
  5205. (should
  5206. (equal "* H\nDEADLINE: <2012-03-29 +2y>"
  5207. (org-test-with-temp-text "* H"
  5208. (let ((org-adapt-indentation nil)
  5209. (org-last-inserted-timestamp nil))
  5210. (org-deadline nil "<2012-03-29 Tue +2y>"))
  5211. (replace-regexp-in-string
  5212. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5213. ;; Remove CLOSED keyword, if any.
  5214. (should
  5215. (equal "* H\nDEADLINE: <2012-03-29>"
  5216. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  5217. (let ((org-adapt-indentation nil)
  5218. (org-last-inserted-timestamp nil))
  5219. (org-deadline nil "<2012-03-29 Tue>"))
  5220. (replace-regexp-in-string
  5221. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5222. ;; With C-u argument, remove DEADLINE keyword.
  5223. (should
  5224. (equal "* H\n"
  5225. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5226. (let ((org-adapt-indentation nil)
  5227. (org-last-inserted-timestamp nil))
  5228. (org-deadline '(4)))
  5229. (buffer-string))))
  5230. (should
  5231. (equal "* H"
  5232. (org-test-with-temp-text "* H"
  5233. (let ((org-adapt-indentation nil)
  5234. (org-last-inserted-timestamp nil))
  5235. (org-deadline '(4)))
  5236. (buffer-string))))
  5237. ;; With C-u C-u argument, prompt for a delay cookie.
  5238. (should
  5239. (equal "* H\nDEADLINE: <2012-03-29 -705d>"
  5240. (cl-letf (((symbol-function 'org-read-date)
  5241. (lambda (&rest args)
  5242. (apply #'encode-time
  5243. (org-parse-time-string "2014-03-04")))))
  5244. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5245. (let ((org-adapt-indentation nil)
  5246. (org-last-inserted-timestamp nil))
  5247. (org-deadline '(16)))
  5248. (buffer-string)))))
  5249. (should-error
  5250. (cl-letf (((symbol-function 'org-read-date)
  5251. (lambda (&rest args)
  5252. (apply #'encode-time
  5253. (org-parse-time-string "2014-03-04")))))
  5254. (org-test-with-temp-text "* H"
  5255. (let ((org-adapt-indentation nil)
  5256. (org-last-inserted-timestamp nil))
  5257. (org-deadline '(16)))
  5258. (buffer-string))))
  5259. ;; When a region is active and
  5260. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5261. ;; same value in all headlines in region.
  5262. (should
  5263. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5264. (org-test-with-temp-text "* H1\n* H2"
  5265. (let ((org-adapt-indentation nil)
  5266. (org-last-inserted-timestamp nil)
  5267. (org-loop-over-headlines-in-active-region t))
  5268. (transient-mark-mode 1)
  5269. (push-mark (point) t t)
  5270. (goto-char (point-max))
  5271. (org-deadline nil "2012-03-29"))
  5272. (replace-regexp-in-string
  5273. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5274. (should-not
  5275. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5276. (org-test-with-temp-text "* H1\n* H2"
  5277. (let ((org-adapt-indentation nil)
  5278. (org-last-inserted-timestamp nil)
  5279. (org-loop-over-headlines-in-active-region nil))
  5280. (transient-mark-mode 1)
  5281. (push-mark (point) t t)
  5282. (goto-char (point-max))
  5283. (org-deadline nil "2012-03-29"))
  5284. (replace-regexp-in-string
  5285. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5286. (ert-deftest test-org/schedule ()
  5287. "Test `org-schedule' specifications."
  5288. ;; Insert a new value or replace existing one.
  5289. (should
  5290. (equal "* H\nSCHEDULED: <2012-03-29>"
  5291. (org-test-with-temp-text "* H"
  5292. (let ((org-adapt-indentation nil)
  5293. (org-last-inserted-timestamp nil))
  5294. (org-schedule nil "<2012-03-29 Tue>"))
  5295. (replace-regexp-in-string
  5296. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5297. nil nil 1))))
  5298. (should
  5299. (equal "* H\nSCHEDULED: <2014-03-04>"
  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 nil "<2014-03-04 Thu>"))
  5304. (replace-regexp-in-string
  5305. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5306. nil nil 1))))
  5307. ;; Accept delta time, e.g., "+2d".
  5308. (should
  5309. (equal "* H\nSCHEDULED: <2015-03-04>"
  5310. (org-test-at-time "2014-03-04"
  5311. (org-test-with-temp-text "* H"
  5312. (let ((org-adapt-indentation nil)
  5313. (org-last-inserted-timestamp nil))
  5314. (org-schedule nil "+1y"))
  5315. (replace-regexp-in-string
  5316. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5317. ;; Preserve repeater.
  5318. (should
  5319. (equal "* H\nSCHEDULED: <2012-03-29 +2y>"
  5320. (org-test-with-temp-text "* H"
  5321. (let ((org-adapt-indentation nil)
  5322. (org-last-inserted-timestamp nil))
  5323. (org-schedule nil "<2012-03-29 Tue +2y>"))
  5324. (replace-regexp-in-string
  5325. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5326. ;; Remove CLOSED keyword, if any.
  5327. (should
  5328. (equal "* H\nSCHEDULED: <2012-03-29>"
  5329. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  5330. (let ((org-adapt-indentation nil)
  5331. (org-last-inserted-timestamp nil))
  5332. (org-schedule nil "<2012-03-29 Tue>"))
  5333. (replace-regexp-in-string
  5334. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5335. ;; With C-u argument, remove SCHEDULED keyword.
  5336. (should
  5337. (equal "* H\n"
  5338. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5339. (let ((org-adapt-indentation nil)
  5340. (org-last-inserted-timestamp nil))
  5341. (org-schedule '(4)))
  5342. (buffer-string))))
  5343. (should
  5344. (equal "* H"
  5345. (org-test-with-temp-text "* H"
  5346. (let ((org-adapt-indentation nil)
  5347. (org-last-inserted-timestamp nil))
  5348. (org-schedule '(4)))
  5349. (buffer-string))))
  5350. ;; With C-u C-u argument, prompt for a delay cookie.
  5351. (should
  5352. (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
  5353. (cl-letf (((symbol-function 'org-read-date)
  5354. (lambda (&rest args)
  5355. (apply #'encode-time
  5356. (org-parse-time-string "2014-03-04")))))
  5357. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5358. (let ((org-adapt-indentation nil)
  5359. (org-last-inserted-timestamp nil))
  5360. (org-schedule '(16)))
  5361. (buffer-string)))))
  5362. (should-error
  5363. (cl-letf (((symbol-function 'org-read-date)
  5364. (lambda (&rest args)
  5365. (apply #'encode-time
  5366. (org-parse-time-string "2014-03-04")))))
  5367. (org-test-with-temp-text "* H"
  5368. (let ((org-adapt-indentation nil)
  5369. (org-last-inserted-timestamp nil))
  5370. (org-schedule '(16)))
  5371. (buffer-string))))
  5372. ;; When a region is active and
  5373. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5374. ;; same value in all headlines in region.
  5375. (should
  5376. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5377. (org-test-with-temp-text "* H1\n* H2"
  5378. (let ((org-adapt-indentation nil)
  5379. (org-last-inserted-timestamp nil)
  5380. (org-loop-over-headlines-in-active-region t))
  5381. (transient-mark-mode 1)
  5382. (push-mark (point) t t)
  5383. (goto-char (point-max))
  5384. (org-schedule nil "2012-03-29"))
  5385. (replace-regexp-in-string
  5386. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5387. (should-not
  5388. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5389. (org-test-with-temp-text "* H1\n* H2"
  5390. (let ((org-adapt-indentation nil)
  5391. (org-last-inserted-timestamp nil)
  5392. (org-loop-over-headlines-in-active-region nil))
  5393. (transient-mark-mode 1)
  5394. (push-mark (point) t t)
  5395. (goto-char (point-max))
  5396. (org-schedule nil "2012-03-29"))
  5397. (replace-regexp-in-string
  5398. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5399. (should
  5400. ;; check if a repeater survives re-scheduling.
  5401. (string-match-p
  5402. "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
  5403. (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
  5404. (let ((org-adapt-indentation nil)
  5405. (org-last-inserted-timestamp nil))
  5406. (org-schedule nil "2017-02-01"))
  5407. (buffer-string)))))
  5408. ;;; Property API
  5409. (ert-deftest test-org/buffer-property-keys ()
  5410. "Test `org-buffer-property-keys' specifications."
  5411. ;; Retrieve properties across siblings.
  5412. (should
  5413. (equal '("A" "B")
  5414. (org-test-with-temp-text "
  5415. * H1
  5416. :PROPERTIES:
  5417. :A: 1
  5418. :END:
  5419. * H2
  5420. :PROPERTIES:
  5421. :B: 1
  5422. :END:"
  5423. (org-buffer-property-keys))))
  5424. ;; Retrieve properties across children.
  5425. (should
  5426. (equal '("A" "B")
  5427. (org-test-with-temp-text "
  5428. * H1
  5429. :PROPERTIES:
  5430. :A: 1
  5431. :END:
  5432. ** H2
  5433. :PROPERTIES:
  5434. :B: 1
  5435. :END:"
  5436. (org-buffer-property-keys))))
  5437. ;; Retrieve muliple properties in the same drawer.
  5438. (should
  5439. (equal '("A" "B")
  5440. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5441. (org-buffer-property-keys))))
  5442. ;; Ignore extension symbol in property name.
  5443. (should
  5444. (equal '("A")
  5445. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5446. (org-buffer-property-keys))))
  5447. ;; Add bare property if xxx_ALL property is there
  5448. (should
  5449. (equal '("A" "B" "B_ALL")
  5450. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B_ALL: foo bar\n:END:"
  5451. (org-buffer-property-keys))))
  5452. ;; Add bare property if xxx_ALL property is there - check dupes
  5453. (should
  5454. (equal '("A" "B" "B_ALL")
  5455. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:B_ALL: foo bar\n:END:"
  5456. (org-buffer-property-keys))))
  5457. ;; Retrieve properties from #+PROPERTY keyword lines
  5458. (should
  5459. (equal '("A" "C")
  5460. (org-test-with-temp-text "#+PROPERTY: C foo\n* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5461. (org-buffer-property-keys))))
  5462. ;; Retrieve properties from #+PROPERTY keyword lines - make sure an _ALL property also
  5463. ;; adds the bare property
  5464. (should
  5465. (equal '("A" "C" "C_ALL")
  5466. (org-test-with-temp-text "#+PROPERTY: C_ALL foo bar\n* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5467. (org-buffer-property-keys))))
  5468. ;; With non-nil COLUMNS, extract property names from columns.
  5469. (should
  5470. (equal '("A" "B")
  5471. (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
  5472. (org-buffer-property-keys nil nil t))))
  5473. (should
  5474. (equal '("A" "B" "COLUMNS")
  5475. (org-test-with-temp-text
  5476. "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
  5477. (org-buffer-property-keys nil nil t))))
  5478. ;; In COLUMNS, ignore title and summary-type.
  5479. (should
  5480. (equal '("A")
  5481. (org-test-with-temp-text "#+COLUMNS: %A(Foo)"
  5482. (org-buffer-property-keys nil nil t))))
  5483. (should
  5484. (equal '("A")
  5485. (org-test-with-temp-text "#+COLUMNS: %A{Foo}"
  5486. (org-buffer-property-keys nil nil t))))
  5487. (should
  5488. (equal '("A")
  5489. (org-test-with-temp-text "#+COLUMNS: %A(Foo){Bar}"
  5490. (org-buffer-property-keys nil nil t)))))
  5491. (ert-deftest test-org/property-values ()
  5492. "Test `org-property-values' specifications."
  5493. ;; Regular test.
  5494. (should
  5495. (equal '("2" "1")
  5496. (org-test-with-temp-text
  5497. "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
  5498. (org-property-values "A"))))
  5499. ;; Ignore empty values.
  5500. (should-not
  5501. (org-test-with-temp-text
  5502. "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
  5503. (org-property-values "A")))
  5504. ;; Take into consideration extended values.
  5505. (should
  5506. (equal '("1 2")
  5507. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5508. (org-property-values "A")))))
  5509. (ert-deftest test-org/set-property ()
  5510. "Test `org-set-property' specifications."
  5511. (should
  5512. (equal
  5513. ":PROPERTIES:\n:TEST: t\n:END:\n"
  5514. (org-test-with-temp-text ""
  5515. (let ((org-property-format "%s %s"))
  5516. (org-set-property "TEST" "t"))
  5517. (buffer-string))))
  5518. (should
  5519. (equal
  5520. "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5521. (org-test-with-temp-text "* H"
  5522. (let ((org-adapt-indentation nil)
  5523. (org-property-format "%s %s"))
  5524. (org-set-property "TEST" "t"))
  5525. (buffer-string)))))
  5526. (ert-deftest test-org/delete-property ()
  5527. "Test `org-delete-property' specifications."
  5528. (should
  5529. (equal
  5530. ""
  5531. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5532. (org-delete-property "TEST")
  5533. (buffer-string))))
  5534. (should
  5535. (equal
  5536. ":PROPERTIES:\n:TEST1: t\n:END:\n"
  5537. (org-test-with-temp-text ":PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5538. (org-delete-property "TEST2")
  5539. (buffer-string))))
  5540. (should
  5541. (equal
  5542. "* H\n"
  5543. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5544. (org-delete-property "TEST")
  5545. (buffer-string))))
  5546. (should
  5547. (equal
  5548. "* H\n:PROPERTIES:\n:TEST1: t\n:END:\n"
  5549. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5550. (org-delete-property "TEST2")
  5551. (buffer-string)))))
  5552. (ert-deftest test-org/delete-property-globally ()
  5553. "Test `org-delete-property-global' specifications."
  5554. (should
  5555. (equal
  5556. ""
  5557. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5558. (org-delete-property-globally "TEST")
  5559. (buffer-string))))
  5560. (should
  5561. (equal
  5562. "* H\n"
  5563. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n* H\n:PROPERTIES:\n:TEST: nil\n:END:"
  5564. (org-delete-property-globally "TEST")
  5565. (buffer-string)))))
  5566. (ert-deftest test-org/find-property ()
  5567. "Test `org-find-property' specifications."
  5568. ;; Regular test.
  5569. (should
  5570. (= 1
  5571. (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
  5572. (org-find-property "prop"))))
  5573. ;; Find properties in top-level property drawer.
  5574. (should
  5575. (= 1
  5576. (org-test-with-temp-text ":PROPERTIES:\n:PROP: value\n:END:"
  5577. (org-find-property "prop"))))
  5578. ;; Ignore false positives.
  5579. (should
  5580. (= 27
  5581. (org-test-with-temp-text
  5582. "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
  5583. (org-find-property "A"))))
  5584. ;; Return first entry found in buffer.
  5585. (should
  5586. (= 1
  5587. (org-test-with-temp-text
  5588. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5589. (org-find-property "A"))))
  5590. ;; Only search visible part of the buffer.
  5591. (should
  5592. (= 31
  5593. (org-test-with-temp-text
  5594. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5595. (org-narrow-to-subtree)
  5596. (org-find-property "A"))))
  5597. ;; With optional argument, only find entries with a specific value.
  5598. (should-not
  5599. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5600. (org-find-property "A" "2")))
  5601. (should
  5602. (= 31
  5603. (org-test-with-temp-text
  5604. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
  5605. (org-find-property "A" "2"))))
  5606. ;; Use "nil" for explicit nil values.
  5607. (should
  5608. (= 31
  5609. (org-test-with-temp-text
  5610. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
  5611. (org-find-property "A" "nil")))))
  5612. (ert-deftest test-org/entry-delete ()
  5613. "Test `org-entry-delete' specifications."
  5614. ;; Regular test.
  5615. (should
  5616. (string-match
  5617. " *:PROPERTIES:\n *:B: +2\n *:END:"
  5618. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5619. (org-entry-delete (point) "A")
  5620. (buffer-string))))
  5621. ;; Also remove accumulated properties.
  5622. (should-not
  5623. (string-match
  5624. ":A"
  5625. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
  5626. (org-entry-delete (point) "A")
  5627. (buffer-string))))
  5628. ;; When last property is removed, remove the property drawer.
  5629. (should-not
  5630. (string-match
  5631. ":PROPERTIES:"
  5632. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
  5633. (org-entry-delete (point) "A")
  5634. (buffer-string))))
  5635. ;; Return a non-nil value when some property was removed.
  5636. (should
  5637. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5638. (org-entry-delete (point) "A")))
  5639. (should-not
  5640. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5641. (org-entry-delete (point) "C")))
  5642. ;; Special properties cannot be located in a drawer. Allow to
  5643. ;; remove them anyway, in case of user error.
  5644. (should
  5645. (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
  5646. (org-entry-delete (point) "SCHEDULED"))))
  5647. (ert-deftest test-org/entry-get ()
  5648. "Test `org-entry-get' specifications."
  5649. ;; Regular test.
  5650. (should
  5651. (equal "1"
  5652. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:"
  5653. (org-entry-get (point) "A"))))
  5654. (should
  5655. (equal "1"
  5656. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5657. (org-entry-get (point) "A"))))
  5658. ;; Ignore case.
  5659. (should
  5660. (equal "1"
  5661. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5662. (org-entry-get (point) "a"))))
  5663. ;; Handle extended values, both before and after base value.
  5664. (should
  5665. (equal "1 2 3"
  5666. (org-test-with-temp-text
  5667. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5668. (org-entry-get (point) "A"))))
  5669. ;; Empty values are returned as the empty string.
  5670. (should
  5671. (equal ""
  5672. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
  5673. (org-entry-get (point) "A"))))
  5674. ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
  5675. ;; otherwise, return nil.
  5676. (should-not
  5677. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5678. (org-entry-get (point) "A")))
  5679. (should
  5680. (equal "nil"
  5681. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5682. (org-entry-get (point) "A" nil t))))
  5683. ;; Return nil when no property is found, independently on the
  5684. ;; LITERAL-NIL argument.
  5685. (should-not
  5686. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5687. (org-entry-get (point) "B")))
  5688. (should-not
  5689. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5690. (org-entry-get (point) "B" nil t)))
  5691. ;; Handle inheritance, when allowed. Include extended values and
  5692. ;; possibly global values.
  5693. (should
  5694. (equal
  5695. "1"
  5696. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:\n* H"
  5697. (org-entry-get (point-max) "A" t))))
  5698. (should
  5699. (equal
  5700. "1"
  5701. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5702. (org-entry-get (point-max) "A" t))))
  5703. (should
  5704. (equal
  5705. "1"
  5706. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5707. (let ((org-use-property-inheritance t))
  5708. (org-entry-get (point-max) "A" 'selective)))))
  5709. (should-not
  5710. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5711. (let ((org-use-property-inheritance nil))
  5712. (org-entry-get (point-max) "A" 'selective))))
  5713. (should-not
  5714. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H2"
  5715. (let ((org-use-property-inheritance t))
  5716. (org-entry-get (point-max) "A" t))))
  5717. (should
  5718. (equal
  5719. "1 2"
  5720. (org-test-with-temp-text
  5721. ":PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5722. (org-entry-get (point-max) "A" t))))
  5723. (should
  5724. (equal
  5725. "1 2"
  5726. (org-test-with-temp-text
  5727. "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5728. (org-entry-get (point-max) "A" t))))
  5729. (should
  5730. (equal
  5731. "1 2"
  5732. (org-test-with-temp-text
  5733. ":PROPERTIES:\n:A: 1\n:END:\n* H1\n* H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5734. (org-entry-get (point-max) "A" t))))
  5735. (should
  5736. (equal
  5737. "1 2"
  5738. (org-test-with-temp-text
  5739. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2.1\n** H2.2\n:PROPERTIES:\n:A+: 2\n:END:"
  5740. (org-entry-get (point-max) "A" t))))
  5741. (should
  5742. (equal "1"
  5743. (org-test-with-temp-text
  5744. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
  5745. (org-mode-restart)
  5746. (org-entry-get (point-max) "A" t))))
  5747. (should
  5748. (equal "0 1"
  5749. (org-test-with-temp-text
  5750. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
  5751. (org-mode-restart)
  5752. (org-entry-get (point-max) "A" t))))
  5753. ;; document level property-drawer has precedance over
  5754. ;; global-property by PROPERTY-keyword.
  5755. (should
  5756. (equal "0 2"
  5757. (org-test-with-temp-text
  5758. ":PROPERTIES:\n:A: 0\n:END:\n#+PROPERTY: A 1\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5759. (org-mode-restart)
  5760. (org-entry-get (point-max) "A" t)))))
  5761. (ert-deftest test-org/entry-properties ()
  5762. "Test `org-entry-properties' specifications."
  5763. ;; Get "ITEM" property.
  5764. (should
  5765. (equal "H"
  5766. (org-test-with-temp-text "* TODO H"
  5767. (cdr (assoc "ITEM" (org-entry-properties nil "ITEM"))))))
  5768. (should
  5769. (equal "H"
  5770. (org-test-with-temp-text "* TODO H"
  5771. (cdr (assoc "ITEM" (org-entry-properties))))))
  5772. ;; Get "TODO" property. TODO keywords are case sensitive.
  5773. (should
  5774. (equal "TODO"
  5775. (org-test-with-temp-text "* TODO H"
  5776. (cdr (assoc "TODO" (org-entry-properties nil "TODO"))))))
  5777. (should
  5778. (equal "TODO"
  5779. (org-test-with-temp-text "* TODO H"
  5780. (cdr (assoc "TODO" (org-entry-properties))))))
  5781. (should-not
  5782. (org-test-with-temp-text "* H"
  5783. (assoc "TODO" (org-entry-properties nil "TODO"))))
  5784. (should-not
  5785. (org-test-with-temp-text "* todo H"
  5786. (assoc "TODO" (org-entry-properties nil "TODO"))))
  5787. ;; Get "PRIORITY" property.
  5788. (should
  5789. (equal "A"
  5790. (org-test-with-temp-text "* [#A] H"
  5791. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  5792. (should
  5793. (equal "A"
  5794. (org-test-with-temp-text "* [#A] H"
  5795. (cdr (assoc "PRIORITY" (org-entry-properties))))))
  5796. (should
  5797. (equal (char-to-string org-priority-default)
  5798. (org-test-with-temp-text "* H"
  5799. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  5800. ;; Get "FILE" property.
  5801. (should
  5802. (org-test-with-temp-text-in-file "* H\nParagraph"
  5803. (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil "FILE")))
  5804. (buffer-file-name))))
  5805. (should
  5806. (org-test-with-temp-text-in-file "* H\nParagraph"
  5807. (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
  5808. (buffer-file-name))))
  5809. (should-not
  5810. (org-test-with-temp-text "* H\nParagraph"
  5811. (cdr (assoc "FILE" (org-entry-properties nil "FILE")))))
  5812. ;; Get "TAGS" property.
  5813. (should
  5814. (equal ":tag1:tag2:"
  5815. (org-test-with-temp-text "* H :tag1:tag2:"
  5816. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS"))))))
  5817. (should
  5818. (equal ":tag1:tag2:"
  5819. (org-test-with-temp-text "* H :tag1:tag2:"
  5820. (cdr (assoc "TAGS" (org-entry-properties))))))
  5821. (should-not
  5822. (org-test-with-temp-text "* H"
  5823. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS")))))
  5824. ;; Get "ALLTAGS" property.
  5825. (should
  5826. (equal ":tag1:tag2:"
  5827. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  5828. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS"))))))
  5829. (should
  5830. (equal ":tag1:tag2:"
  5831. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  5832. (cdr (assoc "ALLTAGS" (org-entry-properties))))))
  5833. (should-not
  5834. (org-test-with-temp-text "* H"
  5835. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS")))))
  5836. ;; Get "BLOCKED" property.
  5837. (should
  5838. (equal "t"
  5839. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  5840. (let ((org-enforce-todo-dependencies t)
  5841. (org-blocker-hook
  5842. '(org-block-todo-from-children-or-siblings-or-parent)))
  5843. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  5844. (should
  5845. (equal ""
  5846. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  5847. (let ((org-enforce-todo-dependencies t)
  5848. (org-blocker-hook
  5849. '(org-block-todo-from-children-or-siblings-or-parent)))
  5850. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  5851. ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
  5852. (should
  5853. (equal
  5854. "[2012-03-29 thu.]"
  5855. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  5856. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED"))))))
  5857. (should
  5858. (equal
  5859. "[2012-03-29 thu.]"
  5860. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  5861. (cdr (assoc "CLOSED" (org-entry-properties))))))
  5862. (should-not
  5863. (org-test-with-temp-text "* H"
  5864. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED")))))
  5865. (should
  5866. (equal
  5867. "<2014-03-04 tue.>"
  5868. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5869. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE"))))))
  5870. (should
  5871. (equal
  5872. "<2014-03-04 tue.>"
  5873. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5874. (cdr (assoc "DEADLINE" (org-entry-properties))))))
  5875. (should-not
  5876. (org-test-with-temp-text "* H"
  5877. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE")))))
  5878. (should
  5879. (equal
  5880. "<2014-03-04 tue.>"
  5881. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5882. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED"))))))
  5883. (should
  5884. (equal
  5885. "<2014-03-04 tue.>"
  5886. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5887. (cdr (assoc "SCHEDULED" (org-entry-properties))))))
  5888. (should-not
  5889. (org-test-with-temp-text "* H"
  5890. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED")))))
  5891. ;; Get "CATEGORY"
  5892. (should
  5893. (equal "cat"
  5894. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  5895. (cdr (assoc "CATEGORY" (org-entry-properties))))))
  5896. (should
  5897. (equal "cat"
  5898. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  5899. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5900. (should
  5901. (equal "cat"
  5902. (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
  5903. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5904. (should
  5905. (equal "cat2"
  5906. (org-test-with-temp-text
  5907. (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  5908. "\n"
  5909. "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
  5910. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5911. ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
  5912. (should
  5913. (equal "<2012-03-29 thu.>"
  5914. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
  5915. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  5916. (should
  5917. (equal "[2012-03-29 thu.]"
  5918. (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
  5919. (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
  5920. (should
  5921. (equal "<2012-03-29 thu.>"
  5922. (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
  5923. (cdr (assoc "TIMESTAMP" (org-entry-properties nil "TIMESTAMP"))))))
  5924. (should
  5925. (equal "[2014-03-04 tue.]"
  5926. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
  5927. (cdr (assoc "TIMESTAMP_IA"
  5928. (org-entry-properties nil "TIMESTAMP_IA"))))))
  5929. (should-not
  5930. (equal "<2012-03-29 thu.>"
  5931. (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
  5932. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  5933. ;; Get standard properties.
  5934. (should
  5935. (equal "1"
  5936. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5937. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5938. ;; Handle extended properties.
  5939. (should
  5940. (equal "1 2 3"
  5941. (org-test-with-temp-text
  5942. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5943. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5944. (should
  5945. (equal "1 2 3"
  5946. (org-test-with-temp-text
  5947. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
  5948. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5949. ;; Ignore forbidden (special) properties.
  5950. (should-not
  5951. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
  5952. (cdr (assoc "TODO" (org-entry-properties nil 'standard))))))
  5953. (ert-deftest test-org/entry-put ()
  5954. "Test `org-entry-put' specifications."
  5955. ;; Error when not a string or nil.
  5956. (should-error
  5957. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5958. (org-entry-put 1 "test" 2)))
  5959. ;; Error when property name is invalid.
  5960. (should-error
  5961. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5962. (org-entry-put 1 "no space" "value")))
  5963. (should-error
  5964. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5965. (org-entry-put 1 "" "value")))
  5966. ;; Set "TODO" property.
  5967. (should
  5968. (string-match (regexp-quote " TODO H")
  5969. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  5970. (org-entry-put (point) "TODO" "TODO")
  5971. (buffer-string))))
  5972. (should
  5973. (string-match (regexp-quote "* H")
  5974. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  5975. (org-entry-put (point) "TODO" nil)
  5976. (buffer-string))))
  5977. ;; Set "PRIORITY" property.
  5978. (should
  5979. (equal "* [#A] H"
  5980. (org-test-with-temp-text "* [#B] H"
  5981. (org-entry-put (point) "PRIORITY" "A")
  5982. (buffer-string))))
  5983. (should
  5984. (equal "* H"
  5985. (org-test-with-temp-text "* [#B] H"
  5986. (org-entry-put (point) "PRIORITY" nil)
  5987. (buffer-string))))
  5988. ;; Set "SCHEDULED" property.
  5989. (should
  5990. (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
  5991. (org-test-with-temp-text "* H"
  5992. (org-entry-put (point) "SCHEDULED" "2014-03-04")
  5993. (buffer-string))))
  5994. (should
  5995. (string= "* H\n"
  5996. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5997. (org-entry-put (point) "SCHEDULED" nil)
  5998. (buffer-string))))
  5999. (should
  6000. (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
  6001. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6002. (org-entry-put (point) "SCHEDULED" "earlier")
  6003. (buffer-string))))
  6004. (should
  6005. (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
  6006. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6007. (org-entry-put (point) "SCHEDULED" "later")
  6008. (buffer-string))))
  6009. ;; Set "DEADLINE" property.
  6010. (should
  6011. (string-match "^ *DEADLINE: <2014-03-04 .*?>"
  6012. (org-test-with-temp-text "* H"
  6013. (org-entry-put (point) "DEADLINE" "2014-03-04")
  6014. (buffer-string))))
  6015. (should
  6016. (string= "* H\n"
  6017. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6018. (org-entry-put (point) "DEADLINE" nil)
  6019. (buffer-string))))
  6020. (should
  6021. (string-match "^ *DEADLINE: <2014-03-03 .*?>"
  6022. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6023. (org-entry-put (point) "DEADLINE" "earlier")
  6024. (buffer-string))))
  6025. (should
  6026. (string-match "^ *DEADLINE: <2014-03-05 .*?>"
  6027. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6028. (org-entry-put (point) "DEADLINE" "later")
  6029. (buffer-string))))
  6030. ;; Set "CATEGORY" property
  6031. (should
  6032. (string-match "^ *:CATEGORY: cat"
  6033. (org-test-with-temp-text "* H"
  6034. (org-entry-put (point) "CATEGORY" "cat")
  6035. (buffer-string))))
  6036. ;; Regular properties, with or without pre-existing drawer.
  6037. (should
  6038. (string-match "^ *:A: +2$"
  6039. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6040. (org-entry-put (point) "A" "2")
  6041. (buffer-string))))
  6042. (should
  6043. (string-match "^ *:A: +1$"
  6044. (org-test-with-temp-text "* H"
  6045. (org-entry-put (point) "A" "1")
  6046. (buffer-string))))
  6047. ;; Special case: two consecutive headlines.
  6048. (should
  6049. (string-match "\\* A\n *:PROPERTIES:"
  6050. (org-test-with-temp-text "* A\n** B"
  6051. (org-entry-put (point) "A" "1")
  6052. (buffer-string)))))
  6053. (ert-deftest test-org/refresh-properties ()
  6054. "Test `org-refresh-properties' specifications."
  6055. (should
  6056. (equal "1"
  6057. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6058. (org-refresh-properties "A" 'org-test)
  6059. (get-text-property (point) 'org-test))))
  6060. (should-not
  6061. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6062. (org-refresh-properties "B" 'org-test)
  6063. (get-text-property (point) 'org-test)))
  6064. ;; Handle properties only defined with extension syntax, i.e.,
  6065. ;; "PROPERTY+".
  6066. (should
  6067. (equal "1"
  6068. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
  6069. (org-refresh-properties "A" 'org-test)
  6070. (get-text-property (point) 'org-test))))
  6071. ;; When property is inherited, add text property to the whole
  6072. ;; sub-tree.
  6073. (should
  6074. (equal "1"
  6075. (org-test-with-temp-text
  6076. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
  6077. (let ((org-use-property-inheritance t))
  6078. (org-refresh-properties "A" 'org-test))
  6079. (get-text-property (point) 'org-test))))
  6080. ;; When a document level property-drawer is used, those properties
  6081. ;; should work exactly like headline-properties as if at a
  6082. ;; headline-level 0.
  6083. (should
  6084. (equal "1"
  6085. (org-test-with-temp-text
  6086. ":PROPERTIES:\n:A: 1\n:END:\n"
  6087. (org-mode-restart)
  6088. (let ((org-use-property-inheritance t))
  6089. (org-refresh-properties "A" 'org-test))
  6090. (get-text-property (point) 'org-test))))
  6091. (should-not
  6092. (equal "1"
  6093. (org-test-with-temp-text
  6094. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  6095. (org-mode-restart)
  6096. (let ((org-use-property-inheritance nil))
  6097. (org-refresh-properties "A" 'org-test))
  6098. (get-text-property (point) 'org-test))))
  6099. (should
  6100. (equal "1"
  6101. (org-test-with-temp-text
  6102. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  6103. (org-mode-restart)
  6104. (let ((org-use-property-inheritance t))
  6105. (org-refresh-properties "A" 'org-test))
  6106. (get-text-property (point) 'org-test))))
  6107. (should
  6108. (equal "2"
  6109. (org-test-with-temp-text
  6110. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1\n:PROPERTIES:\n:A: 2\n:END:"
  6111. (org-mode-restart)
  6112. (let ((org-use-property-inheritance t))
  6113. (org-refresh-properties "A" 'org-test))
  6114. (get-text-property (point) 'org-test))))
  6115. ;; When property is inherited, use global value across the whole
  6116. ;; buffer. However local values have precedence, as well as the
  6117. ;; document level property-drawer.
  6118. (should-not
  6119. (equal "1"
  6120. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  6121. (org-mode-restart)
  6122. (let ((org-use-property-inheritance nil))
  6123. (org-refresh-properties "A" 'org-test))
  6124. (get-text-property (point) 'org-test))))
  6125. (should
  6126. (equal "1"
  6127. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  6128. (org-mode-restart)
  6129. (let ((org-use-property-inheritance t))
  6130. (org-refresh-properties "A" 'org-test))
  6131. (get-text-property (point) 'org-test))))
  6132. (should
  6133. (equal "2"
  6134. (org-test-with-temp-text
  6135. "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
  6136. (org-mode-restart)
  6137. (let ((org-use-property-inheritance t))
  6138. (org-refresh-properties "A" 'org-test))
  6139. (get-text-property (point) 'org-test))))
  6140. ;; When both keyword-property and document-level property-block is
  6141. ;; defined, the property-block has precedance.
  6142. (should
  6143. (equal "1"
  6144. (org-test-with-temp-text
  6145. ":PROPERTIES:\n:A: 1\n:END:\n#+PROPERTY: A 2\n<point>* H1"
  6146. (org-mode-restart)
  6147. (let ((org-use-property-inheritance t))
  6148. (org-refresh-properties "A" 'org-test))
  6149. (get-text-property (point) 'org-test)))))
  6150. (ert-deftest test-org/refresh-category-properties ()
  6151. "Test `org-refresh-category-properties' specifications"
  6152. (should
  6153. (equal "cat1"
  6154. (org-test-with-temp-text
  6155. ":PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6156. (org-refresh-category-properties)
  6157. (org-get-category))))
  6158. (should
  6159. (equal "cat1"
  6160. (org-test-with-temp-text
  6161. "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6162. (org-refresh-category-properties)
  6163. (org-get-category))))
  6164. ;; Even though property-inheritance is deactivated, category
  6165. ;; property should be inherited. As described in
  6166. ;; `org-use-property-inheritance'.
  6167. (should
  6168. (equal "cat1"
  6169. (org-test-with-temp-text
  6170. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  6171. (org-mode-restart)
  6172. (let ((org-use-property-inheritance nil))
  6173. (org-refresh-category-properties))
  6174. (org-get-category))))
  6175. (should
  6176. (equal "cat1"
  6177. (org-test-with-temp-text
  6178. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  6179. (org-mode-restart)
  6180. (let ((org-use-property-inheritance t))
  6181. (org-refresh-category-properties))
  6182. (org-get-category))))
  6183. (should
  6184. (equal "cat2"
  6185. (org-test-with-temp-text
  6186. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H\n:PROPERTIES:\n:CATEGORY: cat2\n:END:\n"
  6187. (org-mode-restart)
  6188. (let ((org-use-property-inheritance t))
  6189. (org-refresh-category-properties))
  6190. (org-get-category)))))
  6191. ;;; Refile
  6192. (ert-deftest test-org/refile-get-targets ()
  6193. "Test `org-refile-get-targets' specifications."
  6194. ;; :maxlevel includes all headings above specified value.
  6195. (should
  6196. (equal '("H1" "H2" "H3")
  6197. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6198. (let ((org-refile-use-outline-path nil)
  6199. (org-refile-targets `((nil :maxlevel . 3))))
  6200. (mapcar #'car (org-refile-get-targets))))))
  6201. (should
  6202. (equal '("H1" "H2")
  6203. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6204. (let ((org-refile-use-outline-path nil)
  6205. (org-refile-targets `((nil :maxlevel . 2))))
  6206. (mapcar #'car (org-refile-get-targets))))))
  6207. ;; :level limits targets to headlines with the specified level.
  6208. (should
  6209. (equal '("H2")
  6210. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6211. (let ((org-refile-use-outline-path nil)
  6212. (org-refile-targets `((nil :level . 2))))
  6213. (mapcar #'car (org-refile-get-targets))))))
  6214. ;; :tag limits targets to headlines with specified tag.
  6215. (should
  6216. (equal '("H1")
  6217. (org-test-with-temp-text "* H1 :foo:\n** H2\n*** H3 :bar:"
  6218. (let ((org-refile-use-outline-path nil)
  6219. (org-refile-targets `((nil :tag . "foo"))))
  6220. (mapcar #'car (org-refile-get-targets))))))
  6221. ;; :todo limits targets to headlines with specified TODO keyword.
  6222. (should
  6223. (equal '("H2")
  6224. (org-test-with-temp-text "* H1\n** TODO H2\n*** DONE H3"
  6225. (let ((org-refile-use-outline-path nil)
  6226. (org-refile-targets `((nil :todo . "TODO"))))
  6227. (mapcar #'car (org-refile-get-targets))))))
  6228. ;; :regexp filters targets matching provided regexp.
  6229. (should
  6230. (equal '("F2" "F3")
  6231. (org-test-with-temp-text "* H1\n** F2\n*** F3"
  6232. (let ((org-refile-use-outline-path nil)
  6233. (org-refile-targets `((nil :regexp . "F"))))
  6234. (mapcar #'car (org-refile-get-targets))))))
  6235. ;; A nil `org-refile-targets' includes only top level headlines in
  6236. ;; current buffer.
  6237. (should
  6238. (equal '("H1" "H2")
  6239. (org-test-with-temp-text "* H1\n** S1\n* H2"
  6240. (let ((org-refile-use-outline-path nil)
  6241. (org-refile-targets nil))
  6242. (mapcar #'car (org-refile-get-targets))))))
  6243. ;; Return value is the union of the targets according to all the
  6244. ;; defined rules. However, prevent duplicates.
  6245. (should
  6246. (equal '("F2" "F3" "H1")
  6247. (org-test-with-temp-text "* TODO H1\n** F2\n*** F3"
  6248. (let ((org-refile-use-outline-path nil)
  6249. (org-refile-targets `((nil :regexp . "F")
  6250. (nil :todo . "TODO"))))
  6251. (mapcar #'car (org-refile-get-targets))))))
  6252. (should
  6253. (equal '("F2" "F3" "H1")
  6254. (org-test-with-temp-text "* TODO H1\n** TODO F2\n*** F3"
  6255. (let ((org-refile-use-outline-path nil)
  6256. (org-refile-targets `((nil :regexp . "F")
  6257. (nil :todo . "TODO"))))
  6258. (mapcar #'car (org-refile-get-targets))))))
  6259. ;; When `org-refile-use-outline-path' is non-nil, provide targets as
  6260. ;; paths.
  6261. (should
  6262. (equal '("H1" "H1/H2" "H1/H2/H3")
  6263. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6264. (let ((org-refile-use-outline-path t)
  6265. (org-refile-targets `((nil :maxlevel . 3))))
  6266. (mapcar #'car (org-refile-get-targets))))))
  6267. ;; When providing targets as paths, escape forward slashes in
  6268. ;; headings with backslashes.
  6269. (should
  6270. (equal '("H1\\/foo")
  6271. (org-test-with-temp-text "* H1/foo"
  6272. (let ((org-refile-use-outline-path t)
  6273. (org-refile-targets `((nil :maxlevel . 1))))
  6274. (mapcar #'car (org-refile-get-targets))))))
  6275. ;; When `org-refile-use-outline-path' is `file', include file name
  6276. ;; without directory in targets.
  6277. (should
  6278. (org-test-with-temp-text-in-file "* H1"
  6279. (let* ((filename (buffer-file-name))
  6280. (org-refile-use-outline-path 'file)
  6281. (org-refile-targets `(((,filename) :level . 1))))
  6282. (member (file-name-nondirectory filename)
  6283. (mapcar #'car (org-refile-get-targets))))))
  6284. ;; When `org-refile-use-outline-path' is `full-file-path', include
  6285. ;; full file name.
  6286. (should
  6287. (org-test-with-temp-text-in-file "* H1"
  6288. (let* ((filename (file-truename (buffer-file-name)))
  6289. (org-refile-use-outline-path 'full-file-path)
  6290. (org-refile-targets `(((,filename) :level . 1))))
  6291. (member filename (mapcar #'car (org-refile-get-targets))))))
  6292. ;; When `org-refile-use-outline-path' is `buffer-name', include
  6293. ;; buffer name.
  6294. (should
  6295. (org-test-with-temp-text "* H1"
  6296. (let* ((org-refile-use-outline-path 'buffer-name)
  6297. (org-refile-targets `((nil :level . 1))))
  6298. (member (buffer-name) (mapcar #'car (org-refile-get-targets)))))))
  6299. ;;; Sparse trees
  6300. (ert-deftest test-org/match-sparse-tree ()
  6301. "Test `org-match-sparse-tree' specifications."
  6302. ;; Match tags.
  6303. (should-not
  6304. (org-test-with-temp-text "* H\n** H1 :tag:"
  6305. (org-match-sparse-tree nil "tag")
  6306. (search-forward "H1")
  6307. (org-invisible-p2)))
  6308. (should
  6309. (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
  6310. (org-match-sparse-tree nil "tag")
  6311. (search-forward "H2")
  6312. (org-invisible-p2)))
  6313. ;; "-" operator for tags.
  6314. (should-not
  6315. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6316. (org-match-sparse-tree nil "tag1-tag2")
  6317. (search-forward "H1")
  6318. (org-invisible-p2)))
  6319. (should
  6320. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6321. (org-match-sparse-tree nil "tag1-tag2")
  6322. (search-forward "H2")
  6323. (org-invisible-p2)))
  6324. ;; "&" operator for tags.
  6325. (should
  6326. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6327. (org-match-sparse-tree nil "tag1&tag2")
  6328. (search-forward "H1")
  6329. (org-invisible-p2)))
  6330. (should-not
  6331. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6332. (org-match-sparse-tree nil "tag1&tag2")
  6333. (search-forward "H2")
  6334. (org-invisible-p2)))
  6335. ;; "|" operator for tags.
  6336. (should-not
  6337. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6338. (org-match-sparse-tree nil "tag1|tag2")
  6339. (search-forward "H1")
  6340. (org-invisible-p2)))
  6341. (should-not
  6342. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6343. (org-match-sparse-tree nil "tag1|tag2")
  6344. (search-forward "H2")
  6345. (org-invisible-p2)))
  6346. ;; Regexp match on tags.
  6347. (should-not
  6348. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6349. (org-match-sparse-tree nil "{^tag.*}")
  6350. (search-forward "H1")
  6351. (org-invisible-p2)))
  6352. (should
  6353. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6354. (org-match-sparse-tree nil "{^tag.*}")
  6355. (search-forward "H2")
  6356. (org-invisible-p2)))
  6357. ;; Match group tags.
  6358. (should-not
  6359. (org-test-with-temp-text
  6360. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6361. (org-match-sparse-tree nil "work")
  6362. (search-forward "H1")
  6363. (org-invisible-p2)))
  6364. (should-not
  6365. (org-test-with-temp-text
  6366. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6367. (org-match-sparse-tree nil "work")
  6368. (search-forward "H2")
  6369. (org-invisible-p2)))
  6370. ;; Match group tags with hard brackets.
  6371. (should-not
  6372. (org-test-with-temp-text
  6373. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6374. (org-match-sparse-tree nil "work")
  6375. (search-forward "H1")
  6376. (org-invisible-p2)))
  6377. (should-not
  6378. (org-test-with-temp-text
  6379. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6380. (org-match-sparse-tree nil "work")
  6381. (search-forward "H2")
  6382. (org-invisible-p2)))
  6383. ;; Match tags in hierarchies
  6384. (should-not
  6385. (org-test-with-temp-text
  6386. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6387. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6388. #+TAGS: { Lev_3 : Lev_4 }\n
  6389. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6390. (org-match-sparse-tree nil "Lev_1")
  6391. (search-forward "H4")
  6392. (org-invisible-p2)))
  6393. (should-not
  6394. (org-test-with-temp-text
  6395. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6396. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6397. #+TAGS: { Lev_3 : Lev_4 }\n
  6398. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6399. (org-match-sparse-tree nil "Lev_1+Lev_3")
  6400. (search-forward "H4")
  6401. (org-invisible-p2)))
  6402. ;; Match regular expressions in tags
  6403. (should-not
  6404. (org-test-with-temp-text
  6405. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
  6406. (org-match-sparse-tree nil "Lev")
  6407. (search-forward "H1")
  6408. (org-invisible-p2)))
  6409. (should
  6410. (org-test-with-temp-text
  6411. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
  6412. (org-match-sparse-tree nil "Lev")
  6413. (search-forward "H1")
  6414. (org-invisible-p2)))
  6415. ;; Match properties.
  6416. (should
  6417. (org-test-with-temp-text
  6418. "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
  6419. (org-match-sparse-tree nil "A=\"1\"")
  6420. (search-forward "H2")
  6421. (org-invisible-p2)))
  6422. (should-not
  6423. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6424. (org-match-sparse-tree nil "A=\"1\"")
  6425. (search-forward "H2")
  6426. (org-invisible-p2)))
  6427. ;; Case is not significant when matching properties.
  6428. (should-not
  6429. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6430. (org-match-sparse-tree nil "a=\"1\"")
  6431. (search-forward "H2")
  6432. (org-invisible-p2)))
  6433. (should-not
  6434. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
  6435. (org-match-sparse-tree nil "A=\"1\"")
  6436. (search-forward "H2")
  6437. (org-invisible-p2)))
  6438. ;; Match special LEVEL property.
  6439. (should-not
  6440. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6441. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6442. (search-forward "H1")
  6443. (org-invisible-p2)))
  6444. (should
  6445. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6446. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6447. (search-forward "H2")
  6448. (org-invisible-p2)))
  6449. ;; Comparison operators when matching properties.
  6450. (should
  6451. (org-test-with-temp-text
  6452. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6453. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6454. (search-forward "H1")
  6455. (org-invisible-p2)))
  6456. (should-not
  6457. (org-test-with-temp-text
  6458. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6459. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6460. (search-forward "H2")
  6461. (org-invisible-p2)))
  6462. ;; Regexp match on properties values.
  6463. (should-not
  6464. (org-test-with-temp-text
  6465. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6466. (org-match-sparse-tree nil "A={f.*}")
  6467. (search-forward "H1")
  6468. (org-invisible-p2)))
  6469. (should
  6470. (org-test-with-temp-text
  6471. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6472. (org-match-sparse-tree nil "A={f.*}")
  6473. (search-forward "H2")
  6474. (org-invisible-p2)))
  6475. ;; With an optional argument, limit match to TODO entries.
  6476. (should-not
  6477. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6478. (org-match-sparse-tree t "tag")
  6479. (search-forward "H1")
  6480. (org-invisible-p2)))
  6481. (should
  6482. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6483. (org-match-sparse-tree t "tag")
  6484. (search-forward "H2")
  6485. (org-invisible-p2))))
  6486. (ert-deftest test-org/occur ()
  6487. "Test `org-occur' specifications."
  6488. ;; Count number of matches.
  6489. (should
  6490. (= 1
  6491. (org-test-with-temp-text "* H\nA\n* H2"
  6492. (org-occur "A"))))
  6493. (should
  6494. (= 2
  6495. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6496. (org-occur "A"))))
  6497. ;; Test CALLBACK optional argument.
  6498. (should
  6499. (= 0
  6500. (org-test-with-temp-text "* H\nA\n* H2"
  6501. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6502. (should
  6503. (= 1
  6504. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6505. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6506. ;; Case-fold searches according to `org-occur-case-fold-search'.
  6507. (should
  6508. (= 2
  6509. (org-test-with-temp-text "Aa"
  6510. (let ((org-occur-case-fold-search t)) (org-occur "A")))))
  6511. (should
  6512. (= 2
  6513. (org-test-with-temp-text "Aa"
  6514. (let ((org-occur-case-fold-search t)) (org-occur "a")))))
  6515. (should
  6516. (= 1
  6517. (org-test-with-temp-text "Aa"
  6518. (let ((org-occur-case-fold-search nil)) (org-occur "A")))))
  6519. (should
  6520. (= 1
  6521. (org-test-with-temp-text "Aa"
  6522. (let ((org-occur-case-fold-search nil)) (org-occur "a")))))
  6523. (should
  6524. (= 1
  6525. (org-test-with-temp-text "Aa"
  6526. (let ((org-occur-case-fold-search 'smart)) (org-occur "A")))))
  6527. (should
  6528. (= 2
  6529. (org-test-with-temp-text "Aa"
  6530. (let ((org-occur-case-fold-search 'smart)) (org-occur "a"))))))
  6531. ;;; Tags
  6532. (ert-deftest test-org/tag-string-to-alist ()
  6533. "Test `org-tag-string-to-alist' specifications."
  6534. ;; Tag without selection key.
  6535. (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
  6536. ;; Tag with selection key.
  6537. (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t))))
  6538. ;; Tag group.
  6539. (should
  6540. (equal
  6541. (org-tag-string-to-alist "[ group : t1 t2 ]")
  6542. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag))))
  6543. ;; Mutually exclusive tags.
  6544. (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
  6545. '((:startgroup) ("tag1") ("tag2") (:endgroup))))
  6546. (should
  6547. (equal
  6548. (org-tag-string-to-alist "{ group : tag1 tag2 }")
  6549. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))))
  6550. (ert-deftest test-org/tag-alist-to-string ()
  6551. "Test `org-tag-alist-to-string' specifications."
  6552. (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
  6553. (should (equal (org-tag-alist-to-string '(("tag1" . ?t))) "tag1(t)"))
  6554. (should
  6555. (equal
  6556. (org-tag-alist-to-string
  6557. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6558. "[ group : t1 t2 ]"))
  6559. (should
  6560. (equal (org-tag-alist-to-string
  6561. '((:startgroup) ("tag1") ("tag2") (:endgroup)))
  6562. "{ tag1 tag2 }"))
  6563. (should
  6564. (equal
  6565. (org-tag-alist-to-string
  6566. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))
  6567. "{ group : tag1 tag2 }")))
  6568. (ert-deftest test-org/tag-alist-to-groups ()
  6569. "Test `org-tag-alist-to-groups' specifications."
  6570. (should
  6571. (equal (org-tag-alist-to-groups
  6572. '((:startgroup) ("group") (:grouptags) ("t1") ("t2") (:endgroup)))
  6573. '(("group" "t1" "t2"))))
  6574. (should
  6575. (equal
  6576. (org-tag-alist-to-groups
  6577. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6578. '(("group" "t1" "t2"))))
  6579. (should-not
  6580. (org-tag-alist-to-groups
  6581. '((:startgroup) ("group") ("t1") ("t2") (:endgroup)))))
  6582. (ert-deftest test-org/tag-align ()
  6583. "Test tags alignment."
  6584. ;; Test aligning tags with different display width.
  6585. (should
  6586. ;; 12345678901234567890
  6587. (equal "* Test :abc:"
  6588. (org-test-with-temp-text "* Test :abc:"
  6589. (let ((org-tags-column -20)
  6590. (indent-tabs-mode nil))
  6591. (org-fix-tags-on-the-fly))
  6592. (buffer-string))))
  6593. (should
  6594. ;; 12345678901234567890
  6595. (equal "* Test :日本語:"
  6596. (org-test-with-temp-text "* Test :日本語:"
  6597. (let ((org-tags-column -20)
  6598. (indent-tabs-mode nil))
  6599. (org-fix-tags-on-the-fly))
  6600. (buffer-string))))
  6601. ;; Make sure aligning tags do not skip invisible text.
  6602. (should
  6603. (equal "* [[linkx]] :tag:"
  6604. (org-test-with-temp-text "* [[link<point>]] :tag:"
  6605. (let ((org-tags-column 0))
  6606. (org-fix-tags-on-the-fly)
  6607. (insert "x")
  6608. (buffer-string)))))
  6609. ;; Aligning tags preserve position.
  6610. (should
  6611. (= 6 (org-test-with-temp-text "* 345 <point> :tag:"
  6612. (let ((org-tags-column 78)
  6613. (indent-tabs-mode nil))
  6614. (org-fix-tags-on-the-fly))
  6615. (current-column))))
  6616. ;; Aligning all tags in visible buffer.
  6617. (should
  6618. ;; 12345678901234567890
  6619. (equal (concat "* Level 1 :abc:\n"
  6620. "** Level 2 :def:")
  6621. (org-test-with-temp-text (concat "* Level 1 :abc:\n"
  6622. "** Level 2 :def:")
  6623. (let ((org-tags-column -20)
  6624. (indent-tabs-mode nil))
  6625. ;; (org-align-tags :all) must work even when the point
  6626. ;; is at the end of the buffer.
  6627. (goto-char (point-max))
  6628. (org-align-tags :all))
  6629. (buffer-string)))))
  6630. (ert-deftest test-org/get-tags ()
  6631. "Test `org-get-tags' specifications."
  6632. ;; Standard test.
  6633. (should
  6634. (equal '("foo")
  6635. (org-test-with-temp-text "* Test :foo:" (org-get-tags))))
  6636. (should
  6637. (equal '("foo" "bar")
  6638. (org-test-with-temp-text "* Test :foo:bar:" (org-get-tags))))
  6639. ;; Tags for inlinetasks.
  6640. (should
  6641. (equal '("foo" "bar")
  6642. (progn
  6643. (require 'org-inlinetask)
  6644. (org-test-with-temp-text (concat (make-string org-inlinetask-min-level ?*) " Test :foo:bar:")
  6645. (org-get-tags (org-element-at-point))))))
  6646. (should
  6647. (equal '("foo" "bar")
  6648. (progn
  6649. (require 'org-inlinetask)
  6650. (org-test-with-temp-text (concat (make-string org-inlinetask-min-level ?*) " Test :foo:bar:")
  6651. (org-get-tags nil)))))
  6652. ;; Return nil when there is no tag.
  6653. (should-not
  6654. (org-test-with-temp-text "* Test" (org-get-tags)))
  6655. ;; Tags are inherited from parent headlines.
  6656. (should
  6657. (equal '("tag")
  6658. (let ((org-use-tag-inheritance t))
  6659. (org-test-with-temp-text "* H0 :foo:\n* H1 :tag:\n<point>** H2"
  6660. (org-get-tags)))))
  6661. ;; Tags are inherited from `org-file-tags'.
  6662. (should
  6663. (equal '("tag")
  6664. (org-test-with-temp-text "* H1"
  6665. (let ((org-file-tags '("tag"))
  6666. (org-use-tag-inheritance t))
  6667. (org-get-tags)))))
  6668. ;; Only inherited tags have the `inherited' text property.
  6669. (should
  6670. (get-text-property 0 'inherited
  6671. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6672. (let ((org-use-tag-inheritance t))
  6673. (assoc-string "foo" (org-get-tags))))))
  6674. (should-not
  6675. (get-text-property 0 'inherited
  6676. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6677. (let ((org-use-tag-inheritance t))
  6678. (assoc-string "bar" (org-get-tags))))))
  6679. ;; Obey to `org-use-tag-inheritance'.
  6680. (should-not
  6681. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6682. (let ((org-use-tag-inheritance nil))
  6683. (assoc-string "foo" (org-get-tags)))))
  6684. (should-not
  6685. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6686. (let ((org-use-tag-inheritance nil)
  6687. (org-file-tags '("foo")))
  6688. (assoc-string "foo" (org-get-tags)))))
  6689. (should-not
  6690. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6691. (let ((org-use-tag-inheritance '("bar")))
  6692. (assoc-string "foo" (org-get-tags)))))
  6693. (should
  6694. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6695. (let ((org-use-tag-inheritance '("bar")))
  6696. (assoc-string "bar" (org-get-tags)))))
  6697. (should-not
  6698. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6699. (let ((org-use-tag-inheritance "b.*"))
  6700. (assoc-string "foo" (org-get-tags)))))
  6701. (should
  6702. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6703. (let ((org-use-tag-inheritance "b.*"))
  6704. (assoc-string "bar" (org-get-tags)))))
  6705. ;; When optional argument LOCAL is non-nil, ignore tag inheritance.
  6706. (should
  6707. (equal '("baz")
  6708. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6709. (let ((org-use-tag-inheritance t))
  6710. (org-get-tags nil t)))))
  6711. ;; When optional argument POS is non-nil, get tags there instead.
  6712. (should
  6713. (equal '("foo")
  6714. (org-test-with-temp-text "* H1 :foo:\n* <point>H2 :bar:"
  6715. (org-get-tags 1))))
  6716. ;; Make sure tags excluded from inheritance are returned if local
  6717. (should
  6718. (equal '("foo")
  6719. (org-test-with-temp-text "* Test :foo:"
  6720. (let ((org-use-tag-inheritance t)
  6721. (org-tags-exclude-from-inheritance '("foo")))
  6722. (org-get-tags)))))
  6723. ;; Test the collection of tags from #+filetags and parent tags.
  6724. (should
  6725. (equal '("a" "b" "c" "d")
  6726. (org-test-with-temp-text (concat "#+filetags: a\n"
  6727. "* Level 1 :b:\n"
  6728. "** Level 2 :c:\n"
  6729. "*** Level 3 :d:\n"
  6730. "<point>")
  6731. (let ((org-use-tag-inheritance t))
  6732. (org-mode-restart) ;So that `org-file-tags' get populated from #+filetags
  6733. (org-get-tags)))))
  6734. ;; Pathological case: tagged headline with an empty body.
  6735. (should (org-test-with-temp-text "* :tag:" (org-get-tags))))
  6736. (ert-deftest test-org/set-tags ()
  6737. "Test `org-set-tags' specifications."
  6738. ;; Throw an error on invalid data.
  6739. (should-error
  6740. (org-test-with-temp-text "* H"
  6741. (org-set-tags 'foo)))
  6742. ;; `nil', an empty, and a blank string remove all tags.
  6743. (should
  6744. (equal "* H"
  6745. (org-test-with-temp-text "* H :tag1:tag2:"
  6746. (org-set-tags nil)
  6747. (buffer-string))))
  6748. (should
  6749. (equal "* H"
  6750. (org-test-with-temp-text "* H :tag1:tag2:"
  6751. (org-set-tags "")
  6752. (buffer-string))))
  6753. (should
  6754. (equal "* H"
  6755. (org-test-with-temp-text "* H :tag1:tag2:"
  6756. (org-set-tags " ")
  6757. (buffer-string))))
  6758. ;; If there's nothing to remove, just bail out.
  6759. (should
  6760. (equal "* H"
  6761. (org-test-with-temp-text "* H"
  6762. (org-set-tags nil)
  6763. (buffer-string))))
  6764. (should
  6765. (equal "* "
  6766. (org-test-with-temp-text "* "
  6767. (org-set-tags nil)
  6768. (buffer-string))))
  6769. ;; If DATA is a tag string, set current tags to it, even if it means
  6770. ;; replacing old tags.
  6771. (should
  6772. (equal "* H :tag0:"
  6773. (org-test-with-temp-text "* H :tag1:tag2:"
  6774. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  6775. (buffer-string))))
  6776. (should
  6777. (equal "* H :tag0:"
  6778. (org-test-with-temp-text "* H"
  6779. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  6780. (buffer-string))))
  6781. ;; If DATA is a list, set tags to this list, even if it means
  6782. ;; replacing old tags.
  6783. (should
  6784. (equal "* H :tag0:"
  6785. (org-test-with-temp-text "* H :tag1:tag2:"
  6786. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6787. (buffer-string))))
  6788. (should
  6789. (equal "* H :tag0:"
  6790. (org-test-with-temp-text "* H"
  6791. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6792. (buffer-string))))
  6793. ;; When set, apply `org-tags-sort-function'.
  6794. (should
  6795. (equal "* H :a:b:"
  6796. (org-test-with-temp-text "* H"
  6797. (let ((org-tags-column 1)
  6798. (org-tags-sort-function #'string<))
  6799. (org-set-tags '("b" "a"))
  6800. (buffer-string)))))
  6801. ;; When new tags are identical to the previous ones, still align.
  6802. (should
  6803. (equal "* H :foo:"
  6804. (org-test-with-temp-text "* H :foo:"
  6805. (let ((org-tags-column 1))
  6806. (org-set-tags '("foo"))
  6807. (buffer-string)))))
  6808. ;; When tags have been changed, run `org-after-tags-change-hook'.
  6809. (should
  6810. (catch :return
  6811. (org-test-with-temp-text "* H :foo:"
  6812. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  6813. (org-set-tags '("bar"))
  6814. nil))))
  6815. (should-not
  6816. (catch :return
  6817. (org-test-with-temp-text "* H :foo:"
  6818. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  6819. (org-set-tags '("foo"))
  6820. nil))))
  6821. ;; Special case: handle empty headlines.
  6822. (should
  6823. (equal "* :tag0:"
  6824. (org-test-with-temp-text "* "
  6825. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6826. (buffer-string))))
  6827. ;; Modify buffer only when a tag change happens or alignment is
  6828. ;; done.
  6829. (should-not
  6830. (org-test-with-temp-text "* H :foo:"
  6831. (set-buffer-modified-p nil)
  6832. (let ((org-tags-column 1)) (org-set-tags '("foo")))
  6833. (buffer-modified-p)))
  6834. (should
  6835. (org-test-with-temp-text "* H :foo:"
  6836. (set-buffer-modified-p nil)
  6837. (let ((org-tags-column 10)) (org-set-tags '("foo")))
  6838. (buffer-modified-p)))
  6839. (should
  6840. (org-test-with-temp-text "* H :foo:"
  6841. (set-buffer-modified-p nil)
  6842. (let ((org-tags-column 10)) (org-set-tags '("bar")))
  6843. (buffer-modified-p)))
  6844. ;; Pathological case: when setting tags of a folded headline, do not
  6845. ;; let new tags being sucked into invisibility.
  6846. (should-not
  6847. (org-test-with-temp-text "* H1\nContent\n* H2\n\n Other Content"
  6848. ;; Show only headlines
  6849. (org-content)
  6850. ;; Set NEXT tag on current entry
  6851. (org-set-tags ":NEXT:")
  6852. ;; Move point to that NEXT tag
  6853. (search-forward "NEXT") (backward-word)
  6854. ;; And it should be visible (i.e. no overlays)
  6855. (overlays-at (point)))))
  6856. (ert-deftest test-org/set-tags-command ()
  6857. "Test `org-set-tags-command' specifications"
  6858. ;; Set tags at current headline.
  6859. (should
  6860. (equal "* H1 :foo:"
  6861. (org-test-with-temp-text "* H1"
  6862. (cl-letf (((symbol-function 'completing-read-multiple)
  6863. (lambda (&rest args) '("foo"))))
  6864. (let ((org-use-fast-tag-selection nil)
  6865. (org-tags-column 1))
  6866. (org-set-tags-command)))
  6867. (buffer-string))))
  6868. ;; Preserve position when called from the section below.
  6869. (should
  6870. (equal "* H1 :foo:\nContents"
  6871. (org-test-with-temp-text "* H1\n<point>Contents"
  6872. (cl-letf (((symbol-function 'completing-read-multiple)
  6873. (lambda (&rest args) '("foo"))))
  6874. (let ((org-use-fast-tag-selection nil)
  6875. (org-tags-column 1))
  6876. (org-set-tags-command)))
  6877. (buffer-string))))
  6878. (should-not
  6879. (equal "* H1 :foo:\nContents2"
  6880. (org-test-with-temp-text "* H1\n<point>Contents2"
  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. (org-at-heading-p))))
  6887. ;; When a region is active and
  6888. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  6889. ;; same value in all headlines in region.
  6890. (should
  6891. (equal "* H1 :foo:\nContents\n* H2 :foo:"
  6892. (org-test-with-temp-text "* H1\nContents\n* H2"
  6893. (cl-letf (((symbol-function 'completing-read-multiple)
  6894. (lambda (&rest args) '("foo"))))
  6895. (let ((org-use-fast-tag-selection nil)
  6896. (org-loop-over-headlines-in-active-region t)
  6897. (org-tags-column 1))
  6898. (transient-mark-mode 1)
  6899. (push-mark (point) t t)
  6900. (goto-char (point-max))
  6901. (org-set-tags-command)))
  6902. (buffer-string))))
  6903. (should
  6904. (equal "* H1\nContents\n* H2 :foo:"
  6905. (org-test-with-temp-text "* H1\nContents\n* H2"
  6906. (cl-letf (((symbol-function 'completing-read-multiple)
  6907. (lambda (&rest args) '("foo"))))
  6908. (let ((org-use-fast-tag-selection nil)
  6909. (org-loop-over-headlines-in-active-region nil)
  6910. (org-tags-column 1))
  6911. (transient-mark-mode 1)
  6912. (push-mark (point) t t)
  6913. (goto-char (point-max))
  6914. (org-set-tags-command)))
  6915. (buffer-string))))
  6916. ;; With a C-u prefix argument, align all tags in the buffer.
  6917. (should
  6918. (equal "* H1 :foo:\n* H2 :bar:"
  6919. (org-test-with-temp-text "* H1 :foo:\n* H2 :bar:"
  6920. (let ((org-tags-column 1)) (org-set-tags-command '(4)))
  6921. (buffer-string))))
  6922. ;; Point does not move with empty headline.
  6923. (should
  6924. (equal ":foo:"
  6925. (org-test-with-temp-text "* <point>"
  6926. (cl-letf (((symbol-function 'completing-read-multiple)
  6927. (lambda (&rest args) '("foo"))))
  6928. (let ((org-use-fast-tag-selection nil)
  6929. (org-tags-column 1))
  6930. (org-set-tags-command)))
  6931. (buffer-substring (point) (line-end-position)))))
  6932. ;; Point does not move at start of line.
  6933. (should
  6934. (equal "* H1 :foo:"
  6935. (org-test-with-temp-text "* H1"
  6936. (cl-letf (((symbol-function 'completing-read-multiple)
  6937. (lambda (&rest args) '("foo"))))
  6938. (let ((org-use-fast-tag-selection nil)
  6939. (org-tags-column 1))
  6940. (org-set-tags-command)))
  6941. (buffer-substring (point) (line-end-position)))))
  6942. ;; Point does not move when within *'s.
  6943. (should
  6944. (equal "* H1 :foo:"
  6945. (org-test-with-temp-text "*<point>* H1"
  6946. (cl-letf (((symbol-function 'completing-read-multiple)
  6947. (lambda (&rest args) '("foo"))))
  6948. (let ((org-use-fast-tag-selection nil)
  6949. (org-tags-column 1))
  6950. (org-set-tags-command)))
  6951. (buffer-substring (point) (line-end-position)))))
  6952. ;; Point workaround does not get fooled when looking at a space.
  6953. (should
  6954. (equal " b :foo:"
  6955. (org-test-with-temp-text "* a<point> b"
  6956. (cl-letf (((symbol-function 'completing-read-multiple)
  6957. (lambda (&rest args) '("foo"))))
  6958. (let ((org-use-fast-tag-selection nil)
  6959. (org-tags-column 1))
  6960. (org-set-tags-command)))
  6961. (buffer-substring (point) (line-end-position)))))
  6962. ;; Handle tags both set locally and inherited.
  6963. (should
  6964. (equal "b :foo:"
  6965. (org-test-with-temp-text "* a :foo:\n** <point>b :foo:"
  6966. (cl-letf (((symbol-function 'completing-read-multiple)
  6967. (lambda (prompt coll &optional pred req initial &rest args)
  6968. (list initial))))
  6969. (let ((org-use-fast-tag-selection nil)
  6970. (org-tags-column 1))
  6971. (org-set-tags-command)))
  6972. (buffer-substring (point) (line-end-position))))))
  6973. (ert-deftest test-org/toggle-tag ()
  6974. "Test `org-toggle-tag' specifications."
  6975. ;; Insert missing tag.
  6976. (should
  6977. (equal "* H :tag:"
  6978. (org-test-with-temp-text "* H"
  6979. (let ((org-tags-column 1)) (org-toggle-tag "tag"))
  6980. (buffer-string))))
  6981. (should
  6982. (equal "* H :tag1:tag2:"
  6983. (org-test-with-temp-text "* H :tag1:"
  6984. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  6985. (buffer-string))))
  6986. ;; Remove existing tag.
  6987. (should
  6988. (equal "* H"
  6989. (org-test-with-temp-text "* H :tag:"
  6990. (org-toggle-tag "tag")
  6991. (buffer-string))))
  6992. (should
  6993. (equal "* H :tag1:"
  6994. (org-test-with-temp-text "* H :tag1:tag2:"
  6995. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  6996. (buffer-string))))
  6997. (should
  6998. (equal "* H :tag2:"
  6999. (org-test-with-temp-text "* H :tag1:tag2:"
  7000. (let ((org-tags-column 1)) (org-toggle-tag "tag1"))
  7001. (buffer-string))))
  7002. ;; With optional argument ONOFF set to `on', try to insert the tag,
  7003. ;; even if its already there.
  7004. (should
  7005. (equal "* H :tag:"
  7006. (org-test-with-temp-text "* H"
  7007. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  7008. (buffer-string))))
  7009. (should
  7010. (equal "* H :tag:"
  7011. (org-test-with-temp-text "* H :tag:"
  7012. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  7013. (buffer-string))))
  7014. ;; With optional argument ONOFF set to `off', try to remove the tag,
  7015. ;; even if its not there.
  7016. (should
  7017. (equal "* H"
  7018. (org-test-with-temp-text "* H :tag:"
  7019. (org-toggle-tag "tag" 'off)
  7020. (buffer-string))))
  7021. (should
  7022. (equal "* H :tag:"
  7023. (org-test-with-temp-text "* H :tag:"
  7024. (let ((org-tags-column 1)) (org-toggle-tag "foo" 'off))
  7025. (buffer-string))))
  7026. ;; Special case: Handle properly tag inheritance. In particular, do
  7027. ;; not set inherited tags.
  7028. (should
  7029. (equal "* H1 :tag:\n** H2 :tag2:tag:"
  7030. (org-test-with-temp-text "* H1 :tag:\n** <point>H2 :tag2:"
  7031. (let ((org-use-tag-inheritance t)
  7032. (org-tags-column 1))
  7033. (org-toggle-tag "tag"))
  7034. (buffer-string))))
  7035. (should
  7036. (equal "* H1 :tag1:tag2:\n** H2 :foo:"
  7037. (org-test-with-temp-text "* H1 :tag1:tag2:\n** <point>H2"
  7038. (let ((org-use-tag-inheritance t)
  7039. (org-tags-column 1))
  7040. (org-toggle-tag "foo"))
  7041. (buffer-string)))))
  7042. (ert-deftest test-org/tags-expand ()
  7043. "Test `org-tags-expand' specifications."
  7044. ;; Expand tag groups as a regexp enclosed within curly brackets.
  7045. (should
  7046. (equal "{\\<[ABC]\\>}"
  7047. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7048. (org-mode-restart)
  7049. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  7050. (should
  7051. (equal "{\\<\\(?:Aa\\|Bb\\|Cc\\)\\>}"
  7052. (org-test-with-temp-text "#+TAGS: [ Aa : Bb Cc ]"
  7053. (org-mode-restart)
  7054. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "Aa")))))
  7055. ;; Preserve operator before the regexp.
  7056. (should
  7057. (equal "+{\\<[ABC]\\>}"
  7058. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7059. (org-mode-restart)
  7060. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "+A")))))
  7061. (should
  7062. (equal "-{\\<[ABC]\\>}"
  7063. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7064. (org-mode-restart)
  7065. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "-A")))))
  7066. ;; Handle "|" syntax.
  7067. (should
  7068. (equal "{\\<[ABC]\\>}|D"
  7069. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7070. (org-mode-restart)
  7071. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|D")))))
  7072. ;; Handle nested groups.
  7073. (should
  7074. (equal "{\\<[A-D]\\>}"
  7075. (org-test-with-temp-text "#+TAGS: [ A : B C ]\n#+TAGS: [ B : D ]"
  7076. (org-mode-restart)
  7077. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  7078. ;; Expand multiple occurrences of the same group.
  7079. (should
  7080. (equal "{\\<[ABC]\\>}|{\\<[ABC]\\>}"
  7081. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7082. (org-mode-restart)
  7083. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|A")))))
  7084. ;; Preserve regexp matches.
  7085. (should
  7086. (equal "{A+}"
  7087. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7088. (org-mode-restart)
  7089. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "{A+}"))))))
  7090. ;;; TODO keywords
  7091. (ert-deftest test-org/auto-repeat-maybe ()
  7092. "Test `org-auto-repeat-maybe' specifications."
  7093. ;; Do not auto repeat when there is no valid time stamp with
  7094. ;; a repeater in the entry.
  7095. (should-not
  7096. (string-prefix-p
  7097. "* TODO H"
  7098. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7099. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
  7100. (org-todo "DONE")
  7101. (buffer-string)))))
  7102. (should-not
  7103. (string-prefix-p
  7104. "* TODO H"
  7105. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7106. (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
  7107. (org-todo "DONE")
  7108. (buffer-string)))))
  7109. ;; When switching to DONE state, switch back to first TODO keyword
  7110. ;; in sequence, or the same keyword if they have different types.
  7111. (should
  7112. (string-prefix-p
  7113. "* TODO H"
  7114. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7115. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7116. (org-todo "DONE")
  7117. (buffer-string)))))
  7118. (should
  7119. (string-prefix-p
  7120. "* KWD1 H"
  7121. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  7122. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  7123. (org-todo "DONE")
  7124. (buffer-string)))))
  7125. (should
  7126. (string-prefix-p
  7127. "* KWD2 H"
  7128. (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
  7129. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  7130. (org-todo "DONE")
  7131. (buffer-string)))))
  7132. ;; If there was no TODO keyword in the first place, do not insert
  7133. ;; any either.
  7134. (should
  7135. (string-prefix-p
  7136. "* H"
  7137. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7138. (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
  7139. (org-todo "DONE")
  7140. (buffer-string)))))
  7141. ;; Revert to REPEAT_TO_STATE, if set.
  7142. (should
  7143. (string-prefix-p
  7144. "* KWD2 H"
  7145. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  7146. (org-test-with-temp-text
  7147. "* KWD2 H
  7148. :PROPERTIES:
  7149. :REPEAT_TO_STATE: KWD2
  7150. :END:
  7151. <2012-03-29 Thu +2y>"
  7152. (org-todo "DONE")
  7153. (buffer-string)))))
  7154. ;; When switching to DONE state, update base date. If there are
  7155. ;; multiple repeated time stamps, update them all.
  7156. (should
  7157. (string-match-p
  7158. "<2014-03-29 .* \\+2y>"
  7159. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7160. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7161. (org-todo "DONE")
  7162. (buffer-string)))))
  7163. (should
  7164. (string-match-p
  7165. "<2015-03-04 .* \\+1y>"
  7166. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7167. (org-test-with-temp-text
  7168. "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
  7169. (org-todo "DONE")
  7170. (buffer-string)))))
  7171. ;; Throw an error if repeater unit is the hour and no time is
  7172. ;; provided in the time-stamp.
  7173. (should-error
  7174. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7175. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
  7176. (org-todo "DONE")
  7177. (buffer-string))))
  7178. ;; Handle every repeater type using hours step.
  7179. (should
  7180. (string-match-p
  7181. "2014-03-04 .* 02:00"
  7182. (org-test-at-time "<2014-03-04 02:35>"
  7183. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 +8h>"
  7184. (org-todo "DONE")
  7185. (buffer-string)))))
  7186. (should
  7187. (string-match-p
  7188. "2014-03-04 .* 10:00"
  7189. (org-test-at-time "<2014-03-04 02:35>"
  7190. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 ++8h>"
  7191. (org-todo "DONE")
  7192. (buffer-string)))))
  7193. (should
  7194. (string-match-p
  7195. "2014-03-04 .* 10:35"
  7196. (org-test-at-time "<2014-03-04 02:35>"
  7197. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 .+8h>"
  7198. (org-todo "DONE")
  7199. (buffer-string)))))
  7200. ;; Do not repeat inactive time stamps with a repeater.
  7201. (should-not
  7202. (string-match-p
  7203. "\\[2014-03-29 .* \\+2y\\]"
  7204. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7205. (org-test-with-temp-text
  7206. "* TODO H\n[2012-03-29 Thu. +2y]"
  7207. (org-todo "DONE")
  7208. (buffer-string)))))
  7209. ;; Do not repeat commented time stamps.
  7210. (should-not
  7211. (string-prefix-p
  7212. "<2015-03-04 .* \\+1y>"
  7213. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7214. (org-test-with-temp-text
  7215. "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
  7216. (org-todo "DONE")
  7217. (buffer-string)))))
  7218. (should-not
  7219. (string-prefix-p
  7220. "<2015-03-04 .* \\+1y>"
  7221. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7222. (org-test-with-temp-text
  7223. "* TODO H
  7224. <2012-03-29 Thu. +2y>
  7225. #+BEGIN_EXAMPLE
  7226. <2014-03-04 Tue +1y>
  7227. #+END_EXAMPLE"
  7228. (org-todo "DONE")
  7229. (buffer-string)))))
  7230. ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
  7231. ;; entry, record time of last repeat.
  7232. (should-not
  7233. (string-match-p
  7234. ":LAST_REPEAT:"
  7235. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  7236. (org-log-repeat nil))
  7237. (cl-letf (((symbol-function 'org-add-log-setup)
  7238. (lambda (&rest args) nil)))
  7239. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  7240. (org-todo "DONE")
  7241. (buffer-string))))))
  7242. (should
  7243. (string-match-p
  7244. ":LAST_REPEAT:"
  7245. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  7246. (org-log-repeat t))
  7247. (cl-letf (((symbol-function 'org-add-log-setup)
  7248. (lambda (&rest args) nil)))
  7249. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  7250. (org-todo "DONE")
  7251. (buffer-string))))))
  7252. (should
  7253. (string-match-p
  7254. ":LAST_REPEAT:"
  7255. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7256. (cl-letf (((symbol-function 'org-add-log-setup)
  7257. (lambda (&rest args) nil)))
  7258. (org-test-with-temp-text
  7259. "* TODO H\n<2012-03-29 Thu +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
  7260. (org-todo "DONE")
  7261. (buffer-string))))))
  7262. ;; When a SCHEDULED entry has no repeater, remove it upon repeating
  7263. ;; the entry as it is no longer relevant.
  7264. (should-not
  7265. (string-match-p
  7266. "^SCHEDULED:"
  7267. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7268. (org-test-with-temp-text
  7269. "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
  7270. (org-todo "DONE")
  7271. (buffer-string)))))
  7272. ;; Properly advance repeater even when a clock entry is specified
  7273. ;; and `org-log-repeat' is nil.
  7274. (should
  7275. (string-match-p
  7276. "SCHEDULED: <2014-03-29"
  7277. (let ((org-log-repeat nil)
  7278. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7279. (org-test-with-temp-text
  7280. "* TODO H
  7281. SCHEDULED: <2012-03-29 Thu +2y>
  7282. CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] => 6:40"
  7283. (org-todo "DONE")
  7284. (buffer-string)))))
  7285. ;; Make sure that logbook state change record does not get
  7286. ;; duplicated when `org-log-repeat' `org-log-done' are non-nil.
  7287. (should
  7288. (string-match-p
  7289. (rx "* TODO Read book
  7290. SCHEDULED: <2021-06-16 " (1+ (not space)) " +1d>
  7291. :PROPERTIES:
  7292. :LAST_REPEAT:" (1+ nonl) "
  7293. :END:
  7294. - State \"DONE\" from \"TODO\"" (1+ nonl) buffer-end)
  7295. (let ((org-log-repeat 'time)
  7296. (org-todo-keywords '((sequence "TODO" "|" "DONE(d!)")))
  7297. (org-log-into-drawer nil))
  7298. (org-test-with-temp-text
  7299. "* TODO Read book
  7300. SCHEDULED: <2021-06-15 Tue +1d>"
  7301. (org-todo "DONE")
  7302. (when (memq 'org-add-log-note post-command-hook)
  7303. (org-add-log-note))
  7304. (buffer-string))))))
  7305. (ert-deftest test-org/org-log-done ()
  7306. "Test `org-log-done' specifications."
  7307. ;; nil value.
  7308. (should
  7309. (string=
  7310. "* DONE task"
  7311. (let ((org-log-done nil)
  7312. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7313. (org-test-with-temp-text
  7314. "* TODO task"
  7315. (org-todo "DONE")
  7316. (when (memq 'org-add-log-note post-command-hook)
  7317. (org-add-log-note))
  7318. (buffer-string)))))
  7319. ;; `time' value.
  7320. (should
  7321. (string=
  7322. (format
  7323. "* DONE task
  7324. CLOSED: %s"
  7325. (org-test-with-temp-text ""
  7326. (org-insert-time-stamp (current-time) t t)
  7327. (buffer-string)))
  7328. (let ((org-log-done 'time)
  7329. (org-log-done-with-time t)
  7330. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7331. (org-test-with-temp-text
  7332. "* TODO task"
  7333. (org-todo "DONE")
  7334. (when (memq 'org-add-log-note post-command-hook)
  7335. (org-add-log-note))
  7336. (buffer-string)))))
  7337. (should
  7338. (string=
  7339. (format
  7340. "* DONE task
  7341. CLOSED: %s"
  7342. (org-test-with-temp-text ""
  7343. (org-insert-time-stamp (current-time) nil t)
  7344. (buffer-string)))
  7345. (let ((org-log-done 'time)
  7346. (org-log-done-with-time nil)
  7347. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7348. (org-test-with-temp-text
  7349. "* TODO task"
  7350. (org-todo "DONE")
  7351. (when (memq 'org-add-log-note post-command-hook)
  7352. (org-add-log-note))
  7353. (buffer-string)))))
  7354. ;; TODO: Test `note' value.
  7355. ;; Test startup overrides.
  7356. (should
  7357. (string=
  7358. "#+STARTUP: nologdone
  7359. * DONE task"
  7360. (let ((org-log-done 'time)
  7361. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7362. (org-test-with-temp-text
  7363. "#+STARTUP: nologdone
  7364. <point>* TODO task"
  7365. (org-set-regexps-and-options)
  7366. (org-todo "DONE")
  7367. (when (memq 'org-add-log-note post-command-hook)
  7368. (org-add-log-note))
  7369. (buffer-string)))))
  7370. (should
  7371. (string=
  7372. (format
  7373. "#+STARTUP: logdone
  7374. * DONE task
  7375. CLOSED: %s"
  7376. (org-test-with-temp-text ""
  7377. (org-insert-time-stamp (current-time) t t)
  7378. (buffer-string)))
  7379. (let ((org-log-done nil)
  7380. (org-log-done-with-time t)
  7381. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7382. (org-test-with-temp-text
  7383. "#+STARTUP: logdone
  7384. <point>* TODO task"
  7385. (org-set-regexps-and-options)
  7386. (org-todo "DONE")
  7387. (when (memq 'org-add-log-note post-command-hook)
  7388. (org-add-log-note))
  7389. (buffer-string)))))
  7390. ;; Test local property overrides.
  7391. (should
  7392. (string=
  7393. "* DONE task
  7394. :PROPERTIES:
  7395. :LOGGING: nil
  7396. :END:"
  7397. (let ((org-log-done 'time)
  7398. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7399. (org-test-with-temp-text
  7400. "* TODO task
  7401. :PROPERTIES:
  7402. :LOGGING: nil
  7403. :END:"
  7404. (org-todo "DONE")
  7405. (when (memq 'org-add-log-note post-command-hook)
  7406. (org-add-log-note))
  7407. (buffer-string)))))
  7408. (should
  7409. (string=
  7410. (format
  7411. "* DONE task
  7412. CLOSED: %s
  7413. :PROPERTIES:
  7414. :LOGGING: logdone
  7415. :END:"
  7416. (org-test-with-temp-text ""
  7417. (org-insert-time-stamp (current-time) t t)
  7418. (buffer-string)))
  7419. (let ((org-log-done nil)
  7420. (org-log-done-with-time t)
  7421. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7422. (org-test-with-temp-text
  7423. "* TODO task
  7424. :PROPERTIES:
  7425. :LOGGING: logdone
  7426. :END:"
  7427. (org-todo "DONE")
  7428. (when (memq 'org-add-log-note post-command-hook)
  7429. (org-add-log-note))
  7430. (buffer-string))))))
  7431. ;;; Timestamps API
  7432. (ert-deftest test-org/at-timestamp-p ()
  7433. "Test `org-at-timestamp-p' specifications."
  7434. (should
  7435. (org-test-with-temp-text "<2012-03-29 Thu>"
  7436. (org-at-timestamp-p)))
  7437. (should-not
  7438. (org-test-with-temp-text "2012-03-29 Thu"
  7439. (org-at-timestamp-p)))
  7440. ;; Test return values.
  7441. (should
  7442. (eq 'bracket
  7443. (org-test-with-temp-text "<2012-03-29 Thu>"
  7444. (org-at-timestamp-p))))
  7445. (should
  7446. (eq 'year
  7447. (org-test-with-temp-text "<<point>2012-03-29 Thu>"
  7448. (org-at-timestamp-p))))
  7449. (should
  7450. (eq 'month
  7451. (org-test-with-temp-text "<2012-<point>03-29 Thu>"
  7452. (org-at-timestamp-p))))
  7453. (should
  7454. (eq 'day
  7455. (org-test-with-temp-text "<2012-03-<point>29 Thu>"
  7456. (org-at-timestamp-p))))
  7457. (should
  7458. (eq 'day
  7459. (org-test-with-temp-text "<2012-03-29 T<point>hu>"
  7460. (org-at-timestamp-p))))
  7461. (should
  7462. (wholenump
  7463. (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
  7464. (org-at-timestamp-p))))
  7465. (should
  7466. (eq 'bracket
  7467. (org-test-with-temp-text "<2012-03-29 Thu<point>>"
  7468. (org-at-timestamp-p))))
  7469. (should
  7470. (eq 'after
  7471. (org-test-with-temp-text "<2012-03-29 Thu><point>»"
  7472. (org-at-timestamp-p))))
  7473. ;; Test `inactive' optional argument.
  7474. (should
  7475. (org-test-with-temp-text "[2012-03-29 Thu]"
  7476. (org-at-timestamp-p 'inactive)))
  7477. (should-not
  7478. (org-test-with-temp-text "[2012-03-29 Thu]"
  7479. (org-at-timestamp-p)))
  7480. ;; When optional argument is `agenda', recognize time-stamps in
  7481. ;; planning info line, property drawers and clocks.
  7482. (should
  7483. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7484. (org-at-timestamp-p 'agenda)))
  7485. (should-not
  7486. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7487. (org-at-timestamp-p)))
  7488. (should
  7489. (org-test-with-temp-text
  7490. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7491. (org-at-timestamp-p 'agenda)))
  7492. (should-not
  7493. (org-test-with-temp-text
  7494. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7495. (org-at-timestamp-p)))
  7496. (should
  7497. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7498. (let ((org-agenda-include-inactive-timestamps t))
  7499. (org-at-timestamp-p 'agenda))))
  7500. (should-not
  7501. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7502. (let ((org-agenda-include-inactive-timestamps t))
  7503. (org-at-timestamp-p))))
  7504. (should-not
  7505. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7506. (let ((org-agenda-include-inactive-timestamps t))
  7507. (org-at-timestamp-p 'inactive))))
  7508. ;; When optional argument is `lax', match any part of the document
  7509. ;; with Org timestamp syntax.
  7510. (should
  7511. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7512. (org-at-timestamp-p 'lax)))
  7513. (should-not
  7514. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7515. (org-at-timestamp-p)))
  7516. (should
  7517. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7518. (org-at-timestamp-p 'lax)))
  7519. (should-not
  7520. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7521. (org-at-timestamp-p)))
  7522. (should
  7523. (org-test-with-temp-text
  7524. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7525. (org-at-timestamp-p 'lax)))
  7526. (should-not
  7527. (org-test-with-temp-text
  7528. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7529. (org-at-timestamp-p)))
  7530. ;; Optional argument `lax' also matches inactive timestamps.
  7531. (should
  7532. (org-test-with-temp-text "# [2012-03-29 Thu]<point>"
  7533. (org-at-timestamp-p 'lax))))
  7534. (ert-deftest test-org/time-stamp ()
  7535. "Test `org-time-stamp' specifications."
  7536. ;; Insert chosen time stamp at point.
  7537. (should
  7538. (string-match
  7539. "Te<2014-03-04 .*?>xt"
  7540. (org-test-with-temp-text "Te<point>xt"
  7541. (cl-letf (((symbol-function 'org-read-date)
  7542. (lambda (&rest args)
  7543. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7544. (org-time-stamp nil)
  7545. (buffer-string)))))
  7546. ;; With a prefix argument, also insert time.
  7547. (should
  7548. (string-match
  7549. "Te<2014-03-04 .*? 00:41>xt"
  7550. (org-test-with-temp-text "Te<point>xt"
  7551. (cl-letf (((symbol-function 'org-read-date)
  7552. (lambda (&rest args)
  7553. (apply #'encode-time
  7554. (org-parse-time-string "2014-03-04 00:41")))))
  7555. (org-time-stamp '(4))
  7556. (buffer-string)))))
  7557. ;; With two universal prefix arguments, insert an active timestamp
  7558. ;; with the current time without prompting the user.
  7559. (should
  7560. (string-match
  7561. "Te<2014-03-04 .*? 00:41>xt"
  7562. (org-test-with-temp-text "Te<point>xt"
  7563. (org-test-at-time "2014-03-04 00:41"
  7564. (org-time-stamp '(16))
  7565. (buffer-string)))))
  7566. ;; When optional argument is non-nil, insert an inactive timestamp.
  7567. (should
  7568. (string-match
  7569. "Te\\[2014-03-04 .*?\\]xt"
  7570. (org-test-with-temp-text "Te<point>xt"
  7571. (cl-letf (((symbol-function 'org-read-date)
  7572. (lambda (&rest args)
  7573. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7574. (org-time-stamp nil t)
  7575. (buffer-string)))))
  7576. ;; When called from a timestamp, replace existing one.
  7577. (should
  7578. (string-match
  7579. "<2014-03-04 .*?>"
  7580. (org-test-with-temp-text "<2012-03-29<point> thu.>"
  7581. (cl-letf (((symbol-function 'org-read-date)
  7582. (lambda (&rest args)
  7583. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7584. (org-time-stamp nil)
  7585. (buffer-string)))))
  7586. (should
  7587. (string-match
  7588. "<2014-03-04 .*?>--<2014-03-04 .*?>"
  7589. (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
  7590. (cl-letf (((symbol-function 'org-read-date)
  7591. (lambda (&rest args)
  7592. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7593. (org-time-stamp nil)
  7594. (buffer-string)))))
  7595. ;; When replacing a timestamp, preserve repeater, if any.
  7596. (should
  7597. (string-match
  7598. "<2014-03-04 .*? \\+2y>"
  7599. (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
  7600. (cl-letf (((symbol-function 'org-read-date)
  7601. (lambda (&rest args)
  7602. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7603. (org-time-stamp nil)
  7604. (buffer-string)))))
  7605. ;; When called twice in a raw, build a date range.
  7606. (should
  7607. (string-match
  7608. "<2012-03-29 .*?>--<2014-03-04 .*?>"
  7609. (org-test-with-temp-text "<2012-03-29 thu.><point>"
  7610. (cl-letf (((symbol-function 'org-read-date)
  7611. (lambda (&rest args)
  7612. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7613. (let ((last-command 'org-time-stamp)
  7614. (this-command 'org-time-stamp))
  7615. (org-time-stamp nil))
  7616. (buffer-string))))))
  7617. (ert-deftest test-org/timestamp-has-time-p ()
  7618. "Test `org-timestamp-has-time-p' specifications."
  7619. ;; With time.
  7620. (should
  7621. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7622. (org-timestamp-has-time-p (org-element-context))))
  7623. ;; Without time.
  7624. (should-not
  7625. (org-test-with-temp-text "<2012-03-29 Thu>"
  7626. (org-timestamp-has-time-p (org-element-context)))))
  7627. (ert-deftest test-org/get-repeat ()
  7628. "Test `org-get-repeat' specifications."
  7629. (should
  7630. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
  7631. (org-get-repeat)))
  7632. (should-not
  7633. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
  7634. (org-get-repeat)))
  7635. ;; Return proper repeat string.
  7636. (should
  7637. (equal "+2y"
  7638. (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
  7639. (org-get-repeat))))
  7640. ;; Prevent false positive (commented or verbatim time stamps)
  7641. (should-not
  7642. (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
  7643. (org-get-repeat)))
  7644. (should-not
  7645. (org-test-with-temp-text
  7646. "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
  7647. (org-get-repeat)))
  7648. ;; Return nil when called before first heading.
  7649. (should-not
  7650. (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
  7651. (org-get-repeat)))
  7652. ;; When called with an optional argument, extract repeater from that
  7653. ;; string instead.
  7654. (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
  7655. (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
  7656. (ert-deftest test-org/timestamp-format ()
  7657. "Test `org-timestamp-format' specifications."
  7658. ;; Regular test.
  7659. (should
  7660. (equal
  7661. "2012-03-29 16:40"
  7662. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7663. (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
  7664. ;; Range end.
  7665. (should
  7666. (equal
  7667. "2012-03-29"
  7668. (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
  7669. (org-timestamp-format (org-element-context) "%Y-%m-%d" t)))))
  7670. (ert-deftest test-org/timestamp-split-range ()
  7671. "Test `org-timestamp-split-range' specifications."
  7672. ;; Extract range start (active).
  7673. (should
  7674. (equal '(2012 3 29)
  7675. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7676. (let ((ts (org-timestamp-split-range (org-element-context))))
  7677. (mapcar (lambda (p) (org-element-property p ts))
  7678. '(:year-end :month-end :day-end))))))
  7679. ;; Extract range start (inactive)
  7680. (should
  7681. (equal '(2012 3 29)
  7682. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7683. (let ((ts (org-timestamp-split-range (org-element-context))))
  7684. (mapcar (lambda (p) (org-element-property p ts))
  7685. '(:year-end :month-end :day-end))))))
  7686. ;; Extract range end (active).
  7687. (should
  7688. (equal '(2012 3 30)
  7689. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7690. (let ((ts (org-timestamp-split-range
  7691. (org-element-context) t)))
  7692. (mapcar (lambda (p) (org-element-property p ts))
  7693. '(:year-end :month-end :day-end))))))
  7694. ;; Extract range end (inactive)
  7695. (should
  7696. (equal '(2012 3 30)
  7697. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7698. (let ((ts (org-timestamp-split-range
  7699. (org-element-context) t)))
  7700. (mapcar (lambda (p) (org-element-property p ts))
  7701. '(:year-end :month-end :day-end))))))
  7702. ;; Return the timestamp if not a range.
  7703. (should
  7704. (org-test-with-temp-text "[2012-03-29 Thu]"
  7705. (let* ((ts-orig (org-element-context))
  7706. (ts-copy (org-timestamp-split-range ts-orig)))
  7707. (eq ts-orig ts-copy))))
  7708. (should
  7709. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7710. (let* ((ts-orig (org-element-context))
  7711. (ts-copy (org-timestamp-split-range ts-orig)))
  7712. (eq ts-orig ts-copy)))))
  7713. (ert-deftest test-org/timestamp-translate ()
  7714. "Test `org-timestamp-translate' specifications."
  7715. ;; Translate whole date range.
  7716. (should
  7717. (equal "<29>--<30>"
  7718. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7719. (let ((org-display-custom-times t)
  7720. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7721. (org-timestamp-translate (org-element-context))))))
  7722. ;; Translate date range start.
  7723. (should
  7724. (equal "<29>"
  7725. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7726. (let ((org-display-custom-times t)
  7727. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7728. (org-timestamp-translate (org-element-context) 'start)))))
  7729. ;; Translate date range end.
  7730. (should
  7731. (equal "<30>"
  7732. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7733. (let ((org-display-custom-times t)
  7734. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7735. (org-timestamp-translate (org-element-context) 'end)))))
  7736. ;; Translate time range.
  7737. (should
  7738. (equal "<08>--<16>"
  7739. (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
  7740. (let ((org-display-custom-times t)
  7741. (org-time-stamp-custom-formats '("<%d>" . "<%H>")))
  7742. (org-timestamp-translate (org-element-context))))))
  7743. ;; Translate non-range timestamp.
  7744. (should
  7745. (equal "<29>"
  7746. (org-test-with-temp-text "<2012-03-29 Thu>"
  7747. (let ((org-display-custom-times t)
  7748. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7749. (org-timestamp-translate (org-element-context))))))
  7750. ;; Do not change `diary' timestamps.
  7751. (should
  7752. (equal "<%%(org-float t 4 2)>"
  7753. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7754. (let ((org-display-custom-times t)
  7755. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7756. (org-timestamp-translate (org-element-context)))))))
  7757. (ert-deftest test-org/timestamp-from-string ()
  7758. "Test `org-timestamp-from-string' specifications."
  7759. ;; Return nil if argument is not a valid Org timestamp.
  7760. (should-not (org-timestamp-from-string ""))
  7761. (should-not (org-timestamp-from-string nil))
  7762. (should-not (org-timestamp-from-string "<2012-03-29"))
  7763. ;; Otherwise, return a valid Org timestamp object.
  7764. (should
  7765. (string-match-p "<2012-03-29 .+>"
  7766. (org-element-interpret-data
  7767. (org-timestamp-from-string "<2012-03-29 Thu>"))))
  7768. (should
  7769. (string-match-p "[2014-03-04 .+]"
  7770. (org-element-interpret-data
  7771. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  7772. (ert-deftest test-org/timestamp-from-time ()
  7773. "Test `org-timestamp-from-time' specifications."
  7774. ;; Standard test.
  7775. (should
  7776. (string-match-p
  7777. "<2012-03-29 .+>"
  7778. (org-element-interpret-data
  7779. (org-timestamp-from-time
  7780. (apply #'encode-time
  7781. (org-parse-time-string "<2012-03-29 Thu 16:40>"))))))
  7782. ;; When optional argument WITH-TIME is non-nil, provide time
  7783. ;; information.
  7784. (should
  7785. (string-match-p
  7786. "<2012-03-29 .+ 16:40>"
  7787. (org-element-interpret-data
  7788. (org-timestamp-from-time
  7789. (apply #'encode-time
  7790. (org-parse-time-string "<2012-03-29 Thu 16:40>"))
  7791. t))))
  7792. ;; When optional argument INACTIVE is non-nil, return an inactive
  7793. ;; timestamp.
  7794. (should
  7795. (string-match-p
  7796. "[2012-03-29 .+]"
  7797. (org-element-interpret-data
  7798. (org-timestamp-from-time
  7799. (apply #'encode-time
  7800. (org-parse-time-string "<2012-03-29 Thu 16:40>"))
  7801. nil t)))))
  7802. (ert-deftest test-org/timestamp-to-time ()
  7803. "Test `org-timestamp-to-time' specifications."
  7804. (should
  7805. (equal "2014-03-04"
  7806. (format-time-string
  7807. "%Y-%m-%d"
  7808. (org-timestamp-to-time
  7809. (org-timestamp-from-string "<2014-03-04 Tue>")))))
  7810. (should
  7811. (equal "2014-03-04"
  7812. (format-time-string
  7813. "%Y-%m-%d"
  7814. (org-timestamp-to-time
  7815. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  7816. (should
  7817. (equal "2012-03-29 08:30"
  7818. (format-time-string
  7819. "%Y-%m-%d %H:%M"
  7820. (org-timestamp-to-time
  7821. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")))))
  7822. (should
  7823. (equal "2012-03-29"
  7824. (format-time-string
  7825. "%Y-%m-%d"
  7826. (org-timestamp-to-time
  7827. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")))))
  7828. (should
  7829. (equal "2012-03-29"
  7830. (format-time-string
  7831. "%Y-%m-%d"
  7832. (org-timestamp-to-time
  7833. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")))))
  7834. ;; When optional argument END is non-nil, use end of date range or
  7835. ;; time range.
  7836. (should
  7837. (equal "2012-03-29 16:40"
  7838. (format-time-string
  7839. "%Y-%m-%d %H:%M"
  7840. (org-timestamp-to-time
  7841. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")
  7842. t))))
  7843. (should
  7844. (equal "2014-03-04"
  7845. (format-time-string
  7846. "%Y-%m-%d"
  7847. (org-timestamp-to-time
  7848. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")
  7849. t))))
  7850. (should
  7851. (equal "2014-03-04"
  7852. (format-time-string
  7853. "%Y-%m-%d"
  7854. (org-timestamp-to-time
  7855. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")
  7856. t)))))
  7857. ;;; Visibility
  7858. (ert-deftest test-org/hide-drawer-toggle ()
  7859. "Test `org-hide-drawer-toggle' specifications."
  7860. ;; Error when not at a drawer.
  7861. (should-error
  7862. (org-test-with-temp-text ":fake-drawer:\ncontents"
  7863. (org-hide-drawer-toggle 'off)
  7864. (get-char-property (line-end-position) 'invisible)))
  7865. (should-error
  7866. (org-test-with-temp-text
  7867. "#+begin_example\n<point>:D:\nc\n:END:\n#+end_example"
  7868. (org-hide-drawer-toggle t)))
  7869. ;; Hide drawer.
  7870. (should
  7871. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7872. (org-hide-drawer-toggle)
  7873. (get-char-property (line-end-position) 'invisible)))
  7874. ;; Show drawer unconditionally when optional argument is `off'.
  7875. (should-not
  7876. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7877. (org-hide-drawer-toggle)
  7878. (org-hide-drawer-toggle 'off)
  7879. (get-char-property (line-end-position) 'invisible)))
  7880. ;; Hide drawer unconditionally when optional argument is non-nil.
  7881. (should
  7882. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7883. (org-hide-drawer-toggle t)
  7884. (get-char-property (line-end-position) 'invisible)))
  7885. ;; Do not hide drawer when called from final blank lines.
  7886. (should-not
  7887. (org-test-with-temp-text ":drawer:\ncontents\n:end:\n\n<point>"
  7888. (org-hide-drawer-toggle)
  7889. (goto-char (point-min))
  7890. (get-char-property (line-end-position) 'invisible)))
  7891. ;; Don't leave point in an invisible part of the buffer when hiding
  7892. ;; a drawer away.
  7893. (should-not
  7894. (org-test-with-temp-text ":drawer:\ncontents\n<point>:end:"
  7895. (org-hide-drawer-toggle)
  7896. (get-char-property (point) 'invisible))))
  7897. (ert-deftest test-org/hide-block-toggle ()
  7898. "Test `org-hide-block-toggle' specifications."
  7899. ;; Error when not at a block.
  7900. (should-error
  7901. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
  7902. (org-hide-block-toggle 'off)
  7903. (get-char-property (line-end-position) 'invisible)))
  7904. ;; Hide block.
  7905. (should
  7906. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  7907. (org-hide-block-toggle)
  7908. (get-char-property (line-end-position) 'invisible)))
  7909. (should
  7910. (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
  7911. (org-hide-block-toggle)
  7912. (get-char-property (line-end-position) 'invisible)))
  7913. ;; Show block unconditionally when optional argument is `off'.
  7914. (should-not
  7915. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7916. (org-hide-block-toggle)
  7917. (org-hide-block-toggle 'off)
  7918. (get-char-property (line-end-position) 'invisible)))
  7919. (should-not
  7920. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7921. (org-hide-block-toggle 'off)
  7922. (get-char-property (line-end-position) 'invisible)))
  7923. ;; Hide block unconditionally when optional argument is non-nil.
  7924. (should
  7925. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7926. (org-hide-block-toggle t)
  7927. (get-char-property (line-end-position) 'invisible)))
  7928. (should
  7929. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7930. (org-hide-block-toggle)
  7931. (org-hide-block-toggle t)
  7932. (get-char-property (line-end-position) 'invisible)))
  7933. ;; Do not hide block when called from final blank lines.
  7934. (should-not
  7935. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
  7936. (org-hide-block-toggle)
  7937. (goto-char (point-min))
  7938. (get-char-property (line-end-position) 'invisible)))
  7939. ;; Don't leave point in an invisible part of the buffer when hiding
  7940. ;; a block away.
  7941. (should-not
  7942. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
  7943. (org-hide-block-toggle)
  7944. (get-char-property (point) 'invisible))))
  7945. (ert-deftest test-org/hide-block-toggle-maybe ()
  7946. "Test `org-hide-block-toggle-maybe' specifications."
  7947. (should
  7948. (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
  7949. (org-hide-block-toggle-maybe)))
  7950. (should-not
  7951. (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
  7952. (ert-deftest test-org/show-set-visibility ()
  7953. "Test `org-show-set-visibility' specifications."
  7954. ;; Do not throw an error before first heading.
  7955. (should
  7956. (org-test-with-temp-text "Preamble\n* Headline"
  7957. (org-show-set-visibility 'tree)
  7958. t))
  7959. ;; Test all visibility spans, both on headline and in entry.
  7960. (let ((list-visible-lines
  7961. (lambda (state headerp)
  7962. (org-test-with-temp-text "* Grandmother (0)
  7963. ** Uncle (1)
  7964. *** Heir (2)
  7965. ** Father (3)
  7966. Ancestor text (4)
  7967. *** Sister (5)
  7968. Sibling text (6)
  7969. *** Self (7)
  7970. Match (8)
  7971. **** First born (9)
  7972. Child text (10)
  7973. **** The other child (11)
  7974. *** Brother (12)
  7975. ** Aunt (13)
  7976. "
  7977. (org-cycle t)
  7978. (search-forward (if headerp "Self" "Match"))
  7979. (org-show-set-visibility state)
  7980. (goto-char (point-min))
  7981. (let (result (line 0))
  7982. (while (not (eobp))
  7983. (unless (org-invisible-p2) (push line result))
  7984. (cl-incf line)
  7985. (forward-line))
  7986. (nreverse result))))))
  7987. (should (equal '(0 7) (funcall list-visible-lines 'minimal t)))
  7988. (should (equal '(0 7 8) (funcall list-visible-lines 'minimal nil)))
  7989. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local t)))
  7990. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local nil)))
  7991. (should (equal '(0 3 7) (funcall list-visible-lines 'ancestors t)))
  7992. (should (equal '(0 3 7 8) (funcall list-visible-lines 'ancestors nil)))
  7993. (should (equal '(0 3 7 8 9 10 11)
  7994. (funcall list-visible-lines 'ancestors-full t)))
  7995. (should (equal '(0 3 7 8 9 10 11)
  7996. (funcall list-visible-lines 'ancestors-full nil)))
  7997. (should (equal '(0 3 5 7 12) (funcall list-visible-lines 'lineage t)))
  7998. (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines 'lineage nil)))
  7999. (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines 'tree t)))
  8000. (should (equal '(0 1 3 5 7 8 9 11 12 13)
  8001. (funcall list-visible-lines 'tree nil)))
  8002. (should (equal '(0 1 3 4 5 7 12 13)
  8003. (funcall list-visible-lines 'canonical t)))
  8004. (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
  8005. (funcall list-visible-lines 'canonical nil))))
  8006. ;; When point is hidden in a drawer or a block, make sure to make it
  8007. ;; visible.
  8008. (should-not
  8009. (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
  8010. (org-hide-block-toggle)
  8011. (search-forward "Text")
  8012. (org-show-set-visibility 'minimal)
  8013. (org-invisible-p2)))
  8014. (should-not
  8015. (org-test-with-temp-text ":DRAWER:\nText\n:END:"
  8016. (org-hide-drawer-toggle)
  8017. (search-forward "Text")
  8018. (org-show-set-visibility 'minimal)
  8019. (org-invisible-p2)))
  8020. (should-not
  8021. (org-test-with-temp-text
  8022. "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
  8023. (org-hide-drawer-toggle)
  8024. (forward-line -1)
  8025. (org-hide-block-toggle)
  8026. (search-forward "Text")
  8027. (org-show-set-visibility 'minimal)
  8028. (org-invisible-p2))))
  8029. (ert-deftest test-org/copy-visible ()
  8030. "Test `org-copy-visible' specifications."
  8031. ;;`org-unfontify-region', which is wired up to
  8032. ;; `font-lock-unfontify-region-function', removes the invisible text
  8033. ;; property, among other things.
  8034. (cl-letf (((symbol-function 'org-unfontify-region) #'ignore))
  8035. (should
  8036. (equal "Foo"
  8037. (org-test-with-temp-text "Foo"
  8038. (let ((kill-ring nil))
  8039. (org-copy-visible (point-min) (point-max))
  8040. (current-kill 0 t)))))
  8041. ;; Skip invisible characters by text property.
  8042. (should
  8043. (equal "Foo"
  8044. (org-test-with-temp-text #("F<hidden>oo" 1 9 (invisible t))
  8045. (let ((kill-ring nil))
  8046. (org-copy-visible (point-min) (point-max))
  8047. (current-kill 0 t)))))
  8048. ;; Skip invisible characters by overlay.
  8049. (should
  8050. (equal "Foo"
  8051. (org-test-with-temp-text "F<hidden>oo"
  8052. (let ((o (make-overlay 2 10)))
  8053. (overlay-put o 'invisible t))
  8054. (let ((kill-ring nil))
  8055. (org-copy-visible (point-min) (point-max))
  8056. (current-kill 0 t)))))
  8057. ;; Handle invisible characters at the beginning and the end of the
  8058. ;; buffer.
  8059. (should
  8060. (equal "Foo"
  8061. (org-test-with-temp-text #("<hidden>Foo" 0 8 (invisible t))
  8062. (let ((kill-ring nil))
  8063. (org-copy-visible (point-min) (point-max))
  8064. (current-kill 0 t)))))
  8065. (should
  8066. (equal "Foo"
  8067. (org-test-with-temp-text #("Foo<hidden>" 3 11 (invisible t))
  8068. (let ((kill-ring nil))
  8069. (org-copy-visible (point-min) (point-max))
  8070. (current-kill 0 t)))))
  8071. ;; Handle multiple visible parts.
  8072. (should
  8073. (equal "abc"
  8074. (org-test-with-temp-text
  8075. #("aXbXc" 1 2 (invisible t) 3 4 (invisible t))
  8076. (let ((kill-ring nil))
  8077. (org-copy-visible (point-min) (point-max))
  8078. (current-kill 0 t)))))
  8079. ;; Handle adjacent invisible parts.
  8080. (should
  8081. (equal "ab"
  8082. (org-test-with-temp-text
  8083. #("aXXb" 1 2 (invisible t) 2 3 (invisible org-link))
  8084. (let ((kill-ring nil))
  8085. (org-copy-visible (point-min) (point-max))
  8086. (current-kill 0 t)))))
  8087. ;; Copies text based on what's actually visible, as defined by
  8088. ;; `buffer-invisibility-spec'.
  8089. (should
  8090. (equal "aYb"
  8091. (org-test-with-temp-text
  8092. #("aXYb"
  8093. 1 2 (invisible t)
  8094. 2 3 (invisible org-test-copy-visible))
  8095. (let ((kill-ring nil))
  8096. (org-copy-visible (point-min) (point-max))
  8097. (current-kill 0 t)))))))
  8098. (ert-deftest test-org/set-visibility-according-to-property ()
  8099. "Test `org-set-visibility-according-to-property' specifications."
  8100. ;; "folded" state.
  8101. (should
  8102. (org-test-with-temp-text
  8103. "
  8104. * a
  8105. :PROPERTIES:
  8106. :VISIBILITY: folded
  8107. :END:
  8108. ** <point>b"
  8109. (org-set-visibility-according-to-property)
  8110. (invisible-p (point))))
  8111. ;; "children" state.
  8112. (should
  8113. (org-test-with-temp-text
  8114. "
  8115. * a
  8116. :PROPERTIES:
  8117. :VISIBILITY: children
  8118. :END:
  8119. ** b
  8120. <point>Contents
  8121. ** c"
  8122. (org-set-visibility-according-to-property)
  8123. (invisible-p (point))))
  8124. (should
  8125. (org-test-with-temp-text
  8126. "
  8127. * a
  8128. :PROPERTIES:
  8129. :VISIBILITY: children
  8130. :END:
  8131. ** b
  8132. Contents
  8133. *** <point>c"
  8134. (org-set-visibility-according-to-property)
  8135. (invisible-p (point))))
  8136. ;; "content" state.
  8137. (should
  8138. (org-test-with-temp-text
  8139. "
  8140. * a
  8141. :PROPERTIES:
  8142. :VISIBILITY: content
  8143. :END:
  8144. ** b
  8145. <point>Contents
  8146. *** c"
  8147. (org-set-visibility-according-to-property)
  8148. (invisible-p (point))))
  8149. (should
  8150. (org-test-with-temp-text
  8151. "
  8152. * a
  8153. :PROPERTIES:
  8154. :VISIBILITY: content
  8155. :END:
  8156. ** b
  8157. Contents
  8158. *** <point>c"
  8159. (org-set-visibility-according-to-property)
  8160. (not (invisible-p (point)))))
  8161. ;; "showall" state.
  8162. (should
  8163. (org-test-with-temp-text
  8164. "
  8165. * a
  8166. :PROPERTIES:
  8167. :VISIBILITY: showall
  8168. :END:
  8169. ** b
  8170. <point>Contents
  8171. *** c"
  8172. (org-set-visibility-according-to-property)
  8173. (not (invisible-p (point)))))
  8174. (should
  8175. (org-test-with-temp-text
  8176. "
  8177. * a
  8178. :PROPERTIES:
  8179. :VISIBILITY: showall
  8180. :END:
  8181. ** b
  8182. Contents
  8183. *** <point>c"
  8184. (org-set-visibility-according-to-property)
  8185. (not (invisible-p (point)))))
  8186. ;; When VISIBILITY properties are nested, ignore inner ones.
  8187. (should
  8188. (org-test-with-temp-text
  8189. "
  8190. * A
  8191. :PROPERTIES:
  8192. :VISIBILITY: folded
  8193. :END:
  8194. ** <point>B
  8195. :PROPERTIES:
  8196. :VISIBILITY: folded
  8197. :END:"
  8198. (org-set-visibility-according-to-property)
  8199. (invisible-p (point)))))
  8200. (ert-deftest test-org/visibility-show-branches ()
  8201. "Test visibility of inline archived subtrees."
  8202. (org-test-with-temp-text
  8203. "* Foo<point>
  8204. ** Bar :ARCHIVE:
  8205. *** Baz
  8206. "
  8207. (org-kill-note-or-show-branches)
  8208. (should (org-invisible-p (- (point-max) 2)))))
  8209. ;;; Yank and Kill
  8210. (ert-deftest test-org/paste-subtree ()
  8211. "Test `org-paste-subtree' specifications."
  8212. ;; Return an error if text to yank is not a set of subtrees.
  8213. (should-error (org-paste-subtree nil "Text"))
  8214. ;; Adjust level according to current one.
  8215. (should
  8216. (equal "* H\n* Text\n"
  8217. (org-test-with-temp-text "* H\n<point>"
  8218. (org-paste-subtree nil "* Text")
  8219. (buffer-string))))
  8220. (should
  8221. (equal "* H1\n** H2\n** Text\n"
  8222. (org-test-with-temp-text "* H1\n** H2\n<point>"
  8223. (org-paste-subtree nil "* Text")
  8224. (buffer-string))))
  8225. ;; When not on a heading, move to next heading before yanking.
  8226. (should
  8227. (equal "* H1\nParagraph\n* Text\n* H2"
  8228. (org-test-with-temp-text "* H1\n<point>Paragraph\n* H2"
  8229. (org-paste-subtree nil "* Text")
  8230. (buffer-string))))
  8231. ;; If point is between two headings, use the deepest level.
  8232. (should
  8233. (equal "* H1\n\n* Text\n* H2"
  8234. (org-test-with-temp-text "* H1\n<point>\n* H2"
  8235. (org-paste-subtree nil "* Text")
  8236. (buffer-string))))
  8237. (should
  8238. (equal "** H1\n\n** Text\n* H2"
  8239. (org-test-with-temp-text "** H1\n<point>\n* H2"
  8240. (org-paste-subtree nil "* Text")
  8241. (buffer-string))))
  8242. (should
  8243. (equal "* H1\n\n** Text\n** H2"
  8244. (org-test-with-temp-text "* H1\n<point>\n** H2"
  8245. (org-paste-subtree nil "* Text")
  8246. (buffer-string))))
  8247. ;; When on an empty heading, after the stars, deduce the new level
  8248. ;; from the number of stars.
  8249. (should
  8250. (equal "*** Text\n"
  8251. (org-test-with-temp-text "*** <point>"
  8252. (org-paste-subtree nil "* Text")
  8253. (buffer-string))))
  8254. ;; Optional argument LEVEL forces a level for the subtree.
  8255. (should
  8256. (equal "* H\n*** Text\n"
  8257. (org-test-with-temp-text "* H<point>"
  8258. (org-paste-subtree 3 "* Text")
  8259. (buffer-string)))))
  8260. (ert-deftest test-org/cut-and-paste-subtree ()
  8261. "Test `org-cut-subtree' and `org-paste-subtree'."
  8262. (should
  8263. (equal
  8264. "* Two
  8265. two
  8266. * One
  8267. "
  8268. (org-test-with-temp-text
  8269. "* One
  8270. <point>* Two
  8271. two
  8272. "
  8273. (call-interactively #'org-cut-subtree)
  8274. (goto-char (point-min))
  8275. (call-interactively #'org-paste-subtree)
  8276. (buffer-string))))
  8277. (should
  8278. (equal
  8279. "* One
  8280. * Two
  8281. "
  8282. (org-test-with-temp-text
  8283. "* One
  8284. <point>* Two
  8285. "
  8286. (call-interactively #'org-cut-subtree)
  8287. (backward-char)
  8288. (call-interactively #'org-paste-subtree)
  8289. (buffer-string)))))
  8290. (provide 'test-org)
  8291. ;;; test-org.el ends here