test-org.el 274 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426
  1. ;;; test-org.el --- tests for org.el
  2. ;; Copyright (c) David Maus
  3. ;; Authors: David Maus
  4. ;; This file is not part of GNU Emacs.
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. ;; Template test file for Org tests
  16. ;;; Code:
  17. (eval-and-compile (require 'cl-lib))
  18. ;;; Helpers
  19. (defmacro org-test-with-timezone (tz &rest body)
  20. "Evaluate BODY with TZ environment temporary set to the passed value."
  21. (declare (indent 1))
  22. (org-with-gensyms (tz-saved)
  23. `(let ((,tz-saved (getenv "TZ")))
  24. (unwind-protect
  25. (progn
  26. (setenv "TZ" ,tz)
  27. ,@body)
  28. (setenv "TZ" ,tz-saved)))))
  29. ;;; Comments
  30. (ert-deftest test-org/toggle-comment ()
  31. "Test `org-toggle-comment' specifications."
  32. ;; Simple headline.
  33. (should
  34. (equal "* Test"
  35. (org-test-with-temp-text "* COMMENT Test"
  36. (org-toggle-comment)
  37. (buffer-string))))
  38. (should
  39. (equal "* COMMENT Test"
  40. (org-test-with-temp-text "* Test"
  41. (org-toggle-comment)
  42. (buffer-string))))
  43. ;; Headline with a regular keyword.
  44. (should
  45. (equal "* TODO Test"
  46. (org-test-with-temp-text "* TODO COMMENT Test"
  47. (org-toggle-comment)
  48. (buffer-string))))
  49. (should
  50. (equal "* TODO COMMENT Test"
  51. (org-test-with-temp-text "* TODO Test"
  52. (org-toggle-comment)
  53. (buffer-string))))
  54. ;; Empty headline.
  55. (should
  56. (equal "* "
  57. (org-test-with-temp-text "* COMMENT"
  58. (org-toggle-comment)
  59. (buffer-string))))
  60. (should
  61. (equal "* COMMENT"
  62. (org-test-with-temp-text "* "
  63. (org-toggle-comment)
  64. (buffer-string))))
  65. ;; Headline with a single keyword.
  66. (should
  67. (equal "* TODO "
  68. (org-test-with-temp-text "* TODO COMMENT"
  69. (org-toggle-comment)
  70. (buffer-string))))
  71. (should
  72. (equal "* TODO COMMENT"
  73. (org-test-with-temp-text "* TODO"
  74. (org-toggle-comment)
  75. (buffer-string))))
  76. ;; Headline with a keyword, a priority cookie and contents.
  77. (should
  78. (equal "* TODO [#A] Headline"
  79. (org-test-with-temp-text "* TODO [#A] COMMENT Headline"
  80. (org-toggle-comment)
  81. (buffer-string))))
  82. (should
  83. (equal "* TODO [#A] COMMENT Headline"
  84. (org-test-with-temp-text "* TODO [#A] Headline"
  85. (org-toggle-comment)
  86. (buffer-string)))))
  87. (ert-deftest test-org/comment-dwim ()
  88. "Test `comment-dwim' behaviour in an Org buffer."
  89. ;; No region selected, no comment on current line and line not
  90. ;; empty: insert comment on line above.
  91. (should
  92. (equal "# \nComment"
  93. (org-test-with-temp-text "Comment"
  94. (call-interactively #'org-comment-dwim)
  95. (buffer-string))))
  96. ;; No region selected, no comment on current line and line empty:
  97. ;; insert comment on this line.
  98. (should
  99. (equal "# \nParagraph"
  100. (org-test-with-temp-text "\nParagraph"
  101. (call-interactively #'org-comment-dwim)
  102. (buffer-string))))
  103. ;; No region selected, and a comment on this line: indent it.
  104. (should
  105. (equal "* Headline\n # Comment"
  106. (org-test-with-temp-text "* Headline\n# <point>Comment"
  107. (let ((org-adapt-indentation t))
  108. (call-interactively #'org-comment-dwim))
  109. (buffer-string))))
  110. ;; Also recognize single # at column 0 as comments.
  111. (should
  112. (equal "# Comment"
  113. (org-test-with-temp-text "# Comment"
  114. (call-interactively #'org-comment-dwim)
  115. (buffer-string))))
  116. ;; Region selected and only comments and blank lines within it:
  117. ;; un-comment all commented lines.
  118. (should
  119. (equal "Comment 1\n\nComment 2"
  120. (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
  121. (transient-mark-mode 1)
  122. (push-mark (point) t t)
  123. (goto-char (point-max))
  124. (call-interactively #'org-comment-dwim)
  125. (buffer-string))))
  126. ;; Region selected without comments: comment all lines if
  127. ;; `comment-empty-lines' is non-nil, only non-blank lines otherwise.
  128. (should
  129. (equal "# Comment 1\n\n# Comment 2"
  130. (org-test-with-temp-text "Comment 1\n\nComment 2"
  131. (transient-mark-mode 1)
  132. (push-mark (point) t t)
  133. (goto-char (point-max))
  134. (let ((comment-empty-lines nil))
  135. (call-interactively #'org-comment-dwim))
  136. (buffer-string))))
  137. (should
  138. (equal "# Comment 1\n# \n# Comment 2"
  139. (org-test-with-temp-text "Comment 1\n\nComment 2"
  140. (transient-mark-mode 1)
  141. (push-mark (point) t t)
  142. (goto-char (point-max))
  143. (let ((comment-empty-lines t))
  144. (call-interactively #'org-comment-dwim))
  145. (buffer-string))))
  146. ;; In front of a keyword without region, insert a new comment.
  147. (should
  148. (equal "# \n#+KEYWORD: value"
  149. (org-test-with-temp-text "#+KEYWORD: value"
  150. (call-interactively #'org-comment-dwim)
  151. (buffer-string))))
  152. ;; Comment a heading
  153. (should
  154. (equal "* COMMENT Test"
  155. (org-test-with-temp-text "* Test"
  156. (call-interactively #'org-comment-dwim)
  157. (buffer-string))))
  158. ;; In a source block, use appropriate syntax.
  159. (should
  160. (equal " ;; "
  161. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n<point>\n#+END_SRC"
  162. (let ((org-edit-src-content-indentation 2))
  163. (call-interactively #'org-comment-dwim))
  164. (buffer-substring-no-properties (line-beginning-position)
  165. (point)))))
  166. (should
  167. (equal "#+BEGIN_SRC emacs-lisp\n ;; a\n ;; b\n#+END_SRC"
  168. (org-test-with-temp-text
  169. "#+BEGIN_SRC emacs-lisp\n<point>a\nb\n#+END_SRC"
  170. (transient-mark-mode 1)
  171. (push-mark (point) t t)
  172. (forward-line 2)
  173. (let ((org-edit-src-content-indentation 2))
  174. (call-interactively #'org-comment-dwim))
  175. (buffer-string)))))
  176. ;;; Date and time analysis
  177. (ert-deftest test-org/org-encode-time ()
  178. "Test various ways to call `org-encode-time'"
  179. (org-test-with-timezone "UTC"
  180. ;; list as the sole argument
  181. (should (string-equal
  182. "2022-03-24 23:30:01"
  183. (format-time-string
  184. "%F %T"
  185. (org-encode-time '(1 30 23 24 3 2022 nil -1 nil)))))
  186. ;; SECOND...YEAR
  187. (should (string-equal
  188. "2022-03-24 23:30:02"
  189. (format-time-string
  190. "%F %T"
  191. (org-encode-time 2 30 23 24 3 2022))))
  192. ;; SECOND...YEAR IGNORED DST ZONE
  193. (should (string-equal
  194. "2022-03-24 23:30:03"
  195. (format-time-string
  196. "%F %T"
  197. (org-encode-time 3 30 23 24 3 2022 nil -1 nil))))
  198. ;; function call
  199. (should (string-equal
  200. "2022-03-24 23:30:04"
  201. (format-time-string
  202. "%F %T"
  203. (org-encode-time (apply #'list 4 30 23 '(24 3 2022 nil -1 nil))))))
  204. ;; wrong number of arguments
  205. (if (not (version< emacs-version "27.1"))
  206. (should-error (string-equal
  207. "2022-03-24 23:30:05"
  208. (format-time-string
  209. "%F %T"
  210. (org-encode-time 5 30 23 24 3 2022 nil))))))
  211. ;; daylight saving time
  212. (if (not (version< emacs-version "27.1"))
  213. ;; DST value is not ignored for multiple arguments unlike for `encode-time'
  214. (should (string-equal
  215. "2022-04-01 00:30:06 +0200 CEST"
  216. (format-time-string
  217. "%F %T %z %Z"
  218. (org-encode-time 6 30 23 31 3 2022 nil nil "Europe/Madrid")
  219. "Europe/Madrid")))
  220. (should (string-equal
  221. "2022-03-31 23:30:07 +0200 CEST"
  222. (format-time-string
  223. "%F %T %z %Z"
  224. (org-encode-time 7 30 23 31 3 2022 nil t "Europe/Madrid")
  225. "Europe/Madrid"))))
  226. (org-test-with-timezone "Europe/Madrid"
  227. ;; Standard time is not forced when DST is not specified
  228. (should (string-equal
  229. "2022-03-31 23:30:08"
  230. (format-time-string
  231. "%F %T"
  232. (org-encode-time 8 30 23 31 3 2022))))))
  233. (ert-deftest test-org/org-time-string-to-time ()
  234. "Test `org-time-string-to-time' around DST transition."
  235. (org-test-with-timezone "UTC"
  236. (should (string-equal
  237. "2022-03-31 23:31:00"
  238. (format-time-string
  239. "%F %T"
  240. (org-time-string-to-time "2022-03-31 23:31")))))
  241. (org-test-with-timezone "Europe/Madrid"
  242. (should (string-equal
  243. "2022-03-24 23:32:00 +0100 CET"
  244. (format-time-string
  245. "%F %T %z %Z"
  246. (org-time-string-to-time "2022-03-24 23:32"))))
  247. (should (string-equal
  248. "2022-03-31 23:33:00 +0200 CEST"
  249. (format-time-string
  250. "%F %T %z %Z"
  251. (org-time-string-to-time "2022-03-31 23:33"))))))
  252. (ert-deftest test-org/org-read-date ()
  253. "Test `org-read-date' specifications."
  254. ;; Parse ISO date with abbreviated year and month.
  255. (should (equal "2012-03-29 16:40"
  256. (let ((org-time-was-given t))
  257. (org-read-date t nil "12-3-29 16:40"))))
  258. ;; Parse Europeans dates.
  259. (should (equal "2012-03-29 16:40"
  260. (let ((org-time-was-given t))
  261. (org-read-date t nil "29.03.2012 16:40"))))
  262. ;; Parse Europeans dates without year.
  263. (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
  264. (let ((org-time-was-given t))
  265. (org-read-date t nil "29.03. 16:40"))))
  266. ;; Relative date applied to current time if there is single
  267. ;; plus/minus, or to default date when there are two of them.
  268. (should
  269. (equal
  270. "2015-03-04"
  271. (org-test-at-time "2014-03-04"
  272. (org-read-date
  273. t nil "+1y" nil
  274. (org-time-string-to-time "2012-03-29")))))
  275. (should
  276. (equal
  277. "2013-03-29"
  278. (org-test-at-time "2014-03-04"
  279. (org-read-date
  280. t nil "++1y" nil
  281. (org-time-string-to-time "2012-03-29")))))
  282. ;; When `org-read-date-prefer-future' is non-nil, prefer future
  283. ;; dates (relatively to now) when incomplete. Otherwise, use
  284. ;; default date.
  285. (should
  286. (equal
  287. "2014-04-01"
  288. (org-test-at-time "2014-03-04"
  289. (let ((org-read-date-prefer-future t))
  290. (org-read-date t nil "1")))))
  291. (should
  292. (equal
  293. "2013-03-04"
  294. (org-test-at-time "2012-03-29"
  295. (let ((org-read-date-prefer-future t))
  296. (org-read-date t nil "3-4")))))
  297. (should
  298. (equal
  299. "2012-03-04"
  300. (org-test-at-time "2012-03-29"
  301. (let ((org-read-date-prefer-future nil))
  302. (org-read-date t nil "3-4")))))
  303. ;; When set to `org-read-date-prefer-future' is set to `time', read
  304. ;; day is moved to tomorrow if specified hour is before current
  305. ;; time. However, it only happens in no other part of the date is
  306. ;; specified.
  307. (should
  308. (equal
  309. "2012-03-30"
  310. (org-test-at-time "2012-03-29 16:40"
  311. (let ((org-read-date-prefer-future 'time))
  312. (org-read-date t nil "00:40" nil)))))
  313. (should-not
  314. (equal
  315. "2012-03-30"
  316. (org-test-at-time "2012-03-29 16:40"
  317. (let ((org-read-date-prefer-future 'time))
  318. (org-read-date t nil "29 00:40" nil)))))
  319. ;; Caveat: `org-read-date-prefer-future' always refers to current
  320. ;; time, not default time, when they differ.
  321. (should
  322. (equal
  323. "2014-04-01"
  324. (org-test-at-time "2014-03-04"
  325. (let ((org-read-date-prefer-future t))
  326. (org-read-date
  327. t nil "1" nil
  328. (org-time-string-to-time "2012-03-29"))))))
  329. (should
  330. (equal
  331. "2014-03-25"
  332. (org-test-at-time "2014-03-04"
  333. (let ((org-read-date-prefer-future t))
  334. (org-read-date
  335. t nil "25" nil
  336. (org-time-string-to-time "2012-03-29")))))))
  337. (ert-deftest test-org/org-parse-time-string ()
  338. "Test `org-parse-time-string'."
  339. (should (equal (org-parse-time-string "2012-03-29 16:40")
  340. '(0 40 16 29 3 2012 nil -1 nil)))
  341. (should (equal (org-parse-time-string "[2012-03-29 16:40]")
  342. '(0 40 16 29 3 2012 nil -1 nil)))
  343. (should (equal (org-parse-time-string "<2012-03-29 16:40>")
  344. '(0 40 16 29 3 2012 nil -1 nil)))
  345. (should (equal (org-parse-time-string "<2012-03-29>")
  346. '(0 0 0 29 3 2012 nil -1 nil)))
  347. (should (equal (org-parse-time-string "<2012-03-29>" t)
  348. '(0 nil nil 29 3 2012 nil -1 nil))))
  349. (ert-deftest test-org/closest-date ()
  350. "Test `org-closest-date' specifications."
  351. (require 'calendar)
  352. ;; Time stamps without a repeater are returned unchanged.
  353. (should
  354. (equal
  355. '(3 29 2012)
  356. (calendar-gregorian-from-absolute
  357. (org-closest-date "<2012-03-29>" "<2014-03-04>" nil))))
  358. ;; Time stamps with a null repeater are returned unchanged.
  359. (should
  360. (equal
  361. '(3 29 2012)
  362. (calendar-gregorian-from-absolute
  363. (org-closest-date "<2012-03-29 +0d>" "<2014-03-04>" nil))))
  364. ;; if PREFER is set to `past' always return a date before, or equal
  365. ;; to CURRENT.
  366. (should
  367. (equal
  368. '(3 1 2014)
  369. (calendar-gregorian-from-absolute
  370. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'past))))
  371. (should
  372. (equal
  373. '(3 4 2014)
  374. (calendar-gregorian-from-absolute
  375. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'past))))
  376. ;; if PREFER is set to `future' always return a date before, or equal
  377. ;; to CURRENT.
  378. (should
  379. (equal
  380. '(3 29 2014)
  381. (calendar-gregorian-from-absolute
  382. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'future))))
  383. (should
  384. (equal
  385. '(3 4 2014)
  386. (calendar-gregorian-from-absolute
  387. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'future))))
  388. ;; If PREFER is neither `past' nor `future', select closest date.
  389. (should
  390. (equal
  391. '(3 1 2014)
  392. (calendar-gregorian-from-absolute
  393. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" nil))))
  394. (should
  395. (equal
  396. '(5 4 2014)
  397. (calendar-gregorian-from-absolute
  398. (org-closest-date "<2012-03-04 +1m>" "<2014-04-28>" nil))))
  399. ;; Test "day" repeater.
  400. (should
  401. (equal '(3 8 2014)
  402. (calendar-gregorian-from-absolute
  403. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'past))))
  404. (should
  405. (equal '(3 10 2014)
  406. (calendar-gregorian-from-absolute
  407. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'future))))
  408. ;; Test "month" repeater.
  409. (should
  410. (equal '(1 5 2015)
  411. (calendar-gregorian-from-absolute
  412. (org-closest-date "<2014-03-05 +2m>" "<2015-02-04>" 'past))))
  413. (should
  414. (equal '(3 29 2014)
  415. (calendar-gregorian-from-absolute
  416. (org-closest-date "<2012-03-29 +2m>" "<2014-03-04>" 'future))))
  417. ;; Test "year" repeater.
  418. (should
  419. (equal '(3 5 2014)
  420. (calendar-gregorian-from-absolute
  421. (org-closest-date "<2014-03-05 +2y>" "<2015-02-04>" 'past))))
  422. (should
  423. (equal '(3 29 2014)
  424. (calendar-gregorian-from-absolute
  425. (org-closest-date "<2012-03-29 +2y>" "<2014-03-04>" 'future)))))
  426. (ert-deftest test-org/deadline-close-p ()
  427. "Test `org-deadline-close-p' specifications."
  428. (org-test-at-time "2016-06-03 Fri 01:43"
  429. ;; Timestamps are close if they are within `ndays' of lead time.
  430. (org-test-with-temp-text "* Heading"
  431. (should (org-deadline-close-p "2016-06-03 Fri" 0))
  432. (should (org-deadline-close-p "2016-06-02 Thu" 0))
  433. (should-not (org-deadline-close-p "2016-06-04 Sat" 0))
  434. (should (org-deadline-close-p "2016-06-04 Sat" 1))
  435. (should (org-deadline-close-p "2016-06-03 Fri 12:00" 0)))
  436. ;; Read `ndays' from timestamp if argument not given.
  437. (org-test-with-temp-text "* H"
  438. (should (org-deadline-close-p "2016-06-04 Sat -1d"))
  439. (should-not (org-deadline-close-p "2016-06-04 Sat -0d"))
  440. (should (org-deadline-close-p "2016-06-10 Fri -1w"))
  441. (should-not (org-deadline-close-p "2016-06-11 Sat -1w")))
  442. ;; Prefer `ndays' argument over lead time in timestamp.
  443. (org-test-with-temp-text "* H"
  444. (should (org-deadline-close-p "2016-06-04 Sat -0d" 1))
  445. (should-not (org-deadline-close-p "2016-06-04 Sat -0d" 0)))
  446. ;; Completed tasks are never close.
  447. (let ((org-todo-keywords '(("TODO" "|" "DONE"))))
  448. (org-test-with-temp-text "* TODO Heading"
  449. (should (org-deadline-close-p "2016-06-03")))
  450. (org-test-with-temp-text "* DONE Heading"
  451. (should-not (org-deadline-close-p "2016-06-03"))))))
  452. ;;; Drawers
  453. (ert-deftest test-org/at-property-p ()
  454. "Test `org-at-property-p' specifications."
  455. (should
  456. (equal 't
  457. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:PROP: t\n:END:\n"
  458. (org-at-property-p))))
  459. (should
  460. (equal 't
  461. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n:END:\n"
  462. (org-at-property-p)))))
  463. (ert-deftest test-org/at-property-drawer-p ()
  464. "Test `org-at-property-drawer-p' specifications."
  465. (should
  466. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:PROP: t\n:END:\n"
  467. (org-at-property-drawer-p)))
  468. (should
  469. (org-test-with-temp-text ":PROPERTIES:\n:PROP: t\n:END:\n"
  470. (org-at-property-drawer-p)))
  471. ;; The function only returns t if point is at the first line of
  472. ;; a property block.
  473. (should-not
  474. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n:END:\n"
  475. (org-at-property-drawer-p)))
  476. ;; The function ignores incomplete drawers.
  477. (should-not
  478. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n"
  479. (org-at-property-drawer-p)))
  480. ;; tab separating the value.
  481. (should
  482. (org-test-with-temp-text ":PROPERTIES:\n:PROP: t\n:END:\n"
  483. (org-at-property-drawer-p))))
  484. (ert-deftest test-org/get-property-block ()
  485. "Test `org-get-property-block' specifications."
  486. (should
  487. (equal '(14 . 14)
  488. (org-test-with-temp-text ":PROPERTIES:\n:END:\n* H\n"
  489. (org-get-property-block))))
  490. (should
  491. (equal '(14 . 14)
  492. (org-test-with-temp-text ":PROPERTIES:\n:END:\n"
  493. (org-get-property-block))))
  494. ;; Comments above a document property block is ok.
  495. (should
  496. (equal '(18 . 18)
  497. (org-test-with-temp-text "# C\n:PROPERTIES:\n:END:\n"
  498. (org-get-property-block))))
  499. ;; Keywords above a document property block is ok.
  500. (should
  501. (equal '(22 . 22)
  502. (org-test-with-temp-text "# C\n# C\n:PROPERTIES:\n:END:\n"
  503. (org-get-property-block))))
  504. ;; Comments and keywords are allowed before a document property block.
  505. (should
  506. (equal '(18 . 27)
  507. (org-test-with-temp-text "# C\n:PROPERTIES:\n:KEY: V:\n:END:\n"
  508. (org-get-property-block))))
  509. ;; A document property block will not be valid if there are lines
  510. ;; with whitespace above it
  511. (should-not
  512. (org-test-with-temp-text "\n:PROPERTIES:\n:END:\n"
  513. (org-get-property-block)))
  514. (should
  515. (equal '(18 . 18)
  516. (org-test-with-temp-text "* H\n:PROPERTIES:\n:END:\n<point>"
  517. (org-get-property-block))))
  518. (should
  519. (equal "* H\n:PROPERTIES:\n:END:\n"
  520. (org-test-with-temp-text "* H"
  521. (let ((org-adapt-indentation nil))
  522. (org-get-property-block nil 'force))
  523. (buffer-string))))
  524. (should
  525. (equal ":PROPERTIES:\n:END:\n"
  526. (org-test-with-temp-text ""
  527. (org-get-property-block nil 'force)
  528. (buffer-string))))
  529. (should
  530. (equal "* H1\n :PROPERTIES:\n :END:\n* H2"
  531. (org-test-with-temp-text "* H1\n* H2"
  532. (let ((org-adapt-indentation t))
  533. (org-get-property-block nil 'force))
  534. (buffer-string)))))
  535. (ert-deftest test-org/insert-property-drawer ()
  536. "Test `org-insert-property-drawer' specifications."
  537. ;; Insert drawer in empty buffer
  538. (should
  539. (equal ":PROPERTIES:\n:END:\n"
  540. (org-test-with-temp-text ""
  541. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  542. (buffer-string))))
  543. ;; Insert drawer in document header with existing comment and
  544. ;; keyword.
  545. (should
  546. (equal "# C\n:PROPERTIES:\n:END:\n#+TITLE: T"
  547. (org-test-with-temp-text "# C\n#+TITLE: T"
  548. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  549. (buffer-string))))
  550. ;; Insert drawer in document header with existing keyword.
  551. (should
  552. (equal ":PROPERTIES:\n:END:\n#+TITLE: T"
  553. (org-test-with-temp-text "#+TITLE: T"
  554. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  555. (buffer-string))))
  556. (should
  557. (equal ":PROPERTIES:\n:END:"
  558. (org-test-with-temp-text ":PROPERTIES:\n:END:"
  559. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  560. (buffer-string))))
  561. ;; Insert drawer in document header with one existing heading in buffer.
  562. (should
  563. (equal ":PROPERTIES:\n:END:\n\n* T\n"
  564. (org-test-with-temp-text "\n* T\n"
  565. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  566. (buffer-string))))
  567. ;; Insert drawer right after headline if there is no planning line,
  568. ;; or after it otherwise.
  569. (should
  570. (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
  571. (org-test-with-temp-text "* H\nParagraph<point>"
  572. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  573. (buffer-string))))
  574. (should
  575. (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
  576. (org-test-with-temp-text
  577. "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
  578. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  579. (buffer-string))))
  580. ;; Indent inserted drawer.
  581. (should
  582. (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
  583. (org-test-with-temp-text "* H\nParagraph<point>"
  584. (let ((org-adapt-indentation t)) (org-insert-property-drawer))
  585. (buffer-string))))
  586. ;; Handle insertion at eob.
  587. (should
  588. (equal "* H\n:PROPERTIES:\n:END:\n"
  589. (org-test-with-temp-text "* H"
  590. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  591. (buffer-string))))
  592. ;; Skip inlinetasks before point.
  593. (when (featurep 'org-inlinetask)
  594. (should
  595. (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
  596. (org-test-with-temp-text
  597. "* H\n*************** I\n*************** END\nP<point>"
  598. (let ((org-adapt-indentation nil)
  599. (org-inlinetask-min-level 15))
  600. (org-insert-property-drawer))
  601. (buffer-string)))))
  602. ;; Correctly set drawer in an inlinetask.
  603. (when (featurep 'org-inlinetask)
  604. (should
  605. (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
  606. (org-test-with-temp-text
  607. "* H\n*************** I\nP<point>\n*************** END"
  608. (let ((org-adapt-indentation nil)
  609. (org-inlinetask-min-level 15))
  610. (org-insert-property-drawer))
  611. (buffer-string))))))
  612. ;;; Filling
  613. (ert-deftest test-org/fill-element ()
  614. "Test `org-fill-element' specifications."
  615. ;; At an Org table, align it.
  616. (should
  617. (equal "| a |\n"
  618. (org-test-with-temp-text "|a|"
  619. (org-fill-element)
  620. (buffer-string))))
  621. (should
  622. (equal "#+name: table\n| a |\n"
  623. (org-test-with-temp-text "#+name: table\n| a |\n"
  624. (org-fill-element)
  625. (buffer-string))))
  626. ;; At a paragraph, preserve line breaks.
  627. (org-test-with-temp-text "some \\\\\nlong\ntext"
  628. (let ((fill-column 20))
  629. (org-fill-element)
  630. (should (equal (buffer-string) "some \\\\\nlong text"))))
  631. ;; Correctly fill a paragraph when point is at its very end.
  632. (should
  633. (equal "A B"
  634. (org-test-with-temp-text "A\nB"
  635. (let ((fill-column 20))
  636. (goto-char (point-max))
  637. (org-fill-element)
  638. (buffer-string)))))
  639. ;; Correctly fill the last paragraph of a greater element.
  640. (should
  641. (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
  642. (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
  643. (let ((fill-column 8))
  644. (forward-line)
  645. (end-of-line)
  646. (org-fill-element)
  647. (buffer-string)))))
  648. ;; Correctly fill an element in a narrowed buffer.
  649. (should
  650. (equal "01234\n6"
  651. (org-test-with-temp-text "01234 6789"
  652. (let ((fill-column 5))
  653. (narrow-to-region 1 8)
  654. (org-fill-element)
  655. (buffer-string)))))
  656. ;; Handle `adaptive-fill-regexp' in paragraphs.
  657. (should
  658. (equal "> a b"
  659. (org-test-with-temp-text "> a\n> b"
  660. (let ((fill-column 5)
  661. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  662. (org-fill-element)
  663. (buffer-string)))))
  664. ;; Special case: Fill first paragraph when point is at an item or
  665. ;; a plain-list or a footnote reference.
  666. (should
  667. (equal "- A B"
  668. (org-test-with-temp-text "- A\n B"
  669. (let ((fill-column 20))
  670. (org-fill-element)
  671. (buffer-string)))))
  672. (should
  673. (equal "[fn:1] A B"
  674. (org-test-with-temp-text "[fn:1] A\nB"
  675. (let ((fill-column 20))
  676. (org-fill-element)
  677. (buffer-string)))))
  678. (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
  679. (let ((fill-column 20))
  680. (org-fill-element)
  681. (should (equal (buffer-string)
  682. "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
  683. ;; Fill contents of `comment-block' elements.
  684. (should
  685. (equal
  686. (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
  687. (let ((fill-column 20))
  688. (forward-line)
  689. (org-fill-element)
  690. (buffer-string)))
  691. "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
  692. ;; Fill `comment' elements.
  693. (should
  694. (equal " # A B"
  695. (org-test-with-temp-text " # A\n # B"
  696. (let ((fill-column 20))
  697. (org-fill-element)
  698. (buffer-string)))))
  699. ;; Do not mix consecutive comments when filling one of them.
  700. (should
  701. (equal "# A B\n\n# C"
  702. (org-test-with-temp-text "# A\n# B\n\n# C"
  703. (let ((fill-column 20))
  704. (org-fill-element)
  705. (buffer-string)))))
  706. ;; Use commented empty lines as separators when filling comments.
  707. (should
  708. (equal "# A B\n#\n# C"
  709. (org-test-with-temp-text "# A\n# B\n#\n# C"
  710. (let ((fill-column 20))
  711. (org-fill-element)
  712. (buffer-string)))))
  713. ;; Handle `adaptive-fill-regexp' in comments.
  714. (should
  715. (equal "# > a b"
  716. (org-test-with-temp-text "# > a\n# > b"
  717. (let ((fill-column 20)
  718. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  719. (org-fill-element)
  720. (buffer-string)))))
  721. ;; Do nothing at affiliated keywords.
  722. (should
  723. (equal "#+NAME: para\nSome\ntext."
  724. (org-test-with-temp-text "#+NAME: para\nSome\ntext."
  725. (let ((fill-column 20))
  726. (org-fill-element)
  727. (buffer-string)))))
  728. ;; Do not move point after table when filling a table.
  729. (should-not
  730. (org-test-with-temp-text "| a | b |\n| c | d |\n"
  731. (forward-char)
  732. (org-fill-element)
  733. (eobp)))
  734. ;; Do not fill "n" macro, with or without arguments, followed by
  735. ;; a dot or a closing parenthesis since it could be confused with
  736. ;; a numbered bullet.
  737. (should-not
  738. (equal "123456789\n{{{n}}}."
  739. (org-test-with-temp-text "123456789 {{{n}}}."
  740. (let ((fill-column 10))
  741. (org-fill-element)
  742. (buffer-string)))))
  743. (should-not
  744. (equal "123456789\n{{{n}}}\)"
  745. (org-test-with-temp-text "123456789 {{{n}}}\)"
  746. (let ((fill-column 10))
  747. (org-fill-element)
  748. (buffer-string)))))
  749. (should-not
  750. (equal "123456789\n{{{n()}}}."
  751. (org-test-with-temp-text "123456789 {{{n()}}}."
  752. (let ((fill-column 10))
  753. (org-fill-element)
  754. (buffer-string)))))
  755. (should-not
  756. (equal "123456789\n{{{n(counter)}}}."
  757. (org-test-with-temp-text "123456789 {{{n(counter)}}}."
  758. (let ((fill-column 10))
  759. (org-fill-element)
  760. (buffer-string))))))
  761. (ert-deftest test-org/fill-paragraph ()
  762. "Test `org-fill-paragraph' specifications."
  763. ;; Regular test.
  764. (should
  765. (equal "012345678\n9"
  766. (org-test-with-temp-text "012345678 9"
  767. (let ((fill-column 10))
  768. (org-fill-paragraph)
  769. (buffer-string)))))
  770. ;; Fill paragraph even at end of buffer.
  771. (should
  772. (equal "012345678\n9\n"
  773. (org-test-with-temp-text "012345678 9\n<point>"
  774. (let ((fill-column 10))
  775. (org-fill-paragraph)
  776. (buffer-string)))))
  777. ;; Between two paragraphs, fill the next one.
  778. (should
  779. (equal "012345678 9\n\n012345678\n9"
  780. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  781. (let ((fill-column 10))
  782. (org-fill-paragraph)
  783. (buffer-string)))))
  784. (should
  785. (equal "012345678\n9\n\n012345678 9"
  786. (org-test-with-temp-text "012345678 9<point>\n\n012345678 9"
  787. (let ((fill-column 10))
  788. (org-fill-paragraph)
  789. (buffer-string)))))
  790. ;; Fill paragraph in a comment block.
  791. (should
  792. (equal "#+begin_comment\n012345678\n9\n#+end_comment"
  793. (org-test-with-temp-text
  794. "#+begin_comment\n<point>012345678 9\n#+end_comment"
  795. (let ((fill-column 10))
  796. (org-fill-paragraph)
  797. (buffer-string)))))
  798. ;; When a region is selected, fill every paragraph in the region.
  799. (should
  800. (equal "012345678\n9\n\n012345678\n9"
  801. (org-test-with-temp-text "012345678 9\n\n012345678 9"
  802. (let ((fill-column 10))
  803. (transient-mark-mode 1)
  804. (push-mark (point-min) t t)
  805. (goto-char (point-max))
  806. (call-interactively #'org-fill-paragraph)
  807. (buffer-string)))))
  808. (should
  809. (equal "012345678\n9\n\n012345678 9"
  810. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  811. (let ((fill-column 10))
  812. (transient-mark-mode 1)
  813. (push-mark (point) t t)
  814. (goto-char (point-min))
  815. (call-interactively #'org-fill-paragraph)
  816. (buffer-string)))))
  817. (should
  818. (equal "012345678 9\n\n012345678\n9"
  819. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  820. (let ((fill-column 10))
  821. (transient-mark-mode 1)
  822. (push-mark (point) t t)
  823. (goto-char (point-max))
  824. (call-interactively #'org-fill-paragraph)
  825. (buffer-string)))))
  826. ;; Fill every list item in a region
  827. (should
  828. (equal "\n- 2345678\n 9\n- 2345678\n 9"
  829. (org-test-with-temp-text "\n- 2345678 9\n- 2345678 9"
  830. (let ((fill-column 10))
  831. (transient-mark-mode 1)
  832. (push-mark (point-min) t t)
  833. (goto-char (point-max))
  834. (call-interactively #'org-fill-paragraph)
  835. (buffer-string)))))
  836. (should
  837. (equal "\n- 2345678\n 9\n- 2345678"
  838. (org-test-with-temp-text "\n- 2345678 9\n- 2345678"
  839. (let ((fill-column 10))
  840. (transient-mark-mode 1)
  841. (push-mark (point-min) t t)
  842. (goto-char (point-max))
  843. (call-interactively #'org-fill-paragraph)
  844. (buffer-string))))))
  845. (ert-deftest test-org/fill-region ()
  846. "Test `fill-region' behaviour."
  847. ;; fill-region should fill every item of a list
  848. (should
  849. (equal "\n- 2345678\n 9\n- 2345678\n 9"
  850. (org-test-with-temp-text "\n- 2345678 9\n- 2345678 9"
  851. (let ((fill-column 10))
  852. (transient-mark-mode 1)
  853. (push-mark (point-min) t t)
  854. (goto-char (point-max))
  855. (call-interactively #'fill-region)
  856. (buffer-string)))))
  857. (should
  858. (equal "\n- 1 2\n- 1 2"
  859. (org-test-with-temp-text "\n- 1\n 2\n- 1\n 2"
  860. (let ((fill-column 10))
  861. (transient-mark-mode 1)
  862. (push-mark (point-min) t t)
  863. (goto-char (point-max))
  864. (call-interactively #'fill-region)
  865. (buffer-string))))) )
  866. (ert-deftest test-org/auto-fill-function ()
  867. "Test auto-filling features."
  868. ;; Auto fill paragraph.
  869. (should
  870. (equal "12345\n7890"
  871. (org-test-with-temp-text "12345 7890"
  872. (let ((fill-column 5))
  873. (end-of-line)
  874. (org-auto-fill-function)
  875. (buffer-string)))))
  876. ;; Auto fill first paragraph in an item.
  877. (should
  878. (equal "- 12345\n 7890"
  879. (org-test-with-temp-text "- 12345 7890"
  880. (let ((fill-column 7))
  881. (end-of-line)
  882. (org-auto-fill-function)
  883. (buffer-string)))))
  884. ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
  885. (should
  886. (equal "> 12345\n 7890"
  887. (org-test-with-temp-text "> 12345 7890"
  888. (let ((fill-column 10)
  889. (adaptive-fill-regexp "[ \t]*>+[ \t]*")
  890. (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
  891. (end-of-line)
  892. (org-auto-fill-function)
  893. (buffer-string)))))
  894. (should
  895. (equal "> 12345\n> 12345\n> 7890"
  896. (org-test-with-temp-text "> 12345\n> 12345 7890"
  897. (let ((fill-column 10)
  898. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  899. (goto-char (point-max))
  900. (org-auto-fill-function)
  901. (buffer-string)))))
  902. (should-not
  903. (equal " 12345\n *12345\n *12345"
  904. (org-test-with-temp-text " 12345\n *12345 12345"
  905. (let ((fill-column 10)
  906. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  907. (goto-char (point-max))
  908. (org-auto-fill-function)
  909. (buffer-string)))))
  910. ;; Auto fill comments.
  911. (should
  912. (equal " # 12345\n # 7890"
  913. (org-test-with-temp-text " # 12345 7890"
  914. (let ((fill-column 10))
  915. (end-of-line)
  916. (org-auto-fill-function)
  917. (buffer-string)))))
  918. ;; A hash within a line isn't a comment.
  919. (should-not
  920. (equal "12345 # 7890\n# 1"
  921. (org-test-with-temp-text "12345 # 7890 1"
  922. (let ((fill-column 12))
  923. (end-of-line)
  924. (org-auto-fill-function)
  925. (buffer-string)))))
  926. ;; Correctly interpret empty prefix.
  927. (should-not
  928. (equal "# a\n# b\nRegular\n# paragraph"
  929. (org-test-with-temp-text "# a\n# b\nRegular paragraph"
  930. (let ((fill-column 12))
  931. (end-of-line 3)
  932. (org-auto-fill-function)
  933. (buffer-string)))))
  934. ;; Comment block: auto fill contents.
  935. (should
  936. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  937. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  938. (let ((fill-column 5))
  939. (forward-line)
  940. (end-of-line)
  941. (org-auto-fill-function)
  942. (buffer-string)))))
  943. (should
  944. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  945. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  946. (let ((fill-column 5))
  947. (forward-line)
  948. (end-of-line)
  949. (org-auto-fill-function)
  950. (buffer-string)))))
  951. ;; Do not fill if a new item could be created.
  952. (should-not
  953. (equal "12345\n- 90"
  954. (org-test-with-temp-text "12345 - 90"
  955. (let ((fill-column 5))
  956. (end-of-line)
  957. (org-auto-fill-function)
  958. (buffer-string)))))
  959. ;; Do not fill if a line break could be introduced.
  960. (should-not
  961. (equal "123\\\\\n7890"
  962. (org-test-with-temp-text "123\\\\ 7890"
  963. (let ((fill-column 6))
  964. (end-of-line)
  965. (org-auto-fill-function)
  966. (buffer-string)))))
  967. ;; Do not fill affiliated keywords.
  968. (should-not
  969. (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
  970. (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
  971. (let ((fill-column 20))
  972. (end-of-line)
  973. (org-auto-fill-function)
  974. (buffer-string))))))
  975. ;;; Indentation
  976. (ert-deftest test-org/indent-line ()
  977. "Test `org-indent-line' specifications."
  978. ;; Do not indent diary sexps, footnote definitions or headlines.
  979. (should
  980. (zerop
  981. (org-test-with-temp-text "%%(org-calendar-holiday)"
  982. (org-indent-line)
  983. (org-get-indentation))))
  984. (should
  985. (zerop
  986. (org-test-with-temp-text "[fn:1] fn"
  987. (let ((org-adapt-indentation t)) (org-indent-line))
  988. (org-get-indentation))))
  989. (should
  990. (zerop
  991. (org-test-with-temp-text "* H"
  992. (org-indent-line)
  993. (org-get-indentation))))
  994. ;; Do not indent before first headline.
  995. (should
  996. (zerop
  997. (org-test-with-temp-text ""
  998. (org-indent-line)
  999. (org-get-indentation))))
  1000. ;; Indent according to headline level otherwise, unless
  1001. ;; `org-adapt-indentation' is nil.
  1002. (should
  1003. (= 2
  1004. (org-test-with-temp-text "* H\n<point>A"
  1005. (let ((org-adapt-indentation t)) (org-indent-line))
  1006. (org-get-indentation))))
  1007. (should
  1008. (= 2
  1009. (org-test-with-temp-text "* H\n<point>\nA"
  1010. (let ((org-adapt-indentation t)) (org-indent-line))
  1011. (org-get-indentation))))
  1012. (should
  1013. (zerop
  1014. (org-test-with-temp-text "* H\n<point>A"
  1015. (let ((org-adapt-indentation nil)) (org-indent-line))
  1016. (org-get-indentation))))
  1017. ;; Indenting preserves point position.
  1018. (should
  1019. (org-test-with-temp-text "* H\nA<point>B"
  1020. (let ((org-adapt-indentation t)) (org-indent-line))
  1021. (looking-at "B")))
  1022. ;; Do not change indentation at an item or a LaTeX environment.
  1023. (should
  1024. (= 1
  1025. (org-test-with-temp-text "* H\n<point> - A"
  1026. (let ((org-adapt-indentation t)) (org-indent-line))
  1027. (org-get-indentation))))
  1028. (should
  1029. (= 1
  1030. (org-test-with-temp-text
  1031. "\\begin{equation}\n <point>1+1=2\n\\end{equation}"
  1032. (org-indent-line)
  1033. (org-get-indentation))))
  1034. ;; On blank lines at the end of a list, indent like last element
  1035. ;; within it if the line is still in the list. If the last element
  1036. ;; is an item, indent like its contents. Otherwise, indent like the
  1037. ;; whole list.
  1038. (should
  1039. (= 4
  1040. (org-test-with-temp-text "* H\n- A\n - AA\n<point>"
  1041. (let ((org-adapt-indentation t)) (org-indent-line))
  1042. (org-get-indentation))))
  1043. (should
  1044. (= 4
  1045. (org-test-with-temp-text "* H\n- A\n -\n\n<point>"
  1046. (let ((org-adapt-indentation t)) (org-indent-line))
  1047. (org-get-indentation))))
  1048. (should
  1049. (zerop
  1050. (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n<point>"
  1051. (let ((org-adapt-indentation t)) (org-indent-line))
  1052. (org-get-indentation))))
  1053. (should
  1054. (= 4
  1055. (org-test-with-temp-text "* H\n- A\n - \n<point>"
  1056. (let ((org-adapt-indentation t)) (org-indent-line))
  1057. (org-get-indentation))))
  1058. (should
  1059. (= 4
  1060. (org-test-with-temp-text
  1061. "* H\n - \n #+BEGIN_SRC emacs-lisp\n t\n #+END_SRC\n<point>"
  1062. (let ((org-adapt-indentation t)) (org-indent-line))
  1063. (org-get-indentation))))
  1064. (should
  1065. (= 2
  1066. (org-test-with-temp-text "- A\n B\n\n<point>"
  1067. (let ((org-adapt-indentation nil)) (org-indent-line))
  1068. (org-get-indentation))))
  1069. (should
  1070. (= 2
  1071. (org-test-with-temp-text
  1072. "- A\n \begin{cases} 1 + 1\n \end{cases}\n\n<point>"
  1073. (let ((org-adapt-indentation nil)) (org-indent-line))
  1074. (org-get-indentation))))
  1075. ;; Likewise, on a blank line at the end of a footnote definition,
  1076. ;; indent at column 0 if line belongs to the definition. Otherwise,
  1077. ;; indent like the definition itself.
  1078. (should
  1079. (zerop
  1080. (org-test-with-temp-text "* H\n[fn:1] Definition\n<point>"
  1081. (let ((org-adapt-indentation t)) (org-indent-line))
  1082. (org-get-indentation))))
  1083. (should
  1084. (zerop
  1085. (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n<point>"
  1086. (let ((org-adapt-indentation t)) (org-indent-line))
  1087. (org-get-indentation))))
  1088. ;; After the end of the contents of a greater element, indent like
  1089. ;; the beginning of the element.
  1090. (should
  1091. (= 1
  1092. (org-test-with-temp-text
  1093. " #+BEGIN_CENTER\n Contents\n<point>#+END_CENTER"
  1094. (org-indent-line)
  1095. (org-get-indentation))))
  1096. ;; On blank lines after a paragraph, indent like its last non-empty
  1097. ;; line.
  1098. (should
  1099. (= 1
  1100. (org-test-with-temp-text " Paragraph\n\n<point>"
  1101. (org-indent-line)
  1102. (org-get-indentation))))
  1103. ;; At the first line of an element, indent like previous element's
  1104. ;; first line, ignoring footnotes definitions and inline tasks, or
  1105. ;; according to parent.
  1106. (let ((org-adapt-indentation t))
  1107. (should
  1108. (= 2
  1109. (org-test-with-temp-text "A\n\n B\n\nC<point>"
  1110. (org-indent-line)
  1111. (org-get-indentation))))
  1112. (should
  1113. (= 1
  1114. (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC<point>"
  1115. (org-indent-line)
  1116. (org-get-indentation))))
  1117. (should
  1118. (= 1
  1119. (org-test-with-temp-text
  1120. " #+BEGIN_CENTER\n<point> Contents\n#+END_CENTER"
  1121. (org-indent-line)
  1122. (org-get-indentation)))))
  1123. ;; Within code part of a source block, use language major mode if
  1124. ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
  1125. ;; according to line above.
  1126. (should
  1127. (= 6
  1128. (org-test-with-temp-text
  1129. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  1130. (let ((org-src-tab-acts-natively t)
  1131. (org-edit-src-content-indentation 0))
  1132. (org-indent-line))
  1133. (org-get-indentation))))
  1134. (should
  1135. (= 1
  1136. (org-test-with-temp-text
  1137. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  1138. (let ((org-src-tab-acts-natively nil)
  1139. (org-edit-src-content-indentation 0))
  1140. (org-indent-line))
  1141. (org-get-indentation))))
  1142. ;; Otherwise, indent like the first non-blank line above.
  1143. (should
  1144. (zerop
  1145. (org-test-with-temp-text
  1146. "#+BEGIN_CENTER\nline1\n\n<point> line2\n#+END_CENTER"
  1147. (org-indent-line)
  1148. (org-get-indentation))))
  1149. ;; Align node properties according to `org-property-format'. Handle
  1150. ;; nicely empty values.
  1151. (should
  1152. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1153. (org-test-with-temp-text
  1154. "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
  1155. (let ((org-property-format "%-10s %s")) (org-indent-line))
  1156. (buffer-string))))
  1157. (should
  1158. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1159. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
  1160. (let ((org-property-format "%-10s %s")) (org-indent-line))
  1161. (buffer-string)))))
  1162. (ert-deftest test-org/indent-region ()
  1163. "Test `org-indent-region' specifications."
  1164. ;; Indent paragraph.
  1165. (let ((org-adapt-indentation t))
  1166. (should
  1167. (equal "A\nB\nC"
  1168. (org-test-with-temp-text " A\nB\n C"
  1169. (org-indent-region (point-min) (point-max))
  1170. (buffer-string)))))
  1171. ;; Indent greater elements along with their contents.
  1172. (should
  1173. (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
  1174. (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
  1175. (org-indent-region (point-min) (point-max))
  1176. (buffer-string))))
  1177. ;; Ignore contents of verse blocks. Only indent block delimiters.
  1178. (should
  1179. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1180. (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1181. (org-indent-region (point-min) (point-max))
  1182. (buffer-string))))
  1183. (let ((org-adapt-indentation t))
  1184. (should
  1185. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1186. (org-test-with-temp-text " #+BEGIN_VERSE\n A\n B\n #+END_VERSE"
  1187. (org-indent-region (point-min) (point-max))
  1188. (buffer-string)))))
  1189. ;; Indent example blocks as a single block, unless indentation
  1190. ;; should be preserved. In this case only indent the block markers.
  1191. (should
  1192. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1193. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1194. (org-indent-region (point-min) (point-max))
  1195. (buffer-string))))
  1196. (let ((org-adapt-indentation t))
  1197. (should
  1198. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1199. (org-test-with-temp-text " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1200. (org-indent-region (point-min) (point-max))
  1201. (buffer-string))))
  1202. (should
  1203. (equal "#+BEGIN_EXAMPLE -i\n A\n B\n#+END_EXAMPLE"
  1204. (org-test-with-temp-text
  1205. " #+BEGIN_EXAMPLE -i\n A\n B\n #+END_EXAMPLE"
  1206. (org-indent-region (point-min) (point-max))
  1207. (buffer-string))))
  1208. (should
  1209. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1210. (org-test-with-temp-text
  1211. " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1212. (let ((org-src-preserve-indentation t))
  1213. (org-indent-region (point-min) (point-max)))
  1214. (buffer-string)))))
  1215. ;; Treat export blocks as a whole.
  1216. (should
  1217. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1218. (org-test-with-temp-text "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1219. (org-indent-region (point-min) (point-max))
  1220. (buffer-string))))
  1221. (let ((org-adapt-indentation t))
  1222. (should
  1223. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1224. (org-test-with-temp-text
  1225. " #+BEGIN_EXPORT latex\n A\n B\n #+END_EXPORT"
  1226. (org-indent-region (point-min) (point-max))
  1227. (buffer-string)))))
  1228. ;; Indent according to mode if `org-src-tab-acts-natively' is
  1229. ;; non-nil. Otherwise, do not indent code at all.
  1230. (should
  1231. (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
  1232. (org-test-with-temp-text
  1233. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1234. (let ((org-src-tab-acts-natively t)
  1235. (org-edit-src-content-indentation 0))
  1236. (org-indent-region (point-min) (point-max)))
  1237. (buffer-string))))
  1238. (should
  1239. (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1240. (org-test-with-temp-text
  1241. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1242. (let ((org-src-tab-acts-natively nil)
  1243. (org-edit-src-content-indentation 0))
  1244. (org-indent-region (point-min) (point-max)))
  1245. (buffer-string))))
  1246. ;; Align node properties according to `org-property-format'. Handle
  1247. ;; nicely empty values.
  1248. (should
  1249. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1250. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
  1251. (let ((org-property-format "%-10s %s")
  1252. (org-adapt-indentation nil))
  1253. (org-indent-region (point) (point-max)))
  1254. (buffer-string))))
  1255. (should
  1256. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1257. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
  1258. (let ((org-property-format "%-10s %s")
  1259. (org-adapt-indentation nil))
  1260. (org-indent-region (point) (point-max)))
  1261. (buffer-string))))
  1262. ;; Indent property drawers according to `org-adapt-indentation'.
  1263. (let ((org-adapt-indentation 'headline-data))
  1264. (should
  1265. (equal "* H\n :PROPERTIES:\n :key:\n :END:"
  1266. (org-test-with-temp-text "* H\n:PROPERTIES:\n:key:\n:END:"
  1267. (org-indent-region (point-min) (point-max))
  1268. (buffer-string)))))
  1269. ;; Indent plain lists.
  1270. (let ((org-adapt-indentation t))
  1271. (should
  1272. (equal "- A\n B\n - C\n\n D"
  1273. (org-test-with-temp-text "- A\n B\n - C\n\n D"
  1274. (org-indent-region (point-min) (point-max))
  1275. (buffer-string))))
  1276. (should
  1277. (equal "- A\n\n- B"
  1278. (org-test-with-temp-text " - A\n\n - B"
  1279. (org-indent-region (point-min) (point-max))
  1280. (buffer-string)))))
  1281. ;; Indent footnote definitions.
  1282. (should
  1283. (equal "[fn:1] Definition\n\nDefinition"
  1284. (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
  1285. (org-indent-region (point-min) (point-max))
  1286. (buffer-string))))
  1287. ;; Special case: Start indenting on a blank line.
  1288. (should
  1289. (equal "\nParagraph"
  1290. (org-test-with-temp-text "\n Paragraph"
  1291. (org-indent-region (point-min) (point-max))
  1292. (buffer-string)))))
  1293. ;;; Editing
  1294. (ert-deftest test-org/delete-indentation ()
  1295. "Test `org-delete-indentation' specifications."
  1296. ;; Regular test.
  1297. (should (equal "foo bar"
  1298. (org-test-with-temp-text
  1299. "foo \n bar<point>"
  1300. (org-delete-indentation)
  1301. (buffer-string))))
  1302. ;; With optional argument.
  1303. (should (equal "foo bar"
  1304. (org-test-with-temp-text
  1305. "foo<point> \n bar"
  1306. (org-delete-indentation t)
  1307. (buffer-string))))
  1308. ;; At headline text should be appended to the headline text.
  1309. (should
  1310. (equal"* foo bar :tag:"
  1311. (let (org-auto-align-tags)
  1312. (org-test-with-temp-text
  1313. "* foo :tag:\n bar<point>"
  1314. (org-delete-indentation)
  1315. (buffer-string)))))
  1316. (should
  1317. (equal "* foo bar :tag:"
  1318. (let (org-auto-align-tags)
  1319. (org-test-with-temp-text
  1320. "* foo <point>:tag:\n bar"
  1321. (org-delete-indentation t)
  1322. (buffer-string))))))
  1323. (ert-deftest test-org/return ()
  1324. "Test `org-return' specifications."
  1325. ;; Regular test.
  1326. (should
  1327. (equal "Para\ngraph"
  1328. (org-test-with-temp-text "Para<point>graph"
  1329. (org-return)
  1330. (buffer-string))))
  1331. ;; With optional argument, indent line.
  1332. (should
  1333. (equal " Para\n graph"
  1334. (org-test-with-temp-text " Para<point>graph"
  1335. (org-return t)
  1336. (buffer-string))))
  1337. ;; On a table, call `org-table-next-row'.
  1338. (should
  1339. (org-test-with-temp-text "| <point>a |\n| b |"
  1340. (org-return)
  1341. (looking-at-p "b")))
  1342. ;; Open link or timestamp under point when `org-return-follows-link'
  1343. ;; is non-nil.
  1344. (should
  1345. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1346. (let ((org-return-follows-link t)
  1347. (org-link-search-must-match-exact-headline nil))
  1348. (org-return))
  1349. (looking-at-p "<<target>>")))
  1350. (should-not
  1351. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1352. (let ((org-return-follows-link nil)) (org-return))
  1353. (looking-at-p "<<target>>")))
  1354. (should
  1355. (org-test-with-temp-text "* [[b][a<point>]]\n* b"
  1356. (let ((org-return-follows-link t)) (org-return))
  1357. (looking-at-p "* b")))
  1358. (should
  1359. (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
  1360. (let ((org-return-follows-link t)
  1361. (org-link-search-must-match-exact-headline nil))
  1362. (org-return))
  1363. (looking-at-p "<<target>>")))
  1364. (should-not
  1365. (org-test-with-temp-text "Link [[target]]<point> <<target>>"
  1366. (let ((org-return-follows-link t)
  1367. (org-link-search-must-match-exact-headline nil))
  1368. (org-return))
  1369. (looking-at-p "<<target>>")))
  1370. ;; When `org-return-follows-link' is non-nil, tolerate links and
  1371. ;; timestamps in comments, node properties, etc.
  1372. (should
  1373. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1374. (let ((org-return-follows-link t)
  1375. (org-link-search-must-match-exact-headline nil))
  1376. (org-return))
  1377. (looking-at-p "<<target>>")))
  1378. (should-not
  1379. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1380. (let ((org-return-follows-link nil)) (org-return))
  1381. (looking-at-p "<<target>>")))
  1382. (should-not
  1383. (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
  1384. (let ((org-return-follows-link t)
  1385. (org-link-search-must-match-exact-headline nil))
  1386. (org-return))
  1387. (looking-at-p "<<target>>")))
  1388. ;; Non-nil `org-return-follows-link' ignores read-only state of
  1389. ;; a buffer.
  1390. (should
  1391. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1392. (let ((org-return-follows-link t)
  1393. (org-link-search-must-match-exact-headline nil))
  1394. (setq buffer-read-only t)
  1395. (call-interactively #'org-return))
  1396. (looking-at-p "<<target>>")))
  1397. ;; `org-return-follows-link' handle multi-line lines.
  1398. (should
  1399. (org-test-with-temp-text
  1400. "[[target][This is a very\n long description<point>]]\n <<target>>"
  1401. (let ((org-return-follows-link t)
  1402. (org-link-search-must-match-exact-headline nil))
  1403. (org-return))
  1404. (looking-at-p "<<target>>")))
  1405. (should-not
  1406. (org-test-with-temp-text
  1407. "[[target][This is a very\n long description]]<point>\n <<target>>"
  1408. (let ((org-return-follows-link t)
  1409. (org-link-search-must-match-exact-headline nil))
  1410. (org-return))
  1411. (looking-at-p "<<target>>")))
  1412. ;; However, do not open link when point is in a table.
  1413. (should
  1414. (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
  1415. (let ((org-return-follows-link t)) (org-return))
  1416. (looking-at-p "between")))
  1417. ;; Special case: in a list, when indenting, do not break structure.
  1418. (should
  1419. (equal "- A\n B"
  1420. (org-test-with-temp-text "- A <point>B"
  1421. (org-return t)
  1422. (buffer-string))))
  1423. (should
  1424. (equal "- A\n\n- B"
  1425. (org-test-with-temp-text "- A\n<point>- B"
  1426. (org-return t)
  1427. (buffer-string))))
  1428. ;; On tags part of a headline, add a newline below it instead of
  1429. ;; breaking it.
  1430. (should
  1431. (equal "* H :tag:\n"
  1432. (org-test-with-temp-text "* H :<point>tag:"
  1433. (org-return)
  1434. (buffer-string))))
  1435. ;; Before headline text, add a newline below it instead of breaking
  1436. ;; it.
  1437. (should
  1438. (equal "* TODO H :tag:\n"
  1439. (org-test-with-temp-text "* <point>TODO H :tag:"
  1440. (org-return)
  1441. (buffer-string))))
  1442. (should
  1443. (equal "* TODO [#B] H :tag:\n"
  1444. (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
  1445. (org-return)
  1446. (buffer-string))))
  1447. (should ;TODO are case-sensitive
  1448. (equal "* \nTodo"
  1449. (org-test-with-temp-text "* <point>Todo"
  1450. (org-return)
  1451. (buffer-string))))
  1452. ;; At headline text, break headline text but preserve tags.
  1453. (should
  1454. (equal "* TODO [#B] foo :tag:\nbar"
  1455. (let (org-auto-align-tags)
  1456. (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
  1457. (org-return)
  1458. (buffer-string)))))
  1459. ;; At bol of headline insert newline.
  1460. (should
  1461. (equal "\n* h"
  1462. (org-test-with-temp-text "<point>* h"
  1463. (org-return)
  1464. (buffer-string))))
  1465. ;; Refuse to leave invalid headline in buffer.
  1466. (should
  1467. (equal "* h\n"
  1468. (org-test-with-temp-text "*<point> h"
  1469. (org-return)
  1470. (buffer-string))))
  1471. ;; Before first column or after last one in a table, split the
  1472. ;; table.
  1473. (should
  1474. (equal "| a |\n\n| b |"
  1475. (org-test-with-temp-text "| a |\n<point>| b |"
  1476. (org-return)
  1477. (buffer-string))))
  1478. (should
  1479. (equal "| a |\n\n| b |"
  1480. (org-test-with-temp-text "| a |<point>\n| b |"
  1481. (org-return)
  1482. (buffer-string))))
  1483. ;; Do not auto-fill on hitting <RET> inside a property drawer.
  1484. (should
  1485. (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:"
  1486. (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:"
  1487. (setq-local fill-column 10)
  1488. (auto-fill-mode 1)
  1489. (org-return)
  1490. (buffer-string)))))
  1491. (ert-deftest test-org/with-electric-indent ()
  1492. "Test RET and C-j specifications with `electric-indent-mode' on."
  1493. ;; Call commands interactively, since this is how `newline' knows it
  1494. ;; must run `post-self-insert-hook'.
  1495. ;;
  1496. ;; RET, like `newline', should indent.
  1497. (should
  1498. (equal " Para\n graph"
  1499. (org-test-with-temp-text " Para<point>graph"
  1500. (electric-indent-local-mode 1)
  1501. (call-interactively 'org-return)
  1502. (buffer-string))))
  1503. (should
  1504. (equal "- item1\n item2"
  1505. (org-test-with-temp-text "- item1<point>item2"
  1506. (electric-indent-local-mode 1)
  1507. (call-interactively 'org-return)
  1508. (buffer-string))))
  1509. ;; TODO: test more values of `org-adapt-indentation'.
  1510. (let ((org-adapt-indentation t))
  1511. (should
  1512. (equal "* heading\n body"
  1513. (org-test-with-temp-text "* heading<point>body"
  1514. (electric-indent-local-mode 1)
  1515. (call-interactively 'org-return)
  1516. (buffer-string)))))
  1517. ;; C-j, like `electric-newline-and-maybe-indent', should not indent.
  1518. (should
  1519. (equal " Para\ngraph"
  1520. (org-test-with-temp-text " Para<point>graph"
  1521. (electric-indent-local-mode 1)
  1522. (call-interactively 'org-return-and-maybe-indent)
  1523. (buffer-string))))
  1524. (should
  1525. (equal "- item1\nitem2"
  1526. (org-test-with-temp-text "- item1<point>item2"
  1527. (electric-indent-local-mode 1)
  1528. (call-interactively 'org-return-and-maybe-indent)
  1529. (buffer-string))))
  1530. ;; TODO: test more values of `org-adapt-indentation'.
  1531. (let ((org-adapt-indentation t))
  1532. (should
  1533. (equal "* heading\nbody"
  1534. (org-test-with-temp-text "* heading<point>body"
  1535. (electric-indent-local-mode 1)
  1536. (call-interactively 'org-return-and-maybe-indent)
  1537. (buffer-string))))))
  1538. (ert-deftest test-org/without-electric-indent ()
  1539. "Test RET and C-j specifications with `electric-indent-mode' off."
  1540. ;; Call commands interactively, since this is how `newline' knows it
  1541. ;; must run `post-self-insert-hook'.
  1542. ;;
  1543. ;; RET, like `newline', should not indent.
  1544. (should
  1545. (equal " Para\ngraph"
  1546. (org-test-with-temp-text " Para<point>graph"
  1547. (electric-indent-local-mode 0)
  1548. (call-interactively 'org-return)
  1549. (buffer-string))))
  1550. (should
  1551. (equal "- item1\nitem2"
  1552. (org-test-with-temp-text "- item1<point>item2"
  1553. (electric-indent-local-mode 0)
  1554. (call-interactively 'org-return)
  1555. (buffer-string))))
  1556. (should
  1557. (equal "* heading\nbody"
  1558. (org-test-with-temp-text "* heading<point>body"
  1559. (electric-indent-local-mode 0)
  1560. (call-interactively 'org-return)
  1561. (buffer-string))))
  1562. ;; C-j, like `electric-newline-and-maybe-indent', should indent.
  1563. (should
  1564. (equal " Para\n graph"
  1565. (org-test-with-temp-text " Para<point>graph"
  1566. (electric-indent-local-mode 0)
  1567. (call-interactively 'org-return-and-maybe-indent)
  1568. (buffer-string))))
  1569. (should
  1570. (equal "- item1\n item2"
  1571. (org-test-with-temp-text "- item1<point>item2"
  1572. (electric-indent-local-mode 0)
  1573. (call-interactively 'org-return-and-maybe-indent)
  1574. (buffer-string))))
  1575. ;; TODO: test more values of `org-adapt-indentation'.
  1576. (let ((org-adapt-indentation t))
  1577. (should
  1578. (equal "* heading\n body"
  1579. (org-test-with-temp-text "* heading<point>body"
  1580. (electric-indent-local-mode 0)
  1581. (call-interactively 'org-return-and-maybe-indent)
  1582. (buffer-string))))))
  1583. (ert-deftest test-org/meta-return ()
  1584. "Test M-RET (`org-meta-return') specifications."
  1585. ;; In a table field insert a row above.
  1586. (should
  1587. (org-test-with-temp-text "| a |"
  1588. (forward-char)
  1589. (org-meta-return)
  1590. (forward-line -1)
  1591. (looking-at "| |$")))
  1592. ;; In a paragraph change current line into a header.
  1593. (should
  1594. (org-test-with-temp-text "a"
  1595. (org-meta-return)
  1596. (beginning-of-line)
  1597. (looking-at "\* a$")))
  1598. ;; In an item insert an item, in this case above.
  1599. (should
  1600. (org-test-with-temp-text "- a"
  1601. (org-meta-return)
  1602. (beginning-of-line)
  1603. (looking-at "- $")))
  1604. ;; In a drawer and item insert an item, in this case above.
  1605. (should
  1606. (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
  1607. (forward-line)
  1608. (org-fold-reveal)
  1609. (org-meta-return)
  1610. (beginning-of-line)
  1611. (looking-at "- $"))))
  1612. (ert-deftest test-org/insert-heading ()
  1613. "Test `org-insert-heading' specifications."
  1614. ;; In an empty buffer, insert a new headline.
  1615. (should
  1616. (equal "* "
  1617. (org-test-with-temp-text ""
  1618. (org-insert-heading)
  1619. (buffer-string))))
  1620. ;; At the beginning of a line, turn it into a headline.
  1621. (should
  1622. (equal "* P"
  1623. (org-test-with-temp-text "<point>P"
  1624. (org-insert-heading)
  1625. (buffer-string))))
  1626. ;; In the middle of a line, split the line if allowed, otherwise,
  1627. ;; insert the headline at its end.
  1628. (should
  1629. (equal "Para\n* graph"
  1630. (org-test-with-temp-text "Para<point>graph"
  1631. (let ((org-M-RET-may-split-line '((default . t))))
  1632. (org-insert-heading))
  1633. (buffer-string))))
  1634. (should
  1635. (equal "Paragraph\n* "
  1636. (org-test-with-temp-text "Para<point>graph"
  1637. (let ((org-M-RET-may-split-line '((default . nil))))
  1638. (org-insert-heading))
  1639. (buffer-string))))
  1640. ;; At the beginning of a headline, create one above.
  1641. (should
  1642. (equal "* \n* H"
  1643. (org-test-with-temp-text "* H"
  1644. (org-insert-heading)
  1645. (buffer-string))))
  1646. ;; In the middle of a headline, split it if allowed.
  1647. (should
  1648. (equal "* H\n* 1"
  1649. (org-test-with-temp-text "* H<point>1"
  1650. (let ((org-M-RET-may-split-line '((headline . t))))
  1651. (org-insert-heading))
  1652. (buffer-string))))
  1653. (should
  1654. (equal "* H1\n* "
  1655. (org-test-with-temp-text "* H<point>1"
  1656. (let ((org-M-RET-may-split-line '((headline . nil))))
  1657. (org-insert-heading))
  1658. (buffer-string))))
  1659. ;; However, splitting cannot happen on TODO keywords, priorities or
  1660. ;; tags.
  1661. (should
  1662. (equal "* TODO H1\n* "
  1663. (org-test-with-temp-text "* TO<point>DO H1"
  1664. (let ((org-M-RET-may-split-line '((headline . t))))
  1665. (org-insert-heading))
  1666. (buffer-string))))
  1667. (should
  1668. (equal "* [#A] H1\n* "
  1669. (org-test-with-temp-text "* [#<point>A] H1"
  1670. (let ((org-M-RET-may-split-line '((headline . t))))
  1671. (org-insert-heading))
  1672. (buffer-string))))
  1673. (should
  1674. (equal "* H1 :tag:\n* "
  1675. (org-test-with-temp-text "* H1 :ta<point>g:"
  1676. (let ((org-M-RET-may-split-line '((headline . t))))
  1677. (org-insert-heading))
  1678. (buffer-string))))
  1679. ;; New headline level depends on the level of the headline above.
  1680. (should
  1681. (equal "** H\n** P"
  1682. (org-test-with-temp-text "** H\n<point>P"
  1683. (org-insert-heading)
  1684. (buffer-string))))
  1685. (should
  1686. (equal "** H\nPara\n** graph"
  1687. (org-test-with-temp-text "** H\nPara<point>graph"
  1688. (let ((org-M-RET-may-split-line '((default . t))))
  1689. (org-insert-heading))
  1690. (buffer-string))))
  1691. (should
  1692. (equal "** \n** H"
  1693. (org-test-with-temp-text "** H"
  1694. (org-insert-heading)
  1695. (buffer-string))))
  1696. ;; When called with one universal argument, insert a new headline at
  1697. ;; the end of the current subtree, independently on the position of
  1698. ;; point.
  1699. (should
  1700. (equal
  1701. "* "
  1702. (org-test-with-temp-text ""
  1703. (let ((org-insert-heading-respect-content nil))
  1704. (org-insert-heading '(4)))
  1705. (buffer-string))))
  1706. (should
  1707. (equal
  1708. "entry
  1709. * "
  1710. (org-test-with-temp-text "entry"
  1711. (let ((org-insert-heading-respect-content nil))
  1712. (org-insert-heading '(4)))
  1713. (buffer-string))))
  1714. (should
  1715. (equal
  1716. "* H1\n** H2\n* "
  1717. (org-test-with-temp-text "* H1\n** H2"
  1718. (let ((org-insert-heading-respect-content nil))
  1719. (org-insert-heading '(4)))
  1720. (buffer-string))))
  1721. (should
  1722. (equal
  1723. "* H1\n** H2\n* "
  1724. (org-test-with-temp-text "* H<point>1\n** H2"
  1725. (let ((org-insert-heading-respect-content nil))
  1726. (org-insert-heading '(4)))
  1727. (buffer-string))))
  1728. ;; When called with two universal arguments, insert a new headline
  1729. ;; at the end of the grandparent subtree.
  1730. (should
  1731. (equal "* H1\n** H3\n- item\n** H2\n** "
  1732. (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
  1733. (let ((org-insert-heading-respect-content nil))
  1734. (org-insert-heading '(16)))
  1735. (buffer-string))))
  1736. ;; When optional TOP-LEVEL argument is non-nil, always insert
  1737. ;; a level 1 heading.
  1738. (should
  1739. (equal "* H1\n** H2\n* "
  1740. (org-test-with-temp-text "* H1\n** H2<point>"
  1741. (org-insert-heading nil nil t)
  1742. (buffer-string))))
  1743. (should
  1744. (equal "* H1\n- item\n* "
  1745. (org-test-with-temp-text "* H1\n- item<point>"
  1746. (org-insert-heading nil nil t)
  1747. (buffer-string))))
  1748. ;; Obey `org-blank-before-new-entry'.
  1749. (should
  1750. (equal "* H1\n\n* "
  1751. (org-test-with-temp-text "* H1<point>"
  1752. (let ((org-blank-before-new-entry '((heading . t))))
  1753. (org-insert-heading))
  1754. (buffer-string))))
  1755. (should
  1756. (equal "* H1\n* "
  1757. (org-test-with-temp-text "* H1<point>"
  1758. (let ((org-blank-before-new-entry '((heading . nil))))
  1759. (org-insert-heading))
  1760. (buffer-string))))
  1761. (should
  1762. (equal "* H1\n* H2\n* "
  1763. (org-test-with-temp-text "* H1\n* H2<point>"
  1764. (let ((org-blank-before-new-entry '((heading . auto))))
  1765. (org-insert-heading))
  1766. (buffer-string))))
  1767. (should
  1768. (equal "* H1\n\n* H2\n\n* "
  1769. (org-test-with-temp-text "* H1\n\n* H2<point>"
  1770. (let ((org-blank-before-new-entry '((heading . auto))))
  1771. (org-insert-heading))
  1772. (buffer-string))))
  1773. ;; Corner case: correctly insert a headline after an empty one.
  1774. (should
  1775. (equal "* \n* "
  1776. (org-test-with-temp-text "* <point>"
  1777. (org-insert-heading)
  1778. (buffer-string))))
  1779. (should
  1780. (org-test-with-temp-text "* <point>\n"
  1781. (org-insert-heading)
  1782. (looking-at-p "\n\\'")))
  1783. ;; Do not insert spurious headlines when inserting a new headline.
  1784. (should
  1785. (equal "* H1\n* H2\n* \n"
  1786. (org-test-with-temp-text "* H1\n* H2<point>\n"
  1787. (org-insert-heading)
  1788. (buffer-string))))
  1789. ;; Preserve visibility at beginning of line. In particular, when
  1790. ;; removing spurious blank lines, do not visually merge heading with
  1791. ;; the line visible above.
  1792. (should-not
  1793. (org-test-with-temp-text "* H1<point>\nContents\n\n* H2\n"
  1794. (org-overview)
  1795. (let ((org-blank-before-new-entry '((heading . nil))))
  1796. (org-insert-heading '(4)))
  1797. (invisible-p (line-end-position 0))))
  1798. ;; Properly handle empty lines when forcing a headline below current
  1799. ;; one.
  1800. (should
  1801. (equal "* H1\n\n* H\n\n* "
  1802. (org-test-with-temp-text "* H1\n\n* H<point>"
  1803. (let ((org-blank-before-new-entry '((heading . t))))
  1804. (org-insert-heading '(4))
  1805. (buffer-string))))))
  1806. (ert-deftest test-org/insert-todo-heading-respect-content ()
  1807. "Test `org-insert-todo-heading-respect-content' specifications."
  1808. ;; Create a TODO heading.
  1809. (should
  1810. (org-test-with-temp-text "* H1\n Body"
  1811. (org-insert-todo-heading-respect-content)
  1812. (nth 2 (org-heading-components))))
  1813. ;; Add headline at the end of the first subtree
  1814. (should
  1815. (equal
  1816. "* TODO "
  1817. (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
  1818. (org-insert-todo-heading-respect-content)
  1819. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1820. ;; In a list, do not create a new item.
  1821. (should
  1822. (equal
  1823. "* TODO "
  1824. (org-test-with-temp-text "* H\n- an item\n- another one"
  1825. (search-forward "an ")
  1826. (org-insert-todo-heading-respect-content)
  1827. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1828. ;; Use the same TODO keyword as current heading.
  1829. (should
  1830. (equal
  1831. "* TODO \n"
  1832. (org-test-with-temp-text "* TODO\n** WAITING\n"
  1833. (org-insert-todo-heading-respect-content)
  1834. (buffer-substring-no-properties (line-beginning-position) (point-max))))))
  1835. (ert-deftest test-org/clone-with-time-shift ()
  1836. "Test `org-clone-subtree-with-time-shift'."
  1837. ;; Raise an error before first heading.
  1838. (should-error
  1839. (org-test-with-temp-text ""
  1840. (org-clone-subtree-with-time-shift 1)))
  1841. ;; Raise an error on invalid number of clones.
  1842. (should-error
  1843. (org-test-with-temp-text "* Clone me"
  1844. (org-clone-subtree-with-time-shift -1)))
  1845. ;; Clone non-repeating once.
  1846. (should
  1847. (equal "\
  1848. * H1\n<2015-06-21>
  1849. * H1\n<2015-06-23>
  1850. "
  1851. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1852. (org-clone-subtree-with-time-shift 1 "+2d")
  1853. (replace-regexp-in-string
  1854. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1855. nil nil 1))))
  1856. ;; Clone repeating once.
  1857. (should
  1858. (equal "\
  1859. * H1\n<2015-06-21>
  1860. * H1\n<2015-06-23>
  1861. * H1\n<2015-06-25 +1w>
  1862. "
  1863. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1864. (org-clone-subtree-with-time-shift 1 "+2d")
  1865. (replace-regexp-in-string
  1866. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1867. nil nil 1))))
  1868. ;; Clone repeating once in backward.
  1869. (should
  1870. (equal "\
  1871. * H1\n<2015-06-21>
  1872. * H1\n<2015-06-19>
  1873. * H1\n<2015-06-17 +1w>
  1874. "
  1875. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1876. (org-clone-subtree-with-time-shift 1 "-2d")
  1877. (replace-regexp-in-string
  1878. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1879. nil nil 1))))
  1880. ;; Clone non-repeating zero times.
  1881. (should
  1882. (equal "\
  1883. * H1\n<2015-06-21>
  1884. "
  1885. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1886. (org-clone-subtree-with-time-shift 0 "+2d")
  1887. (replace-regexp-in-string
  1888. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1889. nil nil 1))))
  1890. ;; Clone repeating "zero" times.
  1891. (should
  1892. (equal "\
  1893. * H1\n<2015-06-21>
  1894. * H1\n<2015-06-23 +1w>
  1895. "
  1896. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1897. (org-clone-subtree-with-time-shift 0 "+2d")
  1898. (replace-regexp-in-string
  1899. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1900. nil nil 1))))
  1901. ;; Clone with blank SHIFT argument.
  1902. (should
  1903. (string-prefix-p
  1904. "* H <2012-03-29"
  1905. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1906. (org-clone-subtree-with-time-shift 1 "")
  1907. (buffer-substring-no-properties (line-beginning-position 2)
  1908. (line-end-position 2)))))
  1909. ;; Find time stamps before point. If SHIFT is not specified, ask
  1910. ;; for a time shift.
  1911. (should
  1912. (string-prefix-p
  1913. "* H <2012-03-30"
  1914. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1915. (org-clone-subtree-with-time-shift 1 "+1d")
  1916. (buffer-substring-no-properties (line-beginning-position 2)
  1917. (line-end-position 2)))))
  1918. (should
  1919. (string-prefix-p
  1920. "* H <2014-03-05"
  1921. (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
  1922. (cl-letf (((symbol-function 'read-from-minibuffer)
  1923. (lambda (&rest args) "+1d")))
  1924. (org-clone-subtree-with-time-shift 1))
  1925. (buffer-substring-no-properties (line-beginning-position 2)
  1926. (line-end-position 2)))))
  1927. ;; Hour shift.
  1928. (should
  1929. (equal "\
  1930. * H1\n<2015-06-21 20:00>
  1931. * H1\n<2015-06-21 23:00>
  1932. * H1\n<2015-06-22 02:00>
  1933. "
  1934. (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>"
  1935. (org-clone-subtree-with-time-shift 2 "+3h")
  1936. (replace-regexp-in-string
  1937. "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" ""
  1938. (buffer-substring-no-properties (point-min) (point-max))
  1939. nil nil 1))))
  1940. (should
  1941. (equal "\
  1942. * H1\n<2015-06-21 20:00>
  1943. * H1\n<2015-06-21 18:00>
  1944. "
  1945. (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>"
  1946. (org-clone-subtree-with-time-shift 1 "-2h")
  1947. (replace-regexp-in-string
  1948. "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" ""
  1949. (buffer-substring-no-properties (point-min) (point-max))
  1950. nil nil 1)))))
  1951. ;;; Fixed-Width Areas
  1952. (ert-deftest test-org/toggle-fixed-width ()
  1953. "Test `org-toggle-fixed-width' specifications."
  1954. ;; No region: Toggle on fixed-width marker in paragraphs.
  1955. (should
  1956. (equal ": A"
  1957. (org-test-with-temp-text "A"
  1958. (org-toggle-fixed-width)
  1959. (buffer-string))))
  1960. ;; No region: Toggle off fixed-width markers in fixed-width areas.
  1961. (should
  1962. (equal "A"
  1963. (org-test-with-temp-text ": A"
  1964. (org-toggle-fixed-width)
  1965. (buffer-string))))
  1966. ;; No region: Toggle on marker in blank lines after elements or just
  1967. ;; after a headline.
  1968. (should
  1969. (equal "* H\n: "
  1970. (org-test-with-temp-text "* H\n"
  1971. (forward-line)
  1972. (org-toggle-fixed-width)
  1973. (buffer-string))))
  1974. (should
  1975. (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
  1976. (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
  1977. (goto-char (point-max))
  1978. (org-toggle-fixed-width)
  1979. (buffer-string))))
  1980. ;; No region: Toggle on marker in front of one line elements (e.g.,
  1981. ;; headlines, clocks)
  1982. (should
  1983. (equal ": * Headline"
  1984. (org-test-with-temp-text "* Headline"
  1985. (org-toggle-fixed-width)
  1986. (buffer-string))))
  1987. (should
  1988. (equal ": #+KEYWORD: value"
  1989. (org-test-with-temp-text "#+KEYWORD: value"
  1990. (org-toggle-fixed-width)
  1991. (buffer-string))))
  1992. ;; No region: error in other situations.
  1993. (should-error
  1994. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
  1995. (forward-line)
  1996. (org-toggle-fixed-width)
  1997. (buffer-string)))
  1998. ;; No region: Indentation is preserved.
  1999. (should
  2000. (equal "- A\n : B"
  2001. (org-test-with-temp-text "- A\n B"
  2002. (forward-line)
  2003. (org-toggle-fixed-width)
  2004. (buffer-string))))
  2005. ;; Region: If it contains only fixed-width elements and blank lines,
  2006. ;; toggle off fixed-width markup.
  2007. (should
  2008. (equal "A\n\nB"
  2009. (org-test-with-temp-text ": A\n\n: B"
  2010. (transient-mark-mode 1)
  2011. (push-mark (point) t t)
  2012. (goto-char (point-max))
  2013. (org-toggle-fixed-width)
  2014. (buffer-string))))
  2015. ;; Region: If it contains anything else, toggle on fixed-width but
  2016. ;; not on fixed-width areas.
  2017. (should
  2018. (equal ": A\n: \n: B\n: \n: C"
  2019. (org-test-with-temp-text "A\n\n: B\n\nC"
  2020. (transient-mark-mode 1)
  2021. (push-mark (point) t t)
  2022. (goto-char (point-max))
  2023. (org-toggle-fixed-width)
  2024. (buffer-string))))
  2025. ;; Region: Ignore blank lines at its end, unless it contains only
  2026. ;; such lines.
  2027. (should
  2028. (equal ": A\n\n"
  2029. (org-test-with-temp-text "A\n\n"
  2030. (transient-mark-mode 1)
  2031. (push-mark (point) t t)
  2032. (goto-char (point-max))
  2033. (org-toggle-fixed-width)
  2034. (buffer-string))))
  2035. (should
  2036. (equal ": \n: \n"
  2037. (org-test-with-temp-text "\n\n"
  2038. (transient-mark-mode 1)
  2039. (push-mark (point) t t)
  2040. (goto-char (point-max))
  2041. (org-toggle-fixed-width)
  2042. (buffer-string)))))
  2043. (ert-deftest test-org/kill-line ()
  2044. "Test `org-kill-line' specifications."
  2045. ;; At the beginning of a line, kill whole line.
  2046. (should
  2047. (equal ""
  2048. (org-test-with-temp-text "abc"
  2049. (org-kill-line)
  2050. (buffer-string))))
  2051. ;; In the middle of a line, kill line until its end.
  2052. (should
  2053. (equal "a"
  2054. (org-test-with-temp-text "a<point>bc"
  2055. (org-kill-line)
  2056. (buffer-string))))
  2057. ;; Do not kill newline character.
  2058. (should
  2059. (equal "\n123"
  2060. (org-test-with-temp-text "abc\n123"
  2061. (org-kill-line)
  2062. (buffer-string))))
  2063. (should
  2064. (equal "a\n123"
  2065. (org-test-with-temp-text "a<point>bc\n123"
  2066. (org-kill-line)
  2067. (buffer-string))))
  2068. ;; When `org-special-ctrl-k' is non-nil and point is at a headline,
  2069. ;; kill until tags.
  2070. (should
  2071. (equal "* A :tag:"
  2072. (org-test-with-temp-text "* A<point>B :tag:"
  2073. (let ((org-special-ctrl-k t)
  2074. (org-tags-column 0))
  2075. (org-kill-line))
  2076. (buffer-string))))
  2077. ;; If point is on tags, only kill part left until the end of line.
  2078. (should
  2079. (equal "* A :tag:"
  2080. (org-test-with-temp-text "* A :tag:<point>tag2:"
  2081. (let ((org-special-ctrl-k t)
  2082. (org-tags-column 0))
  2083. (org-kill-line))
  2084. (buffer-string))))
  2085. ;; However, if point is at the beginning of the line, kill whole
  2086. ;; headline.
  2087. (should
  2088. (equal ""
  2089. (org-test-with-temp-text "* AB :tag:"
  2090. (let ((org-special-ctrl-k t)
  2091. (org-tags-column 0))
  2092. (org-kill-line))
  2093. (buffer-string))))
  2094. ;; When `org-ctrl-k-protect-subtree' is non-nil, and point is in
  2095. ;; invisible text, ask before removing it. When set to `error',
  2096. ;; throw an error.
  2097. (should-error
  2098. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  2099. (org-overview)
  2100. (let ((org-special-ctrl-k nil)
  2101. (org-ctrl-k-protect-subtree t))
  2102. (cl-letf (((symbol-function 'y-or-n-p) 'ignore))
  2103. (org-kill-line)))))
  2104. (should-error
  2105. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  2106. (org-overview)
  2107. (let ((org-special-ctrl-k nil)
  2108. (org-ctrl-k-protect-subtree 'error))
  2109. (org-kill-line)))))
  2110. ;;; Headline
  2111. (ert-deftest test-org/get-heading ()
  2112. "Test `org-get-heading' specifications."
  2113. ;; Return current heading, even if point is not on it.
  2114. (should
  2115. (equal "H"
  2116. (org-test-with-temp-text "* H"
  2117. (org-get-heading))))
  2118. (should
  2119. (equal "H"
  2120. (org-test-with-temp-text "* H\nText<point>"
  2121. (org-get-heading))))
  2122. ;; Without any optional argument, return TODO keyword, priority
  2123. ;; cookie, COMMENT keyword and tags.
  2124. (should
  2125. (equal "TODO H"
  2126. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2127. (org-get-heading))))
  2128. (should
  2129. (equal "[#A] H"
  2130. (org-test-with-temp-text "* [#A] H"
  2131. (org-get-heading))))
  2132. (should
  2133. (equal "COMMENT H"
  2134. (org-test-with-temp-text "* COMMENT H"
  2135. (org-get-heading))))
  2136. (should
  2137. (equal "H :tag:"
  2138. (org-test-with-temp-text "* H :tag:"
  2139. (org-get-heading))))
  2140. ;; With NO-TAGS argument, ignore tags.
  2141. (should
  2142. (equal "TODO H"
  2143. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2144. (org-get-heading t))))
  2145. (should
  2146. (equal "H"
  2147. (org-test-with-temp-text "* H :tag:"
  2148. (org-get-heading t))))
  2149. ;; With NO-TODO, ignore TODO keyword.
  2150. (should
  2151. (equal "H"
  2152. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2153. (org-get-heading nil t))))
  2154. (should
  2155. (equal "H :tag:"
  2156. (org-test-with-temp-text "* H :tag:"
  2157. (org-get-heading nil t))))
  2158. ;; TODO keywords are case-sensitive.
  2159. (should
  2160. (equal "Todo H"
  2161. (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
  2162. (org-get-heading nil t))))
  2163. ;; With NO-PRIORITY, ignore priority.
  2164. (should
  2165. (equal "H"
  2166. (org-test-with-temp-text "* [#A] H"
  2167. (org-get-heading nil nil t))))
  2168. (should
  2169. (equal "H"
  2170. (org-test-with-temp-text "* H"
  2171. (org-get-heading nil nil t))))
  2172. (should
  2173. (equal "TODO H"
  2174. (org-test-with-temp-text "* TODO [#A] H"
  2175. (org-get-heading nil nil t))))
  2176. ;; With NO-COMMENT, ignore COMMENT keyword.
  2177. (should
  2178. (equal "H"
  2179. (org-test-with-temp-text "* COMMENT H"
  2180. (org-get-heading nil nil nil t))))
  2181. (should
  2182. (equal "H"
  2183. (org-test-with-temp-text "* H"
  2184. (org-get-heading nil nil nil t))))
  2185. (should
  2186. (equal "TODO [#A] H"
  2187. (org-test-with-temp-text "* TODO [#A] COMMENT H"
  2188. (org-get-heading nil nil nil t))))
  2189. ;; On an empty headline, return value is consistent.
  2190. (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
  2191. (should (equal "" (org-test-with-temp-text "* " (org-get-heading t))))
  2192. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t))))
  2193. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t))))
  2194. (should
  2195. (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t)))))
  2196. (ert-deftest test-org/in-commented-heading-p ()
  2197. "Test `org-in-commented-heading-p' specifications."
  2198. ;; Commented headline.
  2199. (should
  2200. (org-test-with-temp-text "* COMMENT Headline\nBody"
  2201. (goto-char (point-max))
  2202. (org-in-commented-heading-p)))
  2203. ;; Commented ancestor.
  2204. (should
  2205. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  2206. (goto-char (point-max))
  2207. (org-in-commented-heading-p)))
  2208. ;; Comment keyword is case-sensitive.
  2209. (should-not
  2210. (org-test-with-temp-text "* Comment Headline\nBody"
  2211. (goto-char (point-max))
  2212. (org-in-commented-heading-p)))
  2213. ;; Keyword is standalone.
  2214. (should-not
  2215. (org-test-with-temp-text "* COMMENTHeadline\nBody"
  2216. (goto-char (point-max))
  2217. (org-in-commented-heading-p)))
  2218. ;; Optional argument.
  2219. (should-not
  2220. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  2221. (goto-char (point-max))
  2222. (org-in-commented-heading-p t))))
  2223. (ert-deftest test-org/in-archived-heading-p ()
  2224. "Test `org-in-archived-heading-p' specifications."
  2225. ;; Archived headline.
  2226. (should
  2227. (org-test-with-temp-text "* Headline :ARCHIVE:\nBody"
  2228. (goto-char (point-max))
  2229. (org-in-archived-heading-p)))
  2230. ;; Archived ancestor.
  2231. (should
  2232. (org-test-with-temp-text "* Headline :ARCHIVE:\n** Level 2\nBody"
  2233. (goto-char (point-max))
  2234. (org-in-archived-heading-p)))
  2235. ;; Optional argument.
  2236. (should-not
  2237. (org-test-with-temp-text "* Headline :ARCHIVE:\n** Level 2\nBody"
  2238. (goto-char (point-max))
  2239. (org-in-archived-heading-p t)))
  2240. ;; Archive tag containing ARCHIVE as substring
  2241. (should-not
  2242. (org-test-with-temp-text "* Headline :NOARCHIVE:\n** Level 2\nBody"
  2243. (goto-char (point-max))
  2244. (org-in-archived-heading-p))))
  2245. (ert-deftest test-org/entry-blocked-p ()
  2246. ;; Check other dependencies.
  2247. (should
  2248. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  2249. (let ((org-enforce-todo-dependencies t)
  2250. (org-blocker-hook
  2251. '(org-block-todo-from-children-or-siblings-or-parent)))
  2252. (org-entry-blocked-p))))
  2253. (should-not
  2254. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  2255. (let ((org-enforce-todo-dependencies t)
  2256. (org-blocker-hook
  2257. '(org-block-todo-from-children-or-siblings-or-parent)))
  2258. (org-entry-blocked-p))))
  2259. ;; Entry without a TODO keyword or with a DONE keyword cannot be
  2260. ;; blocked.
  2261. (should-not
  2262. (org-test-with-temp-text "* Blocked\n** TODO one"
  2263. (let ((org-enforce-todo-dependencies t)
  2264. (org-blocker-hook
  2265. '(org-block-todo-from-children-or-siblings-or-parent)))
  2266. (org-entry-blocked-p))))
  2267. (should-not
  2268. (org-test-with-temp-text "* DONE Blocked\n** TODO one"
  2269. (let ((org-enforce-todo-dependencies t)
  2270. (org-blocker-hook
  2271. '(org-block-todo-from-children-or-siblings-or-parent)))
  2272. (org-entry-blocked-p))))
  2273. ;; Follow :ORDERED: specifications.
  2274. (should
  2275. (org-test-with-temp-text
  2276. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
  2277. (let ((org-enforce-todo-dependencies t)
  2278. (org-blocker-hook
  2279. '(org-block-todo-from-children-or-siblings-or-parent)))
  2280. (org-entry-blocked-p))))
  2281. (should-not
  2282. (org-test-with-temp-text
  2283. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
  2284. (let ((org-enforce-todo-dependencies t)
  2285. (org-blocker-hook
  2286. '(org-block-todo-from-children-or-siblings-or-parent)))
  2287. (org-entry-blocked-p)))))
  2288. (ert-deftest test-org/get-outline-path ()
  2289. "Test `org-get-outline-path' specifications."
  2290. ;; Top-level headlines have no outline path.
  2291. (should-not
  2292. (org-test-with-temp-text "* H"
  2293. (org-get-outline-path)))
  2294. ;; Otherwise, outline path is the path leading to the headline.
  2295. (should
  2296. (equal '("H")
  2297. (org-test-with-temp-text "* H\n** S<point>"
  2298. (org-get-outline-path))))
  2299. ;; Find path even when point is not on a headline.
  2300. (should
  2301. (equal '("H")
  2302. (org-test-with-temp-text "* H\n** S\nText<point>"
  2303. (org-get-outline-path))))
  2304. ;; TODO keywords, tags and statistics cookies are ignored.
  2305. (should
  2306. (equal '("H")
  2307. (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
  2308. (org-get-outline-path))))
  2309. ;; Links are replaced with their description or their path.
  2310. (should
  2311. (equal '("Org")
  2312. (org-test-with-temp-text
  2313. "* [[https://orgmode.org][Org]]\n** S<point>"
  2314. (org-get-outline-path))))
  2315. (should
  2316. (equal '("https://orgmode.org")
  2317. (org-test-with-temp-text
  2318. "* [[https://orgmode.org]]\n** S<point>"
  2319. (org-get-outline-path))))
  2320. ;; When WITH-SELF is non-nil, include current heading.
  2321. (should
  2322. (equal '("H")
  2323. (org-test-with-temp-text "* H"
  2324. (org-get-outline-path t))))
  2325. (should
  2326. (equal '("H" "S")
  2327. (org-test-with-temp-text "* H\n** S\nText<point>"
  2328. (org-get-outline-path t))))
  2329. ;; Using cache is transparent to the user.
  2330. (should
  2331. (equal '("H")
  2332. (org-test-with-temp-text "* H\n** S<point>"
  2333. (setq org-outline-path-cache nil)
  2334. (org-get-outline-path nil t))))
  2335. ;; Do not corrupt cache when finding outline path in distant part of
  2336. ;; the buffer.
  2337. (should
  2338. (equal '("H2")
  2339. (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
  2340. (setq org-outline-path-cache nil)
  2341. (org-get-outline-path nil t)
  2342. (search-forward "S2")
  2343. (org-get-outline-path nil t))))
  2344. ;; Do not choke on empty headlines.
  2345. (should
  2346. (org-test-with-temp-text "* H\n** <point>"
  2347. (org-get-outline-path)))
  2348. (should
  2349. (org-test-with-temp-text "* \n** H<point>"
  2350. (org-get-outline-path))))
  2351. (ert-deftest test-org/format-outline-path ()
  2352. "Test `org-format-outline-path' specifications."
  2353. (should
  2354. (string= (org-format-outline-path (list "one" "two" "three"))
  2355. "one/two/three"))
  2356. ;; Empty path.
  2357. (should
  2358. (string= (org-format-outline-path '())
  2359. ""))
  2360. (should
  2361. (string= (org-format-outline-path '(nil))
  2362. ""))
  2363. ;; Empty path and prefix.
  2364. (should
  2365. (string= (org-format-outline-path '() nil ">>")
  2366. ">>"))
  2367. ;; Trailing whitespace in headings.
  2368. (should
  2369. (string= (org-format-outline-path (list "one\t" "tw o " "three "))
  2370. "one/tw o/three"))
  2371. ;; Non-default prefix and separators.
  2372. (should
  2373. (string= (org-format-outline-path (list "one" "two" "three") nil ">>" "|")
  2374. ">>|one|two|three"))
  2375. ;; Truncate.
  2376. (should
  2377. (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
  2378. "one/two/.."))
  2379. ;; Give a very narrow width.
  2380. (should
  2381. (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
  2382. "on"))
  2383. ;; Give a prefix that extends beyond the width.
  2384. (should
  2385. (string= (org-format-outline-path (list "one" "two" "three" "four") 10
  2386. ">>>>>>>>>>")
  2387. ">>>>>>>>..")))
  2388. (ert-deftest test-org/org-find-olp ()
  2389. "Test `org-find-olp' specifications."
  2390. (org-test-with-temp-text
  2391. "
  2392. * Headline
  2393. ** COMMENT headline2
  2394. ** TODO headline3
  2395. *** [#A] headline4 :tags:
  2396. ** [#A]headline5
  2397. ** [0%] headline6
  2398. ** headline7 [100%]
  2399. ** headline8 [1/5] :some:more:tags:
  2400. * Test
  2401. "
  2402. (should (org-find-olp '("Headline") t))
  2403. (should-error (org-find-olp '("Headline" "Test") t))
  2404. (should-error (org-find-olp '("Headlinealksjd") t))
  2405. (should (org-find-olp '("Headline" "headline2") t))
  2406. (should (org-find-olp '("Headline" "headline3") t))
  2407. (should (org-find-olp '("Headline" "headline3" "headline4") t))
  2408. (should-error (org-find-olp '("Headline" "headline5") t))
  2409. (should (org-find-olp '("Headline" "headline6") t))
  2410. (should (org-find-olp '("Headline" "headline7") t))
  2411. (should (org-find-olp '("Headline" "headline8") t))))
  2412. (ert-deftest test-org/map-entries ()
  2413. "Test `org-map-entries' specifications."
  2414. ;; Full match.
  2415. (should
  2416. (equal '(1 11)
  2417. (org-test-with-temp-text "* Level 1\n** Level 2"
  2418. (org-map-entries #'point))))
  2419. ;; Level match.
  2420. (should
  2421. (equal '(1)
  2422. (org-test-with-temp-text "* Level 1\n** Level 2"
  2423. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL=1")))))
  2424. (should
  2425. (equal '(11)
  2426. (org-test-with-temp-text "* Level 1\n** Level 2"
  2427. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL>1")))))
  2428. ;; Tag match.
  2429. (should
  2430. (equal '(11)
  2431. (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
  2432. (org-map-entries #'point "yes"))))
  2433. (should
  2434. (equal '(14)
  2435. (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
  2436. (org-map-entries #'point "+yes-a"))))
  2437. (should
  2438. (equal '(11 23)
  2439. (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
  2440. (org-map-entries #'point "{yes?}"))))
  2441. ;; Priority match.
  2442. (should
  2443. (equal '(1)
  2444. (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
  2445. (org-map-entries #'point "PRIORITY=\"A\""))))
  2446. ;; Date match.
  2447. (should
  2448. (equal '(36)
  2449. (org-test-with-temp-text "
  2450. * H1
  2451. SCHEDULED: <2012-03-29 thu.>
  2452. * H2
  2453. SCHEDULED: <2014-03-04 tue.>"
  2454. (org-map-entries #'point "SCHEDULED=\"<2014-03-04 tue.>\""))))
  2455. (should
  2456. (equal '(2)
  2457. (org-test-with-temp-text "
  2458. * H1
  2459. SCHEDULED: <2012-03-29 thu.>
  2460. * H2
  2461. SCHEDULED: <2014-03-04 tue.>"
  2462. (org-map-entries #'point "SCHEDULED<\"<2013-01-01>\""))))
  2463. ;; Regular property match.
  2464. (should
  2465. (equal '(2)
  2466. (org-test-with-temp-text "
  2467. * H1
  2468. :PROPERTIES:
  2469. :TEST: 1
  2470. :END:
  2471. * H2
  2472. :PROPERTIES:
  2473. :TEST: 2
  2474. :END:"
  2475. (org-map-entries #'point "TEST=1"))))
  2476. ;; Multiple criteria.
  2477. (should
  2478. (equal '(23)
  2479. (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
  2480. (let (org-odd-levels-only
  2481. (org-use-tag-inheritance nil))
  2482. (org-map-entries #'point "yes+LEVEL=1")))))
  2483. ;; "or" criteria.
  2484. (should
  2485. (equal '(12 24)
  2486. (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
  2487. (let (org-odd-levels-only)
  2488. (org-map-entries #'point "LEVEL=2|no")))))
  2489. (should
  2490. (equal '(1 12)
  2491. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
  2492. (let (org-odd-levels-only)
  2493. (org-map-entries #'point "yes|no")))))
  2494. ;; "and" criteria.
  2495. (should
  2496. (equal '(22)
  2497. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
  2498. (let (org-odd-levels-only)
  2499. (org-map-entries #'point "yes&no")))))
  2500. ;; Setting `org-map-continue-from'
  2501. (should
  2502. (string= ""
  2503. (org-test-with-temp-text "* H1\n* H2\n* H3n* H4"
  2504. (org-map-entries
  2505. (lambda ()
  2506. (org-cut-subtree)
  2507. (setq org-map-continue-from (point))))
  2508. (buffer-string))))
  2509. (should
  2510. (string= "* H1\n* H2\n* H3\n"
  2511. (org-test-with-temp-text "* H1\n* H2\n* H3\n* H4"
  2512. (org-map-entries
  2513. (lambda ()
  2514. (when (string= "H4"
  2515. (org-element-property
  2516. :raw-value (org-element-at-point)))
  2517. (org-cut-subtree)
  2518. (setq org-map-continue-from
  2519. (org-element-property
  2520. :begin (org-element-at-point))))))
  2521. (buffer-string)))))
  2522. (ert-deftest test-org/edit-headline ()
  2523. "Test `org-edit-headline' specifications."
  2524. (should
  2525. (equal "* B"
  2526. (org-test-with-temp-text "* A"
  2527. (org-edit-headline "B")
  2528. (buffer-string))))
  2529. ;; Handle empty headings.
  2530. (should
  2531. (equal "* "
  2532. (org-test-with-temp-text "* A"
  2533. (org-edit-headline "")
  2534. (buffer-string))))
  2535. (should
  2536. (equal "* A"
  2537. (org-test-with-temp-text "* "
  2538. (org-edit-headline "A")
  2539. (buffer-string))))
  2540. ;; Handle TODO keywords and priority cookies.
  2541. (should
  2542. (equal "* TODO B"
  2543. (org-test-with-temp-text "* TODO A"
  2544. (org-edit-headline "B")
  2545. (buffer-string))))
  2546. (should
  2547. (equal "* [#A] B"
  2548. (org-test-with-temp-text "* [#A] A"
  2549. (org-edit-headline "B")
  2550. (buffer-string))))
  2551. (should
  2552. (equal "* TODO [#A] B"
  2553. (org-test-with-temp-text "* TODO [#A] A"
  2554. (org-edit-headline "B")
  2555. (buffer-string))))
  2556. ;; Handle tags.
  2557. (equal "* B :tag:"
  2558. (org-test-with-temp-text "* A :tag:"
  2559. (let ((org-tags-column 4)) (org-edit-headline "B"))
  2560. (buffer-string))))
  2561. ;;; Keywords
  2562. (ert-deftest test-org/set-regexps-and-options ()
  2563. "Test `org-set-regexps-and-options' specifications."
  2564. ;; TAGS keyword.
  2565. (should
  2566. (equal '(("A"))
  2567. (let ((org-tag-alist '(("A")))
  2568. (org-tag-persistent-alist nil))
  2569. (org-test-with-temp-text ""
  2570. (org-mode-restart)
  2571. org-current-tag-alist))))
  2572. (should
  2573. (equal '(("B"))
  2574. (let ((org-tag-alist '(("A")))
  2575. (org-tag-persistent-alist nil))
  2576. (org-test-with-temp-text "#+TAGS: B"
  2577. (org-mode-restart)
  2578. org-current-tag-alist))))
  2579. (should
  2580. (equal '(("C") ("B"))
  2581. (let ((org-tag-alist '(("A")))
  2582. (org-tag-persistent-alist '(("C"))))
  2583. (org-test-with-temp-text "#+TAGS: B"
  2584. (org-mode-restart)
  2585. org-current-tag-alist))))
  2586. (should
  2587. (equal '(("B"))
  2588. (let ((org-tag-alist '(("A")))
  2589. (org-tag-persistent-alist '(("C"))))
  2590. (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
  2591. (org-mode-restart)
  2592. org-current-tag-alist))))
  2593. (should
  2594. (equal '(("A" . ?a) ("B") ("C"))
  2595. (let ((org-tag-persistant-alist nil))
  2596. (org-test-with-temp-text "#+TAGS: A(a) B C"
  2597. (org-mode-restart)
  2598. org-current-tag-alist))))
  2599. (should
  2600. (equal '(("A") (:newline) ("B"))
  2601. (let ((org-tag-persistent-alist nil))
  2602. (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
  2603. (org-mode-restart)
  2604. org-current-tag-alist))))
  2605. (should
  2606. (equal '((:startgroup) ("A") ("B") (:endgroup) ("C"))
  2607. (let ((org-tag-persistent-alist nil))
  2608. (org-test-with-temp-text "#+TAGS: { A B } C"
  2609. (org-mode-restart)
  2610. org-current-tag-alist))))
  2611. (should
  2612. (equal '((:startgroup) ("A") (:grouptags) ("B") ("C") (:endgroup))
  2613. (let ((org-tag-persistent-alist nil))
  2614. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2615. (org-mode-restart)
  2616. org-current-tag-alist))))
  2617. (should
  2618. (equal '(("A" "B" "C"))
  2619. (let ((org-tag-persistent-alist nil))
  2620. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2621. (org-mode-restart)
  2622. org-tag-groups-alist))))
  2623. (should
  2624. (equal '((:startgrouptag) ("A") (:grouptags) ("B") ("C") (:endgrouptag))
  2625. (let ((org-tag-persistent-alist nil))
  2626. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2627. (org-mode-restart)
  2628. org-current-tag-alist))))
  2629. (should
  2630. (equal '(("A" "B" "C"))
  2631. (let ((org-tag-persistent-alist nil))
  2632. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2633. (org-mode-restart)
  2634. org-tag-groups-alist))))
  2635. (should-not
  2636. (let ((org-tag-alist '(("A"))))
  2637. (org-test-with-temp-text "#+TAGS:"
  2638. (org-mode-restart)
  2639. org-current-tag-alist)))
  2640. ;; FILETAGS keyword.
  2641. (should
  2642. (equal '("A" "B" "C")
  2643. (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
  2644. (org-mode-restart)
  2645. org-file-tags)))
  2646. ;; PROPERTY keyword. Property names are case-insensitive.
  2647. (should
  2648. (equal "foo=1"
  2649. (org-test-with-temp-text "#+PROPERTY: var foo=1"
  2650. (org-mode-restart)
  2651. (cdr (assoc "var" org-keyword-properties)))))
  2652. (should
  2653. (equal
  2654. "foo=1 bar=2"
  2655. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
  2656. (org-mode-restart)
  2657. (cdr (assoc "var" org-keyword-properties)))))
  2658. (should
  2659. (equal
  2660. "foo=1 bar=2"
  2661. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
  2662. (org-mode-restart)
  2663. (cdr (assoc "var" org-keyword-properties)))))
  2664. ;; ARCHIVE keyword.
  2665. (should
  2666. (equal "%s_done::"
  2667. (org-test-with-temp-text "#+ARCHIVE: %s_done::"
  2668. (org-mode-restart)
  2669. org-archive-location)))
  2670. ;; CATEGORY keyword.
  2671. (should
  2672. (eq 'test
  2673. (org-test-with-temp-text "#+CATEGORY: test"
  2674. (org-mode-restart)
  2675. org-category)))
  2676. (should
  2677. (equal "test"
  2678. (org-test-with-temp-text "#+CATEGORY: test"
  2679. (org-mode-restart)
  2680. (cdr (assoc "CATEGORY" org-keyword-properties)))))
  2681. ;; COLUMNS keyword.
  2682. (should
  2683. (equal "%25ITEM %TAGS %PRIORITY %TODO"
  2684. (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
  2685. (org-mode-restart)
  2686. org-columns-default-format)))
  2687. ;; CONSTANTS keyword. Constants names are case sensitive.
  2688. (should
  2689. (equal '("299792458." "3.14")
  2690. (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
  2691. (org-mode-restart)
  2692. (mapcar
  2693. (lambda (n) (cdr (assoc n org-table-formula-constants-local)))
  2694. '("c" "pi")))))
  2695. (should
  2696. (equal "3.14"
  2697. (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
  2698. (org-mode-restart)
  2699. (cdr (assoc "pi" org-table-formula-constants-local)))))
  2700. (should
  2701. (equal "22/7"
  2702. (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
  2703. (org-mode-restart)
  2704. (cdr (assoc "PI" org-table-formula-constants-local)))))
  2705. ;; LINK keyword.
  2706. (should
  2707. (equal
  2708. '("url1" "url2")
  2709. (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
  2710. (org-mode-restart)
  2711. (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local)))
  2712. '("a" "b")))))
  2713. ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
  2714. (should
  2715. (equal
  2716. '(?X ?Z ?Y)
  2717. (org-test-with-temp-text "#+PRIORITIES: X Z Y"
  2718. (org-mode-restart)
  2719. (list org-priority-highest org-priority-lowest org-priority-default))))
  2720. (should
  2721. (equal
  2722. '(?A ?C ?B)
  2723. (org-test-with-temp-text "#+PRIORITIES: X Z"
  2724. (org-mode-restart)
  2725. (list org-priority-highest org-priority-lowest org-priority-default))))
  2726. ;; STARTUP keyword.
  2727. (should
  2728. (equal '(t t)
  2729. (org-test-with-temp-text "#+STARTUP: fold odd"
  2730. (org-mode-restart)
  2731. (list org-startup-folded org-odd-levels-only))))
  2732. ;; TODO keywords.
  2733. (should
  2734. (equal '(("A" "B") ("C"))
  2735. (org-test-with-temp-text "#+TODO: A B | C"
  2736. (org-mode-restart)
  2737. (list org-not-done-keywords org-done-keywords))))
  2738. (should
  2739. (equal '(("A" "C") ("B" "D"))
  2740. (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
  2741. (org-mode-restart)
  2742. (list org-not-done-keywords org-done-keywords))))
  2743. (should
  2744. (equal '(("A" "B") ("C"))
  2745. (org-test-with-temp-text "#+TYP_TODO: A B | C"
  2746. (org-mode-restart)
  2747. (list org-not-done-keywords org-done-keywords))))
  2748. (should
  2749. (equal '((:startgroup) ("A" . ?a) (:endgroup))
  2750. (org-test-with-temp-text "#+TODO: A(a)"
  2751. (org-mode-restart)
  2752. org-todo-key-alist)))
  2753. (should
  2754. (equal '(("D" note nil) ("C" time nil) ("B" note time))
  2755. (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
  2756. (org-mode-restart)
  2757. org-todo-log-states)))
  2758. ;; Enter SETUPFILE keyword.
  2759. (should
  2760. (equal "1"
  2761. (org-test-with-temp-text
  2762. (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
  2763. (org-mode-restart)
  2764. (cdr (assoc "a" org-keyword-properties))))))
  2765. (ert-deftest test-org/collect-keywords ()
  2766. "Test `org-collect-keywords'."
  2767. (should-not
  2768. (org-test-with-temp-text "#+begin_example\n#+foo: bar\n#+end_example"
  2769. (org-collect-keywords '("FOO")))))
  2770. ;;; Links
  2771. ;;;; Coderefs
  2772. (ert-deftest test-org/coderef ()
  2773. "Test coderef links specifications."
  2774. (should
  2775. (org-test-with-temp-text "
  2776. #+BEGIN_SRC emacs-lisp
  2777. \(+ 1 1) (ref:sc)
  2778. #+END_SRC
  2779. \[[(sc)<point>]]"
  2780. (org-open-at-point)
  2781. (looking-at "(ref:sc)")))
  2782. ;; Find coderef even with alternate label format.
  2783. (should
  2784. (org-test-with-temp-text "
  2785. #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
  2786. \(+ 1 1) {ref:sc}
  2787. #+END_SRC
  2788. \[[(sc)<point>]]"
  2789. (org-open-at-point)
  2790. (looking-at "{ref:sc}"))))
  2791. ;;;; Custom ID
  2792. (ert-deftest test-org/custom-id ()
  2793. "Test custom ID links specifications."
  2794. (should
  2795. (org-test-with-temp-text
  2796. "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2797. (org-open-at-point)
  2798. (looking-at-p "\\* H1")))
  2799. ;; Handle escape characters.
  2800. (should
  2801. (org-test-with-temp-text
  2802. "* H1\n:PROPERTIES:\n:CUSTOM_ID: [%]\n:END:\n* H2\n[[#\\[%\\]<point>]]"
  2803. (org-open-at-point)
  2804. (looking-at-p "\\* H1")))
  2805. ;; Throw an error on false positives.
  2806. (should-error
  2807. (org-test-with-temp-text
  2808. "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2809. (org-open-at-point)
  2810. (looking-at-p "\\* H1"))))
  2811. ;;;; Fuzzy Links
  2812. ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
  2813. ;; a named element (#+name: text) and to headlines (* Text).
  2814. (ert-deftest test-org/fuzzy-links ()
  2815. "Test fuzzy links specifications."
  2816. ;; Fuzzy link goes in priority to a matching target.
  2817. (should
  2818. (org-test-with-temp-text
  2819. "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
  2820. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2821. (looking-at "<<Test>>")))
  2822. ;; Then fuzzy link points to an element with a given name.
  2823. (should
  2824. (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
  2825. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2826. (looking-at "#\\+NAME: Test")))
  2827. ;; A target still lead to a matching headline otherwise.
  2828. (should
  2829. (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
  2830. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2831. (looking-at "\\* Head2")))
  2832. ;; With a leading star in link, enforce heading match.
  2833. (should
  2834. (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
  2835. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2836. (looking-at "\\* Test")))
  2837. ;; With a leading star in link, enforce exact heading match, even
  2838. ;; with `org-link-search-must-match-exact-headline' set to nil.
  2839. (should-error
  2840. (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
  2841. (let ((org-link-search-must-match-exact-headline nil))
  2842. (org-open-at-point))))
  2843. ;; Handle non-nil `org-link-search-must-match-exact-headline'.
  2844. (should
  2845. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
  2846. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2847. (looking-at "\\* Test")))
  2848. (should
  2849. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
  2850. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2851. (looking-at "\\* Test")))
  2852. ;; Heading match should not care about spaces, cookies, TODO
  2853. ;; keywords, priorities, and tags. However, TODO keywords are
  2854. ;; case-sensitive.
  2855. (should
  2856. (let ((first-line
  2857. "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
  2858. (org-test-with-temp-text
  2859. (concat first-line "\nFoo Bar\n<point>[[*Test 1 2]]")
  2860. (let ((org-link-search-must-match-exact-headline nil)
  2861. (org-todo-regexp "TODO"))
  2862. (org-open-at-point))
  2863. (looking-at (regexp-quote first-line)))))
  2864. (should-error
  2865. (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
  2866. (let ((org-link-search-must-match-exact-headline nil)
  2867. (org-todo-regexp "TODO"))
  2868. (org-open-at-point))))
  2869. ;; Heading match should still be exact.
  2870. (should-error
  2871. (org-test-with-temp-text "
  2872. ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
  2873. Foo Bar
  2874. <point>[[*Test 1]]"
  2875. (let ((org-link-search-must-match-exact-headline nil)
  2876. (org-todo-regexp "TODO"))
  2877. (org-open-at-point))))
  2878. (should
  2879. (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
  2880. (let ((org-link-search-must-match-exact-headline nil)
  2881. (org-todo-regexp "TODO"))
  2882. (org-open-at-point))
  2883. (looking-at-p (regexp-quote "** Test 1 2"))))
  2884. ;; Heading match ignores COMMENT keyword.
  2885. (should
  2886. (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
  2887. (org-open-at-point)
  2888. (looking-at "\\* COMMENT Test")))
  2889. (should
  2890. (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
  2891. (org-open-at-point)
  2892. (looking-at "\\* TODO COMMENT Test")))
  2893. ;; Correctly un-escape fuzzy links.
  2894. (should
  2895. (org-test-with-temp-text "* [foo]\n[[*\\[foo\\]][With escaped characters]]"
  2896. (org-open-at-point)
  2897. (bobp)))
  2898. ;; Match search strings containing newline characters, including
  2899. ;; blank lines.
  2900. (should
  2901. (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
  2902. (let ((file (buffer-file-name)))
  2903. (goto-char (point-max))
  2904. (insert (format "[[file:%s::line1 line2]]" file))
  2905. (beginning-of-line)
  2906. (let ((org-link-search-must-match-exact-headline nil))
  2907. (org-open-at-point 0))
  2908. (looking-at-p "line1"))))
  2909. (should
  2910. (org-test-with-temp-text-in-file "Paragraph\n\nline1\n\nline2\n\n"
  2911. (let ((file (buffer-file-name)))
  2912. (goto-char (point-max))
  2913. (insert (format "[[file:%s::line1 line2]]" file))
  2914. (beginning-of-line)
  2915. (let ((org-link-search-must-match-exact-headline nil))
  2916. (org-open-at-point 0))
  2917. (looking-at-p "line1")))))
  2918. ;;;; Open at point
  2919. (ert-deftest test-org/open-at-point/keyword ()
  2920. "Does `org-open-at-point' open link in a keyword line?"
  2921. (should
  2922. (org-test-with-temp-text
  2923. "<<top>>\n#+KEYWORD: <point>[[top]]"
  2924. (org-open-at-point) t))
  2925. (should
  2926. (org-test-with-temp-text
  2927. "* H\n<<top>>\n#+KEYWORD: <point>[[top]]"
  2928. (org-open-at-point) t)))
  2929. (ert-deftest test-org/open-at-point/property ()
  2930. "Does `org-open-at-point' open link in property drawer?"
  2931. (should
  2932. (org-test-with-temp-text
  2933. "* Headline
  2934. :PROPERTIES:
  2935. :URL: <point>[[*Headline]]
  2936. :END:"
  2937. (org-open-at-point) t)))
  2938. (ert-deftest test-org/open-at-point/comment ()
  2939. "Does `org-open-at-point' open link in a commented line?"
  2940. (should
  2941. (org-test-with-temp-text
  2942. "<<top>>\n# <point>[[top]]"
  2943. (org-open-at-point) t))
  2944. (should
  2945. (org-test-with-temp-text
  2946. "* H\n<<top>>\n# <point>[[top]]"
  2947. (org-open-at-point) t)))
  2948. (ert-deftest test-org/open-at-point/inline-image ()
  2949. "Test `org-open-at-point' on nested links."
  2950. (should
  2951. (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
  2952. (org-open-at-point)
  2953. (bobp))))
  2954. (ert-deftest test-org/open-at-point/radio-target ()
  2955. "Test `org-open-at-point' on radio targets."
  2956. (should
  2957. (org-test-with-temp-text "<<<target>>> <point>target"
  2958. (org-update-radio-target-regexp)
  2959. (org-open-at-point)
  2960. (eq (org-element-type (org-element-context)) 'radio-target))))
  2961. (ert-deftest test-org/open-at-point/radio-target-shadowed ()
  2962. "Test `org-open-at-point' on shadowed radio targets."
  2963. (should
  2964. (org-test-with-temp-text
  2965. "<<<target shadowed>>> <<<target>>> <point>target shadowed"
  2966. (org-update-radio-target-regexp)
  2967. (org-open-at-point)
  2968. (string=
  2969. (org-element-property :value
  2970. (org-element-radio-target-parser))
  2971. "target shadowed"))))
  2972. (ert-deftest test-org/open-at-point/tag ()
  2973. "Test `org-open-at-point' on tags."
  2974. (should
  2975. (org-test-with-temp-text "* H :<point>tag:"
  2976. (catch :result
  2977. (cl-letf (((symbol-function 'org-tags-view)
  2978. (lambda (&rest args) (throw :result t))))
  2979. (org-open-at-point)
  2980. nil))))
  2981. (should-not
  2982. (org-test-with-temp-text-in-file "* H<point> :tag:"
  2983. (catch :result
  2984. (cl-letf (((symbol-function 'org-tags-view)
  2985. (lambda (&rest args) (throw :result t))))
  2986. ;; When point isn't on a tag it's going to try other things,
  2987. ;; possibly trying to open attachments which will return an
  2988. ;; error if there isn't an attachment. Suppress that error.
  2989. (ignore-errors
  2990. (org-open-at-point))
  2991. nil)))))
  2992. ;;; Node Properties
  2993. (ert-deftest test-org/accumulated-properties-in-drawers ()
  2994. "Ensure properties accumulate in subtree drawers."
  2995. (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
  2996. (org-babel-next-src-block)
  2997. (should (equal '(2 1) (org-babel-execute-src-block)))))
  2998. (ert-deftest test-org/custom-properties ()
  2999. "Test custom properties specifications."
  3000. ;; Standard test.
  3001. (should
  3002. (let ((org-custom-properties '("FOO")))
  3003. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  3004. (org-toggle-custom-properties-visibility)
  3005. (org-invisible-p2))))
  3006. ;; Properties are case-insensitive.
  3007. (should
  3008. (let ((org-custom-properties '("FOO")))
  3009. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
  3010. (org-toggle-custom-properties-visibility)
  3011. (org-invisible-p2))))
  3012. (should
  3013. (let ((org-custom-properties '("foo")))
  3014. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  3015. (org-toggle-custom-properties-visibility)
  3016. (org-invisible-p2))))
  3017. ;; Multiple custom properties in the same drawer.
  3018. (should
  3019. (let ((org-custom-properties '("FOO" "BAR")))
  3020. (org-test-with-temp-text
  3021. "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
  3022. (org-fold-reveal)
  3023. (org-toggle-custom-properties-visibility)
  3024. (and (org-invisible-p2)
  3025. (not (progn (forward-line) (org-invisible-p2)))
  3026. (progn (forward-line) (org-invisible-p2))))))
  3027. ;; Hide custom properties with an empty value.
  3028. (should
  3029. (let ((org-custom-properties '("FOO")))
  3030. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
  3031. (org-toggle-custom-properties-visibility)
  3032. (org-invisible-p2))))
  3033. ;; Do not hide fake properties.
  3034. (should-not
  3035. (let ((org-custom-properties '("FOO")))
  3036. (org-test-with-temp-text ":FOO: val\n"
  3037. (org-toggle-custom-properties-visibility)
  3038. (org-invisible-p2))))
  3039. (should-not
  3040. (let ((org-custom-properties '("A")))
  3041. (org-test-with-temp-text
  3042. "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
  3043. (org-fold-reveal)
  3044. (org-toggle-custom-properties-visibility)
  3045. (org-invisible-p2)))))
  3046. ;;; Mark Region
  3047. (ert-deftest test-org/mark-element ()
  3048. "Test `org-mark-element' specifications."
  3049. ;; Mark beginning and end of element.
  3050. (should
  3051. (equal '(t t)
  3052. (org-test-with-temp-text "Para<point>graph"
  3053. (org-mark-element)
  3054. (list (bobp) (= (mark) (point-max))))))
  3055. (should
  3056. (equal '(t t)
  3057. (org-test-with-temp-text "P1\n\nPara<point>graph\n\nP2"
  3058. (org-mark-element)
  3059. (list (looking-at "Paragraph")
  3060. (org-with-point-at (mark) (looking-at "P2"))))))
  3061. ;; Do not set mark past (point-max).
  3062. (should
  3063. (org-test-with-temp-text "Para<point>graph"
  3064. (narrow-to-region 2 6)
  3065. (org-mark-element)
  3066. (= 6 (mark)))))
  3067. (ert-deftest test-org/mark-subtree ()
  3068. "Test `org-mark-subtree' specifications."
  3069. ;; Error when point is before first headline.
  3070. (should-error
  3071. (org-test-with-temp-text "Paragraph\n* Headline\nBody"
  3072. (progn (transient-mark-mode 1)
  3073. (org-mark-subtree))))
  3074. ;; Without argument, mark current subtree.
  3075. (should
  3076. (equal
  3077. '(12 32)
  3078. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  3079. (progn (transient-mark-mode 1)
  3080. (forward-line 2)
  3081. (org-mark-subtree)
  3082. (list (region-beginning) (region-end))))))
  3083. ;; With an argument, move ARG up.
  3084. (should
  3085. (equal
  3086. '(1 32)
  3087. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  3088. (progn (transient-mark-mode 1)
  3089. (forward-line 2)
  3090. (org-mark-subtree 1)
  3091. (list (region-beginning) (region-end))))))
  3092. ;; Do not get fooled by inlinetasks.
  3093. (when (featurep 'org-inlinetask)
  3094. (should
  3095. (= 1
  3096. (org-test-with-temp-text "* Headline\n*************** Task\nContents"
  3097. (progn (transient-mark-mode 1)
  3098. (forward-line 1)
  3099. (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
  3100. (region-beginning)))))))
  3101. ;;; Miscellaneous
  3102. (ert-deftest test-org/sort-entries ()
  3103. "Test `org-sort-entries'."
  3104. ;; Sort alphabetically.
  3105. (should
  3106. (equal "\n* abc\n* def\n* xyz\n"
  3107. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  3108. (org-sort-entries nil ?a)
  3109. (buffer-string))))
  3110. (should
  3111. (equal "\n* xyz\n* def\n* abc\n"
  3112. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  3113. (org-sort-entries nil ?A)
  3114. (buffer-string))))
  3115. (should
  3116. (equal "\n* \n* klm\n* xyz\n"
  3117. (org-test-with-temp-text "\n* xyz\n* \n* klm\n"
  3118. (org-sort-entries nil ?a)
  3119. (buffer-string))))
  3120. ;; Sort numerically.
  3121. (should
  3122. (equal "\n* 1\n* 2\n* 10\n"
  3123. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  3124. (org-sort-entries nil ?n)
  3125. (buffer-string))))
  3126. (should
  3127. (equal "\n* 10\n* 2\n* 1\n"
  3128. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  3129. (org-sort-entries nil ?N)
  3130. (buffer-string))))
  3131. (should
  3132. (equal "\n* \n* 1\n* 2\n"
  3133. (org-test-with-temp-text "\n* 1\n* \n* 2\n"
  3134. (org-sort-entries nil ?n)
  3135. (buffer-string))))
  3136. ;; Sort by custom function.
  3137. (should
  3138. (equal "\n* b\n* aa\n* ccc\n"
  3139. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  3140. (org-sort-entries nil ?f
  3141. (lambda ()
  3142. (length (buffer-substring (point-at-bol)
  3143. (point-at-eol))))
  3144. #'<)
  3145. (buffer-string))))
  3146. (should
  3147. (equal "\n* ccc\n* aa\n* b\n"
  3148. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  3149. (org-sort-entries nil ?F
  3150. (lambda ()
  3151. (length (buffer-substring (point-at-bol)
  3152. (point-at-eol))))
  3153. #'<)
  3154. (buffer-string))))
  3155. ;; Sort by TODO keyword.
  3156. (should
  3157. (equal "\n* TODO h1\n* TODO h3\n* DONE h2\n"
  3158. (org-test-with-temp-text
  3159. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  3160. (org-sort-entries nil ?o)
  3161. (buffer-string))))
  3162. (should
  3163. (equal "\n* DONE h2\n* TODO h1\n* TODO h3\n"
  3164. (org-test-with-temp-text
  3165. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  3166. (org-sort-entries nil ?O)
  3167. (buffer-string))))
  3168. ;; Sort by priority.
  3169. (should
  3170. (equal "\n* [#A] h2\n* [#B] h3\n* [#C] h1\n"
  3171. (org-test-with-temp-text
  3172. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  3173. (org-sort-entries nil ?p)
  3174. (buffer-string))))
  3175. (should
  3176. (equal "\n* [#C] h1\n* [#B] h3\n* [#A] h2\n"
  3177. (org-test-with-temp-text
  3178. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  3179. (org-sort-entries nil ?P)
  3180. (buffer-string))))
  3181. ;; Sort by creation time.
  3182. (should
  3183. (equal "
  3184. * h3
  3185. [2017-05-08 Mon]
  3186. * h2
  3187. [2017-05-09 Tue]
  3188. * h1
  3189. [2018-05-09 Wed]
  3190. "
  3191. (org-test-with-temp-text
  3192. "
  3193. * h1
  3194. [2018-05-09 Wed]
  3195. * h2
  3196. [2017-05-09 Tue]
  3197. * h3
  3198. [2017-05-08 Mon]
  3199. "
  3200. (org-sort-entries nil ?c)
  3201. (buffer-string))))
  3202. ;; Sort by scheduled date.
  3203. (should
  3204. (equal "
  3205. * TODO h4
  3206. SCHEDULED: <2017-05-06 Sat>
  3207. * TODO h3
  3208. SCHEDULED: <2017-05-08 Mon>
  3209. * TODO h2
  3210. DEADLINE: <2017-05-09 Tue>
  3211. * TODO h1
  3212. DEADLINE: <2017-05-07 Sun>
  3213. "
  3214. (org-test-with-temp-text
  3215. "
  3216. * TODO h2
  3217. DEADLINE: <2017-05-09 Tue>
  3218. * TODO h1
  3219. DEADLINE: <2017-05-07 Sun>
  3220. * TODO h3
  3221. SCHEDULED: <2017-05-08 Mon>
  3222. * TODO h4
  3223. SCHEDULED: <2017-05-06 Sat>
  3224. "
  3225. (org-sort-entries nil ?s)
  3226. (buffer-string))))
  3227. ;; Sort by deadline date.
  3228. (should
  3229. (equal "
  3230. * TODO h1
  3231. DEADLINE: <2017-05-07 Sun>
  3232. * TODO h2
  3233. DEADLINE: <2017-05-09 Tue>
  3234. * TODO h3
  3235. SCHEDULED: <2017-05-08 Mon>
  3236. * TODO h4
  3237. SCHEDULED: <2017-05-06 Sat>
  3238. "
  3239. (org-test-with-temp-text
  3240. "
  3241. * TODO h2
  3242. DEADLINE: <2017-05-09 Tue>
  3243. * TODO h1
  3244. DEADLINE: <2017-05-07 Sun>
  3245. * TODO h3
  3246. SCHEDULED: <2017-05-08 Mon>
  3247. * TODO h4
  3248. SCHEDULED: <2017-05-06 Sat>
  3249. "
  3250. (org-sort-entries nil ?d)
  3251. (buffer-string))))
  3252. ;; Sort by any date/time
  3253. (should
  3254. (equal "
  3255. * TODO h4
  3256. SCHEDULED: <2017-05-06 Sat>
  3257. * TODO h1
  3258. DEADLINE: <2017-05-07 Sun>
  3259. * TODO h3
  3260. SCHEDULED: <2017-05-08 Mon>
  3261. * TODO h2
  3262. DEADLINE: <2017-05-09 Tue>
  3263. "
  3264. (org-test-with-temp-text
  3265. "
  3266. * TODO h2
  3267. DEADLINE: <2017-05-09 Tue>
  3268. * TODO h1
  3269. DEADLINE: <2017-05-07 Sun>
  3270. * TODO h3
  3271. SCHEDULED: <2017-05-08 Mon>
  3272. * TODO h4
  3273. SCHEDULED: <2017-05-06 Sat>
  3274. "
  3275. (org-sort-entries nil ?t)
  3276. (buffer-string))))
  3277. ;; Sort by clocking time.
  3278. (should
  3279. (equal "
  3280. * clocked h2
  3281. :LOGBOOK:
  3282. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3283. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  3284. :END:
  3285. * clocked h1
  3286. :LOGBOOK:
  3287. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3288. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  3289. :END:
  3290. "
  3291. (org-test-with-temp-text
  3292. "
  3293. * clocked h1
  3294. :LOGBOOK:
  3295. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3296. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  3297. :END:
  3298. * clocked h2
  3299. :LOGBOOK:
  3300. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3301. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  3302. :END:
  3303. "
  3304. (org-sort-entries nil ?k)
  3305. (buffer-string))))
  3306. ;; Preserve file local variables when sorting.
  3307. (should
  3308. (equal "\n* A\n* B\n# Local Variables:\n# foo: t\n# End:\n"
  3309. (org-test-with-temp-text
  3310. "\n* B\n* A\n# Local Variables:\n# foo: t\n# End:"
  3311. (org-sort-entries nil ?a)
  3312. (buffer-string)))))
  3313. (ert-deftest test-org/string-collate-greaterp ()
  3314. "Test `org-string-collate-greaterp' specifications."
  3315. (should (org-string-collate-greaterp "def" "abc"))
  3316. (should-not (org-string-collate-greaterp "abc" "def")))
  3317. (ert-deftest test-org/file-contents ()
  3318. "Test `org-file-contents' specifications."
  3319. ;; Open files.
  3320. (should
  3321. (string= "#+BIND: variable value
  3322. #+DESCRIPTION: l2
  3323. #+LANGUAGE: en
  3324. #+SELECT_TAGS: b
  3325. #+TITLE: b
  3326. #+PROPERTY: a 1
  3327. " (org-file-contents (expand-file-name "setupfile3.org"
  3328. (concat org-test-dir "examples/")))))
  3329. ;; Throw error when trying to access an invalid file.
  3330. (should-error (org-file-contents "this-file-must-not-exist"))
  3331. ;; Try to access an invalid file, but do not throw an error.
  3332. (should
  3333. (progn (org-file-contents "this-file-must-not-exist" :noerror) t))
  3334. ;; Open URL.
  3335. (should
  3336. (let ((org-resource-download-policy t))
  3337. (string= "foo"
  3338. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3339. (unwind-protect
  3340. ;; Simulate successful retrieval of a URL.
  3341. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3342. (lambda (&rest_)
  3343. (with-current-buffer buffer
  3344. (insert "HTTP/1.1 200 OK\n\nfoo"))
  3345. buffer)))
  3346. (org-file-contents "http://some-valid-url"))
  3347. (kill-buffer buffer))))))
  3348. ;; Throw error when trying to access an invalid URL.
  3349. (should-error
  3350. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3351. (unwind-protect
  3352. ;; Simulate unsuccessful retrieval of a URL.
  3353. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3354. (lambda (&rest_)
  3355. (with-current-buffer buffer
  3356. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3357. buffer)))
  3358. (org-file-contents "http://this-url-must-not-exist"))
  3359. (kill-buffer buffer))))
  3360. ;; Try to access an invalid URL, but do not throw an error.
  3361. (should-error
  3362. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3363. (unwind-protect
  3364. ;; Simulate unsuccessful retrieval of a URL.
  3365. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3366. (lambda (&rest_)
  3367. (with-current-buffer buffer
  3368. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3369. buffer)))
  3370. (org-file-contents "http://this-url-must-not-exist"))
  3371. (kill-buffer buffer))))
  3372. (should
  3373. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3374. (unwind-protect
  3375. ;; Simulate unsuccessful retrieval of a URL.
  3376. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3377. (lambda (&rest_)
  3378. (with-current-buffer buffer
  3379. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3380. buffer)))
  3381. (org-file-contents "http://this-url-must-not-exist" :noerror))
  3382. (kill-buffer buffer))
  3383. t)))
  3384. ;;; Navigation
  3385. (ert-deftest test-org/next-visible-heading ()
  3386. "Test `org-next-visible-heading' specifications."
  3387. ;; Move to the beginning of the next headline, taking into
  3388. ;; consideration ARG.
  3389. (should
  3390. (org-test-with-temp-text "* H1\n* H2"
  3391. (org-next-visible-heading 1)
  3392. (looking-at "\\* H2")))
  3393. (should
  3394. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3395. (org-next-visible-heading 2)
  3396. (looking-at "\\* H3")))
  3397. ;; Ignore invisible headlines.
  3398. (should
  3399. (org-test-with-temp-text "* H1\n** H2\n* H3"
  3400. (org-cycle)
  3401. (org-next-visible-heading 1)
  3402. (looking-at "\\* H3")))
  3403. ;; Move point between headlines, not on blank lines between.
  3404. (should
  3405. (org-test-with-temp-text "* H1\n** H2\n\n\n\n* H3"
  3406. (let ((org-cycle-separator-lines 1))
  3407. (org-cycle)
  3408. (org-next-visible-heading 1))
  3409. (looking-at "\\* H3")))
  3410. ;; Move at end of buffer when there is no more headline.
  3411. (should
  3412. (org-test-with-temp-text "* H1"
  3413. (org-next-visible-heading 1)
  3414. (eobp)))
  3415. (should
  3416. (org-test-with-temp-text "* H1\n* H2"
  3417. (org-next-visible-heading 2)
  3418. (eobp)))
  3419. ;; With a negative argument, move backwards.
  3420. (should
  3421. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3422. (org-next-visible-heading -1)
  3423. (looking-at "\\* H2")))
  3424. (should
  3425. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3426. (org-next-visible-heading -2)
  3427. (looking-at "\\* H1"))))
  3428. (ert-deftest test-org/previous-visible-heading ()
  3429. "Test `org-previous-visible-heading' specifications."
  3430. ;; Move to the beginning of the next headline, taking into
  3431. ;; consideration ARG.
  3432. (should
  3433. (org-test-with-temp-text "* H1\n<point>* H2"
  3434. (org-previous-visible-heading 1)
  3435. (looking-at "\\* H1")))
  3436. (should
  3437. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3438. (org-previous-visible-heading 2)
  3439. (looking-at "\\* H1")))
  3440. ;; Ignore invisible headlines.
  3441. (should
  3442. (org-test-with-temp-text "* H1\n** H2\n<point>* H3"
  3443. (org-overview)
  3444. (org-previous-visible-heading 1)
  3445. (looking-at "\\* H1")))
  3446. ;; Move point between headlines, not on blank lines between.
  3447. (should
  3448. (org-test-with-temp-text "* H1\n\n\n\n** H2\n<point>* H3"
  3449. (let ((org-cycle-separator-lines 1))
  3450. (org-overview)
  3451. (org-previous-visible-heading 1))
  3452. (looking-at "\\* H1")))
  3453. ;; Move at end of buffer when there is no more headline.
  3454. (should
  3455. (org-test-with-temp-text "* H1"
  3456. (org-previous-visible-heading 1)
  3457. (bobp)))
  3458. (should
  3459. (org-test-with-temp-text "* H1\n* <point>H2"
  3460. (org-previous-visible-heading 2)
  3461. (bobp)))
  3462. ;; Invisible parts may not start at a headline, i.e., when revealing
  3463. ;; parts of the buffer. Handle this.
  3464. (should
  3465. (org-test-with-temp-text "* Main\n** H1\nFoo\n** H2\nBar\n** H3\nBaz"
  3466. (org-overview)
  3467. (search-forward "H1")
  3468. (org-show-context 'minimal)
  3469. (org-cycle)
  3470. (search-forward "H3")
  3471. (org-show-context 'minimal)
  3472. ;; At this point, buffer displays, with point at "|",
  3473. ;;
  3474. ;; * Main
  3475. ;; ** H1
  3476. ;; Foo
  3477. ;; ** H3|
  3478. (org-previous-visible-heading 1)
  3479. (looking-at "\\*+ H1"))))
  3480. (ert-deftest test-org/forward-heading-same-level ()
  3481. "Test `org-forward-heading-same-level' specifications."
  3482. ;; Test navigation at top level, forward and backward.
  3483. (should
  3484. (equal "* H2"
  3485. (org-test-with-temp-text "* H1\n* H2"
  3486. (org-forward-heading-same-level 1)
  3487. (buffer-substring-no-properties (point) (line-end-position)))))
  3488. (should
  3489. (equal "* H1"
  3490. (org-test-with-temp-text "* H1\n<point>* H2"
  3491. (org-forward-heading-same-level -1)
  3492. (buffer-substring-no-properties (point) (line-end-position)))))
  3493. ;; Test navigation in a sub-tree, forward and backward.
  3494. (should
  3495. (equal "* H2"
  3496. (org-test-with-temp-text "* H1\n** H11\n** H12\n* H2"
  3497. (org-forward-heading-same-level 1)
  3498. (buffer-substring-no-properties (point) (line-end-position)))))
  3499. (should
  3500. (equal "* H1"
  3501. (org-test-with-temp-text "* H1\n** H11\n** H12\n<point>* H2"
  3502. (org-forward-heading-same-level -1)
  3503. (buffer-substring-no-properties (point) (line-end-position)))))
  3504. ;; Stop at first or last sub-heading.
  3505. (should-not
  3506. (equal "* H2"
  3507. (org-test-with-temp-text "* H1\n** H11\n<point>** H12\n* H2"
  3508. (org-forward-heading-same-level 1)
  3509. (buffer-substring-no-properties (point) (line-end-position)))))
  3510. (should-not
  3511. (equal "* H2"
  3512. (org-test-with-temp-text "* H1\n<point>** H11\n** H12\n* H2"
  3513. (org-forward-heading-same-level -1)
  3514. (buffer-substring-no-properties (point) (line-end-position)))))
  3515. ;; Allow multiple moves.
  3516. (should
  3517. (equal "* H3"
  3518. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3519. (org-forward-heading-same-level 2)
  3520. (buffer-substring-no-properties (point) (line-end-position)))))
  3521. (should
  3522. (equal "* H1"
  3523. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3524. (org-forward-heading-same-level -2)
  3525. (buffer-substring-no-properties (point) (line-end-position)))))
  3526. ;; Ignore spurious moves when first (or last) sibling is reached.
  3527. (should
  3528. (equal "** H3"
  3529. (org-test-with-temp-text "* First\n<point>** H1\n** H2\n** H3\n* Last"
  3530. (org-forward-heading-same-level 100)
  3531. (buffer-substring-no-properties (point) (line-end-position)))))
  3532. (should
  3533. (equal "** H1"
  3534. (org-test-with-temp-text "* First\n** H1\n** H2\n<point>** H3\n* Last"
  3535. (org-forward-heading-same-level -100)
  3536. (buffer-substring-no-properties (point) (line-end-position))))))
  3537. (ert-deftest test-org/end-of-meta-data ()
  3538. "Test `org-end-of-meta-data' specifications."
  3539. ;; Skip planning line.
  3540. (should
  3541. (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
  3542. (org-end-of-meta-data)
  3543. (eobp)))
  3544. ;; Skip properties drawer.
  3545. (should
  3546. (org-test-with-temp-text
  3547. "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
  3548. (org-end-of-meta-data)
  3549. (eobp)))
  3550. ;; Skip both.
  3551. (should
  3552. (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
  3553. (org-end-of-meta-data)
  3554. (eobp)))
  3555. ;; Nothing to skip, go to first line.
  3556. (should
  3557. (org-test-with-temp-text "* Headline\nContents"
  3558. (org-end-of-meta-data)
  3559. (looking-at "Contents")))
  3560. ;; With option argument, skip empty lines, regular drawers and
  3561. ;; clocking lines.
  3562. (should
  3563. (org-test-with-temp-text "* Headline\n\nContents"
  3564. (org-end-of-meta-data t)
  3565. (looking-at "Contents")))
  3566. (should
  3567. (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
  3568. (org-end-of-meta-data t)
  3569. (looking-at "Contents")))
  3570. (should
  3571. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
  3572. (org-end-of-meta-data t)
  3573. (looking-at "Contents")))
  3574. ;; Special case: do not skip incomplete drawers.
  3575. (should
  3576. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
  3577. (org-end-of-meta-data t)
  3578. (looking-at ":LOGBOOK:")))
  3579. ;; Special case: Be careful about consecutive headlines.
  3580. (should-not
  3581. (org-test-with-temp-text "* H1\n*H2\nContents"
  3582. (org-end-of-meta-data t)
  3583. (looking-at "Contents"))))
  3584. (ert-deftest test-org/shiftright-heading ()
  3585. "Test `org-shiftright' on headings."
  3586. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  3587. (should
  3588. (equal "* TODO a1\n** a2\n* DONE b1\n"
  3589. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3590. (org-shiftright)
  3591. (buffer-string))))
  3592. (should
  3593. (equal "* TODO a1\n** TODO a2\n* b1\n"
  3594. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3595. (let ((org-loop-over-headlines-in-active-region t))
  3596. (transient-mark-mode 1)
  3597. (push-mark (point) t t)
  3598. (search-forward "* DONE b1")
  3599. (org-shiftright))
  3600. (buffer-string))))
  3601. (should
  3602. (equal "* TODO a1\n** a2\n* b1\n"
  3603. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3604. (let ((org-loop-over-headlines-in-active-region 'start-level))
  3605. (transient-mark-mode 1)
  3606. (push-mark (point) t t)
  3607. (search-forward "* DONE b1")
  3608. (org-shiftright))
  3609. (buffer-string))))))
  3610. (ert-deftest test-org/beginning-of-line ()
  3611. "Test `org-beginning-of-line' specifications."
  3612. ;; Move to beginning of line. If current line in invisible, move to
  3613. ;; beginning of visible line instead.
  3614. (should
  3615. (org-test-with-temp-text "Some text\nSome other text<point>"
  3616. (org-beginning-of-line)
  3617. (bolp)))
  3618. (should
  3619. (org-test-with-temp-text "* H1\n** H2<point>"
  3620. (org-overview)
  3621. (org-beginning-of-line)
  3622. (= (line-beginning-position) 1)))
  3623. ;; With `visual-line-mode' active, move to beginning of visual line.
  3624. (should-not
  3625. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3626. (visual-line-mode)
  3627. (dotimes (i 1000) (insert "very "))
  3628. (org-beginning-of-line)
  3629. (bolp)))
  3630. ;; In a wide headline, with `visual-line-mode', prefer going to the
  3631. ;; beginning of a visual line than to the logical beginning of line,
  3632. ;; even if special movement is active.
  3633. (should-not
  3634. (org-test-with-temp-text "* A <point>long headline"
  3635. (visual-line-mode)
  3636. (dotimes (i 1000) (insert "very "))
  3637. (goto-char (point-max))
  3638. (org-beginning-of-line)
  3639. (bobp)))
  3640. (should-not
  3641. (org-test-with-temp-text "* A <point>long headline"
  3642. (visual-line-mode)
  3643. (dotimes (i 1000) (insert "very "))
  3644. (goto-char (point-max))
  3645. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line))
  3646. (bobp)))
  3647. ;; At an headline with special movement, first move at beginning of
  3648. ;; title, then at the beginning of line, rinse, repeat.
  3649. (should
  3650. (org-test-with-temp-text "* TODO Headline<point>"
  3651. (let ((org-special-ctrl-a/e t))
  3652. (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
  3653. (progn (org-beginning-of-line) (bolp))
  3654. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3655. (should
  3656. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3657. (let ((org-special-ctrl-a/e t))
  3658. (org-beginning-of-line)
  3659. (looking-at "Headline"))))
  3660. (should
  3661. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3662. (let ((org-special-ctrl-a/e '(t . nil)))
  3663. (org-beginning-of-line)
  3664. (looking-at "Headline"))))
  3665. (should-not
  3666. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3667. (let ((org-special-ctrl-a/e '(nil . nil)))
  3668. (org-beginning-of-line)
  3669. (looking-at "Headline"))))
  3670. ;; At an headline with reversed movement, first move to beginning of
  3671. ;; line, then to the beginning of title.
  3672. (should
  3673. (org-test-with-temp-text "* TODO Headline<point>"
  3674. (let ((org-special-ctrl-a/e 'reversed)
  3675. (this-command last-command))
  3676. (and (progn (org-beginning-of-line) (bolp))
  3677. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3678. (should
  3679. (org-test-with-temp-text "* TODO Headline<point>"
  3680. (let ((org-special-ctrl-a/e '(reversed . nil))
  3681. (this-command last-command))
  3682. (and (progn (org-beginning-of-line) (bolp))
  3683. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3684. (should-not
  3685. (org-test-with-temp-text "* TODO Headline<point>"
  3686. (let ((org-special-ctrl-a/e '(t . nil))
  3687. (this-command last-command))
  3688. (and (progn (org-beginning-of-line) (bolp))
  3689. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3690. ;; At an item with special movement, first move after to beginning
  3691. ;; of title, then to the beginning of line, rinse, repeat.
  3692. (should
  3693. (org-test-with-temp-text "- [ ] Item<point>"
  3694. (let ((org-special-ctrl-a/e t))
  3695. (and (progn (org-beginning-of-line) (looking-at-p "Item"))
  3696. (progn (org-beginning-of-line) (bolp))
  3697. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3698. ;; At an item with reversed movement, first move to beginning of
  3699. ;; line, then to the beginning of title.
  3700. (should
  3701. (org-test-with-temp-text "- [X] Item<point>"
  3702. (let ((org-special-ctrl-a/e 'reversed)
  3703. (this-command last-command))
  3704. (and (progn (org-beginning-of-line) (bolp))
  3705. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3706. ;; Leave point before invisible characters at column 0.
  3707. (should
  3708. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3709. (let ((org-special-ctrl-a/e nil))
  3710. (org-beginning-of-line)
  3711. (bolp))))
  3712. (should
  3713. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3714. (let ((org-special-ctrl-a/e t))
  3715. (org-beginning-of-line)
  3716. (bolp))))
  3717. (should
  3718. (org-test-with-temp-text "[[http<point>://orgmode.org]]"
  3719. (visual-line-mode)
  3720. (org-beginning-of-line)
  3721. (bolp)))
  3722. ;; Special case: Do not error when the buffer contains only a single
  3723. ;; asterisk.
  3724. (should
  3725. (org-test-with-temp-text "*<point>"
  3726. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line) t)))
  3727. (should
  3728. (org-test-with-temp-text "*<point>"
  3729. (let ((org-special-ctrl-a/e nil)) (org-beginning-of-line) t))))
  3730. (ert-deftest test-org/end-of-line ()
  3731. "Test `org-end-of-line' specifications."
  3732. ;; Standard test.
  3733. (should
  3734. (org-test-with-temp-text "Some text\nSome other text"
  3735. (org-end-of-line)
  3736. (eolp)))
  3737. ;; With `visual-line-mode' active, move to end of visible line.
  3738. ;; However, never go past ellipsis.
  3739. (should-not
  3740. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3741. (visual-line-mode)
  3742. (dotimes (i 1000) (insert "very "))
  3743. (goto-char (point-min))
  3744. (org-end-of-line)
  3745. (eolp)))
  3746. (should-not
  3747. (org-test-with-temp-text "* A short headline\nSome contents"
  3748. (visual-line-mode)
  3749. (org-overview)
  3750. (org-end-of-line)
  3751. (eobp)))
  3752. ;; In a wide headline, with `visual-line-mode', prefer going to end
  3753. ;; of visible line if tags, or end of line, are farther.
  3754. (should-not
  3755. (org-test-with-temp-text "* A <point>long headline"
  3756. (visual-line-mode)
  3757. (dotimes (i 1000) (insert "very "))
  3758. (goto-char (point-min))
  3759. (org-end-of-line)
  3760. (eolp)))
  3761. (should-not
  3762. (org-test-with-temp-text "* A <point>long headline :tag:"
  3763. (visual-line-mode)
  3764. (dotimes (i 1000) (insert "very "))
  3765. (goto-char (point-min))
  3766. (org-end-of-line)
  3767. (eolp)))
  3768. ;; At an headline without special movement, go to end of line.
  3769. ;; However, never go past ellipsis.
  3770. (should
  3771. (org-test-with-temp-text "* Headline2b :tag:\n"
  3772. (let ((org-special-ctrl-a/e nil))
  3773. (and (progn (org-end-of-line) (eolp))
  3774. (progn (org-end-of-line) (eolp))))))
  3775. (should
  3776. (org-test-with-temp-text "* Headline2b :tag:\n"
  3777. (let ((org-special-ctrl-a/e '(t . nil)))
  3778. (and (progn (org-end-of-line) (eolp))
  3779. (progn (org-end-of-line) (eolp))))))
  3780. (should
  3781. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3782. (org-overview)
  3783. (let ((org-special-ctrl-a/e nil))
  3784. (org-end-of-line)
  3785. (= 1 (line-beginning-position)))))
  3786. ;; At an headline with special movement, first move before tags,
  3787. ;; then at the end of line, rinse, repeat. However, never go past
  3788. ;; ellipsis.
  3789. (should
  3790. (org-test-with-temp-text "* Headline1 :tag:\n"
  3791. (let ((org-special-ctrl-a/e t))
  3792. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3793. (progn (org-end-of-line) (eolp))
  3794. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3795. (should
  3796. (org-test-with-temp-text "* Headline1 :tag:\n"
  3797. (let ((org-special-ctrl-a/e '(nil . t)))
  3798. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3799. (progn (org-end-of-line) (eolp))
  3800. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3801. (should-not
  3802. (org-test-with-temp-text "* Headline1 :tag:\n"
  3803. (let ((org-special-ctrl-a/e '(nil . nil)))
  3804. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3805. (progn (org-end-of-line) (eolp))
  3806. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3807. (should
  3808. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3809. (org-overview)
  3810. (let ((org-special-ctrl-a/e t))
  3811. (org-end-of-line)
  3812. (org-end-of-line)
  3813. (= 1 (line-beginning-position)))))
  3814. ;; At an headline, with reversed movement, first go to end of line,
  3815. ;; then before tags. However, never go past ellipsis.
  3816. (should
  3817. (org-test-with-temp-text "* Headline3 :tag:\n"
  3818. (let ((org-special-ctrl-a/e 'reversed)
  3819. (this-command last-command))
  3820. (and (progn (org-end-of-line) (eolp))
  3821. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3822. (should
  3823. (org-test-with-temp-text "* Headline3 :tag:\n"
  3824. (let ((org-special-ctrl-a/e '(nil . reversed))
  3825. (this-command last-command))
  3826. (and (progn (org-end-of-line) (eolp))
  3827. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3828. (should-not
  3829. (org-test-with-temp-text "* Headline3 :tag:\n"
  3830. (let ((org-special-ctrl-a/e '(nil . t))
  3831. (this-command last-command))
  3832. (and (progn (org-end-of-line) (eolp))
  3833. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3834. (should
  3835. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3836. (org-overview)
  3837. (let ((org-special-ctrl-a/e 'reversed))
  3838. (org-end-of-line)
  3839. (= 1 (line-beginning-position)))))
  3840. ;; At a block without hidden contents.
  3841. (should
  3842. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3843. (progn (org-end-of-line) (eolp))))
  3844. ;; At a block with hidden contents.
  3845. (should-not
  3846. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3847. (let ((org-special-ctrl-a/e t))
  3848. (org-fold-hide-block-toggle)
  3849. (org-end-of-line)
  3850. (eobp))))
  3851. ;; Get past invisible characters at the end of line.
  3852. (should
  3853. (org-test-with-temp-text "[[https://orgmode.org]]"
  3854. (org-end-of-line)
  3855. (eolp))))
  3856. (ert-deftest test-org/open-line ()
  3857. "Test `org-open-line' specifications."
  3858. ;; Call `open-line' outside of tables.
  3859. (should
  3860. (equal "\nText"
  3861. (org-test-with-temp-text "Text"
  3862. (org-open-line 1)
  3863. (buffer-string))))
  3864. ;; At a table, create a row above.
  3865. (should
  3866. (equal "\n| |\n| a |"
  3867. (org-test-with-temp-text "\n<point>| a |"
  3868. (org-open-line 1)
  3869. (buffer-string))))
  3870. ;; At the very first character of the buffer, also call `open-line'.
  3871. (should
  3872. (equal "\n| a |"
  3873. (org-test-with-temp-text "| a |"
  3874. (org-open-line 1)
  3875. (buffer-string))))
  3876. ;; Narrowing does not count.
  3877. (should
  3878. (equal "Text\n| |\n| a |"
  3879. (org-test-with-temp-text "Text\n<point>| a |"
  3880. (narrow-to-region (point) (point-max))
  3881. (org-open-line 1)
  3882. (widen)
  3883. (buffer-string)))))
  3884. (ert-deftest test-org/forward-sentence ()
  3885. "Test `org-forward-sentence' specifications."
  3886. ;; At the end of a table cell, move to the end of the next one.
  3887. (should
  3888. (org-test-with-temp-text "| a<point> | b |"
  3889. (org-forward-sentence)
  3890. (looking-at " |$")))
  3891. ;; Elsewhere in a cell, move to its end.
  3892. (should
  3893. (org-test-with-temp-text "| a<point>c | b |"
  3894. (org-forward-sentence)
  3895. (looking-at " | b |$")))
  3896. ;; Otherwise, simply call `forward-sentence'.
  3897. (should
  3898. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3899. (org-forward-sentence)
  3900. (looking-at " Sentence 2.")))
  3901. (should
  3902. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3903. (org-forward-sentence)
  3904. (org-forward-sentence)
  3905. (eobp)))
  3906. ;; At the end of an element, jump to the next one, without stopping
  3907. ;; on blank lines in-between.
  3908. (should
  3909. (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
  3910. (org-forward-sentence)
  3911. (eobp)))
  3912. ;; Headlines are considered to be sentences by themselves, even if
  3913. ;; they do not end with a full stop.
  3914. (should
  3915. (equal
  3916. "* Headline"
  3917. (org-test-with-temp-text "* <point>Headline\nSentence."
  3918. (org-forward-sentence)
  3919. (buffer-substring-no-properties (line-beginning-position) (point)))))
  3920. (should
  3921. (org-test-with-temp-text "* Headline<point>\nSentence."
  3922. (org-forward-sentence)
  3923. (eobp)))
  3924. (should
  3925. (org-test-with-temp-text "Sentence.<point>\n\n* Headline\n\nSentence 2."
  3926. (org-forward-sentence)
  3927. (and (org-at-heading-p) (eolp)))))
  3928. (ert-deftest test-org/backward-sentence ()
  3929. "Test `org-backward-sentence' specifications."
  3930. ;; At the beginning of a table cell, move to the beginning of the
  3931. ;; previous one.
  3932. (should
  3933. (org-test-with-temp-text "| a | <point>b |"
  3934. (org-backward-sentence)
  3935. (looking-at "a | b |$")))
  3936. ;; Elsewhere in a cell, move to its beginning.
  3937. (should
  3938. (org-test-with-temp-text "| a | b<point>c |"
  3939. (org-backward-sentence)
  3940. (looking-at "bc |$")))
  3941. ;; Otherwise, simply call `backward-sentence'.
  3942. (should
  3943. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3944. (org-backward-sentence)
  3945. (looking-at "Sentence 2.")))
  3946. (should
  3947. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3948. (org-backward-sentence)
  3949. (org-backward-sentence)
  3950. (bobp)))
  3951. ;; Make sure to hit the beginning of a sentence on the same line as
  3952. ;; an item.
  3953. (should
  3954. (org-test-with-temp-text "- Line 1\n line <point>2."
  3955. (org-backward-sentence)
  3956. (looking-at "Line 1"))))
  3957. (ert-deftest test-org/forward-paragraph ()
  3958. "Test `org-forward-paragraph' specifications."
  3959. ;; At end of buffer, do not return an error.
  3960. (should
  3961. (org-test-with-temp-text "Paragraph"
  3962. (goto-char (point-max))
  3963. (org-forward-paragraph)
  3964. t))
  3965. ;; Standard test.
  3966. (should
  3967. (= 2
  3968. (org-test-with-temp-text "P1\n\nP2"
  3969. (org-forward-paragraph)
  3970. (org-current-line))))
  3971. (should
  3972. (= 2
  3973. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  3974. (org-forward-paragraph)
  3975. (org-current-line))))
  3976. ;; Enter greater elements.
  3977. (should
  3978. (= 2
  3979. (org-test-with-temp-text "#+begin_center\nP1\n#+end_center\nP2"
  3980. (org-forward-paragraph)
  3981. (org-current-line))))
  3982. ;; Do not enter elements with invisible contents.
  3983. (should
  3984. (= 4
  3985. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  3986. (org-cycle)
  3987. (org-forward-paragraph)
  3988. (org-current-line))))
  3989. (should
  3990. (= 6
  3991. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\nP3"
  3992. (org-fold-hide-block-toggle)
  3993. (org-forward-paragraph)
  3994. (org-current-line))))
  3995. ;; On an item or a footnote definition, move past the first element
  3996. ;; inside, if any.
  3997. (should
  3998. (= 2
  3999. (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
  4000. (org-forward-paragraph)
  4001. (org-current-line))))
  4002. (should
  4003. (= 2
  4004. (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
  4005. (org-forward-paragraph)
  4006. (org-current-line))))
  4007. ;; On a table (resp. a property drawer) do not move through table
  4008. ;; rows (resp. node properties).
  4009. (should
  4010. (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
  4011. (org-forward-paragraph)
  4012. (looking-at "Paragraph")))
  4013. (should
  4014. (org-test-with-temp-text
  4015. "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
  4016. (org-forward-paragraph)
  4017. (looking-at "Paragraph")))
  4018. ;; Skip consecutive keywords, clocks and diary S-exps.
  4019. (should
  4020. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n"
  4021. (org-forward-paragraph)
  4022. (eobp)))
  4023. (should
  4024. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n"
  4025. (org-forward-paragraph)
  4026. (eobp)))
  4027. (should
  4028. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n"
  4029. (org-forward-paragraph)
  4030. (eobp)))
  4031. (should-not
  4032. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n"
  4033. (org-forward-paragraph)
  4034. (eobp)))
  4035. (should-not
  4036. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n"
  4037. (org-forward-paragraph)
  4038. (eobp)))
  4039. ;; In a plain list with one item every line, skip the whole list,
  4040. ;; even with point in the middle of the list.
  4041. (should
  4042. (org-test-with-temp-text "- A\n - B\n- C\n"
  4043. (org-forward-paragraph)
  4044. (eobp)))
  4045. (should
  4046. (org-test-with-temp-text "- A\n - <point>B\n- C\n"
  4047. (org-forward-paragraph)
  4048. (eobp)))
  4049. ;; On a comment, verse or source block, stop at "contents"
  4050. ;; boundaries and blank lines.
  4051. (should
  4052. (= 2
  4053. (org-test-with-temp-text "#+begin_src emacs-lisp\nL1\n\nL2\n#+end_src"
  4054. (org-forward-paragraph)
  4055. (org-current-line))))
  4056. (should
  4057. (= 3
  4058. (org-test-with-temp-text "#+begin_verse\n<point>L1\n\nL2\n#+end_verse"
  4059. (org-forward-paragraph)
  4060. (org-current-line))))
  4061. (should
  4062. (= 5
  4063. (org-test-with-temp-text "#+begin_comment\nL1\n\n<point>L2\n#+end_comment"
  4064. (org-forward-paragraph)
  4065. (org-current-line))))
  4066. ;; Being on an affiliated keyword shouldn't make any difference.
  4067. (should
  4068. (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
  4069. (org-forward-paragraph)
  4070. (eobp))))
  4071. (ert-deftest test-org/backward-paragraph ()
  4072. "Test `org-backward-paragraph' specifications."
  4073. ;; Do not error at beginning of buffer.
  4074. (should
  4075. (org-test-with-temp-text "Paragraph"
  4076. (org-backward-paragraph)
  4077. t))
  4078. ;; At blank lines at the very beginning of a buffer, move to
  4079. ;; point-min.
  4080. (should
  4081. (org-test-with-temp-text "\n\n<point>\n\nParagraph"
  4082. (org-backward-paragraph)
  4083. (bobp)))
  4084. ;; Regular test.
  4085. (should
  4086. (= 2
  4087. (org-test-with-temp-text "P1\n\nP2<point>"
  4088. (org-backward-paragraph)
  4089. (org-current-line))))
  4090. (should
  4091. (= 4
  4092. (org-test-with-temp-text "P1\n\nP2\n\nP3<point>"
  4093. (org-backward-paragraph)
  4094. (org-current-line))))
  4095. ;; Try to move on the line above current element.
  4096. (should
  4097. (= 2
  4098. (org-test-with-temp-text "\n\n<point>Paragraph"
  4099. (org-backward-paragraph)
  4100. (org-current-line))))
  4101. ;; Do not leave point in an invisible area.
  4102. (should
  4103. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  4104. (org-cycle)
  4105. (goto-char (point-max))
  4106. (beginning-of-line)
  4107. (org-backward-paragraph)
  4108. (bobp)))
  4109. (should
  4110. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\n"
  4111. (org-fold-hide-block-toggle)
  4112. (goto-char (point-max))
  4113. (org-backward-paragraph)
  4114. (bobp)))
  4115. ;; On the first element in an item or a footnote definition, jump
  4116. ;; before the footnote or the item.
  4117. (should
  4118. (org-test-with-temp-text "- line1<point>"
  4119. (org-backward-paragraph)
  4120. (bobp)))
  4121. (should
  4122. (org-test-with-temp-text "[fn:1] line1n<point>"
  4123. (org-backward-paragraph)
  4124. (bobp)))
  4125. ;; On the second element in an item or a footnote definition, jump
  4126. ;; to item or the definition.
  4127. (should
  4128. (= 2
  4129. (org-test-with-temp-text "- line1\n\n<point> line2"
  4130. (org-backward-paragraph)
  4131. (org-current-line))))
  4132. (should
  4133. (= 2
  4134. (org-test-with-temp-text "[fn:1] line1\n\n<point> line2"
  4135. (org-backward-paragraph)
  4136. (org-current-line))))
  4137. ;; On a table (resp. a property drawer), ignore table rows
  4138. ;; (resp. node properties).
  4139. (should
  4140. (org-test-with-temp-text "| a | b |\n| c | d |\n<point>P1"
  4141. (org-backward-paragraph)
  4142. (bobp)))
  4143. (should
  4144. (= 2
  4145. (org-test-with-temp-text
  4146. "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
  4147. (org-backward-paragraph)
  4148. (org-current-line))))
  4149. ;; In a plain list with one item every line, skip the whole list,
  4150. ;; even with point in the middle of the list.
  4151. (should
  4152. (org-test-with-temp-text "- A\n - B\n- C\n<point>"
  4153. (org-backward-paragraph)
  4154. (bobp)))
  4155. (should
  4156. (org-test-with-temp-text "- A\n - B\n- <point>C\n"
  4157. (org-backward-paragraph)
  4158. (bobp)))
  4159. ;; Skip consecutive keywords, clocks and diary S-exps.
  4160. (should
  4161. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n<point>"
  4162. (org-backward-paragraph)
  4163. (bobp)))
  4164. (should
  4165. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n<point>"
  4166. (org-backward-paragraph)
  4167. (bobp)))
  4168. (should
  4169. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n<point>"
  4170. (org-backward-paragraph)
  4171. (bobp)))
  4172. (should-not
  4173. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n<point>"
  4174. (org-backward-paragraph)
  4175. (bobp)))
  4176. (should-not
  4177. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n<point>"
  4178. (org-backward-paragraph)
  4179. (bobp)))
  4180. ;; On a comment, example, source and verse blocks, stop at blank
  4181. ;; lines.
  4182. (should
  4183. (= 1
  4184. (org-test-with-temp-text
  4185. "#+begin_comment\n<point>L1\n\nL2\n\nL3\n#+end_comment"
  4186. (org-backward-paragraph)
  4187. (org-current-line))))
  4188. (should
  4189. (= 2
  4190. (org-test-with-temp-text
  4191. "#+begin_verse\nL1\n\n<point>L2\n\nL3\n#+end_verse"
  4192. (org-backward-paragraph)
  4193. (org-current-line))))
  4194. (should
  4195. (= 3
  4196. (org-test-with-temp-text
  4197. "#+begin_src emacs-lisp\nL1\n\nL2\n\n<point>L3\n#+end_src"
  4198. (org-backward-paragraph)
  4199. (org-current-line))))
  4200. ;; When called from the opening line itself, however, move to
  4201. ;; beginning of block.
  4202. (should
  4203. (org-test-with-temp-text "#+begin_<point>example\nL1\n#+end_example"
  4204. (org-backward-paragraph)
  4205. (bobp)))
  4206. ;; On an empty heading, move above it.
  4207. (should
  4208. (org-test-with-temp-text "\n* <point>"
  4209. (org-backward-paragraph)
  4210. (bobp)))
  4211. (should
  4212. (org-test-with-temp-text "\n* \n<point>"
  4213. (org-backward-paragraph)
  4214. (bobp))))
  4215. (ert-deftest test-org/forward-element ()
  4216. "Test `org-forward-element' specifications."
  4217. ;; 1. At EOB: should error.
  4218. (org-test-with-temp-text "Some text\n"
  4219. (goto-char (point-max))
  4220. (should-error (org-forward-element)))
  4221. ;; 2. Standard move: expected to ignore blank lines.
  4222. (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
  4223. (org-forward-element)
  4224. (should (looking-at (regexp-quote "Second paragraph."))))
  4225. ;; 3. Headline tests.
  4226. (org-test-with-temp-text "
  4227. * Head 1
  4228. ** Head 1.1
  4229. *** Head 1.1.1
  4230. ** Head 1.2"
  4231. ;; 3.1. At an headline beginning: move to next headline at the
  4232. ;; same level.
  4233. (goto-line 3)
  4234. (org-forward-element)
  4235. (should (looking-at (regexp-quote "** Head 1.2")))
  4236. ;; 3.2. At an headline beginning: move to parent headline if no
  4237. ;; headline at the same level.
  4238. (goto-line 3)
  4239. (org-forward-element)
  4240. (should (looking-at (regexp-quote "** Head 1.2"))))
  4241. ;; 4. Greater element tests.
  4242. (org-test-with-temp-text
  4243. "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
  4244. ;; 4.1. At a greater element: expected to skip contents.
  4245. (org-forward-element)
  4246. (should (looking-at (regexp-quote "Outside.")))
  4247. ;; 4.2. At the end of greater element contents: expected to skip
  4248. ;; to the end of the greater element.
  4249. (goto-line 2)
  4250. (org-forward-element)
  4251. (should (looking-at (regexp-quote "Outside."))))
  4252. ;; 5. List tests.
  4253. (org-test-with-temp-text "
  4254. - item1
  4255. - sub1
  4256. - sub2
  4257. - sub3
  4258. Inner paragraph.
  4259. - item2
  4260. Outside."
  4261. ;; 5.1. At list top point: expected to move to the element after
  4262. ;; the list.
  4263. (goto-line 2)
  4264. (org-forward-element)
  4265. (should (looking-at (regexp-quote "Outside.")))
  4266. ;; 5.2. Special case: at the first line of a sub-list, but not at
  4267. ;; beginning of line, move to next item.
  4268. (goto-line 2)
  4269. (forward-char)
  4270. (org-forward-element)
  4271. (should (looking-at "- item2"))
  4272. (goto-line 4)
  4273. (forward-char)
  4274. (org-forward-element)
  4275. (should (looking-at " - sub2"))
  4276. ;; 5.3 At sub-list beginning: expected to move after the sub-list.
  4277. (goto-line 4)
  4278. (org-forward-element)
  4279. (should (looking-at (regexp-quote " Inner paragraph.")))
  4280. ;; 5.4. At sub-list end: expected to move outside the sub-list.
  4281. (goto-line 8)
  4282. (org-forward-element)
  4283. (should (looking-at (regexp-quote " Inner paragraph.")))
  4284. ;; 5.5. At an item: expected to move to next item, if any.
  4285. (goto-line 6)
  4286. (org-forward-element)
  4287. (should (looking-at " - sub3"))))
  4288. (ert-deftest test-org/backward-element ()
  4289. "Test `org-backward-element' specifications."
  4290. ;; 1. Should error at BOB.
  4291. (org-test-with-temp-text " \nParagraph."
  4292. (should-error (org-backward-element)))
  4293. ;; 2. Should move at BOB when called on the first element in buffer.
  4294. (should
  4295. (org-test-with-temp-text "\n#+TITLE: test"
  4296. (progn (forward-line)
  4297. (org-backward-element)
  4298. (bobp))))
  4299. ;; 3. Not at the beginning of an element: move at its beginning.
  4300. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  4301. (goto-line 3)
  4302. (end-of-line)
  4303. (org-backward-element)
  4304. (should (looking-at (regexp-quote "Paragraph2."))))
  4305. ;; 4. Headline tests.
  4306. (org-test-with-temp-text "
  4307. * Head 1
  4308. ** Head 1.1
  4309. *** Head 1.1.1
  4310. ** Head 1.2"
  4311. ;; 4.1. At an headline beginning: move to previous headline at the
  4312. ;; same level.
  4313. (goto-line 5)
  4314. (org-backward-element)
  4315. (should (looking-at (regexp-quote "** Head 1.1")))
  4316. ;; 4.2. At an headline beginning: move to parent headline if no
  4317. ;; headline at the same level.
  4318. (goto-line 3)
  4319. (org-backward-element)
  4320. (should (looking-at (regexp-quote "* Head 1")))
  4321. ;; 4.3. At the first top-level headline: should error.
  4322. (goto-line 2)
  4323. (should-error (org-backward-element)))
  4324. ;; 5. At beginning of first element inside a greater element:
  4325. ;; expected to move to greater element's beginning.
  4326. (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
  4327. (goto-line 3)
  4328. (org-backward-element)
  4329. (should (looking-at "#\\+BEGIN_CENTER")))
  4330. ;; 6. At the beginning of the first element in a section: should
  4331. ;; move back to headline, if any.
  4332. (should
  4333. (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
  4334. (progn (goto-char (point-max))
  4335. (beginning-of-line)
  4336. (org-backward-element)
  4337. (org-at-heading-p))))
  4338. ;; 7. List tests.
  4339. (org-test-with-temp-text "
  4340. - item1
  4341. - sub1
  4342. - sub2
  4343. - sub3
  4344. Inner paragraph.
  4345. - item2
  4346. Outside."
  4347. ;; 7.1. At beginning of sub-list: expected to move to the
  4348. ;; paragraph before it.
  4349. (goto-line 4)
  4350. (org-backward-element)
  4351. (should (looking-at "item1"))
  4352. ;; 7.2. At an item in a list: expected to move at previous item.
  4353. (goto-line 8)
  4354. (org-backward-element)
  4355. (should (looking-at " - sub2"))
  4356. (goto-line 12)
  4357. (org-backward-element)
  4358. (should (looking-at "- item1"))
  4359. ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
  4360. ;; beginning.
  4361. (goto-line 10)
  4362. (org-backward-element)
  4363. (should (looking-at " - sub1"))
  4364. (goto-line 15)
  4365. (org-backward-element)
  4366. (should (looking-at "- item1"))
  4367. ;; 7.4. At blank-lines before list end: expected to move to top
  4368. ;; item.
  4369. (goto-line 14)
  4370. (org-backward-element)
  4371. (should (looking-at "- item1"))))
  4372. (ert-deftest test-org/up-element ()
  4373. "Test `org-up-element' specifications."
  4374. ;; 1. At BOB or with no surrounding element: should error.
  4375. (org-test-with-temp-text "Paragraph."
  4376. (should-error (org-up-element)))
  4377. (org-test-with-temp-text "* Head1\n* Head2"
  4378. (goto-line 2)
  4379. (should-error (org-up-element)))
  4380. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  4381. (goto-line 3)
  4382. (should-error (org-up-element)))
  4383. ;; 2. At an headline: move to parent headline.
  4384. (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
  4385. (goto-line 3)
  4386. (org-up-element)
  4387. (should (looking-at "\\* Head1")))
  4388. ;; 3. Inside a greater element: move to greater element beginning.
  4389. (org-test-with-temp-text
  4390. "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
  4391. (goto-line 3)
  4392. (org-up-element)
  4393. (should (looking-at "#\\+BEGIN_CENTER")))
  4394. ;; 4. List tests.
  4395. (org-test-with-temp-text "* Top
  4396. - item1
  4397. - sub1
  4398. - sub2
  4399. Paragraph within sub2.
  4400. - item2"
  4401. ;; 4.1. Within an item: move to the item beginning.
  4402. (goto-line 8)
  4403. (org-up-element)
  4404. (should (looking-at " - sub2"))
  4405. ;; 4.2. At an item in a sub-list: move to parent item.
  4406. (goto-line 4)
  4407. (org-up-element)
  4408. (should (looking-at "- item1"))
  4409. ;; 4.3. At an item in top list: move to beginning of whole list.
  4410. (goto-line 10)
  4411. (org-up-element)
  4412. (should (looking-at "- item1"))
  4413. ;; 4.4. Special case. At very top point: should move to parent of
  4414. ;; list.
  4415. (goto-line 2)
  4416. (org-up-element)
  4417. (should (looking-at "\\* Top"))))
  4418. (ert-deftest test-org/down-element ()
  4419. "Test `org-down-element' specifications."
  4420. ;; Error when the element hasn't got a recursive type.
  4421. (org-test-with-temp-text "Paragraph."
  4422. (should-error (org-down-element)))
  4423. ;; Error when the element has no contents
  4424. (org-test-with-temp-text "* Headline"
  4425. (should-error (org-down-element)))
  4426. ;; When at a plain-list, move to first item.
  4427. (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
  4428. (goto-line 2)
  4429. (org-down-element)
  4430. (should (looking-at " - Item 1.1")))
  4431. (org-test-with-temp-text "#+NAME: list\n- Item 1"
  4432. (org-down-element)
  4433. (should (looking-at " Item 1")))
  4434. ;; When at a table, move to first row
  4435. (org-test-with-temp-text "#+NAME: table\n| a | b |"
  4436. (org-down-element)
  4437. (should (looking-at " a | b |")))
  4438. ;; Otherwise, move inside the greater element.
  4439. (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
  4440. (org-down-element)
  4441. (should (looking-at "Paragraph"))))
  4442. (ert-deftest test-org/drag-element-backward ()
  4443. "Test `org-drag-element-backward' specifications."
  4444. ;; Standard test.
  4445. (should
  4446. (equal
  4447. "#+key2: val2\n#+key1: val1\n#+key3: val3"
  4448. (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
  4449. (org-drag-element-backward)
  4450. (buffer-string))))
  4451. (should
  4452. (equal
  4453. "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
  4454. (org-test-with-temp-text
  4455. "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
  4456. (org-drag-element-backward)
  4457. (buffer-string))))
  4458. ;; Preserve blank lines.
  4459. (should
  4460. (equal "Paragraph 2\n\n\nPara1\n\nPara3"
  4461. (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
  4462. (org-drag-element-backward)
  4463. (buffer-string))))
  4464. ;; Preserve column.
  4465. (should
  4466. (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
  4467. (org-drag-element-backward)
  4468. (looking-at-p "2")))
  4469. ;; Error when trying to move first element of buffer.
  4470. (should-error
  4471. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4472. (org-drag-element-backward))
  4473. :type 'user-error)
  4474. ;; Error when trying to swap nested elements.
  4475. (should-error
  4476. (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
  4477. (org-drag-element-backward))
  4478. :type 'user-error)
  4479. ;; Error when trying to swap an headline element and a non-headline
  4480. ;; element.
  4481. (should-error
  4482. (org-test-with-temp-text "Test.\n<point>* Head 1"
  4483. (org-drag-element-backward))
  4484. :type 'error)
  4485. ;; Error when called before first element.
  4486. (should-error
  4487. (org-test-with-temp-text "\n<point>"
  4488. (org-drag-element-backward))
  4489. :type 'user-error)
  4490. ;; Preserve visibility of elements and their contents.
  4491. (should
  4492. (equal '((63 . 82) (26 . 48))
  4493. (let ((org-fold-core-style 'text-properties))
  4494. (org-test-with-temp-text
  4495. "
  4496. #+BEGIN_CENTER
  4497. Text.
  4498. #+END_CENTER
  4499. - item 1
  4500. #+BEGIN_QUOTE
  4501. Text.
  4502. #+END_QUOTE"
  4503. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4504. (search-backward "- item 1")
  4505. (org-drag-element-backward)
  4506. (let (regions)
  4507. (goto-char (point-min))
  4508. (while (< (point) (point-max))
  4509. (let ((region (org-fold-get-region-at-point)))
  4510. (if (not region)
  4511. (goto-char (org-fold-next-folding-state-change))
  4512. (goto-char (cdr region))
  4513. (push region regions))))
  4514. regions)))))
  4515. (should
  4516. (equal '((63 . 82) (26 . 48))
  4517. (let ((org-fold-core-style 'overlays))
  4518. (org-test-with-temp-text
  4519. "
  4520. #+BEGIN_CENTER
  4521. Text.
  4522. #+END_CENTER
  4523. - item 1
  4524. #+BEGIN_QUOTE
  4525. Text.
  4526. #+END_QUOTE"
  4527. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4528. (search-backward "- item 1")
  4529. (org-drag-element-backward)
  4530. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4531. (overlays-in (point-min) (point-max)))))))
  4532. ;; Pathological case: handle call with point in blank lines right
  4533. ;; after a headline.
  4534. (should
  4535. (equal "* H2\n\n* H1\nText\n"
  4536. (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
  4537. (org-drag-element-backward)
  4538. (buffer-string)))))
  4539. (ert-deftest test-org/drag-element-forward ()
  4540. "Test `org-drag-element-forward' specifications."
  4541. ;; 1. Error when trying to move first element of buffer.
  4542. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4543. (goto-line 3)
  4544. (should-error (org-drag-element-forward)))
  4545. ;; 2. Error when trying to swap nested elements.
  4546. (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
  4547. (forward-line)
  4548. (should-error (org-drag-element-forward)))
  4549. ;; 3. Error when trying to swap a non-headline element and an
  4550. ;; headline.
  4551. (org-test-with-temp-text "Test.\n* Head 1"
  4552. (should-error (org-drag-element-forward)))
  4553. ;; 4. Error when called before first element.
  4554. (should-error
  4555. (org-test-with-temp-text "\n"
  4556. (forward-line)
  4557. (org-drag-element-backward))
  4558. :type 'user-error)
  4559. ;; 5. Otherwise, swap elements, preserving column and blank lines
  4560. ;; between elements.
  4561. (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
  4562. (search-forward "graph")
  4563. (org-drag-element-forward)
  4564. (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
  4565. (should (looking-at " 1")))
  4566. ;; 5. Preserve visibility of elements and their contents.
  4567. (let ((org-fold-core-style 'text-properties))
  4568. (org-test-with-temp-text
  4569. "
  4570. #+BEGIN_CENTER
  4571. Text.
  4572. #+END_CENTER
  4573. - item 1
  4574. #+BEGIN_QUOTE
  4575. Text.
  4576. #+END_QUOTE"
  4577. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4578. (search-backward "#+BEGIN_CENTER")
  4579. (org-drag-element-forward)
  4580. (should
  4581. (equal
  4582. '((63 . 82) (26 . 48))
  4583. (let (regions)
  4584. (goto-char (point-min))
  4585. (while (< (point) (point-max))
  4586. (let ((region (org-fold-get-region-at-point)))
  4587. (if (not region)
  4588. (goto-char (org-fold-next-folding-state-change))
  4589. (goto-char (cdr region))
  4590. (push region regions))))
  4591. regions)))))
  4592. (let ((org-fold-core-style 'overlays))
  4593. (org-test-with-temp-text
  4594. "
  4595. #+BEGIN_CENTER
  4596. Text.
  4597. #+END_CENTER
  4598. - item 1
  4599. #+BEGIN_QUOTE
  4600. Text.
  4601. #+END_QUOTE"
  4602. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4603. (search-backward "#+BEGIN_CENTER")
  4604. (org-drag-element-forward)
  4605. (should
  4606. (equal
  4607. '((63 . 82) (26 . 48))
  4608. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4609. (overlays-in (point-min) (point-max))))))))
  4610. (ert-deftest test-org/next-block ()
  4611. "Test `org-next-block' specifications."
  4612. ;; Regular test.
  4613. (should
  4614. (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  4615. (org-next-block 1)
  4616. (looking-at "#\\+BEGIN_CENTER")))
  4617. ;; Ignore case.
  4618. (should
  4619. (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
  4620. (let ((case-fold-search nil))
  4621. (org-next-block 1)
  4622. (looking-at "#\\+begin_center"))))
  4623. ;; Ignore current line.
  4624. (should
  4625. (org-test-with-temp-text
  4626. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
  4627. (org-next-block 1)
  4628. (looking-at "#\\+BEGIN_CENTER")))
  4629. ;; Throw an error when no block is found.
  4630. (should-error
  4631. (org-test-with-temp-text "Paragraph"
  4632. (org-next-block 1)))
  4633. ;; With an argument, skip many blocks at once.
  4634. (should
  4635. (org-test-with-temp-text
  4636. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4637. (org-next-block 2)
  4638. (looking-at "#\\+BEGIN_QUOTE")))
  4639. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4640. (should
  4641. (org-test-with-temp-text
  4642. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4643. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4644. (looking-at "#\\+BEGIN_QUOTE")))
  4645. ;; Optional argument is also case-insensitive.
  4646. (should
  4647. (org-test-with-temp-text
  4648. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
  4649. (let ((case-fold-search nil))
  4650. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4651. (looking-at "#\\+begin_quote")))))
  4652. (ert-deftest test-org/insert-structure-template ()
  4653. "Test `org-insert-structure-template'."
  4654. ;; Test in empty buffer.
  4655. (should
  4656. (string= "#+begin_foo\n#+end_foo\n"
  4657. (org-test-with-temp-text ""
  4658. (org-insert-structure-template "foo")
  4659. (buffer-string))))
  4660. ;; Test with multiple lines in buffer.
  4661. (should
  4662. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4663. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4664. (transient-mark-mode 1)
  4665. (org-mark-element)
  4666. (org-insert-structure-template "foo")
  4667. (buffer-string))))
  4668. ;; Mark only the current line.
  4669. (should
  4670. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4671. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4672. (transient-mark-mode 1)
  4673. (set-mark (point-min))
  4674. (end-of-line)
  4675. (org-insert-structure-template "foo")
  4676. (buffer-string))))
  4677. ;; Middle of paragraph.
  4678. (should
  4679. (string= "p1\n#+begin_foo\np2\n#+end_foo\np3"
  4680. (org-test-with-temp-text "p1\n<point>p2\np3"
  4681. (set-mark (line-beginning-position))
  4682. (end-of-line)
  4683. (activate-mark)
  4684. (org-insert-structure-template "foo")
  4685. (buffer-string))))
  4686. ;; Test with text in buffer, no region, no final newline.
  4687. (should
  4688. (string= "#+begin_foo\nI'm a paragraph.\n#+end_foo\n"
  4689. (org-test-with-temp-text "I'm a paragraph."
  4690. (org-mark-element)
  4691. (org-insert-structure-template "foo")
  4692. (buffer-string))))
  4693. ;; Test with text in buffer and region set.
  4694. (should
  4695. (string= "#+begin_foo\nI'm a paragraph\n\nI'm a second paragrah\n#+end_foo\n"
  4696. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragrah"
  4697. (set-mark (point))
  4698. (goto-char (point-max))
  4699. (org-insert-structure-template "foo")
  4700. (buffer-string))))
  4701. ;; Test with example escaping.
  4702. (should
  4703. (string= "#+begin_example\n,* Heading\n#+end_example\n"
  4704. (org-test-with-temp-text "* Heading"
  4705. (org-mark-element)
  4706. (org-insert-structure-template "example")
  4707. (buffer-string))))
  4708. ;; Test with indentation.
  4709. (should
  4710. (string= " #+begin_foo\n This is a paragraph\n #+end_foo\n"
  4711. (org-test-with-temp-text " This is a paragraph"
  4712. (org-mark-element)
  4713. (org-insert-structure-template "foo")
  4714. (buffer-string))))
  4715. (should
  4716. (string= " #+begin_foo\n Line 1\n Line2\n #+end_foo\n"
  4717. (org-test-with-temp-text " Line 1\n Line2"
  4718. (org-mark-element)
  4719. (org-insert-structure-template "foo")
  4720. (buffer-string))))
  4721. ;; Test point location.
  4722. (should
  4723. (string= "#+begin_foo\n"
  4724. (org-test-with-temp-text ""
  4725. (org-insert-structure-template "foo")
  4726. (buffer-substring (point-min) (point)))))
  4727. (should
  4728. (string= "#+begin_src "
  4729. (org-test-with-temp-text ""
  4730. (org-insert-structure-template "src")
  4731. (buffer-substring (point-min) (point))))))
  4732. (ert-deftest test-org/previous-block ()
  4733. "Test `org-previous-block' specifications."
  4734. ;; Regular test.
  4735. (should
  4736. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
  4737. (org-previous-block 1)
  4738. (looking-at "#\\+BEGIN_CENTER")))
  4739. ;; Ignore case.
  4740. (should
  4741. (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
  4742. (let ((case-fold-search nil))
  4743. (org-previous-block 1)
  4744. (looking-at "#\\+begin_center"))))
  4745. ;; Ignore current line.
  4746. (should
  4747. (org-test-with-temp-text
  4748. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
  4749. (org-previous-block 1)
  4750. (looking-at "#\\+BEGIN_QUOTE")))
  4751. ;; Throw an error when no block is found.
  4752. (should-error
  4753. (org-test-with-temp-text "Paragraph<point>"
  4754. (org-previous-block 1)))
  4755. ;; With an argument, skip many blocks at once.
  4756. (should
  4757. (org-test-with-temp-text
  4758. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4759. (org-previous-block 2)
  4760. (looking-at "#\\+BEGIN_CENTER")))
  4761. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4762. (should
  4763. (org-test-with-temp-text
  4764. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4765. (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4766. (looking-at "#\\+BEGIN_QUOTE")))
  4767. ;; Optional argument is also case-insensitive.
  4768. (should
  4769. (org-test-with-temp-text
  4770. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
  4771. (let ((case-fold-search nil))
  4772. (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4773. (looking-at "#\\+begin_quote")))))
  4774. ;;; Outline structure
  4775. (ert-deftest test-org/demote ()
  4776. "Test `org-demote' specifications."
  4777. ;; Add correct number of stars according to `org-odd-levels-only'.
  4778. (should
  4779. (= 2
  4780. (org-test-with-temp-text "* H"
  4781. (let ((org-odd-levels-only nil)) (org-demote))
  4782. (org-current-level))))
  4783. (should
  4784. (= 3
  4785. (org-test-with-temp-text "* H"
  4786. (let ((org-odd-levels-only t)) (org-demote))
  4787. (org-current-level))))
  4788. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4789. (should
  4790. (org-test-with-temp-text "* H :tag:"
  4791. (let ((org-tags-column 10)
  4792. (org-auto-align-tags t)
  4793. (org-odd-levels-only nil))
  4794. (org-demote))
  4795. (org-move-to-column 10)
  4796. (looking-at-p ":tag:$")))
  4797. (should-not
  4798. (org-test-with-temp-text "* H :tag:"
  4799. (let ((org-tags-column 10)
  4800. (org-auto-align-tags nil)
  4801. (org-odd-levels-only nil))
  4802. (org-demote))
  4803. (org-move-to-column 10)
  4804. (looking-at-p ":tag:$")))
  4805. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4806. ;; info and property drawers accordingly.
  4807. (should
  4808. (= 3
  4809. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4810. (let ((org-odd-levels-only nil)
  4811. (org-adapt-indentation t))
  4812. (org-demote))
  4813. (forward-line)
  4814. (org-get-indentation))))
  4815. (should
  4816. (= 3
  4817. (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4818. (let ((org-odd-levels-only nil)
  4819. (org-adapt-indentation t))
  4820. (org-demote))
  4821. (forward-line)
  4822. (org-get-indentation))))
  4823. (should-not
  4824. (= 3
  4825. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4826. (let ((org-odd-levels-only nil)
  4827. (org-adapt-indentation nil))
  4828. (org-demote))
  4829. (forward-line)
  4830. (org-get-indentation))))
  4831. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4832. ;; section accordingly. Ignore, however, footnote definitions and
  4833. ;; inlinetasks boundaries.
  4834. (should
  4835. (= 3
  4836. (org-test-with-temp-text "* H\n Paragraph"
  4837. (let ((org-odd-levels-only nil)
  4838. (org-adapt-indentation t))
  4839. (org-demote))
  4840. (forward-line)
  4841. (org-get-indentation))))
  4842. (should
  4843. (= 2
  4844. (org-test-with-temp-text "* H\n Paragraph"
  4845. (let ((org-odd-levels-only nil)
  4846. (org-adapt-indentation nil))
  4847. (org-demote))
  4848. (forward-line)
  4849. (org-get-indentation))))
  4850. (should
  4851. (zerop
  4852. (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
  4853. (let ((org-odd-levels-only nil)
  4854. (org-adapt-indentation t))
  4855. (org-demote))
  4856. (goto-char (point-max))
  4857. (org-get-indentation))))
  4858. (should
  4859. (= 3
  4860. (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
  4861. (let ((org-odd-levels-only nil)
  4862. (org-adapt-indentation t))
  4863. (org-demote))
  4864. (goto-char (point-max))
  4865. (org-get-indentation))))
  4866. (when (featurep 'org-inlinetask)
  4867. (should
  4868. (zerop
  4869. (let ((org-inlinetask-min-level 5)
  4870. (org-adapt-indentation t))
  4871. (org-test-with-temp-text "* H\n***** I\n***** END"
  4872. (org-demote)
  4873. (forward-line)
  4874. (org-get-indentation))))))
  4875. (when (featurep 'org-inlinetask)
  4876. (should
  4877. (= 3
  4878. (let ((org-inlinetask-min-level 5)
  4879. (org-adapt-indentation t))
  4880. (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
  4881. (org-demote)
  4882. (forward-line 2)
  4883. (org-get-indentation))))))
  4884. ;; When `org-adapt-indentation' is non-nil, log drawers are
  4885. ;; adjusted.
  4886. (should
  4887. (equal
  4888. "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4889. (org-test-with-temp-text "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4890. (let ((org-odd-levels-only nil)
  4891. (org-adapt-indentation t))
  4892. (org-demote))
  4893. (buffer-string))))
  4894. (should
  4895. (equal
  4896. "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4897. (org-test-with-temp-text "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4898. (let ((org-odd-levels-only nil)
  4899. (org-adapt-indentation 'headline-data))
  4900. (org-demote))
  4901. (buffer-string))))
  4902. (should
  4903. (equal
  4904. "** H\n :LOGBOOK:\n - a\n :END:"
  4905. (org-test-with-temp-text "* H\n:LOGBOOK:\n- a\n:END:"
  4906. (let ((org-odd-levels-only nil)
  4907. (org-adapt-indentation t))
  4908. (org-demote))
  4909. (buffer-string))))
  4910. ;; Ignore contents of source blocks or example blocks when
  4911. ;; indentation should be preserved (through
  4912. ;; `org-src-preserve-indentation' or "-i" flag).
  4913. (should-not
  4914. (zerop
  4915. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4916. (let ((org-adapt-indentation t)
  4917. (org-src-preserve-indentation nil))
  4918. (org-demote))
  4919. (forward-line 2)
  4920. (org-get-indentation))))
  4921. (should
  4922. (zerop
  4923. (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
  4924. (let ((org-adapt-indentation t)
  4925. (org-src-preserve-indentation t))
  4926. (org-demote))
  4927. (forward-line 2)
  4928. (org-get-indentation))))
  4929. (should
  4930. (zerop
  4931. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4932. (let ((org-adapt-indentation t)
  4933. (org-src-preserve-indentation t))
  4934. (org-demote))
  4935. (forward-line 2)
  4936. (org-get-indentation))))
  4937. (should
  4938. (zerop
  4939. (org-test-with-temp-text
  4940. "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
  4941. (let ((org-adapt-indentation t)
  4942. (org-src-preserve-indentation nil))
  4943. (org-demote))
  4944. (forward-line 2)
  4945. (org-get-indentation)))))
  4946. (ert-deftest test-org/promote ()
  4947. "Test `org-promote' specifications."
  4948. ;; Return an error if headline is to be promoted to level 0, unless
  4949. ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
  4950. ;; headline becomes a comment.
  4951. (should-error
  4952. (org-test-with-temp-text "* H"
  4953. (let ((org-allow-promoting-top-level-subtree nil)) (org-promote))))
  4954. (should
  4955. (equal "# H"
  4956. (org-test-with-temp-text "* H"
  4957. (let ((org-allow-promoting-top-level-subtree t)) (org-promote))
  4958. (buffer-string))))
  4959. ;; Remove correct number of stars according to
  4960. ;; `org-odd-levels-only'.
  4961. (should
  4962. (= 2
  4963. (org-test-with-temp-text "*** H"
  4964. (let ((org-odd-levels-only nil)) (org-promote))
  4965. (org-current-level))))
  4966. (should
  4967. (= 1
  4968. (org-test-with-temp-text "*** H"
  4969. (let ((org-odd-levels-only t)) (org-promote))
  4970. (org-current-level))))
  4971. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4972. (should
  4973. (org-test-with-temp-text "** H :tag:"
  4974. (let ((org-tags-column 10)
  4975. (org-auto-align-tags t)
  4976. (org-odd-levels-only nil))
  4977. (org-promote))
  4978. (org-move-to-column 10)
  4979. (looking-at-p ":tag:$")))
  4980. (should-not
  4981. (org-test-with-temp-text "** H :tag:"
  4982. (let ((org-tags-column 10)
  4983. (org-auto-align-tags nil)
  4984. (org-odd-levels-only nil))
  4985. (org-promote))
  4986. (org-move-to-column 10)
  4987. (looking-at-p ":tag:$")))
  4988. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4989. ;; info and property drawers.
  4990. (should
  4991. (= 2
  4992. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4993. (let ((org-odd-levels-only nil)
  4994. (org-adapt-indentation t))
  4995. (org-promote))
  4996. (forward-line)
  4997. (org-get-indentation))))
  4998. (should
  4999. (= 2
  5000. (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  5001. (let ((org-odd-levels-only nil)
  5002. (org-adapt-indentation t))
  5003. (org-promote))
  5004. (forward-line)
  5005. (org-get-indentation))))
  5006. (should-not
  5007. (= 2
  5008. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  5009. (let ((org-odd-levels-only nil)
  5010. (org-adapt-indentation nil))
  5011. (org-promote))
  5012. (forward-line)
  5013. (org-get-indentation))))
  5014. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  5015. ;; section accordingly. Ignore, however, footnote definitions and
  5016. ;; inlinetasks boundaries.
  5017. (should
  5018. (= 2
  5019. (org-test-with-temp-text "** H\n Paragraph"
  5020. (let ((org-odd-levels-only nil)
  5021. (org-adapt-indentation t))
  5022. (org-promote))
  5023. (forward-line)
  5024. (org-get-indentation))))
  5025. (should-not
  5026. (= 2
  5027. (org-test-with-temp-text "** H\n Paragraph"
  5028. (let ((org-odd-levels-only nil)
  5029. (org-adapt-indentation nil))
  5030. (org-promote))
  5031. (forward-line)
  5032. (org-get-indentation))))
  5033. (should
  5034. (= 2
  5035. (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
  5036. (let ((org-odd-levels-only nil)
  5037. (org-adapt-indentation t))
  5038. (org-promote))
  5039. (forward-line)
  5040. (org-get-indentation))))
  5041. (when (featurep 'org-inlinetask)
  5042. (should
  5043. (zerop
  5044. (let ((org-inlinetask-min-level 5)
  5045. (org-adapt-indentation t))
  5046. (org-test-with-temp-text "** H\n***** I\n***** END"
  5047. (org-promote)
  5048. (forward-line)
  5049. (org-get-indentation))))))
  5050. (when (featurep 'org-inlinetask)
  5051. (should
  5052. (= 2
  5053. (let ((org-inlinetask-min-level 5)
  5054. (org-adapt-indentation t))
  5055. (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
  5056. (org-promote)
  5057. (forward-line 2)
  5058. (org-get-indentation))))))
  5059. ;; Give up shifting if it would break document's structure
  5060. ;; otherwise.
  5061. (should
  5062. (= 3
  5063. (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
  5064. (let ((org-odd-levels-only nil)
  5065. (org-adapt-indentation t))
  5066. (org-promote))
  5067. (forward-line)
  5068. (org-get-indentation))))
  5069. (should
  5070. (= 3
  5071. (org-test-with-temp-text "** H\n Paragraph\n * list."
  5072. (let ((org-odd-levels-only nil)
  5073. (org-adapt-indentation t))
  5074. (org-promote))
  5075. (forward-line)
  5076. (org-get-indentation))))
  5077. ;; When `org-adapt-indentation' is non-nil, log drawers are
  5078. ;; adjusted.
  5079. (should
  5080. (equal
  5081. "* H\n :LOGBOOK:\n - a\n :END:\n b"
  5082. (org-test-with-temp-text "** H\n :LOGBOOK:\n - a\n :END:\n b"
  5083. (let ((org-odd-levels-only nil)
  5084. (org-adapt-indentation t))
  5085. (org-promote))
  5086. (buffer-string))))
  5087. (should
  5088. (equal
  5089. "* H\n :LOGBOOK:\n - a\n :END:\n b"
  5090. (org-test-with-temp-text "** H\n :LOGBOOK:\n - a\n :END:\n b"
  5091. (let ((org-odd-levels-only nil)
  5092. (org-adapt-indentation 'headline-data))
  5093. (org-promote))
  5094. (buffer-string))))
  5095. (should
  5096. (equal
  5097. "* H\n:LOGBOOK:\n- a\n:END:"
  5098. (org-test-with-temp-text "** H\n:LOGBOOK:\n- a\n:END:"
  5099. (let ((org-odd-levels-only nil)
  5100. (org-adapt-indentation t))
  5101. (org-promote))
  5102. (buffer-string))))
  5103. (should
  5104. (equal
  5105. "# H\n:LOGBOOK:\n- a\n:END:"
  5106. (org-test-with-temp-text "* H\n:LOGBOOK:\n- a\n:END:"
  5107. (let ((org-odd-levels-only nil)
  5108. (org-allow-promoting-top-level-subtree t)
  5109. (org-adapt-indentation t))
  5110. (org-promote))
  5111. (buffer-string))))
  5112. ;; Ignore contents of source blocks or example blocks when
  5113. ;; indentation should be preserved (through
  5114. ;; `org-src-preserve-indentation' or "-i" flag).
  5115. (should-not
  5116. (zerop
  5117. (org-test-with-temp-text
  5118. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  5119. (let ((org-adapt-indentation t)
  5120. (org-src-preserve-indentation nil)
  5121. (org-odd-levels-only nil))
  5122. (org-promote))
  5123. (forward-line)
  5124. (org-get-indentation))))
  5125. (should
  5126. (zerop
  5127. (org-test-with-temp-text
  5128. "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
  5129. (let ((org-adapt-indentation t)
  5130. (org-src-preserve-indentation t)
  5131. (org-odd-levels-only nil))
  5132. (org-promote))
  5133. (forward-line)
  5134. (org-get-indentation))))
  5135. (should
  5136. (zerop
  5137. (org-test-with-temp-text
  5138. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  5139. (let ((org-adapt-indentation t)
  5140. (org-src-preserve-indentation t)
  5141. (org-odd-levels-only nil))
  5142. (org-promote))
  5143. (forward-line)
  5144. (org-get-indentation))))
  5145. (should
  5146. (zerop
  5147. (org-test-with-temp-text
  5148. "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
  5149. (let ((org-adapt-indentation t)
  5150. (org-src-preserve-indentation nil)
  5151. (org-odd-levels-only nil))
  5152. (org-promote))
  5153. (forward-line)
  5154. (org-get-indentation)))))
  5155. (ert-deftest test-org/org-get-valid-level ()
  5156. "Test function `org-get-valid-level' specifications."
  5157. (let ((org-odd-levels-only nil))
  5158. (should (equal 1 (org-get-valid-level 0 0)))
  5159. (should (equal 1 (org-get-valid-level 0 1)))
  5160. (should (equal 2 (org-get-valid-level 0 2)))
  5161. (should (equal 3 (org-get-valid-level 0 3)))
  5162. (should (equal 1 (org-get-valid-level 1 0)))
  5163. (should (equal 2 (org-get-valid-level 1 1)))
  5164. (should (equal 23 (org-get-valid-level 1 22)))
  5165. (should (equal 1 (org-get-valid-level 1 -1)))
  5166. (should (equal 1 (org-get-valid-level 2 -1))))
  5167. (let ((org-odd-levels-only t))
  5168. (should (equal 1 (org-get-valid-level 0 0)))
  5169. (should (equal 1 (org-get-valid-level 0 1)))
  5170. (should (equal 3 (org-get-valid-level 0 2)))
  5171. (should (equal 5 (org-get-valid-level 0 3)))
  5172. (should (equal 1 (org-get-valid-level 1 0)))
  5173. (should (equal 3 (org-get-valid-level 1 1)))
  5174. (should (equal 3 (org-get-valid-level 2 1)))
  5175. (should (equal 5 (org-get-valid-level 3 1)))
  5176. (should (equal 5 (org-get-valid-level 4 1)))
  5177. (should (equal 43 (org-get-valid-level 1 21)))
  5178. (should (equal 1 (org-get-valid-level 1 -1)))
  5179. (should (equal 1 (org-get-valid-level 2 -1)))
  5180. (should (equal 1 (org-get-valid-level 3 -1)))
  5181. (should (equal 3 (org-get-valid-level 4 -1)))
  5182. (should (equal 3 (org-get-valid-level 5 -1)))))
  5183. ;;; Planning
  5184. (ert-deftest test-org/at-planning-p ()
  5185. "Test `org-at-planning-p' specifications."
  5186. ;; Regular test.
  5187. (should
  5188. (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
  5189. (org-at-planning-p)))
  5190. (should-not
  5191. (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
  5192. (org-at-planning-p)))
  5193. ;; Correctly find planning attached to inlinetasks.
  5194. (when (featurep 'org-inlinetask)
  5195. (should
  5196. (org-test-with-temp-text
  5197. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
  5198. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  5199. (should-not
  5200. (org-test-with-temp-text
  5201. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  5202. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  5203. (should-not
  5204. (org-test-with-temp-text
  5205. "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  5206. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  5207. (should-not
  5208. (org-test-with-temp-text
  5209. "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
  5210. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
  5211. (ert-deftest test-org/add-planning-info ()
  5212. "Test `org-add-planning-info'."
  5213. ;; Create deadline when `org-adapt-indentation' is non-nil.
  5214. (should
  5215. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5216. (org-test-with-temp-text "* H\nParagraph<point>"
  5217. (let ((org-adapt-indentation t))
  5218. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5219. (replace-regexp-in-string
  5220. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5221. nil nil 1))))
  5222. ;; Create deadline when `org-adapt-indentation' is nil.
  5223. (should
  5224. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  5225. (org-test-with-temp-text "* H\nParagraph<point>"
  5226. (let ((org-adapt-indentation nil))
  5227. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5228. (replace-regexp-in-string
  5229. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5230. nil nil 1))))
  5231. ;; Update deadline when `org-adapt-indentation' is non-nil.
  5232. (should
  5233. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5234. (org-test-with-temp-text "\
  5235. * H
  5236. DEADLINE: <2015-06-24 Wed>
  5237. Paragraph<point>"
  5238. (let ((org-adapt-indentation t))
  5239. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5240. (replace-regexp-in-string
  5241. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5242. nil nil 1))))
  5243. ;; Update deadline when `org-adapt-indentation' is nil.
  5244. (should
  5245. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  5246. (org-test-with-temp-text "\
  5247. * H
  5248. DEADLINE: <2015-06-24 Wed>
  5249. Paragraph<point>"
  5250. (let ((org-adapt-indentation nil))
  5251. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5252. (replace-regexp-in-string
  5253. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5254. nil nil 1))))
  5255. ;; Schedule when `org-adapt-indentation' is non-nil.
  5256. (should
  5257. (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
  5258. (org-test-with-temp-text "* H\nParagraph<point>"
  5259. (let ((org-adapt-indentation t))
  5260. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  5261. (replace-regexp-in-string
  5262. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5263. nil nil 1))))
  5264. ;; Schedule when `org-adapt-indentation' is nil.
  5265. (should
  5266. (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
  5267. (org-test-with-temp-text "* H\nParagraph<point>"
  5268. (let ((org-adapt-indentation nil))
  5269. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  5270. (replace-regexp-in-string
  5271. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5272. nil nil 1))))
  5273. ;; Add deadline when scheduled.
  5274. (should
  5275. (equal "\
  5276. * H
  5277. DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
  5278. Paragraph"
  5279. (org-test-with-temp-text "\
  5280. * H
  5281. SCHEDULED: <2015-06-24 Wed>
  5282. Paragraph<point>"
  5283. (let ((org-adapt-indentation t))
  5284. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5285. (replace-regexp-in-string
  5286. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5287. nil nil 1))))
  5288. ;; Remove middle entry.
  5289. (should
  5290. (equal "\
  5291. * H
  5292. CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
  5293. Paragraph"
  5294. (org-test-with-temp-text "\
  5295. * H
  5296. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  5297. Paragraph<point>"
  5298. (let ((org-adapt-indentation t))
  5299. (org-add-planning-info nil nil 'deadline))
  5300. (replace-regexp-in-string
  5301. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  5302. nil nil 1))))
  5303. ;; Remove last entry and then middle entry (order should not
  5304. ;; matter).
  5305. (should
  5306. (equal "\
  5307. * H
  5308. CLOSED: [2015-06-24]
  5309. Paragraph"
  5310. (org-test-with-temp-text "\
  5311. * H
  5312. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  5313. Paragraph<point>"
  5314. (let ((org-adapt-indentation t))
  5315. (org-add-planning-info nil nil 'scheduled 'deadline))
  5316. (replace-regexp-in-string
  5317. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  5318. nil nil 1))))
  5319. ;; Remove closed when `org-adapt-indentation' is non-nil.
  5320. (should
  5321. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5322. (org-test-with-temp-text "\
  5323. * H
  5324. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  5325. Paragraph<point>"
  5326. (let ((org-adapt-indentation t))
  5327. (org-add-planning-info nil nil 'closed))
  5328. (replace-regexp-in-string
  5329. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5330. nil nil 1))))
  5331. (should
  5332. (equal "* H\n Paragraph"
  5333. (org-test-with-temp-text "\
  5334. * H
  5335. CLOSED: [2015-06-25 Thu]
  5336. Paragraph<point>"
  5337. (let ((org-adapt-indentation t))
  5338. (org-add-planning-info nil nil 'closed))
  5339. (replace-regexp-in-string
  5340. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5341. nil nil 1))))
  5342. ;; Remove closed when `org-adapt-indentation' is nil.
  5343. (should
  5344. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  5345. (org-test-with-temp-text "\
  5346. * H
  5347. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  5348. Paragraph<point>"
  5349. (let ((org-adapt-indentation nil))
  5350. (org-add-planning-info nil nil 'closed))
  5351. (replace-regexp-in-string
  5352. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5353. nil nil 1))))
  5354. (should
  5355. (equal "* H\nParagraph"
  5356. (org-test-with-temp-text "\
  5357. * H
  5358. CLOSED: [2015-06-25 Thu]
  5359. Paragraph<point>"
  5360. (let ((org-adapt-indentation nil))
  5361. (org-add-planning-info nil nil 'closed))
  5362. (replace-regexp-in-string
  5363. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5364. nil nil 1))))
  5365. ;; Remove closed entry and delete empty line.
  5366. (should
  5367. (equal "\
  5368. * H
  5369. Paragraph"
  5370. (org-test-with-temp-text "\
  5371. * H
  5372. CLOSED: [2015-06-24 Wed]
  5373. Paragraph<point>"
  5374. (let ((org-adapt-indentation t))
  5375. (org-add-planning-info nil nil 'closed))
  5376. (replace-regexp-in-string
  5377. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5378. nil nil 1))))
  5379. ;; Remove one entry and update another.
  5380. (should
  5381. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5382. (org-test-with-temp-text "\
  5383. * H
  5384. SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
  5385. Paragraph<point>"
  5386. (let ((org-adapt-indentation t))
  5387. (org-add-planning-info 'deadline "<2015-06-25 Thu>" 'scheduled))
  5388. (replace-regexp-in-string
  5389. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5390. nil nil 1)))))
  5391. (ert-deftest test-org/deadline ()
  5392. "Test `org-deadline' specifications."
  5393. ;; Insert a new value or replace existing one.
  5394. (should
  5395. (equal "* H\nDEADLINE: <2012-03-29>"
  5396. (org-test-with-temp-text "* H"
  5397. (let ((org-adapt-indentation nil)
  5398. (org-last-inserted-timestamp nil))
  5399. (org-deadline nil "<2012-03-29 Tue>"))
  5400. (replace-regexp-in-string
  5401. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5402. nil nil 1))))
  5403. (should
  5404. (equal "* H\nDEADLINE: <2014-03-04>"
  5405. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5406. (let ((org-adapt-indentation nil)
  5407. (org-last-inserted-timestamp nil))
  5408. (org-deadline nil "<2014-03-04 Thu>"))
  5409. (replace-regexp-in-string
  5410. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5411. nil nil 1))))
  5412. ;; Accept delta time, e.g., "+2d".
  5413. (should
  5414. (equal "* H\nDEADLINE: <2015-03-04>"
  5415. (org-test-at-time "2014-03-04"
  5416. (org-test-with-temp-text "* H"
  5417. (let ((org-adapt-indentation nil)
  5418. (org-last-inserted-timestamp nil))
  5419. (org-deadline nil "+1y"))
  5420. (replace-regexp-in-string
  5421. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5422. ;; Preserve repeater.
  5423. (should
  5424. (equal "* H\nDEADLINE: <2012-03-29 +2y>"
  5425. (org-test-with-temp-text "* H"
  5426. (let ((org-adapt-indentation nil)
  5427. (org-last-inserted-timestamp nil))
  5428. (org-deadline nil "<2012-03-29 Tue +2y>"))
  5429. (replace-regexp-in-string
  5430. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5431. ;; Preserve warning period.
  5432. (should
  5433. (equal "* H\nDEADLINE: <2021-07-20 -1d>"
  5434. (org-test-with-temp-text "* H"
  5435. (let ((org-adapt-indentation nil)
  5436. (org-last-inserted-timestamp nil))
  5437. (org-deadline nil "<2021-07-20 Tue -1d>"))
  5438. (replace-regexp-in-string
  5439. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5440. (should
  5441. (equal "* H\nDEADLINE: <2021-07-20 +1m -3d>"
  5442. (org-test-with-temp-text "* H"
  5443. (let ((org-adapt-indentation nil)
  5444. (org-last-inserted-timestamp nil))
  5445. (org-deadline nil "<2021-07-20 Tue +1m -3d>"))
  5446. (replace-regexp-in-string
  5447. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5448. ;; Remove CLOSED keyword, if any.
  5449. (should
  5450. (equal "* H\nDEADLINE: <2012-03-29>"
  5451. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  5452. (let ((org-adapt-indentation nil)
  5453. (org-last-inserted-timestamp nil))
  5454. (org-deadline nil "<2012-03-29 Tue>"))
  5455. (replace-regexp-in-string
  5456. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5457. ;; With C-u argument, remove DEADLINE keyword.
  5458. (should
  5459. (equal "* H\n"
  5460. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5461. (let ((org-adapt-indentation nil)
  5462. (org-last-inserted-timestamp nil))
  5463. (org-deadline '(4)))
  5464. (buffer-string))))
  5465. (should
  5466. (equal "* H"
  5467. (org-test-with-temp-text "* H"
  5468. (let ((org-adapt-indentation nil)
  5469. (org-last-inserted-timestamp nil))
  5470. (org-deadline '(4)))
  5471. (buffer-string))))
  5472. ;; With C-u C-u argument, prompt for a delay cookie.
  5473. (should
  5474. (equal "* H\nDEADLINE: <2012-03-29 -705d>"
  5475. (cl-letf (((symbol-function 'org-read-date)
  5476. (lambda (&rest args)
  5477. (org-time-string-to-time "2014-03-04"))))
  5478. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5479. (let ((org-adapt-indentation nil)
  5480. (org-last-inserted-timestamp nil))
  5481. (org-deadline '(16)))
  5482. (buffer-string)))))
  5483. (should-error
  5484. (cl-letf (((symbol-function 'org-read-date)
  5485. (lambda (&rest args)
  5486. (org-time-string-to-time "2014-03-04"))))
  5487. (org-test-with-temp-text "* H"
  5488. (let ((org-adapt-indentation nil)
  5489. (org-last-inserted-timestamp nil))
  5490. (org-deadline '(16)))
  5491. (buffer-string))))
  5492. ;; When a region is active and
  5493. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5494. ;; same value in all headlines in region.
  5495. (should
  5496. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5497. (org-test-with-temp-text "* H1\n* H2"
  5498. (let ((org-adapt-indentation nil)
  5499. (org-last-inserted-timestamp nil)
  5500. (org-loop-over-headlines-in-active-region t))
  5501. (transient-mark-mode 1)
  5502. (push-mark (point) t t)
  5503. (goto-char (point-max))
  5504. (org-deadline nil "2012-03-29"))
  5505. (replace-regexp-in-string
  5506. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5507. (should-not
  5508. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5509. (org-test-with-temp-text "* H1\n* H2"
  5510. (let ((org-adapt-indentation nil)
  5511. (org-last-inserted-timestamp nil)
  5512. (org-loop-over-headlines-in-active-region nil))
  5513. (transient-mark-mode 1)
  5514. (push-mark (point) t t)
  5515. (goto-char (point-max))
  5516. (org-deadline nil "2012-03-29"))
  5517. (replace-regexp-in-string
  5518. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5519. (ert-deftest test-org/schedule ()
  5520. "Test `org-schedule' specifications."
  5521. ;; Insert a new value or replace existing one.
  5522. (should
  5523. (equal "* H\nSCHEDULED: <2012-03-29>"
  5524. (org-test-with-temp-text "* H"
  5525. (let ((org-adapt-indentation nil)
  5526. (org-last-inserted-timestamp nil))
  5527. (org-schedule nil "<2012-03-29 Tue>"))
  5528. (replace-regexp-in-string
  5529. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5530. nil nil 1))))
  5531. (should
  5532. (equal "* H\nSCHEDULED: <2014-03-04>"
  5533. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5534. (let ((org-adapt-indentation nil)
  5535. (org-last-inserted-timestamp nil))
  5536. (org-schedule nil "<2014-03-04 Thu>"))
  5537. (replace-regexp-in-string
  5538. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5539. nil nil 1))))
  5540. ;; Accept delta time, e.g., "+2d".
  5541. (should
  5542. (equal "* H\nSCHEDULED: <2015-03-04>"
  5543. (org-test-at-time "2014-03-04"
  5544. (org-test-with-temp-text "* H"
  5545. (let ((org-adapt-indentation nil)
  5546. (org-last-inserted-timestamp nil))
  5547. (org-schedule nil "+1y"))
  5548. (replace-regexp-in-string
  5549. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5550. ;; Preserve repeater.
  5551. (should
  5552. (equal "* H\nSCHEDULED: <2012-03-29 +2y>"
  5553. (org-test-with-temp-text "* H"
  5554. (let ((org-adapt-indentation nil)
  5555. (org-last-inserted-timestamp nil))
  5556. (org-schedule nil "<2012-03-29 Tue +2y>"))
  5557. (replace-regexp-in-string
  5558. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5559. ;; Remove CLOSED keyword, if any.
  5560. (should
  5561. (equal "* H\nSCHEDULED: <2012-03-29>"
  5562. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  5563. (let ((org-adapt-indentation nil)
  5564. (org-last-inserted-timestamp nil))
  5565. (org-schedule nil "<2012-03-29 Tue>"))
  5566. (replace-regexp-in-string
  5567. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5568. ;; With C-u argument, remove SCHEDULED keyword.
  5569. (should
  5570. (equal "* H\n"
  5571. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5572. (let ((org-adapt-indentation nil)
  5573. (org-last-inserted-timestamp nil))
  5574. (org-schedule '(4)))
  5575. (buffer-string))))
  5576. (should
  5577. (equal "* H"
  5578. (org-test-with-temp-text "* H"
  5579. (let ((org-adapt-indentation nil)
  5580. (org-last-inserted-timestamp nil))
  5581. (org-schedule '(4)))
  5582. (buffer-string))))
  5583. ;; With C-u C-u argument, prompt for a delay cookie.
  5584. (should
  5585. (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
  5586. (cl-letf (((symbol-function 'org-read-date)
  5587. (lambda (&rest args)
  5588. (org-time-string-to-time "2014-03-04"))))
  5589. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5590. (let ((org-adapt-indentation nil)
  5591. (org-last-inserted-timestamp nil))
  5592. (org-schedule '(16)))
  5593. (buffer-string)))))
  5594. (should-error
  5595. (cl-letf (((symbol-function 'org-read-date)
  5596. (lambda (&rest args)
  5597. (org-time-string-to-time "2014-03-04"))))
  5598. (org-test-with-temp-text "* H"
  5599. (let ((org-adapt-indentation nil)
  5600. (org-last-inserted-timestamp nil))
  5601. (org-schedule '(16)))
  5602. (buffer-string))))
  5603. ;; When a region is active and
  5604. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5605. ;; same value in all headlines in region.
  5606. (should
  5607. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5608. (org-test-with-temp-text "* H1\n* H2"
  5609. (let ((org-adapt-indentation nil)
  5610. (org-last-inserted-timestamp nil)
  5611. (org-loop-over-headlines-in-active-region t))
  5612. (transient-mark-mode 1)
  5613. (push-mark (point) t t)
  5614. (goto-char (point-max))
  5615. (org-schedule nil "2012-03-29"))
  5616. (replace-regexp-in-string
  5617. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5618. (should-not
  5619. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5620. (org-test-with-temp-text "* H1\n* H2"
  5621. (let ((org-adapt-indentation nil)
  5622. (org-last-inserted-timestamp nil)
  5623. (org-loop-over-headlines-in-active-region nil))
  5624. (transient-mark-mode 1)
  5625. (push-mark (point) t t)
  5626. (goto-char (point-max))
  5627. (org-schedule nil "2012-03-29"))
  5628. (replace-regexp-in-string
  5629. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5630. (should
  5631. ;; check if a repeater survives re-scheduling.
  5632. (string-match-p
  5633. "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
  5634. (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
  5635. (let ((org-adapt-indentation nil)
  5636. (org-last-inserted-timestamp nil))
  5637. (org-schedule nil "2017-02-01"))
  5638. (buffer-string)))))
  5639. ;;; Property API
  5640. (ert-deftest test-org/buffer-property-keys ()
  5641. "Test `org-buffer-property-keys' specifications."
  5642. ;; Retrieve properties across siblings.
  5643. (should
  5644. (equal '("A" "B")
  5645. (org-test-with-temp-text "
  5646. * H1
  5647. :PROPERTIES:
  5648. :A: 1
  5649. :END:
  5650. * H2
  5651. :PROPERTIES:
  5652. :B: 1
  5653. :END:"
  5654. (org-buffer-property-keys))))
  5655. ;; Retrieve properties across children.
  5656. (should
  5657. (equal '("A" "B")
  5658. (org-test-with-temp-text "
  5659. * H1
  5660. :PROPERTIES:
  5661. :A: 1
  5662. :END:
  5663. ** H2
  5664. :PROPERTIES:
  5665. :B: 1
  5666. :END:"
  5667. (org-buffer-property-keys))))
  5668. ;; Retrieve muliple properties in the same drawer.
  5669. (should
  5670. (equal '("A" "B")
  5671. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5672. (org-buffer-property-keys))))
  5673. ;; Ignore extension symbol in property name.
  5674. (should
  5675. (equal '("A")
  5676. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5677. (org-buffer-property-keys))))
  5678. ;; Add bare property if xxx_ALL property is there
  5679. (should
  5680. (equal '("A" "B" "B_ALL")
  5681. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B_ALL: foo bar\n:END:"
  5682. (org-buffer-property-keys))))
  5683. ;; Add bare property if xxx_ALL property is there - check dupes
  5684. (should
  5685. (equal '("A" "B" "B_ALL")
  5686. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:B_ALL: foo bar\n:END:"
  5687. (org-buffer-property-keys))))
  5688. ;; Retrieve properties from #+PROPERTY keyword lines
  5689. (should
  5690. (equal '("A" "C")
  5691. (org-test-with-temp-text "#+PROPERTY: C foo\n* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5692. (org-buffer-property-keys))))
  5693. ;; Retrieve properties from #+PROPERTY keyword lines - make sure an _ALL property also
  5694. ;; adds the bare property
  5695. (should
  5696. (equal '("A" "C" "C_ALL")
  5697. (org-test-with-temp-text "#+PROPERTY: C_ALL foo bar\n* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5698. (org-buffer-property-keys))))
  5699. ;; With non-nil COLUMNS, extract property names from columns.
  5700. (should
  5701. (equal '("A" "B")
  5702. (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
  5703. (org-buffer-property-keys nil nil t))))
  5704. (should
  5705. (equal '("A" "B" "COLUMNS")
  5706. (org-test-with-temp-text
  5707. "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
  5708. (org-buffer-property-keys nil nil t))))
  5709. ;; In COLUMNS, ignore title and summary-type.
  5710. (should
  5711. (equal '("A")
  5712. (org-test-with-temp-text "#+COLUMNS: %A(Foo)"
  5713. (org-buffer-property-keys nil nil t))))
  5714. (should
  5715. (equal '("A")
  5716. (org-test-with-temp-text "#+COLUMNS: %A{Foo}"
  5717. (org-buffer-property-keys nil nil t))))
  5718. (should
  5719. (equal '("A")
  5720. (org-test-with-temp-text "#+COLUMNS: %A(Foo){Bar}"
  5721. (org-buffer-property-keys nil nil t)))))
  5722. (ert-deftest test-org/property-values ()
  5723. "Test `org-property-values' specifications."
  5724. ;; Regular test.
  5725. (should
  5726. (equal '("2" "1")
  5727. (org-test-with-temp-text
  5728. "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
  5729. (org-property-values "A"))))
  5730. ;; Ignore empty values.
  5731. (should-not
  5732. (org-test-with-temp-text
  5733. "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
  5734. (org-property-values "A")))
  5735. ;; Take into consideration extended values.
  5736. (should
  5737. (equal '("1 2")
  5738. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5739. (org-property-values "A")))))
  5740. (ert-deftest test-org/set-property ()
  5741. "Test `org-set-property' specifications."
  5742. (should
  5743. (equal
  5744. ":PROPERTIES:\n:TEST: t\n:END:\n"
  5745. (org-test-with-temp-text ""
  5746. (let ((org-property-format "%s %s"))
  5747. (org-set-property "TEST" "t"))
  5748. (buffer-string))))
  5749. (should
  5750. (equal
  5751. "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5752. (org-test-with-temp-text "* H"
  5753. (let ((org-adapt-indentation nil)
  5754. (org-property-format "%s %s"))
  5755. (org-set-property "TEST" "t"))
  5756. (buffer-string)))))
  5757. (ert-deftest test-org/delete-property ()
  5758. "Test `org-delete-property' specifications."
  5759. (should
  5760. (equal
  5761. ""
  5762. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5763. (org-delete-property "TEST")
  5764. (buffer-string))))
  5765. (should
  5766. (equal
  5767. ":PROPERTIES:\n:TEST1: t\n:END:\n"
  5768. (org-test-with-temp-text ":PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5769. (org-delete-property "TEST2")
  5770. (buffer-string))))
  5771. (should
  5772. (equal
  5773. "* H\n"
  5774. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5775. (org-delete-property "TEST")
  5776. (buffer-string))))
  5777. (should
  5778. (equal
  5779. "* H\n:PROPERTIES:\n:TEST1: t\n:END:\n"
  5780. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5781. (org-delete-property "TEST2")
  5782. (buffer-string)))))
  5783. (ert-deftest test-org/delete-property-globally ()
  5784. "Test `org-delete-property-global' specifications."
  5785. (should
  5786. (equal
  5787. ""
  5788. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5789. (org-delete-property-globally "TEST")
  5790. (buffer-string))))
  5791. (should
  5792. (equal
  5793. "* H\n"
  5794. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n* H\n:PROPERTIES:\n:TEST: nil\n:END:"
  5795. (org-delete-property-globally "TEST")
  5796. (buffer-string)))))
  5797. (ert-deftest test-org/find-property ()
  5798. "Test `org-find-property' specifications."
  5799. ;; Regular test.
  5800. (should
  5801. (= 1
  5802. (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
  5803. (org-find-property "prop"))))
  5804. ;; Find properties in top-level property drawer.
  5805. (should
  5806. (= 1
  5807. (org-test-with-temp-text ":PROPERTIES:\n:PROP: value\n:END:"
  5808. (org-find-property "prop"))))
  5809. ;; Ignore false positives.
  5810. (should
  5811. (= 27
  5812. (org-test-with-temp-text
  5813. "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
  5814. (org-find-property "A"))))
  5815. ;; Return first entry found in buffer.
  5816. (should
  5817. (= 1
  5818. (org-test-with-temp-text
  5819. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5820. (org-find-property "A"))))
  5821. ;; Only search visible part of the buffer.
  5822. (should
  5823. (= 31
  5824. (org-test-with-temp-text
  5825. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5826. (org-narrow-to-subtree)
  5827. (org-find-property "A"))))
  5828. ;; With optional argument, only find entries with a specific value.
  5829. (should-not
  5830. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5831. (org-find-property "A" "2")))
  5832. (should
  5833. (= 31
  5834. (org-test-with-temp-text
  5835. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
  5836. (org-find-property "A" "2"))))
  5837. ;; Use "nil" for explicit nil values.
  5838. (should
  5839. (= 31
  5840. (org-test-with-temp-text
  5841. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
  5842. (org-find-property "A" "nil")))))
  5843. (ert-deftest test-org/entry-delete ()
  5844. "Test `org-entry-delete' specifications."
  5845. ;; Regular test.
  5846. (should
  5847. (string-match
  5848. " *:PROPERTIES:\n *:B: +2\n *:END:"
  5849. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5850. (org-entry-delete (point) "A")
  5851. (buffer-string))))
  5852. ;; Also remove accumulated properties.
  5853. (should-not
  5854. (string-match
  5855. ":A"
  5856. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
  5857. (org-entry-delete (point) "A")
  5858. (buffer-string))))
  5859. ;; When last property is removed, remove the property drawer.
  5860. (should-not
  5861. (string-match
  5862. ":PROPERTIES:"
  5863. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
  5864. (org-entry-delete (point) "A")
  5865. (buffer-string))))
  5866. ;; Return a non-nil value when some property was removed.
  5867. (should
  5868. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5869. (org-entry-delete (point) "A")))
  5870. (should-not
  5871. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5872. (org-entry-delete (point) "C")))
  5873. ;; Special properties cannot be located in a drawer. Allow to
  5874. ;; remove them anyway, in case of user error.
  5875. (should
  5876. (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
  5877. (org-entry-delete (point) "SCHEDULED"))))
  5878. (ert-deftest test-org/entry-get ()
  5879. "Test `org-entry-get' specifications."
  5880. ;; Regular test.
  5881. (should
  5882. (equal "1"
  5883. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:"
  5884. (org-entry-get (point) "A"))))
  5885. (should
  5886. (equal "1"
  5887. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5888. (org-entry-get (point) "A"))))
  5889. ;; Ignore case.
  5890. (should
  5891. (equal "1"
  5892. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5893. (org-entry-get (point) "a"))))
  5894. ;; Handle extended values, both before and after base value.
  5895. (should
  5896. (equal "1 2 3"
  5897. (org-test-with-temp-text
  5898. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5899. (org-entry-get (point) "A"))))
  5900. ;; Empty values are returned as the empty string.
  5901. (should
  5902. (equal ""
  5903. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
  5904. (org-entry-get (point) "A"))))
  5905. ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
  5906. ;; otherwise, return nil.
  5907. (should-not
  5908. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5909. (org-entry-get (point) "A")))
  5910. (should
  5911. (equal "nil"
  5912. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5913. (org-entry-get (point) "A" nil t))))
  5914. ;; Return nil when no property is found, independently on the
  5915. ;; LITERAL-NIL argument.
  5916. (should-not
  5917. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5918. (org-entry-get (point) "B")))
  5919. (should-not
  5920. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5921. (org-entry-get (point) "B" nil t)))
  5922. ;; Handle inheritance, when allowed. Include extended values and
  5923. ;; possibly global values.
  5924. (should
  5925. (equal
  5926. "1"
  5927. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:\n* H"
  5928. (org-entry-get (point-max) "A" t))))
  5929. (should
  5930. (equal
  5931. "1"
  5932. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5933. (org-entry-get (point-max) "A" t))))
  5934. (should
  5935. (equal
  5936. "1"
  5937. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5938. (let ((org-use-property-inheritance t))
  5939. (org-entry-get (point-max) "A" 'selective)))))
  5940. (should-not
  5941. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5942. (let ((org-use-property-inheritance nil))
  5943. (org-entry-get (point-max) "A" 'selective))))
  5944. (should-not
  5945. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H2"
  5946. (let ((org-use-property-inheritance t))
  5947. (org-entry-get (point-max) "A" t))))
  5948. (should
  5949. (equal
  5950. "1 2"
  5951. (org-test-with-temp-text
  5952. ":PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5953. (org-entry-get (point-max) "A" t))))
  5954. (should
  5955. (equal
  5956. "1 2"
  5957. (org-test-with-temp-text
  5958. "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5959. (org-entry-get (point-max) "A" t))))
  5960. (should
  5961. (equal
  5962. "1 2"
  5963. (org-test-with-temp-text
  5964. ":PROPERTIES:\n:A: 1\n:END:\n* H1\n* H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5965. (org-entry-get (point-max) "A" t))))
  5966. (should
  5967. (equal
  5968. "1 2"
  5969. (org-test-with-temp-text
  5970. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2.1\n** H2.2\n:PROPERTIES:\n:A+: 2\n:END:"
  5971. (org-entry-get (point-max) "A" t))))
  5972. (should
  5973. (equal "1"
  5974. (org-test-with-temp-text
  5975. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
  5976. (org-mode-restart)
  5977. (org-entry-get (point-max) "A" t))))
  5978. (should
  5979. (equal "0 1"
  5980. (org-test-with-temp-text
  5981. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
  5982. (org-mode-restart)
  5983. (org-entry-get (point-max) "A" t))))
  5984. ;; document level property-drawer has precedance over
  5985. ;; global-property by PROPERTY-keyword.
  5986. (should
  5987. (equal "0 2"
  5988. (org-test-with-temp-text
  5989. ":PROPERTIES:\n:A: 0\n:END:\n#+PROPERTY: A 1\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5990. (org-mode-restart)
  5991. (org-entry-get (point-max) "A" t))))
  5992. ;; Use alternate separators
  5993. (should
  5994. (equal "0~2"
  5995. (org-test-with-temp-text
  5996. ":PROPERTIES:\n:A: 0\n:A+: 2\n:END:"
  5997. (let ((org-property-separators '((("A") . "~"))))
  5998. (org-entry-get (point) "A")))))
  5999. ;; Default separator is single space
  6000. (should
  6001. (equal "0 2"
  6002. (org-test-with-temp-text
  6003. ":PROPERTIES:\n:A: 0\n:B: 1\n:A+: 2\n:B+: 3\n:END:"
  6004. (let ((org-property-separators '((("B") . "~"))))
  6005. (org-entry-get (point) "A")))))
  6006. ;; Regular expression matching for separator
  6007. (should
  6008. (equal "0/2"
  6009. (org-test-with-temp-text
  6010. ":PROPERTIES:\n:A: 0\n:A+: 2\n:END:"
  6011. (let ((org-property-separators '((("B") . "~") ("[AC]" . "/"))))
  6012. (org-entry-get (point) "A")))))
  6013. ;; Separator works with inheritance
  6014. (should
  6015. (equal "1~2"
  6016. (org-test-with-temp-text
  6017. "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
  6018. (let ((org-property-separators '((("A") . "~"))))
  6019. (org-entry-get (point-max) "A" t))))))
  6020. (ert-deftest test-org/entry-properties ()
  6021. "Test `org-entry-properties' specifications."
  6022. ;; Get "ITEM" property.
  6023. (should
  6024. (equal "H"
  6025. (org-test-with-temp-text "* TODO H"
  6026. (cdr (assoc "ITEM" (org-entry-properties nil "ITEM"))))))
  6027. (should
  6028. (equal "H"
  6029. (org-test-with-temp-text "* TODO H"
  6030. (cdr (assoc "ITEM" (org-entry-properties))))))
  6031. ;; Get "TODO" property. TODO keywords are case sensitive.
  6032. (should
  6033. (equal "TODO"
  6034. (org-test-with-temp-text "* TODO H"
  6035. (cdr (assoc "TODO" (org-entry-properties nil "TODO"))))))
  6036. (should
  6037. (equal "TODO"
  6038. (org-test-with-temp-text "* TODO H"
  6039. (cdr (assoc "TODO" (org-entry-properties))))))
  6040. (should-not
  6041. (org-test-with-temp-text "* H"
  6042. (assoc "TODO" (org-entry-properties nil "TODO"))))
  6043. (should-not
  6044. (org-test-with-temp-text "* todo H"
  6045. (assoc "TODO" (org-entry-properties nil "TODO"))))
  6046. ;; Get "PRIORITY" property.
  6047. (should
  6048. (equal "A"
  6049. (org-test-with-temp-text "* [#A] H"
  6050. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  6051. (should
  6052. (equal "A"
  6053. (org-test-with-temp-text "* [#A] H"
  6054. (cdr (assoc "PRIORITY" (org-entry-properties))))))
  6055. (should
  6056. (equal (char-to-string org-priority-default)
  6057. (org-test-with-temp-text "* H"
  6058. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  6059. ;; Get "FILE" property.
  6060. (should
  6061. (org-test-with-temp-text-in-file "* H\nParagraph"
  6062. (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil "FILE")))
  6063. (buffer-file-name))))
  6064. (should
  6065. (org-test-with-temp-text-in-file "* H\nParagraph"
  6066. (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
  6067. (buffer-file-name))))
  6068. (should-not
  6069. (org-test-with-temp-text "* H\nParagraph"
  6070. (cdr (assoc "FILE" (org-entry-properties nil "FILE")))))
  6071. ;; Get "TAGS" property.
  6072. (should
  6073. (equal ":tag1:tag2:"
  6074. (org-test-with-temp-text "* H :tag1:tag2:"
  6075. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS"))))))
  6076. (should
  6077. (equal ":tag1:tag2:"
  6078. (org-test-with-temp-text "* H :tag1:tag2:"
  6079. (cdr (assoc "TAGS" (org-entry-properties))))))
  6080. (should-not
  6081. (org-test-with-temp-text "* H"
  6082. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS")))))
  6083. ;; Get "ALLTAGS" property.
  6084. (should
  6085. (equal ":tag1:tag2:"
  6086. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  6087. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS"))))))
  6088. (should
  6089. (equal ":tag1:tag2:"
  6090. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  6091. (cdr (assoc "ALLTAGS" (org-entry-properties))))))
  6092. (should-not
  6093. (org-test-with-temp-text "* H"
  6094. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS")))))
  6095. ;; Get "BLOCKED" property.
  6096. (should
  6097. (equal "t"
  6098. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  6099. (let ((org-enforce-todo-dependencies t)
  6100. (org-blocker-hook
  6101. '(org-block-todo-from-children-or-siblings-or-parent)))
  6102. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  6103. (should
  6104. (equal ""
  6105. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  6106. (let ((org-enforce-todo-dependencies t)
  6107. (org-blocker-hook
  6108. '(org-block-todo-from-children-or-siblings-or-parent)))
  6109. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  6110. ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
  6111. (should
  6112. (equal
  6113. "[2012-03-29 thu.]"
  6114. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  6115. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED"))))))
  6116. (should
  6117. (equal
  6118. "[2012-03-29 thu.]"
  6119. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  6120. (cdr (assoc "CLOSED" (org-entry-properties))))))
  6121. (should-not
  6122. (org-test-with-temp-text "* H"
  6123. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED")))))
  6124. (should
  6125. (equal
  6126. "<2014-03-04 tue.>"
  6127. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6128. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE"))))))
  6129. (should
  6130. (equal
  6131. "<2014-03-04 tue.>"
  6132. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6133. (cdr (assoc "DEADLINE" (org-entry-properties))))))
  6134. (should-not
  6135. (org-test-with-temp-text "* H"
  6136. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE")))))
  6137. (should
  6138. (equal
  6139. "<2014-03-04 tue.>"
  6140. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6141. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED"))))))
  6142. (should
  6143. (equal
  6144. "<2014-03-04 tue.>"
  6145. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6146. (cdr (assoc "SCHEDULED" (org-entry-properties))))))
  6147. (should-not
  6148. (org-test-with-temp-text "* H"
  6149. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED")))))
  6150. ;; Get "CATEGORY"
  6151. (should
  6152. (equal "cat"
  6153. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  6154. (cdr (assoc "CATEGORY" (org-entry-properties))))))
  6155. (should
  6156. (equal "cat"
  6157. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  6158. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  6159. (should
  6160. (equal "cat"
  6161. (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
  6162. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  6163. (should
  6164. (equal "cat2"
  6165. (org-test-with-temp-text
  6166. (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6167. "\n"
  6168. "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
  6169. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  6170. ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
  6171. (should
  6172. (equal "<2012-03-29 thu.>"
  6173. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
  6174. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  6175. (should
  6176. (equal "[2012-03-29 thu.]"
  6177. (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
  6178. (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
  6179. (should
  6180. (equal "<2012-03-29 thu.>"
  6181. (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
  6182. (cdr (assoc "TIMESTAMP" (org-entry-properties nil "TIMESTAMP"))))))
  6183. (should
  6184. (equal "[2014-03-04 tue.]"
  6185. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
  6186. (cdr (assoc "TIMESTAMP_IA"
  6187. (org-entry-properties nil "TIMESTAMP_IA"))))))
  6188. (should-not
  6189. (equal "<2012-03-29 thu.>"
  6190. (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
  6191. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  6192. ;; Get standard properties.
  6193. (should
  6194. (equal "1"
  6195. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6196. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  6197. ;; Handle extended properties.
  6198. (should
  6199. (equal "1 2 3"
  6200. (org-test-with-temp-text
  6201. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  6202. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  6203. (should
  6204. (equal "1 2 3"
  6205. (org-test-with-temp-text
  6206. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
  6207. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  6208. ;; Ignore forbidden (special) properties.
  6209. (should-not
  6210. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
  6211. (cdr (assoc "TODO" (org-entry-properties nil 'standard))))))
  6212. (ert-deftest test-org/entry-put ()
  6213. "Test `org-entry-put' specifications."
  6214. ;; Error when not a string or nil.
  6215. (should-error
  6216. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  6217. (org-entry-put 1 "test" 2)))
  6218. ;; Error when property name is invalid.
  6219. (should-error
  6220. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  6221. (org-entry-put 1 "no space" "value")))
  6222. (should-error
  6223. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  6224. (org-entry-put 1 "" "value")))
  6225. ;; Set "TODO" property.
  6226. (should
  6227. (string-match (regexp-quote " TODO H")
  6228. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  6229. (org-entry-put (point) "TODO" "TODO")
  6230. (buffer-string))))
  6231. (should
  6232. (string-match (regexp-quote "* H")
  6233. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  6234. (org-entry-put (point) "TODO" nil)
  6235. (buffer-string))))
  6236. ;; Set "PRIORITY" property.
  6237. (should
  6238. (equal "* [#A] H"
  6239. (org-test-with-temp-text "* [#B] H"
  6240. (org-entry-put (point) "PRIORITY" "A")
  6241. (buffer-string))))
  6242. (should
  6243. (equal "* H"
  6244. (org-test-with-temp-text "* [#B] H"
  6245. (org-entry-put (point) "PRIORITY" nil)
  6246. (buffer-string))))
  6247. ;; Set "SCHEDULED" property.
  6248. (should
  6249. (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
  6250. (org-test-with-temp-text "* H"
  6251. (org-entry-put (point) "SCHEDULED" "2014-03-04")
  6252. (buffer-string))))
  6253. (should
  6254. (string= "* H\n"
  6255. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6256. (org-entry-put (point) "SCHEDULED" nil)
  6257. (buffer-string))))
  6258. (should
  6259. (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
  6260. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6261. (org-entry-put (point) "SCHEDULED" "earlier")
  6262. (buffer-string))))
  6263. (should
  6264. (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
  6265. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6266. (org-entry-put (point) "SCHEDULED" "later")
  6267. (buffer-string))))
  6268. ;; Set "DEADLINE" property.
  6269. (should
  6270. (string-match "^ *DEADLINE: <2014-03-04 .*?>"
  6271. (org-test-with-temp-text "* H"
  6272. (org-entry-put (point) "DEADLINE" "2014-03-04")
  6273. (buffer-string))))
  6274. (should
  6275. (string= "* H\n"
  6276. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6277. (org-entry-put (point) "DEADLINE" nil)
  6278. (buffer-string))))
  6279. (should
  6280. (string-match "^ *DEADLINE: <2014-03-03 .*?>"
  6281. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6282. (org-entry-put (point) "DEADLINE" "earlier")
  6283. (buffer-string))))
  6284. (should
  6285. (string-match "^ *DEADLINE: <2014-03-05 .*?>"
  6286. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6287. (org-entry-put (point) "DEADLINE" "later")
  6288. (buffer-string))))
  6289. ;; Set "CATEGORY" property
  6290. (should
  6291. (string-match "^ *:CATEGORY: cat"
  6292. (org-test-with-temp-text "* H"
  6293. (org-entry-put (point) "CATEGORY" "cat")
  6294. (buffer-string))))
  6295. ;; Regular properties, with or without pre-existing drawer.
  6296. (should
  6297. (string-match "^ *:A: +2$"
  6298. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6299. (org-entry-put (point) "A" "2")
  6300. (buffer-string))))
  6301. (should
  6302. (string-match "^ *:A: +1$"
  6303. (org-test-with-temp-text "* H"
  6304. (org-entry-put (point) "A" "1")
  6305. (buffer-string))))
  6306. ;; Special case: two consecutive headlines.
  6307. (should
  6308. (string-match "\\* A\n *:PROPERTIES:"
  6309. (org-test-with-temp-text "* A\n** B"
  6310. (org-entry-put (point) "A" "1")
  6311. (buffer-string)))))
  6312. (ert-deftest test-org/refresh-properties ()
  6313. "Test `org-refresh-properties' specifications."
  6314. (should
  6315. (equal "1"
  6316. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6317. (org-refresh-properties "A" 'org-test)
  6318. (get-text-property (point) 'org-test))))
  6319. (should-not
  6320. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6321. (org-refresh-properties "B" 'org-test)
  6322. (get-text-property (point) 'org-test)))
  6323. ;; Handle properties only defined with extension syntax, i.e.,
  6324. ;; "PROPERTY+".
  6325. (should
  6326. (equal "1"
  6327. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
  6328. (org-refresh-properties "A" 'org-test)
  6329. (get-text-property (point) 'org-test))))
  6330. ;; When property is inherited, add text property to the whole
  6331. ;; sub-tree.
  6332. (should
  6333. (equal "1"
  6334. (org-test-with-temp-text
  6335. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
  6336. (let ((org-use-property-inheritance t))
  6337. (org-refresh-properties "A" 'org-test))
  6338. (get-text-property (point) 'org-test))))
  6339. ;; When a document level property-drawer is used, those properties
  6340. ;; should work exactly like headline-properties as if at a
  6341. ;; headline-level 0.
  6342. (should
  6343. (equal "1"
  6344. (org-test-with-temp-text
  6345. ":PROPERTIES:\n:A: 1\n:END:\n"
  6346. (org-mode-restart)
  6347. (let ((org-use-property-inheritance t))
  6348. (org-refresh-properties "A" 'org-test))
  6349. (get-text-property (point) 'org-test))))
  6350. (should-not
  6351. (equal "1"
  6352. (org-test-with-temp-text
  6353. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  6354. (org-mode-restart)
  6355. (let ((org-use-property-inheritance nil))
  6356. (org-refresh-properties "A" 'org-test))
  6357. (get-text-property (point) 'org-test))))
  6358. (should
  6359. (equal "1"
  6360. (org-test-with-temp-text
  6361. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  6362. (org-mode-restart)
  6363. (let ((org-use-property-inheritance t))
  6364. (org-refresh-properties "A" 'org-test))
  6365. (get-text-property (point) 'org-test))))
  6366. (should
  6367. (equal "2"
  6368. (org-test-with-temp-text
  6369. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1\n:PROPERTIES:\n:A: 2\n:END:"
  6370. (org-mode-restart)
  6371. (let ((org-use-property-inheritance t))
  6372. (org-refresh-properties "A" 'org-test))
  6373. (get-text-property (point) 'org-test))))
  6374. ;; When property is inherited, use global value across the whole
  6375. ;; buffer. However local values have precedence, as well as the
  6376. ;; document level property-drawer.
  6377. (should-not
  6378. (equal "1"
  6379. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  6380. (org-mode-restart)
  6381. (let ((org-use-property-inheritance nil))
  6382. (org-refresh-properties "A" 'org-test))
  6383. (get-text-property (point) 'org-test))))
  6384. (should
  6385. (equal "1"
  6386. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  6387. (org-mode-restart)
  6388. (let ((org-use-property-inheritance t))
  6389. (org-refresh-properties "A" 'org-test))
  6390. (get-text-property (point) 'org-test))))
  6391. (should
  6392. (equal "2"
  6393. (org-test-with-temp-text
  6394. "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
  6395. (org-mode-restart)
  6396. (let ((org-use-property-inheritance t))
  6397. (org-refresh-properties "A" 'org-test))
  6398. (get-text-property (point) 'org-test))))
  6399. ;; When both keyword-property and document-level property-block is
  6400. ;; defined, the property-block has precedance.
  6401. (should
  6402. (equal "1"
  6403. (org-test-with-temp-text
  6404. ":PROPERTIES:\n:A: 1\n:END:\n#+PROPERTY: A 2\n<point>* H1"
  6405. (org-mode-restart)
  6406. (let ((org-use-property-inheritance t))
  6407. (org-refresh-properties "A" 'org-test))
  6408. (get-text-property (point) 'org-test)))))
  6409. (ert-deftest test-org/refresh-category-properties ()
  6410. "Test `org-refresh-category-properties' specifications"
  6411. (should
  6412. (equal "cat1"
  6413. (org-test-with-temp-text
  6414. ":PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6415. (org-refresh-category-properties)
  6416. (org-get-category))))
  6417. (should
  6418. (equal "cat1"
  6419. (org-test-with-temp-text
  6420. "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6421. (org-refresh-category-properties)
  6422. (org-get-category))))
  6423. ;; Even though property-inheritance is deactivated, category
  6424. ;; property should be inherited. As described in
  6425. ;; `org-use-property-inheritance'.
  6426. (should
  6427. (equal "cat1"
  6428. (org-test-with-temp-text
  6429. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  6430. (org-mode-restart)
  6431. (let ((org-use-property-inheritance nil))
  6432. (org-refresh-category-properties))
  6433. (org-get-category))))
  6434. (should
  6435. (equal "cat1"
  6436. (org-test-with-temp-text
  6437. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  6438. (org-mode-restart)
  6439. (let ((org-use-property-inheritance t))
  6440. (org-refresh-category-properties))
  6441. (org-get-category))))
  6442. (should
  6443. (equal "cat2"
  6444. (org-test-with-temp-text
  6445. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H\n:PROPERTIES:\n:CATEGORY: cat2\n:END:\n"
  6446. (org-mode-restart)
  6447. (let ((org-use-property-inheritance t))
  6448. (org-refresh-category-properties))
  6449. (org-get-category)))))
  6450. ;;; Refile
  6451. (ert-deftest test-org/refile-get-targets ()
  6452. "Test `org-refile-get-targets' specifications."
  6453. ;; :maxlevel includes all headings above specified value.
  6454. (should
  6455. (equal '("H1" "H2" "H3")
  6456. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6457. (let ((org-refile-use-outline-path nil)
  6458. (org-refile-targets `((nil :maxlevel . 3))))
  6459. (mapcar #'car (org-refile-get-targets))))))
  6460. (should
  6461. (equal '("H1" "H2")
  6462. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6463. (let ((org-refile-use-outline-path nil)
  6464. (org-refile-targets `((nil :maxlevel . 2))))
  6465. (mapcar #'car (org-refile-get-targets))))))
  6466. ;; :level limits targets to headlines with the specified level.
  6467. (should
  6468. (equal '("H2")
  6469. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6470. (let ((org-refile-use-outline-path nil)
  6471. (org-refile-targets `((nil :level . 2))))
  6472. (mapcar #'car (org-refile-get-targets))))))
  6473. ;; :tag limits targets to headlines with specified tag.
  6474. (should
  6475. (equal '("H1")
  6476. (org-test-with-temp-text "* H1 :foo:\n** H2\n*** H3 :bar:"
  6477. (let ((org-refile-use-outline-path nil)
  6478. (org-refile-targets `((nil :tag . "foo"))))
  6479. (mapcar #'car (org-refile-get-targets))))))
  6480. ;; :todo limits targets to headlines with specified TODO keyword.
  6481. (should
  6482. (equal '("H2")
  6483. (org-test-with-temp-text "* H1\n** TODO H2\n*** DONE H3"
  6484. (let ((org-refile-use-outline-path nil)
  6485. (org-refile-targets `((nil :todo . "TODO"))))
  6486. (mapcar #'car (org-refile-get-targets))))))
  6487. ;; :regexp filters targets matching provided regexp.
  6488. (should
  6489. (equal '("F2" "F3")
  6490. (org-test-with-temp-text "* H1\n** F2\n*** F3"
  6491. (let ((org-refile-use-outline-path nil)
  6492. (org-refile-targets `((nil :regexp . "F"))))
  6493. (mapcar #'car (org-refile-get-targets))))))
  6494. ;; A nil `org-refile-targets' includes only top level headlines in
  6495. ;; current buffer.
  6496. (should
  6497. (equal '("H1" "H2")
  6498. (org-test-with-temp-text "* H1\n** S1\n* H2"
  6499. (let ((org-refile-use-outline-path nil)
  6500. (org-refile-targets nil))
  6501. (mapcar #'car (org-refile-get-targets))))))
  6502. ;; Return value is the union of the targets according to all the
  6503. ;; defined rules. However, prevent duplicates.
  6504. (should
  6505. (equal '("F2" "F3" "H1")
  6506. (org-test-with-temp-text "* TODO H1\n** F2\n*** F3"
  6507. (let ((org-refile-use-outline-path nil)
  6508. (org-refile-targets `((nil :regexp . "F")
  6509. (nil :todo . "TODO"))))
  6510. (mapcar #'car (org-refile-get-targets))))))
  6511. (should
  6512. (equal '("F2" "F3" "H1")
  6513. (org-test-with-temp-text "* TODO H1\n** TODO F2\n*** F3"
  6514. (let ((org-refile-use-outline-path nil)
  6515. (org-refile-targets `((nil :regexp . "F")
  6516. (nil :todo . "TODO"))))
  6517. (mapcar #'car (org-refile-get-targets))))))
  6518. ;; When `org-refile-use-outline-path' is non-nil, provide targets as
  6519. ;; paths.
  6520. (should
  6521. (equal '("H1" "H1/H2" "H1/H2/H3")
  6522. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6523. (let ((org-refile-use-outline-path t)
  6524. (org-refile-targets `((nil :maxlevel . 3))))
  6525. (mapcar #'car (org-refile-get-targets))))))
  6526. ;; When providing targets as paths, escape forward slashes in
  6527. ;; headings with backslashes.
  6528. (should
  6529. (equal '("H1\\/foo")
  6530. (org-test-with-temp-text "* H1/foo"
  6531. (let ((org-refile-use-outline-path t)
  6532. (org-refile-targets `((nil :maxlevel . 1))))
  6533. (mapcar #'car (org-refile-get-targets))))))
  6534. ;; When `org-refile-use-outline-path' is `file', include file name
  6535. ;; without directory in targets.
  6536. (should
  6537. (org-test-with-temp-text-in-file "* H1"
  6538. (let* ((filename (buffer-file-name))
  6539. (org-refile-use-outline-path 'file)
  6540. (org-refile-targets `(((,filename) :level . 1))))
  6541. (member (file-name-nondirectory filename)
  6542. (mapcar #'car (org-refile-get-targets))))))
  6543. ;; When `org-refile-use-outline-path' is `full-file-path', include
  6544. ;; full file name.
  6545. (should
  6546. (org-test-with-temp-text-in-file "* H1"
  6547. (let* ((filename (file-truename (buffer-file-name)))
  6548. (org-refile-use-outline-path 'full-file-path)
  6549. (org-refile-targets `(((,filename) :level . 1))))
  6550. (member filename (mapcar #'car (org-refile-get-targets))))))
  6551. ;; When `org-refile-use-outline-path' is `buffer-name', include
  6552. ;; buffer name.
  6553. (should
  6554. (org-test-with-temp-text "* H1"
  6555. (let* ((org-refile-use-outline-path 'buffer-name)
  6556. (org-refile-targets `((nil :level . 1))))
  6557. (member (buffer-name) (mapcar #'car (org-refile-get-targets)))))))
  6558. ;;; Sparse trees
  6559. (ert-deftest test-org/match-sparse-tree ()
  6560. "Test `org-match-sparse-tree' specifications."
  6561. ;; Match tags.
  6562. (should-not
  6563. (org-test-with-temp-text "* H\n** H1 :tag:"
  6564. (org-match-sparse-tree nil "tag")
  6565. (search-forward "H1")
  6566. (org-invisible-p2)))
  6567. (should
  6568. (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
  6569. (org-match-sparse-tree nil "tag")
  6570. (search-forward "H2")
  6571. (org-invisible-p2)))
  6572. ;; "-" operator for tags.
  6573. (should-not
  6574. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6575. (org-match-sparse-tree nil "tag1-tag2")
  6576. (search-forward "H1")
  6577. (org-invisible-p2)))
  6578. (should
  6579. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6580. (org-match-sparse-tree nil "tag1-tag2")
  6581. (search-forward "H2")
  6582. (org-invisible-p2)))
  6583. ;; "&" operator for tags.
  6584. (should
  6585. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6586. (org-match-sparse-tree nil "tag1&tag2")
  6587. (search-forward "H1")
  6588. (org-invisible-p2)))
  6589. (should-not
  6590. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6591. (org-match-sparse-tree nil "tag1&tag2")
  6592. (search-forward "H2")
  6593. (org-invisible-p2)))
  6594. ;; "|" operator for tags.
  6595. (should-not
  6596. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6597. (org-match-sparse-tree nil "tag1|tag2")
  6598. (search-forward "H1")
  6599. (org-invisible-p2)))
  6600. (should-not
  6601. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6602. (org-match-sparse-tree nil "tag1|tag2")
  6603. (search-forward "H2")
  6604. (org-invisible-p2)))
  6605. ;; Regexp match on tags.
  6606. (should-not
  6607. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6608. (org-match-sparse-tree nil "{^tag.*}")
  6609. (search-forward "H1")
  6610. (org-invisible-p2)))
  6611. (should
  6612. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6613. (org-match-sparse-tree nil "{^tag.*}")
  6614. (search-forward "H2")
  6615. (org-invisible-p2)))
  6616. ;; Match group tags.
  6617. (should-not
  6618. (org-test-with-temp-text
  6619. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6620. (org-match-sparse-tree nil "work")
  6621. (search-forward "H1")
  6622. (org-invisible-p2)))
  6623. (should-not
  6624. (org-test-with-temp-text
  6625. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6626. (org-match-sparse-tree nil "work")
  6627. (search-forward "H2")
  6628. (org-invisible-p2)))
  6629. ;; Match group tags with hard brackets.
  6630. (should-not
  6631. (org-test-with-temp-text
  6632. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6633. (org-match-sparse-tree nil "work")
  6634. (search-forward "H1")
  6635. (org-invisible-p2)))
  6636. (should-not
  6637. (org-test-with-temp-text
  6638. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6639. (org-match-sparse-tree nil "work")
  6640. (search-forward "H2")
  6641. (org-invisible-p2)))
  6642. ;; Match tags in hierarchies
  6643. (should-not
  6644. (org-test-with-temp-text
  6645. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6646. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6647. #+TAGS: { Lev_3 : Lev_4 }\n
  6648. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6649. (org-match-sparse-tree nil "Lev_1")
  6650. (search-forward "H4")
  6651. (org-invisible-p2)))
  6652. (should-not
  6653. (org-test-with-temp-text
  6654. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6655. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6656. #+TAGS: { Lev_3 : Lev_4 }\n
  6657. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6658. (org-match-sparse-tree nil "Lev_1+Lev_3")
  6659. (search-forward "H4")
  6660. (org-invisible-p2)))
  6661. ;; Match regular expressions in tags
  6662. (should-not
  6663. (org-test-with-temp-text
  6664. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
  6665. (org-match-sparse-tree nil "Lev")
  6666. (search-forward "H1")
  6667. (org-invisible-p2)))
  6668. (should
  6669. (org-test-with-temp-text
  6670. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
  6671. (org-match-sparse-tree nil "Lev")
  6672. (search-forward "H1")
  6673. (org-invisible-p2)))
  6674. ;; Match properties.
  6675. (should
  6676. (org-test-with-temp-text
  6677. "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
  6678. (org-match-sparse-tree nil "A=\"1\"")
  6679. (search-forward "H2")
  6680. (org-invisible-p2)))
  6681. (should-not
  6682. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6683. (org-match-sparse-tree nil "A=\"1\"")
  6684. (search-forward "H2")
  6685. (org-invisible-p2)))
  6686. ;; Case is not significant when matching properties.
  6687. (should-not
  6688. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6689. (org-match-sparse-tree nil "a=\"1\"")
  6690. (search-forward "H2")
  6691. (org-invisible-p2)))
  6692. (should-not
  6693. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
  6694. (org-match-sparse-tree nil "A=\"1\"")
  6695. (search-forward "H2")
  6696. (org-invisible-p2)))
  6697. ;; Match special LEVEL property.
  6698. (should-not
  6699. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6700. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6701. (search-forward "H1")
  6702. (org-invisible-p2)))
  6703. (should
  6704. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6705. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6706. (search-forward "H2")
  6707. (org-invisible-p2)))
  6708. ;; Comparison operators when matching properties.
  6709. (should
  6710. (org-test-with-temp-text
  6711. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6712. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6713. (search-forward "H1")
  6714. (org-invisible-p2)))
  6715. (should-not
  6716. (org-test-with-temp-text
  6717. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6718. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6719. (search-forward "H2")
  6720. (org-invisible-p2)))
  6721. ;; Regexp match on properties values.
  6722. (should-not
  6723. (org-test-with-temp-text
  6724. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6725. (org-match-sparse-tree nil "A={f.*}")
  6726. (search-forward "H1")
  6727. (org-invisible-p2)))
  6728. (should
  6729. (org-test-with-temp-text
  6730. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6731. (org-match-sparse-tree nil "A={f.*}")
  6732. (search-forward "H2")
  6733. (org-invisible-p2)))
  6734. ;; With an optional argument, limit match to TODO entries.
  6735. (should-not
  6736. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6737. (org-match-sparse-tree t "tag")
  6738. (search-forward "H1")
  6739. (org-invisible-p2)))
  6740. (should
  6741. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6742. (org-match-sparse-tree t "tag")
  6743. (search-forward "H2")
  6744. (org-invisible-p2))))
  6745. (ert-deftest test-org/occur ()
  6746. "Test `org-occur' specifications."
  6747. ;; Count number of matches.
  6748. (should
  6749. (= 1
  6750. (org-test-with-temp-text "* H\nA\n* H2"
  6751. (org-occur "A"))))
  6752. (should
  6753. (= 2
  6754. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6755. (org-occur "A"))))
  6756. ;; Test CALLBACK optional argument.
  6757. (should
  6758. (= 0
  6759. (org-test-with-temp-text "* H\nA\n* H2"
  6760. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6761. (should
  6762. (= 1
  6763. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6764. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6765. ;; Case-fold searches according to `org-occur-case-fold-search'.
  6766. (should
  6767. (= 2
  6768. (org-test-with-temp-text "Aa"
  6769. (let ((org-occur-case-fold-search t)) (org-occur "A")))))
  6770. (should
  6771. (= 2
  6772. (org-test-with-temp-text "Aa"
  6773. (let ((org-occur-case-fold-search t)) (org-occur "a")))))
  6774. (should
  6775. (= 1
  6776. (org-test-with-temp-text "Aa"
  6777. (let ((org-occur-case-fold-search nil)) (org-occur "A")))))
  6778. (should
  6779. (= 1
  6780. (org-test-with-temp-text "Aa"
  6781. (let ((org-occur-case-fold-search nil)) (org-occur "a")))))
  6782. (should
  6783. (= 1
  6784. (org-test-with-temp-text "Aa"
  6785. (let ((org-occur-case-fold-search 'smart)) (org-occur "A")))))
  6786. (should
  6787. (= 2
  6788. (org-test-with-temp-text "Aa"
  6789. (let ((org-occur-case-fold-search 'smart)) (org-occur "a"))))))
  6790. ;;; Tags
  6791. (ert-deftest test-org/tag-string-to-alist ()
  6792. "Test `org-tag-string-to-alist' specifications."
  6793. ;; Tag without selection key.
  6794. (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
  6795. ;; Tag with selection key.
  6796. (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t))))
  6797. ;; Tag group.
  6798. (should
  6799. (equal
  6800. (org-tag-string-to-alist "[ group : t1 t2 ]")
  6801. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag))))
  6802. ;; Mutually exclusive tags.
  6803. (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
  6804. '((:startgroup) ("tag1") ("tag2") (:endgroup))))
  6805. (should
  6806. (equal
  6807. (org-tag-string-to-alist "{ group : tag1 tag2 }")
  6808. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))))
  6809. (ert-deftest test-org/tag-alist-to-string ()
  6810. "Test `org-tag-alist-to-string' specifications."
  6811. (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
  6812. (should (equal (org-tag-alist-to-string '(("tag1" . ?t))) "tag1(t)"))
  6813. (should
  6814. (equal
  6815. (org-tag-alist-to-string
  6816. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6817. "[ group : t1 t2 ]"))
  6818. (should
  6819. (equal (org-tag-alist-to-string
  6820. '((:startgroup) ("tag1") ("tag2") (:endgroup)))
  6821. "{ tag1 tag2 }"))
  6822. (should
  6823. (equal
  6824. (org-tag-alist-to-string
  6825. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))
  6826. "{ group : tag1 tag2 }")))
  6827. (ert-deftest test-org/tag-alist-to-groups ()
  6828. "Test `org-tag-alist-to-groups' specifications."
  6829. (should
  6830. (equal (org-tag-alist-to-groups
  6831. '((:startgroup) ("group") (:grouptags) ("t1") ("t2") (:endgroup)))
  6832. '(("group" "t1" "t2"))))
  6833. (should
  6834. (equal
  6835. (org-tag-alist-to-groups
  6836. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6837. '(("group" "t1" "t2"))))
  6838. (should-not
  6839. (org-tag-alist-to-groups
  6840. '((:startgroup) ("group") ("t1") ("t2") (:endgroup)))))
  6841. (ert-deftest test-org/tag-align ()
  6842. "Test tags alignment."
  6843. ;; Test aligning tags with different display width.
  6844. (should
  6845. ;; 12345678901234567890
  6846. (equal "* Test :abc:"
  6847. (org-test-with-temp-text "* Test :abc:"
  6848. (let ((org-tags-column -20)
  6849. (indent-tabs-mode nil))
  6850. (org-fix-tags-on-the-fly))
  6851. (buffer-string))))
  6852. (should
  6853. ;; 12345678901234567890
  6854. (equal "* Test :日本語:"
  6855. (org-test-with-temp-text "* Test :日本語:"
  6856. (let ((org-tags-column -20)
  6857. (indent-tabs-mode nil))
  6858. (org-fix-tags-on-the-fly))
  6859. (buffer-string))))
  6860. ;; Make sure aligning tags do not skip invisible text.
  6861. (should
  6862. (equal "* [[linkx]] :tag:"
  6863. (org-test-with-temp-text "* [[link<point>]] :tag:"
  6864. (let ((org-tags-column 0))
  6865. (org-fix-tags-on-the-fly)
  6866. (insert "x")
  6867. (buffer-string)))))
  6868. ;; Aligning tags preserve position.
  6869. (should
  6870. (= 6 (org-test-with-temp-text "* 345 <point> :tag:"
  6871. (let ((org-tags-column 78)
  6872. (indent-tabs-mode nil))
  6873. (org-fix-tags-on-the-fly))
  6874. (current-column))))
  6875. ;; Aligning all tags in visible buffer.
  6876. (should
  6877. ;; 12345678901234567890
  6878. (equal (concat "* Level 1 :abc:\n"
  6879. "** Level 2 :def:")
  6880. (org-test-with-temp-text (concat "* Level 1 :abc:\n"
  6881. "** Level 2 :def:")
  6882. (let ((org-tags-column -20)
  6883. (indent-tabs-mode nil))
  6884. ;; (org-align-tags :all) must work even when the point
  6885. ;; is at the end of the buffer.
  6886. (goto-char (point-max))
  6887. (org-align-tags :all))
  6888. (buffer-string)))))
  6889. (ert-deftest test-org/get-tags ()
  6890. "Test `org-get-tags' specifications."
  6891. ;; Standard test.
  6892. (should
  6893. (equal '("foo")
  6894. (org-test-with-temp-text "* Test :foo:" (org-get-tags))))
  6895. (should
  6896. (equal '("foo" "bar")
  6897. (org-test-with-temp-text "* Test :foo:bar:" (org-get-tags))))
  6898. ;; Tags for inlinetasks.
  6899. (should
  6900. (equal '("foo" "bar")
  6901. (progn
  6902. (require 'org-inlinetask)
  6903. (org-test-with-temp-text (concat (make-string org-inlinetask-min-level ?*) " Test :foo:bar:")
  6904. (org-get-tags (org-element-at-point))))))
  6905. (should
  6906. (equal '("foo" "bar")
  6907. (progn
  6908. (require 'org-inlinetask)
  6909. (org-test-with-temp-text (concat (make-string org-inlinetask-min-level ?*) " Test :foo:bar:")
  6910. (org-get-tags nil)))))
  6911. ;; Return nil when there is no tag.
  6912. (should-not
  6913. (org-test-with-temp-text "* Test" (org-get-tags)))
  6914. ;; Tags are inherited from parent headlines.
  6915. (should
  6916. (equal '("tag")
  6917. (let ((org-use-tag-inheritance t))
  6918. (org-test-with-temp-text "* H0 :foo:\n* H1 :tag:\n<point>** H2"
  6919. (org-get-tags)))))
  6920. ;; Tags are inherited from `org-file-tags'.
  6921. (should
  6922. (equal '("tag")
  6923. (org-test-with-temp-text "* H1"
  6924. (let ((org-file-tags '("tag"))
  6925. (org-use-tag-inheritance t))
  6926. (org-get-tags)))))
  6927. ;; Only inherited tags have the `inherited' text property.
  6928. (should
  6929. (get-text-property 0 'inherited
  6930. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6931. (let ((org-use-tag-inheritance t))
  6932. (assoc-string "foo" (org-get-tags))))))
  6933. (should-not
  6934. (get-text-property 0 'inherited
  6935. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6936. (let ((org-use-tag-inheritance t))
  6937. (assoc-string "bar" (org-get-tags))))))
  6938. ;; Obey to `org-use-tag-inheritance'.
  6939. (should-not
  6940. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6941. (let ((org-use-tag-inheritance nil))
  6942. (assoc-string "foo" (org-get-tags)))))
  6943. (should-not
  6944. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6945. (let ((org-use-tag-inheritance nil)
  6946. (org-file-tags '("foo")))
  6947. (assoc-string "foo" (org-get-tags)))))
  6948. (should-not
  6949. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6950. (let ((org-use-tag-inheritance '("bar")))
  6951. (assoc-string "foo" (org-get-tags)))))
  6952. (should
  6953. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6954. (let ((org-use-tag-inheritance '("bar")))
  6955. (assoc-string "bar" (org-get-tags)))))
  6956. (should-not
  6957. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6958. (let ((org-use-tag-inheritance "b.*"))
  6959. (assoc-string "foo" (org-get-tags)))))
  6960. (should
  6961. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6962. (let ((org-use-tag-inheritance "b.*"))
  6963. (assoc-string "bar" (org-get-tags)))))
  6964. ;; When optional argument LOCAL is non-nil, ignore tag inheritance.
  6965. (should
  6966. (equal '("baz")
  6967. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6968. (let ((org-use-tag-inheritance t))
  6969. (org-get-tags nil t)))))
  6970. ;; When optional argument POS is non-nil, get tags there instead.
  6971. (should
  6972. (equal '("foo")
  6973. (org-test-with-temp-text "* H1 :foo:\n* <point>H2 :bar:"
  6974. (org-get-tags 1))))
  6975. ;; Make sure tags excluded from inheritance are returned if local
  6976. (should
  6977. (equal '("foo")
  6978. (org-test-with-temp-text "* Test :foo:"
  6979. (let ((org-use-tag-inheritance t)
  6980. (org-tags-exclude-from-inheritance '("foo")))
  6981. (org-get-tags)))))
  6982. ;; Test the collection of tags from #+filetags and parent tags.
  6983. (should
  6984. (equal '("a" "b" "c" "d")
  6985. (org-test-with-temp-text (concat "#+filetags: a\n"
  6986. "* Level 1 :b:\n"
  6987. "** Level 2 :c:\n"
  6988. "*** Level 3 :d:\n"
  6989. "<point>")
  6990. (let ((org-use-tag-inheritance t))
  6991. (org-mode-restart) ;So that `org-file-tags' get populated from #+filetags
  6992. (org-get-tags)))))
  6993. ;; Pathological case: tagged headline with an empty body.
  6994. (should (org-test-with-temp-text "* :tag:" (org-get-tags))))
  6995. (ert-deftest test-org/set-tags ()
  6996. "Test `org-set-tags' specifications."
  6997. ;; Throw an error on invalid data.
  6998. (should-error
  6999. (org-test-with-temp-text "* H"
  7000. (org-set-tags 'foo)))
  7001. ;; `nil', an empty, and a blank string remove all tags.
  7002. (should
  7003. (equal "* H"
  7004. (org-test-with-temp-text "* H :tag1:tag2:"
  7005. (org-set-tags nil)
  7006. (buffer-string))))
  7007. (should
  7008. (equal "* H"
  7009. (org-test-with-temp-text "* H :tag1:tag2:"
  7010. (org-set-tags "")
  7011. (buffer-string))))
  7012. (should
  7013. (equal "* H"
  7014. (org-test-with-temp-text "* H :tag1:tag2:"
  7015. (org-set-tags " ")
  7016. (buffer-string))))
  7017. ;; If there's nothing to remove, just bail out.
  7018. (should
  7019. (equal "* H"
  7020. (org-test-with-temp-text "* H"
  7021. (org-set-tags nil)
  7022. (buffer-string))))
  7023. (should
  7024. (equal "* "
  7025. (org-test-with-temp-text "* "
  7026. (org-set-tags nil)
  7027. (buffer-string))))
  7028. ;; If DATA is a tag string, set current tags to it, even if it means
  7029. ;; replacing old tags.
  7030. (should
  7031. (equal "* H :tag0:"
  7032. (org-test-with-temp-text "* H :tag1:tag2:"
  7033. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  7034. (buffer-string))))
  7035. (should
  7036. (equal "* H :tag0:"
  7037. (org-test-with-temp-text "* H"
  7038. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  7039. (buffer-string))))
  7040. ;; If DATA is a list, set tags to this list, even if it means
  7041. ;; replacing old tags.
  7042. (should
  7043. (equal "* H :tag0:"
  7044. (org-test-with-temp-text "* H :tag1:tag2:"
  7045. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  7046. (buffer-string))))
  7047. (should
  7048. (equal "* H :tag0:"
  7049. (org-test-with-temp-text "* H"
  7050. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  7051. (buffer-string))))
  7052. ;; When set, apply `org-tags-sort-function'.
  7053. (should
  7054. (equal "* H :a:b:"
  7055. (org-test-with-temp-text "* H"
  7056. (let ((org-tags-column 1)
  7057. (org-tags-sort-function #'string<))
  7058. (org-set-tags '("b" "a"))
  7059. (buffer-string)))))
  7060. ;; When new tags are identical to the previous ones, still align.
  7061. (should
  7062. (equal "* H :foo:"
  7063. (org-test-with-temp-text "* H :foo:"
  7064. (let ((org-tags-column 1))
  7065. (org-set-tags '("foo"))
  7066. (buffer-string)))))
  7067. ;; When tags have been changed, run `org-after-tags-change-hook'.
  7068. (should
  7069. (catch :return
  7070. (org-test-with-temp-text "* H :foo:"
  7071. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  7072. (org-set-tags '("bar"))
  7073. nil))))
  7074. (should-not
  7075. (catch :return
  7076. (org-test-with-temp-text "* H :foo:"
  7077. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  7078. (org-set-tags '("foo"))
  7079. nil))))
  7080. ;; Special case: handle empty headlines.
  7081. (should
  7082. (equal "* :tag0:"
  7083. (org-test-with-temp-text "* "
  7084. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  7085. (buffer-string))))
  7086. ;; Modify buffer only when a tag change happens or alignment is
  7087. ;; done.
  7088. (should-not
  7089. (org-test-with-temp-text "* H :foo:"
  7090. (set-buffer-modified-p nil)
  7091. (let ((org-tags-column 1)) (org-set-tags '("foo")))
  7092. (buffer-modified-p)))
  7093. (should
  7094. (org-test-with-temp-text "* H :foo:"
  7095. (set-buffer-modified-p nil)
  7096. (let ((org-tags-column 10)) (org-set-tags '("foo")))
  7097. (buffer-modified-p)))
  7098. (should
  7099. (org-test-with-temp-text "* H :foo:"
  7100. (set-buffer-modified-p nil)
  7101. (let ((org-tags-column 10)) (org-set-tags '("bar")))
  7102. (buffer-modified-p)))
  7103. ;; Pathological case: when setting tags of a folded headline, do not
  7104. ;; let new tags being sucked into invisibility.
  7105. (should-not
  7106. (org-test-with-temp-text "* H1\nContent\n* H2\n\n Other Content"
  7107. ;; Show only headlines
  7108. (org-content)
  7109. ;; Set NEXT tag on current entry
  7110. (org-set-tags ":NEXT:")
  7111. ;; Move point to that NEXT tag
  7112. (search-forward "NEXT") (backward-word)
  7113. ;; And it should be visible (i.e. no overlays)
  7114. (overlays-at (point)))))
  7115. (ert-deftest test-org/set-tags-command ()
  7116. "Test `org-set-tags-command' specifications"
  7117. ;; Set tags at current headline.
  7118. (should
  7119. (equal "* H1 :foo:"
  7120. (org-test-with-temp-text "* H1"
  7121. (cl-letf (((symbol-function 'completing-read-multiple)
  7122. (lambda (&rest args) '("foo"))))
  7123. (let ((org-use-fast-tag-selection nil)
  7124. (org-tags-column 1))
  7125. (org-set-tags-command)))
  7126. (buffer-string))))
  7127. ;; Preserve position when called from the section below.
  7128. (should
  7129. (equal "* H1 :foo:\nContents"
  7130. (org-test-with-temp-text "* H1\n<point>Contents"
  7131. (cl-letf (((symbol-function 'completing-read-multiple)
  7132. (lambda (&rest args) '("foo"))))
  7133. (let ((org-use-fast-tag-selection nil)
  7134. (org-tags-column 1))
  7135. (org-set-tags-command)))
  7136. (buffer-string))))
  7137. (should-not
  7138. (equal "* H1 :foo:\nContents2"
  7139. (org-test-with-temp-text "* H1\n<point>Contents2"
  7140. (cl-letf (((symbol-function 'completing-read-multiple)
  7141. (lambda (&rest args) '("foo"))))
  7142. (let ((org-use-fast-tag-selection nil)
  7143. (org-tags-column 1))
  7144. (org-set-tags-command)))
  7145. (org-at-heading-p))))
  7146. ;; When a region is active and
  7147. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  7148. ;; same value in all headlines in region.
  7149. (should
  7150. (equal "* H1 :foo:\nContents\n* H2 :foo:"
  7151. (org-test-with-temp-text "* H1\nContents\n* H2"
  7152. (cl-letf (((symbol-function 'completing-read-multiple)
  7153. (lambda (&rest args) '("foo"))))
  7154. (let ((org-use-fast-tag-selection nil)
  7155. (org-loop-over-headlines-in-active-region t)
  7156. (org-tags-column 1))
  7157. (transient-mark-mode 1)
  7158. (push-mark (point) t t)
  7159. (goto-char (point-max))
  7160. (org-set-tags-command)))
  7161. (buffer-string))))
  7162. (should
  7163. (equal "* H1\nContents\n* H2 :foo:"
  7164. (org-test-with-temp-text "* H1\nContents\n* H2"
  7165. (cl-letf (((symbol-function 'completing-read-multiple)
  7166. (lambda (&rest args) '("foo"))))
  7167. (let ((org-use-fast-tag-selection nil)
  7168. (org-loop-over-headlines-in-active-region nil)
  7169. (org-tags-column 1))
  7170. (transient-mark-mode 1)
  7171. (push-mark (point) t t)
  7172. (goto-char (point-max))
  7173. (org-set-tags-command)))
  7174. (buffer-string))))
  7175. ;; With a C-u prefix argument, align all tags in the buffer.
  7176. (should
  7177. (equal "* H1 :foo:\n* H2 :bar:"
  7178. (org-test-with-temp-text "* H1 :foo:\n* H2 :bar:"
  7179. (let ((org-tags-column 1)) (org-set-tags-command '(4)))
  7180. (buffer-string))))
  7181. ;; Point does not move with empty headline.
  7182. (should
  7183. (equal ":foo:"
  7184. (org-test-with-temp-text "* <point>"
  7185. (cl-letf (((symbol-function 'completing-read-multiple)
  7186. (lambda (&rest args) '("foo"))))
  7187. (let ((org-use-fast-tag-selection nil)
  7188. (org-tags-column 1))
  7189. (org-set-tags-command)))
  7190. (buffer-substring (point) (line-end-position)))))
  7191. ;; Point does not move at start of line.
  7192. (should
  7193. (equal "* H1 :foo:"
  7194. (org-test-with-temp-text "* H1"
  7195. (cl-letf (((symbol-function 'completing-read-multiple)
  7196. (lambda (&rest args) '("foo"))))
  7197. (let ((org-use-fast-tag-selection nil)
  7198. (org-tags-column 1))
  7199. (org-set-tags-command)))
  7200. (buffer-substring (point) (line-end-position)))))
  7201. ;; Point does not move when within *'s.
  7202. (should
  7203. (equal "* H1 :foo:"
  7204. (org-test-with-temp-text "*<point>* H1"
  7205. (cl-letf (((symbol-function 'completing-read-multiple)
  7206. (lambda (&rest args) '("foo"))))
  7207. (let ((org-use-fast-tag-selection nil)
  7208. (org-tags-column 1))
  7209. (org-set-tags-command)))
  7210. (buffer-substring (point) (line-end-position)))))
  7211. ;; Point workaround does not get fooled when looking at a space.
  7212. (should
  7213. (equal " b :foo:"
  7214. (org-test-with-temp-text "* a<point> b"
  7215. (cl-letf (((symbol-function 'completing-read-multiple)
  7216. (lambda (&rest args) '("foo"))))
  7217. (let ((org-use-fast-tag-selection nil)
  7218. (org-tags-column 1))
  7219. (org-set-tags-command)))
  7220. (buffer-substring (point) (line-end-position)))))
  7221. ;; Handle tags both set locally and inherited.
  7222. (should
  7223. (equal "b :foo:"
  7224. (org-test-with-temp-text "* a :foo:\n** <point>b :foo:"
  7225. (cl-letf (((symbol-function 'completing-read-multiple)
  7226. (lambda (prompt coll &optional pred req initial &rest args)
  7227. (list initial))))
  7228. (let ((org-use-fast-tag-selection nil)
  7229. (org-tags-column 1))
  7230. (org-set-tags-command)))
  7231. (buffer-substring (point) (line-end-position))))))
  7232. (ert-deftest test-org/toggle-tag ()
  7233. "Test `org-toggle-tag' specifications."
  7234. ;; Insert missing tag.
  7235. (should
  7236. (equal "* H :tag:"
  7237. (org-test-with-temp-text "* H"
  7238. (let ((org-tags-column 1)) (org-toggle-tag "tag"))
  7239. (buffer-string))))
  7240. (should
  7241. (equal "* H :tag1:tag2:"
  7242. (org-test-with-temp-text "* H :tag1:"
  7243. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  7244. (buffer-string))))
  7245. ;; Remove existing tag.
  7246. (should
  7247. (equal "* H"
  7248. (org-test-with-temp-text "* H :tag:"
  7249. (org-toggle-tag "tag")
  7250. (buffer-string))))
  7251. (should
  7252. (equal "* H :tag1:"
  7253. (org-test-with-temp-text "* H :tag1:tag2:"
  7254. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  7255. (buffer-string))))
  7256. (should
  7257. (equal "* H :tag2:"
  7258. (org-test-with-temp-text "* H :tag1:tag2:"
  7259. (let ((org-tags-column 1)) (org-toggle-tag "tag1"))
  7260. (buffer-string))))
  7261. ;; With optional argument ONOFF set to `on', try to insert the tag,
  7262. ;; even if its already there.
  7263. (should
  7264. (equal "* H :tag:"
  7265. (org-test-with-temp-text "* H"
  7266. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  7267. (buffer-string))))
  7268. (should
  7269. (equal "* H :tag:"
  7270. (org-test-with-temp-text "* H :tag:"
  7271. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  7272. (buffer-string))))
  7273. ;; With optional argument ONOFF set to `off', try to remove the tag,
  7274. ;; even if its not there.
  7275. (should
  7276. (equal "* H"
  7277. (org-test-with-temp-text "* H :tag:"
  7278. (org-toggle-tag "tag" 'off)
  7279. (buffer-string))))
  7280. (should
  7281. (equal "* H :tag:"
  7282. (org-test-with-temp-text "* H :tag:"
  7283. (let ((org-tags-column 1)) (org-toggle-tag "foo" 'off))
  7284. (buffer-string))))
  7285. ;; Special case: Handle properly tag inheritance. In particular, do
  7286. ;; not set inherited tags.
  7287. (should
  7288. (equal "* H1 :tag:\n** H2 :tag2:tag:"
  7289. (org-test-with-temp-text "* H1 :tag:\n** <point>H2 :tag2:"
  7290. (let ((org-use-tag-inheritance t)
  7291. (org-tags-column 1))
  7292. (org-toggle-tag "tag"))
  7293. (buffer-string))))
  7294. (should
  7295. (equal "* H1 :tag1:tag2:\n** H2 :foo:"
  7296. (org-test-with-temp-text "* H1 :tag1:tag2:\n** <point>H2"
  7297. (let ((org-use-tag-inheritance t)
  7298. (org-tags-column 1))
  7299. (org-toggle-tag "foo"))
  7300. (buffer-string)))))
  7301. (ert-deftest test-org/tags-expand ()
  7302. "Test `org-tags-expand' specifications."
  7303. ;; Expand tag groups as a regexp enclosed within curly brackets.
  7304. (should
  7305. (equal "{\\<[ABC]\\>}"
  7306. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7307. (org-mode-restart)
  7308. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  7309. (should
  7310. (equal "{\\<\\(?:Aa\\|Bb\\|Cc\\)\\>}"
  7311. (org-test-with-temp-text "#+TAGS: [ Aa : Bb Cc ]"
  7312. (org-mode-restart)
  7313. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "Aa")))))
  7314. ;; Preserve operator before the regexp.
  7315. (should
  7316. (equal "+{\\<[ABC]\\>}"
  7317. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7318. (org-mode-restart)
  7319. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "+A")))))
  7320. (should
  7321. (equal "-{\\<[ABC]\\>}"
  7322. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7323. (org-mode-restart)
  7324. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "-A")))))
  7325. ;; Handle "|" syntax.
  7326. (should
  7327. (equal "{\\<[ABC]\\>}|D"
  7328. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7329. (org-mode-restart)
  7330. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|D")))))
  7331. ;; Handle nested groups.
  7332. (should
  7333. (equal "{\\<[A-D]\\>}"
  7334. (org-test-with-temp-text "#+TAGS: [ A : B C ]\n#+TAGS: [ B : D ]"
  7335. (org-mode-restart)
  7336. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  7337. ;; Expand multiple occurrences of the same group.
  7338. (should
  7339. (equal "{\\<[ABC]\\>}|{\\<[ABC]\\>}"
  7340. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7341. (org-mode-restart)
  7342. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|A")))))
  7343. ;; Preserve regexp matches.
  7344. (should
  7345. (equal "{A+}"
  7346. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7347. (org-mode-restart)
  7348. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "{A+}"))))))
  7349. ;;; TODO keywords
  7350. (ert-deftest test-org/auto-repeat-maybe ()
  7351. "Test `org-auto-repeat-maybe' specifications."
  7352. ;; Do not auto repeat when there is no valid time stamp with
  7353. ;; a repeater in the entry.
  7354. (should-not
  7355. (string-prefix-p
  7356. "* TODO H"
  7357. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7358. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
  7359. (org-todo "DONE")
  7360. (buffer-string)))))
  7361. (should-not
  7362. (string-prefix-p
  7363. "* TODO H"
  7364. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7365. (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
  7366. (org-todo "DONE")
  7367. (buffer-string)))))
  7368. ;; When switching to DONE state, switch back to first TODO keyword
  7369. ;; in sequence, or the same keyword if they have different types.
  7370. (should
  7371. (string-prefix-p
  7372. "* TODO H"
  7373. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7374. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7375. (org-todo "DONE")
  7376. (buffer-string)))))
  7377. (should
  7378. (string-prefix-p
  7379. "* KWD1 H"
  7380. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  7381. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  7382. (org-todo "DONE")
  7383. (buffer-string)))))
  7384. (should
  7385. (string-prefix-p
  7386. "* KWD2 H"
  7387. (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
  7388. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  7389. (org-todo "DONE")
  7390. (buffer-string)))))
  7391. ;; If there was no TODO keyword in the first place, do not insert
  7392. ;; any either.
  7393. (should
  7394. (string-prefix-p
  7395. "* H"
  7396. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7397. (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
  7398. (org-todo "DONE")
  7399. (buffer-string)))))
  7400. ;; Revert to REPEAT_TO_STATE, if set.
  7401. (should
  7402. (string-prefix-p
  7403. "* KWD2 H"
  7404. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  7405. (org-test-with-temp-text
  7406. "* KWD2 H
  7407. :PROPERTIES:
  7408. :REPEAT_TO_STATE: KWD2
  7409. :END:
  7410. <2012-03-29 Thu +2y>"
  7411. (org-todo "DONE")
  7412. (buffer-string)))))
  7413. ;; When switching to DONE state, update base date. If there are
  7414. ;; multiple repeated time stamps, update them all.
  7415. (should
  7416. (string-match-p
  7417. "<2014-03-29 .* \\+2y>"
  7418. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7419. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7420. (org-todo "DONE")
  7421. (buffer-string)))))
  7422. (should
  7423. (string-match-p
  7424. "<2015-03-04 .* \\+1y>"
  7425. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7426. (org-test-with-temp-text
  7427. "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
  7428. (org-todo "DONE")
  7429. (buffer-string)))))
  7430. ;; Throw an error if repeater unit is the hour and no time is
  7431. ;; provided in the time-stamp.
  7432. (should-error
  7433. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7434. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
  7435. (org-todo "DONE")
  7436. (buffer-string))))
  7437. ;; Handle every repeater type using hours step.
  7438. (should
  7439. (string-match-p
  7440. "2014-03-04 .* 02:00"
  7441. (org-test-at-time "<2014-03-04 02:35>"
  7442. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 +8h>"
  7443. (org-todo "DONE")
  7444. (buffer-string)))))
  7445. (should
  7446. (string-match-p
  7447. "2014-03-04 .* 10:00"
  7448. (org-test-at-time "<2014-03-04 02:35>"
  7449. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 ++8h>"
  7450. (org-todo "DONE")
  7451. (buffer-string)))))
  7452. (should
  7453. (string-match-p
  7454. "2014-03-04 .* 10:35"
  7455. (org-test-at-time "<2014-03-04 02:35>"
  7456. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 .+8h>"
  7457. (org-todo "DONE")
  7458. (buffer-string)))))
  7459. ;; Do not repeat inactive time stamps with a repeater.
  7460. (should-not
  7461. (string-match-p
  7462. "\\[2014-03-29 .* \\+2y\\]"
  7463. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7464. (org-test-with-temp-text
  7465. "* TODO H\n[2012-03-29 Thu. +2y]"
  7466. (org-todo "DONE")
  7467. (buffer-string)))))
  7468. ;; Do not repeat commented time stamps.
  7469. (should-not
  7470. (string-prefix-p
  7471. "<2015-03-04 .* \\+1y>"
  7472. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7473. (org-test-with-temp-text
  7474. "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
  7475. (org-todo "DONE")
  7476. (buffer-string)))))
  7477. (should-not
  7478. (string-prefix-p
  7479. "<2015-03-04 .* \\+1y>"
  7480. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7481. (org-test-with-temp-text
  7482. "* TODO H
  7483. <2012-03-29 Thu. +2y>
  7484. #+BEGIN_EXAMPLE
  7485. <2014-03-04 Tue +1y>
  7486. #+END_EXAMPLE"
  7487. (org-todo "DONE")
  7488. (buffer-string)))))
  7489. ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
  7490. ;; entry, record time of last repeat.
  7491. (should-not
  7492. (string-match-p
  7493. ":LAST_REPEAT:"
  7494. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  7495. (org-log-repeat nil))
  7496. (cl-letf (((symbol-function 'org-add-log-setup)
  7497. (lambda (&rest args) nil)))
  7498. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  7499. (org-todo "DONE")
  7500. (buffer-string))))))
  7501. (should
  7502. (string-match-p
  7503. ":LAST_REPEAT:"
  7504. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  7505. (org-log-repeat t))
  7506. (cl-letf (((symbol-function 'org-add-log-setup)
  7507. (lambda (&rest args) nil)))
  7508. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  7509. (org-todo "DONE")
  7510. (buffer-string))))))
  7511. (should
  7512. (string-match-p
  7513. ":LAST_REPEAT:"
  7514. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7515. (cl-letf (((symbol-function 'org-add-log-setup)
  7516. (lambda (&rest args) nil)))
  7517. (org-test-with-temp-text
  7518. "* TODO H\n<2012-03-29 Thu +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
  7519. (org-todo "DONE")
  7520. (buffer-string))))))
  7521. ;; When a SCHEDULED entry has no repeater, remove it upon repeating
  7522. ;; the entry as it is no longer relevant.
  7523. (should-not
  7524. (string-match-p
  7525. "^SCHEDULED:"
  7526. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7527. (org-test-with-temp-text
  7528. "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
  7529. (org-todo "DONE")
  7530. (buffer-string)))))
  7531. ;; Properly advance repeater even when a clock entry is specified
  7532. ;; and `org-log-repeat' is nil.
  7533. (should
  7534. (string-match-p
  7535. "SCHEDULED: <2014-03-29"
  7536. (let ((org-log-repeat nil)
  7537. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7538. (org-test-with-temp-text
  7539. "* TODO H
  7540. SCHEDULED: <2012-03-29 Thu +2y>
  7541. CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] => 6:40"
  7542. (org-todo "DONE")
  7543. (buffer-string)))))
  7544. ;; Make sure that logbook state change record does not get
  7545. ;; duplicated when `org-log-repeat' `org-log-done' are non-nil.
  7546. (should
  7547. (string-match-p
  7548. (rx "* TODO Read book
  7549. SCHEDULED: <2021-06-16 " (1+ (not space)) " +1d>
  7550. :PROPERTIES:
  7551. :LAST_REPEAT:" (1+ nonl) "
  7552. :END:
  7553. - State \"DONE\" from \"TODO\"" (1+ nonl) buffer-end)
  7554. (let ((org-log-repeat 'time)
  7555. (org-todo-keywords '((sequence "TODO" "|" "DONE(d!)")))
  7556. (org-log-into-drawer nil))
  7557. (org-test-with-temp-text
  7558. "* TODO Read book
  7559. SCHEDULED: <2021-06-15 Tue +1d>"
  7560. (org-todo "DONE")
  7561. (when (memq 'org-add-log-note post-command-hook)
  7562. (org-add-log-note))
  7563. (buffer-string))))))
  7564. (ert-deftest test-org/org-log-done ()
  7565. "Test `org-log-done' specifications."
  7566. ;; nil value.
  7567. (should
  7568. (string=
  7569. "* DONE task"
  7570. (let ((org-log-done nil)
  7571. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7572. (org-test-with-temp-text
  7573. "* TODO task"
  7574. (org-todo "DONE")
  7575. (when (memq 'org-add-log-note post-command-hook)
  7576. (org-add-log-note))
  7577. (buffer-string)))))
  7578. ;; `time' value.
  7579. (should
  7580. (string=
  7581. (format
  7582. "* DONE task
  7583. CLOSED: %s"
  7584. (org-test-with-temp-text ""
  7585. (org-insert-time-stamp (current-time) t t)
  7586. (buffer-string)))
  7587. (let ((org-log-done 'time)
  7588. (org-log-done-with-time t)
  7589. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7590. (org-test-with-temp-text
  7591. "* TODO task"
  7592. (org-todo "DONE")
  7593. (when (memq 'org-add-log-note post-command-hook)
  7594. (org-add-log-note))
  7595. (buffer-string)))))
  7596. (should
  7597. (string=
  7598. (format
  7599. "* DONE task
  7600. CLOSED: %s"
  7601. (org-test-with-temp-text ""
  7602. (org-insert-time-stamp (current-time) nil t)
  7603. (buffer-string)))
  7604. (let ((org-log-done 'time)
  7605. (org-log-done-with-time nil)
  7606. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7607. (org-test-with-temp-text
  7608. "* TODO task"
  7609. (org-todo "DONE")
  7610. (when (memq 'org-add-log-note post-command-hook)
  7611. (org-add-log-note))
  7612. (buffer-string)))))
  7613. ;; TODO: Test `note' value.
  7614. ;; Test startup overrides.
  7615. (should
  7616. (string=
  7617. "#+STARTUP: nologdone
  7618. * DONE task"
  7619. (let ((org-log-done 'time)
  7620. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7621. (org-test-with-temp-text
  7622. "#+STARTUP: nologdone
  7623. <point>* TODO task"
  7624. (org-set-regexps-and-options)
  7625. (org-todo "DONE")
  7626. (when (memq 'org-add-log-note post-command-hook)
  7627. (org-add-log-note))
  7628. (buffer-string)))))
  7629. (should
  7630. (string=
  7631. (format
  7632. "#+STARTUP: logdone
  7633. * DONE task
  7634. CLOSED: %s"
  7635. (org-test-with-temp-text ""
  7636. (org-insert-time-stamp (current-time) t t)
  7637. (buffer-string)))
  7638. (let ((org-log-done nil)
  7639. (org-log-done-with-time t)
  7640. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7641. (org-test-with-temp-text
  7642. "#+STARTUP: logdone
  7643. <point>* TODO task"
  7644. (org-set-regexps-and-options)
  7645. (org-todo "DONE")
  7646. (when (memq 'org-add-log-note post-command-hook)
  7647. (org-add-log-note))
  7648. (buffer-string)))))
  7649. ;; Test local property overrides.
  7650. (should
  7651. (string=
  7652. "* DONE task
  7653. :PROPERTIES:
  7654. :LOGGING: nil
  7655. :END:"
  7656. (let ((org-log-done 'time)
  7657. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7658. (org-test-with-temp-text
  7659. "* TODO task
  7660. :PROPERTIES:
  7661. :LOGGING: nil
  7662. :END:"
  7663. (org-todo "DONE")
  7664. (when (memq 'org-add-log-note post-command-hook)
  7665. (org-add-log-note))
  7666. (buffer-string)))))
  7667. (should
  7668. (string=
  7669. (format
  7670. "* DONE task
  7671. CLOSED: %s
  7672. :PROPERTIES:
  7673. :LOGGING: logdone
  7674. :END:"
  7675. (org-test-with-temp-text ""
  7676. (org-insert-time-stamp (current-time) t t)
  7677. (buffer-string)))
  7678. (let ((org-log-done nil)
  7679. (org-log-done-with-time t)
  7680. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7681. (org-test-with-temp-text
  7682. "* TODO task
  7683. :PROPERTIES:
  7684. :LOGGING: logdone
  7685. :END:"
  7686. (org-todo "DONE")
  7687. (when (memq 'org-add-log-note post-command-hook)
  7688. (org-add-log-note))
  7689. (buffer-string))))))
  7690. (ert-deftest test-org/org-todo-prefix ()
  7691. "Test `org-todo' prefix arg behavior."
  7692. ;; FIXME: Add tests for all other allowed prefix arguments.
  7693. ;; -1 prefix arg should cancel repeater and mark DONE.
  7694. (should
  7695. (string-match-p
  7696. "DONE H\\(.*\n\\)*<2012-03-29 Thu \\+0y>"
  7697. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7698. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7699. (org-todo -1)
  7700. (buffer-string)))))
  7701. ;; - prefix arg should cancel repeater and mark DONE.
  7702. (should
  7703. (string-match-p
  7704. "DONE H\\(.*\n\\)*<2012-03-29 Thu \\+0y>"
  7705. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7706. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7707. (org-todo '-)
  7708. (buffer-string))))))
  7709. ;;; Timestamps API
  7710. (ert-deftest test-org/at-timestamp-p ()
  7711. "Test `org-at-timestamp-p' specifications."
  7712. (should
  7713. (org-test-with-temp-text "<2012-03-29 Thu>"
  7714. (org-at-timestamp-p)))
  7715. (should-not
  7716. (org-test-with-temp-text "2012-03-29 Thu"
  7717. (org-at-timestamp-p)))
  7718. ;; Test return values.
  7719. (should
  7720. (eq 'bracket
  7721. (org-test-with-temp-text "<2012-03-29 Thu>"
  7722. (org-at-timestamp-p))))
  7723. (should
  7724. (eq 'year
  7725. (org-test-with-temp-text "<<point>2012-03-29 Thu>"
  7726. (org-at-timestamp-p))))
  7727. (should
  7728. (eq 'month
  7729. (org-test-with-temp-text "<2012-<point>03-29 Thu>"
  7730. (org-at-timestamp-p))))
  7731. (should
  7732. (eq 'day
  7733. (org-test-with-temp-text "<2012-03-<point>29 Thu>"
  7734. (org-at-timestamp-p))))
  7735. (should
  7736. (eq 'day
  7737. (org-test-with-temp-text "<2012-03-29 T<point>hu>"
  7738. (org-at-timestamp-p))))
  7739. (should
  7740. (wholenump
  7741. (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
  7742. (org-at-timestamp-p))))
  7743. (should
  7744. (eq 'bracket
  7745. (org-test-with-temp-text "<2012-03-29 Thu<point>>"
  7746. (org-at-timestamp-p))))
  7747. (should
  7748. (eq 'after
  7749. (org-test-with-temp-text "<2012-03-29 Thu><point>»"
  7750. (org-at-timestamp-p))))
  7751. ;; Test `inactive' optional argument.
  7752. (should
  7753. (org-test-with-temp-text "[2012-03-29 Thu]"
  7754. (org-at-timestamp-p 'inactive)))
  7755. (should-not
  7756. (org-test-with-temp-text "[2012-03-29 Thu]"
  7757. (org-at-timestamp-p)))
  7758. ;; When optional argument is `agenda', recognize time-stamps in
  7759. ;; planning info line, property drawers and clocks.
  7760. (should
  7761. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7762. (org-at-timestamp-p 'agenda)))
  7763. (should-not
  7764. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7765. (org-at-timestamp-p)))
  7766. (should
  7767. (org-test-with-temp-text
  7768. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7769. (org-at-timestamp-p 'agenda)))
  7770. (should-not
  7771. (org-test-with-temp-text
  7772. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7773. (org-at-timestamp-p)))
  7774. (should
  7775. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7776. (let ((org-agenda-include-inactive-timestamps t))
  7777. (org-at-timestamp-p 'agenda))))
  7778. (should-not
  7779. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7780. (let ((org-agenda-include-inactive-timestamps t))
  7781. (org-at-timestamp-p))))
  7782. (should-not
  7783. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7784. (let ((org-agenda-include-inactive-timestamps t))
  7785. (org-at-timestamp-p 'inactive))))
  7786. ;; When optional argument is `lax', match any part of the document
  7787. ;; with Org timestamp syntax.
  7788. (should
  7789. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7790. (org-at-timestamp-p 'lax)))
  7791. (should-not
  7792. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7793. (org-at-timestamp-p)))
  7794. (should
  7795. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7796. (org-at-timestamp-p 'lax)))
  7797. (should-not
  7798. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7799. (org-at-timestamp-p)))
  7800. (should
  7801. (org-test-with-temp-text
  7802. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7803. (org-at-timestamp-p 'lax)))
  7804. (should-not
  7805. (org-test-with-temp-text
  7806. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7807. (org-at-timestamp-p)))
  7808. ;; Optional argument `lax' also matches inactive timestamps.
  7809. (should
  7810. (org-test-with-temp-text "# [2012-03-29 Thu]<point>"
  7811. (org-at-timestamp-p 'lax))))
  7812. (ert-deftest test-org/time-stamp ()
  7813. "Test `org-time-stamp' specifications."
  7814. ;; Insert chosen time stamp at point.
  7815. (should
  7816. (string-match
  7817. "Te<2014-03-04 .*?>xt"
  7818. (org-test-with-temp-text "Te<point>xt"
  7819. (cl-letf (((symbol-function 'org-read-date)
  7820. (lambda (&rest args)
  7821. (org-time-string-to-time "2014-03-04"))))
  7822. (org-time-stamp nil)
  7823. (buffer-string)))))
  7824. ;; With a prefix argument, also insert time.
  7825. (should
  7826. (string-match
  7827. "Te<2014-03-04 .*? 00:41>xt"
  7828. (org-test-with-temp-text "Te<point>xt"
  7829. (cl-letf (((symbol-function 'org-read-date)
  7830. (lambda (&rest args)
  7831. (org-time-string-to-time "2014-03-04 00:41"))))
  7832. (org-time-stamp '(4))
  7833. (buffer-string)))))
  7834. ;; With two universal prefix arguments, insert an active timestamp
  7835. ;; with the current time without prompting the user.
  7836. (should
  7837. (string-match
  7838. "Te<2014-03-04 .*? 00:41>xt"
  7839. (org-test-with-temp-text "Te<point>xt"
  7840. (org-test-at-time "2014-03-04 00:41"
  7841. (org-time-stamp '(16))
  7842. (buffer-string)))))
  7843. ;; When optional argument is non-nil, insert an inactive timestamp.
  7844. (should
  7845. (string-match
  7846. "Te\\[2014-03-04 .*?\\]xt"
  7847. (org-test-with-temp-text "Te<point>xt"
  7848. (cl-letf (((symbol-function 'org-read-date)
  7849. (lambda (&rest args)
  7850. (org-time-string-to-time "2014-03-04"))))
  7851. (org-time-stamp nil t)
  7852. (buffer-string)))))
  7853. ;; When called from a timestamp, replace existing one.
  7854. (should
  7855. (string-match
  7856. "<2014-03-04 .*?>"
  7857. (org-test-with-temp-text "<2012-03-29<point> thu.>"
  7858. (cl-letf (((symbol-function 'org-read-date)
  7859. (lambda (&rest args)
  7860. (org-time-string-to-time "2014-03-04"))))
  7861. (org-time-stamp nil)
  7862. (buffer-string)))))
  7863. (should
  7864. (string-match
  7865. "<2014-03-04 .*?>--<2014-03-04 .*?>"
  7866. (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
  7867. (cl-letf (((symbol-function 'org-read-date)
  7868. (lambda (&rest args)
  7869. (org-time-string-to-time "2014-03-04"))))
  7870. (org-time-stamp nil)
  7871. (buffer-string)))))
  7872. ;; When replacing a timestamp, preserve repeater, if any.
  7873. (should
  7874. (string-match
  7875. "<2014-03-04 .*? \\+2y>"
  7876. (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
  7877. (cl-letf (((symbol-function 'org-read-date)
  7878. (lambda (&rest args)
  7879. (org-time-string-to-time "2014-03-04"))))
  7880. (org-time-stamp nil)
  7881. (buffer-string)))))
  7882. ;; When called twice in a raw, build a date range.
  7883. (should
  7884. (string-match
  7885. "<2012-03-29 .*?>--<2014-03-04 .*?>"
  7886. (org-test-with-temp-text "<2012-03-29 thu.><point>"
  7887. (cl-letf (((symbol-function 'org-read-date)
  7888. (lambda (&rest args)
  7889. (org-time-string-to-time "2014-03-04"))))
  7890. (let ((last-command 'org-time-stamp)
  7891. (this-command 'org-time-stamp))
  7892. (org-time-stamp nil))
  7893. (buffer-string))))))
  7894. (ert-deftest test-org/timestamp-has-time-p ()
  7895. "Test `org-timestamp-has-time-p' specifications."
  7896. ;; With time.
  7897. (should
  7898. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7899. (org-timestamp-has-time-p (org-element-context))))
  7900. ;; Without time.
  7901. (should-not
  7902. (org-test-with-temp-text "<2012-03-29 Thu>"
  7903. (org-timestamp-has-time-p (org-element-context)))))
  7904. (ert-deftest test-org/get-repeat ()
  7905. "Test `org-get-repeat' specifications."
  7906. (should
  7907. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
  7908. (org-get-repeat)))
  7909. (should-not
  7910. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
  7911. (org-get-repeat)))
  7912. ;; Return proper repeat string.
  7913. (should
  7914. (equal "+2y"
  7915. (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
  7916. (org-get-repeat))))
  7917. ;; Prevent false positive (commented or verbatim time stamps)
  7918. (should-not
  7919. (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
  7920. (org-get-repeat)))
  7921. (should-not
  7922. (org-test-with-temp-text
  7923. "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
  7924. (org-get-repeat)))
  7925. ;; Return nil when called before first heading.
  7926. (should-not
  7927. (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
  7928. (org-get-repeat)))
  7929. ;; When called with an optional argument, extract repeater from that
  7930. ;; string instead.
  7931. (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
  7932. (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
  7933. (ert-deftest test-org/timestamp-format ()
  7934. "Test `org-timestamp-format' specifications."
  7935. ;; Regular test.
  7936. (should
  7937. (equal
  7938. "2012-03-29 16:40"
  7939. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7940. (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
  7941. ;; Range end.
  7942. (should
  7943. (equal
  7944. "2012-03-29"
  7945. (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
  7946. (org-timestamp-format (org-element-context) "%Y-%m-%d" t)))))
  7947. (ert-deftest test-org/timestamp-split-range ()
  7948. "Test `org-timestamp-split-range' specifications."
  7949. ;; Extract range start (active).
  7950. (should
  7951. (equal '(2012 3 29)
  7952. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7953. (let ((ts (org-timestamp-split-range (org-element-context))))
  7954. (mapcar (lambda (p) (org-element-property p ts))
  7955. '(:year-end :month-end :day-end))))))
  7956. ;; Extract range start (inactive)
  7957. (should
  7958. (equal '(2012 3 29)
  7959. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7960. (let ((ts (org-timestamp-split-range (org-element-context))))
  7961. (mapcar (lambda (p) (org-element-property p ts))
  7962. '(:year-end :month-end :day-end))))))
  7963. ;; Extract range end (active).
  7964. (should
  7965. (equal '(2012 3 30)
  7966. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7967. (let ((ts (org-timestamp-split-range
  7968. (org-element-context) t)))
  7969. (mapcar (lambda (p) (org-element-property p ts))
  7970. '(:year-end :month-end :day-end))))))
  7971. ;; Extract range end (inactive)
  7972. (should
  7973. (equal '(2012 3 30)
  7974. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7975. (let ((ts (org-timestamp-split-range
  7976. (org-element-context) t)))
  7977. (mapcar (lambda (p) (org-element-property p ts))
  7978. '(:year-end :month-end :day-end))))))
  7979. ;; Return the timestamp if not a range.
  7980. (should
  7981. (org-test-with-temp-text "[2012-03-29 Thu]"
  7982. (let* ((ts-orig (org-element-context))
  7983. (ts-copy (org-timestamp-split-range ts-orig)))
  7984. (eq ts-orig ts-copy))))
  7985. (should
  7986. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7987. (let* ((ts-orig (org-element-context))
  7988. (ts-copy (org-timestamp-split-range ts-orig)))
  7989. (eq ts-orig ts-copy)))))
  7990. (ert-deftest test-org/timestamp-translate ()
  7991. "Test `org-timestamp-translate' specifications."
  7992. ;; Translate whole date range.
  7993. (should
  7994. (equal "<29>--<30>"
  7995. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7996. (let ((org-display-custom-times t)
  7997. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7998. (org-timestamp-translate (org-element-context))))))
  7999. ;; Translate date range start.
  8000. (should
  8001. (equal "<29>"
  8002. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  8003. (let ((org-display-custom-times t)
  8004. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  8005. (org-timestamp-translate (org-element-context) 'start)))))
  8006. ;; Translate date range end.
  8007. (should
  8008. (equal "<30>"
  8009. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  8010. (let ((org-display-custom-times t)
  8011. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  8012. (org-timestamp-translate (org-element-context) 'end)))))
  8013. ;; Translate time range.
  8014. (should
  8015. (equal "<08>--<16>"
  8016. (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
  8017. (let ((org-display-custom-times t)
  8018. (org-time-stamp-custom-formats '("<%d>" . "<%H>")))
  8019. (org-timestamp-translate (org-element-context))))))
  8020. ;; Translate non-range timestamp.
  8021. (should
  8022. (equal "<29>"
  8023. (org-test-with-temp-text "<2012-03-29 Thu>"
  8024. (let ((org-display-custom-times t)
  8025. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  8026. (org-timestamp-translate (org-element-context))))))
  8027. ;; Do not change `diary' timestamps.
  8028. (should
  8029. (equal "<%%(org-float t 4 2)>"
  8030. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  8031. (let ((org-display-custom-times t)
  8032. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  8033. (org-timestamp-translate (org-element-context)))))))
  8034. (ert-deftest test-org/timestamp-from-string ()
  8035. "Test `org-timestamp-from-string' specifications."
  8036. ;; Return nil if argument is not a valid Org timestamp.
  8037. (should-not (org-timestamp-from-string ""))
  8038. (should-not (org-timestamp-from-string nil))
  8039. (should-not (org-timestamp-from-string "<2012-03-29"))
  8040. ;; Otherwise, return a valid Org timestamp object.
  8041. (should
  8042. (string-match-p "<2012-03-29 .+>"
  8043. (org-element-interpret-data
  8044. (org-timestamp-from-string "<2012-03-29 Thu>"))))
  8045. (should
  8046. (string-match-p "[2014-03-04 .+]"
  8047. (org-element-interpret-data
  8048. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  8049. (ert-deftest test-org/timestamp-from-time ()
  8050. "Test `org-timestamp-from-time' specifications."
  8051. ;; Standard test.
  8052. (should
  8053. (string-match-p
  8054. "<2012-03-29 .+>"
  8055. (org-element-interpret-data
  8056. (org-timestamp-from-time
  8057. (org-time-string-to-time "<2012-03-29 Thu 16:40>")))))
  8058. ;; When optional argument WITH-TIME is non-nil, provide time
  8059. ;; information.
  8060. (should
  8061. (string-match-p
  8062. "<2012-03-29 .+ 16:40>"
  8063. (org-element-interpret-data
  8064. (org-timestamp-from-time
  8065. (org-time-string-to-time "<2012-03-29 Thu 16:40>")
  8066. t))))
  8067. ;; When optional argument INACTIVE is non-nil, return an inactive
  8068. ;; timestamp.
  8069. (should
  8070. (string-match-p
  8071. "[2012-03-29 .+]"
  8072. (org-element-interpret-data
  8073. (org-timestamp-from-time
  8074. (org-time-string-to-time "<2012-03-29 Thu 16:40>")
  8075. nil t)))))
  8076. (ert-deftest test-org/timestamp-to-time ()
  8077. "Test `org-timestamp-to-time' specifications."
  8078. (should
  8079. (equal "2014-03-04"
  8080. (format-time-string
  8081. "%Y-%m-%d"
  8082. (org-timestamp-to-time
  8083. (org-timestamp-from-string "<2014-03-04 Tue>")))))
  8084. (should
  8085. (equal "2014-03-04"
  8086. (format-time-string
  8087. "%Y-%m-%d"
  8088. (org-timestamp-to-time
  8089. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  8090. (should
  8091. (equal "2012-03-29 08:30"
  8092. (format-time-string
  8093. "%Y-%m-%d %H:%M"
  8094. (org-timestamp-to-time
  8095. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")))))
  8096. (should
  8097. (equal "2012-03-29"
  8098. (format-time-string
  8099. "%Y-%m-%d"
  8100. (org-timestamp-to-time
  8101. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")))))
  8102. (should
  8103. (equal "2012-03-29"
  8104. (format-time-string
  8105. "%Y-%m-%d"
  8106. (org-timestamp-to-time
  8107. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")))))
  8108. ;; When optional argument END is non-nil, use end of date range or
  8109. ;; time range.
  8110. (should
  8111. (equal "2012-03-29 16:40"
  8112. (format-time-string
  8113. "%Y-%m-%d %H:%M"
  8114. (org-timestamp-to-time
  8115. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")
  8116. t))))
  8117. (should
  8118. (equal "2014-03-04"
  8119. (format-time-string
  8120. "%Y-%m-%d"
  8121. (org-timestamp-to-time
  8122. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")
  8123. t))))
  8124. (should
  8125. (equal "2014-03-04"
  8126. (format-time-string
  8127. "%Y-%m-%d"
  8128. (org-timestamp-to-time
  8129. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")
  8130. t)))))
  8131. ;;; Yank and Kill
  8132. (ert-deftest test-org/paste-subtree ()
  8133. "Test `org-paste-subtree' specifications."
  8134. ;; Return an error if text to yank is not a set of subtrees.
  8135. (should-error (org-paste-subtree nil "Text"))
  8136. ;; Adjust level according to current one.
  8137. (should
  8138. (equal "* H\n* Text\n"
  8139. (org-test-with-temp-text "* H\n<point>"
  8140. (org-paste-subtree nil "* Text")
  8141. (buffer-string))))
  8142. (should
  8143. (equal "* H1\n** H2\n** Text\n"
  8144. (org-test-with-temp-text "* H1\n** H2\n<point>"
  8145. (org-paste-subtree nil "* Text")
  8146. (buffer-string))))
  8147. ;; When not on a heading, move to next heading before yanking.
  8148. (should
  8149. (equal "* H1\nParagraph\n* Text\n* H2"
  8150. (org-test-with-temp-text "* H1\n<point>Paragraph\n* H2"
  8151. (org-paste-subtree nil "* Text")
  8152. (buffer-string))))
  8153. ;; If point is between two headings, use the deepest level.
  8154. (should
  8155. (equal "* H1\n\n* Text\n* H2"
  8156. (org-test-with-temp-text "* H1\n<point>\n* H2"
  8157. (org-paste-subtree nil "* Text")
  8158. (buffer-string))))
  8159. (should
  8160. (equal "** H1\n\n** Text\n* H2"
  8161. (org-test-with-temp-text "** H1\n<point>\n* H2"
  8162. (org-paste-subtree nil "* Text")
  8163. (buffer-string))))
  8164. (should
  8165. (equal "* H1\n\n** Text\n** H2"
  8166. (org-test-with-temp-text "* H1\n<point>\n** H2"
  8167. (org-paste-subtree nil "* Text")
  8168. (buffer-string))))
  8169. ;; When on an empty heading, after the stars, deduce the new level
  8170. ;; from the number of stars.
  8171. (should
  8172. (equal "*** Text\n"
  8173. (org-test-with-temp-text "*** <point>"
  8174. (org-paste-subtree nil "* Text")
  8175. (buffer-string))))
  8176. ;; Optional argument LEVEL forces a level for the subtree.
  8177. (should
  8178. (equal "* H\n*** Text\n"
  8179. (org-test-with-temp-text "* H<point>"
  8180. (org-paste-subtree 3 "* Text")
  8181. (buffer-string)))))
  8182. (ert-deftest test-org/cut-and-paste-subtree ()
  8183. "Test `org-cut-subtree' and `org-paste-subtree'."
  8184. (should
  8185. (equal
  8186. "* Two
  8187. two
  8188. * One
  8189. "
  8190. (org-test-with-temp-text
  8191. "* One
  8192. <point>* Two
  8193. two
  8194. "
  8195. (call-interactively #'org-cut-subtree)
  8196. (goto-char (point-min))
  8197. (call-interactively #'org-paste-subtree)
  8198. (buffer-string))))
  8199. (should
  8200. (equal
  8201. "* One
  8202. * Two
  8203. "
  8204. (org-test-with-temp-text
  8205. "* One
  8206. <point>* Two
  8207. "
  8208. (call-interactively #'org-cut-subtree)
  8209. (backward-char)
  8210. (call-interactively #'org-paste-subtree)
  8211. (buffer-string)))))
  8212. (provide 'test-org)
  8213. ;;; test-org.el ends here