test-org.el 273 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405
  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-read-date ()
  234. "Test `org-read-date' specifications."
  235. ;; Parse ISO date with abbreviated year and month.
  236. (should (equal "2012-03-29 16:40"
  237. (let ((org-time-was-given t))
  238. (org-read-date t nil "12-3-29 16:40"))))
  239. ;; Parse Europeans dates.
  240. (should (equal "2012-03-29 16:40"
  241. (let ((org-time-was-given t))
  242. (org-read-date t nil "29.03.2012 16:40"))))
  243. ;; Parse Europeans dates without year.
  244. (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
  245. (let ((org-time-was-given t))
  246. (org-read-date t nil "29.03. 16:40"))))
  247. ;; Relative date applied to current time if there is single
  248. ;; plus/minus, or to default date when there are two of them.
  249. (should
  250. (equal
  251. "2015-03-04"
  252. (org-test-at-time "2014-03-04"
  253. (org-read-date
  254. t nil "+1y" nil
  255. (org-time-string-to-time "2012-03-29")))))
  256. (should
  257. (equal
  258. "2013-03-29"
  259. (org-test-at-time "2014-03-04"
  260. (org-read-date
  261. t nil "++1y" nil
  262. (org-time-string-to-time "2012-03-29")))))
  263. ;; When `org-read-date-prefer-future' is non-nil, prefer future
  264. ;; dates (relatively to now) when incomplete. Otherwise, use
  265. ;; default date.
  266. (should
  267. (equal
  268. "2014-04-01"
  269. (org-test-at-time "2014-03-04"
  270. (let ((org-read-date-prefer-future t))
  271. (org-read-date t nil "1")))))
  272. (should
  273. (equal
  274. "2013-03-04"
  275. (org-test-at-time "2012-03-29"
  276. (let ((org-read-date-prefer-future t))
  277. (org-read-date t nil "3-4")))))
  278. (should
  279. (equal
  280. "2012-03-04"
  281. (org-test-at-time "2012-03-29"
  282. (let ((org-read-date-prefer-future nil))
  283. (org-read-date t nil "3-4")))))
  284. ;; When set to `org-read-date-prefer-future' is set to `time', read
  285. ;; day is moved to tomorrow if specified hour is before current
  286. ;; time. However, it only happens in no other part of the date is
  287. ;; specified.
  288. (should
  289. (equal
  290. "2012-03-30"
  291. (org-test-at-time "2012-03-29 16:40"
  292. (let ((org-read-date-prefer-future 'time))
  293. (org-read-date t nil "00:40" nil)))))
  294. (should-not
  295. (equal
  296. "2012-03-30"
  297. (org-test-at-time "2012-03-29 16:40"
  298. (let ((org-read-date-prefer-future 'time))
  299. (org-read-date t nil "29 00:40" nil)))))
  300. ;; Caveat: `org-read-date-prefer-future' always refers to current
  301. ;; time, not default time, when they differ.
  302. (should
  303. (equal
  304. "2014-04-01"
  305. (org-test-at-time "2014-03-04"
  306. (let ((org-read-date-prefer-future t))
  307. (org-read-date
  308. t nil "1" nil
  309. (org-time-string-to-time "2012-03-29"))))))
  310. (should
  311. (equal
  312. "2014-03-25"
  313. (org-test-at-time "2014-03-04"
  314. (let ((org-read-date-prefer-future t))
  315. (org-read-date
  316. t nil "25" nil
  317. (org-time-string-to-time "2012-03-29")))))))
  318. (ert-deftest test-org/org-parse-time-string ()
  319. "Test `org-parse-time-string'."
  320. (should (equal (org-parse-time-string "2012-03-29 16:40")
  321. '(0 40 16 29 3 2012 nil -1 nil)))
  322. (should (equal (org-parse-time-string "[2012-03-29 16:40]")
  323. '(0 40 16 29 3 2012 nil -1 nil)))
  324. (should (equal (org-parse-time-string "<2012-03-29 16:40>")
  325. '(0 40 16 29 3 2012 nil -1 nil)))
  326. (should (equal (org-parse-time-string "<2012-03-29>")
  327. '(0 0 0 29 3 2012 nil -1 nil)))
  328. (should (equal (org-parse-time-string "<2012-03-29>" t)
  329. '(0 nil nil 29 3 2012 nil -1 nil))))
  330. (ert-deftest test-org/closest-date ()
  331. "Test `org-closest-date' specifications."
  332. (require 'calendar)
  333. ;; Time stamps without a repeater are returned unchanged.
  334. (should
  335. (equal
  336. '(3 29 2012)
  337. (calendar-gregorian-from-absolute
  338. (org-closest-date "<2012-03-29>" "<2014-03-04>" nil))))
  339. ;; Time stamps with a null repeater are returned unchanged.
  340. (should
  341. (equal
  342. '(3 29 2012)
  343. (calendar-gregorian-from-absolute
  344. (org-closest-date "<2012-03-29 +0d>" "<2014-03-04>" nil))))
  345. ;; if PREFER is set to `past' always return a date before, or equal
  346. ;; to CURRENT.
  347. (should
  348. (equal
  349. '(3 1 2014)
  350. (calendar-gregorian-from-absolute
  351. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'past))))
  352. (should
  353. (equal
  354. '(3 4 2014)
  355. (calendar-gregorian-from-absolute
  356. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'past))))
  357. ;; if PREFER is set to `future' always return a date before, or equal
  358. ;; to CURRENT.
  359. (should
  360. (equal
  361. '(3 29 2014)
  362. (calendar-gregorian-from-absolute
  363. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'future))))
  364. (should
  365. (equal
  366. '(3 4 2014)
  367. (calendar-gregorian-from-absolute
  368. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'future))))
  369. ;; If PREFER is neither `past' nor `future', select closest date.
  370. (should
  371. (equal
  372. '(3 1 2014)
  373. (calendar-gregorian-from-absolute
  374. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" nil))))
  375. (should
  376. (equal
  377. '(5 4 2014)
  378. (calendar-gregorian-from-absolute
  379. (org-closest-date "<2012-03-04 +1m>" "<2014-04-28>" nil))))
  380. ;; Test "day" repeater.
  381. (should
  382. (equal '(3 8 2014)
  383. (calendar-gregorian-from-absolute
  384. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'past))))
  385. (should
  386. (equal '(3 10 2014)
  387. (calendar-gregorian-from-absolute
  388. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'future))))
  389. ;; Test "month" repeater.
  390. (should
  391. (equal '(1 5 2015)
  392. (calendar-gregorian-from-absolute
  393. (org-closest-date "<2014-03-05 +2m>" "<2015-02-04>" 'past))))
  394. (should
  395. (equal '(3 29 2014)
  396. (calendar-gregorian-from-absolute
  397. (org-closest-date "<2012-03-29 +2m>" "<2014-03-04>" 'future))))
  398. ;; Test "year" repeater.
  399. (should
  400. (equal '(3 5 2014)
  401. (calendar-gregorian-from-absolute
  402. (org-closest-date "<2014-03-05 +2y>" "<2015-02-04>" 'past))))
  403. (should
  404. (equal '(3 29 2014)
  405. (calendar-gregorian-from-absolute
  406. (org-closest-date "<2012-03-29 +2y>" "<2014-03-04>" 'future)))))
  407. (ert-deftest test-org/deadline-close-p ()
  408. "Test `org-deadline-close-p' specifications."
  409. (org-test-at-time "2016-06-03 Fri 01:43"
  410. ;; Timestamps are close if they are within `ndays' of lead time.
  411. (org-test-with-temp-text "* Heading"
  412. (should (org-deadline-close-p "2016-06-03 Fri" 0))
  413. (should (org-deadline-close-p "2016-06-02 Thu" 0))
  414. (should-not (org-deadline-close-p "2016-06-04 Sat" 0))
  415. (should (org-deadline-close-p "2016-06-04 Sat" 1))
  416. (should (org-deadline-close-p "2016-06-03 Fri 12:00" 0)))
  417. ;; Read `ndays' from timestamp if argument not given.
  418. (org-test-with-temp-text "* H"
  419. (should (org-deadline-close-p "2016-06-04 Sat -1d"))
  420. (should-not (org-deadline-close-p "2016-06-04 Sat -0d"))
  421. (should (org-deadline-close-p "2016-06-10 Fri -1w"))
  422. (should-not (org-deadline-close-p "2016-06-11 Sat -1w")))
  423. ;; Prefer `ndays' argument over lead time in timestamp.
  424. (org-test-with-temp-text "* H"
  425. (should (org-deadline-close-p "2016-06-04 Sat -0d" 1))
  426. (should-not (org-deadline-close-p "2016-06-04 Sat -0d" 0)))
  427. ;; Completed tasks are never close.
  428. (let ((org-todo-keywords '(("TODO" "|" "DONE"))))
  429. (org-test-with-temp-text "* TODO Heading"
  430. (should (org-deadline-close-p "2016-06-03")))
  431. (org-test-with-temp-text "* DONE Heading"
  432. (should-not (org-deadline-close-p "2016-06-03"))))))
  433. ;;; Drawers
  434. (ert-deftest test-org/at-property-p ()
  435. "Test `org-at-property-p' specifications."
  436. (should
  437. (equal 't
  438. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:PROP: t\n:END:\n"
  439. (org-at-property-p))))
  440. (should
  441. (equal 't
  442. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n:END:\n"
  443. (org-at-property-p)))))
  444. (ert-deftest test-org/at-property-drawer-p ()
  445. "Test `org-at-property-drawer-p' specifications."
  446. (should
  447. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:PROP: t\n:END:\n"
  448. (org-at-property-drawer-p)))
  449. (should
  450. (org-test-with-temp-text ":PROPERTIES:\n:PROP: t\n:END:\n"
  451. (org-at-property-drawer-p)))
  452. ;; The function only returns t if point is at the first line of
  453. ;; a property block.
  454. (should-not
  455. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n:END:\n"
  456. (org-at-property-drawer-p)))
  457. ;; The function ignores incomplete drawers.
  458. (should-not
  459. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n"
  460. (org-at-property-drawer-p)))
  461. ;; tab separating the value.
  462. (should
  463. (org-test-with-temp-text ":PROPERTIES:\n:PROP: t\n:END:\n"
  464. (org-at-property-drawer-p))))
  465. (ert-deftest test-org/get-property-block ()
  466. "Test `org-get-property-block' specifications."
  467. (should
  468. (equal '(14 . 14)
  469. (org-test-with-temp-text ":PROPERTIES:\n:END:\n* H\n"
  470. (org-get-property-block))))
  471. (should
  472. (equal '(14 . 14)
  473. (org-test-with-temp-text ":PROPERTIES:\n:END:\n"
  474. (org-get-property-block))))
  475. ;; Comments above a document property block is ok.
  476. (should
  477. (equal '(18 . 18)
  478. (org-test-with-temp-text "# C\n:PROPERTIES:\n:END:\n"
  479. (org-get-property-block))))
  480. ;; Keywords above a document property block is ok.
  481. (should
  482. (equal '(22 . 22)
  483. (org-test-with-temp-text "# C\n# C\n:PROPERTIES:\n:END:\n"
  484. (org-get-property-block))))
  485. ;; Comments and keywords are allowed before a document property block.
  486. (should
  487. (equal '(18 . 27)
  488. (org-test-with-temp-text "# C\n:PROPERTIES:\n:KEY: V:\n:END:\n"
  489. (org-get-property-block))))
  490. ;; A document property block will not be valid if there are lines
  491. ;; with whitespace above it
  492. (should-not
  493. (org-test-with-temp-text "\n:PROPERTIES:\n:END:\n"
  494. (org-get-property-block)))
  495. (should
  496. (equal '(18 . 18)
  497. (org-test-with-temp-text "* H\n:PROPERTIES:\n:END:\n<point>"
  498. (org-get-property-block))))
  499. (should
  500. (equal "* H\n:PROPERTIES:\n:END:\n"
  501. (org-test-with-temp-text "* H"
  502. (let ((org-adapt-indentation nil))
  503. (org-get-property-block nil 'force))
  504. (buffer-string))))
  505. (should
  506. (equal ":PROPERTIES:\n:END:\n"
  507. (org-test-with-temp-text ""
  508. (org-get-property-block nil 'force)
  509. (buffer-string))))
  510. (should
  511. (equal "* H1\n :PROPERTIES:\n :END:\n* H2"
  512. (org-test-with-temp-text "* H1\n* H2"
  513. (let ((org-adapt-indentation t))
  514. (org-get-property-block nil 'force))
  515. (buffer-string)))))
  516. (ert-deftest test-org/insert-property-drawer ()
  517. "Test `org-insert-property-drawer' specifications."
  518. ;; Insert drawer in empty buffer
  519. (should
  520. (equal ":PROPERTIES:\n:END:\n"
  521. (org-test-with-temp-text ""
  522. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  523. (buffer-string))))
  524. ;; Insert drawer in document header with existing comment and
  525. ;; keyword.
  526. (should
  527. (equal "# C\n:PROPERTIES:\n:END:\n#+TITLE: T"
  528. (org-test-with-temp-text "# C\n#+TITLE: T"
  529. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  530. (buffer-string))))
  531. ;; Insert drawer in document header with existing keyword.
  532. (should
  533. (equal ":PROPERTIES:\n:END:\n#+TITLE: T"
  534. (org-test-with-temp-text "#+TITLE: T"
  535. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  536. (buffer-string))))
  537. (should
  538. (equal ":PROPERTIES:\n:END:"
  539. (org-test-with-temp-text ":PROPERTIES:\n:END:"
  540. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  541. (buffer-string))))
  542. ;; Insert drawer in document header with one existing heading in buffer.
  543. (should
  544. (equal ":PROPERTIES:\n:END:\n\n* T\n"
  545. (org-test-with-temp-text "\n* T\n"
  546. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  547. (buffer-string))))
  548. ;; Insert drawer right after headline if there is no planning line,
  549. ;; or after it otherwise.
  550. (should
  551. (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
  552. (org-test-with-temp-text "* H\nParagraph<point>"
  553. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  554. (buffer-string))))
  555. (should
  556. (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
  557. (org-test-with-temp-text
  558. "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
  559. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  560. (buffer-string))))
  561. ;; Indent inserted drawer.
  562. (should
  563. (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
  564. (org-test-with-temp-text "* H\nParagraph<point>"
  565. (let ((org-adapt-indentation t)) (org-insert-property-drawer))
  566. (buffer-string))))
  567. ;; Handle insertion at eob.
  568. (should
  569. (equal "* H\n:PROPERTIES:\n:END:\n"
  570. (org-test-with-temp-text "* H"
  571. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  572. (buffer-string))))
  573. ;; Skip inlinetasks before point.
  574. (when (featurep 'org-inlinetask)
  575. (should
  576. (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
  577. (org-test-with-temp-text
  578. "* H\n*************** I\n*************** END\nP<point>"
  579. (let ((org-adapt-indentation nil)
  580. (org-inlinetask-min-level 15))
  581. (org-insert-property-drawer))
  582. (buffer-string)))))
  583. ;; Correctly set drawer in an inlinetask.
  584. (when (featurep 'org-inlinetask)
  585. (should
  586. (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
  587. (org-test-with-temp-text
  588. "* H\n*************** I\nP<point>\n*************** END"
  589. (let ((org-adapt-indentation nil)
  590. (org-inlinetask-min-level 15))
  591. (org-insert-property-drawer))
  592. (buffer-string))))))
  593. ;;; Filling
  594. (ert-deftest test-org/fill-element ()
  595. "Test `org-fill-element' specifications."
  596. ;; At an Org table, align it.
  597. (should
  598. (equal "| a |\n"
  599. (org-test-with-temp-text "|a|"
  600. (org-fill-element)
  601. (buffer-string))))
  602. (should
  603. (equal "#+name: table\n| a |\n"
  604. (org-test-with-temp-text "#+name: table\n| a |\n"
  605. (org-fill-element)
  606. (buffer-string))))
  607. ;; At a paragraph, preserve line breaks.
  608. (org-test-with-temp-text "some \\\\\nlong\ntext"
  609. (let ((fill-column 20))
  610. (org-fill-element)
  611. (should (equal (buffer-string) "some \\\\\nlong text"))))
  612. ;; Correctly fill a paragraph when point is at its very end.
  613. (should
  614. (equal "A B"
  615. (org-test-with-temp-text "A\nB"
  616. (let ((fill-column 20))
  617. (goto-char (point-max))
  618. (org-fill-element)
  619. (buffer-string)))))
  620. ;; Correctly fill the last paragraph of a greater element.
  621. (should
  622. (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
  623. (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
  624. (let ((fill-column 8))
  625. (forward-line)
  626. (end-of-line)
  627. (org-fill-element)
  628. (buffer-string)))))
  629. ;; Correctly fill an element in a narrowed buffer.
  630. (should
  631. (equal "01234\n6"
  632. (org-test-with-temp-text "01234 6789"
  633. (let ((fill-column 5))
  634. (narrow-to-region 1 8)
  635. (org-fill-element)
  636. (buffer-string)))))
  637. ;; Handle `adaptive-fill-regexp' in paragraphs.
  638. (should
  639. (equal "> a b"
  640. (org-test-with-temp-text "> a\n> b"
  641. (let ((fill-column 5)
  642. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  643. (org-fill-element)
  644. (buffer-string)))))
  645. ;; Special case: Fill first paragraph when point is at an item or
  646. ;; a plain-list or a footnote reference.
  647. (should
  648. (equal "- A B"
  649. (org-test-with-temp-text "- A\n B"
  650. (let ((fill-column 20))
  651. (org-fill-element)
  652. (buffer-string)))))
  653. (should
  654. (equal "[fn:1] A B"
  655. (org-test-with-temp-text "[fn:1] A\nB"
  656. (let ((fill-column 20))
  657. (org-fill-element)
  658. (buffer-string)))))
  659. (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
  660. (let ((fill-column 20))
  661. (org-fill-element)
  662. (should (equal (buffer-string)
  663. "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
  664. ;; Fill contents of `comment-block' elements.
  665. (should
  666. (equal
  667. (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
  668. (let ((fill-column 20))
  669. (forward-line)
  670. (org-fill-element)
  671. (buffer-string)))
  672. "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
  673. ;; Fill `comment' elements.
  674. (should
  675. (equal " # A B"
  676. (org-test-with-temp-text " # A\n # B"
  677. (let ((fill-column 20))
  678. (org-fill-element)
  679. (buffer-string)))))
  680. ;; Do not mix consecutive comments when filling one of them.
  681. (should
  682. (equal "# A B\n\n# C"
  683. (org-test-with-temp-text "# A\n# B\n\n# C"
  684. (let ((fill-column 20))
  685. (org-fill-element)
  686. (buffer-string)))))
  687. ;; Use commented empty lines as separators when filling comments.
  688. (should
  689. (equal "# A B\n#\n# C"
  690. (org-test-with-temp-text "# A\n# B\n#\n# C"
  691. (let ((fill-column 20))
  692. (org-fill-element)
  693. (buffer-string)))))
  694. ;; Handle `adaptive-fill-regexp' in comments.
  695. (should
  696. (equal "# > a b"
  697. (org-test-with-temp-text "# > a\n# > b"
  698. (let ((fill-column 20)
  699. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  700. (org-fill-element)
  701. (buffer-string)))))
  702. ;; Do nothing at affiliated keywords.
  703. (should
  704. (equal "#+NAME: para\nSome\ntext."
  705. (org-test-with-temp-text "#+NAME: para\nSome\ntext."
  706. (let ((fill-column 20))
  707. (org-fill-element)
  708. (buffer-string)))))
  709. ;; Do not move point after table when filling a table.
  710. (should-not
  711. (org-test-with-temp-text "| a | b |\n| c | d |\n"
  712. (forward-char)
  713. (org-fill-element)
  714. (eobp)))
  715. ;; Do not fill "n" macro, with or without arguments, followed by
  716. ;; a dot or a closing parenthesis since it could be confused with
  717. ;; a numbered bullet.
  718. (should-not
  719. (equal "123456789\n{{{n}}}."
  720. (org-test-with-temp-text "123456789 {{{n}}}."
  721. (let ((fill-column 10))
  722. (org-fill-element)
  723. (buffer-string)))))
  724. (should-not
  725. (equal "123456789\n{{{n}}}\)"
  726. (org-test-with-temp-text "123456789 {{{n}}}\)"
  727. (let ((fill-column 10))
  728. (org-fill-element)
  729. (buffer-string)))))
  730. (should-not
  731. (equal "123456789\n{{{n()}}}."
  732. (org-test-with-temp-text "123456789 {{{n()}}}."
  733. (let ((fill-column 10))
  734. (org-fill-element)
  735. (buffer-string)))))
  736. (should-not
  737. (equal "123456789\n{{{n(counter)}}}."
  738. (org-test-with-temp-text "123456789 {{{n(counter)}}}."
  739. (let ((fill-column 10))
  740. (org-fill-element)
  741. (buffer-string))))))
  742. (ert-deftest test-org/fill-paragraph ()
  743. "Test `org-fill-paragraph' specifications."
  744. ;; Regular test.
  745. (should
  746. (equal "012345678\n9"
  747. (org-test-with-temp-text "012345678 9"
  748. (let ((fill-column 10))
  749. (org-fill-paragraph)
  750. (buffer-string)))))
  751. ;; Fill paragraph even at end of buffer.
  752. (should
  753. (equal "012345678\n9\n"
  754. (org-test-with-temp-text "012345678 9\n<point>"
  755. (let ((fill-column 10))
  756. (org-fill-paragraph)
  757. (buffer-string)))))
  758. ;; Between two paragraphs, fill the next one.
  759. (should
  760. (equal "012345678 9\n\n012345678\n9"
  761. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  762. (let ((fill-column 10))
  763. (org-fill-paragraph)
  764. (buffer-string)))))
  765. (should
  766. (equal "012345678\n9\n\n012345678 9"
  767. (org-test-with-temp-text "012345678 9<point>\n\n012345678 9"
  768. (let ((fill-column 10))
  769. (org-fill-paragraph)
  770. (buffer-string)))))
  771. ;; Fill paragraph in a comment block.
  772. (should
  773. (equal "#+begin_comment\n012345678\n9\n#+end_comment"
  774. (org-test-with-temp-text
  775. "#+begin_comment\n<point>012345678 9\n#+end_comment"
  776. (let ((fill-column 10))
  777. (org-fill-paragraph)
  778. (buffer-string)))))
  779. ;; When a region is selected, fill every paragraph in the region.
  780. (should
  781. (equal "012345678\n9\n\n012345678\n9"
  782. (org-test-with-temp-text "012345678 9\n\n012345678 9"
  783. (let ((fill-column 10))
  784. (transient-mark-mode 1)
  785. (push-mark (point-min) t t)
  786. (goto-char (point-max))
  787. (call-interactively #'org-fill-paragraph)
  788. (buffer-string)))))
  789. (should
  790. (equal "012345678\n9\n\n012345678 9"
  791. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  792. (let ((fill-column 10))
  793. (transient-mark-mode 1)
  794. (push-mark (point) t t)
  795. (goto-char (point-min))
  796. (call-interactively #'org-fill-paragraph)
  797. (buffer-string)))))
  798. (should
  799. (equal "012345678 9\n\n012345678\n9"
  800. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  801. (let ((fill-column 10))
  802. (transient-mark-mode 1)
  803. (push-mark (point) t t)
  804. (goto-char (point-max))
  805. (call-interactively #'org-fill-paragraph)
  806. (buffer-string)))))
  807. ;; Fill every list item in a region
  808. (should
  809. (equal "\n- 2345678\n 9\n- 2345678\n 9"
  810. (org-test-with-temp-text "\n- 2345678 9\n- 2345678 9"
  811. (let ((fill-column 10))
  812. (transient-mark-mode 1)
  813. (push-mark (point-min) t t)
  814. (goto-char (point-max))
  815. (call-interactively #'org-fill-paragraph)
  816. (buffer-string)))))
  817. (should
  818. (equal "\n- 2345678\n 9\n- 2345678"
  819. (org-test-with-temp-text "\n- 2345678 9\n- 2345678"
  820. (let ((fill-column 10))
  821. (transient-mark-mode 1)
  822. (push-mark (point-min) t t)
  823. (goto-char (point-max))
  824. (call-interactively #'org-fill-paragraph)
  825. (buffer-string))))))
  826. (ert-deftest test-org/fill-region ()
  827. "Test `fill-region' behaviour."
  828. ;; fill-region should fill every item of a list
  829. (should
  830. (equal "\n- 2345678\n 9\n- 2345678\n 9"
  831. (org-test-with-temp-text "\n- 2345678 9\n- 2345678 9"
  832. (let ((fill-column 10))
  833. (transient-mark-mode 1)
  834. (push-mark (point-min) t t)
  835. (goto-char (point-max))
  836. (call-interactively #'fill-region)
  837. (buffer-string)))))
  838. (should
  839. (equal "\n- 1 2\n- 1 2"
  840. (org-test-with-temp-text "\n- 1\n 2\n- 1\n 2"
  841. (let ((fill-column 10))
  842. (transient-mark-mode 1)
  843. (push-mark (point-min) t t)
  844. (goto-char (point-max))
  845. (call-interactively #'fill-region)
  846. (buffer-string))))) )
  847. (ert-deftest test-org/auto-fill-function ()
  848. "Test auto-filling features."
  849. ;; Auto fill paragraph.
  850. (should
  851. (equal "12345\n7890"
  852. (org-test-with-temp-text "12345 7890"
  853. (let ((fill-column 5))
  854. (end-of-line)
  855. (org-auto-fill-function)
  856. (buffer-string)))))
  857. ;; Auto fill first paragraph in an item.
  858. (should
  859. (equal "- 12345\n 7890"
  860. (org-test-with-temp-text "- 12345 7890"
  861. (let ((fill-column 7))
  862. (end-of-line)
  863. (org-auto-fill-function)
  864. (buffer-string)))))
  865. ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
  866. (should
  867. (equal "> 12345\n 7890"
  868. (org-test-with-temp-text "> 12345 7890"
  869. (let ((fill-column 10)
  870. (adaptive-fill-regexp "[ \t]*>+[ \t]*")
  871. (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
  872. (end-of-line)
  873. (org-auto-fill-function)
  874. (buffer-string)))))
  875. (should
  876. (equal "> 12345\n> 12345\n> 7890"
  877. (org-test-with-temp-text "> 12345\n> 12345 7890"
  878. (let ((fill-column 10)
  879. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  880. (goto-char (point-max))
  881. (org-auto-fill-function)
  882. (buffer-string)))))
  883. (should-not
  884. (equal " 12345\n *12345\n *12345"
  885. (org-test-with-temp-text " 12345\n *12345 12345"
  886. (let ((fill-column 10)
  887. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  888. (goto-char (point-max))
  889. (org-auto-fill-function)
  890. (buffer-string)))))
  891. ;; Auto fill comments.
  892. (should
  893. (equal " # 12345\n # 7890"
  894. (org-test-with-temp-text " # 12345 7890"
  895. (let ((fill-column 10))
  896. (end-of-line)
  897. (org-auto-fill-function)
  898. (buffer-string)))))
  899. ;; A hash within a line isn't a comment.
  900. (should-not
  901. (equal "12345 # 7890\n# 1"
  902. (org-test-with-temp-text "12345 # 7890 1"
  903. (let ((fill-column 12))
  904. (end-of-line)
  905. (org-auto-fill-function)
  906. (buffer-string)))))
  907. ;; Correctly interpret empty prefix.
  908. (should-not
  909. (equal "# a\n# b\nRegular\n# paragraph"
  910. (org-test-with-temp-text "# a\n# b\nRegular paragraph"
  911. (let ((fill-column 12))
  912. (end-of-line 3)
  913. (org-auto-fill-function)
  914. (buffer-string)))))
  915. ;; Comment block: auto fill contents.
  916. (should
  917. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  918. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  919. (let ((fill-column 5))
  920. (forward-line)
  921. (end-of-line)
  922. (org-auto-fill-function)
  923. (buffer-string)))))
  924. (should
  925. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  926. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  927. (let ((fill-column 5))
  928. (forward-line)
  929. (end-of-line)
  930. (org-auto-fill-function)
  931. (buffer-string)))))
  932. ;; Do not fill if a new item could be created.
  933. (should-not
  934. (equal "12345\n- 90"
  935. (org-test-with-temp-text "12345 - 90"
  936. (let ((fill-column 5))
  937. (end-of-line)
  938. (org-auto-fill-function)
  939. (buffer-string)))))
  940. ;; Do not fill if a line break could be introduced.
  941. (should-not
  942. (equal "123\\\\\n7890"
  943. (org-test-with-temp-text "123\\\\ 7890"
  944. (let ((fill-column 6))
  945. (end-of-line)
  946. (org-auto-fill-function)
  947. (buffer-string)))))
  948. ;; Do not fill affiliated keywords.
  949. (should-not
  950. (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
  951. (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
  952. (let ((fill-column 20))
  953. (end-of-line)
  954. (org-auto-fill-function)
  955. (buffer-string))))))
  956. ;;; Indentation
  957. (ert-deftest test-org/indent-line ()
  958. "Test `org-indent-line' specifications."
  959. ;; Do not indent diary sexps, footnote definitions or headlines.
  960. (should
  961. (zerop
  962. (org-test-with-temp-text "%%(org-calendar-holiday)"
  963. (org-indent-line)
  964. (org-get-indentation))))
  965. (should
  966. (zerop
  967. (org-test-with-temp-text "[fn:1] fn"
  968. (let ((org-adapt-indentation t)) (org-indent-line))
  969. (org-get-indentation))))
  970. (should
  971. (zerop
  972. (org-test-with-temp-text "* H"
  973. (org-indent-line)
  974. (org-get-indentation))))
  975. ;; Do not indent before first headline.
  976. (should
  977. (zerop
  978. (org-test-with-temp-text ""
  979. (org-indent-line)
  980. (org-get-indentation))))
  981. ;; Indent according to headline level otherwise, unless
  982. ;; `org-adapt-indentation' is nil.
  983. (should
  984. (= 2
  985. (org-test-with-temp-text "* H\n<point>A"
  986. (let ((org-adapt-indentation t)) (org-indent-line))
  987. (org-get-indentation))))
  988. (should
  989. (= 2
  990. (org-test-with-temp-text "* H\n<point>\nA"
  991. (let ((org-adapt-indentation t)) (org-indent-line))
  992. (org-get-indentation))))
  993. (should
  994. (zerop
  995. (org-test-with-temp-text "* H\n<point>A"
  996. (let ((org-adapt-indentation nil)) (org-indent-line))
  997. (org-get-indentation))))
  998. ;; Indenting preserves point position.
  999. (should
  1000. (org-test-with-temp-text "* H\nA<point>B"
  1001. (let ((org-adapt-indentation t)) (org-indent-line))
  1002. (looking-at "B")))
  1003. ;; Do not change indentation at an item or a LaTeX environment.
  1004. (should
  1005. (= 1
  1006. (org-test-with-temp-text "* H\n<point> - A"
  1007. (let ((org-adapt-indentation t)) (org-indent-line))
  1008. (org-get-indentation))))
  1009. (should
  1010. (= 1
  1011. (org-test-with-temp-text
  1012. "\\begin{equation}\n <point>1+1=2\n\\end{equation}"
  1013. (org-indent-line)
  1014. (org-get-indentation))))
  1015. ;; On blank lines at the end of a list, indent like last element
  1016. ;; within it if the line is still in the list. If the last element
  1017. ;; is an item, indent like its contents. Otherwise, indent like the
  1018. ;; whole list.
  1019. (should
  1020. (= 4
  1021. (org-test-with-temp-text "* H\n- A\n - AA\n<point>"
  1022. (let ((org-adapt-indentation t)) (org-indent-line))
  1023. (org-get-indentation))))
  1024. (should
  1025. (= 4
  1026. (org-test-with-temp-text "* H\n- A\n -\n\n<point>"
  1027. (let ((org-adapt-indentation t)) (org-indent-line))
  1028. (org-get-indentation))))
  1029. (should
  1030. (zerop
  1031. (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n<point>"
  1032. (let ((org-adapt-indentation t)) (org-indent-line))
  1033. (org-get-indentation))))
  1034. (should
  1035. (= 4
  1036. (org-test-with-temp-text "* H\n- A\n - \n<point>"
  1037. (let ((org-adapt-indentation t)) (org-indent-line))
  1038. (org-get-indentation))))
  1039. (should
  1040. (= 4
  1041. (org-test-with-temp-text
  1042. "* H\n - \n #+BEGIN_SRC emacs-lisp\n t\n #+END_SRC\n<point>"
  1043. (let ((org-adapt-indentation t)) (org-indent-line))
  1044. (org-get-indentation))))
  1045. (should
  1046. (= 2
  1047. (org-test-with-temp-text "- A\n B\n\n<point>"
  1048. (let ((org-adapt-indentation nil)) (org-indent-line))
  1049. (org-get-indentation))))
  1050. (should
  1051. (= 2
  1052. (org-test-with-temp-text
  1053. "- A\n \begin{cases} 1 + 1\n \end{cases}\n\n<point>"
  1054. (let ((org-adapt-indentation nil)) (org-indent-line))
  1055. (org-get-indentation))))
  1056. ;; Likewise, on a blank line at the end of a footnote definition,
  1057. ;; indent at column 0 if line belongs to the definition. Otherwise,
  1058. ;; indent like the definition itself.
  1059. (should
  1060. (zerop
  1061. (org-test-with-temp-text "* H\n[fn:1] Definition\n<point>"
  1062. (let ((org-adapt-indentation t)) (org-indent-line))
  1063. (org-get-indentation))))
  1064. (should
  1065. (zerop
  1066. (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n<point>"
  1067. (let ((org-adapt-indentation t)) (org-indent-line))
  1068. (org-get-indentation))))
  1069. ;; After the end of the contents of a greater element, indent like
  1070. ;; the beginning of the element.
  1071. (should
  1072. (= 1
  1073. (org-test-with-temp-text
  1074. " #+BEGIN_CENTER\n Contents\n<point>#+END_CENTER"
  1075. (org-indent-line)
  1076. (org-get-indentation))))
  1077. ;; On blank lines after a paragraph, indent like its last non-empty
  1078. ;; line.
  1079. (should
  1080. (= 1
  1081. (org-test-with-temp-text " Paragraph\n\n<point>"
  1082. (org-indent-line)
  1083. (org-get-indentation))))
  1084. ;; At the first line of an element, indent like previous element's
  1085. ;; first line, ignoring footnotes definitions and inline tasks, or
  1086. ;; according to parent.
  1087. (let ((org-adapt-indentation t))
  1088. (should
  1089. (= 2
  1090. (org-test-with-temp-text "A\n\n B\n\nC<point>"
  1091. (org-indent-line)
  1092. (org-get-indentation))))
  1093. (should
  1094. (= 1
  1095. (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC<point>"
  1096. (org-indent-line)
  1097. (org-get-indentation))))
  1098. (should
  1099. (= 1
  1100. (org-test-with-temp-text
  1101. " #+BEGIN_CENTER\n<point> Contents\n#+END_CENTER"
  1102. (org-indent-line)
  1103. (org-get-indentation)))))
  1104. ;; Within code part of a source block, use language major mode if
  1105. ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
  1106. ;; according to line above.
  1107. (should
  1108. (= 6
  1109. (org-test-with-temp-text
  1110. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  1111. (let ((org-src-tab-acts-natively t)
  1112. (org-edit-src-content-indentation 0))
  1113. (org-indent-line))
  1114. (org-get-indentation))))
  1115. (should
  1116. (= 1
  1117. (org-test-with-temp-text
  1118. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  1119. (let ((org-src-tab-acts-natively nil)
  1120. (org-edit-src-content-indentation 0))
  1121. (org-indent-line))
  1122. (org-get-indentation))))
  1123. ;; Otherwise, indent like the first non-blank line above.
  1124. (should
  1125. (zerop
  1126. (org-test-with-temp-text
  1127. "#+BEGIN_CENTER\nline1\n\n<point> line2\n#+END_CENTER"
  1128. (org-indent-line)
  1129. (org-get-indentation))))
  1130. ;; Align node properties according to `org-property-format'. Handle
  1131. ;; nicely empty values.
  1132. (should
  1133. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1134. (org-test-with-temp-text
  1135. "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
  1136. (let ((org-property-format "%-10s %s")) (org-indent-line))
  1137. (buffer-string))))
  1138. (should
  1139. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1140. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
  1141. (let ((org-property-format "%-10s %s")) (org-indent-line))
  1142. (buffer-string)))))
  1143. (ert-deftest test-org/indent-region ()
  1144. "Test `org-indent-region' specifications."
  1145. ;; Indent paragraph.
  1146. (let ((org-adapt-indentation t))
  1147. (should
  1148. (equal "A\nB\nC"
  1149. (org-test-with-temp-text " A\nB\n C"
  1150. (org-indent-region (point-min) (point-max))
  1151. (buffer-string)))))
  1152. ;; Indent greater elements along with their contents.
  1153. (should
  1154. (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
  1155. (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
  1156. (org-indent-region (point-min) (point-max))
  1157. (buffer-string))))
  1158. ;; Ignore contents of verse blocks. Only indent block delimiters.
  1159. (should
  1160. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1161. (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1162. (org-indent-region (point-min) (point-max))
  1163. (buffer-string))))
  1164. (let ((org-adapt-indentation t))
  1165. (should
  1166. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1167. (org-test-with-temp-text " #+BEGIN_VERSE\n A\n B\n #+END_VERSE"
  1168. (org-indent-region (point-min) (point-max))
  1169. (buffer-string)))))
  1170. ;; Indent example blocks as a single block, unless indentation
  1171. ;; should be preserved. In this case only indent the block markers.
  1172. (should
  1173. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1174. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1175. (org-indent-region (point-min) (point-max))
  1176. (buffer-string))))
  1177. (let ((org-adapt-indentation t))
  1178. (should
  1179. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1180. (org-test-with-temp-text " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1181. (org-indent-region (point-min) (point-max))
  1182. (buffer-string))))
  1183. (should
  1184. (equal "#+BEGIN_EXAMPLE -i\n A\n B\n#+END_EXAMPLE"
  1185. (org-test-with-temp-text
  1186. " #+BEGIN_EXAMPLE -i\n A\n B\n #+END_EXAMPLE"
  1187. (org-indent-region (point-min) (point-max))
  1188. (buffer-string))))
  1189. (should
  1190. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1191. (org-test-with-temp-text
  1192. " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1193. (let ((org-src-preserve-indentation t))
  1194. (org-indent-region (point-min) (point-max)))
  1195. (buffer-string)))))
  1196. ;; Treat export blocks as a whole.
  1197. (should
  1198. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1199. (org-test-with-temp-text "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1200. (org-indent-region (point-min) (point-max))
  1201. (buffer-string))))
  1202. (let ((org-adapt-indentation t))
  1203. (should
  1204. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1205. (org-test-with-temp-text
  1206. " #+BEGIN_EXPORT latex\n A\n B\n #+END_EXPORT"
  1207. (org-indent-region (point-min) (point-max))
  1208. (buffer-string)))))
  1209. ;; Indent according to mode if `org-src-tab-acts-natively' is
  1210. ;; non-nil. Otherwise, do not indent code at all.
  1211. (should
  1212. (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
  1213. (org-test-with-temp-text
  1214. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1215. (let ((org-src-tab-acts-natively t)
  1216. (org-edit-src-content-indentation 0))
  1217. (org-indent-region (point-min) (point-max)))
  1218. (buffer-string))))
  1219. (should
  1220. (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1221. (org-test-with-temp-text
  1222. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1223. (let ((org-src-tab-acts-natively nil)
  1224. (org-edit-src-content-indentation 0))
  1225. (org-indent-region (point-min) (point-max)))
  1226. (buffer-string))))
  1227. ;; Align node properties according to `org-property-format'. Handle
  1228. ;; nicely empty values.
  1229. (should
  1230. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1231. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
  1232. (let ((org-property-format "%-10s %s")
  1233. (org-adapt-indentation nil))
  1234. (org-indent-region (point) (point-max)))
  1235. (buffer-string))))
  1236. (should
  1237. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1238. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
  1239. (let ((org-property-format "%-10s %s")
  1240. (org-adapt-indentation nil))
  1241. (org-indent-region (point) (point-max)))
  1242. (buffer-string))))
  1243. ;; Indent property drawers according to `org-adapt-indentation'.
  1244. (let ((org-adapt-indentation 'headline-data))
  1245. (should
  1246. (equal "* H\n :PROPERTIES:\n :key:\n :END:"
  1247. (org-test-with-temp-text "* H\n:PROPERTIES:\n:key:\n:END:"
  1248. (org-indent-region (point-min) (point-max))
  1249. (buffer-string)))))
  1250. ;; Indent plain lists.
  1251. (let ((org-adapt-indentation t))
  1252. (should
  1253. (equal "- A\n B\n - C\n\n D"
  1254. (org-test-with-temp-text "- A\n B\n - C\n\n D"
  1255. (org-indent-region (point-min) (point-max))
  1256. (buffer-string))))
  1257. (should
  1258. (equal "- A\n\n- B"
  1259. (org-test-with-temp-text " - A\n\n - B"
  1260. (org-indent-region (point-min) (point-max))
  1261. (buffer-string)))))
  1262. ;; Indent footnote definitions.
  1263. (should
  1264. (equal "[fn:1] Definition\n\nDefinition"
  1265. (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
  1266. (org-indent-region (point-min) (point-max))
  1267. (buffer-string))))
  1268. ;; Special case: Start indenting on a blank line.
  1269. (should
  1270. (equal "\nParagraph"
  1271. (org-test-with-temp-text "\n Paragraph"
  1272. (org-indent-region (point-min) (point-max))
  1273. (buffer-string)))))
  1274. ;;; Editing
  1275. (ert-deftest test-org/delete-indentation ()
  1276. "Test `org-delete-indentation' specifications."
  1277. ;; Regular test.
  1278. (should (equal "foo bar"
  1279. (org-test-with-temp-text
  1280. "foo \n bar<point>"
  1281. (org-delete-indentation)
  1282. (buffer-string))))
  1283. ;; With optional argument.
  1284. (should (equal "foo bar"
  1285. (org-test-with-temp-text
  1286. "foo<point> \n bar"
  1287. (org-delete-indentation t)
  1288. (buffer-string))))
  1289. ;; At headline text should be appended to the headline text.
  1290. (should
  1291. (equal"* foo bar :tag:"
  1292. (let (org-auto-align-tags)
  1293. (org-test-with-temp-text
  1294. "* foo :tag:\n bar<point>"
  1295. (org-delete-indentation)
  1296. (buffer-string)))))
  1297. (should
  1298. (equal "* foo bar :tag:"
  1299. (let (org-auto-align-tags)
  1300. (org-test-with-temp-text
  1301. "* foo <point>:tag:\n bar"
  1302. (org-delete-indentation t)
  1303. (buffer-string))))))
  1304. (ert-deftest test-org/return ()
  1305. "Test `org-return' specifications."
  1306. ;; Regular test.
  1307. (should
  1308. (equal "Para\ngraph"
  1309. (org-test-with-temp-text "Para<point>graph"
  1310. (org-return)
  1311. (buffer-string))))
  1312. ;; With optional argument, indent line.
  1313. (should
  1314. (equal " Para\n graph"
  1315. (org-test-with-temp-text " Para<point>graph"
  1316. (org-return t)
  1317. (buffer-string))))
  1318. ;; On a table, call `org-table-next-row'.
  1319. (should
  1320. (org-test-with-temp-text "| <point>a |\n| b |"
  1321. (org-return)
  1322. (looking-at-p "b")))
  1323. ;; Open link or timestamp under point when `org-return-follows-link'
  1324. ;; is non-nil.
  1325. (should
  1326. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1327. (let ((org-return-follows-link t)
  1328. (org-link-search-must-match-exact-headline nil))
  1329. (org-return))
  1330. (looking-at-p "<<target>>")))
  1331. (should-not
  1332. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1333. (let ((org-return-follows-link nil)) (org-return))
  1334. (looking-at-p "<<target>>")))
  1335. (should
  1336. (org-test-with-temp-text "* [[b][a<point>]]\n* b"
  1337. (let ((org-return-follows-link t)) (org-return))
  1338. (looking-at-p "* b")))
  1339. (should
  1340. (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
  1341. (let ((org-return-follows-link t)
  1342. (org-link-search-must-match-exact-headline nil))
  1343. (org-return))
  1344. (looking-at-p "<<target>>")))
  1345. (should-not
  1346. (org-test-with-temp-text "Link [[target]]<point> <<target>>"
  1347. (let ((org-return-follows-link t)
  1348. (org-link-search-must-match-exact-headline nil))
  1349. (org-return))
  1350. (looking-at-p "<<target>>")))
  1351. ;; When `org-return-follows-link' is non-nil, tolerate links and
  1352. ;; timestamps in comments, node properties, etc.
  1353. (should
  1354. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1355. (let ((org-return-follows-link t)
  1356. (org-link-search-must-match-exact-headline nil))
  1357. (org-return))
  1358. (looking-at-p "<<target>>")))
  1359. (should-not
  1360. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1361. (let ((org-return-follows-link nil)) (org-return))
  1362. (looking-at-p "<<target>>")))
  1363. (should-not
  1364. (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
  1365. (let ((org-return-follows-link t)
  1366. (org-link-search-must-match-exact-headline nil))
  1367. (org-return))
  1368. (looking-at-p "<<target>>")))
  1369. ;; Non-nil `org-return-follows-link' ignores read-only state of
  1370. ;; a buffer.
  1371. (should
  1372. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1373. (let ((org-return-follows-link t)
  1374. (org-link-search-must-match-exact-headline nil))
  1375. (setq buffer-read-only t)
  1376. (call-interactively #'org-return))
  1377. (looking-at-p "<<target>>")))
  1378. ;; `org-return-follows-link' handle multi-line lines.
  1379. (should
  1380. (org-test-with-temp-text
  1381. "[[target][This is a very\n long description<point>]]\n <<target>>"
  1382. (let ((org-return-follows-link t)
  1383. (org-link-search-must-match-exact-headline nil))
  1384. (org-return))
  1385. (looking-at-p "<<target>>")))
  1386. (should-not
  1387. (org-test-with-temp-text
  1388. "[[target][This is a very\n long description]]<point>\n <<target>>"
  1389. (let ((org-return-follows-link t)
  1390. (org-link-search-must-match-exact-headline nil))
  1391. (org-return))
  1392. (looking-at-p "<<target>>")))
  1393. ;; However, do not open link when point is in a table.
  1394. (should
  1395. (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
  1396. (let ((org-return-follows-link t)) (org-return))
  1397. (looking-at-p "between")))
  1398. ;; Special case: in a list, when indenting, do not break structure.
  1399. (should
  1400. (equal "- A\n B"
  1401. (org-test-with-temp-text "- A <point>B"
  1402. (org-return t)
  1403. (buffer-string))))
  1404. (should
  1405. (equal "- A\n\n- B"
  1406. (org-test-with-temp-text "- A\n<point>- B"
  1407. (org-return t)
  1408. (buffer-string))))
  1409. ;; On tags part of a headline, add a newline below it instead of
  1410. ;; breaking it.
  1411. (should
  1412. (equal "* H :tag:\n"
  1413. (org-test-with-temp-text "* H :<point>tag:"
  1414. (org-return)
  1415. (buffer-string))))
  1416. ;; Before headline text, add a newline below it instead of breaking
  1417. ;; it.
  1418. (should
  1419. (equal "* TODO H :tag:\n"
  1420. (org-test-with-temp-text "* <point>TODO H :tag:"
  1421. (org-return)
  1422. (buffer-string))))
  1423. (should
  1424. (equal "* TODO [#B] H :tag:\n"
  1425. (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
  1426. (org-return)
  1427. (buffer-string))))
  1428. (should ;TODO are case-sensitive
  1429. (equal "* \nTodo"
  1430. (org-test-with-temp-text "* <point>Todo"
  1431. (org-return)
  1432. (buffer-string))))
  1433. ;; At headline text, break headline text but preserve tags.
  1434. (should
  1435. (equal "* TODO [#B] foo :tag:\nbar"
  1436. (let (org-auto-align-tags)
  1437. (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
  1438. (org-return)
  1439. (buffer-string)))))
  1440. ;; At bol of headline insert newline.
  1441. (should
  1442. (equal "\n* h"
  1443. (org-test-with-temp-text "<point>* h"
  1444. (org-return)
  1445. (buffer-string))))
  1446. ;; Refuse to leave invalid headline in buffer.
  1447. (should
  1448. (equal "* h\n"
  1449. (org-test-with-temp-text "*<point> h"
  1450. (org-return)
  1451. (buffer-string))))
  1452. ;; Before first column or after last one in a table, split the
  1453. ;; table.
  1454. (should
  1455. (equal "| a |\n\n| b |"
  1456. (org-test-with-temp-text "| a |\n<point>| b |"
  1457. (org-return)
  1458. (buffer-string))))
  1459. (should
  1460. (equal "| a |\n\n| b |"
  1461. (org-test-with-temp-text "| a |<point>\n| b |"
  1462. (org-return)
  1463. (buffer-string))))
  1464. ;; Do not auto-fill on hitting <RET> inside a property drawer.
  1465. (should
  1466. (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:"
  1467. (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:"
  1468. (setq-local fill-column 10)
  1469. (auto-fill-mode 1)
  1470. (org-return)
  1471. (buffer-string)))))
  1472. (ert-deftest test-org/with-electric-indent ()
  1473. "Test RET and C-j specifications with `electric-indent-mode' on."
  1474. ;; Call commands interactively, since this is how `newline' knows it
  1475. ;; must run `post-self-insert-hook'.
  1476. ;;
  1477. ;; RET, like `newline', should indent.
  1478. (should
  1479. (equal " Para\n graph"
  1480. (org-test-with-temp-text " Para<point>graph"
  1481. (electric-indent-local-mode 1)
  1482. (call-interactively 'org-return)
  1483. (buffer-string))))
  1484. (should
  1485. (equal "- item1\n item2"
  1486. (org-test-with-temp-text "- item1<point>item2"
  1487. (electric-indent-local-mode 1)
  1488. (call-interactively 'org-return)
  1489. (buffer-string))))
  1490. ;; TODO: test more values of `org-adapt-indentation'.
  1491. (let ((org-adapt-indentation t))
  1492. (should
  1493. (equal "* heading\n body"
  1494. (org-test-with-temp-text "* heading<point>body"
  1495. (electric-indent-local-mode 1)
  1496. (call-interactively 'org-return)
  1497. (buffer-string)))))
  1498. ;; C-j, like `electric-newline-and-maybe-indent', should not indent.
  1499. (should
  1500. (equal " Para\ngraph"
  1501. (org-test-with-temp-text " Para<point>graph"
  1502. (electric-indent-local-mode 1)
  1503. (call-interactively 'org-return-and-maybe-indent)
  1504. (buffer-string))))
  1505. (should
  1506. (equal "- item1\nitem2"
  1507. (org-test-with-temp-text "- item1<point>item2"
  1508. (electric-indent-local-mode 1)
  1509. (call-interactively 'org-return-and-maybe-indent)
  1510. (buffer-string))))
  1511. ;; TODO: test more values of `org-adapt-indentation'.
  1512. (let ((org-adapt-indentation t))
  1513. (should
  1514. (equal "* heading\nbody"
  1515. (org-test-with-temp-text "* heading<point>body"
  1516. (electric-indent-local-mode 1)
  1517. (call-interactively 'org-return-and-maybe-indent)
  1518. (buffer-string))))))
  1519. (ert-deftest test-org/without-electric-indent ()
  1520. "Test RET and C-j specifications with `electric-indent-mode' off."
  1521. ;; Call commands interactively, since this is how `newline' knows it
  1522. ;; must run `post-self-insert-hook'.
  1523. ;;
  1524. ;; RET, like `newline', should not indent.
  1525. (should
  1526. (equal " Para\ngraph"
  1527. (org-test-with-temp-text " Para<point>graph"
  1528. (electric-indent-local-mode 0)
  1529. (call-interactively 'org-return)
  1530. (buffer-string))))
  1531. (should
  1532. (equal "- item1\nitem2"
  1533. (org-test-with-temp-text "- item1<point>item2"
  1534. (electric-indent-local-mode 0)
  1535. (call-interactively 'org-return)
  1536. (buffer-string))))
  1537. (should
  1538. (equal "* heading\nbody"
  1539. (org-test-with-temp-text "* heading<point>body"
  1540. (electric-indent-local-mode 0)
  1541. (call-interactively 'org-return)
  1542. (buffer-string))))
  1543. ;; C-j, like `electric-newline-and-maybe-indent', should indent.
  1544. (should
  1545. (equal " Para\n graph"
  1546. (org-test-with-temp-text " Para<point>graph"
  1547. (electric-indent-local-mode 0)
  1548. (call-interactively 'org-return-and-maybe-indent)
  1549. (buffer-string))))
  1550. (should
  1551. (equal "- item1\n item2"
  1552. (org-test-with-temp-text "- item1<point>item2"
  1553. (electric-indent-local-mode 0)
  1554. (call-interactively 'org-return-and-maybe-indent)
  1555. (buffer-string))))
  1556. ;; TODO: test more values of `org-adapt-indentation'.
  1557. (let ((org-adapt-indentation t))
  1558. (should
  1559. (equal "* heading\n body"
  1560. (org-test-with-temp-text "* heading<point>body"
  1561. (electric-indent-local-mode 0)
  1562. (call-interactively 'org-return-and-maybe-indent)
  1563. (buffer-string))))))
  1564. (ert-deftest test-org/meta-return ()
  1565. "Test M-RET (`org-meta-return') specifications."
  1566. ;; In a table field insert a row above.
  1567. (should
  1568. (org-test-with-temp-text "| a |"
  1569. (forward-char)
  1570. (org-meta-return)
  1571. (forward-line -1)
  1572. (looking-at "| |$")))
  1573. ;; In a paragraph change current line into a header.
  1574. (should
  1575. (org-test-with-temp-text "a"
  1576. (org-meta-return)
  1577. (beginning-of-line)
  1578. (looking-at "\* a$")))
  1579. ;; In an item insert an item, in this case above.
  1580. (should
  1581. (org-test-with-temp-text "- a"
  1582. (org-meta-return)
  1583. (beginning-of-line)
  1584. (looking-at "- $")))
  1585. ;; In a drawer and item insert an item, in this case above.
  1586. (should
  1587. (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
  1588. (forward-line)
  1589. (org-fold-reveal)
  1590. (org-meta-return)
  1591. (beginning-of-line)
  1592. (looking-at "- $"))))
  1593. (ert-deftest test-org/insert-heading ()
  1594. "Test `org-insert-heading' specifications."
  1595. ;; In an empty buffer, insert a new headline.
  1596. (should
  1597. (equal "* "
  1598. (org-test-with-temp-text ""
  1599. (org-insert-heading)
  1600. (buffer-string))))
  1601. ;; At the beginning of a line, turn it into a headline.
  1602. (should
  1603. (equal "* P"
  1604. (org-test-with-temp-text "<point>P"
  1605. (org-insert-heading)
  1606. (buffer-string))))
  1607. ;; In the middle of a line, split the line if allowed, otherwise,
  1608. ;; insert the headline at its end.
  1609. (should
  1610. (equal "Para\n* graph"
  1611. (org-test-with-temp-text "Para<point>graph"
  1612. (let ((org-M-RET-may-split-line '((default . t))))
  1613. (org-insert-heading))
  1614. (buffer-string))))
  1615. (should
  1616. (equal "Paragraph\n* "
  1617. (org-test-with-temp-text "Para<point>graph"
  1618. (let ((org-M-RET-may-split-line '((default . nil))))
  1619. (org-insert-heading))
  1620. (buffer-string))))
  1621. ;; At the beginning of a headline, create one above.
  1622. (should
  1623. (equal "* \n* H"
  1624. (org-test-with-temp-text "* H"
  1625. (org-insert-heading)
  1626. (buffer-string))))
  1627. ;; In the middle of a headline, split it if allowed.
  1628. (should
  1629. (equal "* H\n* 1"
  1630. (org-test-with-temp-text "* H<point>1"
  1631. (let ((org-M-RET-may-split-line '((headline . t))))
  1632. (org-insert-heading))
  1633. (buffer-string))))
  1634. (should
  1635. (equal "* H1\n* "
  1636. (org-test-with-temp-text "* H<point>1"
  1637. (let ((org-M-RET-may-split-line '((headline . nil))))
  1638. (org-insert-heading))
  1639. (buffer-string))))
  1640. ;; However, splitting cannot happen on TODO keywords, priorities or
  1641. ;; tags.
  1642. (should
  1643. (equal "* TODO H1\n* "
  1644. (org-test-with-temp-text "* TO<point>DO H1"
  1645. (let ((org-M-RET-may-split-line '((headline . t))))
  1646. (org-insert-heading))
  1647. (buffer-string))))
  1648. (should
  1649. (equal "* [#A] H1\n* "
  1650. (org-test-with-temp-text "* [#<point>A] H1"
  1651. (let ((org-M-RET-may-split-line '((headline . t))))
  1652. (org-insert-heading))
  1653. (buffer-string))))
  1654. (should
  1655. (equal "* H1 :tag:\n* "
  1656. (org-test-with-temp-text "* H1 :ta<point>g:"
  1657. (let ((org-M-RET-may-split-line '((headline . t))))
  1658. (org-insert-heading))
  1659. (buffer-string))))
  1660. ;; New headline level depends on the level of the headline above.
  1661. (should
  1662. (equal "** H\n** P"
  1663. (org-test-with-temp-text "** H\n<point>P"
  1664. (org-insert-heading)
  1665. (buffer-string))))
  1666. (should
  1667. (equal "** H\nPara\n** graph"
  1668. (org-test-with-temp-text "** H\nPara<point>graph"
  1669. (let ((org-M-RET-may-split-line '((default . t))))
  1670. (org-insert-heading))
  1671. (buffer-string))))
  1672. (should
  1673. (equal "** \n** H"
  1674. (org-test-with-temp-text "** H"
  1675. (org-insert-heading)
  1676. (buffer-string))))
  1677. ;; When called with one universal argument, insert a new headline at
  1678. ;; the end of the current subtree, independently on the position of
  1679. ;; point.
  1680. (should
  1681. (equal
  1682. "* "
  1683. (org-test-with-temp-text ""
  1684. (let ((org-insert-heading-respect-content nil))
  1685. (org-insert-heading '(4)))
  1686. (buffer-string))))
  1687. (should
  1688. (equal
  1689. "entry
  1690. * "
  1691. (org-test-with-temp-text "entry"
  1692. (let ((org-insert-heading-respect-content nil))
  1693. (org-insert-heading '(4)))
  1694. (buffer-string))))
  1695. (should
  1696. (equal
  1697. "* H1\n** H2\n* "
  1698. (org-test-with-temp-text "* H1\n** H2"
  1699. (let ((org-insert-heading-respect-content nil))
  1700. (org-insert-heading '(4)))
  1701. (buffer-string))))
  1702. (should
  1703. (equal
  1704. "* H1\n** H2\n* "
  1705. (org-test-with-temp-text "* H<point>1\n** H2"
  1706. (let ((org-insert-heading-respect-content nil))
  1707. (org-insert-heading '(4)))
  1708. (buffer-string))))
  1709. ;; When called with two universal arguments, insert a new headline
  1710. ;; at the end of the grandparent subtree.
  1711. (should
  1712. (equal "* H1\n** H3\n- item\n** H2\n** "
  1713. (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
  1714. (let ((org-insert-heading-respect-content nil))
  1715. (org-insert-heading '(16)))
  1716. (buffer-string))))
  1717. ;; When optional TOP-LEVEL argument is non-nil, always insert
  1718. ;; a level 1 heading.
  1719. (should
  1720. (equal "* H1\n** H2\n* "
  1721. (org-test-with-temp-text "* H1\n** H2<point>"
  1722. (org-insert-heading nil nil t)
  1723. (buffer-string))))
  1724. (should
  1725. (equal "* H1\n- item\n* "
  1726. (org-test-with-temp-text "* H1\n- item<point>"
  1727. (org-insert-heading nil nil t)
  1728. (buffer-string))))
  1729. ;; Obey `org-blank-before-new-entry'.
  1730. (should
  1731. (equal "* H1\n\n* "
  1732. (org-test-with-temp-text "* H1<point>"
  1733. (let ((org-blank-before-new-entry '((heading . t))))
  1734. (org-insert-heading))
  1735. (buffer-string))))
  1736. (should
  1737. (equal "* H1\n* "
  1738. (org-test-with-temp-text "* H1<point>"
  1739. (let ((org-blank-before-new-entry '((heading . nil))))
  1740. (org-insert-heading))
  1741. (buffer-string))))
  1742. (should
  1743. (equal "* H1\n* H2\n* "
  1744. (org-test-with-temp-text "* H1\n* H2<point>"
  1745. (let ((org-blank-before-new-entry '((heading . auto))))
  1746. (org-insert-heading))
  1747. (buffer-string))))
  1748. (should
  1749. (equal "* H1\n\n* H2\n\n* "
  1750. (org-test-with-temp-text "* H1\n\n* H2<point>"
  1751. (let ((org-blank-before-new-entry '((heading . auto))))
  1752. (org-insert-heading))
  1753. (buffer-string))))
  1754. ;; Corner case: correctly insert a headline after an empty one.
  1755. (should
  1756. (equal "* \n* "
  1757. (org-test-with-temp-text "* <point>"
  1758. (org-insert-heading)
  1759. (buffer-string))))
  1760. (should
  1761. (org-test-with-temp-text "* <point>\n"
  1762. (org-insert-heading)
  1763. (looking-at-p "\n\\'")))
  1764. ;; Do not insert spurious headlines when inserting a new headline.
  1765. (should
  1766. (equal "* H1\n* H2\n* \n"
  1767. (org-test-with-temp-text "* H1\n* H2<point>\n"
  1768. (org-insert-heading)
  1769. (buffer-string))))
  1770. ;; Preserve visibility at beginning of line. In particular, when
  1771. ;; removing spurious blank lines, do not visually merge heading with
  1772. ;; the line visible above.
  1773. (should-not
  1774. (org-test-with-temp-text "* H1<point>\nContents\n\n* H2\n"
  1775. (org-overview)
  1776. (let ((org-blank-before-new-entry '((heading . nil))))
  1777. (org-insert-heading '(4)))
  1778. (invisible-p (line-end-position 0))))
  1779. ;; Properly handle empty lines when forcing a headline below current
  1780. ;; one.
  1781. (should
  1782. (equal "* H1\n\n* H\n\n* "
  1783. (org-test-with-temp-text "* H1\n\n* H<point>"
  1784. (let ((org-blank-before-new-entry '((heading . t))))
  1785. (org-insert-heading '(4))
  1786. (buffer-string))))))
  1787. (ert-deftest test-org/insert-todo-heading-respect-content ()
  1788. "Test `org-insert-todo-heading-respect-content' specifications."
  1789. ;; Create a TODO heading.
  1790. (should
  1791. (org-test-with-temp-text "* H1\n Body"
  1792. (org-insert-todo-heading-respect-content)
  1793. (nth 2 (org-heading-components))))
  1794. ;; Add headline at the end of the first subtree
  1795. (should
  1796. (equal
  1797. "* TODO "
  1798. (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
  1799. (org-insert-todo-heading-respect-content)
  1800. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1801. ;; In a list, do not create a new item.
  1802. (should
  1803. (equal
  1804. "* TODO "
  1805. (org-test-with-temp-text "* H\n- an item\n- another one"
  1806. (search-forward "an ")
  1807. (org-insert-todo-heading-respect-content)
  1808. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1809. ;; Use the same TODO keyword as current heading.
  1810. (should
  1811. (equal
  1812. "* TODO \n"
  1813. (org-test-with-temp-text "* TODO\n** WAITING\n"
  1814. (org-insert-todo-heading-respect-content)
  1815. (buffer-substring-no-properties (line-beginning-position) (point-max))))))
  1816. (ert-deftest test-org/clone-with-time-shift ()
  1817. "Test `org-clone-subtree-with-time-shift'."
  1818. ;; Raise an error before first heading.
  1819. (should-error
  1820. (org-test-with-temp-text ""
  1821. (org-clone-subtree-with-time-shift 1)))
  1822. ;; Raise an error on invalid number of clones.
  1823. (should-error
  1824. (org-test-with-temp-text "* Clone me"
  1825. (org-clone-subtree-with-time-shift -1)))
  1826. ;; Clone non-repeating once.
  1827. (should
  1828. (equal "\
  1829. * H1\n<2015-06-21>
  1830. * H1\n<2015-06-23>
  1831. "
  1832. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1833. (org-clone-subtree-with-time-shift 1 "+2d")
  1834. (replace-regexp-in-string
  1835. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1836. nil nil 1))))
  1837. ;; Clone repeating once.
  1838. (should
  1839. (equal "\
  1840. * H1\n<2015-06-21>
  1841. * H1\n<2015-06-23>
  1842. * H1\n<2015-06-25 +1w>
  1843. "
  1844. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1845. (org-clone-subtree-with-time-shift 1 "+2d")
  1846. (replace-regexp-in-string
  1847. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1848. nil nil 1))))
  1849. ;; Clone repeating once in backward.
  1850. (should
  1851. (equal "\
  1852. * H1\n<2015-06-21>
  1853. * H1\n<2015-06-19>
  1854. * H1\n<2015-06-17 +1w>
  1855. "
  1856. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1857. (org-clone-subtree-with-time-shift 1 "-2d")
  1858. (replace-regexp-in-string
  1859. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1860. nil nil 1))))
  1861. ;; Clone non-repeating zero times.
  1862. (should
  1863. (equal "\
  1864. * H1\n<2015-06-21>
  1865. "
  1866. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1867. (org-clone-subtree-with-time-shift 0 "+2d")
  1868. (replace-regexp-in-string
  1869. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1870. nil nil 1))))
  1871. ;; Clone repeating "zero" times.
  1872. (should
  1873. (equal "\
  1874. * H1\n<2015-06-21>
  1875. * H1\n<2015-06-23 +1w>
  1876. "
  1877. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1878. (org-clone-subtree-with-time-shift 0 "+2d")
  1879. (replace-regexp-in-string
  1880. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1881. nil nil 1))))
  1882. ;; Clone with blank SHIFT argument.
  1883. (should
  1884. (string-prefix-p
  1885. "* H <2012-03-29"
  1886. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1887. (org-clone-subtree-with-time-shift 1 "")
  1888. (buffer-substring-no-properties (line-beginning-position 2)
  1889. (line-end-position 2)))))
  1890. ;; Find time stamps before point. If SHIFT is not specified, ask
  1891. ;; for a time shift.
  1892. (should
  1893. (string-prefix-p
  1894. "* H <2012-03-30"
  1895. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1896. (org-clone-subtree-with-time-shift 1 "+1d")
  1897. (buffer-substring-no-properties (line-beginning-position 2)
  1898. (line-end-position 2)))))
  1899. (should
  1900. (string-prefix-p
  1901. "* H <2014-03-05"
  1902. (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
  1903. (cl-letf (((symbol-function 'read-from-minibuffer)
  1904. (lambda (&rest args) "+1d")))
  1905. (org-clone-subtree-with-time-shift 1))
  1906. (buffer-substring-no-properties (line-beginning-position 2)
  1907. (line-end-position 2)))))
  1908. ;; Hour shift.
  1909. (should
  1910. (equal "\
  1911. * H1\n<2015-06-21 20:00>
  1912. * H1\n<2015-06-21 23:00>
  1913. * H1\n<2015-06-22 02:00>
  1914. "
  1915. (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>"
  1916. (org-clone-subtree-with-time-shift 2 "+3h")
  1917. (replace-regexp-in-string
  1918. "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" ""
  1919. (buffer-substring-no-properties (point-min) (point-max))
  1920. nil nil 1))))
  1921. (should
  1922. (equal "\
  1923. * H1\n<2015-06-21 20:00>
  1924. * H1\n<2015-06-21 18:00>
  1925. "
  1926. (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>"
  1927. (org-clone-subtree-with-time-shift 1 "-2h")
  1928. (replace-regexp-in-string
  1929. "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" ""
  1930. (buffer-substring-no-properties (point-min) (point-max))
  1931. nil nil 1)))))
  1932. ;;; Fixed-Width Areas
  1933. (ert-deftest test-org/toggle-fixed-width ()
  1934. "Test `org-toggle-fixed-width' specifications."
  1935. ;; No region: Toggle on fixed-width marker in paragraphs.
  1936. (should
  1937. (equal ": A"
  1938. (org-test-with-temp-text "A"
  1939. (org-toggle-fixed-width)
  1940. (buffer-string))))
  1941. ;; No region: Toggle off fixed-width markers in fixed-width areas.
  1942. (should
  1943. (equal "A"
  1944. (org-test-with-temp-text ": A"
  1945. (org-toggle-fixed-width)
  1946. (buffer-string))))
  1947. ;; No region: Toggle on marker in blank lines after elements or just
  1948. ;; after a headline.
  1949. (should
  1950. (equal "* H\n: "
  1951. (org-test-with-temp-text "* H\n"
  1952. (forward-line)
  1953. (org-toggle-fixed-width)
  1954. (buffer-string))))
  1955. (should
  1956. (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
  1957. (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
  1958. (goto-char (point-max))
  1959. (org-toggle-fixed-width)
  1960. (buffer-string))))
  1961. ;; No region: Toggle on marker in front of one line elements (e.g.,
  1962. ;; headlines, clocks)
  1963. (should
  1964. (equal ": * Headline"
  1965. (org-test-with-temp-text "* Headline"
  1966. (org-toggle-fixed-width)
  1967. (buffer-string))))
  1968. (should
  1969. (equal ": #+KEYWORD: value"
  1970. (org-test-with-temp-text "#+KEYWORD: value"
  1971. (org-toggle-fixed-width)
  1972. (buffer-string))))
  1973. ;; No region: error in other situations.
  1974. (should-error
  1975. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
  1976. (forward-line)
  1977. (org-toggle-fixed-width)
  1978. (buffer-string)))
  1979. ;; No region: Indentation is preserved.
  1980. (should
  1981. (equal "- A\n : B"
  1982. (org-test-with-temp-text "- A\n B"
  1983. (forward-line)
  1984. (org-toggle-fixed-width)
  1985. (buffer-string))))
  1986. ;; Region: If it contains only fixed-width elements and blank lines,
  1987. ;; toggle off fixed-width markup.
  1988. (should
  1989. (equal "A\n\nB"
  1990. (org-test-with-temp-text ": A\n\n: B"
  1991. (transient-mark-mode 1)
  1992. (push-mark (point) t t)
  1993. (goto-char (point-max))
  1994. (org-toggle-fixed-width)
  1995. (buffer-string))))
  1996. ;; Region: If it contains anything else, toggle on fixed-width but
  1997. ;; not on fixed-width areas.
  1998. (should
  1999. (equal ": A\n: \n: B\n: \n: C"
  2000. (org-test-with-temp-text "A\n\n: B\n\nC"
  2001. (transient-mark-mode 1)
  2002. (push-mark (point) t t)
  2003. (goto-char (point-max))
  2004. (org-toggle-fixed-width)
  2005. (buffer-string))))
  2006. ;; Region: Ignore blank lines at its end, unless it contains only
  2007. ;; such lines.
  2008. (should
  2009. (equal ": A\n\n"
  2010. (org-test-with-temp-text "A\n\n"
  2011. (transient-mark-mode 1)
  2012. (push-mark (point) t t)
  2013. (goto-char (point-max))
  2014. (org-toggle-fixed-width)
  2015. (buffer-string))))
  2016. (should
  2017. (equal ": \n: \n"
  2018. (org-test-with-temp-text "\n\n"
  2019. (transient-mark-mode 1)
  2020. (push-mark (point) t t)
  2021. (goto-char (point-max))
  2022. (org-toggle-fixed-width)
  2023. (buffer-string)))))
  2024. (ert-deftest test-org/kill-line ()
  2025. "Test `org-kill-line' specifications."
  2026. ;; At the beginning of a line, kill whole line.
  2027. (should
  2028. (equal ""
  2029. (org-test-with-temp-text "abc"
  2030. (org-kill-line)
  2031. (buffer-string))))
  2032. ;; In the middle of a line, kill line until its end.
  2033. (should
  2034. (equal "a"
  2035. (org-test-with-temp-text "a<point>bc"
  2036. (org-kill-line)
  2037. (buffer-string))))
  2038. ;; Do not kill newline character.
  2039. (should
  2040. (equal "\n123"
  2041. (org-test-with-temp-text "abc\n123"
  2042. (org-kill-line)
  2043. (buffer-string))))
  2044. (should
  2045. (equal "a\n123"
  2046. (org-test-with-temp-text "a<point>bc\n123"
  2047. (org-kill-line)
  2048. (buffer-string))))
  2049. ;; When `org-special-ctrl-k' is non-nil and point is at a headline,
  2050. ;; kill until tags.
  2051. (should
  2052. (equal "* A :tag:"
  2053. (org-test-with-temp-text "* A<point>B :tag:"
  2054. (let ((org-special-ctrl-k t)
  2055. (org-tags-column 0))
  2056. (org-kill-line))
  2057. (buffer-string))))
  2058. ;; If point is on tags, only kill part left until the end of line.
  2059. (should
  2060. (equal "* A :tag:"
  2061. (org-test-with-temp-text "* A :tag:<point>tag2:"
  2062. (let ((org-special-ctrl-k t)
  2063. (org-tags-column 0))
  2064. (org-kill-line))
  2065. (buffer-string))))
  2066. ;; However, if point is at the beginning of the line, kill whole
  2067. ;; headline.
  2068. (should
  2069. (equal ""
  2070. (org-test-with-temp-text "* AB :tag:"
  2071. (let ((org-special-ctrl-k t)
  2072. (org-tags-column 0))
  2073. (org-kill-line))
  2074. (buffer-string))))
  2075. ;; When `org-ctrl-k-protect-subtree' is non-nil, and point is in
  2076. ;; invisible text, ask before removing it. When set to `error',
  2077. ;; throw an error.
  2078. (should-error
  2079. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  2080. (org-overview)
  2081. (let ((org-special-ctrl-k nil)
  2082. (org-ctrl-k-protect-subtree t))
  2083. (cl-letf (((symbol-function 'y-or-n-p) 'ignore))
  2084. (org-kill-line)))))
  2085. (should-error
  2086. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  2087. (org-overview)
  2088. (let ((org-special-ctrl-k nil)
  2089. (org-ctrl-k-protect-subtree 'error))
  2090. (org-kill-line)))))
  2091. ;;; Headline
  2092. (ert-deftest test-org/get-heading ()
  2093. "Test `org-get-heading' specifications."
  2094. ;; Return current heading, even if point is not on it.
  2095. (should
  2096. (equal "H"
  2097. (org-test-with-temp-text "* H"
  2098. (org-get-heading))))
  2099. (should
  2100. (equal "H"
  2101. (org-test-with-temp-text "* H\nText<point>"
  2102. (org-get-heading))))
  2103. ;; Without any optional argument, return TODO keyword, priority
  2104. ;; cookie, COMMENT keyword and tags.
  2105. (should
  2106. (equal "TODO H"
  2107. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2108. (org-get-heading))))
  2109. (should
  2110. (equal "[#A] H"
  2111. (org-test-with-temp-text "* [#A] H"
  2112. (org-get-heading))))
  2113. (should
  2114. (equal "COMMENT H"
  2115. (org-test-with-temp-text "* COMMENT H"
  2116. (org-get-heading))))
  2117. (should
  2118. (equal "H :tag:"
  2119. (org-test-with-temp-text "* H :tag:"
  2120. (org-get-heading))))
  2121. ;; With NO-TAGS argument, ignore tags.
  2122. (should
  2123. (equal "TODO H"
  2124. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2125. (org-get-heading t))))
  2126. (should
  2127. (equal "H"
  2128. (org-test-with-temp-text "* H :tag:"
  2129. (org-get-heading t))))
  2130. ;; With NO-TODO, ignore TODO keyword.
  2131. (should
  2132. (equal "H"
  2133. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2134. (org-get-heading nil t))))
  2135. (should
  2136. (equal "H :tag:"
  2137. (org-test-with-temp-text "* H :tag:"
  2138. (org-get-heading nil t))))
  2139. ;; TODO keywords are case-sensitive.
  2140. (should
  2141. (equal "Todo H"
  2142. (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
  2143. (org-get-heading nil t))))
  2144. ;; With NO-PRIORITY, ignore priority.
  2145. (should
  2146. (equal "H"
  2147. (org-test-with-temp-text "* [#A] H"
  2148. (org-get-heading nil nil t))))
  2149. (should
  2150. (equal "H"
  2151. (org-test-with-temp-text "* H"
  2152. (org-get-heading nil nil t))))
  2153. (should
  2154. (equal "TODO H"
  2155. (org-test-with-temp-text "* TODO [#A] H"
  2156. (org-get-heading nil nil t))))
  2157. ;; With NO-COMMENT, ignore COMMENT keyword.
  2158. (should
  2159. (equal "H"
  2160. (org-test-with-temp-text "* COMMENT H"
  2161. (org-get-heading nil nil nil t))))
  2162. (should
  2163. (equal "H"
  2164. (org-test-with-temp-text "* H"
  2165. (org-get-heading nil nil nil t))))
  2166. (should
  2167. (equal "TODO [#A] H"
  2168. (org-test-with-temp-text "* TODO [#A] COMMENT H"
  2169. (org-get-heading nil nil nil t))))
  2170. ;; On an empty headline, return value is consistent.
  2171. (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
  2172. (should (equal "" (org-test-with-temp-text "* " (org-get-heading t))))
  2173. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t))))
  2174. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t))))
  2175. (should
  2176. (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t)))))
  2177. (ert-deftest test-org/in-commented-heading-p ()
  2178. "Test `org-in-commented-heading-p' specifications."
  2179. ;; Commented headline.
  2180. (should
  2181. (org-test-with-temp-text "* COMMENT Headline\nBody"
  2182. (goto-char (point-max))
  2183. (org-in-commented-heading-p)))
  2184. ;; Commented ancestor.
  2185. (should
  2186. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  2187. (goto-char (point-max))
  2188. (org-in-commented-heading-p)))
  2189. ;; Comment keyword is case-sensitive.
  2190. (should-not
  2191. (org-test-with-temp-text "* Comment Headline\nBody"
  2192. (goto-char (point-max))
  2193. (org-in-commented-heading-p)))
  2194. ;; Keyword is standalone.
  2195. (should-not
  2196. (org-test-with-temp-text "* COMMENTHeadline\nBody"
  2197. (goto-char (point-max))
  2198. (org-in-commented-heading-p)))
  2199. ;; Optional argument.
  2200. (should-not
  2201. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  2202. (goto-char (point-max))
  2203. (org-in-commented-heading-p t))))
  2204. (ert-deftest test-org/in-archived-heading-p ()
  2205. "Test `org-in-archived-heading-p' specifications."
  2206. ;; Archived headline.
  2207. (should
  2208. (org-test-with-temp-text "* Headline :ARCHIVE:\nBody"
  2209. (goto-char (point-max))
  2210. (org-in-archived-heading-p)))
  2211. ;; Archived ancestor.
  2212. (should
  2213. (org-test-with-temp-text "* Headline :ARCHIVE:\n** Level 2\nBody"
  2214. (goto-char (point-max))
  2215. (org-in-archived-heading-p)))
  2216. ;; Optional argument.
  2217. (should-not
  2218. (org-test-with-temp-text "* Headline :ARCHIVE:\n** Level 2\nBody"
  2219. (goto-char (point-max))
  2220. (org-in-archived-heading-p t)))
  2221. ;; Archive tag containing ARCHIVE as substring
  2222. (should-not
  2223. (org-test-with-temp-text "* Headline :NOARCHIVE:\n** Level 2\nBody"
  2224. (goto-char (point-max))
  2225. (org-in-archived-heading-p))))
  2226. (ert-deftest test-org/entry-blocked-p ()
  2227. ;; Check other dependencies.
  2228. (should
  2229. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  2230. (let ((org-enforce-todo-dependencies t)
  2231. (org-blocker-hook
  2232. '(org-block-todo-from-children-or-siblings-or-parent)))
  2233. (org-entry-blocked-p))))
  2234. (should-not
  2235. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  2236. (let ((org-enforce-todo-dependencies t)
  2237. (org-blocker-hook
  2238. '(org-block-todo-from-children-or-siblings-or-parent)))
  2239. (org-entry-blocked-p))))
  2240. ;; Entry without a TODO keyword or with a DONE keyword cannot be
  2241. ;; blocked.
  2242. (should-not
  2243. (org-test-with-temp-text "* Blocked\n** TODO one"
  2244. (let ((org-enforce-todo-dependencies t)
  2245. (org-blocker-hook
  2246. '(org-block-todo-from-children-or-siblings-or-parent)))
  2247. (org-entry-blocked-p))))
  2248. (should-not
  2249. (org-test-with-temp-text "* DONE Blocked\n** TODO one"
  2250. (let ((org-enforce-todo-dependencies t)
  2251. (org-blocker-hook
  2252. '(org-block-todo-from-children-or-siblings-or-parent)))
  2253. (org-entry-blocked-p))))
  2254. ;; Follow :ORDERED: specifications.
  2255. (should
  2256. (org-test-with-temp-text
  2257. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
  2258. (let ((org-enforce-todo-dependencies t)
  2259. (org-blocker-hook
  2260. '(org-block-todo-from-children-or-siblings-or-parent)))
  2261. (org-entry-blocked-p))))
  2262. (should-not
  2263. (org-test-with-temp-text
  2264. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
  2265. (let ((org-enforce-todo-dependencies t)
  2266. (org-blocker-hook
  2267. '(org-block-todo-from-children-or-siblings-or-parent)))
  2268. (org-entry-blocked-p)))))
  2269. (ert-deftest test-org/get-outline-path ()
  2270. "Test `org-get-outline-path' specifications."
  2271. ;; Top-level headlines have no outline path.
  2272. (should-not
  2273. (org-test-with-temp-text "* H"
  2274. (org-get-outline-path)))
  2275. ;; Otherwise, outline path is the path leading to the headline.
  2276. (should
  2277. (equal '("H")
  2278. (org-test-with-temp-text "* H\n** S<point>"
  2279. (org-get-outline-path))))
  2280. ;; Find path even when point is not on a headline.
  2281. (should
  2282. (equal '("H")
  2283. (org-test-with-temp-text "* H\n** S\nText<point>"
  2284. (org-get-outline-path))))
  2285. ;; TODO keywords, tags and statistics cookies are ignored.
  2286. (should
  2287. (equal '("H")
  2288. (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
  2289. (org-get-outline-path))))
  2290. ;; Links are replaced with their description or their path.
  2291. (should
  2292. (equal '("Org")
  2293. (org-test-with-temp-text
  2294. "* [[https://orgmode.org][Org]]\n** S<point>"
  2295. (org-get-outline-path))))
  2296. (should
  2297. (equal '("https://orgmode.org")
  2298. (org-test-with-temp-text
  2299. "* [[https://orgmode.org]]\n** S<point>"
  2300. (org-get-outline-path))))
  2301. ;; When WITH-SELF is non-nil, include current heading.
  2302. (should
  2303. (equal '("H")
  2304. (org-test-with-temp-text "* H"
  2305. (org-get-outline-path t))))
  2306. (should
  2307. (equal '("H" "S")
  2308. (org-test-with-temp-text "* H\n** S\nText<point>"
  2309. (org-get-outline-path t))))
  2310. ;; Using cache is transparent to the user.
  2311. (should
  2312. (equal '("H")
  2313. (org-test-with-temp-text "* H\n** S<point>"
  2314. (setq org-outline-path-cache nil)
  2315. (org-get-outline-path nil t))))
  2316. ;; Do not corrupt cache when finding outline path in distant part of
  2317. ;; the buffer.
  2318. (should
  2319. (equal '("H2")
  2320. (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
  2321. (setq org-outline-path-cache nil)
  2322. (org-get-outline-path nil t)
  2323. (search-forward "S2")
  2324. (org-get-outline-path nil t))))
  2325. ;; Do not choke on empty headlines.
  2326. (should
  2327. (org-test-with-temp-text "* H\n** <point>"
  2328. (org-get-outline-path)))
  2329. (should
  2330. (org-test-with-temp-text "* \n** H<point>"
  2331. (org-get-outline-path))))
  2332. (ert-deftest test-org/format-outline-path ()
  2333. "Test `org-format-outline-path' specifications."
  2334. (should
  2335. (string= (org-format-outline-path (list "one" "two" "three"))
  2336. "one/two/three"))
  2337. ;; Empty path.
  2338. (should
  2339. (string= (org-format-outline-path '())
  2340. ""))
  2341. (should
  2342. (string= (org-format-outline-path '(nil))
  2343. ""))
  2344. ;; Empty path and prefix.
  2345. (should
  2346. (string= (org-format-outline-path '() nil ">>")
  2347. ">>"))
  2348. ;; Trailing whitespace in headings.
  2349. (should
  2350. (string= (org-format-outline-path (list "one\t" "tw o " "three "))
  2351. "one/tw o/three"))
  2352. ;; Non-default prefix and separators.
  2353. (should
  2354. (string= (org-format-outline-path (list "one" "two" "three") nil ">>" "|")
  2355. ">>|one|two|three"))
  2356. ;; Truncate.
  2357. (should
  2358. (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
  2359. "one/two/.."))
  2360. ;; Give a very narrow width.
  2361. (should
  2362. (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
  2363. "on"))
  2364. ;; Give a prefix that extends beyond the width.
  2365. (should
  2366. (string= (org-format-outline-path (list "one" "two" "three" "four") 10
  2367. ">>>>>>>>>>")
  2368. ">>>>>>>>..")))
  2369. (ert-deftest test-org/org-find-olp ()
  2370. "Test `org-find-olp' specifications."
  2371. (org-test-with-temp-text
  2372. "
  2373. * Headline
  2374. ** COMMENT headline2
  2375. ** TODO headline3
  2376. *** [#A] headline4 :tags:
  2377. ** [#A]headline5
  2378. ** [0%] headline6
  2379. ** headline7 [100%]
  2380. ** headline8 [1/5] :some:more:tags:
  2381. * Test
  2382. "
  2383. (should (org-find-olp '("Headline") t))
  2384. (should-error (org-find-olp '("Headline" "Test") t))
  2385. (should-error (org-find-olp '("Headlinealksjd") t))
  2386. (should (org-find-olp '("Headline" "headline2") t))
  2387. (should (org-find-olp '("Headline" "headline3") t))
  2388. (should (org-find-olp '("Headline" "headline3" "headline4") t))
  2389. (should-error (org-find-olp '("Headline" "headline5") t))
  2390. (should (org-find-olp '("Headline" "headline6") t))
  2391. (should (org-find-olp '("Headline" "headline7") t))
  2392. (should (org-find-olp '("Headline" "headline8") t))))
  2393. (ert-deftest test-org/map-entries ()
  2394. "Test `org-map-entries' specifications."
  2395. ;; Full match.
  2396. (should
  2397. (equal '(1 11)
  2398. (org-test-with-temp-text "* Level 1\n** Level 2"
  2399. (org-map-entries #'point))))
  2400. ;; Level match.
  2401. (should
  2402. (equal '(1)
  2403. (org-test-with-temp-text "* Level 1\n** Level 2"
  2404. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL=1")))))
  2405. (should
  2406. (equal '(11)
  2407. (org-test-with-temp-text "* Level 1\n** Level 2"
  2408. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL>1")))))
  2409. ;; Tag match.
  2410. (should
  2411. (equal '(11)
  2412. (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
  2413. (org-map-entries #'point "yes"))))
  2414. (should
  2415. (equal '(14)
  2416. (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
  2417. (org-map-entries #'point "+yes-a"))))
  2418. (should
  2419. (equal '(11 23)
  2420. (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
  2421. (org-map-entries #'point "{yes?}"))))
  2422. ;; Priority match.
  2423. (should
  2424. (equal '(1)
  2425. (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
  2426. (org-map-entries #'point "PRIORITY=\"A\""))))
  2427. ;; Date match.
  2428. (should
  2429. (equal '(36)
  2430. (org-test-with-temp-text "
  2431. * H1
  2432. SCHEDULED: <2012-03-29 thu.>
  2433. * H2
  2434. SCHEDULED: <2014-03-04 tue.>"
  2435. (org-map-entries #'point "SCHEDULED=\"<2014-03-04 tue.>\""))))
  2436. (should
  2437. (equal '(2)
  2438. (org-test-with-temp-text "
  2439. * H1
  2440. SCHEDULED: <2012-03-29 thu.>
  2441. * H2
  2442. SCHEDULED: <2014-03-04 tue.>"
  2443. (org-map-entries #'point "SCHEDULED<\"<2013-01-01>\""))))
  2444. ;; Regular property match.
  2445. (should
  2446. (equal '(2)
  2447. (org-test-with-temp-text "
  2448. * H1
  2449. :PROPERTIES:
  2450. :TEST: 1
  2451. :END:
  2452. * H2
  2453. :PROPERTIES:
  2454. :TEST: 2
  2455. :END:"
  2456. (org-map-entries #'point "TEST=1"))))
  2457. ;; Multiple criteria.
  2458. (should
  2459. (equal '(23)
  2460. (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
  2461. (let (org-odd-levels-only
  2462. (org-use-tag-inheritance nil))
  2463. (org-map-entries #'point "yes+LEVEL=1")))))
  2464. ;; "or" criteria.
  2465. (should
  2466. (equal '(12 24)
  2467. (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
  2468. (let (org-odd-levels-only)
  2469. (org-map-entries #'point "LEVEL=2|no")))))
  2470. (should
  2471. (equal '(1 12)
  2472. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
  2473. (let (org-odd-levels-only)
  2474. (org-map-entries #'point "yes|no")))))
  2475. ;; "and" criteria.
  2476. (should
  2477. (equal '(22)
  2478. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
  2479. (let (org-odd-levels-only)
  2480. (org-map-entries #'point "yes&no")))))
  2481. ;; Setting `org-map-continue-from'
  2482. (should
  2483. (string= ""
  2484. (org-test-with-temp-text "* H1\n* H2\n* H3n* H4"
  2485. (org-map-entries
  2486. (lambda ()
  2487. (org-cut-subtree)
  2488. (setq org-map-continue-from (point))))
  2489. (buffer-string))))
  2490. (should
  2491. (string= "* H1\n* H2\n* H3\n"
  2492. (org-test-with-temp-text "* H1\n* H2\n* H3\n* H4"
  2493. (org-map-entries
  2494. (lambda ()
  2495. (when (string= "H4"
  2496. (org-element-property
  2497. :raw-value (org-element-at-point)))
  2498. (org-cut-subtree)
  2499. (setq org-map-continue-from
  2500. (org-element-property
  2501. :begin (org-element-at-point))))))
  2502. (buffer-string)))))
  2503. (ert-deftest test-org/edit-headline ()
  2504. "Test `org-edit-headline' specifications."
  2505. (should
  2506. (equal "* B"
  2507. (org-test-with-temp-text "* A"
  2508. (org-edit-headline "B")
  2509. (buffer-string))))
  2510. ;; Handle empty headings.
  2511. (should
  2512. (equal "* "
  2513. (org-test-with-temp-text "* A"
  2514. (org-edit-headline "")
  2515. (buffer-string))))
  2516. (should
  2517. (equal "* A"
  2518. (org-test-with-temp-text "* "
  2519. (org-edit-headline "A")
  2520. (buffer-string))))
  2521. ;; Handle TODO keywords and priority cookies.
  2522. (should
  2523. (equal "* TODO B"
  2524. (org-test-with-temp-text "* TODO A"
  2525. (org-edit-headline "B")
  2526. (buffer-string))))
  2527. (should
  2528. (equal "* [#A] B"
  2529. (org-test-with-temp-text "* [#A] A"
  2530. (org-edit-headline "B")
  2531. (buffer-string))))
  2532. (should
  2533. (equal "* TODO [#A] B"
  2534. (org-test-with-temp-text "* TODO [#A] A"
  2535. (org-edit-headline "B")
  2536. (buffer-string))))
  2537. ;; Handle tags.
  2538. (equal "* B :tag:"
  2539. (org-test-with-temp-text "* A :tag:"
  2540. (let ((org-tags-column 4)) (org-edit-headline "B"))
  2541. (buffer-string))))
  2542. ;;; Keywords
  2543. (ert-deftest test-org/set-regexps-and-options ()
  2544. "Test `org-set-regexps-and-options' specifications."
  2545. ;; TAGS keyword.
  2546. (should
  2547. (equal '(("A"))
  2548. (let ((org-tag-alist '(("A")))
  2549. (org-tag-persistent-alist nil))
  2550. (org-test-with-temp-text ""
  2551. (org-mode-restart)
  2552. org-current-tag-alist))))
  2553. (should
  2554. (equal '(("B"))
  2555. (let ((org-tag-alist '(("A")))
  2556. (org-tag-persistent-alist nil))
  2557. (org-test-with-temp-text "#+TAGS: B"
  2558. (org-mode-restart)
  2559. org-current-tag-alist))))
  2560. (should
  2561. (equal '(("C") ("B"))
  2562. (let ((org-tag-alist '(("A")))
  2563. (org-tag-persistent-alist '(("C"))))
  2564. (org-test-with-temp-text "#+TAGS: B"
  2565. (org-mode-restart)
  2566. org-current-tag-alist))))
  2567. (should
  2568. (equal '(("B"))
  2569. (let ((org-tag-alist '(("A")))
  2570. (org-tag-persistent-alist '(("C"))))
  2571. (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
  2572. (org-mode-restart)
  2573. org-current-tag-alist))))
  2574. (should
  2575. (equal '(("A" . ?a) ("B") ("C"))
  2576. (let ((org-tag-persistant-alist nil))
  2577. (org-test-with-temp-text "#+TAGS: A(a) B C"
  2578. (org-mode-restart)
  2579. org-current-tag-alist))))
  2580. (should
  2581. (equal '(("A") (:newline) ("B"))
  2582. (let ((org-tag-persistent-alist nil))
  2583. (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
  2584. (org-mode-restart)
  2585. org-current-tag-alist))))
  2586. (should
  2587. (equal '((:startgroup) ("A") ("B") (:endgroup) ("C"))
  2588. (let ((org-tag-persistent-alist nil))
  2589. (org-test-with-temp-text "#+TAGS: { A B } C"
  2590. (org-mode-restart)
  2591. org-current-tag-alist))))
  2592. (should
  2593. (equal '((:startgroup) ("A") (:grouptags) ("B") ("C") (:endgroup))
  2594. (let ((org-tag-persistent-alist nil))
  2595. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2596. (org-mode-restart)
  2597. org-current-tag-alist))))
  2598. (should
  2599. (equal '(("A" "B" "C"))
  2600. (let ((org-tag-persistent-alist nil))
  2601. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2602. (org-mode-restart)
  2603. org-tag-groups-alist))))
  2604. (should
  2605. (equal '((:startgrouptag) ("A") (:grouptags) ("B") ("C") (:endgrouptag))
  2606. (let ((org-tag-persistent-alist nil))
  2607. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2608. (org-mode-restart)
  2609. org-current-tag-alist))))
  2610. (should
  2611. (equal '(("A" "B" "C"))
  2612. (let ((org-tag-persistent-alist nil))
  2613. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2614. (org-mode-restart)
  2615. org-tag-groups-alist))))
  2616. (should-not
  2617. (let ((org-tag-alist '(("A"))))
  2618. (org-test-with-temp-text "#+TAGS:"
  2619. (org-mode-restart)
  2620. org-current-tag-alist)))
  2621. ;; FILETAGS keyword.
  2622. (should
  2623. (equal '("A" "B" "C")
  2624. (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
  2625. (org-mode-restart)
  2626. org-file-tags)))
  2627. ;; PROPERTY keyword. Property names are case-insensitive.
  2628. (should
  2629. (equal "foo=1"
  2630. (org-test-with-temp-text "#+PROPERTY: var foo=1"
  2631. (org-mode-restart)
  2632. (cdr (assoc "var" org-keyword-properties)))))
  2633. (should
  2634. (equal
  2635. "foo=1 bar=2"
  2636. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
  2637. (org-mode-restart)
  2638. (cdr (assoc "var" org-keyword-properties)))))
  2639. (should
  2640. (equal
  2641. "foo=1 bar=2"
  2642. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
  2643. (org-mode-restart)
  2644. (cdr (assoc "var" org-keyword-properties)))))
  2645. ;; ARCHIVE keyword.
  2646. (should
  2647. (equal "%s_done::"
  2648. (org-test-with-temp-text "#+ARCHIVE: %s_done::"
  2649. (org-mode-restart)
  2650. org-archive-location)))
  2651. ;; CATEGORY keyword.
  2652. (should
  2653. (eq 'test
  2654. (org-test-with-temp-text "#+CATEGORY: test"
  2655. (org-mode-restart)
  2656. org-category)))
  2657. (should
  2658. (equal "test"
  2659. (org-test-with-temp-text "#+CATEGORY: test"
  2660. (org-mode-restart)
  2661. (cdr (assoc "CATEGORY" org-keyword-properties)))))
  2662. ;; COLUMNS keyword.
  2663. (should
  2664. (equal "%25ITEM %TAGS %PRIORITY %TODO"
  2665. (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
  2666. (org-mode-restart)
  2667. org-columns-default-format)))
  2668. ;; CONSTANTS keyword. Constants names are case sensitive.
  2669. (should
  2670. (equal '("299792458." "3.14")
  2671. (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
  2672. (org-mode-restart)
  2673. (mapcar
  2674. (lambda (n) (cdr (assoc n org-table-formula-constants-local)))
  2675. '("c" "pi")))))
  2676. (should
  2677. (equal "3.14"
  2678. (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
  2679. (org-mode-restart)
  2680. (cdr (assoc "pi" org-table-formula-constants-local)))))
  2681. (should
  2682. (equal "22/7"
  2683. (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
  2684. (org-mode-restart)
  2685. (cdr (assoc "PI" org-table-formula-constants-local)))))
  2686. ;; LINK keyword.
  2687. (should
  2688. (equal
  2689. '("url1" "url2")
  2690. (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
  2691. (org-mode-restart)
  2692. (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local)))
  2693. '("a" "b")))))
  2694. ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
  2695. (should
  2696. (equal
  2697. '(?X ?Z ?Y)
  2698. (org-test-with-temp-text "#+PRIORITIES: X Z Y"
  2699. (org-mode-restart)
  2700. (list org-priority-highest org-priority-lowest org-priority-default))))
  2701. (should
  2702. (equal
  2703. '(?A ?C ?B)
  2704. (org-test-with-temp-text "#+PRIORITIES: X Z"
  2705. (org-mode-restart)
  2706. (list org-priority-highest org-priority-lowest org-priority-default))))
  2707. ;; STARTUP keyword.
  2708. (should
  2709. (equal '(t t)
  2710. (org-test-with-temp-text "#+STARTUP: fold odd"
  2711. (org-mode-restart)
  2712. (list org-startup-folded org-odd-levels-only))))
  2713. ;; TODO keywords.
  2714. (should
  2715. (equal '(("A" "B") ("C"))
  2716. (org-test-with-temp-text "#+TODO: A B | C"
  2717. (org-mode-restart)
  2718. (list org-not-done-keywords org-done-keywords))))
  2719. (should
  2720. (equal '(("A" "C") ("B" "D"))
  2721. (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
  2722. (org-mode-restart)
  2723. (list org-not-done-keywords org-done-keywords))))
  2724. (should
  2725. (equal '(("A" "B") ("C"))
  2726. (org-test-with-temp-text "#+TYP_TODO: A B | C"
  2727. (org-mode-restart)
  2728. (list org-not-done-keywords org-done-keywords))))
  2729. (should
  2730. (equal '((:startgroup) ("A" . ?a) (:endgroup))
  2731. (org-test-with-temp-text "#+TODO: A(a)"
  2732. (org-mode-restart)
  2733. org-todo-key-alist)))
  2734. (should
  2735. (equal '(("D" note nil) ("C" time nil) ("B" note time))
  2736. (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
  2737. (org-mode-restart)
  2738. org-todo-log-states)))
  2739. ;; Enter SETUPFILE keyword.
  2740. (should
  2741. (equal "1"
  2742. (org-test-with-temp-text
  2743. (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
  2744. (org-mode-restart)
  2745. (cdr (assoc "a" org-keyword-properties))))))
  2746. (ert-deftest test-org/collect-keywords ()
  2747. "Test `org-collect-keywords'."
  2748. (should-not
  2749. (org-test-with-temp-text "#+begin_example\n#+foo: bar\n#+end_example"
  2750. (org-collect-keywords '("FOO")))))
  2751. ;;; Links
  2752. ;;;; Coderefs
  2753. (ert-deftest test-org/coderef ()
  2754. "Test coderef links specifications."
  2755. (should
  2756. (org-test-with-temp-text "
  2757. #+BEGIN_SRC emacs-lisp
  2758. \(+ 1 1) (ref:sc)
  2759. #+END_SRC
  2760. \[[(sc)<point>]]"
  2761. (org-open-at-point)
  2762. (looking-at "(ref:sc)")))
  2763. ;; Find coderef even with alternate label format.
  2764. (should
  2765. (org-test-with-temp-text "
  2766. #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
  2767. \(+ 1 1) {ref:sc}
  2768. #+END_SRC
  2769. \[[(sc)<point>]]"
  2770. (org-open-at-point)
  2771. (looking-at "{ref:sc}"))))
  2772. ;;;; Custom ID
  2773. (ert-deftest test-org/custom-id ()
  2774. "Test custom ID links specifications."
  2775. (should
  2776. (org-test-with-temp-text
  2777. "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2778. (org-open-at-point)
  2779. (looking-at-p "\\* H1")))
  2780. ;; Handle escape characters.
  2781. (should
  2782. (org-test-with-temp-text
  2783. "* H1\n:PROPERTIES:\n:CUSTOM_ID: [%]\n:END:\n* H2\n[[#\\[%\\]<point>]]"
  2784. (org-open-at-point)
  2785. (looking-at-p "\\* H1")))
  2786. ;; Throw an error on false positives.
  2787. (should-error
  2788. (org-test-with-temp-text
  2789. "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2790. (org-open-at-point)
  2791. (looking-at-p "\\* H1"))))
  2792. ;;;; Fuzzy Links
  2793. ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
  2794. ;; a named element (#+name: text) and to headlines (* Text).
  2795. (ert-deftest test-org/fuzzy-links ()
  2796. "Test fuzzy links specifications."
  2797. ;; Fuzzy link goes in priority to a matching target.
  2798. (should
  2799. (org-test-with-temp-text
  2800. "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
  2801. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2802. (looking-at "<<Test>>")))
  2803. ;; Then fuzzy link points to an element with a given name.
  2804. (should
  2805. (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
  2806. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2807. (looking-at "#\\+NAME: Test")))
  2808. ;; A target still lead to a matching headline otherwise.
  2809. (should
  2810. (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
  2811. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2812. (looking-at "\\* Head2")))
  2813. ;; With a leading star in link, enforce heading match.
  2814. (should
  2815. (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
  2816. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2817. (looking-at "\\* Test")))
  2818. ;; With a leading star in link, enforce exact heading match, even
  2819. ;; with `org-link-search-must-match-exact-headline' set to nil.
  2820. (should-error
  2821. (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
  2822. (let ((org-link-search-must-match-exact-headline nil))
  2823. (org-open-at-point))))
  2824. ;; Handle non-nil `org-link-search-must-match-exact-headline'.
  2825. (should
  2826. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
  2827. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2828. (looking-at "\\* Test")))
  2829. (should
  2830. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
  2831. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2832. (looking-at "\\* Test")))
  2833. ;; Heading match should not care about spaces, cookies, TODO
  2834. ;; keywords, priorities, and tags. However, TODO keywords are
  2835. ;; case-sensitive.
  2836. (should
  2837. (let ((first-line
  2838. "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
  2839. (org-test-with-temp-text
  2840. (concat first-line "\nFoo Bar\n<point>[[*Test 1 2]]")
  2841. (let ((org-link-search-must-match-exact-headline nil)
  2842. (org-todo-regexp "TODO"))
  2843. (org-open-at-point))
  2844. (looking-at (regexp-quote first-line)))))
  2845. (should-error
  2846. (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
  2847. (let ((org-link-search-must-match-exact-headline nil)
  2848. (org-todo-regexp "TODO"))
  2849. (org-open-at-point))))
  2850. ;; Heading match should still be exact.
  2851. (should-error
  2852. (org-test-with-temp-text "
  2853. ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
  2854. Foo Bar
  2855. <point>[[*Test 1]]"
  2856. (let ((org-link-search-must-match-exact-headline nil)
  2857. (org-todo-regexp "TODO"))
  2858. (org-open-at-point))))
  2859. (should
  2860. (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
  2861. (let ((org-link-search-must-match-exact-headline nil)
  2862. (org-todo-regexp "TODO"))
  2863. (org-open-at-point))
  2864. (looking-at-p (regexp-quote "** Test 1 2"))))
  2865. ;; Heading match ignores COMMENT keyword.
  2866. (should
  2867. (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
  2868. (org-open-at-point)
  2869. (looking-at "\\* COMMENT Test")))
  2870. (should
  2871. (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
  2872. (org-open-at-point)
  2873. (looking-at "\\* TODO COMMENT Test")))
  2874. ;; Correctly un-escape fuzzy links.
  2875. (should
  2876. (org-test-with-temp-text "* [foo]\n[[*\\[foo\\]][With escaped characters]]"
  2877. (org-open-at-point)
  2878. (bobp)))
  2879. ;; Match search strings containing newline characters, including
  2880. ;; blank lines.
  2881. (should
  2882. (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
  2883. (let ((file (buffer-file-name)))
  2884. (goto-char (point-max))
  2885. (insert (format "[[file:%s::line1 line2]]" file))
  2886. (beginning-of-line)
  2887. (let ((org-link-search-must-match-exact-headline nil))
  2888. (org-open-at-point 0))
  2889. (looking-at-p "line1"))))
  2890. (should
  2891. (org-test-with-temp-text-in-file "Paragraph\n\nline1\n\nline2\n\n"
  2892. (let ((file (buffer-file-name)))
  2893. (goto-char (point-max))
  2894. (insert (format "[[file:%s::line1 line2]]" file))
  2895. (beginning-of-line)
  2896. (let ((org-link-search-must-match-exact-headline nil))
  2897. (org-open-at-point 0))
  2898. (looking-at-p "line1")))))
  2899. ;;;; Open at point
  2900. (ert-deftest test-org/open-at-point/keyword ()
  2901. "Does `org-open-at-point' open link in a keyword line?"
  2902. (should
  2903. (org-test-with-temp-text
  2904. "<<top>>\n#+KEYWORD: <point>[[top]]"
  2905. (org-open-at-point) t))
  2906. (should
  2907. (org-test-with-temp-text
  2908. "* H\n<<top>>\n#+KEYWORD: <point>[[top]]"
  2909. (org-open-at-point) t)))
  2910. (ert-deftest test-org/open-at-point/property ()
  2911. "Does `org-open-at-point' open link in property drawer?"
  2912. (should
  2913. (org-test-with-temp-text
  2914. "* Headline
  2915. :PROPERTIES:
  2916. :URL: <point>[[*Headline]]
  2917. :END:"
  2918. (org-open-at-point) t)))
  2919. (ert-deftest test-org/open-at-point/comment ()
  2920. "Does `org-open-at-point' open link in a commented line?"
  2921. (should
  2922. (org-test-with-temp-text
  2923. "<<top>>\n# <point>[[top]]"
  2924. (org-open-at-point) t))
  2925. (should
  2926. (org-test-with-temp-text
  2927. "* H\n<<top>>\n# <point>[[top]]"
  2928. (org-open-at-point) t)))
  2929. (ert-deftest test-org/open-at-point/inline-image ()
  2930. "Test `org-open-at-point' on nested links."
  2931. (should
  2932. (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
  2933. (org-open-at-point)
  2934. (bobp))))
  2935. (ert-deftest test-org/open-at-point/radio-target ()
  2936. "Test `org-open-at-point' on radio targets."
  2937. (should
  2938. (org-test-with-temp-text "<<<target>>> <point>target"
  2939. (org-update-radio-target-regexp)
  2940. (org-open-at-point)
  2941. (eq (org-element-type (org-element-context)) 'radio-target))))
  2942. (ert-deftest test-org/open-at-point/radio-target-shadowed ()
  2943. "Test `org-open-at-point' on shadowed radio targets."
  2944. (should
  2945. (org-test-with-temp-text
  2946. "<<<target shadowed>>> <<<target>>> <point>target shadowed"
  2947. (org-update-radio-target-regexp)
  2948. (org-open-at-point)
  2949. (string=
  2950. (org-element-property :value
  2951. (org-element-radio-target-parser))
  2952. "target shadowed"))))
  2953. (ert-deftest test-org/open-at-point/tag ()
  2954. "Test `org-open-at-point' on tags."
  2955. (should
  2956. (org-test-with-temp-text "* H :<point>tag:"
  2957. (catch :result
  2958. (cl-letf (((symbol-function 'org-tags-view)
  2959. (lambda (&rest args) (throw :result t))))
  2960. (org-open-at-point)
  2961. nil))))
  2962. (should-not
  2963. (org-test-with-temp-text-in-file "* H<point> :tag:"
  2964. (catch :result
  2965. (cl-letf (((symbol-function 'org-tags-view)
  2966. (lambda (&rest args) (throw :result t))))
  2967. ;; When point isn't on a tag it's going to try other things,
  2968. ;; possibly trying to open attachments which will return an
  2969. ;; error if there isn't an attachment. Suppress that error.
  2970. (ignore-errors
  2971. (org-open-at-point))
  2972. nil)))))
  2973. ;;; Node Properties
  2974. (ert-deftest test-org/accumulated-properties-in-drawers ()
  2975. "Ensure properties accumulate in subtree drawers."
  2976. (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
  2977. (org-babel-next-src-block)
  2978. (should (equal '(2 1) (org-babel-execute-src-block)))))
  2979. (ert-deftest test-org/custom-properties ()
  2980. "Test custom properties specifications."
  2981. ;; Standard test.
  2982. (should
  2983. (let ((org-custom-properties '("FOO")))
  2984. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2985. (org-toggle-custom-properties-visibility)
  2986. (org-invisible-p2))))
  2987. ;; Properties are case-insensitive.
  2988. (should
  2989. (let ((org-custom-properties '("FOO")))
  2990. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
  2991. (org-toggle-custom-properties-visibility)
  2992. (org-invisible-p2))))
  2993. (should
  2994. (let ((org-custom-properties '("foo")))
  2995. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2996. (org-toggle-custom-properties-visibility)
  2997. (org-invisible-p2))))
  2998. ;; Multiple custom properties in the same drawer.
  2999. (should
  3000. (let ((org-custom-properties '("FOO" "BAR")))
  3001. (org-test-with-temp-text
  3002. "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
  3003. (org-fold-reveal)
  3004. (org-toggle-custom-properties-visibility)
  3005. (and (org-invisible-p2)
  3006. (not (progn (forward-line) (org-invisible-p2)))
  3007. (progn (forward-line) (org-invisible-p2))))))
  3008. ;; Hide custom properties with an empty value.
  3009. (should
  3010. (let ((org-custom-properties '("FOO")))
  3011. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
  3012. (org-toggle-custom-properties-visibility)
  3013. (org-invisible-p2))))
  3014. ;; Do not hide fake properties.
  3015. (should-not
  3016. (let ((org-custom-properties '("FOO")))
  3017. (org-test-with-temp-text ":FOO: val\n"
  3018. (org-toggle-custom-properties-visibility)
  3019. (org-invisible-p2))))
  3020. (should-not
  3021. (let ((org-custom-properties '("A")))
  3022. (org-test-with-temp-text
  3023. "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
  3024. (org-fold-reveal)
  3025. (org-toggle-custom-properties-visibility)
  3026. (org-invisible-p2)))))
  3027. ;;; Mark Region
  3028. (ert-deftest test-org/mark-element ()
  3029. "Test `org-mark-element' specifications."
  3030. ;; Mark beginning and end of element.
  3031. (should
  3032. (equal '(t t)
  3033. (org-test-with-temp-text "Para<point>graph"
  3034. (org-mark-element)
  3035. (list (bobp) (= (mark) (point-max))))))
  3036. (should
  3037. (equal '(t t)
  3038. (org-test-with-temp-text "P1\n\nPara<point>graph\n\nP2"
  3039. (org-mark-element)
  3040. (list (looking-at "Paragraph")
  3041. (org-with-point-at (mark) (looking-at "P2"))))))
  3042. ;; Do not set mark past (point-max).
  3043. (should
  3044. (org-test-with-temp-text "Para<point>graph"
  3045. (narrow-to-region 2 6)
  3046. (org-mark-element)
  3047. (= 6 (mark)))))
  3048. (ert-deftest test-org/mark-subtree ()
  3049. "Test `org-mark-subtree' specifications."
  3050. ;; Error when point is before first headline.
  3051. (should-error
  3052. (org-test-with-temp-text "Paragraph\n* Headline\nBody"
  3053. (progn (transient-mark-mode 1)
  3054. (org-mark-subtree))))
  3055. ;; Without argument, mark current subtree.
  3056. (should
  3057. (equal
  3058. '(12 32)
  3059. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  3060. (progn (transient-mark-mode 1)
  3061. (forward-line 2)
  3062. (org-mark-subtree)
  3063. (list (region-beginning) (region-end))))))
  3064. ;; With an argument, move ARG up.
  3065. (should
  3066. (equal
  3067. '(1 32)
  3068. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  3069. (progn (transient-mark-mode 1)
  3070. (forward-line 2)
  3071. (org-mark-subtree 1)
  3072. (list (region-beginning) (region-end))))))
  3073. ;; Do not get fooled by inlinetasks.
  3074. (when (featurep 'org-inlinetask)
  3075. (should
  3076. (= 1
  3077. (org-test-with-temp-text "* Headline\n*************** Task\nContents"
  3078. (progn (transient-mark-mode 1)
  3079. (forward-line 1)
  3080. (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
  3081. (region-beginning)))))))
  3082. ;;; Miscellaneous
  3083. (ert-deftest test-org/sort-entries ()
  3084. "Test `org-sort-entries'."
  3085. ;; Sort alphabetically.
  3086. (should
  3087. (equal "\n* abc\n* def\n* xyz\n"
  3088. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  3089. (org-sort-entries nil ?a)
  3090. (buffer-string))))
  3091. (should
  3092. (equal "\n* xyz\n* def\n* abc\n"
  3093. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  3094. (org-sort-entries nil ?A)
  3095. (buffer-string))))
  3096. (should
  3097. (equal "\n* \n* klm\n* xyz\n"
  3098. (org-test-with-temp-text "\n* xyz\n* \n* klm\n"
  3099. (org-sort-entries nil ?a)
  3100. (buffer-string))))
  3101. ;; Sort numerically.
  3102. (should
  3103. (equal "\n* 1\n* 2\n* 10\n"
  3104. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  3105. (org-sort-entries nil ?n)
  3106. (buffer-string))))
  3107. (should
  3108. (equal "\n* 10\n* 2\n* 1\n"
  3109. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  3110. (org-sort-entries nil ?N)
  3111. (buffer-string))))
  3112. (should
  3113. (equal "\n* \n* 1\n* 2\n"
  3114. (org-test-with-temp-text "\n* 1\n* \n* 2\n"
  3115. (org-sort-entries nil ?n)
  3116. (buffer-string))))
  3117. ;; Sort by custom function.
  3118. (should
  3119. (equal "\n* b\n* aa\n* ccc\n"
  3120. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  3121. (org-sort-entries nil ?f
  3122. (lambda ()
  3123. (length (buffer-substring (point-at-bol)
  3124. (point-at-eol))))
  3125. #'<)
  3126. (buffer-string))))
  3127. (should
  3128. (equal "\n* ccc\n* aa\n* b\n"
  3129. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  3130. (org-sort-entries nil ?F
  3131. (lambda ()
  3132. (length (buffer-substring (point-at-bol)
  3133. (point-at-eol))))
  3134. #'<)
  3135. (buffer-string))))
  3136. ;; Sort by TODO keyword.
  3137. (should
  3138. (equal "\n* TODO h1\n* TODO h3\n* DONE h2\n"
  3139. (org-test-with-temp-text
  3140. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  3141. (org-sort-entries nil ?o)
  3142. (buffer-string))))
  3143. (should
  3144. (equal "\n* DONE h2\n* TODO h1\n* TODO h3\n"
  3145. (org-test-with-temp-text
  3146. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  3147. (org-sort-entries nil ?O)
  3148. (buffer-string))))
  3149. ;; Sort by priority.
  3150. (should
  3151. (equal "\n* [#A] h2\n* [#B] h3\n* [#C] h1\n"
  3152. (org-test-with-temp-text
  3153. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  3154. (org-sort-entries nil ?p)
  3155. (buffer-string))))
  3156. (should
  3157. (equal "\n* [#C] h1\n* [#B] h3\n* [#A] h2\n"
  3158. (org-test-with-temp-text
  3159. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  3160. (org-sort-entries nil ?P)
  3161. (buffer-string))))
  3162. ;; Sort by creation time.
  3163. (should
  3164. (equal "
  3165. * h3
  3166. [2017-05-08 Mon]
  3167. * h2
  3168. [2017-05-09 Tue]
  3169. * h1
  3170. [2018-05-09 Wed]
  3171. "
  3172. (org-test-with-temp-text
  3173. "
  3174. * h1
  3175. [2018-05-09 Wed]
  3176. * h2
  3177. [2017-05-09 Tue]
  3178. * h3
  3179. [2017-05-08 Mon]
  3180. "
  3181. (org-sort-entries nil ?c)
  3182. (buffer-string))))
  3183. ;; Sort by scheduled date.
  3184. (should
  3185. (equal "
  3186. * TODO h4
  3187. SCHEDULED: <2017-05-06 Sat>
  3188. * TODO h3
  3189. SCHEDULED: <2017-05-08 Mon>
  3190. * TODO h2
  3191. DEADLINE: <2017-05-09 Tue>
  3192. * TODO h1
  3193. DEADLINE: <2017-05-07 Sun>
  3194. "
  3195. (org-test-with-temp-text
  3196. "
  3197. * TODO h2
  3198. DEADLINE: <2017-05-09 Tue>
  3199. * TODO h1
  3200. DEADLINE: <2017-05-07 Sun>
  3201. * TODO h3
  3202. SCHEDULED: <2017-05-08 Mon>
  3203. * TODO h4
  3204. SCHEDULED: <2017-05-06 Sat>
  3205. "
  3206. (org-sort-entries nil ?s)
  3207. (buffer-string))))
  3208. ;; Sort by deadline date.
  3209. (should
  3210. (equal "
  3211. * TODO h1
  3212. DEADLINE: <2017-05-07 Sun>
  3213. * TODO h2
  3214. DEADLINE: <2017-05-09 Tue>
  3215. * TODO h3
  3216. SCHEDULED: <2017-05-08 Mon>
  3217. * TODO h4
  3218. SCHEDULED: <2017-05-06 Sat>
  3219. "
  3220. (org-test-with-temp-text
  3221. "
  3222. * TODO h2
  3223. DEADLINE: <2017-05-09 Tue>
  3224. * TODO h1
  3225. DEADLINE: <2017-05-07 Sun>
  3226. * TODO h3
  3227. SCHEDULED: <2017-05-08 Mon>
  3228. * TODO h4
  3229. SCHEDULED: <2017-05-06 Sat>
  3230. "
  3231. (org-sort-entries nil ?d)
  3232. (buffer-string))))
  3233. ;; Sort by any date/time
  3234. (should
  3235. (equal "
  3236. * TODO h4
  3237. SCHEDULED: <2017-05-06 Sat>
  3238. * TODO h1
  3239. DEADLINE: <2017-05-07 Sun>
  3240. * TODO h3
  3241. SCHEDULED: <2017-05-08 Mon>
  3242. * TODO h2
  3243. DEADLINE: <2017-05-09 Tue>
  3244. "
  3245. (org-test-with-temp-text
  3246. "
  3247. * TODO h2
  3248. DEADLINE: <2017-05-09 Tue>
  3249. * TODO h1
  3250. DEADLINE: <2017-05-07 Sun>
  3251. * TODO h3
  3252. SCHEDULED: <2017-05-08 Mon>
  3253. * TODO h4
  3254. SCHEDULED: <2017-05-06 Sat>
  3255. "
  3256. (org-sort-entries nil ?t)
  3257. (buffer-string))))
  3258. ;; Sort by clocking time.
  3259. (should
  3260. (equal "
  3261. * clocked h2
  3262. :LOGBOOK:
  3263. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3264. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  3265. :END:
  3266. * clocked h1
  3267. :LOGBOOK:
  3268. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3269. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  3270. :END:
  3271. "
  3272. (org-test-with-temp-text
  3273. "
  3274. * clocked h1
  3275. :LOGBOOK:
  3276. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3277. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  3278. :END:
  3279. * clocked h2
  3280. :LOGBOOK:
  3281. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3282. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  3283. :END:
  3284. "
  3285. (org-sort-entries nil ?k)
  3286. (buffer-string))))
  3287. ;; Preserve file local variables when sorting.
  3288. (should
  3289. (equal "\n* A\n* B\n# Local Variables:\n# foo: t\n# End:\n"
  3290. (org-test-with-temp-text
  3291. "\n* B\n* A\n# Local Variables:\n# foo: t\n# End:"
  3292. (org-sort-entries nil ?a)
  3293. (buffer-string)))))
  3294. (ert-deftest test-org/string-collate-greaterp ()
  3295. "Test `org-string-collate-greaterp' specifications."
  3296. (should (org-string-collate-greaterp "def" "abc"))
  3297. (should-not (org-string-collate-greaterp "abc" "def")))
  3298. (ert-deftest test-org/file-contents ()
  3299. "Test `org-file-contents' specifications."
  3300. ;; Open files.
  3301. (should
  3302. (string= "#+BIND: variable value
  3303. #+DESCRIPTION: l2
  3304. #+LANGUAGE: en
  3305. #+SELECT_TAGS: b
  3306. #+TITLE: b
  3307. #+PROPERTY: a 1
  3308. " (org-file-contents (expand-file-name "setupfile3.org"
  3309. (concat org-test-dir "examples/")))))
  3310. ;; Throw error when trying to access an invalid file.
  3311. (should-error (org-file-contents "this-file-must-not-exist"))
  3312. ;; Try to access an invalid file, but do not throw an error.
  3313. (should
  3314. (progn (org-file-contents "this-file-must-not-exist" :noerror) t))
  3315. ;; Open URL.
  3316. (should
  3317. (string= "foo"
  3318. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3319. (unwind-protect
  3320. ;; Simulate successful retrieval of a URL.
  3321. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3322. (lambda (&rest_)
  3323. (with-current-buffer buffer
  3324. (insert "HTTP/1.1 200 OK\n\nfoo"))
  3325. buffer)))
  3326. (org-file-contents "http://some-valid-url"))
  3327. (kill-buffer buffer)))))
  3328. ;; Throw error when trying to access an invalid URL.
  3329. (should-error
  3330. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3331. (unwind-protect
  3332. ;; Simulate unsuccessful retrieval of a URL.
  3333. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3334. (lambda (&rest_)
  3335. (with-current-buffer buffer
  3336. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3337. buffer)))
  3338. (org-file-contents "http://this-url-must-not-exist"))
  3339. (kill-buffer buffer))))
  3340. ;; Try to access an invalid URL, but do not throw an error.
  3341. (should-error
  3342. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3343. (unwind-protect
  3344. ;; Simulate unsuccessful retrieval of a URL.
  3345. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3346. (lambda (&rest_)
  3347. (with-current-buffer buffer
  3348. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3349. buffer)))
  3350. (org-file-contents "http://this-url-must-not-exist"))
  3351. (kill-buffer buffer))))
  3352. (should
  3353. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3354. (unwind-protect
  3355. ;; Simulate unsuccessful retrieval of a URL.
  3356. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3357. (lambda (&rest_)
  3358. (with-current-buffer buffer
  3359. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3360. buffer)))
  3361. (org-file-contents "http://this-url-must-not-exist" :noerror))
  3362. (kill-buffer buffer))
  3363. t)))
  3364. ;;; Navigation
  3365. (ert-deftest test-org/next-visible-heading ()
  3366. "Test `org-next-visible-heading' specifications."
  3367. ;; Move to the beginning of the next headline, taking into
  3368. ;; consideration ARG.
  3369. (should
  3370. (org-test-with-temp-text "* H1\n* H2"
  3371. (org-next-visible-heading 1)
  3372. (looking-at "\\* H2")))
  3373. (should
  3374. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3375. (org-next-visible-heading 2)
  3376. (looking-at "\\* H3")))
  3377. ;; Ignore invisible headlines.
  3378. (should
  3379. (org-test-with-temp-text "* H1\n** H2\n* H3"
  3380. (org-cycle)
  3381. (org-next-visible-heading 1)
  3382. (looking-at "\\* H3")))
  3383. ;; Move point between headlines, not on blank lines between.
  3384. (should
  3385. (org-test-with-temp-text "* H1\n** H2\n\n\n\n* H3"
  3386. (let ((org-cycle-separator-lines 1))
  3387. (org-cycle)
  3388. (org-next-visible-heading 1))
  3389. (looking-at "\\* H3")))
  3390. ;; Move at end of buffer when there is no more headline.
  3391. (should
  3392. (org-test-with-temp-text "* H1"
  3393. (org-next-visible-heading 1)
  3394. (eobp)))
  3395. (should
  3396. (org-test-with-temp-text "* H1\n* H2"
  3397. (org-next-visible-heading 2)
  3398. (eobp)))
  3399. ;; With a negative argument, move backwards.
  3400. (should
  3401. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3402. (org-next-visible-heading -1)
  3403. (looking-at "\\* H2")))
  3404. (should
  3405. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3406. (org-next-visible-heading -2)
  3407. (looking-at "\\* H1"))))
  3408. (ert-deftest test-org/previous-visible-heading ()
  3409. "Test `org-previous-visible-heading' specifications."
  3410. ;; Move to the beginning of the next headline, taking into
  3411. ;; consideration ARG.
  3412. (should
  3413. (org-test-with-temp-text "* H1\n<point>* H2"
  3414. (org-previous-visible-heading 1)
  3415. (looking-at "\\* H1")))
  3416. (should
  3417. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3418. (org-previous-visible-heading 2)
  3419. (looking-at "\\* H1")))
  3420. ;; Ignore invisible headlines.
  3421. (should
  3422. (org-test-with-temp-text "* H1\n** H2\n<point>* H3"
  3423. (org-overview)
  3424. (org-previous-visible-heading 1)
  3425. (looking-at "\\* H1")))
  3426. ;; Move point between headlines, not on blank lines between.
  3427. (should
  3428. (org-test-with-temp-text "* H1\n\n\n\n** H2\n<point>* H3"
  3429. (let ((org-cycle-separator-lines 1))
  3430. (org-overview)
  3431. (org-previous-visible-heading 1))
  3432. (looking-at "\\* H1")))
  3433. ;; Move at end of buffer when there is no more headline.
  3434. (should
  3435. (org-test-with-temp-text "* H1"
  3436. (org-previous-visible-heading 1)
  3437. (bobp)))
  3438. (should
  3439. (org-test-with-temp-text "* H1\n* <point>H2"
  3440. (org-previous-visible-heading 2)
  3441. (bobp)))
  3442. ;; Invisible parts may not start at a headline, i.e., when revealing
  3443. ;; parts of the buffer. Handle this.
  3444. (should
  3445. (org-test-with-temp-text "* Main\n** H1\nFoo\n** H2\nBar\n** H3\nBaz"
  3446. (org-overview)
  3447. (search-forward "H1")
  3448. (org-show-context 'minimal)
  3449. (org-cycle)
  3450. (search-forward "H3")
  3451. (org-show-context 'minimal)
  3452. ;; At this point, buffer displays, with point at "|",
  3453. ;;
  3454. ;; * Main
  3455. ;; ** H1
  3456. ;; Foo
  3457. ;; ** H3|
  3458. (org-previous-visible-heading 1)
  3459. (looking-at "\\*+ H1"))))
  3460. (ert-deftest test-org/forward-heading-same-level ()
  3461. "Test `org-forward-heading-same-level' specifications."
  3462. ;; Test navigation at top level, forward and backward.
  3463. (should
  3464. (equal "* H2"
  3465. (org-test-with-temp-text "* H1\n* H2"
  3466. (org-forward-heading-same-level 1)
  3467. (buffer-substring-no-properties (point) (line-end-position)))))
  3468. (should
  3469. (equal "* H1"
  3470. (org-test-with-temp-text "* H1\n<point>* H2"
  3471. (org-forward-heading-same-level -1)
  3472. (buffer-substring-no-properties (point) (line-end-position)))))
  3473. ;; Test navigation in a sub-tree, forward and backward.
  3474. (should
  3475. (equal "* H2"
  3476. (org-test-with-temp-text "* H1\n** H11\n** H12\n* H2"
  3477. (org-forward-heading-same-level 1)
  3478. (buffer-substring-no-properties (point) (line-end-position)))))
  3479. (should
  3480. (equal "* H1"
  3481. (org-test-with-temp-text "* H1\n** H11\n** H12\n<point>* H2"
  3482. (org-forward-heading-same-level -1)
  3483. (buffer-substring-no-properties (point) (line-end-position)))))
  3484. ;; Stop at first or last sub-heading.
  3485. (should-not
  3486. (equal "* H2"
  3487. (org-test-with-temp-text "* H1\n** H11\n<point>** H12\n* H2"
  3488. (org-forward-heading-same-level 1)
  3489. (buffer-substring-no-properties (point) (line-end-position)))))
  3490. (should-not
  3491. (equal "* H2"
  3492. (org-test-with-temp-text "* H1\n<point>** H11\n** H12\n* H2"
  3493. (org-forward-heading-same-level -1)
  3494. (buffer-substring-no-properties (point) (line-end-position)))))
  3495. ;; Allow multiple moves.
  3496. (should
  3497. (equal "* H3"
  3498. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3499. (org-forward-heading-same-level 2)
  3500. (buffer-substring-no-properties (point) (line-end-position)))))
  3501. (should
  3502. (equal "* H1"
  3503. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3504. (org-forward-heading-same-level -2)
  3505. (buffer-substring-no-properties (point) (line-end-position)))))
  3506. ;; Ignore spurious moves when first (or last) sibling is reached.
  3507. (should
  3508. (equal "** H3"
  3509. (org-test-with-temp-text "* First\n<point>** H1\n** H2\n** H3\n* Last"
  3510. (org-forward-heading-same-level 100)
  3511. (buffer-substring-no-properties (point) (line-end-position)))))
  3512. (should
  3513. (equal "** H1"
  3514. (org-test-with-temp-text "* First\n** H1\n** H2\n<point>** H3\n* Last"
  3515. (org-forward-heading-same-level -100)
  3516. (buffer-substring-no-properties (point) (line-end-position))))))
  3517. (ert-deftest test-org/end-of-meta-data ()
  3518. "Test `org-end-of-meta-data' specifications."
  3519. ;; Skip planning line.
  3520. (should
  3521. (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
  3522. (org-end-of-meta-data)
  3523. (eobp)))
  3524. ;; Skip properties drawer.
  3525. (should
  3526. (org-test-with-temp-text
  3527. "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
  3528. (org-end-of-meta-data)
  3529. (eobp)))
  3530. ;; Skip both.
  3531. (should
  3532. (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
  3533. (org-end-of-meta-data)
  3534. (eobp)))
  3535. ;; Nothing to skip, go to first line.
  3536. (should
  3537. (org-test-with-temp-text "* Headline\nContents"
  3538. (org-end-of-meta-data)
  3539. (looking-at "Contents")))
  3540. ;; With option argument, skip empty lines, regular drawers and
  3541. ;; clocking lines.
  3542. (should
  3543. (org-test-with-temp-text "* Headline\n\nContents"
  3544. (org-end-of-meta-data t)
  3545. (looking-at "Contents")))
  3546. (should
  3547. (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
  3548. (org-end-of-meta-data t)
  3549. (looking-at "Contents")))
  3550. (should
  3551. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
  3552. (org-end-of-meta-data t)
  3553. (looking-at "Contents")))
  3554. ;; Special case: do not skip incomplete drawers.
  3555. (should
  3556. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
  3557. (org-end-of-meta-data t)
  3558. (looking-at ":LOGBOOK:")))
  3559. ;; Special case: Be careful about consecutive headlines.
  3560. (should-not
  3561. (org-test-with-temp-text "* H1\n*H2\nContents"
  3562. (org-end-of-meta-data t)
  3563. (looking-at "Contents"))))
  3564. (ert-deftest test-org/shiftright-heading ()
  3565. "Test `org-shiftright' on headings."
  3566. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  3567. (should
  3568. (equal "* TODO a1\n** a2\n* DONE b1\n"
  3569. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3570. (org-shiftright)
  3571. (buffer-string))))
  3572. (should
  3573. (equal "* TODO a1\n** TODO a2\n* b1\n"
  3574. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3575. (let ((org-loop-over-headlines-in-active-region t))
  3576. (transient-mark-mode 1)
  3577. (push-mark (point) t t)
  3578. (search-forward "* DONE b1")
  3579. (org-shiftright))
  3580. (buffer-string))))
  3581. (should
  3582. (equal "* TODO a1\n** a2\n* b1\n"
  3583. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3584. (let ((org-loop-over-headlines-in-active-region 'start-level))
  3585. (transient-mark-mode 1)
  3586. (push-mark (point) t t)
  3587. (search-forward "* DONE b1")
  3588. (org-shiftright))
  3589. (buffer-string))))))
  3590. (ert-deftest test-org/beginning-of-line ()
  3591. "Test `org-beginning-of-line' specifications."
  3592. ;; Move to beginning of line. If current line in invisible, move to
  3593. ;; beginning of visible line instead.
  3594. (should
  3595. (org-test-with-temp-text "Some text\nSome other text<point>"
  3596. (org-beginning-of-line)
  3597. (bolp)))
  3598. (should
  3599. (org-test-with-temp-text "* H1\n** H2<point>"
  3600. (org-overview)
  3601. (org-beginning-of-line)
  3602. (= (line-beginning-position) 1)))
  3603. ;; With `visual-line-mode' active, move to beginning of visual line.
  3604. (should-not
  3605. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3606. (visual-line-mode)
  3607. (dotimes (i 1000) (insert "very "))
  3608. (org-beginning-of-line)
  3609. (bolp)))
  3610. ;; In a wide headline, with `visual-line-mode', prefer going to the
  3611. ;; beginning of a visual line than to the logical beginning of line,
  3612. ;; even if special movement is active.
  3613. (should-not
  3614. (org-test-with-temp-text "* A <point>long headline"
  3615. (visual-line-mode)
  3616. (dotimes (i 1000) (insert "very "))
  3617. (goto-char (point-max))
  3618. (org-beginning-of-line)
  3619. (bobp)))
  3620. (should-not
  3621. (org-test-with-temp-text "* A <point>long headline"
  3622. (visual-line-mode)
  3623. (dotimes (i 1000) (insert "very "))
  3624. (goto-char (point-max))
  3625. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line))
  3626. (bobp)))
  3627. ;; At an headline with special movement, first move at beginning of
  3628. ;; title, then at the beginning of line, rinse, repeat.
  3629. (should
  3630. (org-test-with-temp-text "* TODO Headline<point>"
  3631. (let ((org-special-ctrl-a/e t))
  3632. (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
  3633. (progn (org-beginning-of-line) (bolp))
  3634. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3635. (should
  3636. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3637. (let ((org-special-ctrl-a/e t))
  3638. (org-beginning-of-line)
  3639. (looking-at "Headline"))))
  3640. (should
  3641. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3642. (let ((org-special-ctrl-a/e '(t . nil)))
  3643. (org-beginning-of-line)
  3644. (looking-at "Headline"))))
  3645. (should-not
  3646. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3647. (let ((org-special-ctrl-a/e '(nil . nil)))
  3648. (org-beginning-of-line)
  3649. (looking-at "Headline"))))
  3650. ;; At an headline with reversed movement, first move to beginning of
  3651. ;; line, then to the beginning of title.
  3652. (should
  3653. (org-test-with-temp-text "* TODO Headline<point>"
  3654. (let ((org-special-ctrl-a/e 'reversed)
  3655. (this-command last-command))
  3656. (and (progn (org-beginning-of-line) (bolp))
  3657. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3658. (should
  3659. (org-test-with-temp-text "* TODO Headline<point>"
  3660. (let ((org-special-ctrl-a/e '(reversed . nil))
  3661. (this-command last-command))
  3662. (and (progn (org-beginning-of-line) (bolp))
  3663. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3664. (should-not
  3665. (org-test-with-temp-text "* TODO Headline<point>"
  3666. (let ((org-special-ctrl-a/e '(t . nil))
  3667. (this-command last-command))
  3668. (and (progn (org-beginning-of-line) (bolp))
  3669. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3670. ;; At an item with special movement, first move after to beginning
  3671. ;; of title, then to the beginning of line, rinse, repeat.
  3672. (should
  3673. (org-test-with-temp-text "- [ ] Item<point>"
  3674. (let ((org-special-ctrl-a/e t))
  3675. (and (progn (org-beginning-of-line) (looking-at-p "Item"))
  3676. (progn (org-beginning-of-line) (bolp))
  3677. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3678. ;; At an item with reversed movement, first move to beginning of
  3679. ;; line, then to the beginning of title.
  3680. (should
  3681. (org-test-with-temp-text "- [X] Item<point>"
  3682. (let ((org-special-ctrl-a/e 'reversed)
  3683. (this-command last-command))
  3684. (and (progn (org-beginning-of-line) (bolp))
  3685. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3686. ;; Leave point before invisible characters at column 0.
  3687. (should
  3688. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3689. (let ((org-special-ctrl-a/e nil))
  3690. (org-beginning-of-line)
  3691. (bolp))))
  3692. (should
  3693. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3694. (let ((org-special-ctrl-a/e t))
  3695. (org-beginning-of-line)
  3696. (bolp))))
  3697. (should
  3698. (org-test-with-temp-text "[[http<point>://orgmode.org]]"
  3699. (visual-line-mode)
  3700. (org-beginning-of-line)
  3701. (bolp)))
  3702. ;; Special case: Do not error when the buffer contains only a single
  3703. ;; asterisk.
  3704. (should
  3705. (org-test-with-temp-text "*<point>"
  3706. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line) t)))
  3707. (should
  3708. (org-test-with-temp-text "*<point>"
  3709. (let ((org-special-ctrl-a/e nil)) (org-beginning-of-line) t))))
  3710. (ert-deftest test-org/end-of-line ()
  3711. "Test `org-end-of-line' specifications."
  3712. ;; Standard test.
  3713. (should
  3714. (org-test-with-temp-text "Some text\nSome other text"
  3715. (org-end-of-line)
  3716. (eolp)))
  3717. ;; With `visual-line-mode' active, move to end of visible line.
  3718. ;; However, never go past ellipsis.
  3719. (should-not
  3720. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3721. (visual-line-mode)
  3722. (dotimes (i 1000) (insert "very "))
  3723. (goto-char (point-min))
  3724. (org-end-of-line)
  3725. (eolp)))
  3726. (should-not
  3727. (org-test-with-temp-text "* A short headline\nSome contents"
  3728. (visual-line-mode)
  3729. (org-overview)
  3730. (org-end-of-line)
  3731. (eobp)))
  3732. ;; In a wide headline, with `visual-line-mode', prefer going to end
  3733. ;; of visible line if tags, or end of line, are farther.
  3734. (should-not
  3735. (org-test-with-temp-text "* A <point>long headline"
  3736. (visual-line-mode)
  3737. (dotimes (i 1000) (insert "very "))
  3738. (goto-char (point-min))
  3739. (org-end-of-line)
  3740. (eolp)))
  3741. (should-not
  3742. (org-test-with-temp-text "* A <point>long headline :tag:"
  3743. (visual-line-mode)
  3744. (dotimes (i 1000) (insert "very "))
  3745. (goto-char (point-min))
  3746. (org-end-of-line)
  3747. (eolp)))
  3748. ;; At an headline without special movement, go to end of line.
  3749. ;; However, never go past ellipsis.
  3750. (should
  3751. (org-test-with-temp-text "* Headline2b :tag:\n"
  3752. (let ((org-special-ctrl-a/e nil))
  3753. (and (progn (org-end-of-line) (eolp))
  3754. (progn (org-end-of-line) (eolp))))))
  3755. (should
  3756. (org-test-with-temp-text "* Headline2b :tag:\n"
  3757. (let ((org-special-ctrl-a/e '(t . nil)))
  3758. (and (progn (org-end-of-line) (eolp))
  3759. (progn (org-end-of-line) (eolp))))))
  3760. (should
  3761. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3762. (org-overview)
  3763. (let ((org-special-ctrl-a/e nil))
  3764. (org-end-of-line)
  3765. (= 1 (line-beginning-position)))))
  3766. ;; At an headline with special movement, first move before tags,
  3767. ;; then at the end of line, rinse, repeat. However, never go past
  3768. ;; ellipsis.
  3769. (should
  3770. (org-test-with-temp-text "* Headline1 :tag:\n"
  3771. (let ((org-special-ctrl-a/e t))
  3772. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3773. (progn (org-end-of-line) (eolp))
  3774. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3775. (should
  3776. (org-test-with-temp-text "* Headline1 :tag:\n"
  3777. (let ((org-special-ctrl-a/e '(nil . t)))
  3778. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3779. (progn (org-end-of-line) (eolp))
  3780. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3781. (should-not
  3782. (org-test-with-temp-text "* Headline1 :tag:\n"
  3783. (let ((org-special-ctrl-a/e '(nil . nil)))
  3784. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3785. (progn (org-end-of-line) (eolp))
  3786. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3787. (should
  3788. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3789. (org-overview)
  3790. (let ((org-special-ctrl-a/e t))
  3791. (org-end-of-line)
  3792. (org-end-of-line)
  3793. (= 1 (line-beginning-position)))))
  3794. ;; At an headline, with reversed movement, first go to end of line,
  3795. ;; then before tags. However, never go past ellipsis.
  3796. (should
  3797. (org-test-with-temp-text "* Headline3 :tag:\n"
  3798. (let ((org-special-ctrl-a/e 'reversed)
  3799. (this-command last-command))
  3800. (and (progn (org-end-of-line) (eolp))
  3801. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3802. (should
  3803. (org-test-with-temp-text "* Headline3 :tag:\n"
  3804. (let ((org-special-ctrl-a/e '(nil . reversed))
  3805. (this-command last-command))
  3806. (and (progn (org-end-of-line) (eolp))
  3807. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3808. (should-not
  3809. (org-test-with-temp-text "* Headline3 :tag:\n"
  3810. (let ((org-special-ctrl-a/e '(nil . t))
  3811. (this-command last-command))
  3812. (and (progn (org-end-of-line) (eolp))
  3813. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3814. (should
  3815. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3816. (org-overview)
  3817. (let ((org-special-ctrl-a/e 'reversed))
  3818. (org-end-of-line)
  3819. (= 1 (line-beginning-position)))))
  3820. ;; At a block without hidden contents.
  3821. (should
  3822. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3823. (progn (org-end-of-line) (eolp))))
  3824. ;; At a block with hidden contents.
  3825. (should-not
  3826. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3827. (let ((org-special-ctrl-a/e t))
  3828. (org-fold-hide-block-toggle)
  3829. (org-end-of-line)
  3830. (eobp))))
  3831. ;; Get past invisible characters at the end of line.
  3832. (should
  3833. (org-test-with-temp-text "[[https://orgmode.org]]"
  3834. (org-end-of-line)
  3835. (eolp))))
  3836. (ert-deftest test-org/open-line ()
  3837. "Test `org-open-line' specifications."
  3838. ;; Call `open-line' outside of tables.
  3839. (should
  3840. (equal "\nText"
  3841. (org-test-with-temp-text "Text"
  3842. (org-open-line 1)
  3843. (buffer-string))))
  3844. ;; At a table, create a row above.
  3845. (should
  3846. (equal "\n| |\n| a |"
  3847. (org-test-with-temp-text "\n<point>| a |"
  3848. (org-open-line 1)
  3849. (buffer-string))))
  3850. ;; At the very first character of the buffer, also call `open-line'.
  3851. (should
  3852. (equal "\n| a |"
  3853. (org-test-with-temp-text "| a |"
  3854. (org-open-line 1)
  3855. (buffer-string))))
  3856. ;; Narrowing does not count.
  3857. (should
  3858. (equal "Text\n| |\n| a |"
  3859. (org-test-with-temp-text "Text\n<point>| a |"
  3860. (narrow-to-region (point) (point-max))
  3861. (org-open-line 1)
  3862. (widen)
  3863. (buffer-string)))))
  3864. (ert-deftest test-org/forward-sentence ()
  3865. "Test `org-forward-sentence' specifications."
  3866. ;; At the end of a table cell, move to the end of the next one.
  3867. (should
  3868. (org-test-with-temp-text "| a<point> | b |"
  3869. (org-forward-sentence)
  3870. (looking-at " |$")))
  3871. ;; Elsewhere in a cell, move to its end.
  3872. (should
  3873. (org-test-with-temp-text "| a<point>c | b |"
  3874. (org-forward-sentence)
  3875. (looking-at " | b |$")))
  3876. ;; Otherwise, simply call `forward-sentence'.
  3877. (should
  3878. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3879. (org-forward-sentence)
  3880. (looking-at " Sentence 2.")))
  3881. (should
  3882. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3883. (org-forward-sentence)
  3884. (org-forward-sentence)
  3885. (eobp)))
  3886. ;; At the end of an element, jump to the next one, without stopping
  3887. ;; on blank lines in-between.
  3888. (should
  3889. (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
  3890. (org-forward-sentence)
  3891. (eobp)))
  3892. ;; Headlines are considered to be sentences by themselves, even if
  3893. ;; they do not end with a full stop.
  3894. (should
  3895. (equal
  3896. "* Headline"
  3897. (org-test-with-temp-text "* <point>Headline\nSentence."
  3898. (org-forward-sentence)
  3899. (buffer-substring-no-properties (line-beginning-position) (point)))))
  3900. (should
  3901. (org-test-with-temp-text "* Headline<point>\nSentence."
  3902. (org-forward-sentence)
  3903. (eobp)))
  3904. (should
  3905. (org-test-with-temp-text "Sentence.<point>\n\n* Headline\n\nSentence 2."
  3906. (org-forward-sentence)
  3907. (and (org-at-heading-p) (eolp)))))
  3908. (ert-deftest test-org/backward-sentence ()
  3909. "Test `org-backward-sentence' specifications."
  3910. ;; At the beginning of a table cell, move to the beginning of the
  3911. ;; previous one.
  3912. (should
  3913. (org-test-with-temp-text "| a | <point>b |"
  3914. (org-backward-sentence)
  3915. (looking-at "a | b |$")))
  3916. ;; Elsewhere in a cell, move to its beginning.
  3917. (should
  3918. (org-test-with-temp-text "| a | b<point>c |"
  3919. (org-backward-sentence)
  3920. (looking-at "bc |$")))
  3921. ;; Otherwise, simply call `backward-sentence'.
  3922. (should
  3923. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3924. (org-backward-sentence)
  3925. (looking-at "Sentence 2.")))
  3926. (should
  3927. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3928. (org-backward-sentence)
  3929. (org-backward-sentence)
  3930. (bobp)))
  3931. ;; Make sure to hit the beginning of a sentence on the same line as
  3932. ;; an item.
  3933. (should
  3934. (org-test-with-temp-text "- Line 1\n line <point>2."
  3935. (org-backward-sentence)
  3936. (looking-at "Line 1"))))
  3937. (ert-deftest test-org/forward-paragraph ()
  3938. "Test `org-forward-paragraph' specifications."
  3939. ;; At end of buffer, do not return an error.
  3940. (should
  3941. (org-test-with-temp-text "Paragraph"
  3942. (goto-char (point-max))
  3943. (org-forward-paragraph)
  3944. t))
  3945. ;; Standard test.
  3946. (should
  3947. (= 2
  3948. (org-test-with-temp-text "P1\n\nP2"
  3949. (org-forward-paragraph)
  3950. (org-current-line))))
  3951. (should
  3952. (= 2
  3953. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  3954. (org-forward-paragraph)
  3955. (org-current-line))))
  3956. ;; Enter greater elements.
  3957. (should
  3958. (= 2
  3959. (org-test-with-temp-text "#+begin_center\nP1\n#+end_center\nP2"
  3960. (org-forward-paragraph)
  3961. (org-current-line))))
  3962. ;; Do not enter elements with invisible contents.
  3963. (should
  3964. (= 4
  3965. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  3966. (org-cycle)
  3967. (org-forward-paragraph)
  3968. (org-current-line))))
  3969. (should
  3970. (= 6
  3971. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\nP3"
  3972. (org-fold-hide-block-toggle)
  3973. (org-forward-paragraph)
  3974. (org-current-line))))
  3975. ;; On an item or a footnote definition, move past the first element
  3976. ;; inside, if any.
  3977. (should
  3978. (= 2
  3979. (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
  3980. (org-forward-paragraph)
  3981. (org-current-line))))
  3982. (should
  3983. (= 2
  3984. (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
  3985. (org-forward-paragraph)
  3986. (org-current-line))))
  3987. ;; On a table (resp. a property drawer) do not move through table
  3988. ;; rows (resp. node properties).
  3989. (should
  3990. (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
  3991. (org-forward-paragraph)
  3992. (looking-at "Paragraph")))
  3993. (should
  3994. (org-test-with-temp-text
  3995. "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
  3996. (org-forward-paragraph)
  3997. (looking-at "Paragraph")))
  3998. ;; Skip consecutive keywords, clocks and diary S-exps.
  3999. (should
  4000. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n"
  4001. (org-forward-paragraph)
  4002. (eobp)))
  4003. (should
  4004. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n"
  4005. (org-forward-paragraph)
  4006. (eobp)))
  4007. (should
  4008. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n"
  4009. (org-forward-paragraph)
  4010. (eobp)))
  4011. (should-not
  4012. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n"
  4013. (org-forward-paragraph)
  4014. (eobp)))
  4015. (should-not
  4016. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n"
  4017. (org-forward-paragraph)
  4018. (eobp)))
  4019. ;; In a plain list with one item every line, skip the whole list,
  4020. ;; even with point in the middle of the list.
  4021. (should
  4022. (org-test-with-temp-text "- A\n - B\n- C\n"
  4023. (org-forward-paragraph)
  4024. (eobp)))
  4025. (should
  4026. (org-test-with-temp-text "- A\n - <point>B\n- C\n"
  4027. (org-forward-paragraph)
  4028. (eobp)))
  4029. ;; On a comment, verse or source block, stop at "contents"
  4030. ;; boundaries and blank lines.
  4031. (should
  4032. (= 2
  4033. (org-test-with-temp-text "#+begin_src emacs-lisp\nL1\n\nL2\n#+end_src"
  4034. (org-forward-paragraph)
  4035. (org-current-line))))
  4036. (should
  4037. (= 3
  4038. (org-test-with-temp-text "#+begin_verse\n<point>L1\n\nL2\n#+end_verse"
  4039. (org-forward-paragraph)
  4040. (org-current-line))))
  4041. (should
  4042. (= 5
  4043. (org-test-with-temp-text "#+begin_comment\nL1\n\n<point>L2\n#+end_comment"
  4044. (org-forward-paragraph)
  4045. (org-current-line))))
  4046. ;; Being on an affiliated keyword shouldn't make any difference.
  4047. (should
  4048. (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
  4049. (org-forward-paragraph)
  4050. (eobp))))
  4051. (ert-deftest test-org/backward-paragraph ()
  4052. "Test `org-backward-paragraph' specifications."
  4053. ;; Do not error at beginning of buffer.
  4054. (should
  4055. (org-test-with-temp-text "Paragraph"
  4056. (org-backward-paragraph)
  4057. t))
  4058. ;; At blank lines at the very beginning of a buffer, move to
  4059. ;; point-min.
  4060. (should
  4061. (org-test-with-temp-text "\n\n<point>\n\nParagraph"
  4062. (org-backward-paragraph)
  4063. (bobp)))
  4064. ;; Regular test.
  4065. (should
  4066. (= 2
  4067. (org-test-with-temp-text "P1\n\nP2<point>"
  4068. (org-backward-paragraph)
  4069. (org-current-line))))
  4070. (should
  4071. (= 4
  4072. (org-test-with-temp-text "P1\n\nP2\n\nP3<point>"
  4073. (org-backward-paragraph)
  4074. (org-current-line))))
  4075. ;; Try to move on the line above current element.
  4076. (should
  4077. (= 2
  4078. (org-test-with-temp-text "\n\n<point>Paragraph"
  4079. (org-backward-paragraph)
  4080. (org-current-line))))
  4081. ;; Do not leave point in an invisible area.
  4082. (should
  4083. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  4084. (org-cycle)
  4085. (goto-char (point-max))
  4086. (beginning-of-line)
  4087. (org-backward-paragraph)
  4088. (bobp)))
  4089. (should
  4090. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\n"
  4091. (org-fold-hide-block-toggle)
  4092. (goto-char (point-max))
  4093. (org-backward-paragraph)
  4094. (bobp)))
  4095. ;; On the first element in an item or a footnote definition, jump
  4096. ;; before the footnote or the item.
  4097. (should
  4098. (org-test-with-temp-text "- line1<point>"
  4099. (org-backward-paragraph)
  4100. (bobp)))
  4101. (should
  4102. (org-test-with-temp-text "[fn:1] line1n<point>"
  4103. (org-backward-paragraph)
  4104. (bobp)))
  4105. ;; On the second element in an item or a footnote definition, jump
  4106. ;; to item or the definition.
  4107. (should
  4108. (= 2
  4109. (org-test-with-temp-text "- line1\n\n<point> line2"
  4110. (org-backward-paragraph)
  4111. (org-current-line))))
  4112. (should
  4113. (= 2
  4114. (org-test-with-temp-text "[fn:1] line1\n\n<point> line2"
  4115. (org-backward-paragraph)
  4116. (org-current-line))))
  4117. ;; On a table (resp. a property drawer), ignore table rows
  4118. ;; (resp. node properties).
  4119. (should
  4120. (org-test-with-temp-text "| a | b |\n| c | d |\n<point>P1"
  4121. (org-backward-paragraph)
  4122. (bobp)))
  4123. (should
  4124. (= 2
  4125. (org-test-with-temp-text
  4126. "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
  4127. (org-backward-paragraph)
  4128. (org-current-line))))
  4129. ;; In a plain list with one item every line, skip the whole list,
  4130. ;; even with point in the middle of the list.
  4131. (should
  4132. (org-test-with-temp-text "- A\n - B\n- C\n<point>"
  4133. (org-backward-paragraph)
  4134. (bobp)))
  4135. (should
  4136. (org-test-with-temp-text "- A\n - B\n- <point>C\n"
  4137. (org-backward-paragraph)
  4138. (bobp)))
  4139. ;; Skip consecutive keywords, clocks and diary S-exps.
  4140. (should
  4141. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n<point>"
  4142. (org-backward-paragraph)
  4143. (bobp)))
  4144. (should
  4145. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n<point>"
  4146. (org-backward-paragraph)
  4147. (bobp)))
  4148. (should
  4149. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n<point>"
  4150. (org-backward-paragraph)
  4151. (bobp)))
  4152. (should-not
  4153. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n<point>"
  4154. (org-backward-paragraph)
  4155. (bobp)))
  4156. (should-not
  4157. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n<point>"
  4158. (org-backward-paragraph)
  4159. (bobp)))
  4160. ;; On a comment, example, source and verse blocks, stop at blank
  4161. ;; lines.
  4162. (should
  4163. (= 1
  4164. (org-test-with-temp-text
  4165. "#+begin_comment\n<point>L1\n\nL2\n\nL3\n#+end_comment"
  4166. (org-backward-paragraph)
  4167. (org-current-line))))
  4168. (should
  4169. (= 2
  4170. (org-test-with-temp-text
  4171. "#+begin_verse\nL1\n\n<point>L2\n\nL3\n#+end_verse"
  4172. (org-backward-paragraph)
  4173. (org-current-line))))
  4174. (should
  4175. (= 3
  4176. (org-test-with-temp-text
  4177. "#+begin_src emacs-lisp\nL1\n\nL2\n\n<point>L3\n#+end_src"
  4178. (org-backward-paragraph)
  4179. (org-current-line))))
  4180. ;; When called from the opening line itself, however, move to
  4181. ;; beginning of block.
  4182. (should
  4183. (org-test-with-temp-text "#+begin_<point>example\nL1\n#+end_example"
  4184. (org-backward-paragraph)
  4185. (bobp)))
  4186. ;; On an empty heading, move above it.
  4187. (should
  4188. (org-test-with-temp-text "\n* <point>"
  4189. (org-backward-paragraph)
  4190. (bobp)))
  4191. (should
  4192. (org-test-with-temp-text "\n* \n<point>"
  4193. (org-backward-paragraph)
  4194. (bobp))))
  4195. (ert-deftest test-org/forward-element ()
  4196. "Test `org-forward-element' specifications."
  4197. ;; 1. At EOB: should error.
  4198. (org-test-with-temp-text "Some text\n"
  4199. (goto-char (point-max))
  4200. (should-error (org-forward-element)))
  4201. ;; 2. Standard move: expected to ignore blank lines.
  4202. (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
  4203. (org-forward-element)
  4204. (should (looking-at (regexp-quote "Second paragraph."))))
  4205. ;; 3. Headline tests.
  4206. (org-test-with-temp-text "
  4207. * Head 1
  4208. ** Head 1.1
  4209. *** Head 1.1.1
  4210. ** Head 1.2"
  4211. ;; 3.1. At an headline beginning: move to next headline at the
  4212. ;; same level.
  4213. (goto-line 3)
  4214. (org-forward-element)
  4215. (should (looking-at (regexp-quote "** Head 1.2")))
  4216. ;; 3.2. At an headline beginning: move to parent headline if no
  4217. ;; headline at the same level.
  4218. (goto-line 3)
  4219. (org-forward-element)
  4220. (should (looking-at (regexp-quote "** Head 1.2"))))
  4221. ;; 4. Greater element tests.
  4222. (org-test-with-temp-text
  4223. "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
  4224. ;; 4.1. At a greater element: expected to skip contents.
  4225. (org-forward-element)
  4226. (should (looking-at (regexp-quote "Outside.")))
  4227. ;; 4.2. At the end of greater element contents: expected to skip
  4228. ;; to the end of the greater element.
  4229. (goto-line 2)
  4230. (org-forward-element)
  4231. (should (looking-at (regexp-quote "Outside."))))
  4232. ;; 5. List tests.
  4233. (org-test-with-temp-text "
  4234. - item1
  4235. - sub1
  4236. - sub2
  4237. - sub3
  4238. Inner paragraph.
  4239. - item2
  4240. Outside."
  4241. ;; 5.1. At list top point: expected to move to the element after
  4242. ;; the list.
  4243. (goto-line 2)
  4244. (org-forward-element)
  4245. (should (looking-at (regexp-quote "Outside.")))
  4246. ;; 5.2. Special case: at the first line of a sub-list, but not at
  4247. ;; beginning of line, move to next item.
  4248. (goto-line 2)
  4249. (forward-char)
  4250. (org-forward-element)
  4251. (should (looking-at "- item2"))
  4252. (goto-line 4)
  4253. (forward-char)
  4254. (org-forward-element)
  4255. (should (looking-at " - sub2"))
  4256. ;; 5.3 At sub-list beginning: expected to move after the sub-list.
  4257. (goto-line 4)
  4258. (org-forward-element)
  4259. (should (looking-at (regexp-quote " Inner paragraph.")))
  4260. ;; 5.4. At sub-list end: expected to move outside the sub-list.
  4261. (goto-line 8)
  4262. (org-forward-element)
  4263. (should (looking-at (regexp-quote " Inner paragraph.")))
  4264. ;; 5.5. At an item: expected to move to next item, if any.
  4265. (goto-line 6)
  4266. (org-forward-element)
  4267. (should (looking-at " - sub3"))))
  4268. (ert-deftest test-org/backward-element ()
  4269. "Test `org-backward-element' specifications."
  4270. ;; 1. Should error at BOB.
  4271. (org-test-with-temp-text " \nParagraph."
  4272. (should-error (org-backward-element)))
  4273. ;; 2. Should move at BOB when called on the first element in buffer.
  4274. (should
  4275. (org-test-with-temp-text "\n#+TITLE: test"
  4276. (progn (forward-line)
  4277. (org-backward-element)
  4278. (bobp))))
  4279. ;; 3. Not at the beginning of an element: move at its beginning.
  4280. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  4281. (goto-line 3)
  4282. (end-of-line)
  4283. (org-backward-element)
  4284. (should (looking-at (regexp-quote "Paragraph2."))))
  4285. ;; 4. Headline tests.
  4286. (org-test-with-temp-text "
  4287. * Head 1
  4288. ** Head 1.1
  4289. *** Head 1.1.1
  4290. ** Head 1.2"
  4291. ;; 4.1. At an headline beginning: move to previous headline at the
  4292. ;; same level.
  4293. (goto-line 5)
  4294. (org-backward-element)
  4295. (should (looking-at (regexp-quote "** Head 1.1")))
  4296. ;; 4.2. At an headline beginning: move to parent headline if no
  4297. ;; headline at the same level.
  4298. (goto-line 3)
  4299. (org-backward-element)
  4300. (should (looking-at (regexp-quote "* Head 1")))
  4301. ;; 4.3. At the first top-level headline: should error.
  4302. (goto-line 2)
  4303. (should-error (org-backward-element)))
  4304. ;; 5. At beginning of first element inside a greater element:
  4305. ;; expected to move to greater element's beginning.
  4306. (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
  4307. (goto-line 3)
  4308. (org-backward-element)
  4309. (should (looking-at "#\\+BEGIN_CENTER")))
  4310. ;; 6. At the beginning of the first element in a section: should
  4311. ;; move back to headline, if any.
  4312. (should
  4313. (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
  4314. (progn (goto-char (point-max))
  4315. (beginning-of-line)
  4316. (org-backward-element)
  4317. (org-at-heading-p))))
  4318. ;; 7. List tests.
  4319. (org-test-with-temp-text "
  4320. - item1
  4321. - sub1
  4322. - sub2
  4323. - sub3
  4324. Inner paragraph.
  4325. - item2
  4326. Outside."
  4327. ;; 7.1. At beginning of sub-list: expected to move to the
  4328. ;; paragraph before it.
  4329. (goto-line 4)
  4330. (org-backward-element)
  4331. (should (looking-at "item1"))
  4332. ;; 7.2. At an item in a list: expected to move at previous item.
  4333. (goto-line 8)
  4334. (org-backward-element)
  4335. (should (looking-at " - sub2"))
  4336. (goto-line 12)
  4337. (org-backward-element)
  4338. (should (looking-at "- item1"))
  4339. ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
  4340. ;; beginning.
  4341. (goto-line 10)
  4342. (org-backward-element)
  4343. (should (looking-at " - sub1"))
  4344. (goto-line 15)
  4345. (org-backward-element)
  4346. (should (looking-at "- item1"))
  4347. ;; 7.4. At blank-lines before list end: expected to move to top
  4348. ;; item.
  4349. (goto-line 14)
  4350. (org-backward-element)
  4351. (should (looking-at "- item1"))))
  4352. (ert-deftest test-org/up-element ()
  4353. "Test `org-up-element' specifications."
  4354. ;; 1. At BOB or with no surrounding element: should error.
  4355. (org-test-with-temp-text "Paragraph."
  4356. (should-error (org-up-element)))
  4357. (org-test-with-temp-text "* Head1\n* Head2"
  4358. (goto-line 2)
  4359. (should-error (org-up-element)))
  4360. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  4361. (goto-line 3)
  4362. (should-error (org-up-element)))
  4363. ;; 2. At an headline: move to parent headline.
  4364. (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
  4365. (goto-line 3)
  4366. (org-up-element)
  4367. (should (looking-at "\\* Head1")))
  4368. ;; 3. Inside a greater element: move to greater element beginning.
  4369. (org-test-with-temp-text
  4370. "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
  4371. (goto-line 3)
  4372. (org-up-element)
  4373. (should (looking-at "#\\+BEGIN_CENTER")))
  4374. ;; 4. List tests.
  4375. (org-test-with-temp-text "* Top
  4376. - item1
  4377. - sub1
  4378. - sub2
  4379. Paragraph within sub2.
  4380. - item2"
  4381. ;; 4.1. Within an item: move to the item beginning.
  4382. (goto-line 8)
  4383. (org-up-element)
  4384. (should (looking-at " - sub2"))
  4385. ;; 4.2. At an item in a sub-list: move to parent item.
  4386. (goto-line 4)
  4387. (org-up-element)
  4388. (should (looking-at "- item1"))
  4389. ;; 4.3. At an item in top list: move to beginning of whole list.
  4390. (goto-line 10)
  4391. (org-up-element)
  4392. (should (looking-at "- item1"))
  4393. ;; 4.4. Special case. At very top point: should move to parent of
  4394. ;; list.
  4395. (goto-line 2)
  4396. (org-up-element)
  4397. (should (looking-at "\\* Top"))))
  4398. (ert-deftest test-org/down-element ()
  4399. "Test `org-down-element' specifications."
  4400. ;; Error when the element hasn't got a recursive type.
  4401. (org-test-with-temp-text "Paragraph."
  4402. (should-error (org-down-element)))
  4403. ;; Error when the element has no contents
  4404. (org-test-with-temp-text "* Headline"
  4405. (should-error (org-down-element)))
  4406. ;; When at a plain-list, move to first item.
  4407. (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
  4408. (goto-line 2)
  4409. (org-down-element)
  4410. (should (looking-at " - Item 1.1")))
  4411. (org-test-with-temp-text "#+NAME: list\n- Item 1"
  4412. (org-down-element)
  4413. (should (looking-at " Item 1")))
  4414. ;; When at a table, move to first row
  4415. (org-test-with-temp-text "#+NAME: table\n| a | b |"
  4416. (org-down-element)
  4417. (should (looking-at " a | b |")))
  4418. ;; Otherwise, move inside the greater element.
  4419. (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
  4420. (org-down-element)
  4421. (should (looking-at "Paragraph"))))
  4422. (ert-deftest test-org/drag-element-backward ()
  4423. "Test `org-drag-element-backward' specifications."
  4424. ;; Standard test.
  4425. (should
  4426. (equal
  4427. "#+key2: val2\n#+key1: val1\n#+key3: val3"
  4428. (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
  4429. (org-drag-element-backward)
  4430. (buffer-string))))
  4431. (should
  4432. (equal
  4433. "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
  4434. (org-test-with-temp-text
  4435. "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
  4436. (org-drag-element-backward)
  4437. (buffer-string))))
  4438. ;; Preserve blank lines.
  4439. (should
  4440. (equal "Paragraph 2\n\n\nPara1\n\nPara3"
  4441. (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
  4442. (org-drag-element-backward)
  4443. (buffer-string))))
  4444. ;; Preserve column.
  4445. (should
  4446. (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
  4447. (org-drag-element-backward)
  4448. (looking-at-p "2")))
  4449. ;; Error when trying to move first element of buffer.
  4450. (should-error
  4451. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4452. (org-drag-element-backward))
  4453. :type 'user-error)
  4454. ;; Error when trying to swap nested elements.
  4455. (should-error
  4456. (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
  4457. (org-drag-element-backward))
  4458. :type 'user-error)
  4459. ;; Error when trying to swap an headline element and a non-headline
  4460. ;; element.
  4461. (should-error
  4462. (org-test-with-temp-text "Test.\n<point>* Head 1"
  4463. (org-drag-element-backward))
  4464. :type 'error)
  4465. ;; Error when called before first element.
  4466. (should-error
  4467. (org-test-with-temp-text "\n<point>"
  4468. (org-drag-element-backward))
  4469. :type 'user-error)
  4470. ;; Preserve visibility of elements and their contents.
  4471. (should
  4472. (equal '((63 . 82) (26 . 48))
  4473. (let ((org-fold-core-style 'text-properties))
  4474. (org-test-with-temp-text
  4475. "
  4476. #+BEGIN_CENTER
  4477. Text.
  4478. #+END_CENTER
  4479. - item 1
  4480. #+BEGIN_QUOTE
  4481. Text.
  4482. #+END_QUOTE"
  4483. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4484. (search-backward "- item 1")
  4485. (org-drag-element-backward)
  4486. (let (regions)
  4487. (goto-char (point-min))
  4488. (while (< (point) (point-max))
  4489. (let ((region (org-fold-get-region-at-point)))
  4490. (if (not region)
  4491. (goto-char (org-fold-next-folding-state-change))
  4492. (goto-char (cdr region))
  4493. (push region regions))))
  4494. regions)))))
  4495. (should
  4496. (equal '((63 . 82) (26 . 48))
  4497. (let ((org-fold-core-style 'overlays))
  4498. (org-test-with-temp-text
  4499. "
  4500. #+BEGIN_CENTER
  4501. Text.
  4502. #+END_CENTER
  4503. - item 1
  4504. #+BEGIN_QUOTE
  4505. Text.
  4506. #+END_QUOTE"
  4507. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4508. (search-backward "- item 1")
  4509. (org-drag-element-backward)
  4510. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4511. (overlays-in (point-min) (point-max)))))))
  4512. ;; Pathological case: handle call with point in blank lines right
  4513. ;; after a headline.
  4514. (should
  4515. (equal "* H2\n\n* H1\nText\n"
  4516. (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
  4517. (org-drag-element-backward)
  4518. (buffer-string)))))
  4519. (ert-deftest test-org/drag-element-forward ()
  4520. "Test `org-drag-element-forward' specifications."
  4521. ;; 1. Error when trying to move first element of buffer.
  4522. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4523. (goto-line 3)
  4524. (should-error (org-drag-element-forward)))
  4525. ;; 2. Error when trying to swap nested elements.
  4526. (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
  4527. (forward-line)
  4528. (should-error (org-drag-element-forward)))
  4529. ;; 3. Error when trying to swap a non-headline element and an
  4530. ;; headline.
  4531. (org-test-with-temp-text "Test.\n* Head 1"
  4532. (should-error (org-drag-element-forward)))
  4533. ;; 4. Error when called before first element.
  4534. (should-error
  4535. (org-test-with-temp-text "\n"
  4536. (forward-line)
  4537. (org-drag-element-backward))
  4538. :type 'user-error)
  4539. ;; 5. Otherwise, swap elements, preserving column and blank lines
  4540. ;; between elements.
  4541. (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
  4542. (search-forward "graph")
  4543. (org-drag-element-forward)
  4544. (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
  4545. (should (looking-at " 1")))
  4546. ;; 5. Preserve visibility of elements and their contents.
  4547. (let ((org-fold-core-style 'text-properties))
  4548. (org-test-with-temp-text
  4549. "
  4550. #+BEGIN_CENTER
  4551. Text.
  4552. #+END_CENTER
  4553. - item 1
  4554. #+BEGIN_QUOTE
  4555. Text.
  4556. #+END_QUOTE"
  4557. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4558. (search-backward "#+BEGIN_CENTER")
  4559. (org-drag-element-forward)
  4560. (should
  4561. (equal
  4562. '((63 . 82) (26 . 48))
  4563. (let (regions)
  4564. (goto-char (point-min))
  4565. (while (< (point) (point-max))
  4566. (let ((region (org-fold-get-region-at-point)))
  4567. (if (not region)
  4568. (goto-char (org-fold-next-folding-state-change))
  4569. (goto-char (cdr region))
  4570. (push region regions))))
  4571. regions)))))
  4572. (let ((org-fold-core-style 'overlays))
  4573. (org-test-with-temp-text
  4574. "
  4575. #+BEGIN_CENTER
  4576. Text.
  4577. #+END_CENTER
  4578. - item 1
  4579. #+BEGIN_QUOTE
  4580. Text.
  4581. #+END_QUOTE"
  4582. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4583. (search-backward "#+BEGIN_CENTER")
  4584. (org-drag-element-forward)
  4585. (should
  4586. (equal
  4587. '((63 . 82) (26 . 48))
  4588. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4589. (overlays-in (point-min) (point-max))))))))
  4590. (ert-deftest test-org/next-block ()
  4591. "Test `org-next-block' specifications."
  4592. ;; Regular test.
  4593. (should
  4594. (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  4595. (org-next-block 1)
  4596. (looking-at "#\\+BEGIN_CENTER")))
  4597. ;; Ignore case.
  4598. (should
  4599. (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
  4600. (let ((case-fold-search nil))
  4601. (org-next-block 1)
  4602. (looking-at "#\\+begin_center"))))
  4603. ;; Ignore current line.
  4604. (should
  4605. (org-test-with-temp-text
  4606. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
  4607. (org-next-block 1)
  4608. (looking-at "#\\+BEGIN_CENTER")))
  4609. ;; Throw an error when no block is found.
  4610. (should-error
  4611. (org-test-with-temp-text "Paragraph"
  4612. (org-next-block 1)))
  4613. ;; With an argument, skip many blocks at once.
  4614. (should
  4615. (org-test-with-temp-text
  4616. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4617. (org-next-block 2)
  4618. (looking-at "#\\+BEGIN_QUOTE")))
  4619. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4620. (should
  4621. (org-test-with-temp-text
  4622. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4623. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4624. (looking-at "#\\+BEGIN_QUOTE")))
  4625. ;; Optional argument is also case-insensitive.
  4626. (should
  4627. (org-test-with-temp-text
  4628. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
  4629. (let ((case-fold-search nil))
  4630. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4631. (looking-at "#\\+begin_quote")))))
  4632. (ert-deftest test-org/insert-structure-template ()
  4633. "Test `org-insert-structure-template'."
  4634. ;; Test in empty buffer.
  4635. (should
  4636. (string= "#+begin_foo\n#+end_foo\n"
  4637. (org-test-with-temp-text ""
  4638. (org-insert-structure-template "foo")
  4639. (buffer-string))))
  4640. ;; Test with multiple lines in buffer.
  4641. (should
  4642. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4643. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4644. (transient-mark-mode 1)
  4645. (org-mark-element)
  4646. (org-insert-structure-template "foo")
  4647. (buffer-string))))
  4648. ;; Mark only the current line.
  4649. (should
  4650. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4651. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4652. (transient-mark-mode 1)
  4653. (set-mark (point-min))
  4654. (end-of-line)
  4655. (org-insert-structure-template "foo")
  4656. (buffer-string))))
  4657. ;; Middle of paragraph.
  4658. (should
  4659. (string= "p1\n#+begin_foo\np2\n#+end_foo\np3"
  4660. (org-test-with-temp-text "p1\n<point>p2\np3"
  4661. (set-mark (line-beginning-position))
  4662. (end-of-line)
  4663. (activate-mark)
  4664. (org-insert-structure-template "foo")
  4665. (buffer-string))))
  4666. ;; Test with text in buffer, no region, no final newline.
  4667. (should
  4668. (string= "#+begin_foo\nI'm a paragraph.\n#+end_foo\n"
  4669. (org-test-with-temp-text "I'm a paragraph."
  4670. (org-mark-element)
  4671. (org-insert-structure-template "foo")
  4672. (buffer-string))))
  4673. ;; Test with text in buffer and region set.
  4674. (should
  4675. (string= "#+begin_foo\nI'm a paragraph\n\nI'm a second paragrah\n#+end_foo\n"
  4676. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragrah"
  4677. (set-mark (point))
  4678. (goto-char (point-max))
  4679. (org-insert-structure-template "foo")
  4680. (buffer-string))))
  4681. ;; Test with example escaping.
  4682. (should
  4683. (string= "#+begin_example\n,* Heading\n#+end_example\n"
  4684. (org-test-with-temp-text "* Heading"
  4685. (org-mark-element)
  4686. (org-insert-structure-template "example")
  4687. (buffer-string))))
  4688. ;; Test with indentation.
  4689. (should
  4690. (string= " #+begin_foo\n This is a paragraph\n #+end_foo\n"
  4691. (org-test-with-temp-text " This is a paragraph"
  4692. (org-mark-element)
  4693. (org-insert-structure-template "foo")
  4694. (buffer-string))))
  4695. (should
  4696. (string= " #+begin_foo\n Line 1\n Line2\n #+end_foo\n"
  4697. (org-test-with-temp-text " Line 1\n Line2"
  4698. (org-mark-element)
  4699. (org-insert-structure-template "foo")
  4700. (buffer-string))))
  4701. ;; Test point location.
  4702. (should
  4703. (string= "#+begin_foo\n"
  4704. (org-test-with-temp-text ""
  4705. (org-insert-structure-template "foo")
  4706. (buffer-substring (point-min) (point)))))
  4707. (should
  4708. (string= "#+begin_src "
  4709. (org-test-with-temp-text ""
  4710. (org-insert-structure-template "src")
  4711. (buffer-substring (point-min) (point))))))
  4712. (ert-deftest test-org/previous-block ()
  4713. "Test `org-previous-block' specifications."
  4714. ;; Regular test.
  4715. (should
  4716. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
  4717. (org-previous-block 1)
  4718. (looking-at "#\\+BEGIN_CENTER")))
  4719. ;; Ignore case.
  4720. (should
  4721. (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
  4722. (let ((case-fold-search nil))
  4723. (org-previous-block 1)
  4724. (looking-at "#\\+begin_center"))))
  4725. ;; Ignore current line.
  4726. (should
  4727. (org-test-with-temp-text
  4728. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
  4729. (org-previous-block 1)
  4730. (looking-at "#\\+BEGIN_QUOTE")))
  4731. ;; Throw an error when no block is found.
  4732. (should-error
  4733. (org-test-with-temp-text "Paragraph<point>"
  4734. (org-previous-block 1)))
  4735. ;; With an argument, skip many blocks at once.
  4736. (should
  4737. (org-test-with-temp-text
  4738. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4739. (org-previous-block 2)
  4740. (looking-at "#\\+BEGIN_CENTER")))
  4741. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4742. (should
  4743. (org-test-with-temp-text
  4744. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4745. (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4746. (looking-at "#\\+BEGIN_QUOTE")))
  4747. ;; Optional argument is also case-insensitive.
  4748. (should
  4749. (org-test-with-temp-text
  4750. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
  4751. (let ((case-fold-search nil))
  4752. (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4753. (looking-at "#\\+begin_quote")))))
  4754. ;;; Outline structure
  4755. (ert-deftest test-org/demote ()
  4756. "Test `org-demote' specifications."
  4757. ;; Add correct number of stars according to `org-odd-levels-only'.
  4758. (should
  4759. (= 2
  4760. (org-test-with-temp-text "* H"
  4761. (let ((org-odd-levels-only nil)) (org-demote))
  4762. (org-current-level))))
  4763. (should
  4764. (= 3
  4765. (org-test-with-temp-text "* H"
  4766. (let ((org-odd-levels-only t)) (org-demote))
  4767. (org-current-level))))
  4768. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4769. (should
  4770. (org-test-with-temp-text "* H :tag:"
  4771. (let ((org-tags-column 10)
  4772. (org-auto-align-tags t)
  4773. (org-odd-levels-only nil))
  4774. (org-demote))
  4775. (org-move-to-column 10)
  4776. (looking-at-p ":tag:$")))
  4777. (should-not
  4778. (org-test-with-temp-text "* H :tag:"
  4779. (let ((org-tags-column 10)
  4780. (org-auto-align-tags nil)
  4781. (org-odd-levels-only nil))
  4782. (org-demote))
  4783. (org-move-to-column 10)
  4784. (looking-at-p ":tag:$")))
  4785. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4786. ;; info and property drawers accordingly.
  4787. (should
  4788. (= 3
  4789. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4790. (let ((org-odd-levels-only nil)
  4791. (org-adapt-indentation t))
  4792. (org-demote))
  4793. (forward-line)
  4794. (org-get-indentation))))
  4795. (should
  4796. (= 3
  4797. (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4798. (let ((org-odd-levels-only nil)
  4799. (org-adapt-indentation t))
  4800. (org-demote))
  4801. (forward-line)
  4802. (org-get-indentation))))
  4803. (should-not
  4804. (= 3
  4805. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4806. (let ((org-odd-levels-only nil)
  4807. (org-adapt-indentation nil))
  4808. (org-demote))
  4809. (forward-line)
  4810. (org-get-indentation))))
  4811. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4812. ;; section accordingly. Ignore, however, footnote definitions and
  4813. ;; inlinetasks boundaries.
  4814. (should
  4815. (= 3
  4816. (org-test-with-temp-text "* H\n Paragraph"
  4817. (let ((org-odd-levels-only nil)
  4818. (org-adapt-indentation t))
  4819. (org-demote))
  4820. (forward-line)
  4821. (org-get-indentation))))
  4822. (should
  4823. (= 2
  4824. (org-test-with-temp-text "* H\n Paragraph"
  4825. (let ((org-odd-levels-only nil)
  4826. (org-adapt-indentation nil))
  4827. (org-demote))
  4828. (forward-line)
  4829. (org-get-indentation))))
  4830. (should
  4831. (zerop
  4832. (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
  4833. (let ((org-odd-levels-only nil)
  4834. (org-adapt-indentation t))
  4835. (org-demote))
  4836. (goto-char (point-max))
  4837. (org-get-indentation))))
  4838. (should
  4839. (= 3
  4840. (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
  4841. (let ((org-odd-levels-only nil)
  4842. (org-adapt-indentation t))
  4843. (org-demote))
  4844. (goto-char (point-max))
  4845. (org-get-indentation))))
  4846. (when (featurep 'org-inlinetask)
  4847. (should
  4848. (zerop
  4849. (let ((org-inlinetask-min-level 5)
  4850. (org-adapt-indentation t))
  4851. (org-test-with-temp-text "* H\n***** I\n***** END"
  4852. (org-demote)
  4853. (forward-line)
  4854. (org-get-indentation))))))
  4855. (when (featurep 'org-inlinetask)
  4856. (should
  4857. (= 3
  4858. (let ((org-inlinetask-min-level 5)
  4859. (org-adapt-indentation t))
  4860. (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
  4861. (org-demote)
  4862. (forward-line 2)
  4863. (org-get-indentation))))))
  4864. ;; When `org-adapt-indentation' is non-nil, log drawers are
  4865. ;; adjusted.
  4866. (should
  4867. (equal
  4868. "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4869. (org-test-with-temp-text "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4870. (let ((org-odd-levels-only nil)
  4871. (org-adapt-indentation t))
  4872. (org-demote))
  4873. (buffer-string))))
  4874. (should
  4875. (equal
  4876. "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4877. (org-test-with-temp-text "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4878. (let ((org-odd-levels-only nil)
  4879. (org-adapt-indentation 'headline-data))
  4880. (org-demote))
  4881. (buffer-string))))
  4882. (should
  4883. (equal
  4884. "** H\n :LOGBOOK:\n - a\n :END:"
  4885. (org-test-with-temp-text "* H\n:LOGBOOK:\n- a\n:END:"
  4886. (let ((org-odd-levels-only nil)
  4887. (org-adapt-indentation t))
  4888. (org-demote))
  4889. (buffer-string))))
  4890. ;; Ignore contents of source blocks or example blocks when
  4891. ;; indentation should be preserved (through
  4892. ;; `org-src-preserve-indentation' or "-i" flag).
  4893. (should-not
  4894. (zerop
  4895. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4896. (let ((org-adapt-indentation t)
  4897. (org-src-preserve-indentation nil))
  4898. (org-demote))
  4899. (forward-line 2)
  4900. (org-get-indentation))))
  4901. (should
  4902. (zerop
  4903. (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
  4904. (let ((org-adapt-indentation t)
  4905. (org-src-preserve-indentation t))
  4906. (org-demote))
  4907. (forward-line 2)
  4908. (org-get-indentation))))
  4909. (should
  4910. (zerop
  4911. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4912. (let ((org-adapt-indentation t)
  4913. (org-src-preserve-indentation t))
  4914. (org-demote))
  4915. (forward-line 2)
  4916. (org-get-indentation))))
  4917. (should
  4918. (zerop
  4919. (org-test-with-temp-text
  4920. "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
  4921. (let ((org-adapt-indentation t)
  4922. (org-src-preserve-indentation nil))
  4923. (org-demote))
  4924. (forward-line 2)
  4925. (org-get-indentation)))))
  4926. (ert-deftest test-org/promote ()
  4927. "Test `org-promote' specifications."
  4928. ;; Return an error if headline is to be promoted to level 0, unless
  4929. ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
  4930. ;; headline becomes a comment.
  4931. (should-error
  4932. (org-test-with-temp-text "* H"
  4933. (let ((org-allow-promoting-top-level-subtree nil)) (org-promote))))
  4934. (should
  4935. (equal "# H"
  4936. (org-test-with-temp-text "* H"
  4937. (let ((org-allow-promoting-top-level-subtree t)) (org-promote))
  4938. (buffer-string))))
  4939. ;; Remove correct number of stars according to
  4940. ;; `org-odd-levels-only'.
  4941. (should
  4942. (= 2
  4943. (org-test-with-temp-text "*** H"
  4944. (let ((org-odd-levels-only nil)) (org-promote))
  4945. (org-current-level))))
  4946. (should
  4947. (= 1
  4948. (org-test-with-temp-text "*** H"
  4949. (let ((org-odd-levels-only t)) (org-promote))
  4950. (org-current-level))))
  4951. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4952. (should
  4953. (org-test-with-temp-text "** H :tag:"
  4954. (let ((org-tags-column 10)
  4955. (org-auto-align-tags t)
  4956. (org-odd-levels-only nil))
  4957. (org-promote))
  4958. (org-move-to-column 10)
  4959. (looking-at-p ":tag:$")))
  4960. (should-not
  4961. (org-test-with-temp-text "** H :tag:"
  4962. (let ((org-tags-column 10)
  4963. (org-auto-align-tags nil)
  4964. (org-odd-levels-only nil))
  4965. (org-promote))
  4966. (org-move-to-column 10)
  4967. (looking-at-p ":tag:$")))
  4968. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4969. ;; info and property drawers.
  4970. (should
  4971. (= 2
  4972. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4973. (let ((org-odd-levels-only nil)
  4974. (org-adapt-indentation t))
  4975. (org-promote))
  4976. (forward-line)
  4977. (org-get-indentation))))
  4978. (should
  4979. (= 2
  4980. (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4981. (let ((org-odd-levels-only nil)
  4982. (org-adapt-indentation t))
  4983. (org-promote))
  4984. (forward-line)
  4985. (org-get-indentation))))
  4986. (should-not
  4987. (= 2
  4988. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4989. (let ((org-odd-levels-only nil)
  4990. (org-adapt-indentation nil))
  4991. (org-promote))
  4992. (forward-line)
  4993. (org-get-indentation))))
  4994. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4995. ;; section accordingly. Ignore, however, footnote definitions and
  4996. ;; inlinetasks boundaries.
  4997. (should
  4998. (= 2
  4999. (org-test-with-temp-text "** H\n Paragraph"
  5000. (let ((org-odd-levels-only nil)
  5001. (org-adapt-indentation t))
  5002. (org-promote))
  5003. (forward-line)
  5004. (org-get-indentation))))
  5005. (should-not
  5006. (= 2
  5007. (org-test-with-temp-text "** H\n Paragraph"
  5008. (let ((org-odd-levels-only nil)
  5009. (org-adapt-indentation nil))
  5010. (org-promote))
  5011. (forward-line)
  5012. (org-get-indentation))))
  5013. (should
  5014. (= 2
  5015. (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
  5016. (let ((org-odd-levels-only nil)
  5017. (org-adapt-indentation t))
  5018. (org-promote))
  5019. (forward-line)
  5020. (org-get-indentation))))
  5021. (when (featurep 'org-inlinetask)
  5022. (should
  5023. (zerop
  5024. (let ((org-inlinetask-min-level 5)
  5025. (org-adapt-indentation t))
  5026. (org-test-with-temp-text "** H\n***** I\n***** END"
  5027. (org-promote)
  5028. (forward-line)
  5029. (org-get-indentation))))))
  5030. (when (featurep 'org-inlinetask)
  5031. (should
  5032. (= 2
  5033. (let ((org-inlinetask-min-level 5)
  5034. (org-adapt-indentation t))
  5035. (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
  5036. (org-promote)
  5037. (forward-line 2)
  5038. (org-get-indentation))))))
  5039. ;; Give up shifting if it would break document's structure
  5040. ;; otherwise.
  5041. (should
  5042. (= 3
  5043. (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
  5044. (let ((org-odd-levels-only nil)
  5045. (org-adapt-indentation t))
  5046. (org-promote))
  5047. (forward-line)
  5048. (org-get-indentation))))
  5049. (should
  5050. (= 3
  5051. (org-test-with-temp-text "** H\n Paragraph\n * list."
  5052. (let ((org-odd-levels-only nil)
  5053. (org-adapt-indentation t))
  5054. (org-promote))
  5055. (forward-line)
  5056. (org-get-indentation))))
  5057. ;; When `org-adapt-indentation' is non-nil, log drawers are
  5058. ;; adjusted.
  5059. (should
  5060. (equal
  5061. "* H\n :LOGBOOK:\n - a\n :END:\n b"
  5062. (org-test-with-temp-text "** H\n :LOGBOOK:\n - a\n :END:\n b"
  5063. (let ((org-odd-levels-only nil)
  5064. (org-adapt-indentation t))
  5065. (org-promote))
  5066. (buffer-string))))
  5067. (should
  5068. (equal
  5069. "* H\n :LOGBOOK:\n - a\n :END:\n b"
  5070. (org-test-with-temp-text "** H\n :LOGBOOK:\n - a\n :END:\n b"
  5071. (let ((org-odd-levels-only nil)
  5072. (org-adapt-indentation 'headline-data))
  5073. (org-promote))
  5074. (buffer-string))))
  5075. (should
  5076. (equal
  5077. "* H\n:LOGBOOK:\n- a\n:END:"
  5078. (org-test-with-temp-text "** H\n:LOGBOOK:\n- a\n:END:"
  5079. (let ((org-odd-levels-only nil)
  5080. (org-adapt-indentation t))
  5081. (org-promote))
  5082. (buffer-string))))
  5083. (should
  5084. (equal
  5085. "# H\n:LOGBOOK:\n- a\n:END:"
  5086. (org-test-with-temp-text "* H\n:LOGBOOK:\n- a\n:END:"
  5087. (let ((org-odd-levels-only nil)
  5088. (org-allow-promoting-top-level-subtree t)
  5089. (org-adapt-indentation t))
  5090. (org-promote))
  5091. (buffer-string))))
  5092. ;; Ignore contents of source blocks or example blocks when
  5093. ;; indentation should be preserved (through
  5094. ;; `org-src-preserve-indentation' or "-i" flag).
  5095. (should-not
  5096. (zerop
  5097. (org-test-with-temp-text
  5098. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  5099. (let ((org-adapt-indentation t)
  5100. (org-src-preserve-indentation nil)
  5101. (org-odd-levels-only nil))
  5102. (org-promote))
  5103. (forward-line)
  5104. (org-get-indentation))))
  5105. (should
  5106. (zerop
  5107. (org-test-with-temp-text
  5108. "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
  5109. (let ((org-adapt-indentation t)
  5110. (org-src-preserve-indentation t)
  5111. (org-odd-levels-only nil))
  5112. (org-promote))
  5113. (forward-line)
  5114. (org-get-indentation))))
  5115. (should
  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 t)
  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_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
  5129. (let ((org-adapt-indentation t)
  5130. (org-src-preserve-indentation nil)
  5131. (org-odd-levels-only nil))
  5132. (org-promote))
  5133. (forward-line)
  5134. (org-get-indentation)))))
  5135. (ert-deftest test-org/org-get-valid-level ()
  5136. "Test function `org-get-valid-level' specifications."
  5137. (let ((org-odd-levels-only nil))
  5138. (should (equal 1 (org-get-valid-level 0 0)))
  5139. (should (equal 1 (org-get-valid-level 0 1)))
  5140. (should (equal 2 (org-get-valid-level 0 2)))
  5141. (should (equal 3 (org-get-valid-level 0 3)))
  5142. (should (equal 1 (org-get-valid-level 1 0)))
  5143. (should (equal 2 (org-get-valid-level 1 1)))
  5144. (should (equal 23 (org-get-valid-level 1 22)))
  5145. (should (equal 1 (org-get-valid-level 1 -1)))
  5146. (should (equal 1 (org-get-valid-level 2 -1))))
  5147. (let ((org-odd-levels-only t))
  5148. (should (equal 1 (org-get-valid-level 0 0)))
  5149. (should (equal 1 (org-get-valid-level 0 1)))
  5150. (should (equal 3 (org-get-valid-level 0 2)))
  5151. (should (equal 5 (org-get-valid-level 0 3)))
  5152. (should (equal 1 (org-get-valid-level 1 0)))
  5153. (should (equal 3 (org-get-valid-level 1 1)))
  5154. (should (equal 3 (org-get-valid-level 2 1)))
  5155. (should (equal 5 (org-get-valid-level 3 1)))
  5156. (should (equal 5 (org-get-valid-level 4 1)))
  5157. (should (equal 43 (org-get-valid-level 1 21)))
  5158. (should (equal 1 (org-get-valid-level 1 -1)))
  5159. (should (equal 1 (org-get-valid-level 2 -1)))
  5160. (should (equal 1 (org-get-valid-level 3 -1)))
  5161. (should (equal 3 (org-get-valid-level 4 -1)))
  5162. (should (equal 3 (org-get-valid-level 5 -1)))))
  5163. ;;; Planning
  5164. (ert-deftest test-org/at-planning-p ()
  5165. "Test `org-at-planning-p' specifications."
  5166. ;; Regular test.
  5167. (should
  5168. (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
  5169. (org-at-planning-p)))
  5170. (should-not
  5171. (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
  5172. (org-at-planning-p)))
  5173. ;; Correctly find planning attached to inlinetasks.
  5174. (when (featurep 'org-inlinetask)
  5175. (should
  5176. (org-test-with-temp-text
  5177. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
  5178. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  5179. (should-not
  5180. (org-test-with-temp-text
  5181. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  5182. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  5183. (should-not
  5184. (org-test-with-temp-text
  5185. "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  5186. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  5187. (should-not
  5188. (org-test-with-temp-text
  5189. "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
  5190. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
  5191. (ert-deftest test-org/add-planning-info ()
  5192. "Test `org-add-planning-info'."
  5193. ;; Create deadline when `org-adapt-indentation' is non-nil.
  5194. (should
  5195. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5196. (org-test-with-temp-text "* H\nParagraph<point>"
  5197. (let ((org-adapt-indentation t))
  5198. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5199. (replace-regexp-in-string
  5200. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5201. nil nil 1))))
  5202. ;; Create deadline when `org-adapt-indentation' is nil.
  5203. (should
  5204. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  5205. (org-test-with-temp-text "* H\nParagraph<point>"
  5206. (let ((org-adapt-indentation nil))
  5207. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5208. (replace-regexp-in-string
  5209. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5210. nil nil 1))))
  5211. ;; Update deadline when `org-adapt-indentation' is non-nil.
  5212. (should
  5213. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5214. (org-test-with-temp-text "\
  5215. * H
  5216. DEADLINE: <2015-06-24 Wed>
  5217. Paragraph<point>"
  5218. (let ((org-adapt-indentation t))
  5219. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5220. (replace-regexp-in-string
  5221. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5222. nil nil 1))))
  5223. ;; Update deadline when `org-adapt-indentation' is nil.
  5224. (should
  5225. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  5226. (org-test-with-temp-text "\
  5227. * H
  5228. DEADLINE: <2015-06-24 Wed>
  5229. Paragraph<point>"
  5230. (let ((org-adapt-indentation nil))
  5231. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5232. (replace-regexp-in-string
  5233. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5234. nil nil 1))))
  5235. ;; Schedule when `org-adapt-indentation' is non-nil.
  5236. (should
  5237. (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
  5238. (org-test-with-temp-text "* H\nParagraph<point>"
  5239. (let ((org-adapt-indentation t))
  5240. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  5241. (replace-regexp-in-string
  5242. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5243. nil nil 1))))
  5244. ;; Schedule when `org-adapt-indentation' is nil.
  5245. (should
  5246. (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
  5247. (org-test-with-temp-text "* H\nParagraph<point>"
  5248. (let ((org-adapt-indentation nil))
  5249. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  5250. (replace-regexp-in-string
  5251. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5252. nil nil 1))))
  5253. ;; Add deadline when scheduled.
  5254. (should
  5255. (equal "\
  5256. * H
  5257. DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
  5258. Paragraph"
  5259. (org-test-with-temp-text "\
  5260. * H
  5261. SCHEDULED: <2015-06-24 Wed>
  5262. Paragraph<point>"
  5263. (let ((org-adapt-indentation t))
  5264. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5265. (replace-regexp-in-string
  5266. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5267. nil nil 1))))
  5268. ;; Remove middle entry.
  5269. (should
  5270. (equal "\
  5271. * H
  5272. CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
  5273. Paragraph"
  5274. (org-test-with-temp-text "\
  5275. * H
  5276. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  5277. Paragraph<point>"
  5278. (let ((org-adapt-indentation t))
  5279. (org-add-planning-info nil nil 'deadline))
  5280. (replace-regexp-in-string
  5281. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  5282. nil nil 1))))
  5283. ;; Remove last entry and then middle entry (order should not
  5284. ;; matter).
  5285. (should
  5286. (equal "\
  5287. * H
  5288. CLOSED: [2015-06-24]
  5289. Paragraph"
  5290. (org-test-with-temp-text "\
  5291. * H
  5292. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  5293. Paragraph<point>"
  5294. (let ((org-adapt-indentation t))
  5295. (org-add-planning-info nil nil 'scheduled 'deadline))
  5296. (replace-regexp-in-string
  5297. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  5298. nil nil 1))))
  5299. ;; Remove closed when `org-adapt-indentation' is non-nil.
  5300. (should
  5301. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5302. (org-test-with-temp-text "\
  5303. * H
  5304. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  5305. Paragraph<point>"
  5306. (let ((org-adapt-indentation t))
  5307. (org-add-planning-info nil nil 'closed))
  5308. (replace-regexp-in-string
  5309. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5310. nil nil 1))))
  5311. (should
  5312. (equal "* H\n Paragraph"
  5313. (org-test-with-temp-text "\
  5314. * H
  5315. CLOSED: [2015-06-25 Thu]
  5316. Paragraph<point>"
  5317. (let ((org-adapt-indentation t))
  5318. (org-add-planning-info nil nil 'closed))
  5319. (replace-regexp-in-string
  5320. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5321. nil nil 1))))
  5322. ;; Remove closed when `org-adapt-indentation' is nil.
  5323. (should
  5324. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  5325. (org-test-with-temp-text "\
  5326. * H
  5327. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  5328. Paragraph<point>"
  5329. (let ((org-adapt-indentation nil))
  5330. (org-add-planning-info nil nil 'closed))
  5331. (replace-regexp-in-string
  5332. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5333. nil nil 1))))
  5334. (should
  5335. (equal "* H\nParagraph"
  5336. (org-test-with-temp-text "\
  5337. * H
  5338. CLOSED: [2015-06-25 Thu]
  5339. Paragraph<point>"
  5340. (let ((org-adapt-indentation nil))
  5341. (org-add-planning-info nil nil 'closed))
  5342. (replace-regexp-in-string
  5343. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5344. nil nil 1))))
  5345. ;; Remove closed entry and delete empty line.
  5346. (should
  5347. (equal "\
  5348. * H
  5349. Paragraph"
  5350. (org-test-with-temp-text "\
  5351. * H
  5352. CLOSED: [2015-06-24 Wed]
  5353. Paragraph<point>"
  5354. (let ((org-adapt-indentation t))
  5355. (org-add-planning-info nil nil 'closed))
  5356. (replace-regexp-in-string
  5357. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5358. nil nil 1))))
  5359. ;; Remove one entry and update another.
  5360. (should
  5361. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5362. (org-test-with-temp-text "\
  5363. * H
  5364. SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
  5365. Paragraph<point>"
  5366. (let ((org-adapt-indentation t))
  5367. (org-add-planning-info 'deadline "<2015-06-25 Thu>" 'scheduled))
  5368. (replace-regexp-in-string
  5369. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5370. nil nil 1)))))
  5371. (ert-deftest test-org/deadline ()
  5372. "Test `org-deadline' specifications."
  5373. ;; Insert a new value or replace existing one.
  5374. (should
  5375. (equal "* H\nDEADLINE: <2012-03-29>"
  5376. (org-test-with-temp-text "* H"
  5377. (let ((org-adapt-indentation nil)
  5378. (org-last-inserted-timestamp nil))
  5379. (org-deadline nil "<2012-03-29 Tue>"))
  5380. (replace-regexp-in-string
  5381. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5382. nil nil 1))))
  5383. (should
  5384. (equal "* H\nDEADLINE: <2014-03-04>"
  5385. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5386. (let ((org-adapt-indentation nil)
  5387. (org-last-inserted-timestamp nil))
  5388. (org-deadline nil "<2014-03-04 Thu>"))
  5389. (replace-regexp-in-string
  5390. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5391. nil nil 1))))
  5392. ;; Accept delta time, e.g., "+2d".
  5393. (should
  5394. (equal "* H\nDEADLINE: <2015-03-04>"
  5395. (org-test-at-time "2014-03-04"
  5396. (org-test-with-temp-text "* H"
  5397. (let ((org-adapt-indentation nil)
  5398. (org-last-inserted-timestamp nil))
  5399. (org-deadline nil "+1y"))
  5400. (replace-regexp-in-string
  5401. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5402. ;; Preserve repeater.
  5403. (should
  5404. (equal "* H\nDEADLINE: <2012-03-29 +2y>"
  5405. (org-test-with-temp-text "* H"
  5406. (let ((org-adapt-indentation nil)
  5407. (org-last-inserted-timestamp nil))
  5408. (org-deadline nil "<2012-03-29 Tue +2y>"))
  5409. (replace-regexp-in-string
  5410. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5411. ;; Preserve warning period.
  5412. (should
  5413. (equal "* H\nDEADLINE: <2021-07-20 -1d>"
  5414. (org-test-with-temp-text "* H"
  5415. (let ((org-adapt-indentation nil)
  5416. (org-last-inserted-timestamp nil))
  5417. (org-deadline nil "<2021-07-20 Tue -1d>"))
  5418. (replace-regexp-in-string
  5419. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5420. (should
  5421. (equal "* H\nDEADLINE: <2021-07-20 +1m -3d>"
  5422. (org-test-with-temp-text "* H"
  5423. (let ((org-adapt-indentation nil)
  5424. (org-last-inserted-timestamp nil))
  5425. (org-deadline nil "<2021-07-20 Tue +1m -3d>"))
  5426. (replace-regexp-in-string
  5427. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5428. ;; Remove CLOSED keyword, if any.
  5429. (should
  5430. (equal "* H\nDEADLINE: <2012-03-29>"
  5431. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  5432. (let ((org-adapt-indentation nil)
  5433. (org-last-inserted-timestamp nil))
  5434. (org-deadline nil "<2012-03-29 Tue>"))
  5435. (replace-regexp-in-string
  5436. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5437. ;; With C-u argument, remove DEADLINE keyword.
  5438. (should
  5439. (equal "* H\n"
  5440. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5441. (let ((org-adapt-indentation nil)
  5442. (org-last-inserted-timestamp nil))
  5443. (org-deadline '(4)))
  5444. (buffer-string))))
  5445. (should
  5446. (equal "* H"
  5447. (org-test-with-temp-text "* H"
  5448. (let ((org-adapt-indentation nil)
  5449. (org-last-inserted-timestamp nil))
  5450. (org-deadline '(4)))
  5451. (buffer-string))))
  5452. ;; With C-u C-u argument, prompt for a delay cookie.
  5453. (should
  5454. (equal "* H\nDEADLINE: <2012-03-29 -705d>"
  5455. (cl-letf (((symbol-function 'org-read-date)
  5456. (lambda (&rest args)
  5457. (org-time-string-to-time "2014-03-04"))))
  5458. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5459. (let ((org-adapt-indentation nil)
  5460. (org-last-inserted-timestamp nil))
  5461. (org-deadline '(16)))
  5462. (buffer-string)))))
  5463. (should-error
  5464. (cl-letf (((symbol-function 'org-read-date)
  5465. (lambda (&rest args)
  5466. (org-time-string-to-time "2014-03-04"))))
  5467. (org-test-with-temp-text "* H"
  5468. (let ((org-adapt-indentation nil)
  5469. (org-last-inserted-timestamp nil))
  5470. (org-deadline '(16)))
  5471. (buffer-string))))
  5472. ;; When a region is active and
  5473. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5474. ;; same value in all headlines in region.
  5475. (should
  5476. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5477. (org-test-with-temp-text "* H1\n* H2"
  5478. (let ((org-adapt-indentation nil)
  5479. (org-last-inserted-timestamp nil)
  5480. (org-loop-over-headlines-in-active-region t))
  5481. (transient-mark-mode 1)
  5482. (push-mark (point) t t)
  5483. (goto-char (point-max))
  5484. (org-deadline nil "2012-03-29"))
  5485. (replace-regexp-in-string
  5486. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5487. (should-not
  5488. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5489. (org-test-with-temp-text "* H1\n* H2"
  5490. (let ((org-adapt-indentation nil)
  5491. (org-last-inserted-timestamp nil)
  5492. (org-loop-over-headlines-in-active-region nil))
  5493. (transient-mark-mode 1)
  5494. (push-mark (point) t t)
  5495. (goto-char (point-max))
  5496. (org-deadline nil "2012-03-29"))
  5497. (replace-regexp-in-string
  5498. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5499. (ert-deftest test-org/schedule ()
  5500. "Test `org-schedule' specifications."
  5501. ;; Insert a new value or replace existing one.
  5502. (should
  5503. (equal "* H\nSCHEDULED: <2012-03-29>"
  5504. (org-test-with-temp-text "* H"
  5505. (let ((org-adapt-indentation nil)
  5506. (org-last-inserted-timestamp nil))
  5507. (org-schedule nil "<2012-03-29 Tue>"))
  5508. (replace-regexp-in-string
  5509. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5510. nil nil 1))))
  5511. (should
  5512. (equal "* H\nSCHEDULED: <2014-03-04>"
  5513. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5514. (let ((org-adapt-indentation nil)
  5515. (org-last-inserted-timestamp nil))
  5516. (org-schedule nil "<2014-03-04 Thu>"))
  5517. (replace-regexp-in-string
  5518. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5519. nil nil 1))))
  5520. ;; Accept delta time, e.g., "+2d".
  5521. (should
  5522. (equal "* H\nSCHEDULED: <2015-03-04>"
  5523. (org-test-at-time "2014-03-04"
  5524. (org-test-with-temp-text "* H"
  5525. (let ((org-adapt-indentation nil)
  5526. (org-last-inserted-timestamp nil))
  5527. (org-schedule nil "+1y"))
  5528. (replace-regexp-in-string
  5529. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5530. ;; Preserve repeater.
  5531. (should
  5532. (equal "* H\nSCHEDULED: <2012-03-29 +2y>"
  5533. (org-test-with-temp-text "* H"
  5534. (let ((org-adapt-indentation nil)
  5535. (org-last-inserted-timestamp nil))
  5536. (org-schedule nil "<2012-03-29 Tue +2y>"))
  5537. (replace-regexp-in-string
  5538. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5539. ;; Remove CLOSED keyword, if any.
  5540. (should
  5541. (equal "* H\nSCHEDULED: <2012-03-29>"
  5542. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  5543. (let ((org-adapt-indentation nil)
  5544. (org-last-inserted-timestamp nil))
  5545. (org-schedule nil "<2012-03-29 Tue>"))
  5546. (replace-regexp-in-string
  5547. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5548. ;; With C-u argument, remove SCHEDULED keyword.
  5549. (should
  5550. (equal "* H\n"
  5551. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5552. (let ((org-adapt-indentation nil)
  5553. (org-last-inserted-timestamp nil))
  5554. (org-schedule '(4)))
  5555. (buffer-string))))
  5556. (should
  5557. (equal "* H"
  5558. (org-test-with-temp-text "* H"
  5559. (let ((org-adapt-indentation nil)
  5560. (org-last-inserted-timestamp nil))
  5561. (org-schedule '(4)))
  5562. (buffer-string))))
  5563. ;; With C-u C-u argument, prompt for a delay cookie.
  5564. (should
  5565. (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
  5566. (cl-letf (((symbol-function 'org-read-date)
  5567. (lambda (&rest args)
  5568. (org-time-string-to-time "2014-03-04"))))
  5569. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5570. (let ((org-adapt-indentation nil)
  5571. (org-last-inserted-timestamp nil))
  5572. (org-schedule '(16)))
  5573. (buffer-string)))))
  5574. (should-error
  5575. (cl-letf (((symbol-function 'org-read-date)
  5576. (lambda (&rest args)
  5577. (org-time-string-to-time "2014-03-04"))))
  5578. (org-test-with-temp-text "* H"
  5579. (let ((org-adapt-indentation nil)
  5580. (org-last-inserted-timestamp nil))
  5581. (org-schedule '(16)))
  5582. (buffer-string))))
  5583. ;; When a region is active and
  5584. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5585. ;; same value in all headlines in region.
  5586. (should
  5587. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5588. (org-test-with-temp-text "* H1\n* H2"
  5589. (let ((org-adapt-indentation nil)
  5590. (org-last-inserted-timestamp nil)
  5591. (org-loop-over-headlines-in-active-region t))
  5592. (transient-mark-mode 1)
  5593. (push-mark (point) t t)
  5594. (goto-char (point-max))
  5595. (org-schedule nil "2012-03-29"))
  5596. (replace-regexp-in-string
  5597. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5598. (should-not
  5599. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5600. (org-test-with-temp-text "* H1\n* H2"
  5601. (let ((org-adapt-indentation nil)
  5602. (org-last-inserted-timestamp nil)
  5603. (org-loop-over-headlines-in-active-region nil))
  5604. (transient-mark-mode 1)
  5605. (push-mark (point) t t)
  5606. (goto-char (point-max))
  5607. (org-schedule nil "2012-03-29"))
  5608. (replace-regexp-in-string
  5609. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5610. (should
  5611. ;; check if a repeater survives re-scheduling.
  5612. (string-match-p
  5613. "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
  5614. (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
  5615. (let ((org-adapt-indentation nil)
  5616. (org-last-inserted-timestamp nil))
  5617. (org-schedule nil "2017-02-01"))
  5618. (buffer-string)))))
  5619. ;;; Property API
  5620. (ert-deftest test-org/buffer-property-keys ()
  5621. "Test `org-buffer-property-keys' specifications."
  5622. ;; Retrieve properties across siblings.
  5623. (should
  5624. (equal '("A" "B")
  5625. (org-test-with-temp-text "
  5626. * H1
  5627. :PROPERTIES:
  5628. :A: 1
  5629. :END:
  5630. * H2
  5631. :PROPERTIES:
  5632. :B: 1
  5633. :END:"
  5634. (org-buffer-property-keys))))
  5635. ;; Retrieve properties across children.
  5636. (should
  5637. (equal '("A" "B")
  5638. (org-test-with-temp-text "
  5639. * H1
  5640. :PROPERTIES:
  5641. :A: 1
  5642. :END:
  5643. ** H2
  5644. :PROPERTIES:
  5645. :B: 1
  5646. :END:"
  5647. (org-buffer-property-keys))))
  5648. ;; Retrieve muliple properties in the same drawer.
  5649. (should
  5650. (equal '("A" "B")
  5651. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5652. (org-buffer-property-keys))))
  5653. ;; Ignore extension symbol in property name.
  5654. (should
  5655. (equal '("A")
  5656. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5657. (org-buffer-property-keys))))
  5658. ;; Add bare property if xxx_ALL property is there
  5659. (should
  5660. (equal '("A" "B" "B_ALL")
  5661. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B_ALL: foo bar\n:END:"
  5662. (org-buffer-property-keys))))
  5663. ;; Add bare property if xxx_ALL property is there - check dupes
  5664. (should
  5665. (equal '("A" "B" "B_ALL")
  5666. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:B_ALL: foo bar\n:END:"
  5667. (org-buffer-property-keys))))
  5668. ;; Retrieve properties from #+PROPERTY keyword lines
  5669. (should
  5670. (equal '("A" "C")
  5671. (org-test-with-temp-text "#+PROPERTY: C foo\n* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5672. (org-buffer-property-keys))))
  5673. ;; Retrieve properties from #+PROPERTY keyword lines - make sure an _ALL property also
  5674. ;; adds the bare property
  5675. (should
  5676. (equal '("A" "C" "C_ALL")
  5677. (org-test-with-temp-text "#+PROPERTY: C_ALL foo bar\n* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5678. (org-buffer-property-keys))))
  5679. ;; With non-nil COLUMNS, extract property names from columns.
  5680. (should
  5681. (equal '("A" "B")
  5682. (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
  5683. (org-buffer-property-keys nil nil t))))
  5684. (should
  5685. (equal '("A" "B" "COLUMNS")
  5686. (org-test-with-temp-text
  5687. "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
  5688. (org-buffer-property-keys nil nil t))))
  5689. ;; In COLUMNS, ignore title and summary-type.
  5690. (should
  5691. (equal '("A")
  5692. (org-test-with-temp-text "#+COLUMNS: %A(Foo)"
  5693. (org-buffer-property-keys nil nil t))))
  5694. (should
  5695. (equal '("A")
  5696. (org-test-with-temp-text "#+COLUMNS: %A{Foo}"
  5697. (org-buffer-property-keys nil nil t))))
  5698. (should
  5699. (equal '("A")
  5700. (org-test-with-temp-text "#+COLUMNS: %A(Foo){Bar}"
  5701. (org-buffer-property-keys nil nil t)))))
  5702. (ert-deftest test-org/property-values ()
  5703. "Test `org-property-values' specifications."
  5704. ;; Regular test.
  5705. (should
  5706. (equal '("2" "1")
  5707. (org-test-with-temp-text
  5708. "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
  5709. (org-property-values "A"))))
  5710. ;; Ignore empty values.
  5711. (should-not
  5712. (org-test-with-temp-text
  5713. "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
  5714. (org-property-values "A")))
  5715. ;; Take into consideration extended values.
  5716. (should
  5717. (equal '("1 2")
  5718. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5719. (org-property-values "A")))))
  5720. (ert-deftest test-org/set-property ()
  5721. "Test `org-set-property' specifications."
  5722. (should
  5723. (equal
  5724. ":PROPERTIES:\n:TEST: t\n:END:\n"
  5725. (org-test-with-temp-text ""
  5726. (let ((org-property-format "%s %s"))
  5727. (org-set-property "TEST" "t"))
  5728. (buffer-string))))
  5729. (should
  5730. (equal
  5731. "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5732. (org-test-with-temp-text "* H"
  5733. (let ((org-adapt-indentation nil)
  5734. (org-property-format "%s %s"))
  5735. (org-set-property "TEST" "t"))
  5736. (buffer-string)))))
  5737. (ert-deftest test-org/delete-property ()
  5738. "Test `org-delete-property' specifications."
  5739. (should
  5740. (equal
  5741. ""
  5742. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5743. (org-delete-property "TEST")
  5744. (buffer-string))))
  5745. (should
  5746. (equal
  5747. ":PROPERTIES:\n:TEST1: t\n:END:\n"
  5748. (org-test-with-temp-text ":PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5749. (org-delete-property "TEST2")
  5750. (buffer-string))))
  5751. (should
  5752. (equal
  5753. "* H\n"
  5754. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5755. (org-delete-property "TEST")
  5756. (buffer-string))))
  5757. (should
  5758. (equal
  5759. "* H\n:PROPERTIES:\n:TEST1: t\n:END:\n"
  5760. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5761. (org-delete-property "TEST2")
  5762. (buffer-string)))))
  5763. (ert-deftest test-org/delete-property-globally ()
  5764. "Test `org-delete-property-global' specifications."
  5765. (should
  5766. (equal
  5767. ""
  5768. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5769. (org-delete-property-globally "TEST")
  5770. (buffer-string))))
  5771. (should
  5772. (equal
  5773. "* H\n"
  5774. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n* H\n:PROPERTIES:\n:TEST: nil\n:END:"
  5775. (org-delete-property-globally "TEST")
  5776. (buffer-string)))))
  5777. (ert-deftest test-org/find-property ()
  5778. "Test `org-find-property' specifications."
  5779. ;; Regular test.
  5780. (should
  5781. (= 1
  5782. (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
  5783. (org-find-property "prop"))))
  5784. ;; Find properties in top-level property drawer.
  5785. (should
  5786. (= 1
  5787. (org-test-with-temp-text ":PROPERTIES:\n:PROP: value\n:END:"
  5788. (org-find-property "prop"))))
  5789. ;; Ignore false positives.
  5790. (should
  5791. (= 27
  5792. (org-test-with-temp-text
  5793. "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
  5794. (org-find-property "A"))))
  5795. ;; Return first entry found in buffer.
  5796. (should
  5797. (= 1
  5798. (org-test-with-temp-text
  5799. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5800. (org-find-property "A"))))
  5801. ;; Only search visible part of the buffer.
  5802. (should
  5803. (= 31
  5804. (org-test-with-temp-text
  5805. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5806. (org-narrow-to-subtree)
  5807. (org-find-property "A"))))
  5808. ;; With optional argument, only find entries with a specific value.
  5809. (should-not
  5810. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5811. (org-find-property "A" "2")))
  5812. (should
  5813. (= 31
  5814. (org-test-with-temp-text
  5815. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
  5816. (org-find-property "A" "2"))))
  5817. ;; Use "nil" for explicit nil values.
  5818. (should
  5819. (= 31
  5820. (org-test-with-temp-text
  5821. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
  5822. (org-find-property "A" "nil")))))
  5823. (ert-deftest test-org/entry-delete ()
  5824. "Test `org-entry-delete' specifications."
  5825. ;; Regular test.
  5826. (should
  5827. (string-match
  5828. " *:PROPERTIES:\n *:B: +2\n *:END:"
  5829. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5830. (org-entry-delete (point) "A")
  5831. (buffer-string))))
  5832. ;; Also remove accumulated properties.
  5833. (should-not
  5834. (string-match
  5835. ":A"
  5836. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
  5837. (org-entry-delete (point) "A")
  5838. (buffer-string))))
  5839. ;; When last property is removed, remove the property drawer.
  5840. (should-not
  5841. (string-match
  5842. ":PROPERTIES:"
  5843. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
  5844. (org-entry-delete (point) "A")
  5845. (buffer-string))))
  5846. ;; Return a non-nil value when some property was removed.
  5847. (should
  5848. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5849. (org-entry-delete (point) "A")))
  5850. (should-not
  5851. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5852. (org-entry-delete (point) "C")))
  5853. ;; Special properties cannot be located in a drawer. Allow to
  5854. ;; remove them anyway, in case of user error.
  5855. (should
  5856. (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
  5857. (org-entry-delete (point) "SCHEDULED"))))
  5858. (ert-deftest test-org/entry-get ()
  5859. "Test `org-entry-get' specifications."
  5860. ;; Regular test.
  5861. (should
  5862. (equal "1"
  5863. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:"
  5864. (org-entry-get (point) "A"))))
  5865. (should
  5866. (equal "1"
  5867. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5868. (org-entry-get (point) "A"))))
  5869. ;; Ignore case.
  5870. (should
  5871. (equal "1"
  5872. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5873. (org-entry-get (point) "a"))))
  5874. ;; Handle extended values, both before and after base value.
  5875. (should
  5876. (equal "1 2 3"
  5877. (org-test-with-temp-text
  5878. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5879. (org-entry-get (point) "A"))))
  5880. ;; Empty values are returned as the empty string.
  5881. (should
  5882. (equal ""
  5883. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
  5884. (org-entry-get (point) "A"))))
  5885. ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
  5886. ;; otherwise, return nil.
  5887. (should-not
  5888. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5889. (org-entry-get (point) "A")))
  5890. (should
  5891. (equal "nil"
  5892. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5893. (org-entry-get (point) "A" nil t))))
  5894. ;; Return nil when no property is found, independently on the
  5895. ;; LITERAL-NIL argument.
  5896. (should-not
  5897. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5898. (org-entry-get (point) "B")))
  5899. (should-not
  5900. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5901. (org-entry-get (point) "B" nil t)))
  5902. ;; Handle inheritance, when allowed. Include extended values and
  5903. ;; possibly global values.
  5904. (should
  5905. (equal
  5906. "1"
  5907. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:\n* H"
  5908. (org-entry-get (point-max) "A" t))))
  5909. (should
  5910. (equal
  5911. "1"
  5912. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5913. (org-entry-get (point-max) "A" t))))
  5914. (should
  5915. (equal
  5916. "1"
  5917. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5918. (let ((org-use-property-inheritance t))
  5919. (org-entry-get (point-max) "A" 'selective)))))
  5920. (should-not
  5921. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5922. (let ((org-use-property-inheritance nil))
  5923. (org-entry-get (point-max) "A" 'selective))))
  5924. (should-not
  5925. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H2"
  5926. (let ((org-use-property-inheritance t))
  5927. (org-entry-get (point-max) "A" t))))
  5928. (should
  5929. (equal
  5930. "1 2"
  5931. (org-test-with-temp-text
  5932. ":PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5933. (org-entry-get (point-max) "A" t))))
  5934. (should
  5935. (equal
  5936. "1 2"
  5937. (org-test-with-temp-text
  5938. "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5939. (org-entry-get (point-max) "A" t))))
  5940. (should
  5941. (equal
  5942. "1 2"
  5943. (org-test-with-temp-text
  5944. ":PROPERTIES:\n:A: 1\n:END:\n* H1\n* H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5945. (org-entry-get (point-max) "A" t))))
  5946. (should
  5947. (equal
  5948. "1 2"
  5949. (org-test-with-temp-text
  5950. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2.1\n** H2.2\n:PROPERTIES:\n:A+: 2\n:END:"
  5951. (org-entry-get (point-max) "A" t))))
  5952. (should
  5953. (equal "1"
  5954. (org-test-with-temp-text
  5955. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
  5956. (org-mode-restart)
  5957. (org-entry-get (point-max) "A" t))))
  5958. (should
  5959. (equal "0 1"
  5960. (org-test-with-temp-text
  5961. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
  5962. (org-mode-restart)
  5963. (org-entry-get (point-max) "A" t))))
  5964. ;; document level property-drawer has precedance over
  5965. ;; global-property by PROPERTY-keyword.
  5966. (should
  5967. (equal "0 2"
  5968. (org-test-with-temp-text
  5969. ":PROPERTIES:\n:A: 0\n:END:\n#+PROPERTY: A 1\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5970. (org-mode-restart)
  5971. (org-entry-get (point-max) "A" t))))
  5972. ;; Use alternate separators
  5973. (should
  5974. (equal "0~2"
  5975. (org-test-with-temp-text
  5976. ":PROPERTIES:\n:A: 0\n:A+: 2\n:END:"
  5977. (let ((org-property-separators '((("A") . "~"))))
  5978. (org-entry-get (point) "A")))))
  5979. ;; Default separator is single space
  5980. (should
  5981. (equal "0 2"
  5982. (org-test-with-temp-text
  5983. ":PROPERTIES:\n:A: 0\n:B: 1\n:A+: 2\n:B+: 3\n:END:"
  5984. (let ((org-property-separators '((("B") . "~"))))
  5985. (org-entry-get (point) "A")))))
  5986. ;; Regular expression matching for separator
  5987. (should
  5988. (equal "0/2"
  5989. (org-test-with-temp-text
  5990. ":PROPERTIES:\n:A: 0\n:A+: 2\n:END:"
  5991. (let ((org-property-separators '((("B") . "~") ("[AC]" . "/"))))
  5992. (org-entry-get (point) "A")))))
  5993. ;; Separator works with inheritance
  5994. (should
  5995. (equal "1~2"
  5996. (org-test-with-temp-text
  5997. "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5998. (let ((org-property-separators '((("A") . "~"))))
  5999. (org-entry-get (point-max) "A" t))))))
  6000. (ert-deftest test-org/entry-properties ()
  6001. "Test `org-entry-properties' specifications."
  6002. ;; Get "ITEM" property.
  6003. (should
  6004. (equal "H"
  6005. (org-test-with-temp-text "* TODO H"
  6006. (cdr (assoc "ITEM" (org-entry-properties nil "ITEM"))))))
  6007. (should
  6008. (equal "H"
  6009. (org-test-with-temp-text "* TODO H"
  6010. (cdr (assoc "ITEM" (org-entry-properties))))))
  6011. ;; Get "TODO" property. TODO keywords are case sensitive.
  6012. (should
  6013. (equal "TODO"
  6014. (org-test-with-temp-text "* TODO H"
  6015. (cdr (assoc "TODO" (org-entry-properties nil "TODO"))))))
  6016. (should
  6017. (equal "TODO"
  6018. (org-test-with-temp-text "* TODO H"
  6019. (cdr (assoc "TODO" (org-entry-properties))))))
  6020. (should-not
  6021. (org-test-with-temp-text "* H"
  6022. (assoc "TODO" (org-entry-properties nil "TODO"))))
  6023. (should-not
  6024. (org-test-with-temp-text "* todo H"
  6025. (assoc "TODO" (org-entry-properties nil "TODO"))))
  6026. ;; Get "PRIORITY" property.
  6027. (should
  6028. (equal "A"
  6029. (org-test-with-temp-text "* [#A] H"
  6030. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  6031. (should
  6032. (equal "A"
  6033. (org-test-with-temp-text "* [#A] H"
  6034. (cdr (assoc "PRIORITY" (org-entry-properties))))))
  6035. (should
  6036. (equal (char-to-string org-priority-default)
  6037. (org-test-with-temp-text "* H"
  6038. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  6039. ;; Get "FILE" property.
  6040. (should
  6041. (org-test-with-temp-text-in-file "* H\nParagraph"
  6042. (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil "FILE")))
  6043. (buffer-file-name))))
  6044. (should
  6045. (org-test-with-temp-text-in-file "* H\nParagraph"
  6046. (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
  6047. (buffer-file-name))))
  6048. (should-not
  6049. (org-test-with-temp-text "* H\nParagraph"
  6050. (cdr (assoc "FILE" (org-entry-properties nil "FILE")))))
  6051. ;; Get "TAGS" property.
  6052. (should
  6053. (equal ":tag1:tag2:"
  6054. (org-test-with-temp-text "* H :tag1:tag2:"
  6055. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS"))))))
  6056. (should
  6057. (equal ":tag1:tag2:"
  6058. (org-test-with-temp-text "* H :tag1:tag2:"
  6059. (cdr (assoc "TAGS" (org-entry-properties))))))
  6060. (should-not
  6061. (org-test-with-temp-text "* H"
  6062. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS")))))
  6063. ;; Get "ALLTAGS" property.
  6064. (should
  6065. (equal ":tag1:tag2:"
  6066. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  6067. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS"))))))
  6068. (should
  6069. (equal ":tag1:tag2:"
  6070. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  6071. (cdr (assoc "ALLTAGS" (org-entry-properties))))))
  6072. (should-not
  6073. (org-test-with-temp-text "* H"
  6074. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS")))))
  6075. ;; Get "BLOCKED" property.
  6076. (should
  6077. (equal "t"
  6078. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  6079. (let ((org-enforce-todo-dependencies t)
  6080. (org-blocker-hook
  6081. '(org-block-todo-from-children-or-siblings-or-parent)))
  6082. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  6083. (should
  6084. (equal ""
  6085. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  6086. (let ((org-enforce-todo-dependencies t)
  6087. (org-blocker-hook
  6088. '(org-block-todo-from-children-or-siblings-or-parent)))
  6089. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  6090. ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
  6091. (should
  6092. (equal
  6093. "[2012-03-29 thu.]"
  6094. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  6095. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED"))))))
  6096. (should
  6097. (equal
  6098. "[2012-03-29 thu.]"
  6099. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  6100. (cdr (assoc "CLOSED" (org-entry-properties))))))
  6101. (should-not
  6102. (org-test-with-temp-text "* H"
  6103. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED")))))
  6104. (should
  6105. (equal
  6106. "<2014-03-04 tue.>"
  6107. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6108. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE"))))))
  6109. (should
  6110. (equal
  6111. "<2014-03-04 tue.>"
  6112. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6113. (cdr (assoc "DEADLINE" (org-entry-properties))))))
  6114. (should-not
  6115. (org-test-with-temp-text "* H"
  6116. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE")))))
  6117. (should
  6118. (equal
  6119. "<2014-03-04 tue.>"
  6120. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6121. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED"))))))
  6122. (should
  6123. (equal
  6124. "<2014-03-04 tue.>"
  6125. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6126. (cdr (assoc "SCHEDULED" (org-entry-properties))))))
  6127. (should-not
  6128. (org-test-with-temp-text "* H"
  6129. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED")))))
  6130. ;; Get "CATEGORY"
  6131. (should
  6132. (equal "cat"
  6133. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  6134. (cdr (assoc "CATEGORY" (org-entry-properties))))))
  6135. (should
  6136. (equal "cat"
  6137. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  6138. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  6139. (should
  6140. (equal "cat"
  6141. (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
  6142. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  6143. (should
  6144. (equal "cat2"
  6145. (org-test-with-temp-text
  6146. (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6147. "\n"
  6148. "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
  6149. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  6150. ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
  6151. (should
  6152. (equal "<2012-03-29 thu.>"
  6153. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
  6154. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  6155. (should
  6156. (equal "[2012-03-29 thu.]"
  6157. (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
  6158. (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
  6159. (should
  6160. (equal "<2012-03-29 thu.>"
  6161. (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
  6162. (cdr (assoc "TIMESTAMP" (org-entry-properties nil "TIMESTAMP"))))))
  6163. (should
  6164. (equal "[2014-03-04 tue.]"
  6165. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
  6166. (cdr (assoc "TIMESTAMP_IA"
  6167. (org-entry-properties nil "TIMESTAMP_IA"))))))
  6168. (should-not
  6169. (equal "<2012-03-29 thu.>"
  6170. (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
  6171. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  6172. ;; Get standard properties.
  6173. (should
  6174. (equal "1"
  6175. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6176. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  6177. ;; Handle extended properties.
  6178. (should
  6179. (equal "1 2 3"
  6180. (org-test-with-temp-text
  6181. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  6182. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  6183. (should
  6184. (equal "1 2 3"
  6185. (org-test-with-temp-text
  6186. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
  6187. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  6188. ;; Ignore forbidden (special) properties.
  6189. (should-not
  6190. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
  6191. (cdr (assoc "TODO" (org-entry-properties nil 'standard))))))
  6192. (ert-deftest test-org/entry-put ()
  6193. "Test `org-entry-put' specifications."
  6194. ;; Error when not a string or nil.
  6195. (should-error
  6196. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  6197. (org-entry-put 1 "test" 2)))
  6198. ;; Error when property name is invalid.
  6199. (should-error
  6200. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  6201. (org-entry-put 1 "no space" "value")))
  6202. (should-error
  6203. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  6204. (org-entry-put 1 "" "value")))
  6205. ;; Set "TODO" property.
  6206. (should
  6207. (string-match (regexp-quote " TODO H")
  6208. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  6209. (org-entry-put (point) "TODO" "TODO")
  6210. (buffer-string))))
  6211. (should
  6212. (string-match (regexp-quote "* H")
  6213. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  6214. (org-entry-put (point) "TODO" nil)
  6215. (buffer-string))))
  6216. ;; Set "PRIORITY" property.
  6217. (should
  6218. (equal "* [#A] H"
  6219. (org-test-with-temp-text "* [#B] H"
  6220. (org-entry-put (point) "PRIORITY" "A")
  6221. (buffer-string))))
  6222. (should
  6223. (equal "* H"
  6224. (org-test-with-temp-text "* [#B] H"
  6225. (org-entry-put (point) "PRIORITY" nil)
  6226. (buffer-string))))
  6227. ;; Set "SCHEDULED" property.
  6228. (should
  6229. (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
  6230. (org-test-with-temp-text "* H"
  6231. (org-entry-put (point) "SCHEDULED" "2014-03-04")
  6232. (buffer-string))))
  6233. (should
  6234. (string= "* H\n"
  6235. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6236. (org-entry-put (point) "SCHEDULED" nil)
  6237. (buffer-string))))
  6238. (should
  6239. (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
  6240. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6241. (org-entry-put (point) "SCHEDULED" "earlier")
  6242. (buffer-string))))
  6243. (should
  6244. (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
  6245. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6246. (org-entry-put (point) "SCHEDULED" "later")
  6247. (buffer-string))))
  6248. ;; Set "DEADLINE" property.
  6249. (should
  6250. (string-match "^ *DEADLINE: <2014-03-04 .*?>"
  6251. (org-test-with-temp-text "* H"
  6252. (org-entry-put (point) "DEADLINE" "2014-03-04")
  6253. (buffer-string))))
  6254. (should
  6255. (string= "* H\n"
  6256. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6257. (org-entry-put (point) "DEADLINE" nil)
  6258. (buffer-string))))
  6259. (should
  6260. (string-match "^ *DEADLINE: <2014-03-03 .*?>"
  6261. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6262. (org-entry-put (point) "DEADLINE" "earlier")
  6263. (buffer-string))))
  6264. (should
  6265. (string-match "^ *DEADLINE: <2014-03-05 .*?>"
  6266. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6267. (org-entry-put (point) "DEADLINE" "later")
  6268. (buffer-string))))
  6269. ;; Set "CATEGORY" property
  6270. (should
  6271. (string-match "^ *:CATEGORY: cat"
  6272. (org-test-with-temp-text "* H"
  6273. (org-entry-put (point) "CATEGORY" "cat")
  6274. (buffer-string))))
  6275. ;; Regular properties, with or without pre-existing drawer.
  6276. (should
  6277. (string-match "^ *:A: +2$"
  6278. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6279. (org-entry-put (point) "A" "2")
  6280. (buffer-string))))
  6281. (should
  6282. (string-match "^ *:A: +1$"
  6283. (org-test-with-temp-text "* H"
  6284. (org-entry-put (point) "A" "1")
  6285. (buffer-string))))
  6286. ;; Special case: two consecutive headlines.
  6287. (should
  6288. (string-match "\\* A\n *:PROPERTIES:"
  6289. (org-test-with-temp-text "* A\n** B"
  6290. (org-entry-put (point) "A" "1")
  6291. (buffer-string)))))
  6292. (ert-deftest test-org/refresh-properties ()
  6293. "Test `org-refresh-properties' specifications."
  6294. (should
  6295. (equal "1"
  6296. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6297. (org-refresh-properties "A" 'org-test)
  6298. (get-text-property (point) 'org-test))))
  6299. (should-not
  6300. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6301. (org-refresh-properties "B" 'org-test)
  6302. (get-text-property (point) 'org-test)))
  6303. ;; Handle properties only defined with extension syntax, i.e.,
  6304. ;; "PROPERTY+".
  6305. (should
  6306. (equal "1"
  6307. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
  6308. (org-refresh-properties "A" 'org-test)
  6309. (get-text-property (point) 'org-test))))
  6310. ;; When property is inherited, add text property to the whole
  6311. ;; sub-tree.
  6312. (should
  6313. (equal "1"
  6314. (org-test-with-temp-text
  6315. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
  6316. (let ((org-use-property-inheritance t))
  6317. (org-refresh-properties "A" 'org-test))
  6318. (get-text-property (point) 'org-test))))
  6319. ;; When a document level property-drawer is used, those properties
  6320. ;; should work exactly like headline-properties as if at a
  6321. ;; headline-level 0.
  6322. (should
  6323. (equal "1"
  6324. (org-test-with-temp-text
  6325. ":PROPERTIES:\n:A: 1\n:END:\n"
  6326. (org-mode-restart)
  6327. (let ((org-use-property-inheritance t))
  6328. (org-refresh-properties "A" 'org-test))
  6329. (get-text-property (point) 'org-test))))
  6330. (should-not
  6331. (equal "1"
  6332. (org-test-with-temp-text
  6333. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  6334. (org-mode-restart)
  6335. (let ((org-use-property-inheritance nil))
  6336. (org-refresh-properties "A" 'org-test))
  6337. (get-text-property (point) 'org-test))))
  6338. (should
  6339. (equal "1"
  6340. (org-test-with-temp-text
  6341. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  6342. (org-mode-restart)
  6343. (let ((org-use-property-inheritance t))
  6344. (org-refresh-properties "A" 'org-test))
  6345. (get-text-property (point) 'org-test))))
  6346. (should
  6347. (equal "2"
  6348. (org-test-with-temp-text
  6349. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1\n:PROPERTIES:\n:A: 2\n:END:"
  6350. (org-mode-restart)
  6351. (let ((org-use-property-inheritance t))
  6352. (org-refresh-properties "A" 'org-test))
  6353. (get-text-property (point) 'org-test))))
  6354. ;; When property is inherited, use global value across the whole
  6355. ;; buffer. However local values have precedence, as well as the
  6356. ;; document level property-drawer.
  6357. (should-not
  6358. (equal "1"
  6359. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  6360. (org-mode-restart)
  6361. (let ((org-use-property-inheritance nil))
  6362. (org-refresh-properties "A" 'org-test))
  6363. (get-text-property (point) 'org-test))))
  6364. (should
  6365. (equal "1"
  6366. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  6367. (org-mode-restart)
  6368. (let ((org-use-property-inheritance t))
  6369. (org-refresh-properties "A" 'org-test))
  6370. (get-text-property (point) 'org-test))))
  6371. (should
  6372. (equal "2"
  6373. (org-test-with-temp-text
  6374. "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
  6375. (org-mode-restart)
  6376. (let ((org-use-property-inheritance t))
  6377. (org-refresh-properties "A" 'org-test))
  6378. (get-text-property (point) 'org-test))))
  6379. ;; When both keyword-property and document-level property-block is
  6380. ;; defined, the property-block has precedance.
  6381. (should
  6382. (equal "1"
  6383. (org-test-with-temp-text
  6384. ":PROPERTIES:\n:A: 1\n:END:\n#+PROPERTY: A 2\n<point>* H1"
  6385. (org-mode-restart)
  6386. (let ((org-use-property-inheritance t))
  6387. (org-refresh-properties "A" 'org-test))
  6388. (get-text-property (point) 'org-test)))))
  6389. (ert-deftest test-org/refresh-category-properties ()
  6390. "Test `org-refresh-category-properties' specifications"
  6391. (should
  6392. (equal "cat1"
  6393. (org-test-with-temp-text
  6394. ":PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6395. (org-refresh-category-properties)
  6396. (org-get-category))))
  6397. (should
  6398. (equal "cat1"
  6399. (org-test-with-temp-text
  6400. "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6401. (org-refresh-category-properties)
  6402. (org-get-category))))
  6403. ;; Even though property-inheritance is deactivated, category
  6404. ;; property should be inherited. As described in
  6405. ;; `org-use-property-inheritance'.
  6406. (should
  6407. (equal "cat1"
  6408. (org-test-with-temp-text
  6409. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  6410. (org-mode-restart)
  6411. (let ((org-use-property-inheritance nil))
  6412. (org-refresh-category-properties))
  6413. (org-get-category))))
  6414. (should
  6415. (equal "cat1"
  6416. (org-test-with-temp-text
  6417. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  6418. (org-mode-restart)
  6419. (let ((org-use-property-inheritance t))
  6420. (org-refresh-category-properties))
  6421. (org-get-category))))
  6422. (should
  6423. (equal "cat2"
  6424. (org-test-with-temp-text
  6425. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H\n:PROPERTIES:\n:CATEGORY: cat2\n:END:\n"
  6426. (org-mode-restart)
  6427. (let ((org-use-property-inheritance t))
  6428. (org-refresh-category-properties))
  6429. (org-get-category)))))
  6430. ;;; Refile
  6431. (ert-deftest test-org/refile-get-targets ()
  6432. "Test `org-refile-get-targets' specifications."
  6433. ;; :maxlevel includes all headings above specified value.
  6434. (should
  6435. (equal '("H1" "H2" "H3")
  6436. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6437. (let ((org-refile-use-outline-path nil)
  6438. (org-refile-targets `((nil :maxlevel . 3))))
  6439. (mapcar #'car (org-refile-get-targets))))))
  6440. (should
  6441. (equal '("H1" "H2")
  6442. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6443. (let ((org-refile-use-outline-path nil)
  6444. (org-refile-targets `((nil :maxlevel . 2))))
  6445. (mapcar #'car (org-refile-get-targets))))))
  6446. ;; :level limits targets to headlines with the specified level.
  6447. (should
  6448. (equal '("H2")
  6449. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6450. (let ((org-refile-use-outline-path nil)
  6451. (org-refile-targets `((nil :level . 2))))
  6452. (mapcar #'car (org-refile-get-targets))))))
  6453. ;; :tag limits targets to headlines with specified tag.
  6454. (should
  6455. (equal '("H1")
  6456. (org-test-with-temp-text "* H1 :foo:\n** H2\n*** H3 :bar:"
  6457. (let ((org-refile-use-outline-path nil)
  6458. (org-refile-targets `((nil :tag . "foo"))))
  6459. (mapcar #'car (org-refile-get-targets))))))
  6460. ;; :todo limits targets to headlines with specified TODO keyword.
  6461. (should
  6462. (equal '("H2")
  6463. (org-test-with-temp-text "* H1\n** TODO H2\n*** DONE H3"
  6464. (let ((org-refile-use-outline-path nil)
  6465. (org-refile-targets `((nil :todo . "TODO"))))
  6466. (mapcar #'car (org-refile-get-targets))))))
  6467. ;; :regexp filters targets matching provided regexp.
  6468. (should
  6469. (equal '("F2" "F3")
  6470. (org-test-with-temp-text "* H1\n** F2\n*** F3"
  6471. (let ((org-refile-use-outline-path nil)
  6472. (org-refile-targets `((nil :regexp . "F"))))
  6473. (mapcar #'car (org-refile-get-targets))))))
  6474. ;; A nil `org-refile-targets' includes only top level headlines in
  6475. ;; current buffer.
  6476. (should
  6477. (equal '("H1" "H2")
  6478. (org-test-with-temp-text "* H1\n** S1\n* H2"
  6479. (let ((org-refile-use-outline-path nil)
  6480. (org-refile-targets nil))
  6481. (mapcar #'car (org-refile-get-targets))))))
  6482. ;; Return value is the union of the targets according to all the
  6483. ;; defined rules. However, prevent duplicates.
  6484. (should
  6485. (equal '("F2" "F3" "H1")
  6486. (org-test-with-temp-text "* TODO H1\n** F2\n*** F3"
  6487. (let ((org-refile-use-outline-path nil)
  6488. (org-refile-targets `((nil :regexp . "F")
  6489. (nil :todo . "TODO"))))
  6490. (mapcar #'car (org-refile-get-targets))))))
  6491. (should
  6492. (equal '("F2" "F3" "H1")
  6493. (org-test-with-temp-text "* TODO H1\n** TODO F2\n*** F3"
  6494. (let ((org-refile-use-outline-path nil)
  6495. (org-refile-targets `((nil :regexp . "F")
  6496. (nil :todo . "TODO"))))
  6497. (mapcar #'car (org-refile-get-targets))))))
  6498. ;; When `org-refile-use-outline-path' is non-nil, provide targets as
  6499. ;; paths.
  6500. (should
  6501. (equal '("H1" "H1/H2" "H1/H2/H3")
  6502. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6503. (let ((org-refile-use-outline-path t)
  6504. (org-refile-targets `((nil :maxlevel . 3))))
  6505. (mapcar #'car (org-refile-get-targets))))))
  6506. ;; When providing targets as paths, escape forward slashes in
  6507. ;; headings with backslashes.
  6508. (should
  6509. (equal '("H1\\/foo")
  6510. (org-test-with-temp-text "* H1/foo"
  6511. (let ((org-refile-use-outline-path t)
  6512. (org-refile-targets `((nil :maxlevel . 1))))
  6513. (mapcar #'car (org-refile-get-targets))))))
  6514. ;; When `org-refile-use-outline-path' is `file', include file name
  6515. ;; without directory in targets.
  6516. (should
  6517. (org-test-with-temp-text-in-file "* H1"
  6518. (let* ((filename (buffer-file-name))
  6519. (org-refile-use-outline-path 'file)
  6520. (org-refile-targets `(((,filename) :level . 1))))
  6521. (member (file-name-nondirectory filename)
  6522. (mapcar #'car (org-refile-get-targets))))))
  6523. ;; When `org-refile-use-outline-path' is `full-file-path', include
  6524. ;; full file name.
  6525. (should
  6526. (org-test-with-temp-text-in-file "* H1"
  6527. (let* ((filename (file-truename (buffer-file-name)))
  6528. (org-refile-use-outline-path 'full-file-path)
  6529. (org-refile-targets `(((,filename) :level . 1))))
  6530. (member filename (mapcar #'car (org-refile-get-targets))))))
  6531. ;; When `org-refile-use-outline-path' is `buffer-name', include
  6532. ;; buffer name.
  6533. (should
  6534. (org-test-with-temp-text "* H1"
  6535. (let* ((org-refile-use-outline-path 'buffer-name)
  6536. (org-refile-targets `((nil :level . 1))))
  6537. (member (buffer-name) (mapcar #'car (org-refile-get-targets)))))))
  6538. ;;; Sparse trees
  6539. (ert-deftest test-org/match-sparse-tree ()
  6540. "Test `org-match-sparse-tree' specifications."
  6541. ;; Match tags.
  6542. (should-not
  6543. (org-test-with-temp-text "* H\n** H1 :tag:"
  6544. (org-match-sparse-tree nil "tag")
  6545. (search-forward "H1")
  6546. (org-invisible-p2)))
  6547. (should
  6548. (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
  6549. (org-match-sparse-tree nil "tag")
  6550. (search-forward "H2")
  6551. (org-invisible-p2)))
  6552. ;; "-" operator for tags.
  6553. (should-not
  6554. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6555. (org-match-sparse-tree nil "tag1-tag2")
  6556. (search-forward "H1")
  6557. (org-invisible-p2)))
  6558. (should
  6559. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6560. (org-match-sparse-tree nil "tag1-tag2")
  6561. (search-forward "H2")
  6562. (org-invisible-p2)))
  6563. ;; "&" operator for tags.
  6564. (should
  6565. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6566. (org-match-sparse-tree nil "tag1&tag2")
  6567. (search-forward "H1")
  6568. (org-invisible-p2)))
  6569. (should-not
  6570. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6571. (org-match-sparse-tree nil "tag1&tag2")
  6572. (search-forward "H2")
  6573. (org-invisible-p2)))
  6574. ;; "|" operator for tags.
  6575. (should-not
  6576. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6577. (org-match-sparse-tree nil "tag1|tag2")
  6578. (search-forward "H1")
  6579. (org-invisible-p2)))
  6580. (should-not
  6581. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6582. (org-match-sparse-tree nil "tag1|tag2")
  6583. (search-forward "H2")
  6584. (org-invisible-p2)))
  6585. ;; Regexp match on tags.
  6586. (should-not
  6587. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6588. (org-match-sparse-tree nil "{^tag.*}")
  6589. (search-forward "H1")
  6590. (org-invisible-p2)))
  6591. (should
  6592. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6593. (org-match-sparse-tree nil "{^tag.*}")
  6594. (search-forward "H2")
  6595. (org-invisible-p2)))
  6596. ;; Match group tags.
  6597. (should-not
  6598. (org-test-with-temp-text
  6599. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6600. (org-match-sparse-tree nil "work")
  6601. (search-forward "H1")
  6602. (org-invisible-p2)))
  6603. (should-not
  6604. (org-test-with-temp-text
  6605. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6606. (org-match-sparse-tree nil "work")
  6607. (search-forward "H2")
  6608. (org-invisible-p2)))
  6609. ;; Match group tags with hard brackets.
  6610. (should-not
  6611. (org-test-with-temp-text
  6612. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6613. (org-match-sparse-tree nil "work")
  6614. (search-forward "H1")
  6615. (org-invisible-p2)))
  6616. (should-not
  6617. (org-test-with-temp-text
  6618. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6619. (org-match-sparse-tree nil "work")
  6620. (search-forward "H2")
  6621. (org-invisible-p2)))
  6622. ;; Match tags in hierarchies
  6623. (should-not
  6624. (org-test-with-temp-text
  6625. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6626. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6627. #+TAGS: { Lev_3 : Lev_4 }\n
  6628. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6629. (org-match-sparse-tree nil "Lev_1")
  6630. (search-forward "H4")
  6631. (org-invisible-p2)))
  6632. (should-not
  6633. (org-test-with-temp-text
  6634. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6635. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6636. #+TAGS: { Lev_3 : Lev_4 }\n
  6637. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6638. (org-match-sparse-tree nil "Lev_1+Lev_3")
  6639. (search-forward "H4")
  6640. (org-invisible-p2)))
  6641. ;; Match regular expressions in tags
  6642. (should-not
  6643. (org-test-with-temp-text
  6644. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
  6645. (org-match-sparse-tree nil "Lev")
  6646. (search-forward "H1")
  6647. (org-invisible-p2)))
  6648. (should
  6649. (org-test-with-temp-text
  6650. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
  6651. (org-match-sparse-tree nil "Lev")
  6652. (search-forward "H1")
  6653. (org-invisible-p2)))
  6654. ;; Match properties.
  6655. (should
  6656. (org-test-with-temp-text
  6657. "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
  6658. (org-match-sparse-tree nil "A=\"1\"")
  6659. (search-forward "H2")
  6660. (org-invisible-p2)))
  6661. (should-not
  6662. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6663. (org-match-sparse-tree nil "A=\"1\"")
  6664. (search-forward "H2")
  6665. (org-invisible-p2)))
  6666. ;; Case is not significant when matching properties.
  6667. (should-not
  6668. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6669. (org-match-sparse-tree nil "a=\"1\"")
  6670. (search-forward "H2")
  6671. (org-invisible-p2)))
  6672. (should-not
  6673. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
  6674. (org-match-sparse-tree nil "A=\"1\"")
  6675. (search-forward "H2")
  6676. (org-invisible-p2)))
  6677. ;; Match special LEVEL property.
  6678. (should-not
  6679. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6680. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6681. (search-forward "H1")
  6682. (org-invisible-p2)))
  6683. (should
  6684. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6685. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6686. (search-forward "H2")
  6687. (org-invisible-p2)))
  6688. ;; Comparison operators when matching properties.
  6689. (should
  6690. (org-test-with-temp-text
  6691. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6692. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6693. (search-forward "H1")
  6694. (org-invisible-p2)))
  6695. (should-not
  6696. (org-test-with-temp-text
  6697. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6698. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6699. (search-forward "H2")
  6700. (org-invisible-p2)))
  6701. ;; Regexp match on properties values.
  6702. (should-not
  6703. (org-test-with-temp-text
  6704. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6705. (org-match-sparse-tree nil "A={f.*}")
  6706. (search-forward "H1")
  6707. (org-invisible-p2)))
  6708. (should
  6709. (org-test-with-temp-text
  6710. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6711. (org-match-sparse-tree nil "A={f.*}")
  6712. (search-forward "H2")
  6713. (org-invisible-p2)))
  6714. ;; With an optional argument, limit match to TODO entries.
  6715. (should-not
  6716. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6717. (org-match-sparse-tree t "tag")
  6718. (search-forward "H1")
  6719. (org-invisible-p2)))
  6720. (should
  6721. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6722. (org-match-sparse-tree t "tag")
  6723. (search-forward "H2")
  6724. (org-invisible-p2))))
  6725. (ert-deftest test-org/occur ()
  6726. "Test `org-occur' specifications."
  6727. ;; Count number of matches.
  6728. (should
  6729. (= 1
  6730. (org-test-with-temp-text "* H\nA\n* H2"
  6731. (org-occur "A"))))
  6732. (should
  6733. (= 2
  6734. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6735. (org-occur "A"))))
  6736. ;; Test CALLBACK optional argument.
  6737. (should
  6738. (= 0
  6739. (org-test-with-temp-text "* H\nA\n* H2"
  6740. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6741. (should
  6742. (= 1
  6743. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6744. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6745. ;; Case-fold searches according to `org-occur-case-fold-search'.
  6746. (should
  6747. (= 2
  6748. (org-test-with-temp-text "Aa"
  6749. (let ((org-occur-case-fold-search t)) (org-occur "A")))))
  6750. (should
  6751. (= 2
  6752. (org-test-with-temp-text "Aa"
  6753. (let ((org-occur-case-fold-search t)) (org-occur "a")))))
  6754. (should
  6755. (= 1
  6756. (org-test-with-temp-text "Aa"
  6757. (let ((org-occur-case-fold-search nil)) (org-occur "A")))))
  6758. (should
  6759. (= 1
  6760. (org-test-with-temp-text "Aa"
  6761. (let ((org-occur-case-fold-search nil)) (org-occur "a")))))
  6762. (should
  6763. (= 1
  6764. (org-test-with-temp-text "Aa"
  6765. (let ((org-occur-case-fold-search 'smart)) (org-occur "A")))))
  6766. (should
  6767. (= 2
  6768. (org-test-with-temp-text "Aa"
  6769. (let ((org-occur-case-fold-search 'smart)) (org-occur "a"))))))
  6770. ;;; Tags
  6771. (ert-deftest test-org/tag-string-to-alist ()
  6772. "Test `org-tag-string-to-alist' specifications."
  6773. ;; Tag without selection key.
  6774. (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
  6775. ;; Tag with selection key.
  6776. (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t))))
  6777. ;; Tag group.
  6778. (should
  6779. (equal
  6780. (org-tag-string-to-alist "[ group : t1 t2 ]")
  6781. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag))))
  6782. ;; Mutually exclusive tags.
  6783. (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
  6784. '((:startgroup) ("tag1") ("tag2") (:endgroup))))
  6785. (should
  6786. (equal
  6787. (org-tag-string-to-alist "{ group : tag1 tag2 }")
  6788. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))))
  6789. (ert-deftest test-org/tag-alist-to-string ()
  6790. "Test `org-tag-alist-to-string' specifications."
  6791. (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
  6792. (should (equal (org-tag-alist-to-string '(("tag1" . ?t))) "tag1(t)"))
  6793. (should
  6794. (equal
  6795. (org-tag-alist-to-string
  6796. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6797. "[ group : t1 t2 ]"))
  6798. (should
  6799. (equal (org-tag-alist-to-string
  6800. '((:startgroup) ("tag1") ("tag2") (:endgroup)))
  6801. "{ tag1 tag2 }"))
  6802. (should
  6803. (equal
  6804. (org-tag-alist-to-string
  6805. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))
  6806. "{ group : tag1 tag2 }")))
  6807. (ert-deftest test-org/tag-alist-to-groups ()
  6808. "Test `org-tag-alist-to-groups' specifications."
  6809. (should
  6810. (equal (org-tag-alist-to-groups
  6811. '((:startgroup) ("group") (:grouptags) ("t1") ("t2") (:endgroup)))
  6812. '(("group" "t1" "t2"))))
  6813. (should
  6814. (equal
  6815. (org-tag-alist-to-groups
  6816. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6817. '(("group" "t1" "t2"))))
  6818. (should-not
  6819. (org-tag-alist-to-groups
  6820. '((:startgroup) ("group") ("t1") ("t2") (:endgroup)))))
  6821. (ert-deftest test-org/tag-align ()
  6822. "Test tags alignment."
  6823. ;; Test aligning tags with different display width.
  6824. (should
  6825. ;; 12345678901234567890
  6826. (equal "* Test :abc:"
  6827. (org-test-with-temp-text "* Test :abc:"
  6828. (let ((org-tags-column -20)
  6829. (indent-tabs-mode nil))
  6830. (org-fix-tags-on-the-fly))
  6831. (buffer-string))))
  6832. (should
  6833. ;; 12345678901234567890
  6834. (equal "* Test :日本語:"
  6835. (org-test-with-temp-text "* Test :日本語:"
  6836. (let ((org-tags-column -20)
  6837. (indent-tabs-mode nil))
  6838. (org-fix-tags-on-the-fly))
  6839. (buffer-string))))
  6840. ;; Make sure aligning tags do not skip invisible text.
  6841. (should
  6842. (equal "* [[linkx]] :tag:"
  6843. (org-test-with-temp-text "* [[link<point>]] :tag:"
  6844. (let ((org-tags-column 0))
  6845. (org-fix-tags-on-the-fly)
  6846. (insert "x")
  6847. (buffer-string)))))
  6848. ;; Aligning tags preserve position.
  6849. (should
  6850. (= 6 (org-test-with-temp-text "* 345 <point> :tag:"
  6851. (let ((org-tags-column 78)
  6852. (indent-tabs-mode nil))
  6853. (org-fix-tags-on-the-fly))
  6854. (current-column))))
  6855. ;; Aligning all tags in visible buffer.
  6856. (should
  6857. ;; 12345678901234567890
  6858. (equal (concat "* Level 1 :abc:\n"
  6859. "** Level 2 :def:")
  6860. (org-test-with-temp-text (concat "* Level 1 :abc:\n"
  6861. "** Level 2 :def:")
  6862. (let ((org-tags-column -20)
  6863. (indent-tabs-mode nil))
  6864. ;; (org-align-tags :all) must work even when the point
  6865. ;; is at the end of the buffer.
  6866. (goto-char (point-max))
  6867. (org-align-tags :all))
  6868. (buffer-string)))))
  6869. (ert-deftest test-org/get-tags ()
  6870. "Test `org-get-tags' specifications."
  6871. ;; Standard test.
  6872. (should
  6873. (equal '("foo")
  6874. (org-test-with-temp-text "* Test :foo:" (org-get-tags))))
  6875. (should
  6876. (equal '("foo" "bar")
  6877. (org-test-with-temp-text "* Test :foo:bar:" (org-get-tags))))
  6878. ;; Tags for inlinetasks.
  6879. (should
  6880. (equal '("foo" "bar")
  6881. (progn
  6882. (require 'org-inlinetask)
  6883. (org-test-with-temp-text (concat (make-string org-inlinetask-min-level ?*) " Test :foo:bar:")
  6884. (org-get-tags (org-element-at-point))))))
  6885. (should
  6886. (equal '("foo" "bar")
  6887. (progn
  6888. (require 'org-inlinetask)
  6889. (org-test-with-temp-text (concat (make-string org-inlinetask-min-level ?*) " Test :foo:bar:")
  6890. (org-get-tags nil)))))
  6891. ;; Return nil when there is no tag.
  6892. (should-not
  6893. (org-test-with-temp-text "* Test" (org-get-tags)))
  6894. ;; Tags are inherited from parent headlines.
  6895. (should
  6896. (equal '("tag")
  6897. (let ((org-use-tag-inheritance t))
  6898. (org-test-with-temp-text "* H0 :foo:\n* H1 :tag:\n<point>** H2"
  6899. (org-get-tags)))))
  6900. ;; Tags are inherited from `org-file-tags'.
  6901. (should
  6902. (equal '("tag")
  6903. (org-test-with-temp-text "* H1"
  6904. (let ((org-file-tags '("tag"))
  6905. (org-use-tag-inheritance t))
  6906. (org-get-tags)))))
  6907. ;; Only inherited tags have the `inherited' text property.
  6908. (should
  6909. (get-text-property 0 'inherited
  6910. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6911. (let ((org-use-tag-inheritance t))
  6912. (assoc-string "foo" (org-get-tags))))))
  6913. (should-not
  6914. (get-text-property 0 'inherited
  6915. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6916. (let ((org-use-tag-inheritance t))
  6917. (assoc-string "bar" (org-get-tags))))))
  6918. ;; Obey to `org-use-tag-inheritance'.
  6919. (should-not
  6920. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6921. (let ((org-use-tag-inheritance nil))
  6922. (assoc-string "foo" (org-get-tags)))))
  6923. (should-not
  6924. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6925. (let ((org-use-tag-inheritance nil)
  6926. (org-file-tags '("foo")))
  6927. (assoc-string "foo" (org-get-tags)))))
  6928. (should-not
  6929. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6930. (let ((org-use-tag-inheritance '("bar")))
  6931. (assoc-string "foo" (org-get-tags)))))
  6932. (should
  6933. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6934. (let ((org-use-tag-inheritance '("bar")))
  6935. (assoc-string "bar" (org-get-tags)))))
  6936. (should-not
  6937. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6938. (let ((org-use-tag-inheritance "b.*"))
  6939. (assoc-string "foo" (org-get-tags)))))
  6940. (should
  6941. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6942. (let ((org-use-tag-inheritance "b.*"))
  6943. (assoc-string "bar" (org-get-tags)))))
  6944. ;; When optional argument LOCAL is non-nil, ignore tag inheritance.
  6945. (should
  6946. (equal '("baz")
  6947. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6948. (let ((org-use-tag-inheritance t))
  6949. (org-get-tags nil t)))))
  6950. ;; When optional argument POS is non-nil, get tags there instead.
  6951. (should
  6952. (equal '("foo")
  6953. (org-test-with-temp-text "* H1 :foo:\n* <point>H2 :bar:"
  6954. (org-get-tags 1))))
  6955. ;; Make sure tags excluded from inheritance are returned if local
  6956. (should
  6957. (equal '("foo")
  6958. (org-test-with-temp-text "* Test :foo:"
  6959. (let ((org-use-tag-inheritance t)
  6960. (org-tags-exclude-from-inheritance '("foo")))
  6961. (org-get-tags)))))
  6962. ;; Test the collection of tags from #+filetags and parent tags.
  6963. (should
  6964. (equal '("a" "b" "c" "d")
  6965. (org-test-with-temp-text (concat "#+filetags: a\n"
  6966. "* Level 1 :b:\n"
  6967. "** Level 2 :c:\n"
  6968. "*** Level 3 :d:\n"
  6969. "<point>")
  6970. (let ((org-use-tag-inheritance t))
  6971. (org-mode-restart) ;So that `org-file-tags' get populated from #+filetags
  6972. (org-get-tags)))))
  6973. ;; Pathological case: tagged headline with an empty body.
  6974. (should (org-test-with-temp-text "* :tag:" (org-get-tags))))
  6975. (ert-deftest test-org/set-tags ()
  6976. "Test `org-set-tags' specifications."
  6977. ;; Throw an error on invalid data.
  6978. (should-error
  6979. (org-test-with-temp-text "* H"
  6980. (org-set-tags 'foo)))
  6981. ;; `nil', an empty, and a blank string remove all tags.
  6982. (should
  6983. (equal "* H"
  6984. (org-test-with-temp-text "* H :tag1:tag2:"
  6985. (org-set-tags nil)
  6986. (buffer-string))))
  6987. (should
  6988. (equal "* H"
  6989. (org-test-with-temp-text "* H :tag1:tag2:"
  6990. (org-set-tags "")
  6991. (buffer-string))))
  6992. (should
  6993. (equal "* H"
  6994. (org-test-with-temp-text "* H :tag1:tag2:"
  6995. (org-set-tags " ")
  6996. (buffer-string))))
  6997. ;; If there's nothing to remove, just bail out.
  6998. (should
  6999. (equal "* H"
  7000. (org-test-with-temp-text "* H"
  7001. (org-set-tags nil)
  7002. (buffer-string))))
  7003. (should
  7004. (equal "* "
  7005. (org-test-with-temp-text "* "
  7006. (org-set-tags nil)
  7007. (buffer-string))))
  7008. ;; If DATA is a tag string, set current tags to it, even if it means
  7009. ;; replacing old tags.
  7010. (should
  7011. (equal "* H :tag0:"
  7012. (org-test-with-temp-text "* H :tag1:tag2:"
  7013. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  7014. (buffer-string))))
  7015. (should
  7016. (equal "* H :tag0:"
  7017. (org-test-with-temp-text "* H"
  7018. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  7019. (buffer-string))))
  7020. ;; If DATA is a list, set tags to this list, even if it means
  7021. ;; replacing old tags.
  7022. (should
  7023. (equal "* H :tag0:"
  7024. (org-test-with-temp-text "* H :tag1:tag2:"
  7025. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  7026. (buffer-string))))
  7027. (should
  7028. (equal "* H :tag0:"
  7029. (org-test-with-temp-text "* H"
  7030. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  7031. (buffer-string))))
  7032. ;; When set, apply `org-tags-sort-function'.
  7033. (should
  7034. (equal "* H :a:b:"
  7035. (org-test-with-temp-text "* H"
  7036. (let ((org-tags-column 1)
  7037. (org-tags-sort-function #'string<))
  7038. (org-set-tags '("b" "a"))
  7039. (buffer-string)))))
  7040. ;; When new tags are identical to the previous ones, still align.
  7041. (should
  7042. (equal "* H :foo:"
  7043. (org-test-with-temp-text "* H :foo:"
  7044. (let ((org-tags-column 1))
  7045. (org-set-tags '("foo"))
  7046. (buffer-string)))))
  7047. ;; When tags have been changed, run `org-after-tags-change-hook'.
  7048. (should
  7049. (catch :return
  7050. (org-test-with-temp-text "* H :foo:"
  7051. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  7052. (org-set-tags '("bar"))
  7053. nil))))
  7054. (should-not
  7055. (catch :return
  7056. (org-test-with-temp-text "* H :foo:"
  7057. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  7058. (org-set-tags '("foo"))
  7059. nil))))
  7060. ;; Special case: handle empty headlines.
  7061. (should
  7062. (equal "* :tag0:"
  7063. (org-test-with-temp-text "* "
  7064. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  7065. (buffer-string))))
  7066. ;; Modify buffer only when a tag change happens or alignment is
  7067. ;; done.
  7068. (should-not
  7069. (org-test-with-temp-text "* H :foo:"
  7070. (set-buffer-modified-p nil)
  7071. (let ((org-tags-column 1)) (org-set-tags '("foo")))
  7072. (buffer-modified-p)))
  7073. (should
  7074. (org-test-with-temp-text "* H :foo:"
  7075. (set-buffer-modified-p nil)
  7076. (let ((org-tags-column 10)) (org-set-tags '("foo")))
  7077. (buffer-modified-p)))
  7078. (should
  7079. (org-test-with-temp-text "* H :foo:"
  7080. (set-buffer-modified-p nil)
  7081. (let ((org-tags-column 10)) (org-set-tags '("bar")))
  7082. (buffer-modified-p)))
  7083. ;; Pathological case: when setting tags of a folded headline, do not
  7084. ;; let new tags being sucked into invisibility.
  7085. (should-not
  7086. (org-test-with-temp-text "* H1\nContent\n* H2\n\n Other Content"
  7087. ;; Show only headlines
  7088. (org-content)
  7089. ;; Set NEXT tag on current entry
  7090. (org-set-tags ":NEXT:")
  7091. ;; Move point to that NEXT tag
  7092. (search-forward "NEXT") (backward-word)
  7093. ;; And it should be visible (i.e. no overlays)
  7094. (overlays-at (point)))))
  7095. (ert-deftest test-org/set-tags-command ()
  7096. "Test `org-set-tags-command' specifications"
  7097. ;; Set tags at current headline.
  7098. (should
  7099. (equal "* H1 :foo:"
  7100. (org-test-with-temp-text "* H1"
  7101. (cl-letf (((symbol-function 'completing-read-multiple)
  7102. (lambda (&rest args) '("foo"))))
  7103. (let ((org-use-fast-tag-selection nil)
  7104. (org-tags-column 1))
  7105. (org-set-tags-command)))
  7106. (buffer-string))))
  7107. ;; Preserve position when called from the section below.
  7108. (should
  7109. (equal "* H1 :foo:\nContents"
  7110. (org-test-with-temp-text "* H1\n<point>Contents"
  7111. (cl-letf (((symbol-function 'completing-read-multiple)
  7112. (lambda (&rest args) '("foo"))))
  7113. (let ((org-use-fast-tag-selection nil)
  7114. (org-tags-column 1))
  7115. (org-set-tags-command)))
  7116. (buffer-string))))
  7117. (should-not
  7118. (equal "* H1 :foo:\nContents2"
  7119. (org-test-with-temp-text "* H1\n<point>Contents2"
  7120. (cl-letf (((symbol-function 'completing-read-multiple)
  7121. (lambda (&rest args) '("foo"))))
  7122. (let ((org-use-fast-tag-selection nil)
  7123. (org-tags-column 1))
  7124. (org-set-tags-command)))
  7125. (org-at-heading-p))))
  7126. ;; When a region is active and
  7127. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  7128. ;; same value in all headlines in region.
  7129. (should
  7130. (equal "* H1 :foo:\nContents\n* H2 :foo:"
  7131. (org-test-with-temp-text "* H1\nContents\n* H2"
  7132. (cl-letf (((symbol-function 'completing-read-multiple)
  7133. (lambda (&rest args) '("foo"))))
  7134. (let ((org-use-fast-tag-selection nil)
  7135. (org-loop-over-headlines-in-active-region t)
  7136. (org-tags-column 1))
  7137. (transient-mark-mode 1)
  7138. (push-mark (point) t t)
  7139. (goto-char (point-max))
  7140. (org-set-tags-command)))
  7141. (buffer-string))))
  7142. (should
  7143. (equal "* H1\nContents\n* H2 :foo:"
  7144. (org-test-with-temp-text "* H1\nContents\n* H2"
  7145. (cl-letf (((symbol-function 'completing-read-multiple)
  7146. (lambda (&rest args) '("foo"))))
  7147. (let ((org-use-fast-tag-selection nil)
  7148. (org-loop-over-headlines-in-active-region nil)
  7149. (org-tags-column 1))
  7150. (transient-mark-mode 1)
  7151. (push-mark (point) t t)
  7152. (goto-char (point-max))
  7153. (org-set-tags-command)))
  7154. (buffer-string))))
  7155. ;; With a C-u prefix argument, align all tags in the buffer.
  7156. (should
  7157. (equal "* H1 :foo:\n* H2 :bar:"
  7158. (org-test-with-temp-text "* H1 :foo:\n* H2 :bar:"
  7159. (let ((org-tags-column 1)) (org-set-tags-command '(4)))
  7160. (buffer-string))))
  7161. ;; Point does not move with empty headline.
  7162. (should
  7163. (equal ":foo:"
  7164. (org-test-with-temp-text "* <point>"
  7165. (cl-letf (((symbol-function 'completing-read-multiple)
  7166. (lambda (&rest args) '("foo"))))
  7167. (let ((org-use-fast-tag-selection nil)
  7168. (org-tags-column 1))
  7169. (org-set-tags-command)))
  7170. (buffer-substring (point) (line-end-position)))))
  7171. ;; Point does not move at start of line.
  7172. (should
  7173. (equal "* H1 :foo:"
  7174. (org-test-with-temp-text "* H1"
  7175. (cl-letf (((symbol-function 'completing-read-multiple)
  7176. (lambda (&rest args) '("foo"))))
  7177. (let ((org-use-fast-tag-selection nil)
  7178. (org-tags-column 1))
  7179. (org-set-tags-command)))
  7180. (buffer-substring (point) (line-end-position)))))
  7181. ;; Point does not move when within *'s.
  7182. (should
  7183. (equal "* H1 :foo:"
  7184. (org-test-with-temp-text "*<point>* H1"
  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 workaround does not get fooled when looking at a space.
  7192. (should
  7193. (equal " b :foo:"
  7194. (org-test-with-temp-text "* a<point> b"
  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. ;; Handle tags both set locally and inherited.
  7202. (should
  7203. (equal "b :foo:"
  7204. (org-test-with-temp-text "* a :foo:\n** <point>b :foo:"
  7205. (cl-letf (((symbol-function 'completing-read-multiple)
  7206. (lambda (prompt coll &optional pred req initial &rest args)
  7207. (list initial))))
  7208. (let ((org-use-fast-tag-selection nil)
  7209. (org-tags-column 1))
  7210. (org-set-tags-command)))
  7211. (buffer-substring (point) (line-end-position))))))
  7212. (ert-deftest test-org/toggle-tag ()
  7213. "Test `org-toggle-tag' specifications."
  7214. ;; Insert missing tag.
  7215. (should
  7216. (equal "* H :tag:"
  7217. (org-test-with-temp-text "* H"
  7218. (let ((org-tags-column 1)) (org-toggle-tag "tag"))
  7219. (buffer-string))))
  7220. (should
  7221. (equal "* H :tag1:tag2:"
  7222. (org-test-with-temp-text "* H :tag1:"
  7223. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  7224. (buffer-string))))
  7225. ;; Remove existing tag.
  7226. (should
  7227. (equal "* H"
  7228. (org-test-with-temp-text "* H :tag:"
  7229. (org-toggle-tag "tag")
  7230. (buffer-string))))
  7231. (should
  7232. (equal "* H :tag1:"
  7233. (org-test-with-temp-text "* H :tag1:tag2:"
  7234. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  7235. (buffer-string))))
  7236. (should
  7237. (equal "* H :tag2:"
  7238. (org-test-with-temp-text "* H :tag1:tag2:"
  7239. (let ((org-tags-column 1)) (org-toggle-tag "tag1"))
  7240. (buffer-string))))
  7241. ;; With optional argument ONOFF set to `on', try to insert the tag,
  7242. ;; even if its already there.
  7243. (should
  7244. (equal "* H :tag:"
  7245. (org-test-with-temp-text "* H"
  7246. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  7247. (buffer-string))))
  7248. (should
  7249. (equal "* H :tag:"
  7250. (org-test-with-temp-text "* H :tag:"
  7251. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  7252. (buffer-string))))
  7253. ;; With optional argument ONOFF set to `off', try to remove the tag,
  7254. ;; even if its not there.
  7255. (should
  7256. (equal "* H"
  7257. (org-test-with-temp-text "* H :tag:"
  7258. (org-toggle-tag "tag" 'off)
  7259. (buffer-string))))
  7260. (should
  7261. (equal "* H :tag:"
  7262. (org-test-with-temp-text "* H :tag:"
  7263. (let ((org-tags-column 1)) (org-toggle-tag "foo" 'off))
  7264. (buffer-string))))
  7265. ;; Special case: Handle properly tag inheritance. In particular, do
  7266. ;; not set inherited tags.
  7267. (should
  7268. (equal "* H1 :tag:\n** H2 :tag2:tag:"
  7269. (org-test-with-temp-text "* H1 :tag:\n** <point>H2 :tag2:"
  7270. (let ((org-use-tag-inheritance t)
  7271. (org-tags-column 1))
  7272. (org-toggle-tag "tag"))
  7273. (buffer-string))))
  7274. (should
  7275. (equal "* H1 :tag1:tag2:\n** H2 :foo:"
  7276. (org-test-with-temp-text "* H1 :tag1:tag2:\n** <point>H2"
  7277. (let ((org-use-tag-inheritance t)
  7278. (org-tags-column 1))
  7279. (org-toggle-tag "foo"))
  7280. (buffer-string)))))
  7281. (ert-deftest test-org/tags-expand ()
  7282. "Test `org-tags-expand' specifications."
  7283. ;; Expand tag groups as a regexp enclosed within curly brackets.
  7284. (should
  7285. (equal "{\\<[ABC]\\>}"
  7286. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7287. (org-mode-restart)
  7288. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  7289. (should
  7290. (equal "{\\<\\(?:Aa\\|Bb\\|Cc\\)\\>}"
  7291. (org-test-with-temp-text "#+TAGS: [ Aa : Bb Cc ]"
  7292. (org-mode-restart)
  7293. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "Aa")))))
  7294. ;; Preserve operator before the regexp.
  7295. (should
  7296. (equal "+{\\<[ABC]\\>}"
  7297. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7298. (org-mode-restart)
  7299. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "+A")))))
  7300. (should
  7301. (equal "-{\\<[ABC]\\>}"
  7302. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7303. (org-mode-restart)
  7304. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "-A")))))
  7305. ;; Handle "|" syntax.
  7306. (should
  7307. (equal "{\\<[ABC]\\>}|D"
  7308. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7309. (org-mode-restart)
  7310. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|D")))))
  7311. ;; Handle nested groups.
  7312. (should
  7313. (equal "{\\<[A-D]\\>}"
  7314. (org-test-with-temp-text "#+TAGS: [ A : B C ]\n#+TAGS: [ B : D ]"
  7315. (org-mode-restart)
  7316. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  7317. ;; Expand multiple occurrences of the same group.
  7318. (should
  7319. (equal "{\\<[ABC]\\>}|{\\<[ABC]\\>}"
  7320. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7321. (org-mode-restart)
  7322. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|A")))))
  7323. ;; Preserve regexp matches.
  7324. (should
  7325. (equal "{A+}"
  7326. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7327. (org-mode-restart)
  7328. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "{A+}"))))))
  7329. ;;; TODO keywords
  7330. (ert-deftest test-org/auto-repeat-maybe ()
  7331. "Test `org-auto-repeat-maybe' specifications."
  7332. ;; Do not auto repeat when there is no valid time stamp with
  7333. ;; a repeater in the entry.
  7334. (should-not
  7335. (string-prefix-p
  7336. "* TODO H"
  7337. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7338. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
  7339. (org-todo "DONE")
  7340. (buffer-string)))))
  7341. (should-not
  7342. (string-prefix-p
  7343. "* TODO H"
  7344. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7345. (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
  7346. (org-todo "DONE")
  7347. (buffer-string)))))
  7348. ;; When switching to DONE state, switch back to first TODO keyword
  7349. ;; in sequence, or the same keyword if they have different types.
  7350. (should
  7351. (string-prefix-p
  7352. "* TODO H"
  7353. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7354. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7355. (org-todo "DONE")
  7356. (buffer-string)))))
  7357. (should
  7358. (string-prefix-p
  7359. "* KWD1 H"
  7360. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  7361. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  7362. (org-todo "DONE")
  7363. (buffer-string)))))
  7364. (should
  7365. (string-prefix-p
  7366. "* KWD2 H"
  7367. (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
  7368. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  7369. (org-todo "DONE")
  7370. (buffer-string)))))
  7371. ;; If there was no TODO keyword in the first place, do not insert
  7372. ;; any either.
  7373. (should
  7374. (string-prefix-p
  7375. "* H"
  7376. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7377. (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
  7378. (org-todo "DONE")
  7379. (buffer-string)))))
  7380. ;; Revert to REPEAT_TO_STATE, if set.
  7381. (should
  7382. (string-prefix-p
  7383. "* KWD2 H"
  7384. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  7385. (org-test-with-temp-text
  7386. "* KWD2 H
  7387. :PROPERTIES:
  7388. :REPEAT_TO_STATE: KWD2
  7389. :END:
  7390. <2012-03-29 Thu +2y>"
  7391. (org-todo "DONE")
  7392. (buffer-string)))))
  7393. ;; When switching to DONE state, update base date. If there are
  7394. ;; multiple repeated time stamps, update them all.
  7395. (should
  7396. (string-match-p
  7397. "<2014-03-29 .* \\+2y>"
  7398. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7399. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7400. (org-todo "DONE")
  7401. (buffer-string)))))
  7402. (should
  7403. (string-match-p
  7404. "<2015-03-04 .* \\+1y>"
  7405. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7406. (org-test-with-temp-text
  7407. "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
  7408. (org-todo "DONE")
  7409. (buffer-string)))))
  7410. ;; Throw an error if repeater unit is the hour and no time is
  7411. ;; provided in the time-stamp.
  7412. (should-error
  7413. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7414. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
  7415. (org-todo "DONE")
  7416. (buffer-string))))
  7417. ;; Handle every repeater type using hours step.
  7418. (should
  7419. (string-match-p
  7420. "2014-03-04 .* 02:00"
  7421. (org-test-at-time "<2014-03-04 02:35>"
  7422. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 +8h>"
  7423. (org-todo "DONE")
  7424. (buffer-string)))))
  7425. (should
  7426. (string-match-p
  7427. "2014-03-04 .* 10:00"
  7428. (org-test-at-time "<2014-03-04 02:35>"
  7429. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 ++8h>"
  7430. (org-todo "DONE")
  7431. (buffer-string)))))
  7432. (should
  7433. (string-match-p
  7434. "2014-03-04 .* 10:35"
  7435. (org-test-at-time "<2014-03-04 02:35>"
  7436. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 .+8h>"
  7437. (org-todo "DONE")
  7438. (buffer-string)))))
  7439. ;; Do not repeat inactive time stamps with a repeater.
  7440. (should-not
  7441. (string-match-p
  7442. "\\[2014-03-29 .* \\+2y\\]"
  7443. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7444. (org-test-with-temp-text
  7445. "* TODO H\n[2012-03-29 Thu. +2y]"
  7446. (org-todo "DONE")
  7447. (buffer-string)))))
  7448. ;; Do not repeat commented time stamps.
  7449. (should-not
  7450. (string-prefix-p
  7451. "<2015-03-04 .* \\+1y>"
  7452. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7453. (org-test-with-temp-text
  7454. "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
  7455. (org-todo "DONE")
  7456. (buffer-string)))))
  7457. (should-not
  7458. (string-prefix-p
  7459. "<2015-03-04 .* \\+1y>"
  7460. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7461. (org-test-with-temp-text
  7462. "* TODO H
  7463. <2012-03-29 Thu. +2y>
  7464. #+BEGIN_EXAMPLE
  7465. <2014-03-04 Tue +1y>
  7466. #+END_EXAMPLE"
  7467. (org-todo "DONE")
  7468. (buffer-string)))))
  7469. ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
  7470. ;; entry, record time of last repeat.
  7471. (should-not
  7472. (string-match-p
  7473. ":LAST_REPEAT:"
  7474. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  7475. (org-log-repeat nil))
  7476. (cl-letf (((symbol-function 'org-add-log-setup)
  7477. (lambda (&rest args) nil)))
  7478. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  7479. (org-todo "DONE")
  7480. (buffer-string))))))
  7481. (should
  7482. (string-match-p
  7483. ":LAST_REPEAT:"
  7484. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  7485. (org-log-repeat t))
  7486. (cl-letf (((symbol-function 'org-add-log-setup)
  7487. (lambda (&rest args) nil)))
  7488. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  7489. (org-todo "DONE")
  7490. (buffer-string))))))
  7491. (should
  7492. (string-match-p
  7493. ":LAST_REPEAT:"
  7494. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7495. (cl-letf (((symbol-function 'org-add-log-setup)
  7496. (lambda (&rest args) nil)))
  7497. (org-test-with-temp-text
  7498. "* TODO H\n<2012-03-29 Thu +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
  7499. (org-todo "DONE")
  7500. (buffer-string))))))
  7501. ;; When a SCHEDULED entry has no repeater, remove it upon repeating
  7502. ;; the entry as it is no longer relevant.
  7503. (should-not
  7504. (string-match-p
  7505. "^SCHEDULED:"
  7506. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7507. (org-test-with-temp-text
  7508. "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
  7509. (org-todo "DONE")
  7510. (buffer-string)))))
  7511. ;; Properly advance repeater even when a clock entry is specified
  7512. ;; and `org-log-repeat' is nil.
  7513. (should
  7514. (string-match-p
  7515. "SCHEDULED: <2014-03-29"
  7516. (let ((org-log-repeat nil)
  7517. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7518. (org-test-with-temp-text
  7519. "* TODO H
  7520. SCHEDULED: <2012-03-29 Thu +2y>
  7521. CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] => 6:40"
  7522. (org-todo "DONE")
  7523. (buffer-string)))))
  7524. ;; Make sure that logbook state change record does not get
  7525. ;; duplicated when `org-log-repeat' `org-log-done' are non-nil.
  7526. (should
  7527. (string-match-p
  7528. (rx "* TODO Read book
  7529. SCHEDULED: <2021-06-16 " (1+ (not space)) " +1d>
  7530. :PROPERTIES:
  7531. :LAST_REPEAT:" (1+ nonl) "
  7532. :END:
  7533. - State \"DONE\" from \"TODO\"" (1+ nonl) buffer-end)
  7534. (let ((org-log-repeat 'time)
  7535. (org-todo-keywords '((sequence "TODO" "|" "DONE(d!)")))
  7536. (org-log-into-drawer nil))
  7537. (org-test-with-temp-text
  7538. "* TODO Read book
  7539. SCHEDULED: <2021-06-15 Tue +1d>"
  7540. (org-todo "DONE")
  7541. (when (memq 'org-add-log-note post-command-hook)
  7542. (org-add-log-note))
  7543. (buffer-string))))))
  7544. (ert-deftest test-org/org-log-done ()
  7545. "Test `org-log-done' specifications."
  7546. ;; nil value.
  7547. (should
  7548. (string=
  7549. "* DONE task"
  7550. (let ((org-log-done nil)
  7551. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7552. (org-test-with-temp-text
  7553. "* TODO task"
  7554. (org-todo "DONE")
  7555. (when (memq 'org-add-log-note post-command-hook)
  7556. (org-add-log-note))
  7557. (buffer-string)))))
  7558. ;; `time' value.
  7559. (should
  7560. (string=
  7561. (format
  7562. "* DONE task
  7563. CLOSED: %s"
  7564. (org-test-with-temp-text ""
  7565. (org-insert-time-stamp (current-time) t t)
  7566. (buffer-string)))
  7567. (let ((org-log-done 'time)
  7568. (org-log-done-with-time t)
  7569. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7570. (org-test-with-temp-text
  7571. "* TODO task"
  7572. (org-todo "DONE")
  7573. (when (memq 'org-add-log-note post-command-hook)
  7574. (org-add-log-note))
  7575. (buffer-string)))))
  7576. (should
  7577. (string=
  7578. (format
  7579. "* DONE task
  7580. CLOSED: %s"
  7581. (org-test-with-temp-text ""
  7582. (org-insert-time-stamp (current-time) nil t)
  7583. (buffer-string)))
  7584. (let ((org-log-done 'time)
  7585. (org-log-done-with-time nil)
  7586. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7587. (org-test-with-temp-text
  7588. "* TODO task"
  7589. (org-todo "DONE")
  7590. (when (memq 'org-add-log-note post-command-hook)
  7591. (org-add-log-note))
  7592. (buffer-string)))))
  7593. ;; TODO: Test `note' value.
  7594. ;; Test startup overrides.
  7595. (should
  7596. (string=
  7597. "#+STARTUP: nologdone
  7598. * DONE task"
  7599. (let ((org-log-done 'time)
  7600. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7601. (org-test-with-temp-text
  7602. "#+STARTUP: nologdone
  7603. <point>* TODO task"
  7604. (org-set-regexps-and-options)
  7605. (org-todo "DONE")
  7606. (when (memq 'org-add-log-note post-command-hook)
  7607. (org-add-log-note))
  7608. (buffer-string)))))
  7609. (should
  7610. (string=
  7611. (format
  7612. "#+STARTUP: logdone
  7613. * DONE task
  7614. CLOSED: %s"
  7615. (org-test-with-temp-text ""
  7616. (org-insert-time-stamp (current-time) t t)
  7617. (buffer-string)))
  7618. (let ((org-log-done nil)
  7619. (org-log-done-with-time t)
  7620. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7621. (org-test-with-temp-text
  7622. "#+STARTUP: logdone
  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. ;; Test local property overrides.
  7630. (should
  7631. (string=
  7632. "* DONE task
  7633. :PROPERTIES:
  7634. :LOGGING: nil
  7635. :END:"
  7636. (let ((org-log-done 'time)
  7637. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7638. (org-test-with-temp-text
  7639. "* TODO task
  7640. :PROPERTIES:
  7641. :LOGGING: nil
  7642. :END:"
  7643. (org-todo "DONE")
  7644. (when (memq 'org-add-log-note post-command-hook)
  7645. (org-add-log-note))
  7646. (buffer-string)))))
  7647. (should
  7648. (string=
  7649. (format
  7650. "* DONE task
  7651. CLOSED: %s
  7652. :PROPERTIES:
  7653. :LOGGING: logdone
  7654. :END:"
  7655. (org-test-with-temp-text ""
  7656. (org-insert-time-stamp (current-time) t t)
  7657. (buffer-string)))
  7658. (let ((org-log-done nil)
  7659. (org-log-done-with-time t)
  7660. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7661. (org-test-with-temp-text
  7662. "* TODO task
  7663. :PROPERTIES:
  7664. :LOGGING: logdone
  7665. :END:"
  7666. (org-todo "DONE")
  7667. (when (memq 'org-add-log-note post-command-hook)
  7668. (org-add-log-note))
  7669. (buffer-string))))))
  7670. (ert-deftest test-org/org-todo-prefix ()
  7671. "Test `org-todo' prefix arg behavior."
  7672. ;; FIXME: Add tests for all other allowed prefix arguments.
  7673. ;; -1 prefix arg should cancel repeater and mark DONE.
  7674. (should
  7675. (string-match-p
  7676. "DONE H\\(.*\n\\)*<2012-03-29 Thu \\+0y>"
  7677. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7678. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7679. (org-todo -1)
  7680. (buffer-string)))))
  7681. ;; - prefix arg should cancel repeater and mark DONE.
  7682. (should
  7683. (string-match-p
  7684. "DONE H\\(.*\n\\)*<2012-03-29 Thu \\+0y>"
  7685. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7686. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7687. (org-todo '-)
  7688. (buffer-string))))))
  7689. ;;; Timestamps API
  7690. (ert-deftest test-org/at-timestamp-p ()
  7691. "Test `org-at-timestamp-p' specifications."
  7692. (should
  7693. (org-test-with-temp-text "<2012-03-29 Thu>"
  7694. (org-at-timestamp-p)))
  7695. (should-not
  7696. (org-test-with-temp-text "2012-03-29 Thu"
  7697. (org-at-timestamp-p)))
  7698. ;; Test return values.
  7699. (should
  7700. (eq 'bracket
  7701. (org-test-with-temp-text "<2012-03-29 Thu>"
  7702. (org-at-timestamp-p))))
  7703. (should
  7704. (eq 'year
  7705. (org-test-with-temp-text "<<point>2012-03-29 Thu>"
  7706. (org-at-timestamp-p))))
  7707. (should
  7708. (eq 'month
  7709. (org-test-with-temp-text "<2012-<point>03-29 Thu>"
  7710. (org-at-timestamp-p))))
  7711. (should
  7712. (eq 'day
  7713. (org-test-with-temp-text "<2012-03-<point>29 Thu>"
  7714. (org-at-timestamp-p))))
  7715. (should
  7716. (eq 'day
  7717. (org-test-with-temp-text "<2012-03-29 T<point>hu>"
  7718. (org-at-timestamp-p))))
  7719. (should
  7720. (wholenump
  7721. (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
  7722. (org-at-timestamp-p))))
  7723. (should
  7724. (eq 'bracket
  7725. (org-test-with-temp-text "<2012-03-29 Thu<point>>"
  7726. (org-at-timestamp-p))))
  7727. (should
  7728. (eq 'after
  7729. (org-test-with-temp-text "<2012-03-29 Thu><point>»"
  7730. (org-at-timestamp-p))))
  7731. ;; Test `inactive' optional argument.
  7732. (should
  7733. (org-test-with-temp-text "[2012-03-29 Thu]"
  7734. (org-at-timestamp-p 'inactive)))
  7735. (should-not
  7736. (org-test-with-temp-text "[2012-03-29 Thu]"
  7737. (org-at-timestamp-p)))
  7738. ;; When optional argument is `agenda', recognize time-stamps in
  7739. ;; planning info line, property drawers and clocks.
  7740. (should
  7741. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7742. (org-at-timestamp-p 'agenda)))
  7743. (should-not
  7744. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7745. (org-at-timestamp-p)))
  7746. (should
  7747. (org-test-with-temp-text
  7748. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7749. (org-at-timestamp-p 'agenda)))
  7750. (should-not
  7751. (org-test-with-temp-text
  7752. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7753. (org-at-timestamp-p)))
  7754. (should
  7755. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7756. (let ((org-agenda-include-inactive-timestamps t))
  7757. (org-at-timestamp-p 'agenda))))
  7758. (should-not
  7759. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7760. (let ((org-agenda-include-inactive-timestamps t))
  7761. (org-at-timestamp-p))))
  7762. (should-not
  7763. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7764. (let ((org-agenda-include-inactive-timestamps t))
  7765. (org-at-timestamp-p 'inactive))))
  7766. ;; When optional argument is `lax', match any part of the document
  7767. ;; with Org timestamp syntax.
  7768. (should
  7769. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7770. (org-at-timestamp-p 'lax)))
  7771. (should-not
  7772. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7773. (org-at-timestamp-p)))
  7774. (should
  7775. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7776. (org-at-timestamp-p 'lax)))
  7777. (should-not
  7778. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7779. (org-at-timestamp-p)))
  7780. (should
  7781. (org-test-with-temp-text
  7782. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7783. (org-at-timestamp-p 'lax)))
  7784. (should-not
  7785. (org-test-with-temp-text
  7786. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7787. (org-at-timestamp-p)))
  7788. ;; Optional argument `lax' also matches inactive timestamps.
  7789. (should
  7790. (org-test-with-temp-text "# [2012-03-29 Thu]<point>"
  7791. (org-at-timestamp-p 'lax))))
  7792. (ert-deftest test-org/time-stamp ()
  7793. "Test `org-time-stamp' specifications."
  7794. ;; Insert chosen time stamp at point.
  7795. (should
  7796. (string-match
  7797. "Te<2014-03-04 .*?>xt"
  7798. (org-test-with-temp-text "Te<point>xt"
  7799. (cl-letf (((symbol-function 'org-read-date)
  7800. (lambda (&rest args)
  7801. (org-time-string-to-time "2014-03-04"))))
  7802. (org-time-stamp nil)
  7803. (buffer-string)))))
  7804. ;; With a prefix argument, also insert time.
  7805. (should
  7806. (string-match
  7807. "Te<2014-03-04 .*? 00:41>xt"
  7808. (org-test-with-temp-text "Te<point>xt"
  7809. (cl-letf (((symbol-function 'org-read-date)
  7810. (lambda (&rest args)
  7811. (org-time-string-to-time "2014-03-04 00:41"))))
  7812. (org-time-stamp '(4))
  7813. (buffer-string)))))
  7814. ;; With two universal prefix arguments, insert an active timestamp
  7815. ;; with the current time without prompting the user.
  7816. (should
  7817. (string-match
  7818. "Te<2014-03-04 .*? 00:41>xt"
  7819. (org-test-with-temp-text "Te<point>xt"
  7820. (org-test-at-time "2014-03-04 00:41"
  7821. (org-time-stamp '(16))
  7822. (buffer-string)))))
  7823. ;; When optional argument is non-nil, insert an inactive timestamp.
  7824. (should
  7825. (string-match
  7826. "Te\\[2014-03-04 .*?\\]xt"
  7827. (org-test-with-temp-text "Te<point>xt"
  7828. (cl-letf (((symbol-function 'org-read-date)
  7829. (lambda (&rest args)
  7830. (org-time-string-to-time "2014-03-04"))))
  7831. (org-time-stamp nil t)
  7832. (buffer-string)))))
  7833. ;; When called from a timestamp, replace existing one.
  7834. (should
  7835. (string-match
  7836. "<2014-03-04 .*?>"
  7837. (org-test-with-temp-text "<2012-03-29<point> thu.>"
  7838. (cl-letf (((symbol-function 'org-read-date)
  7839. (lambda (&rest args)
  7840. (org-time-string-to-time "2014-03-04"))))
  7841. (org-time-stamp nil)
  7842. (buffer-string)))))
  7843. (should
  7844. (string-match
  7845. "<2014-03-04 .*?>--<2014-03-04 .*?>"
  7846. (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
  7847. (cl-letf (((symbol-function 'org-read-date)
  7848. (lambda (&rest args)
  7849. (org-time-string-to-time "2014-03-04"))))
  7850. (org-time-stamp nil)
  7851. (buffer-string)))))
  7852. ;; When replacing a timestamp, preserve repeater, if any.
  7853. (should
  7854. (string-match
  7855. "<2014-03-04 .*? \\+2y>"
  7856. (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
  7857. (cl-letf (((symbol-function 'org-read-date)
  7858. (lambda (&rest args)
  7859. (org-time-string-to-time "2014-03-04"))))
  7860. (org-time-stamp nil)
  7861. (buffer-string)))))
  7862. ;; When called twice in a raw, build a date range.
  7863. (should
  7864. (string-match
  7865. "<2012-03-29 .*?>--<2014-03-04 .*?>"
  7866. (org-test-with-temp-text "<2012-03-29 thu.><point>"
  7867. (cl-letf (((symbol-function 'org-read-date)
  7868. (lambda (&rest args)
  7869. (org-time-string-to-time "2014-03-04"))))
  7870. (let ((last-command 'org-time-stamp)
  7871. (this-command 'org-time-stamp))
  7872. (org-time-stamp nil))
  7873. (buffer-string))))))
  7874. (ert-deftest test-org/timestamp-has-time-p ()
  7875. "Test `org-timestamp-has-time-p' specifications."
  7876. ;; With time.
  7877. (should
  7878. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7879. (org-timestamp-has-time-p (org-element-context))))
  7880. ;; Without time.
  7881. (should-not
  7882. (org-test-with-temp-text "<2012-03-29 Thu>"
  7883. (org-timestamp-has-time-p (org-element-context)))))
  7884. (ert-deftest test-org/get-repeat ()
  7885. "Test `org-get-repeat' specifications."
  7886. (should
  7887. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
  7888. (org-get-repeat)))
  7889. (should-not
  7890. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
  7891. (org-get-repeat)))
  7892. ;; Return proper repeat string.
  7893. (should
  7894. (equal "+2y"
  7895. (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
  7896. (org-get-repeat))))
  7897. ;; Prevent false positive (commented or verbatim time stamps)
  7898. (should-not
  7899. (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
  7900. (org-get-repeat)))
  7901. (should-not
  7902. (org-test-with-temp-text
  7903. "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
  7904. (org-get-repeat)))
  7905. ;; Return nil when called before first heading.
  7906. (should-not
  7907. (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
  7908. (org-get-repeat)))
  7909. ;; When called with an optional argument, extract repeater from that
  7910. ;; string instead.
  7911. (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
  7912. (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
  7913. (ert-deftest test-org/timestamp-format ()
  7914. "Test `org-timestamp-format' specifications."
  7915. ;; Regular test.
  7916. (should
  7917. (equal
  7918. "2012-03-29 16:40"
  7919. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7920. (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
  7921. ;; Range end.
  7922. (should
  7923. (equal
  7924. "2012-03-29"
  7925. (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
  7926. (org-timestamp-format (org-element-context) "%Y-%m-%d" t)))))
  7927. (ert-deftest test-org/timestamp-split-range ()
  7928. "Test `org-timestamp-split-range' specifications."
  7929. ;; Extract range start (active).
  7930. (should
  7931. (equal '(2012 3 29)
  7932. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7933. (let ((ts (org-timestamp-split-range (org-element-context))))
  7934. (mapcar (lambda (p) (org-element-property p ts))
  7935. '(:year-end :month-end :day-end))))))
  7936. ;; Extract range start (inactive)
  7937. (should
  7938. (equal '(2012 3 29)
  7939. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7940. (let ((ts (org-timestamp-split-range (org-element-context))))
  7941. (mapcar (lambda (p) (org-element-property p ts))
  7942. '(:year-end :month-end :day-end))))))
  7943. ;; Extract range end (active).
  7944. (should
  7945. (equal '(2012 3 30)
  7946. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7947. (let ((ts (org-timestamp-split-range
  7948. (org-element-context) t)))
  7949. (mapcar (lambda (p) (org-element-property p ts))
  7950. '(:year-end :month-end :day-end))))))
  7951. ;; Extract range end (inactive)
  7952. (should
  7953. (equal '(2012 3 30)
  7954. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7955. (let ((ts (org-timestamp-split-range
  7956. (org-element-context) t)))
  7957. (mapcar (lambda (p) (org-element-property p ts))
  7958. '(:year-end :month-end :day-end))))))
  7959. ;; Return the timestamp if not a range.
  7960. (should
  7961. (org-test-with-temp-text "[2012-03-29 Thu]"
  7962. (let* ((ts-orig (org-element-context))
  7963. (ts-copy (org-timestamp-split-range ts-orig)))
  7964. (eq ts-orig ts-copy))))
  7965. (should
  7966. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7967. (let* ((ts-orig (org-element-context))
  7968. (ts-copy (org-timestamp-split-range ts-orig)))
  7969. (eq ts-orig ts-copy)))))
  7970. (ert-deftest test-org/timestamp-translate ()
  7971. "Test `org-timestamp-translate' specifications."
  7972. ;; Translate whole date range.
  7973. (should
  7974. (equal "<29>--<30>"
  7975. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7976. (let ((org-display-custom-times t)
  7977. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7978. (org-timestamp-translate (org-element-context))))))
  7979. ;; Translate date range start.
  7980. (should
  7981. (equal "<29>"
  7982. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7983. (let ((org-display-custom-times t)
  7984. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7985. (org-timestamp-translate (org-element-context) 'start)))))
  7986. ;; Translate date range end.
  7987. (should
  7988. (equal "<30>"
  7989. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7990. (let ((org-display-custom-times t)
  7991. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7992. (org-timestamp-translate (org-element-context) 'end)))))
  7993. ;; Translate time range.
  7994. (should
  7995. (equal "<08>--<16>"
  7996. (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
  7997. (let ((org-display-custom-times t)
  7998. (org-time-stamp-custom-formats '("<%d>" . "<%H>")))
  7999. (org-timestamp-translate (org-element-context))))))
  8000. ;; Translate non-range timestamp.
  8001. (should
  8002. (equal "<29>"
  8003. (org-test-with-temp-text "<2012-03-29 Thu>"
  8004. (let ((org-display-custom-times t)
  8005. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  8006. (org-timestamp-translate (org-element-context))))))
  8007. ;; Do not change `diary' timestamps.
  8008. (should
  8009. (equal "<%%(org-float t 4 2)>"
  8010. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  8011. (let ((org-display-custom-times t)
  8012. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  8013. (org-timestamp-translate (org-element-context)))))))
  8014. (ert-deftest test-org/timestamp-from-string ()
  8015. "Test `org-timestamp-from-string' specifications."
  8016. ;; Return nil if argument is not a valid Org timestamp.
  8017. (should-not (org-timestamp-from-string ""))
  8018. (should-not (org-timestamp-from-string nil))
  8019. (should-not (org-timestamp-from-string "<2012-03-29"))
  8020. ;; Otherwise, return a valid Org timestamp object.
  8021. (should
  8022. (string-match-p "<2012-03-29 .+>"
  8023. (org-element-interpret-data
  8024. (org-timestamp-from-string "<2012-03-29 Thu>"))))
  8025. (should
  8026. (string-match-p "[2014-03-04 .+]"
  8027. (org-element-interpret-data
  8028. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  8029. (ert-deftest test-org/timestamp-from-time ()
  8030. "Test `org-timestamp-from-time' specifications."
  8031. ;; Standard test.
  8032. (should
  8033. (string-match-p
  8034. "<2012-03-29 .+>"
  8035. (org-element-interpret-data
  8036. (org-timestamp-from-time
  8037. (org-time-string-to-time "<2012-03-29 Thu 16:40>")))))
  8038. ;; When optional argument WITH-TIME is non-nil, provide time
  8039. ;; information.
  8040. (should
  8041. (string-match-p
  8042. "<2012-03-29 .+ 16:40>"
  8043. (org-element-interpret-data
  8044. (org-timestamp-from-time
  8045. (org-time-string-to-time "<2012-03-29 Thu 16:40>")
  8046. t))))
  8047. ;; When optional argument INACTIVE is non-nil, return an inactive
  8048. ;; timestamp.
  8049. (should
  8050. (string-match-p
  8051. "[2012-03-29 .+]"
  8052. (org-element-interpret-data
  8053. (org-timestamp-from-time
  8054. (org-time-string-to-time "<2012-03-29 Thu 16:40>")
  8055. nil t)))))
  8056. (ert-deftest test-org/timestamp-to-time ()
  8057. "Test `org-timestamp-to-time' specifications."
  8058. (should
  8059. (equal "2014-03-04"
  8060. (format-time-string
  8061. "%Y-%m-%d"
  8062. (org-timestamp-to-time
  8063. (org-timestamp-from-string "<2014-03-04 Tue>")))))
  8064. (should
  8065. (equal "2014-03-04"
  8066. (format-time-string
  8067. "%Y-%m-%d"
  8068. (org-timestamp-to-time
  8069. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  8070. (should
  8071. (equal "2012-03-29 08:30"
  8072. (format-time-string
  8073. "%Y-%m-%d %H:%M"
  8074. (org-timestamp-to-time
  8075. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")))))
  8076. (should
  8077. (equal "2012-03-29"
  8078. (format-time-string
  8079. "%Y-%m-%d"
  8080. (org-timestamp-to-time
  8081. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")))))
  8082. (should
  8083. (equal "2012-03-29"
  8084. (format-time-string
  8085. "%Y-%m-%d"
  8086. (org-timestamp-to-time
  8087. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")))))
  8088. ;; When optional argument END is non-nil, use end of date range or
  8089. ;; time range.
  8090. (should
  8091. (equal "2012-03-29 16:40"
  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. t))))
  8097. (should
  8098. (equal "2014-03-04"
  8099. (format-time-string
  8100. "%Y-%m-%d"
  8101. (org-timestamp-to-time
  8102. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")
  8103. t))))
  8104. (should
  8105. (equal "2014-03-04"
  8106. (format-time-string
  8107. "%Y-%m-%d"
  8108. (org-timestamp-to-time
  8109. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")
  8110. t)))))
  8111. ;;; Yank and Kill
  8112. (ert-deftest test-org/paste-subtree ()
  8113. "Test `org-paste-subtree' specifications."
  8114. ;; Return an error if text to yank is not a set of subtrees.
  8115. (should-error (org-paste-subtree nil "Text"))
  8116. ;; Adjust level according to current one.
  8117. (should
  8118. (equal "* H\n* Text\n"
  8119. (org-test-with-temp-text "* H\n<point>"
  8120. (org-paste-subtree nil "* Text")
  8121. (buffer-string))))
  8122. (should
  8123. (equal "* H1\n** H2\n** Text\n"
  8124. (org-test-with-temp-text "* H1\n** H2\n<point>"
  8125. (org-paste-subtree nil "* Text")
  8126. (buffer-string))))
  8127. ;; When not on a heading, move to next heading before yanking.
  8128. (should
  8129. (equal "* H1\nParagraph\n* Text\n* H2"
  8130. (org-test-with-temp-text "* H1\n<point>Paragraph\n* H2"
  8131. (org-paste-subtree nil "* Text")
  8132. (buffer-string))))
  8133. ;; If point is between two headings, use the deepest level.
  8134. (should
  8135. (equal "* H1\n\n* Text\n* H2"
  8136. (org-test-with-temp-text "* H1\n<point>\n* H2"
  8137. (org-paste-subtree nil "* Text")
  8138. (buffer-string))))
  8139. (should
  8140. (equal "** H1\n\n** Text\n* H2"
  8141. (org-test-with-temp-text "** H1\n<point>\n* H2"
  8142. (org-paste-subtree nil "* Text")
  8143. (buffer-string))))
  8144. (should
  8145. (equal "* H1\n\n** Text\n** H2"
  8146. (org-test-with-temp-text "* H1\n<point>\n** H2"
  8147. (org-paste-subtree nil "* Text")
  8148. (buffer-string))))
  8149. ;; When on an empty heading, after the stars, deduce the new level
  8150. ;; from the number of stars.
  8151. (should
  8152. (equal "*** Text\n"
  8153. (org-test-with-temp-text "*** <point>"
  8154. (org-paste-subtree nil "* Text")
  8155. (buffer-string))))
  8156. ;; Optional argument LEVEL forces a level for the subtree.
  8157. (should
  8158. (equal "* H\n*** Text\n"
  8159. (org-test-with-temp-text "* H<point>"
  8160. (org-paste-subtree 3 "* Text")
  8161. (buffer-string)))))
  8162. (ert-deftest test-org/cut-and-paste-subtree ()
  8163. "Test `org-cut-subtree' and `org-paste-subtree'."
  8164. (should
  8165. (equal
  8166. "* Two
  8167. two
  8168. * One
  8169. "
  8170. (org-test-with-temp-text
  8171. "* One
  8172. <point>* Two
  8173. two
  8174. "
  8175. (call-interactively #'org-cut-subtree)
  8176. (goto-char (point-min))
  8177. (call-interactively #'org-paste-subtree)
  8178. (buffer-string))))
  8179. (should
  8180. (equal
  8181. "* One
  8182. * Two
  8183. "
  8184. (org-test-with-temp-text
  8185. "* One
  8186. <point>* Two
  8187. "
  8188. (call-interactively #'org-cut-subtree)
  8189. (backward-char)
  8190. (call-interactively #'org-paste-subtree)
  8191. (buffer-string)))))
  8192. (provide 'test-org)
  8193. ;;; test-org.el ends here