test-org.el 255 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868
  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 <http://www.gnu.org/licenses/>.
  15. ;; Template test file for Org tests
  16. ;;; Code:
  17. (eval-and-compile (require 'cl-lib))
  18. ;;; Comments
  19. (ert-deftest test-org/toggle-comment ()
  20. "Test `org-toggle-comment' specifications."
  21. ;; Simple headline.
  22. (should
  23. (equal "* Test"
  24. (org-test-with-temp-text "* COMMENT Test"
  25. (org-toggle-comment)
  26. (buffer-string))))
  27. (should
  28. (equal "* COMMENT Test"
  29. (org-test-with-temp-text "* Test"
  30. (org-toggle-comment)
  31. (buffer-string))))
  32. ;; Headline with a regular keyword.
  33. (should
  34. (equal "* TODO Test"
  35. (org-test-with-temp-text "* TODO COMMENT Test"
  36. (org-toggle-comment)
  37. (buffer-string))))
  38. (should
  39. (equal "* TODO COMMENT Test"
  40. (org-test-with-temp-text "* TODO Test"
  41. (org-toggle-comment)
  42. (buffer-string))))
  43. ;; Empty headline.
  44. (should
  45. (equal "* "
  46. (org-test-with-temp-text "* COMMENT"
  47. (org-toggle-comment)
  48. (buffer-string))))
  49. (should
  50. (equal "* COMMENT"
  51. (org-test-with-temp-text "* "
  52. (org-toggle-comment)
  53. (buffer-string))))
  54. ;; Headline with a single keyword.
  55. (should
  56. (equal "* TODO "
  57. (org-test-with-temp-text "* TODO COMMENT"
  58. (org-toggle-comment)
  59. (buffer-string))))
  60. (should
  61. (equal "* TODO COMMENT"
  62. (org-test-with-temp-text "* TODO"
  63. (org-toggle-comment)
  64. (buffer-string))))
  65. ;; Headline with a keyword, a priority cookie and contents.
  66. (should
  67. (equal "* TODO [#A] Headline"
  68. (org-test-with-temp-text "* TODO [#A] COMMENT Headline"
  69. (org-toggle-comment)
  70. (buffer-string))))
  71. (should
  72. (equal "* TODO [#A] COMMENT Headline"
  73. (org-test-with-temp-text "* TODO [#A] Headline"
  74. (org-toggle-comment)
  75. (buffer-string)))))
  76. (ert-deftest test-org/comment-dwim ()
  77. "Test `comment-dwim' behaviour in an Org buffer."
  78. ;; No region selected, no comment on current line and line not
  79. ;; empty: insert comment on line above.
  80. (should
  81. (equal "# \nComment"
  82. (org-test-with-temp-text "Comment"
  83. (call-interactively #'org-comment-dwim)
  84. (buffer-string))))
  85. ;; No region selected, no comment on current line and line empty:
  86. ;; insert comment on this line.
  87. (should
  88. (equal "# \nParagraph"
  89. (org-test-with-temp-text "\nParagraph"
  90. (call-interactively #'org-comment-dwim)
  91. (buffer-string))))
  92. ;; No region selected, and a comment on this line: indent it.
  93. (should
  94. (equal "* Headline\n # Comment"
  95. (org-test-with-temp-text "* Headline\n# <point>Comment"
  96. (let ((org-adapt-indentation t))
  97. (call-interactively #'org-comment-dwim))
  98. (buffer-string))))
  99. ;; Also recognize single # at column 0 as comments.
  100. (should
  101. (equal "# Comment"
  102. (org-test-with-temp-text "# Comment"
  103. (call-interactively #'org-comment-dwim)
  104. (buffer-string))))
  105. ;; Region selected and only comments and blank lines within it:
  106. ;; un-comment all commented lines.
  107. (should
  108. (equal "Comment 1\n\nComment 2"
  109. (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
  110. (transient-mark-mode 1)
  111. (push-mark (point) t t)
  112. (goto-char (point-max))
  113. (call-interactively #'org-comment-dwim)
  114. (buffer-string))))
  115. ;; Region selected without comments: comment all lines if
  116. ;; `comment-empty-lines' is non-nil, only non-blank lines otherwise.
  117. (should
  118. (equal "# Comment 1\n\n# Comment 2"
  119. (org-test-with-temp-text "Comment 1\n\nComment 2"
  120. (transient-mark-mode 1)
  121. (push-mark (point) t t)
  122. (goto-char (point-max))
  123. (let ((comment-empty-lines nil))
  124. (call-interactively #'org-comment-dwim))
  125. (buffer-string))))
  126. (should
  127. (equal "# Comment 1\n# \n# Comment 2"
  128. (org-test-with-temp-text "Comment 1\n\nComment 2"
  129. (transient-mark-mode 1)
  130. (push-mark (point) t t)
  131. (goto-char (point-max))
  132. (let ((comment-empty-lines t))
  133. (call-interactively #'org-comment-dwim))
  134. (buffer-string))))
  135. ;; In front of a keyword without region, insert a new comment.
  136. (should
  137. (equal "# \n#+KEYWORD: value"
  138. (org-test-with-temp-text "#+KEYWORD: value"
  139. (call-interactively #'org-comment-dwim)
  140. (buffer-string))))
  141. ;; Comment a heading
  142. (should
  143. (equal "* COMMENT Test"
  144. (org-test-with-temp-text "* Test"
  145. (call-interactively #'org-comment-dwim)
  146. (buffer-string))))
  147. ;; In a source block, use appropriate syntax.
  148. (should
  149. (equal " ;; "
  150. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n<point>\n#+END_SRC"
  151. (let ((org-edit-src-content-indentation 2))
  152. (call-interactively #'org-comment-dwim))
  153. (buffer-substring-no-properties (line-beginning-position)
  154. (point)))))
  155. (should
  156. (equal "#+BEGIN_SRC emacs-lisp\n ;; a\n ;; b\n#+END_SRC"
  157. (org-test-with-temp-text
  158. "#+BEGIN_SRC emacs-lisp\n<point>a\nb\n#+END_SRC"
  159. (transient-mark-mode 1)
  160. (push-mark (point) t t)
  161. (forward-line 2)
  162. (let ((org-edit-src-content-indentation 2))
  163. (call-interactively #'org-comment-dwim))
  164. (buffer-string)))))
  165. ;;; Date and time analysis
  166. (ert-deftest test-org/org-read-date ()
  167. "Test `org-read-date' specifications."
  168. ;; Parse ISO date with abbreviated year and month.
  169. (should (equal "2012-03-29 16:40"
  170. (let ((org-time-was-given t))
  171. (org-read-date t nil "12-3-29 16:40"))))
  172. ;; Parse Europeans dates.
  173. (should (equal "2012-03-29 16:40"
  174. (let ((org-time-was-given t))
  175. (org-read-date t nil "29.03.2012 16:40"))))
  176. ;; Parse Europeans dates without year.
  177. (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
  178. (let ((org-time-was-given t))
  179. (org-read-date t nil "29.03. 16:40"))))
  180. ;; Relative date applied to current time if there is single
  181. ;; plus/minus, or to default date when there are two of them.
  182. (should
  183. (equal
  184. "2015-03-04"
  185. (org-test-at-time "2014-03-04"
  186. (org-read-date
  187. t nil "+1y" nil
  188. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))
  189. (should
  190. (equal
  191. "2013-03-29"
  192. (org-test-at-time "2014-03-04"
  193. (org-read-date
  194. t nil "++1y" nil
  195. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))
  196. ;; When `org-read-date-prefer-future' is non-nil, prefer future
  197. ;; dates (relatively to now) when incomplete. Otherwise, use
  198. ;; default date.
  199. (should
  200. (equal
  201. "2014-04-01"
  202. (org-test-at-time "2014-03-04"
  203. (let ((org-read-date-prefer-future t))
  204. (org-read-date t nil "1")))))
  205. (should
  206. (equal
  207. "2013-03-04"
  208. (org-test-at-time "2012-03-29"
  209. (let ((org-read-date-prefer-future t))
  210. (org-read-date t nil "3-4")))))
  211. (should
  212. (equal
  213. "2012-03-04"
  214. (org-test-at-time "2012-03-29"
  215. (let ((org-read-date-prefer-future nil))
  216. (org-read-date t nil "3-4")))))
  217. ;; When set to `org-read-date-prefer-future' is set to `time', read
  218. ;; day is moved to tomorrow if specified hour is before current
  219. ;; time. However, it only happens in no other part of the date is
  220. ;; specified.
  221. (should
  222. (equal
  223. "2012-03-30"
  224. (org-test-at-time "2012-03-29 16:40"
  225. (let ((org-read-date-prefer-future 'time))
  226. (org-read-date t nil "00:40" nil)))))
  227. (should-not
  228. (equal
  229. "2012-03-30"
  230. (org-test-at-time "2012-03-29 16:40"
  231. (let ((org-read-date-prefer-future 'time))
  232. (org-read-date t nil "29 00:40" nil)))))
  233. ;; Caveat: `org-read-date-prefer-future' always refers to current
  234. ;; time, not default time, when they differ.
  235. (should
  236. (equal
  237. "2014-04-01"
  238. (org-test-at-time "2014-03-04"
  239. (let ((org-read-date-prefer-future t))
  240. (org-read-date
  241. t nil "1" nil
  242. (apply #'encode-time (org-parse-time-string "2012-03-29")))))))
  243. (should
  244. (equal
  245. "2014-03-25"
  246. (org-test-at-time "2014-03-04"
  247. (let ((org-read-date-prefer-future t))
  248. (org-read-date
  249. t nil "25" nil
  250. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))))
  251. (ert-deftest test-org/org-parse-time-string ()
  252. "Test `org-parse-time-string'."
  253. (should (equal (org-parse-time-string "2012-03-29 16:40")
  254. '(0 40 16 29 3 2012 nil nil nil)))
  255. (should (equal (org-parse-time-string "[2012-03-29 16:40]")
  256. '(0 40 16 29 3 2012 nil nil nil)))
  257. (should (equal (org-parse-time-string "<2012-03-29 16:40>")
  258. '(0 40 16 29 3 2012 nil nil nil)))
  259. (should (equal (org-parse-time-string "<2012-03-29>")
  260. '(0 0 0 29 3 2012 nil nil nil)))
  261. (should (equal (org-parse-time-string "<2012-03-29>" t)
  262. '(0 nil nil 29 3 2012 nil nil nil))))
  263. (ert-deftest test-org/closest-date ()
  264. "Test `org-closest-date' specifications."
  265. (require 'calendar)
  266. ;; Time stamps without a repeater are returned unchanged.
  267. (should
  268. (equal
  269. '(3 29 2012)
  270. (calendar-gregorian-from-absolute
  271. (org-closest-date "<2012-03-29>" "<2014-03-04>" nil))))
  272. ;; Time stamps with a null repeater are returned unchanged.
  273. (should
  274. (equal
  275. '(3 29 2012)
  276. (calendar-gregorian-from-absolute
  277. (org-closest-date "<2012-03-29 +0d>" "<2014-03-04>" nil))))
  278. ;; if PREFER is set to `past' always return a date before, or equal
  279. ;; to CURRENT.
  280. (should
  281. (equal
  282. '(3 1 2014)
  283. (calendar-gregorian-from-absolute
  284. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'past))))
  285. (should
  286. (equal
  287. '(3 4 2014)
  288. (calendar-gregorian-from-absolute
  289. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'past))))
  290. ;; if PREFER is set to `future' always return a date before, or equal
  291. ;; to CURRENT.
  292. (should
  293. (equal
  294. '(3 29 2014)
  295. (calendar-gregorian-from-absolute
  296. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'future))))
  297. (should
  298. (equal
  299. '(3 4 2014)
  300. (calendar-gregorian-from-absolute
  301. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'future))))
  302. ;; If PREFER is neither `past' nor `future', select closest date.
  303. (should
  304. (equal
  305. '(3 1 2014)
  306. (calendar-gregorian-from-absolute
  307. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" nil))))
  308. (should
  309. (equal
  310. '(5 4 2014)
  311. (calendar-gregorian-from-absolute
  312. (org-closest-date "<2012-03-04 +1m>" "<2014-04-28>" nil))))
  313. ;; Test "day" repeater.
  314. (should
  315. (equal '(3 8 2014)
  316. (calendar-gregorian-from-absolute
  317. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'past))))
  318. (should
  319. (equal '(3 10 2014)
  320. (calendar-gregorian-from-absolute
  321. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'future))))
  322. ;; Test "month" repeater.
  323. (should
  324. (equal '(1 5 2015)
  325. (calendar-gregorian-from-absolute
  326. (org-closest-date "<2014-03-05 +2m>" "<2015-02-04>" 'past))))
  327. (should
  328. (equal '(3 29 2014)
  329. (calendar-gregorian-from-absolute
  330. (org-closest-date "<2012-03-29 +2m>" "<2014-03-04>" 'future))))
  331. ;; Test "year" repeater.
  332. (should
  333. (equal '(3 5 2014)
  334. (calendar-gregorian-from-absolute
  335. (org-closest-date "<2014-03-05 +2y>" "<2015-02-04>" 'past))))
  336. (should
  337. (equal '(3 29 2014)
  338. (calendar-gregorian-from-absolute
  339. (org-closest-date "<2012-03-29 +2y>" "<2014-03-04>" 'future)))))
  340. (ert-deftest test-org/deadline-close-p ()
  341. "Test `org-deadline-close-p' specifications."
  342. (org-test-at-time "2016-06-03 Fri 01:43"
  343. ;; Timestamps are close if they are within `ndays' of lead time.
  344. (org-test-with-temp-text "* Heading"
  345. (should (org-deadline-close-p "2016-06-03 Fri" 0))
  346. (should (org-deadline-close-p "2016-06-02 Thu" 0))
  347. (should-not (org-deadline-close-p "2016-06-04 Sat" 0))
  348. (should (org-deadline-close-p "2016-06-04 Sat" 1))
  349. (should (org-deadline-close-p "2016-06-03 Fri 12:00" 0)))
  350. ;; Read `ndays' from timestamp if argument not given.
  351. (org-test-with-temp-text "* H"
  352. (should (org-deadline-close-p "2016-06-04 Sat -1d"))
  353. (should-not (org-deadline-close-p "2016-06-04 Sat -0d"))
  354. (should (org-deadline-close-p "2016-06-10 Fri -1w"))
  355. (should-not (org-deadline-close-p "2016-06-11 Sat -1w")))
  356. ;; Prefer `ndays' argument over lead time in timestamp.
  357. (org-test-with-temp-text "* H"
  358. (should (org-deadline-close-p "2016-06-04 Sat -0d" 1))
  359. (should-not (org-deadline-close-p "2016-06-04 Sat -0d" 0)))
  360. ;; Completed tasks are never close.
  361. (let ((org-todo-keywords '(("TODO" "|" "DONE"))))
  362. (org-test-with-temp-text "* TODO Heading"
  363. (should (org-deadline-close-p "2016-06-03")))
  364. (org-test-with-temp-text "* DONE Heading"
  365. (should-not (org-deadline-close-p "2016-06-03"))))))
  366. ;;; Drawers
  367. (ert-deftest test-org/at-property-p ()
  368. "Test `org-at-property-p' specifications."
  369. (should
  370. (equal 't
  371. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:PROP: t\n:END:\n"
  372. (org-at-property-p))))
  373. (should
  374. (equal 't
  375. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n:END:\n"
  376. (org-at-property-p)))))
  377. (ert-deftest test-org/at-property-drawer-p ()
  378. "Test `org-at-property-drawer-p' specifications."
  379. (should
  380. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:PROP: t\n:END:\n"
  381. (org-at-property-drawer-p)))
  382. (should
  383. (org-test-with-temp-text ":PROPERTIES:\n:PROP: t\n:END:\n"
  384. (org-at-property-drawer-p)))
  385. ;; The function only returns t if point is at the first line of
  386. ;; a property block.
  387. (should-not
  388. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n:END:\n"
  389. (org-at-property-drawer-p)))
  390. ;; The function ignores incomplete drawers.
  391. (should-not
  392. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n"
  393. (org-at-property-drawer-p))))
  394. (ert-deftest test-org/get-property-block ()
  395. "Test `org-get-property-block' specifications."
  396. (should
  397. (equal '(14 . 14)
  398. (org-test-with-temp-text ":PROPERTIES:\n:END:\n* H\n"
  399. (org-get-property-block))))
  400. (should
  401. (equal '(14 . 14)
  402. (org-test-with-temp-text ":PROPERTIES:\n:END:\n"
  403. (org-get-property-block))))
  404. ;; Comments above a document property block is ok.
  405. (should
  406. (equal '(18 . 18)
  407. (org-test-with-temp-text "# C\n:PROPERTIES:\n:END:\n"
  408. (org-get-property-block))))
  409. ;; Keywords above a document property block is ok.
  410. (should
  411. (equal '(22 . 22)
  412. (org-test-with-temp-text "# C\n# C\n:PROPERTIES:\n:END:\n"
  413. (org-get-property-block))))
  414. ;; Comments and keywords are allowed before a document property block.
  415. (should
  416. (equal '(18 . 27)
  417. (org-test-with-temp-text "# C\n:PROPERTIES:\n:KEY: V:\n:END:\n"
  418. (org-get-property-block))))
  419. ;; A document property block will not be valid if there are lines
  420. ;; with whitespace above it
  421. (should-not
  422. (org-test-with-temp-text "\n:PROPERTIES:\n:END:\n"
  423. (org-get-property-block)))
  424. (should
  425. (equal '(18 . 18)
  426. (org-test-with-temp-text "* H\n:PROPERTIES:\n:END:\n<point>"
  427. (org-get-property-block))))
  428. (should
  429. (equal "* H\n:PROPERTIES:\n:END:\n"
  430. (org-test-with-temp-text "* H"
  431. (let ((org-adapt-indentation nil))
  432. (org-get-property-block nil 'force))
  433. (buffer-string))))
  434. (should
  435. (equal ":PROPERTIES:\n:END:\n"
  436. (org-test-with-temp-text ""
  437. (org-get-property-block nil 'force)
  438. (buffer-string))))
  439. (should
  440. (equal "* H1\n :PROPERTIES:\n :END:\n* H2"
  441. (org-test-with-temp-text "* H1\n* H2"
  442. (let ((org-adapt-indentation t))
  443. (org-get-property-block nil 'force))
  444. (buffer-string)))))
  445. (ert-deftest test-org/insert-property-drawer ()
  446. "Test `org-insert-property-drawer' specifications."
  447. ;; Insert drawer in empty buffer
  448. (should
  449. (equal ":PROPERTIES:\n:END:\n"
  450. (org-test-with-temp-text ""
  451. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  452. (buffer-string))))
  453. ;; Insert drawer in document header with existing comment and
  454. ;; keyword.
  455. (should
  456. (equal "# C\n:PROPERTIES:\n:END:\n#+TITLE: T"
  457. (org-test-with-temp-text "# C\n#+TITLE: T"
  458. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  459. (buffer-string))))
  460. ;; Insert drawer in document header with existing keyword.
  461. (should
  462. (equal ":PROPERTIES:\n:END:\n#+TITLE: T"
  463. (org-test-with-temp-text "#+TITLE: T"
  464. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  465. (buffer-string))))
  466. (should
  467. (equal ":PROPERTIES:\n:END:"
  468. (org-test-with-temp-text ":PROPERTIES:\n:END:"
  469. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  470. (buffer-string))))
  471. ;; Insert drawer in document header with one existing heading in buffer.
  472. (should
  473. (equal ":PROPERTIES:\n:END:\n\n* T\n"
  474. (org-test-with-temp-text "\n* T\n"
  475. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  476. (buffer-string))))
  477. ;; Insert drawer right after headline if there is no planning line,
  478. ;; or after it otherwise.
  479. (should
  480. (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
  481. (org-test-with-temp-text "* H\nParagraph<point>"
  482. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  483. (buffer-string))))
  484. (should
  485. (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
  486. (org-test-with-temp-text
  487. "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
  488. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  489. (buffer-string))))
  490. ;; Indent inserted drawer.
  491. (should
  492. (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
  493. (org-test-with-temp-text "* H\nParagraph<point>"
  494. (let ((org-adapt-indentation t)) (org-insert-property-drawer))
  495. (buffer-string))))
  496. ;; Handle insertion at eob.
  497. (should
  498. (equal "* H\n:PROPERTIES:\n:END:\n"
  499. (org-test-with-temp-text "* H"
  500. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  501. (buffer-string))))
  502. ;; Skip inlinetasks before point.
  503. (when (featurep 'org-inlinetask)
  504. (should
  505. (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
  506. (org-test-with-temp-text
  507. "* H\n*************** I\n*************** END\nP<point>"
  508. (let ((org-adapt-indentation nil)
  509. (org-inlinetask-min-level 15))
  510. (org-insert-property-drawer))
  511. (buffer-string)))))
  512. ;; Correctly set drawer in an inlinetask.
  513. (when (featurep 'org-inlinetask)
  514. (should
  515. (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
  516. (org-test-with-temp-text
  517. "* H\n*************** I\nP<point>\n*************** END"
  518. (let ((org-adapt-indentation nil)
  519. (org-inlinetask-min-level 15))
  520. (org-insert-property-drawer))
  521. (buffer-string))))))
  522. ;;; Filling
  523. (ert-deftest test-org/fill-element ()
  524. "Test `org-fill-element' specifications."
  525. ;; At an Org table, align it.
  526. (should
  527. (equal "| a |\n"
  528. (org-test-with-temp-text "|a|"
  529. (org-fill-element)
  530. (buffer-string))))
  531. (should
  532. (equal "#+name: table\n| a |\n"
  533. (org-test-with-temp-text "#+name: table\n| a |\n"
  534. (org-fill-element)
  535. (buffer-string))))
  536. ;; At a paragraph, preserve line breaks.
  537. (org-test-with-temp-text "some \\\\\nlong\ntext"
  538. (let ((fill-column 20))
  539. (org-fill-element)
  540. (should (equal (buffer-string) "some \\\\\nlong text"))))
  541. ;; Correctly fill a paragraph when point is at its very end.
  542. (should
  543. (equal "A B"
  544. (org-test-with-temp-text "A\nB"
  545. (let ((fill-column 20))
  546. (goto-char (point-max))
  547. (org-fill-element)
  548. (buffer-string)))))
  549. ;; Correctly fill the last paragraph of a greater element.
  550. (should
  551. (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
  552. (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
  553. (let ((fill-column 8))
  554. (forward-line)
  555. (end-of-line)
  556. (org-fill-element)
  557. (buffer-string)))))
  558. ;; Correctly fill an element in a narrowed buffer.
  559. (should
  560. (equal "01234\n6"
  561. (org-test-with-temp-text "01234 6789"
  562. (let ((fill-column 5))
  563. (narrow-to-region 1 8)
  564. (org-fill-element)
  565. (buffer-string)))))
  566. ;; Handle `adaptive-fill-regexp' in paragraphs.
  567. (should
  568. (equal "> a b"
  569. (org-test-with-temp-text "> a\n> b"
  570. (let ((fill-column 5)
  571. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  572. (org-fill-element)
  573. (buffer-string)))))
  574. ;; Special case: Fill first paragraph when point is at an item or
  575. ;; a plain-list or a footnote reference.
  576. (should
  577. (equal "- A B"
  578. (org-test-with-temp-text "- A\n B"
  579. (let ((fill-column 20))
  580. (org-fill-element)
  581. (buffer-string)))))
  582. (should
  583. (equal "[fn:1] A B"
  584. (org-test-with-temp-text "[fn:1] A\nB"
  585. (let ((fill-column 20))
  586. (org-fill-element)
  587. (buffer-string)))))
  588. (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
  589. (let ((fill-column 20))
  590. (org-fill-element)
  591. (should (equal (buffer-string)
  592. "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
  593. ;; Fill contents of `comment-block' elements.
  594. (should
  595. (equal
  596. (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
  597. (let ((fill-column 20))
  598. (forward-line)
  599. (org-fill-element)
  600. (buffer-string)))
  601. "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
  602. ;; Fill `comment' elements.
  603. (should
  604. (equal " # A B"
  605. (org-test-with-temp-text " # A\n # B"
  606. (let ((fill-column 20))
  607. (org-fill-element)
  608. (buffer-string)))))
  609. ;; Do not mix consecutive comments when filling one of them.
  610. (should
  611. (equal "# A B\n\n# C"
  612. (org-test-with-temp-text "# A\n# B\n\n# C"
  613. (let ((fill-column 20))
  614. (org-fill-element)
  615. (buffer-string)))))
  616. ;; Use commented empty lines as separators when filling comments.
  617. (should
  618. (equal "# A B\n#\n# C"
  619. (org-test-with-temp-text "# A\n# B\n#\n# C"
  620. (let ((fill-column 20))
  621. (org-fill-element)
  622. (buffer-string)))))
  623. ;; Handle `adaptive-fill-regexp' in comments.
  624. (should
  625. (equal "# > a b"
  626. (org-test-with-temp-text "# > a\n# > b"
  627. (let ((fill-column 20)
  628. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  629. (org-fill-element)
  630. (buffer-string)))))
  631. ;; Do nothing at affiliated keywords.
  632. (should
  633. (equal "#+NAME: para\nSome\ntext."
  634. (org-test-with-temp-text "#+NAME: para\nSome\ntext."
  635. (let ((fill-column 20))
  636. (org-fill-element)
  637. (buffer-string)))))
  638. ;; Do not move point after table when filling a table.
  639. (should-not
  640. (org-test-with-temp-text "| a | b |\n| c | d |\n"
  641. (forward-char)
  642. (org-fill-element)
  643. (eobp)))
  644. ;; Do not fill "n" macro, with or without arguments, followed by
  645. ;; a dot or a closing parenthesis since it could be confused with
  646. ;; a numbered bullet.
  647. (should-not
  648. (equal "123456789\n{{{n}}}."
  649. (org-test-with-temp-text "123456789 {{{n}}}."
  650. (let ((fill-column 10))
  651. (org-fill-element)
  652. (buffer-string)))))
  653. (should-not
  654. (equal "123456789\n{{{n}}}\)"
  655. (org-test-with-temp-text "123456789 {{{n}}}\)"
  656. (let ((fill-column 10))
  657. (org-fill-element)
  658. (buffer-string)))))
  659. (should-not
  660. (equal "123456789\n{{{n()}}}."
  661. (org-test-with-temp-text "123456789 {{{n()}}}."
  662. (let ((fill-column 10))
  663. (org-fill-element)
  664. (buffer-string)))))
  665. (should-not
  666. (equal "123456789\n{{{n(counter)}}}."
  667. (org-test-with-temp-text "123456789 {{{n(counter)}}}."
  668. (let ((fill-column 10))
  669. (org-fill-element)
  670. (buffer-string))))))
  671. (ert-deftest test-org/auto-fill-function ()
  672. "Test auto-filling features."
  673. ;; Auto fill paragraph.
  674. (should
  675. (equal "12345\n7890"
  676. (org-test-with-temp-text "12345 7890"
  677. (let ((fill-column 5))
  678. (end-of-line)
  679. (org-auto-fill-function)
  680. (buffer-string)))))
  681. ;; Auto fill first paragraph in an item.
  682. (should
  683. (equal "- 12345\n 7890"
  684. (org-test-with-temp-text "- 12345 7890"
  685. (let ((fill-column 7))
  686. (end-of-line)
  687. (org-auto-fill-function)
  688. (buffer-string)))))
  689. ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
  690. (should
  691. (equal "> 12345\n 7890"
  692. (org-test-with-temp-text "> 12345 7890"
  693. (let ((fill-column 10)
  694. (adaptive-fill-regexp "[ \t]*>+[ \t]*")
  695. (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
  696. (end-of-line)
  697. (org-auto-fill-function)
  698. (buffer-string)))))
  699. (should
  700. (equal "> 12345\n> 12345\n> 7890"
  701. (org-test-with-temp-text "> 12345\n> 12345 7890"
  702. (let ((fill-column 10)
  703. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  704. (goto-char (point-max))
  705. (org-auto-fill-function)
  706. (buffer-string)))))
  707. (should-not
  708. (equal " 12345\n *12345\n *12345"
  709. (org-test-with-temp-text " 12345\n *12345 12345"
  710. (let ((fill-column 10)
  711. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  712. (goto-char (point-max))
  713. (org-auto-fill-function)
  714. (buffer-string)))))
  715. ;; Auto fill comments.
  716. (should
  717. (equal " # 12345\n # 7890"
  718. (org-test-with-temp-text " # 12345 7890"
  719. (let ((fill-column 10))
  720. (end-of-line)
  721. (org-auto-fill-function)
  722. (buffer-string)))))
  723. ;; A hash within a line isn't a comment.
  724. (should-not
  725. (equal "12345 # 7890\n# 1"
  726. (org-test-with-temp-text "12345 # 7890 1"
  727. (let ((fill-column 12))
  728. (end-of-line)
  729. (org-auto-fill-function)
  730. (buffer-string)))))
  731. ;; Correctly interpret empty prefix.
  732. (should-not
  733. (equal "# a\n# b\nRegular\n# paragraph"
  734. (org-test-with-temp-text "# a\n# b\nRegular paragraph"
  735. (let ((fill-column 12))
  736. (end-of-line 3)
  737. (org-auto-fill-function)
  738. (buffer-string)))))
  739. ;; Comment block: auto fill contents.
  740. (should
  741. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  742. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  743. (let ((fill-column 5))
  744. (forward-line)
  745. (end-of-line)
  746. (org-auto-fill-function)
  747. (buffer-string)))))
  748. (should
  749. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  750. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  751. (let ((fill-column 5))
  752. (forward-line)
  753. (end-of-line)
  754. (org-auto-fill-function)
  755. (buffer-string)))))
  756. ;; Do not fill if a new item could be created.
  757. (should-not
  758. (equal "12345\n- 90"
  759. (org-test-with-temp-text "12345 - 90"
  760. (let ((fill-column 5))
  761. (end-of-line)
  762. (org-auto-fill-function)
  763. (buffer-string)))))
  764. ;; Do not fill if a line break could be introduced.
  765. (should-not
  766. (equal "123\\\\\n7890"
  767. (org-test-with-temp-text "123\\\\ 7890"
  768. (let ((fill-column 6))
  769. (end-of-line)
  770. (org-auto-fill-function)
  771. (buffer-string)))))
  772. ;; Do not fill affiliated keywords.
  773. (should-not
  774. (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
  775. (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
  776. (let ((fill-column 20))
  777. (end-of-line)
  778. (org-auto-fill-function)
  779. (buffer-string))))))
  780. ;;; Indentation
  781. (ert-deftest test-org/indent-line ()
  782. "Test `org-indent-line' specifications."
  783. ;; Do not indent diary sexps, footnote definitions or headlines.
  784. (should
  785. (zerop
  786. (org-test-with-temp-text "%%(org-calendar-holiday)"
  787. (org-indent-line)
  788. (org-get-indentation))))
  789. (should
  790. (zerop
  791. (org-test-with-temp-text "[fn:1] fn"
  792. (let ((org-adapt-indentation t)) (org-indent-line))
  793. (org-get-indentation))))
  794. (should
  795. (zerop
  796. (org-test-with-temp-text "* H"
  797. (org-indent-line)
  798. (org-get-indentation))))
  799. ;; Do not indent before first headline.
  800. (should
  801. (zerop
  802. (org-test-with-temp-text ""
  803. (org-indent-line)
  804. (org-get-indentation))))
  805. ;; Indent according to headline level otherwise, unless
  806. ;; `org-adapt-indentation' is nil.
  807. (should
  808. (= 2
  809. (org-test-with-temp-text "* H\n<point>A"
  810. (let ((org-adapt-indentation t)) (org-indent-line))
  811. (org-get-indentation))))
  812. (should
  813. (= 2
  814. (org-test-with-temp-text "* H\n<point>\nA"
  815. (let ((org-adapt-indentation t)) (org-indent-line))
  816. (org-get-indentation))))
  817. (should
  818. (zerop
  819. (org-test-with-temp-text "* H\n<point>A"
  820. (let ((org-adapt-indentation nil)) (org-indent-line))
  821. (org-get-indentation))))
  822. ;; Indenting preserves point position.
  823. (should
  824. (org-test-with-temp-text "* H\nA<point>B"
  825. (let ((org-adapt-indentation t)) (org-indent-line))
  826. (looking-at "B")))
  827. ;; Do not change indentation at an item or a LaTeX environment.
  828. (should
  829. (= 1
  830. (org-test-with-temp-text "* H\n<point> - A"
  831. (let ((org-adapt-indentation t)) (org-indent-line))
  832. (org-get-indentation))))
  833. (should
  834. (= 1
  835. (org-test-with-temp-text
  836. "\\begin{equation}\n <point>1+1=2\n\\end{equation}"
  837. (org-indent-line)
  838. (org-get-indentation))))
  839. ;; On blank lines at the end of a list, indent like last element
  840. ;; within it if the line is still in the list. If the last element
  841. ;; is an item, indent like its contents. Otherwise, indent like the
  842. ;; whole list.
  843. (should
  844. (= 4
  845. (org-test-with-temp-text "* H\n- A\n - AA\n<point>"
  846. (let ((org-adapt-indentation t)) (org-indent-line))
  847. (org-get-indentation))))
  848. (should
  849. (= 4
  850. (org-test-with-temp-text "* H\n- A\n -\n\n<point>"
  851. (let ((org-adapt-indentation t)) (org-indent-line))
  852. (org-get-indentation))))
  853. (should
  854. (zerop
  855. (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n<point>"
  856. (let ((org-adapt-indentation t)) (org-indent-line))
  857. (org-get-indentation))))
  858. (should
  859. (= 4
  860. (org-test-with-temp-text "* H\n- A\n - \n<point>"
  861. (let ((org-adapt-indentation t)) (org-indent-line))
  862. (org-get-indentation))))
  863. (should
  864. (= 4
  865. (org-test-with-temp-text
  866. "* H\n - \n #+BEGIN_SRC emacs-lisp\n t\n #+END_SRC\n<point>"
  867. (let ((org-adapt-indentation t)) (org-indent-line))
  868. (org-get-indentation))))
  869. (should
  870. (= 2
  871. (org-test-with-temp-text "- A\n B\n\n<point>"
  872. (let ((org-adapt-indentation nil)) (org-indent-line))
  873. (org-get-indentation))))
  874. (should
  875. (= 2
  876. (org-test-with-temp-text
  877. "- A\n \begin{cases} 1 + 1\n \end{cases}\n\n<point>"
  878. (let ((org-adapt-indentation nil)) (org-indent-line))
  879. (org-get-indentation))))
  880. ;; Likewise, on a blank line at the end of a footnote definition,
  881. ;; indent at column 0 if line belongs to the definition. Otherwise,
  882. ;; indent like the definition itself.
  883. (should
  884. (zerop
  885. (org-test-with-temp-text "* H\n[fn:1] Definition\n<point>"
  886. (let ((org-adapt-indentation t)) (org-indent-line))
  887. (org-get-indentation))))
  888. (should
  889. (zerop
  890. (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n<point>"
  891. (let ((org-adapt-indentation t)) (org-indent-line))
  892. (org-get-indentation))))
  893. ;; After the end of the contents of a greater element, indent like
  894. ;; the beginning of the element.
  895. (should
  896. (= 1
  897. (org-test-with-temp-text
  898. " #+BEGIN_CENTER\n Contents\n<point>#+END_CENTER"
  899. (org-indent-line)
  900. (org-get-indentation))))
  901. ;; On blank lines after a paragraph, indent like its last non-empty
  902. ;; line.
  903. (should
  904. (= 1
  905. (org-test-with-temp-text " Paragraph\n\n<point>"
  906. (org-indent-line)
  907. (org-get-indentation))))
  908. ;; At the first line of an element, indent like previous element's
  909. ;; first line, ignoring footnotes definitions and inline tasks, or
  910. ;; according to parent.
  911. (should
  912. (= 2
  913. (org-test-with-temp-text "A\n\n B\n\nC<point>"
  914. (org-indent-line)
  915. (org-get-indentation))))
  916. (should
  917. (= 1
  918. (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC<point>"
  919. (org-indent-line)
  920. (org-get-indentation))))
  921. (should
  922. (= 1
  923. (org-test-with-temp-text
  924. " #+BEGIN_CENTER\n<point> Contents\n#+END_CENTER"
  925. (org-indent-line)
  926. (org-get-indentation))))
  927. ;; Within code part of a source block, use language major mode if
  928. ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
  929. ;; according to line above.
  930. (should
  931. (= 6
  932. (org-test-with-temp-text
  933. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  934. (let ((org-src-tab-acts-natively t)
  935. (org-edit-src-content-indentation 0))
  936. (org-indent-line))
  937. (org-get-indentation))))
  938. (should
  939. (= 1
  940. (org-test-with-temp-text
  941. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  942. (let ((org-src-tab-acts-natively nil)
  943. (org-edit-src-content-indentation 0))
  944. (org-indent-line))
  945. (org-get-indentation))))
  946. ;; Otherwise, indent like the first non-blank line above.
  947. (should
  948. (zerop
  949. (org-test-with-temp-text
  950. "#+BEGIN_CENTER\nline1\n\n<point> line2\n#+END_CENTER"
  951. (org-indent-line)
  952. (org-get-indentation))))
  953. ;; Align node properties according to `org-property-format'. Handle
  954. ;; nicely empty values.
  955. (should
  956. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  957. (org-test-with-temp-text
  958. "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
  959. (let ((org-property-format "%-10s %s")) (org-indent-line))
  960. (buffer-string))))
  961. (should
  962. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  963. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
  964. (let ((org-property-format "%-10s %s")) (org-indent-line))
  965. (buffer-string)))))
  966. (ert-deftest test-org/indent-region ()
  967. "Test `org-indent-region' specifications."
  968. ;; Indent paragraph.
  969. (should
  970. (equal "A\nB\nC"
  971. (org-test-with-temp-text " A\nB\n C"
  972. (org-indent-region (point-min) (point-max))
  973. (buffer-string))))
  974. ;; Indent greater elements along with their contents.
  975. (should
  976. (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
  977. (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
  978. (org-indent-region (point-min) (point-max))
  979. (buffer-string))))
  980. ;; Ignore contents of verse blocks. Only indent block delimiters.
  981. (should
  982. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  983. (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  984. (org-indent-region (point-min) (point-max))
  985. (buffer-string))))
  986. (should
  987. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  988. (org-test-with-temp-text " #+BEGIN_VERSE\n A\n B\n #+END_VERSE"
  989. (org-indent-region (point-min) (point-max))
  990. (buffer-string))))
  991. ;; Indent example blocks as a single block, unless indentation
  992. ;; should be preserved. In this case only indent the block markers.
  993. (should
  994. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  995. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  996. (org-indent-region (point-min) (point-max))
  997. (buffer-string))))
  998. (should
  999. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1000. (org-test-with-temp-text " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1001. (org-indent-region (point-min) (point-max))
  1002. (buffer-string))))
  1003. (should
  1004. (equal "#+BEGIN_EXAMPLE -i\n A\n B\n#+END_EXAMPLE"
  1005. (org-test-with-temp-text
  1006. " #+BEGIN_EXAMPLE -i\n A\n B\n #+END_EXAMPLE"
  1007. (org-indent-region (point-min) (point-max))
  1008. (buffer-string))))
  1009. (should
  1010. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1011. (org-test-with-temp-text
  1012. " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1013. (let ((org-src-preserve-indentation t))
  1014. (org-indent-region (point-min) (point-max)))
  1015. (buffer-string))))
  1016. ;; Treat export blocks as a whole.
  1017. (should
  1018. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1019. (org-test-with-temp-text "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1020. (org-indent-region (point-min) (point-max))
  1021. (buffer-string))))
  1022. (should
  1023. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1024. (org-test-with-temp-text
  1025. " #+BEGIN_EXPORT latex\n A\n B\n #+END_EXPORT"
  1026. (org-indent-region (point-min) (point-max))
  1027. (buffer-string))))
  1028. ;; Indent according to mode if `org-src-tab-acts-natively' is
  1029. ;; non-nil. Otherwise, do not indent code at all.
  1030. (should
  1031. (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
  1032. (org-test-with-temp-text
  1033. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1034. (let ((org-src-tab-acts-natively t)
  1035. (org-edit-src-content-indentation 0))
  1036. (org-indent-region (point-min) (point-max)))
  1037. (buffer-string))))
  1038. (should
  1039. (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1040. (org-test-with-temp-text
  1041. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1042. (let ((org-src-tab-acts-natively nil)
  1043. (org-edit-src-content-indentation 0))
  1044. (org-indent-region (point-min) (point-max)))
  1045. (buffer-string))))
  1046. ;; Align node properties according to `org-property-format'. Handle
  1047. ;; nicely empty values.
  1048. (should
  1049. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1050. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
  1051. (let ((org-property-format "%-10s %s")
  1052. (org-adapt-indentation nil))
  1053. (org-indent-region (point) (point-max)))
  1054. (buffer-string))))
  1055. (should
  1056. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1057. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
  1058. (let ((org-property-format "%-10s %s")
  1059. (org-adapt-indentation nil))
  1060. (org-indent-region (point) (point-max)))
  1061. (buffer-string))))
  1062. ;; Indent plain lists.
  1063. (should
  1064. (equal "- A\n B\n - C\n\n D"
  1065. (org-test-with-temp-text "- A\n B\n - C\n\n D"
  1066. (org-indent-region (point-min) (point-max))
  1067. (buffer-string))))
  1068. (should
  1069. (equal "- A\n\n- B"
  1070. (org-test-with-temp-text " - A\n\n - B"
  1071. (org-indent-region (point-min) (point-max))
  1072. (buffer-string))))
  1073. ;; Indent footnote definitions.
  1074. (should
  1075. (equal "[fn:1] Definition\n\nDefinition"
  1076. (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
  1077. (org-indent-region (point-min) (point-max))
  1078. (buffer-string))))
  1079. ;; Special case: Start indenting on a blank line.
  1080. (should
  1081. (equal "\nParagraph"
  1082. (org-test-with-temp-text "\n Paragraph"
  1083. (org-indent-region (point-min) (point-max))
  1084. (buffer-string)))))
  1085. ;;; Editing
  1086. (ert-deftest test-org/delete-indentation ()
  1087. "Test `org-delete-indentation' specifications."
  1088. ;; Regular test.
  1089. (should (equal "foo bar"
  1090. (org-test-with-temp-text
  1091. "foo \n bar<point>"
  1092. (org-delete-indentation)
  1093. (buffer-string))))
  1094. ;; With optional argument.
  1095. (should (equal "foo bar"
  1096. (org-test-with-temp-text
  1097. "foo<point> \n bar"
  1098. (org-delete-indentation t)
  1099. (buffer-string))))
  1100. ;; At headline text should be appended to the headline text.
  1101. (should
  1102. (equal"* foo bar :tag:"
  1103. (let (org-auto-align-tags)
  1104. (org-test-with-temp-text
  1105. "* foo :tag:\n bar<point>"
  1106. (org-delete-indentation)
  1107. (buffer-string)))))
  1108. (should
  1109. (equal "* foo bar :tag:"
  1110. (let (org-auto-align-tags)
  1111. (org-test-with-temp-text
  1112. "* foo <point>:tag:\n bar"
  1113. (org-delete-indentation t)
  1114. (buffer-string))))))
  1115. (ert-deftest test-org/return ()
  1116. "Test `org-return' specifications."
  1117. ;; Regular test.
  1118. (should
  1119. (equal "Para\ngraph"
  1120. (org-test-with-temp-text "Para<point>graph"
  1121. (org-return)
  1122. (buffer-string))))
  1123. ;; With optional argument, indent line.
  1124. (should
  1125. (equal " Para\n graph"
  1126. (org-test-with-temp-text " Para<point>graph"
  1127. (org-return t)
  1128. (buffer-string))))
  1129. ;; On a table, call `org-table-next-row'.
  1130. (should
  1131. (org-test-with-temp-text "| <point>a |\n| b |"
  1132. (org-return)
  1133. (looking-at-p "b")))
  1134. ;; Open link or timestamp under point when `org-return-follows-link'
  1135. ;; is non-nil.
  1136. (should
  1137. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1138. (let ((org-return-follows-link t)
  1139. (org-link-search-must-match-exact-headline nil))
  1140. (org-return))
  1141. (looking-at-p "<<target>>")))
  1142. (should-not
  1143. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1144. (let ((org-return-follows-link nil)) (org-return))
  1145. (looking-at-p "<<target>>")))
  1146. (should
  1147. (org-test-with-temp-text "* [[b][a<point>]]\n* b"
  1148. (let ((org-return-follows-link t)) (org-return))
  1149. (looking-at-p "* b")))
  1150. (should
  1151. (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
  1152. (let ((org-return-follows-link t)
  1153. (org-link-search-must-match-exact-headline nil))
  1154. (org-return))
  1155. (looking-at-p "<<target>>")))
  1156. (should-not
  1157. (org-test-with-temp-text "Link [[target]]<point> <<target>>"
  1158. (let ((org-return-follows-link t)
  1159. (org-link-search-must-match-exact-headline nil))
  1160. (org-return))
  1161. (looking-at-p "<<target>>")))
  1162. ;; When `org-return-follows-link' is non-nil, tolerate links and
  1163. ;; timestamps in comments, node properties, etc.
  1164. (should
  1165. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1166. (let ((org-return-follows-link t)
  1167. (org-link-search-must-match-exact-headline nil))
  1168. (org-return))
  1169. (looking-at-p "<<target>>")))
  1170. (should-not
  1171. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1172. (let ((org-return-follows-link nil)) (org-return))
  1173. (looking-at-p "<<target>>")))
  1174. (should-not
  1175. (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
  1176. (let ((org-return-follows-link t)
  1177. (org-link-search-must-match-exact-headline nil))
  1178. (org-return))
  1179. (looking-at-p "<<target>>")))
  1180. ;; Non-nil `org-return-follows-link' ignores read-only state of
  1181. ;; a buffer.
  1182. (should
  1183. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1184. (let ((org-return-follows-link t)
  1185. (org-link-search-must-match-exact-headline nil))
  1186. (setq buffer-read-only t)
  1187. (call-interactively #'org-return))
  1188. (looking-at-p "<<target>>")))
  1189. ;; `org-return-follows-link' handle multi-line lines.
  1190. (should
  1191. (org-test-with-temp-text
  1192. "[[target][This is a very\n long description<point>]]\n <<target>>"
  1193. (let ((org-return-follows-link t)
  1194. (org-link-search-must-match-exact-headline nil))
  1195. (org-return))
  1196. (looking-at-p "<<target>>")))
  1197. (should-not
  1198. (org-test-with-temp-text
  1199. "[[target][This is a very\n long description]]<point>\n <<target>>"
  1200. (let ((org-return-follows-link t)
  1201. (org-link-search-must-match-exact-headline nil))
  1202. (org-return))
  1203. (looking-at-p "<<target>>")))
  1204. ;; However, do not open link when point is in a table.
  1205. (should
  1206. (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
  1207. (let ((org-return-follows-link t)) (org-return))
  1208. (looking-at-p "between")))
  1209. ;; Special case: in a list, when indenting, do not break structure.
  1210. (should
  1211. (equal "- A\n B"
  1212. (org-test-with-temp-text "- A <point>B"
  1213. (org-return t)
  1214. (buffer-string))))
  1215. (should
  1216. (equal "- A\n\n- B"
  1217. (org-test-with-temp-text "- A\n<point>- B"
  1218. (org-return t)
  1219. (buffer-string))))
  1220. ;; On tags part of a headline, add a newline below it instead of
  1221. ;; breaking it.
  1222. (should
  1223. (equal "* H :tag:\n"
  1224. (org-test-with-temp-text "* H :<point>tag:"
  1225. (org-return)
  1226. (buffer-string))))
  1227. ;; Before headline text, add a newline below it instead of breaking
  1228. ;; it.
  1229. (should
  1230. (equal "* TODO H :tag:\n"
  1231. (org-test-with-temp-text "* <point>TODO H :tag:"
  1232. (org-return)
  1233. (buffer-string))))
  1234. (should
  1235. (equal "* TODO [#B] H :tag:\n"
  1236. (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
  1237. (org-return)
  1238. (buffer-string))))
  1239. (should ;TODO are case-sensitive
  1240. (equal "* \nTodo"
  1241. (org-test-with-temp-text "* <point>Todo"
  1242. (org-return)
  1243. (buffer-string))))
  1244. ;; At headline text, break headline text but preserve tags.
  1245. (should
  1246. (equal "* TODO [#B] foo :tag:\nbar"
  1247. (let (org-auto-align-tags)
  1248. (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
  1249. (org-return)
  1250. (buffer-string)))))
  1251. ;; At bol of headline insert newline.
  1252. (should
  1253. (equal "\n* h"
  1254. (org-test-with-temp-text "<point>* h"
  1255. (org-return)
  1256. (buffer-string))))
  1257. ;; Refuse to leave invalid headline in buffer.
  1258. (should
  1259. (equal "* h\n"
  1260. (org-test-with-temp-text "*<point> h"
  1261. (org-return)
  1262. (buffer-string))))
  1263. ;; Before first column or after last one in a table, split the
  1264. ;; table.
  1265. (should
  1266. (equal "| a |\n\n| b |"
  1267. (org-test-with-temp-text "| a |\n<point>| b |"
  1268. (org-return)
  1269. (buffer-string))))
  1270. (should
  1271. (equal "| a |\n\n| b |"
  1272. (org-test-with-temp-text "| a |<point>\n| b |"
  1273. (org-return)
  1274. (buffer-string))))
  1275. ;; Do not auto-fill on hitting <RET> inside a property drawer.
  1276. (should
  1277. (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:"
  1278. (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:"
  1279. (setq-local fill-column 10)
  1280. (auto-fill-mode 1)
  1281. (org-return)
  1282. (buffer-string)))))
  1283. (ert-deftest test-org/with-electric-indent ()
  1284. "Test RET and C-j specifications with `electric-indent-mode' on."
  1285. ;; Call commands interactively, since this is how `newline' knows it
  1286. ;; must run `post-self-insert-hook'.
  1287. ;;
  1288. ;; RET, like `newline', should indent.
  1289. (should
  1290. (equal " Para\n graph"
  1291. (org-test-with-temp-text " Para<point>graph"
  1292. (electric-indent-local-mode 1)
  1293. (call-interactively 'org-return)
  1294. (buffer-string))))
  1295. (should
  1296. (equal "- item1\n item2"
  1297. (org-test-with-temp-text "- item1<point>item2"
  1298. (electric-indent-local-mode 1)
  1299. (call-interactively 'org-return)
  1300. (buffer-string))))
  1301. (should
  1302. (equal "* heading\n body"
  1303. (org-test-with-temp-text "* heading<point>body"
  1304. (electric-indent-local-mode 1)
  1305. (call-interactively 'org-return)
  1306. (buffer-string))))
  1307. ;; C-j, like `electric-newline-and-maybe-indent', should not indent.
  1308. (should
  1309. (equal " Para\ngraph"
  1310. (org-test-with-temp-text " Para<point>graph"
  1311. (electric-indent-local-mode 1)
  1312. (call-interactively 'org-return-and-maybe-indent)
  1313. (buffer-string))))
  1314. (should
  1315. (equal "- item1\nitem2"
  1316. (org-test-with-temp-text "- item1<point>item2"
  1317. (electric-indent-local-mode 1)
  1318. (call-interactively 'org-return-and-maybe-indent)
  1319. (buffer-string))))
  1320. (should
  1321. (equal "* heading\nbody"
  1322. (org-test-with-temp-text "* heading<point>body"
  1323. (electric-indent-local-mode 1)
  1324. (call-interactively 'org-return-and-maybe-indent)
  1325. (buffer-string)))))
  1326. (ert-deftest test-org/without-electric-indent ()
  1327. "Test RET and C-j specifications with `electric-indent-mode' off."
  1328. ;; Call commands interactively, since this is how `newline' knows it
  1329. ;; must run `post-self-insert-hook'.
  1330. ;;
  1331. ;; RET, like `newline', should not indent.
  1332. (should
  1333. (equal " Para\ngraph"
  1334. (org-test-with-temp-text " Para<point>graph"
  1335. (electric-indent-local-mode 0)
  1336. (call-interactively 'org-return)
  1337. (buffer-string))))
  1338. (should
  1339. (equal "- item1\nitem2"
  1340. (org-test-with-temp-text "- item1<point>item2"
  1341. (electric-indent-local-mode 0)
  1342. (call-interactively 'org-return)
  1343. (buffer-string))))
  1344. (should
  1345. (equal "* heading\nbody"
  1346. (org-test-with-temp-text "* heading<point>body"
  1347. (electric-indent-local-mode 0)
  1348. (call-interactively 'org-return)
  1349. (buffer-string))))
  1350. ;; C-j, like `electric-newline-and-maybe-indent', should indent.
  1351. (should
  1352. (equal " Para\n graph"
  1353. (org-test-with-temp-text " Para<point>graph"
  1354. (electric-indent-local-mode 0)
  1355. (call-interactively 'org-return-and-maybe-indent)
  1356. (buffer-string))))
  1357. (should
  1358. (equal "- item1\n item2"
  1359. (org-test-with-temp-text "- item1<point>item2"
  1360. (electric-indent-local-mode 0)
  1361. (call-interactively 'org-return-and-maybe-indent)
  1362. (buffer-string))))
  1363. (should
  1364. (equal "* heading\n body"
  1365. (org-test-with-temp-text "* heading<point>body"
  1366. (electric-indent-local-mode 0)
  1367. (call-interactively 'org-return-and-maybe-indent)
  1368. (buffer-string)))))
  1369. (ert-deftest test-org/meta-return ()
  1370. "Test M-RET (`org-meta-return') specifications."
  1371. ;; In a table field insert a row above.
  1372. (should
  1373. (org-test-with-temp-text "| a |"
  1374. (forward-char)
  1375. (org-meta-return)
  1376. (forward-line -1)
  1377. (looking-at "| |$")))
  1378. ;; In a paragraph change current line into a header.
  1379. (should
  1380. (org-test-with-temp-text "a"
  1381. (org-meta-return)
  1382. (beginning-of-line)
  1383. (looking-at "\* a$")))
  1384. ;; In an item insert an item, in this case above.
  1385. (should
  1386. (org-test-with-temp-text "- a"
  1387. (org-meta-return)
  1388. (beginning-of-line)
  1389. (looking-at "- $")))
  1390. ;; In a drawer and item insert an item, in this case above.
  1391. (should
  1392. (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
  1393. (forward-line)
  1394. (org-meta-return)
  1395. (beginning-of-line)
  1396. (looking-at "- $"))))
  1397. (ert-deftest test-org/insert-heading ()
  1398. "Test `org-insert-heading' specifications."
  1399. ;; In an empty buffer, insert a new headline.
  1400. (should
  1401. (equal "* "
  1402. (org-test-with-temp-text ""
  1403. (org-insert-heading)
  1404. (buffer-string))))
  1405. ;; At the beginning of a line, turn it into a headline.
  1406. (should
  1407. (equal "* P"
  1408. (org-test-with-temp-text "<point>P"
  1409. (org-insert-heading)
  1410. (buffer-string))))
  1411. ;; In the middle of a line, split the line if allowed, otherwise,
  1412. ;; insert the headline at its end.
  1413. (should
  1414. (equal "Para\n* graph"
  1415. (org-test-with-temp-text "Para<point>graph"
  1416. (let ((org-M-RET-may-split-line '((default . t))))
  1417. (org-insert-heading))
  1418. (buffer-string))))
  1419. (should
  1420. (equal "Paragraph\n* "
  1421. (org-test-with-temp-text "Para<point>graph"
  1422. (let ((org-M-RET-may-split-line '((default . nil))))
  1423. (org-insert-heading))
  1424. (buffer-string))))
  1425. ;; At the beginning of a headline, create one above.
  1426. (should
  1427. (equal "* \n* H"
  1428. (org-test-with-temp-text "* H"
  1429. (org-insert-heading)
  1430. (buffer-string))))
  1431. ;; In the middle of a headline, split it if allowed.
  1432. (should
  1433. (equal "* H\n* 1"
  1434. (org-test-with-temp-text "* H<point>1"
  1435. (let ((org-M-RET-may-split-line '((headline . t))))
  1436. (org-insert-heading))
  1437. (buffer-string))))
  1438. (should
  1439. (equal "* H1\n* "
  1440. (org-test-with-temp-text "* H<point>1"
  1441. (let ((org-M-RET-may-split-line '((headline . nil))))
  1442. (org-insert-heading))
  1443. (buffer-string))))
  1444. ;; However, splitting cannot happen on TODO keywords, priorities or
  1445. ;; tags.
  1446. (should
  1447. (equal "* TODO H1\n* "
  1448. (org-test-with-temp-text "* TO<point>DO H1"
  1449. (let ((org-M-RET-may-split-line '((headline . t))))
  1450. (org-insert-heading))
  1451. (buffer-string))))
  1452. (should
  1453. (equal "* [#A] H1\n* "
  1454. (org-test-with-temp-text "* [#<point>A] H1"
  1455. (let ((org-M-RET-may-split-line '((headline . t))))
  1456. (org-insert-heading))
  1457. (buffer-string))))
  1458. (should
  1459. (equal "* H1 :tag:\n* "
  1460. (org-test-with-temp-text "* H1 :ta<point>g:"
  1461. (let ((org-M-RET-may-split-line '((headline . t))))
  1462. (org-insert-heading))
  1463. (buffer-string))))
  1464. ;; New headline level depends on the level of the headline above.
  1465. (should
  1466. (equal "** H\n** P"
  1467. (org-test-with-temp-text "** H\n<point>P"
  1468. (org-insert-heading)
  1469. (buffer-string))))
  1470. (should
  1471. (equal "** H\nPara\n** graph"
  1472. (org-test-with-temp-text "** H\nPara<point>graph"
  1473. (let ((org-M-RET-may-split-line '((default . t))))
  1474. (org-insert-heading))
  1475. (buffer-string))))
  1476. (should
  1477. (equal "** \n** H"
  1478. (org-test-with-temp-text "** H"
  1479. (org-insert-heading)
  1480. (buffer-string))))
  1481. ;; When called with one universal argument, insert a new headline at
  1482. ;; the end of the current subtree, independently on the position of
  1483. ;; point.
  1484. (should
  1485. (equal
  1486. "* H1\n** H2\n* "
  1487. (org-test-with-temp-text "* H1\n** H2"
  1488. (let ((org-insert-heading-respect-content nil))
  1489. (org-insert-heading '(4)))
  1490. (buffer-string))))
  1491. (should
  1492. (equal
  1493. "* H1\n** H2\n* "
  1494. (org-test-with-temp-text "* H<point>1\n** H2"
  1495. (let ((org-insert-heading-respect-content nil))
  1496. (org-insert-heading '(4)))
  1497. (buffer-string))))
  1498. ;; When called with two universal arguments, insert a new headline
  1499. ;; at the end of the grandparent subtree.
  1500. (should
  1501. (equal "* H1\n** H3\n- item\n** H2\n** "
  1502. (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
  1503. (let ((org-insert-heading-respect-content nil))
  1504. (org-insert-heading '(16)))
  1505. (buffer-string))))
  1506. ;; When optional TOP-LEVEL argument is non-nil, always insert
  1507. ;; a level 1 heading.
  1508. (should
  1509. (equal "* H1\n** H2\n* "
  1510. (org-test-with-temp-text "* H1\n** H2<point>"
  1511. (org-insert-heading nil nil t)
  1512. (buffer-string))))
  1513. (should
  1514. (equal "* H1\n- item\n* "
  1515. (org-test-with-temp-text "* H1\n- item<point>"
  1516. (org-insert-heading nil nil t)
  1517. (buffer-string))))
  1518. ;; Obey `org-blank-before-new-entry'.
  1519. (should
  1520. (equal "* H1\n\n* "
  1521. (org-test-with-temp-text "* H1<point>"
  1522. (let ((org-blank-before-new-entry '((heading . t))))
  1523. (org-insert-heading))
  1524. (buffer-string))))
  1525. (should
  1526. (equal "* H1\n* "
  1527. (org-test-with-temp-text "* H1<point>"
  1528. (let ((org-blank-before-new-entry '((heading . nil))))
  1529. (org-insert-heading))
  1530. (buffer-string))))
  1531. (should
  1532. (equal "* H1\n* H2\n* "
  1533. (org-test-with-temp-text "* H1\n* H2<point>"
  1534. (let ((org-blank-before-new-entry '((heading . auto))))
  1535. (org-insert-heading))
  1536. (buffer-string))))
  1537. (should
  1538. (equal "* H1\n\n* H2\n\n* "
  1539. (org-test-with-temp-text "* H1\n\n* H2<point>"
  1540. (let ((org-blank-before-new-entry '((heading . auto))))
  1541. (org-insert-heading))
  1542. (buffer-string))))
  1543. ;; Corner case: correctly insert a headline after an empty one.
  1544. (should
  1545. (equal "* \n* "
  1546. (org-test-with-temp-text "* <point>"
  1547. (org-insert-heading)
  1548. (buffer-string))))
  1549. (should
  1550. (org-test-with-temp-text "* <point>\n"
  1551. (org-insert-heading)
  1552. (looking-at-p "\n\\'")))
  1553. ;; Do not insert spurious headlines when inserting a new headline.
  1554. (should
  1555. (equal "* H1\n* H2\n* \n"
  1556. (org-test-with-temp-text "* H1\n* H2<point>\n"
  1557. (org-insert-heading)
  1558. (buffer-string))))
  1559. ;; Preserve visibility at beginning of line. In particular, when
  1560. ;; removing spurious blank lines, do not visually merge heading with
  1561. ;; the line visible above.
  1562. (should-not
  1563. (org-test-with-temp-text "* H1<point>\nContents\n\n* H2\n"
  1564. (org-overview)
  1565. (let ((org-blank-before-new-entry '((heading . nil))))
  1566. (org-insert-heading '(4)))
  1567. (invisible-p (line-end-position 0))))
  1568. ;; Properly handle empty lines when forcing a headline below current
  1569. ;; one.
  1570. (should
  1571. (equal "* H1\n\n* H\n\n* "
  1572. (org-test-with-temp-text "* H1\n\n* H<point>"
  1573. (let ((org-blank-before-new-entry '((heading . t))))
  1574. (org-insert-heading '(4))
  1575. (buffer-string))))))
  1576. (ert-deftest test-org/insert-todo-heading-respect-content ()
  1577. "Test `org-insert-todo-heading-respect-content' specifications."
  1578. ;; Create a TODO heading.
  1579. (should
  1580. (org-test-with-temp-text "* H1\n Body"
  1581. (org-insert-todo-heading-respect-content)
  1582. (nth 2 (org-heading-components))))
  1583. ;; Add headline at the end of the first subtree
  1584. (should
  1585. (equal
  1586. "* TODO "
  1587. (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
  1588. (org-insert-todo-heading-respect-content)
  1589. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1590. ;; In a list, do not create a new item.
  1591. (should
  1592. (equal
  1593. "* TODO "
  1594. (org-test-with-temp-text "* H\n- an item\n- another one"
  1595. (search-forward "an ")
  1596. (org-insert-todo-heading-respect-content)
  1597. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1598. ;; Use the same TODO keyword as current heading.
  1599. (should
  1600. (equal
  1601. "* TODO \n"
  1602. (org-test-with-temp-text "* TODO\n** WAITING\n"
  1603. (org-insert-todo-heading-respect-content)
  1604. (buffer-substring-no-properties (line-beginning-position) (point-max))))))
  1605. (ert-deftest test-org/clone-with-time-shift ()
  1606. "Test `org-clone-subtree-with-time-shift'."
  1607. ;; Raise an error before first heading.
  1608. (should-error
  1609. (org-test-with-temp-text ""
  1610. (org-clone-subtree-with-time-shift 1)))
  1611. ;; Raise an error on invalid number of clones.
  1612. (should-error
  1613. (org-test-with-temp-text "* Clone me"
  1614. (org-clone-subtree-with-time-shift -1)))
  1615. ;; Clone non-repeating once.
  1616. (should
  1617. (equal "\
  1618. * H1\n<2015-06-21>
  1619. * H1\n<2015-06-23>
  1620. "
  1621. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1622. (org-clone-subtree-with-time-shift 1 "+2d")
  1623. (replace-regexp-in-string
  1624. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1625. nil nil 1))))
  1626. ;; Clone repeating once.
  1627. (should
  1628. (equal "\
  1629. * H1\n<2015-06-21>
  1630. * H1\n<2015-06-23>
  1631. * H1\n<2015-06-25 +1w>
  1632. "
  1633. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1634. (org-clone-subtree-with-time-shift 1 "+2d")
  1635. (replace-regexp-in-string
  1636. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1637. nil nil 1))))
  1638. ;; Clone repeating once in backward.
  1639. (should
  1640. (equal "\
  1641. * H1\n<2015-06-21>
  1642. * H1\n<2015-06-19>
  1643. * H1\n<2015-06-17 +1w>
  1644. "
  1645. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1646. (org-clone-subtree-with-time-shift 1 "-2d")
  1647. (replace-regexp-in-string
  1648. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1649. nil nil 1))))
  1650. ;; Clone non-repeating zero times.
  1651. (should
  1652. (equal "\
  1653. * H1\n<2015-06-21>
  1654. "
  1655. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1656. (org-clone-subtree-with-time-shift 0 "+2d")
  1657. (replace-regexp-in-string
  1658. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1659. nil nil 1))))
  1660. ;; Clone repeating "zero" times.
  1661. (should
  1662. (equal "\
  1663. * H1\n<2015-06-21>
  1664. * H1\n<2015-06-23 +1w>
  1665. "
  1666. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1667. (org-clone-subtree-with-time-shift 0 "+2d")
  1668. (replace-regexp-in-string
  1669. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1670. nil nil 1))))
  1671. ;; Clone with blank SHIFT argument.
  1672. (should
  1673. (string-prefix-p
  1674. "* H <2012-03-29"
  1675. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1676. (org-clone-subtree-with-time-shift 1 "")
  1677. (buffer-substring-no-properties (line-beginning-position 2)
  1678. (line-end-position 2)))))
  1679. ;; Find time stamps before point. If SHIFT is not specified, ask
  1680. ;; for a time shift.
  1681. (should
  1682. (string-prefix-p
  1683. "* H <2012-03-30"
  1684. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1685. (org-clone-subtree-with-time-shift 1 "+1d")
  1686. (buffer-substring-no-properties (line-beginning-position 2)
  1687. (line-end-position 2)))))
  1688. (should
  1689. (string-prefix-p
  1690. "* H <2014-03-05"
  1691. (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
  1692. (cl-letf (((symbol-function 'read-from-minibuffer)
  1693. (lambda (&rest args) "+1d")))
  1694. (org-clone-subtree-with-time-shift 1))
  1695. (buffer-substring-no-properties (line-beginning-position 2)
  1696. (line-end-position 2))))))
  1697. ;;; Fixed-Width Areas
  1698. (ert-deftest test-org/toggle-fixed-width ()
  1699. "Test `org-toggle-fixed-width' specifications."
  1700. ;; No region: Toggle on fixed-width marker in paragraphs.
  1701. (should
  1702. (equal ": A"
  1703. (org-test-with-temp-text "A"
  1704. (org-toggle-fixed-width)
  1705. (buffer-string))))
  1706. ;; No region: Toggle off fixed-width markers in fixed-width areas.
  1707. (should
  1708. (equal "A"
  1709. (org-test-with-temp-text ": A"
  1710. (org-toggle-fixed-width)
  1711. (buffer-string))))
  1712. ;; No region: Toggle on marker in blank lines after elements or just
  1713. ;; after a headline.
  1714. (should
  1715. (equal "* H\n: "
  1716. (org-test-with-temp-text "* H\n"
  1717. (forward-line)
  1718. (org-toggle-fixed-width)
  1719. (buffer-string))))
  1720. (should
  1721. (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
  1722. (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
  1723. (goto-char (point-max))
  1724. (org-toggle-fixed-width)
  1725. (buffer-string))))
  1726. ;; No region: Toggle on marker in front of one line elements (e.g.,
  1727. ;; headlines, clocks)
  1728. (should
  1729. (equal ": * Headline"
  1730. (org-test-with-temp-text "* Headline"
  1731. (org-toggle-fixed-width)
  1732. (buffer-string))))
  1733. (should
  1734. (equal ": #+KEYWORD: value"
  1735. (org-test-with-temp-text "#+KEYWORD: value"
  1736. (org-toggle-fixed-width)
  1737. (buffer-string))))
  1738. ;; No region: error in other situations.
  1739. (should-error
  1740. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
  1741. (forward-line)
  1742. (org-toggle-fixed-width)
  1743. (buffer-string)))
  1744. ;; No region: Indentation is preserved.
  1745. (should
  1746. (equal "- A\n : B"
  1747. (org-test-with-temp-text "- A\n B"
  1748. (forward-line)
  1749. (org-toggle-fixed-width)
  1750. (buffer-string))))
  1751. ;; Region: If it contains only fixed-width elements and blank lines,
  1752. ;; toggle off fixed-width markup.
  1753. (should
  1754. (equal "A\n\nB"
  1755. (org-test-with-temp-text ": A\n\n: B"
  1756. (transient-mark-mode 1)
  1757. (push-mark (point) t t)
  1758. (goto-char (point-max))
  1759. (org-toggle-fixed-width)
  1760. (buffer-string))))
  1761. ;; Region: If it contains anything else, toggle on fixed-width but
  1762. ;; not on fixed-width areas.
  1763. (should
  1764. (equal ": A\n: \n: B\n: \n: C"
  1765. (org-test-with-temp-text "A\n\n: B\n\nC"
  1766. (transient-mark-mode 1)
  1767. (push-mark (point) t t)
  1768. (goto-char (point-max))
  1769. (org-toggle-fixed-width)
  1770. (buffer-string))))
  1771. ;; Region: Ignore blank lines at its end, unless it contains only
  1772. ;; such lines.
  1773. (should
  1774. (equal ": A\n\n"
  1775. (org-test-with-temp-text "A\n\n"
  1776. (transient-mark-mode 1)
  1777. (push-mark (point) t t)
  1778. (goto-char (point-max))
  1779. (org-toggle-fixed-width)
  1780. (buffer-string))))
  1781. (should
  1782. (equal ": \n: \n"
  1783. (org-test-with-temp-text "\n\n"
  1784. (transient-mark-mode 1)
  1785. (push-mark (point) t t)
  1786. (goto-char (point-max))
  1787. (org-toggle-fixed-width)
  1788. (buffer-string)))))
  1789. (ert-deftest test-org/kill-line ()
  1790. "Test `org-kill-line' specifications."
  1791. ;; At the beginning of a line, kill whole line.
  1792. (should
  1793. (equal ""
  1794. (org-test-with-temp-text "abc"
  1795. (org-kill-line)
  1796. (buffer-string))))
  1797. ;; In the middle of a line, kill line until its end.
  1798. (should
  1799. (equal "a"
  1800. (org-test-with-temp-text "a<point>bc"
  1801. (org-kill-line)
  1802. (buffer-string))))
  1803. ;; Do not kill newline character.
  1804. (should
  1805. (equal "\n123"
  1806. (org-test-with-temp-text "abc\n123"
  1807. (org-kill-line)
  1808. (buffer-string))))
  1809. (should
  1810. (equal "a\n123"
  1811. (org-test-with-temp-text "a<point>bc\n123"
  1812. (org-kill-line)
  1813. (buffer-string))))
  1814. ;; When `org-special-ctrl-k' is non-nil and point is at a headline,
  1815. ;; kill until tags.
  1816. (should
  1817. (equal "* A :tag:"
  1818. (org-test-with-temp-text "* A<point>B :tag:"
  1819. (let ((org-special-ctrl-k t)
  1820. (org-tags-column 0))
  1821. (org-kill-line))
  1822. (buffer-string))))
  1823. ;; If point is on tags, only kill part left until the end of line.
  1824. (should
  1825. (equal "* A :tag:"
  1826. (org-test-with-temp-text "* A :tag:<point>tag2:"
  1827. (let ((org-special-ctrl-k t)
  1828. (org-tags-column 0))
  1829. (org-kill-line))
  1830. (buffer-string))))
  1831. ;; However, if point is at the beginning of the line, kill whole
  1832. ;; headline.
  1833. (should
  1834. (equal ""
  1835. (org-test-with-temp-text "* AB :tag:"
  1836. (let ((org-special-ctrl-k t)
  1837. (org-tags-column 0))
  1838. (org-kill-line))
  1839. (buffer-string))))
  1840. ;; When `org-ctrl-k-protect-subtree' is non-nil, and point is in
  1841. ;; invisible text, ask before removing it. When set to `error',
  1842. ;; throw an error.
  1843. (should-error
  1844. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  1845. (org-overview)
  1846. (let ((org-special-ctrl-k nil)
  1847. (org-ctrl-k-protect-subtree t))
  1848. (cl-letf (((symbol-function 'y-or-n-p) 'ignore))
  1849. (org-kill-line)))))
  1850. (should-error
  1851. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  1852. (org-overview)
  1853. (let ((org-special-ctrl-k nil)
  1854. (org-ctrl-k-protect-subtree 'error))
  1855. (org-kill-line)))))
  1856. ;;; Headline
  1857. (ert-deftest test-org/get-heading ()
  1858. "Test `org-get-heading' specifications."
  1859. ;; Return current heading, even if point is not on it.
  1860. (should
  1861. (equal "H"
  1862. (org-test-with-temp-text "* H"
  1863. (org-get-heading))))
  1864. (should
  1865. (equal "H"
  1866. (org-test-with-temp-text "* H\nText<point>"
  1867. (org-get-heading))))
  1868. ;; Without any optional argument, return TODO keyword, priority
  1869. ;; cookie, COMMENT keyword and tags.
  1870. (should
  1871. (equal "TODO H"
  1872. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  1873. (org-get-heading))))
  1874. (should
  1875. (equal "[#A] H"
  1876. (org-test-with-temp-text "* [#A] H"
  1877. (org-get-heading))))
  1878. (should
  1879. (equal "COMMENT H"
  1880. (org-test-with-temp-text "* COMMENT H"
  1881. (org-get-heading))))
  1882. (should
  1883. (equal "H :tag:"
  1884. (org-test-with-temp-text "* H :tag:"
  1885. (org-get-heading))))
  1886. ;; With NO-TAGS argument, ignore tags.
  1887. (should
  1888. (equal "TODO H"
  1889. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  1890. (org-get-heading t))))
  1891. (should
  1892. (equal "H"
  1893. (org-test-with-temp-text "* H :tag:"
  1894. (org-get-heading t))))
  1895. ;; With NO-TODO, ignore TODO keyword.
  1896. (should
  1897. (equal "H"
  1898. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  1899. (org-get-heading nil t))))
  1900. (should
  1901. (equal "H :tag:"
  1902. (org-test-with-temp-text "* H :tag:"
  1903. (org-get-heading nil t))))
  1904. ;; TODO keywords are case-sensitive.
  1905. (should
  1906. (equal "Todo H"
  1907. (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
  1908. (org-get-heading nil t))))
  1909. ;; With NO-PRIORITY, ignore priority.
  1910. (should
  1911. (equal "H"
  1912. (org-test-with-temp-text "* [#A] H"
  1913. (org-get-heading nil nil t))))
  1914. (should
  1915. (equal "H"
  1916. (org-test-with-temp-text "* H"
  1917. (org-get-heading nil nil t))))
  1918. (should
  1919. (equal "TODO H"
  1920. (org-test-with-temp-text "* TODO [#A] H"
  1921. (org-get-heading nil nil t))))
  1922. ;; With NO-COMMENT, ignore COMMENT keyword.
  1923. (should
  1924. (equal "H"
  1925. (org-test-with-temp-text "* COMMENT H"
  1926. (org-get-heading nil nil nil t))))
  1927. (should
  1928. (equal "H"
  1929. (org-test-with-temp-text "* H"
  1930. (org-get-heading nil nil nil t))))
  1931. (should
  1932. (equal "TODO [#A] H"
  1933. (org-test-with-temp-text "* TODO [#A] COMMENT H"
  1934. (org-get-heading nil nil nil t))))
  1935. ;; On an empty headline, return value is consistent.
  1936. (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
  1937. (should (equal "" (org-test-with-temp-text "* " (org-get-heading t))))
  1938. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t))))
  1939. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t))))
  1940. (should
  1941. (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t)))))
  1942. (ert-deftest test-org/in-commented-heading-p ()
  1943. "Test `org-in-commented-heading-p' specifications."
  1944. ;; Commented headline.
  1945. (should
  1946. (org-test-with-temp-text "* COMMENT Headline\nBody"
  1947. (goto-char (point-max))
  1948. (org-in-commented-heading-p)))
  1949. ;; Commented ancestor.
  1950. (should
  1951. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  1952. (goto-char (point-max))
  1953. (org-in-commented-heading-p)))
  1954. ;; Comment keyword is case-sensitive.
  1955. (should-not
  1956. (org-test-with-temp-text "* Comment Headline\nBody"
  1957. (goto-char (point-max))
  1958. (org-in-commented-heading-p)))
  1959. ;; Keyword is standalone.
  1960. (should-not
  1961. (org-test-with-temp-text "* COMMENTHeadline\nBody"
  1962. (goto-char (point-max))
  1963. (org-in-commented-heading-p)))
  1964. ;; Optional argument.
  1965. (should-not
  1966. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  1967. (goto-char (point-max))
  1968. (org-in-commented-heading-p t))))
  1969. (ert-deftest test-org/entry-blocked-p ()
  1970. ;; Check other dependencies.
  1971. (should
  1972. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  1973. (let ((org-enforce-todo-dependencies t)
  1974. (org-blocker-hook
  1975. '(org-block-todo-from-children-or-siblings-or-parent)))
  1976. (org-entry-blocked-p))))
  1977. (should-not
  1978. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  1979. (let ((org-enforce-todo-dependencies t)
  1980. (org-blocker-hook
  1981. '(org-block-todo-from-children-or-siblings-or-parent)))
  1982. (org-entry-blocked-p))))
  1983. ;; Entry without a TODO keyword or with a DONE keyword cannot be
  1984. ;; blocked.
  1985. (should-not
  1986. (org-test-with-temp-text "* Blocked\n** TODO one"
  1987. (let ((org-enforce-todo-dependencies t)
  1988. (org-blocker-hook
  1989. '(org-block-todo-from-children-or-siblings-or-parent)))
  1990. (org-entry-blocked-p))))
  1991. (should-not
  1992. (org-test-with-temp-text "* DONE Blocked\n** TODO one"
  1993. (let ((org-enforce-todo-dependencies t)
  1994. (org-blocker-hook
  1995. '(org-block-todo-from-children-or-siblings-or-parent)))
  1996. (org-entry-blocked-p))))
  1997. ;; Follow :ORDERED: specifications.
  1998. (should
  1999. (org-test-with-temp-text
  2000. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
  2001. (let ((org-enforce-todo-dependencies t)
  2002. (org-blocker-hook
  2003. '(org-block-todo-from-children-or-siblings-or-parent)))
  2004. (org-entry-blocked-p))))
  2005. (should-not
  2006. (org-test-with-temp-text
  2007. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
  2008. (let ((org-enforce-todo-dependencies t)
  2009. (org-blocker-hook
  2010. '(org-block-todo-from-children-or-siblings-or-parent)))
  2011. (org-entry-blocked-p)))))
  2012. (ert-deftest test-org/get-outline-path ()
  2013. "Test `org-get-outline-path' specifications."
  2014. ;; Top-level headlines have no outline path.
  2015. (should-not
  2016. (org-test-with-temp-text "* H"
  2017. (org-get-outline-path)))
  2018. ;; Otherwise, outline path is the path leading to the headline.
  2019. (should
  2020. (equal '("H")
  2021. (org-test-with-temp-text "* H\n** S<point>"
  2022. (org-get-outline-path))))
  2023. ;; Find path even when point is not on a headline.
  2024. (should
  2025. (equal '("H")
  2026. (org-test-with-temp-text "* H\n** S\nText<point>"
  2027. (org-get-outline-path))))
  2028. ;; TODO keywords, tags and statistics cookies are ignored.
  2029. (should
  2030. (equal '("H")
  2031. (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
  2032. (org-get-outline-path))))
  2033. ;; Links are replaced with their description or their path.
  2034. (should
  2035. (equal '("Org")
  2036. (org-test-with-temp-text
  2037. "* [[https://orgmode.org][Org]]\n** S<point>"
  2038. (org-get-outline-path))))
  2039. (should
  2040. (equal '("https://orgmode.org")
  2041. (org-test-with-temp-text
  2042. "* [[https://orgmode.org]]\n** S<point>"
  2043. (org-get-outline-path))))
  2044. ;; When WITH-SELF is non-nil, include current heading.
  2045. (should
  2046. (equal '("H")
  2047. (org-test-with-temp-text "* H"
  2048. (org-get-outline-path t))))
  2049. (should
  2050. (equal '("H" "S")
  2051. (org-test-with-temp-text "* H\n** S\nText<point>"
  2052. (org-get-outline-path t))))
  2053. ;; Using cache is transparent to the user.
  2054. (should
  2055. (equal '("H")
  2056. (org-test-with-temp-text "* H\n** S<point>"
  2057. (setq org-outline-path-cache nil)
  2058. (org-get-outline-path nil t))))
  2059. ;; Do not corrupt cache when finding outline path in distant part of
  2060. ;; the buffer.
  2061. (should
  2062. (equal '("H2")
  2063. (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
  2064. (setq org-outline-path-cache nil)
  2065. (org-get-outline-path nil t)
  2066. (search-forward "S2")
  2067. (org-get-outline-path nil t))))
  2068. ;; Do not choke on empty headlines.
  2069. (should
  2070. (org-test-with-temp-text "* H\n** <point>"
  2071. (org-get-outline-path)))
  2072. (should
  2073. (org-test-with-temp-text "* \n** H<point>"
  2074. (org-get-outline-path))))
  2075. (ert-deftest test-org/format-outline-path ()
  2076. "Test `org-format-outline-path' specifications."
  2077. (should
  2078. (string= (org-format-outline-path (list "one" "two" "three"))
  2079. "one/two/three"))
  2080. ;; Empty path.
  2081. (should
  2082. (string= (org-format-outline-path '())
  2083. ""))
  2084. (should
  2085. (string= (org-format-outline-path '(nil))
  2086. ""))
  2087. ;; Empty path and prefix.
  2088. (should
  2089. (string= (org-format-outline-path '() nil ">>")
  2090. ">>"))
  2091. ;; Trailing whitespace in headings.
  2092. (should
  2093. (string= (org-format-outline-path (list "one\t" "tw o " "three "))
  2094. "one/tw o/three"))
  2095. ;; Non-default prefix and separators.
  2096. (should
  2097. (string= (org-format-outline-path (list "one" "two" "three") nil ">>" "|")
  2098. ">>|one|two|three"))
  2099. ;; Truncate.
  2100. (should
  2101. (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
  2102. "one/two/.."))
  2103. ;; Give a very narrow width.
  2104. (should
  2105. (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
  2106. "on"))
  2107. ;; Give a prefix that extends beyond the width.
  2108. (should
  2109. (string= (org-format-outline-path (list "one" "two" "three" "four") 10
  2110. ">>>>>>>>>>")
  2111. ">>>>>>>>..")))
  2112. (ert-deftest test-org/map-entries ()
  2113. "Test `org-map-entries' specifications."
  2114. ;; Full match.
  2115. (should
  2116. (equal '(1 11)
  2117. (org-test-with-temp-text "* Level 1\n** Level 2"
  2118. (org-map-entries #'point))))
  2119. ;; Level match.
  2120. (should
  2121. (equal '(1)
  2122. (org-test-with-temp-text "* Level 1\n** Level 2"
  2123. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL=1")))))
  2124. (should
  2125. (equal '(11)
  2126. (org-test-with-temp-text "* Level 1\n** Level 2"
  2127. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL>1")))))
  2128. ;; Tag match.
  2129. (should
  2130. (equal '(11)
  2131. (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
  2132. (org-map-entries #'point "yes"))))
  2133. (should
  2134. (equal '(14)
  2135. (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
  2136. (org-map-entries #'point "+yes-a"))))
  2137. (should
  2138. (equal '(11 23)
  2139. (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
  2140. (org-map-entries #'point "{yes?}"))))
  2141. ;; Priority match.
  2142. (should
  2143. (equal '(1)
  2144. (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
  2145. (org-map-entries #'point "PRIORITY=\"A\""))))
  2146. ;; Date match.
  2147. (should
  2148. (equal '(36)
  2149. (org-test-with-temp-text "
  2150. * H1
  2151. SCHEDULED: <2012-03-29 thu.>
  2152. * H2
  2153. SCHEDULED: <2014-03-04 tue.>"
  2154. (org-map-entries #'point "SCHEDULED=\"<2014-03-04 tue.>\""))))
  2155. (should
  2156. (equal '(2)
  2157. (org-test-with-temp-text "
  2158. * H1
  2159. SCHEDULED: <2012-03-29 thu.>
  2160. * H2
  2161. SCHEDULED: <2014-03-04 tue.>"
  2162. (org-map-entries #'point "SCHEDULED<\"<2013-01-01>\""))))
  2163. ;; Regular property match.
  2164. (should
  2165. (equal '(2)
  2166. (org-test-with-temp-text "
  2167. * H1
  2168. :PROPERTIES:
  2169. :TEST: 1
  2170. :END:
  2171. * H2
  2172. :PROPERTIES:
  2173. :TEST: 2
  2174. :END:"
  2175. (org-map-entries #'point "TEST=1"))))
  2176. ;; Multiple criteria.
  2177. (should
  2178. (equal '(23)
  2179. (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
  2180. (let (org-odd-levels-only
  2181. (org-use-tag-inheritance nil))
  2182. (org-map-entries #'point "yes+LEVEL=1")))))
  2183. ;; "or" criteria.
  2184. (should
  2185. (equal '(12 24)
  2186. (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
  2187. (let (org-odd-levels-only)
  2188. (org-map-entries #'point "LEVEL=2|no")))))
  2189. (should
  2190. (equal '(1 12)
  2191. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
  2192. (let (org-odd-levels-only)
  2193. (org-map-entries #'point "yes|no")))))
  2194. ;; "and" criteria.
  2195. (should
  2196. (equal '(22)
  2197. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
  2198. (let (org-odd-levels-only)
  2199. (org-map-entries #'point "yes&no"))))))
  2200. (ert-deftest test-org/edit-headline ()
  2201. "Test `org-edit-headline' specifications."
  2202. (should
  2203. (equal "* B"
  2204. (org-test-with-temp-text "* A"
  2205. (org-edit-headline "B")
  2206. (buffer-string))))
  2207. ;; Handle empty headings.
  2208. (should
  2209. (equal "* "
  2210. (org-test-with-temp-text "* A"
  2211. (org-edit-headline "")
  2212. (buffer-string))))
  2213. (should
  2214. (equal "* A"
  2215. (org-test-with-temp-text "* "
  2216. (org-edit-headline "A")
  2217. (buffer-string))))
  2218. ;; Handle TODO keywords and priority cookies.
  2219. (should
  2220. (equal "* TODO B"
  2221. (org-test-with-temp-text "* TODO A"
  2222. (org-edit-headline "B")
  2223. (buffer-string))))
  2224. (should
  2225. (equal "* [#A] B"
  2226. (org-test-with-temp-text "* [#A] A"
  2227. (org-edit-headline "B")
  2228. (buffer-string))))
  2229. (should
  2230. (equal "* TODO [#A] B"
  2231. (org-test-with-temp-text "* TODO [#A] A"
  2232. (org-edit-headline "B")
  2233. (buffer-string))))
  2234. ;; Handle tags.
  2235. (equal "* B :tag:"
  2236. (org-test-with-temp-text "* A :tag:"
  2237. (let ((org-tags-column 4)) (org-edit-headline "B"))
  2238. (buffer-string))))
  2239. ;;; Keywords
  2240. (ert-deftest test-org/set-regexps-and-options ()
  2241. "Test `org-set-regexps-and-options' specifications."
  2242. ;; TAGS keyword.
  2243. (should
  2244. (equal '(("A"))
  2245. (let ((org-tag-alist '(("A")))
  2246. (org-tag-persistent-alist nil))
  2247. (org-test-with-temp-text ""
  2248. (org-mode-restart)
  2249. org-current-tag-alist))))
  2250. (should
  2251. (equal '(("B"))
  2252. (let ((org-tag-alist '(("A")))
  2253. (org-tag-persistent-alist nil))
  2254. (org-test-with-temp-text "#+TAGS: B"
  2255. (org-mode-restart)
  2256. org-current-tag-alist))))
  2257. (should
  2258. (equal '(("C") ("B"))
  2259. (let ((org-tag-alist '(("A")))
  2260. (org-tag-persistent-alist '(("C"))))
  2261. (org-test-with-temp-text "#+TAGS: B"
  2262. (org-mode-restart)
  2263. org-current-tag-alist))))
  2264. (should
  2265. (equal '(("B"))
  2266. (let ((org-tag-alist '(("A")))
  2267. (org-tag-persistent-alist '(("C"))))
  2268. (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
  2269. (org-mode-restart)
  2270. org-current-tag-alist))))
  2271. (should
  2272. (equal '(("A" . ?a) ("B") ("C"))
  2273. (let ((org-tag-persistant-alist nil))
  2274. (org-test-with-temp-text "#+TAGS: A(a) B C"
  2275. (org-mode-restart)
  2276. org-current-tag-alist))))
  2277. (should
  2278. (equal '(("A") (:newline) ("B"))
  2279. (let ((org-tag-persistent-alist nil))
  2280. (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
  2281. (org-mode-restart)
  2282. org-current-tag-alist))))
  2283. (should
  2284. (equal '((:startgroup) ("A") ("B") (:endgroup) ("C"))
  2285. (let ((org-tag-persistent-alist nil))
  2286. (org-test-with-temp-text "#+TAGS: { A B } C"
  2287. (org-mode-restart)
  2288. org-current-tag-alist))))
  2289. (should
  2290. (equal '((:startgroup) ("A") (:grouptags) ("B") ("C") (:endgroup))
  2291. (let ((org-tag-persistent-alist nil))
  2292. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2293. (org-mode-restart)
  2294. org-current-tag-alist))))
  2295. (should
  2296. (equal '(("A" "B" "C"))
  2297. (let ((org-tag-persistent-alist nil))
  2298. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2299. (org-mode-restart)
  2300. org-tag-groups-alist))))
  2301. (should
  2302. (equal '((:startgrouptag) ("A") (:grouptags) ("B") ("C") (:endgrouptag))
  2303. (let ((org-tag-persistent-alist nil))
  2304. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2305. (org-mode-restart)
  2306. org-current-tag-alist))))
  2307. (should
  2308. (equal '(("A" "B" "C"))
  2309. (let ((org-tag-persistent-alist nil))
  2310. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2311. (org-mode-restart)
  2312. org-tag-groups-alist))))
  2313. ;; FILETAGS keyword.
  2314. (should
  2315. (equal '("A" "B" "C")
  2316. (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
  2317. (org-mode-restart)
  2318. org-file-tags)))
  2319. ;; PROPERTY keyword. Property names are case-insensitive.
  2320. (should
  2321. (equal "foo=1"
  2322. (org-test-with-temp-text "#+PROPERTY: var foo=1"
  2323. (org-mode-restart)
  2324. (cdr (assoc "var" org-keyword-properties)))))
  2325. (should
  2326. (equal
  2327. "foo=1 bar=2"
  2328. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
  2329. (org-mode-restart)
  2330. (cdr (assoc "var" org-keyword-properties)))))
  2331. (should
  2332. (equal
  2333. "foo=1 bar=2"
  2334. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
  2335. (org-mode-restart)
  2336. (cdr (assoc "var" org-keyword-properties)))))
  2337. ;; ARCHIVE keyword.
  2338. (should
  2339. (equal "%s_done::"
  2340. (org-test-with-temp-text "#+ARCHIVE: %s_done::"
  2341. (org-mode-restart)
  2342. org-archive-location)))
  2343. ;; CATEGORY keyword.
  2344. (should
  2345. (eq 'test
  2346. (org-test-with-temp-text "#+CATEGORY: test"
  2347. (org-mode-restart)
  2348. org-category)))
  2349. (should
  2350. (equal "test"
  2351. (org-test-with-temp-text "#+CATEGORY: test"
  2352. (org-mode-restart)
  2353. (cdr (assoc "CATEGORY" org-keyword-properties)))))
  2354. ;; COLUMNS keyword.
  2355. (should
  2356. (equal "%25ITEM %TAGS %PRIORITY %TODO"
  2357. (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
  2358. (org-mode-restart)
  2359. org-columns-default-format)))
  2360. ;; CONSTANTS keyword. Constants names are case sensitive.
  2361. (should
  2362. (equal '("299792458." "3.14")
  2363. (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
  2364. (org-mode-restart)
  2365. (mapcar
  2366. (lambda (n) (cdr (assoc n org-table-formula-constants-local)))
  2367. '("c" "pi")))))
  2368. (should
  2369. (equal "3.14"
  2370. (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
  2371. (org-mode-restart)
  2372. (cdr (assoc "pi" org-table-formula-constants-local)))))
  2373. (should
  2374. (equal "22/7"
  2375. (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
  2376. (org-mode-restart)
  2377. (cdr (assoc "PI" org-table-formula-constants-local)))))
  2378. ;; LINK keyword.
  2379. (should
  2380. (equal
  2381. '("url1" "url2")
  2382. (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
  2383. (org-mode-restart)
  2384. (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local)))
  2385. '("a" "b")))))
  2386. ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
  2387. (should
  2388. (equal
  2389. '(?X ?Z ?Y)
  2390. (org-test-with-temp-text "#+PRIORITIES: X Z Y"
  2391. (org-mode-restart)
  2392. (list org-priority-highest org-priority-lowest org-priority-default))))
  2393. (should
  2394. (equal
  2395. '(?A ?C ?B)
  2396. (org-test-with-temp-text "#+PRIORITIES: X Z"
  2397. (org-mode-restart)
  2398. (list org-priority-highest org-priority-lowest org-priority-default))))
  2399. ;; STARTUP keyword.
  2400. (should
  2401. (equal '(t t)
  2402. (org-test-with-temp-text "#+STARTUP: fold odd"
  2403. (org-mode-restart)
  2404. (list org-startup-folded org-odd-levels-only))))
  2405. ;; TODO keywords.
  2406. (should
  2407. (equal '(("A" "B") ("C"))
  2408. (org-test-with-temp-text "#+TODO: A B | C"
  2409. (org-mode-restart)
  2410. (list org-not-done-keywords org-done-keywords))))
  2411. (should
  2412. (equal '(("A" "C") ("B" "D"))
  2413. (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
  2414. (org-mode-restart)
  2415. (list org-not-done-keywords org-done-keywords))))
  2416. (should
  2417. (equal '(("A" "B") ("C"))
  2418. (org-test-with-temp-text "#+TYP_TODO: A B | C"
  2419. (org-mode-restart)
  2420. (list org-not-done-keywords org-done-keywords))))
  2421. (should
  2422. (equal '((:startgroup) ("A" . ?a) (:endgroup))
  2423. (org-test-with-temp-text "#+TODO: A(a)"
  2424. (org-mode-restart)
  2425. org-todo-key-alist)))
  2426. (should
  2427. (equal '(("D" note nil) ("C" time nil) ("B" note time))
  2428. (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
  2429. (org-mode-restart)
  2430. org-todo-log-states)))
  2431. ;; Enter SETUPFILE keyword.
  2432. (should
  2433. (equal "1"
  2434. (org-test-with-temp-text
  2435. (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
  2436. (org-mode-restart)
  2437. (cdr (assoc "a" org-keyword-properties))))))
  2438. ;;; Links
  2439. ;;;; Coderefs
  2440. (ert-deftest test-org/coderef ()
  2441. "Test coderef links specifications."
  2442. (should
  2443. (org-test-with-temp-text "
  2444. #+BEGIN_SRC emacs-lisp
  2445. \(+ 1 1) (ref:sc)
  2446. #+END_SRC
  2447. \[[(sc)<point>]]"
  2448. (org-open-at-point)
  2449. (looking-at "(ref:sc)")))
  2450. ;; Find coderef even with alternate label format.
  2451. (should
  2452. (org-test-with-temp-text "
  2453. #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
  2454. \(+ 1 1) {ref:sc}
  2455. #+END_SRC
  2456. \[[(sc)<point>]]"
  2457. (org-open-at-point)
  2458. (looking-at "{ref:sc}"))))
  2459. ;;;; Custom ID
  2460. (ert-deftest test-org/custom-id ()
  2461. "Test custom ID links specifications."
  2462. (should
  2463. (org-test-with-temp-text
  2464. "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2465. (org-open-at-point)
  2466. (looking-at-p "\\* H1")))
  2467. ;; Handle escape characters.
  2468. (should
  2469. (org-test-with-temp-text
  2470. "* H1\n:PROPERTIES:\n:CUSTOM_ID: [%]\n:END:\n* H2\n[[#\\[%\\]<point>]]"
  2471. (org-open-at-point)
  2472. (looking-at-p "\\* H1")))
  2473. ;; Throw an error on false positives.
  2474. (should-error
  2475. (org-test-with-temp-text
  2476. "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2477. (org-open-at-point)
  2478. (looking-at-p "\\* H1"))))
  2479. ;;;; Fuzzy Links
  2480. ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
  2481. ;; a named element (#+name: text) and to headlines (* Text).
  2482. (ert-deftest test-org/fuzzy-links ()
  2483. "Test fuzzy links specifications."
  2484. ;; Fuzzy link goes in priority to a matching target.
  2485. (should
  2486. (org-test-with-temp-text
  2487. "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
  2488. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2489. (looking-at "<<Test>>")))
  2490. ;; Then fuzzy link points to an element with a given name.
  2491. (should
  2492. (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
  2493. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2494. (looking-at "#\\+NAME: Test")))
  2495. ;; A target still lead to a matching headline otherwise.
  2496. (should
  2497. (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
  2498. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2499. (looking-at "\\* Head2")))
  2500. ;; With a leading star in link, enforce heading match.
  2501. (should
  2502. (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
  2503. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2504. (looking-at "\\* Test")))
  2505. ;; With a leading star in link, enforce exact heading match, even
  2506. ;; with `org-link-search-must-match-exact-headline' set to nil.
  2507. (should-error
  2508. (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
  2509. (let ((org-link-search-must-match-exact-headline nil))
  2510. (org-open-at-point))))
  2511. ;; Handle non-nil `org-link-search-must-match-exact-headline'.
  2512. (should
  2513. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
  2514. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2515. (looking-at "\\* Test")))
  2516. (should
  2517. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
  2518. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2519. (looking-at "\\* Test")))
  2520. ;; Heading match should not care about spaces, cookies, TODO
  2521. ;; keywords, priorities, and tags. However, TODO keywords are
  2522. ;; case-sensitive.
  2523. (should
  2524. (let ((first-line
  2525. "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
  2526. (org-test-with-temp-text
  2527. (concat first-line "\nFoo Bar\n<point>[[*Test 1 2]]")
  2528. (let ((org-link-search-must-match-exact-headline nil)
  2529. (org-todo-regexp "TODO"))
  2530. (org-open-at-point))
  2531. (looking-at (regexp-quote first-line)))))
  2532. (should-error
  2533. (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
  2534. (let ((org-link-search-must-match-exact-headline nil)
  2535. (org-todo-regexp "TODO"))
  2536. (org-open-at-point))))
  2537. ;; Heading match should still be exact.
  2538. (should-error
  2539. (org-test-with-temp-text "
  2540. ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
  2541. Foo Bar
  2542. <point>[[*Test 1]]"
  2543. (let ((org-link-search-must-match-exact-headline nil)
  2544. (org-todo-regexp "TODO"))
  2545. (org-open-at-point))))
  2546. (should
  2547. (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
  2548. (let ((org-link-search-must-match-exact-headline nil)
  2549. (org-todo-regexp "TODO"))
  2550. (org-open-at-point))
  2551. (looking-at-p (regexp-quote "** Test 1 2"))))
  2552. ;; Heading match ignores COMMENT keyword.
  2553. (should
  2554. (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
  2555. (org-open-at-point)
  2556. (looking-at "\\* COMMENT Test")))
  2557. (should
  2558. (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
  2559. (org-open-at-point)
  2560. (looking-at "\\* TODO COMMENT Test")))
  2561. ;; Correctly un-escape fuzzy links.
  2562. (should
  2563. (org-test-with-temp-text "* [foo]\n[[*\\[foo\\]][With escaped characters]]"
  2564. (org-open-at-point)
  2565. (bobp)))
  2566. ;; Match search strings containing newline characters, including
  2567. ;; blank lines.
  2568. (should
  2569. (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
  2570. (let ((file (buffer-file-name)))
  2571. (goto-char (point-max))
  2572. (insert (format "[[file:%s::line1 line2]]" file))
  2573. (beginning-of-line)
  2574. (let ((org-link-search-must-match-exact-headline nil))
  2575. (org-open-at-point 0))
  2576. (looking-at-p "line1"))))
  2577. (should
  2578. (org-test-with-temp-text-in-file "Paragraph\n\nline1\n\nline2\n\n"
  2579. (let ((file (buffer-file-name)))
  2580. (goto-char (point-max))
  2581. (insert (format "[[file:%s::line1 line2]]" file))
  2582. (beginning-of-line)
  2583. (let ((org-link-search-must-match-exact-headline nil))
  2584. (org-open-at-point 0))
  2585. (looking-at-p "line1")))))
  2586. ;;;; Open at point
  2587. (ert-deftest test-org/open-at-point/keyword ()
  2588. "Does `org-open-at-point' open link in a keyword line?"
  2589. (should
  2590. (org-test-with-temp-text
  2591. "<<top>>\n#+KEYWORD: <point>[[top]]"
  2592. (org-open-at-point) t))
  2593. (should
  2594. (org-test-with-temp-text
  2595. "* H\n<<top>>\n#+KEYWORD: <point>[[top]]"
  2596. (org-open-at-point) t)))
  2597. (ert-deftest test-org/open-at-point/property ()
  2598. "Does `org-open-at-point' open link in property drawer?"
  2599. (should
  2600. (org-test-with-temp-text
  2601. "* Headline
  2602. :PROPERTIES:
  2603. :URL: <point>[[*Headline]]
  2604. :END:"
  2605. (org-open-at-point) t)))
  2606. (ert-deftest test-org/open-at-point/comment ()
  2607. "Does `org-open-at-point' open link in a commented line?"
  2608. (should
  2609. (org-test-with-temp-text
  2610. "<<top>>\n# <point>[[top]]"
  2611. (org-open-at-point) t))
  2612. (should
  2613. (org-test-with-temp-text
  2614. "* H\n<<top>>\n# <point>[[top]]"
  2615. (org-open-at-point) t)))
  2616. (ert-deftest test-org/open-at-point/inline-image ()
  2617. "Test `org-open-at-point' on nested links."
  2618. (should
  2619. (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
  2620. (org-open-at-point)
  2621. (bobp))))
  2622. (ert-deftest test-org/open-at-point/radio-target ()
  2623. "Test `org-open-at-point' on radio targets."
  2624. (should
  2625. (org-test-with-temp-text "<<<target>>> <point>target"
  2626. (org-update-radio-target-regexp)
  2627. (org-open-at-point)
  2628. (eq (org-element-type (org-element-context)) 'radio-target))))
  2629. (ert-deftest test-org/open-at-point/tag ()
  2630. "Test `org-open-at-point' on tags."
  2631. (should
  2632. (org-test-with-temp-text "* H :<point>tag:"
  2633. (catch :result
  2634. (cl-letf (((symbol-function 'org-tags-view)
  2635. (lambda (&rest args) (throw :result t))))
  2636. (org-open-at-point)
  2637. nil))))
  2638. (should-not
  2639. (org-test-with-temp-text-in-file "* H<point> :tag:"
  2640. (catch :result
  2641. (cl-letf (((symbol-function 'org-tags-view)
  2642. (lambda (&rest args) (throw :result t))))
  2643. ;; When point isn't on a tag it's going to try other things,
  2644. ;; possibly trying to open attachments which will return an
  2645. ;; error if there isn't an attachment. Suppress that error.
  2646. (ignore-errors
  2647. (org-open-at-point))
  2648. nil)))))
  2649. ;;; Node Properties
  2650. (ert-deftest test-org/accumulated-properties-in-drawers ()
  2651. "Ensure properties accumulate in subtree drawers."
  2652. (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
  2653. (org-babel-next-src-block)
  2654. (should (equal '(2 1) (org-babel-execute-src-block)))))
  2655. (ert-deftest test-org/custom-properties ()
  2656. "Test custom properties specifications."
  2657. ;; Standard test.
  2658. (should
  2659. (let ((org-custom-properties '("FOO")))
  2660. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2661. (org-toggle-custom-properties-visibility)
  2662. (org-invisible-p2))))
  2663. ;; Properties are case-insensitive.
  2664. (should
  2665. (let ((org-custom-properties '("FOO")))
  2666. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
  2667. (org-toggle-custom-properties-visibility)
  2668. (org-invisible-p2))))
  2669. (should
  2670. (let ((org-custom-properties '("foo")))
  2671. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2672. (org-toggle-custom-properties-visibility)
  2673. (org-invisible-p2))))
  2674. ;; Multiple custom properties in the same drawer.
  2675. (should
  2676. (let ((org-custom-properties '("FOO" "BAR")))
  2677. (org-test-with-temp-text
  2678. "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
  2679. (org-toggle-custom-properties-visibility)
  2680. (and (org-invisible-p2)
  2681. (not (progn (forward-line) (org-invisible-p2)))
  2682. (progn (forward-line) (org-invisible-p2))))))
  2683. ;; Hide custom properties with an empty value.
  2684. (should
  2685. (let ((org-custom-properties '("FOO")))
  2686. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
  2687. (org-toggle-custom-properties-visibility)
  2688. (org-invisible-p2))))
  2689. ;; Do not hide fake properties.
  2690. (should-not
  2691. (let ((org-custom-properties '("FOO")))
  2692. (org-test-with-temp-text ":FOO: val\n"
  2693. (org-toggle-custom-properties-visibility)
  2694. (org-invisible-p2))))
  2695. (should-not
  2696. (let ((org-custom-properties '("A")))
  2697. (org-test-with-temp-text
  2698. "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
  2699. (org-toggle-custom-properties-visibility)
  2700. (org-invisible-p2)))))
  2701. ;;; Mark Region
  2702. (ert-deftest test-org/mark-element ()
  2703. "Test `org-mark-element' specifications."
  2704. ;; Mark beginning and end of element.
  2705. (should
  2706. (equal '(t t)
  2707. (org-test-with-temp-text "Para<point>graph"
  2708. (org-mark-element)
  2709. (list (bobp) (= (mark) (point-max))))))
  2710. (should
  2711. (equal '(t t)
  2712. (org-test-with-temp-text "P1\n\nPara<point>graph\n\nP2"
  2713. (org-mark-element)
  2714. (list (looking-at "Paragraph")
  2715. (org-with-point-at (mark) (looking-at "P2"))))))
  2716. ;; Do not set mark past (point-max).
  2717. (should
  2718. (org-test-with-temp-text "Para<point>graph"
  2719. (narrow-to-region 2 6)
  2720. (org-mark-element)
  2721. (= 6 (mark)))))
  2722. (ert-deftest test-org/mark-subtree ()
  2723. "Test `org-mark-subtree' specifications."
  2724. ;; Error when point is before first headline.
  2725. (should-error
  2726. (org-test-with-temp-text "Paragraph\n* Headline\nBody"
  2727. (progn (transient-mark-mode 1)
  2728. (org-mark-subtree))))
  2729. ;; Without argument, mark current subtree.
  2730. (should
  2731. (equal
  2732. '(12 32)
  2733. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  2734. (progn (transient-mark-mode 1)
  2735. (forward-line 2)
  2736. (org-mark-subtree)
  2737. (list (region-beginning) (region-end))))))
  2738. ;; With an argument, move ARG up.
  2739. (should
  2740. (equal
  2741. '(1 32)
  2742. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  2743. (progn (transient-mark-mode 1)
  2744. (forward-line 2)
  2745. (org-mark-subtree 1)
  2746. (list (region-beginning) (region-end))))))
  2747. ;; Do not get fooled by inlinetasks.
  2748. (when (featurep 'org-inlinetask)
  2749. (should
  2750. (= 1
  2751. (org-test-with-temp-text "* Headline\n*************** Task\nContents"
  2752. (progn (transient-mark-mode 1)
  2753. (forward-line 1)
  2754. (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
  2755. (region-beginning)))))))
  2756. ;;; Miscellaneous
  2757. (ert-deftest test-org/sort-entries ()
  2758. "Test `org-sort-entries'."
  2759. ;; Sort alphabetically.
  2760. (should
  2761. (equal "\n* abc\n* def\n* xyz\n"
  2762. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  2763. (org-sort-entries nil ?a)
  2764. (buffer-string))))
  2765. (should
  2766. (equal "\n* xyz\n* def\n* abc\n"
  2767. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  2768. (org-sort-entries nil ?A)
  2769. (buffer-string))))
  2770. (should
  2771. (equal "\n* \n* klm\n* xyz\n"
  2772. (org-test-with-temp-text "\n* xyz\n* \n* klm\n"
  2773. (org-sort-entries nil ?a)
  2774. (buffer-string))))
  2775. ;; Sort numerically.
  2776. (should
  2777. (equal "\n* 1\n* 2\n* 10\n"
  2778. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  2779. (org-sort-entries nil ?n)
  2780. (buffer-string))))
  2781. (should
  2782. (equal "\n* 10\n* 2\n* 1\n"
  2783. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  2784. (org-sort-entries nil ?N)
  2785. (buffer-string))))
  2786. (should
  2787. (equal "\n* \n* 1\n* 2\n"
  2788. (org-test-with-temp-text "\n* 1\n* \n* 2\n"
  2789. (org-sort-entries nil ?n)
  2790. (buffer-string))))
  2791. ;; Sort by custom function.
  2792. (should
  2793. (equal "\n* b\n* aa\n* ccc\n"
  2794. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  2795. (org-sort-entries nil ?f
  2796. (lambda ()
  2797. (length (buffer-substring (point-at-bol)
  2798. (point-at-eol))))
  2799. #'<)
  2800. (buffer-string))))
  2801. (should
  2802. (equal "\n* ccc\n* aa\n* b\n"
  2803. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  2804. (org-sort-entries nil ?F
  2805. (lambda ()
  2806. (length (buffer-substring (point-at-bol)
  2807. (point-at-eol))))
  2808. #'<)
  2809. (buffer-string))))
  2810. ;; Sort by TODO keyword.
  2811. (should
  2812. (equal "\n* TODO h1\n* TODO h3\n* DONE h2\n"
  2813. (org-test-with-temp-text
  2814. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  2815. (org-sort-entries nil ?o)
  2816. (buffer-string))))
  2817. (should
  2818. (equal "\n* DONE h2\n* TODO h1\n* TODO h3\n"
  2819. (org-test-with-temp-text
  2820. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  2821. (org-sort-entries nil ?O)
  2822. (buffer-string))))
  2823. ;; Sort by priority.
  2824. (should
  2825. (equal "\n* [#A] h2\n* [#B] h3\n* [#C] h1\n"
  2826. (org-test-with-temp-text
  2827. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  2828. (org-sort-entries nil ?p)
  2829. (buffer-string))))
  2830. (should
  2831. (equal "\n* [#C] h1\n* [#B] h3\n* [#A] h2\n"
  2832. (org-test-with-temp-text
  2833. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  2834. (org-sort-entries nil ?P)
  2835. (buffer-string))))
  2836. ;; Sort by creation time.
  2837. (should
  2838. (equal "
  2839. * h3
  2840. [2017-05-08 Mon]
  2841. * h2
  2842. [2017-05-09 Tue]
  2843. * h1
  2844. [2018-05-09 Wed]
  2845. "
  2846. (org-test-with-temp-text
  2847. "
  2848. * h1
  2849. [2018-05-09 Wed]
  2850. * h2
  2851. [2017-05-09 Tue]
  2852. * h3
  2853. [2017-05-08 Mon]
  2854. "
  2855. (org-sort-entries nil ?c)
  2856. (buffer-string))))
  2857. ;; Sort by scheduled date.
  2858. (should
  2859. (equal "
  2860. * TODO h4
  2861. SCHEDULED: <2017-05-06 Sat>
  2862. * TODO h3
  2863. SCHEDULED: <2017-05-08 Mon>
  2864. * TODO h2
  2865. DEADLINE: <2017-05-09 Tue>
  2866. * TODO h1
  2867. DEADLINE: <2017-05-07 Sun>
  2868. "
  2869. (org-test-with-temp-text
  2870. "
  2871. * TODO h2
  2872. DEADLINE: <2017-05-09 Tue>
  2873. * TODO h1
  2874. DEADLINE: <2017-05-07 Sun>
  2875. * TODO h3
  2876. SCHEDULED: <2017-05-08 Mon>
  2877. * TODO h4
  2878. SCHEDULED: <2017-05-06 Sat>
  2879. "
  2880. (org-sort-entries nil ?s)
  2881. (buffer-string))))
  2882. ;; Sort by deadline date.
  2883. (should
  2884. (equal "
  2885. * TODO h1
  2886. DEADLINE: <2017-05-07 Sun>
  2887. * TODO h2
  2888. DEADLINE: <2017-05-09 Tue>
  2889. * TODO h3
  2890. SCHEDULED: <2017-05-08 Mon>
  2891. * TODO h4
  2892. SCHEDULED: <2017-05-06 Sat>
  2893. "
  2894. (org-test-with-temp-text
  2895. "
  2896. * TODO h2
  2897. DEADLINE: <2017-05-09 Tue>
  2898. * TODO h1
  2899. DEADLINE: <2017-05-07 Sun>
  2900. * TODO h3
  2901. SCHEDULED: <2017-05-08 Mon>
  2902. * TODO h4
  2903. SCHEDULED: <2017-05-06 Sat>
  2904. "
  2905. (org-sort-entries nil ?d)
  2906. (buffer-string))))
  2907. ;; Sort by any date/time
  2908. (should
  2909. (equal "
  2910. * TODO h4
  2911. SCHEDULED: <2017-05-06 Sat>
  2912. * TODO h1
  2913. DEADLINE: <2017-05-07 Sun>
  2914. * TODO h3
  2915. SCHEDULED: <2017-05-08 Mon>
  2916. * TODO h2
  2917. DEADLINE: <2017-05-09 Tue>
  2918. "
  2919. (org-test-with-temp-text
  2920. "
  2921. * TODO h2
  2922. DEADLINE: <2017-05-09 Tue>
  2923. * TODO h1
  2924. DEADLINE: <2017-05-07 Sun>
  2925. * TODO h3
  2926. SCHEDULED: <2017-05-08 Mon>
  2927. * TODO h4
  2928. SCHEDULED: <2017-05-06 Sat>
  2929. "
  2930. (org-sort-entries nil ?t)
  2931. (buffer-string))))
  2932. ;; Sort by clocking time.
  2933. (should
  2934. (equal "
  2935. * clocked h2
  2936. :LOGBOOK:
  2937. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  2938. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  2939. :END:
  2940. * clocked h1
  2941. :LOGBOOK:
  2942. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  2943. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  2944. :END:
  2945. "
  2946. (org-test-with-temp-text
  2947. "
  2948. * clocked h1
  2949. :LOGBOOK:
  2950. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  2951. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  2952. :END:
  2953. * clocked h2
  2954. :LOGBOOK:
  2955. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  2956. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  2957. :END:
  2958. "
  2959. (org-sort-entries nil ?k)
  2960. (buffer-string))))
  2961. ;; Preserve file local variables when sorting.
  2962. (should
  2963. (equal "\n* A\n* B\n# Local Variables:\n# foo: t\n# End:\n"
  2964. (org-test-with-temp-text
  2965. "\n* B\n* A\n# Local Variables:\n# foo: t\n# End:"
  2966. (org-sort-entries nil ?a)
  2967. (buffer-string)))))
  2968. (ert-deftest test-org/string-collate-greaterp ()
  2969. "Test `org-string-collate-greaterp' specifications."
  2970. (should (org-string-collate-greaterp "def" "abc"))
  2971. (should-not (org-string-collate-greaterp "abc" "def")))
  2972. (ert-deftest test-org/file-contents ()
  2973. "Test `org-file-contents' specifications."
  2974. ;; Open files.
  2975. (should
  2976. (string= "#+BIND: variable value
  2977. #+DESCRIPTION: l2
  2978. #+LANGUAGE: en
  2979. #+SELECT_TAGS: b
  2980. #+TITLE: b
  2981. #+PROPERTY: a 1
  2982. " (org-file-contents (expand-file-name "setupfile3.org"
  2983. (concat org-test-dir "examples/")))))
  2984. ;; Throw error when trying to access an invalid file.
  2985. (should-error (org-file-contents "this-file-must-not-exist"))
  2986. ;; Try to access an invalid file, but do not throw an error.
  2987. (should
  2988. (progn (org-file-contents "this-file-must-not-exist" :noerror) t))
  2989. ;; Open URL.
  2990. (should
  2991. (string= "foo"
  2992. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  2993. (unwind-protect
  2994. ;; Simulate successful retrieval of a URL.
  2995. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  2996. (lambda (&rest_)
  2997. (with-current-buffer buffer
  2998. (insert "HTTP/1.1 200 OK\n\nfoo"))
  2999. buffer)))
  3000. (org-file-contents "http://some-valid-url"))
  3001. (kill-buffer buffer)))))
  3002. ;; Throw error when trying to access an invalid URL.
  3003. (should-error
  3004. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3005. (unwind-protect
  3006. ;; Simulate unsuccessful retrieval of a URL.
  3007. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3008. (lambda (&rest_)
  3009. (with-current-buffer buffer
  3010. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3011. buffer)))
  3012. (org-file-contents "http://this-url-must-not-exist"))
  3013. (kill-buffer buffer))))
  3014. ;; Try to access an invalid URL, but do not throw an error.
  3015. (should-error
  3016. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3017. (unwind-protect
  3018. ;; Simulate unsuccessful retrieval of a URL.
  3019. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3020. (lambda (&rest_)
  3021. (with-current-buffer buffer
  3022. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3023. buffer)))
  3024. (org-file-contents "http://this-url-must-not-exist"))
  3025. (kill-buffer buffer))))
  3026. (should
  3027. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3028. (unwind-protect
  3029. ;; Simulate unsuccessful retrieval of a URL.
  3030. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3031. (lambda (&rest_)
  3032. (with-current-buffer buffer
  3033. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3034. buffer)))
  3035. (org-file-contents "http://this-url-must-not-exist" :noerror))
  3036. (kill-buffer buffer))
  3037. t)))
  3038. ;;; Navigation
  3039. (ert-deftest test-org/next-visible-heading ()
  3040. "Test `org-next-visible-heading' specifications."
  3041. ;; Move to the beginning of the next headline, taking into
  3042. ;; consideration ARG.
  3043. (should
  3044. (org-test-with-temp-text "* H1\n* H2"
  3045. (org-next-visible-heading 1)
  3046. (looking-at "\\* H2")))
  3047. (should
  3048. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3049. (org-next-visible-heading 2)
  3050. (looking-at "\\* H3")))
  3051. ;; Ignore invisible headlines.
  3052. (should
  3053. (org-test-with-temp-text "* H1\n** H2\n* H3"
  3054. (org-cycle)
  3055. (org-next-visible-heading 1)
  3056. (looking-at "\\* H3")))
  3057. (should
  3058. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3059. (org-next-visible-heading 1)
  3060. (looking-at "\\* H2")))
  3061. ;; Move point between headlines, not on blank lines between.
  3062. (should
  3063. (org-test-with-temp-text "* H1\n** H2\n\n\n\n* H3"
  3064. (let ((org-cycle-separator-lines 1))
  3065. (org-cycle)
  3066. (org-next-visible-heading 1))
  3067. (looking-at "\\* H3")))
  3068. ;; Move at end of buffer when there is no more headline.
  3069. (should
  3070. (org-test-with-temp-text "* H1"
  3071. (org-next-visible-heading 1)
  3072. (eobp)))
  3073. (should
  3074. (org-test-with-temp-text "* H1\n* H2"
  3075. (org-next-visible-heading 2)
  3076. (eobp)))
  3077. ;; With a negative argument, move backwards.
  3078. (should
  3079. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3080. (org-next-visible-heading -1)
  3081. (looking-at "\\* H2")))
  3082. (should
  3083. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3084. (org-next-visible-heading -2)
  3085. (looking-at "\\* H1"))))
  3086. (ert-deftest test-org/forward-heading-same-level ()
  3087. "Test `org-forward-heading-same-level' specifications."
  3088. ;; Test navigation at top level, forward and backward.
  3089. (should
  3090. (equal "* H2"
  3091. (org-test-with-temp-text "* H1\n* H2"
  3092. (org-forward-heading-same-level 1)
  3093. (buffer-substring-no-properties (point) (line-end-position)))))
  3094. (should
  3095. (equal "* H1"
  3096. (org-test-with-temp-text "* H1\n<point>* H2"
  3097. (org-forward-heading-same-level -1)
  3098. (buffer-substring-no-properties (point) (line-end-position)))))
  3099. ;; Test navigation in a sub-tree, forward and backward.
  3100. (should
  3101. (equal "* H2"
  3102. (org-test-with-temp-text "* H1\n** H11\n** H12\n* H2"
  3103. (org-forward-heading-same-level 1)
  3104. (buffer-substring-no-properties (point) (line-end-position)))))
  3105. (should
  3106. (equal "* H1"
  3107. (org-test-with-temp-text "* H1\n** H11\n** H12\n<point>* H2"
  3108. (org-forward-heading-same-level -1)
  3109. (buffer-substring-no-properties (point) (line-end-position)))))
  3110. ;; Stop at first or last sub-heading.
  3111. (should-not
  3112. (equal "* H2"
  3113. (org-test-with-temp-text "* H1\n** H11\n<point>** H12\n* H2"
  3114. (org-forward-heading-same-level 1)
  3115. (buffer-substring-no-properties (point) (line-end-position)))))
  3116. (should-not
  3117. (equal "* H2"
  3118. (org-test-with-temp-text "* H1\n<point>** H11\n** H12\n* H2"
  3119. (org-forward-heading-same-level -1)
  3120. (buffer-substring-no-properties (point) (line-end-position)))))
  3121. ;; Allow multiple moves.
  3122. (should
  3123. (equal "* H3"
  3124. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3125. (org-forward-heading-same-level 2)
  3126. (buffer-substring-no-properties (point) (line-end-position)))))
  3127. (should
  3128. (equal "* H1"
  3129. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3130. (org-forward-heading-same-level -2)
  3131. (buffer-substring-no-properties (point) (line-end-position)))))
  3132. ;; Ignore spurious moves when first (or last) sibling is reached.
  3133. (should
  3134. (equal "** H3"
  3135. (org-test-with-temp-text "* First\n<point>** H1\n** H2\n** H3\n* Last"
  3136. (org-forward-heading-same-level 100)
  3137. (buffer-substring-no-properties (point) (line-end-position)))))
  3138. (should
  3139. (equal "** H1"
  3140. (org-test-with-temp-text "* First\n** H1\n** H2\n<point>** H3\n* Last"
  3141. (org-forward-heading-same-level -100)
  3142. (buffer-substring-no-properties (point) (line-end-position))))))
  3143. (ert-deftest test-org/end-of-meta-data ()
  3144. "Test `org-end-of-meta-data' specifications."
  3145. ;; Skip planning line.
  3146. (should
  3147. (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
  3148. (org-end-of-meta-data)
  3149. (eobp)))
  3150. ;; Skip properties drawer.
  3151. (should
  3152. (org-test-with-temp-text
  3153. "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
  3154. (org-end-of-meta-data)
  3155. (eobp)))
  3156. ;; Skip both.
  3157. (should
  3158. (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
  3159. (org-end-of-meta-data)
  3160. (eobp)))
  3161. ;; Nothing to skip, go to first line.
  3162. (should
  3163. (org-test-with-temp-text "* Headline\nContents"
  3164. (org-end-of-meta-data)
  3165. (looking-at "Contents")))
  3166. ;; With option argument, skip empty lines, regular drawers and
  3167. ;; clocking lines.
  3168. (should
  3169. (org-test-with-temp-text "* Headline\n\nContents"
  3170. (org-end-of-meta-data t)
  3171. (looking-at "Contents")))
  3172. (should
  3173. (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
  3174. (org-end-of-meta-data t)
  3175. (looking-at "Contents")))
  3176. (should
  3177. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
  3178. (org-end-of-meta-data t)
  3179. (looking-at "Contents")))
  3180. ;; Special case: do not skip incomplete drawers.
  3181. (should
  3182. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
  3183. (org-end-of-meta-data t)
  3184. (looking-at ":LOGBOOK:")))
  3185. ;; Special case: Be careful about consecutive headlines.
  3186. (should-not
  3187. (org-test-with-temp-text "* H1\n*H2\nContents"
  3188. (org-end-of-meta-data t)
  3189. (looking-at "Contents"))))
  3190. (ert-deftest test-org/beginning-of-line ()
  3191. "Test `org-beginning-of-line' specifications."
  3192. ;; Move to beginning of line. If current line in invisible, move to
  3193. ;; beginning of visible line instead.
  3194. (should
  3195. (org-test-with-temp-text "Some text\nSome other text<point>"
  3196. (org-beginning-of-line)
  3197. (bolp)))
  3198. (should
  3199. (org-test-with-temp-text "* H1\n** H2<point>"
  3200. (org-overview)
  3201. (org-beginning-of-line)
  3202. (= (line-beginning-position) 1)))
  3203. ;; With `visual-line-mode' active, move to beginning of visual line.
  3204. (should-not
  3205. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3206. (visual-line-mode)
  3207. (dotimes (i 1000) (insert "very "))
  3208. (org-beginning-of-line)
  3209. (bolp)))
  3210. ;; In a wide headline, with `visual-line-mode', prefer going to the
  3211. ;; beginning of a visual line than to the logical beginning of line,
  3212. ;; even if special movement is active.
  3213. (should-not
  3214. (org-test-with-temp-text "* A <point>long headline"
  3215. (visual-line-mode)
  3216. (dotimes (i 1000) (insert "very "))
  3217. (goto-char (point-max))
  3218. (org-beginning-of-line)
  3219. (bobp)))
  3220. (should-not
  3221. (org-test-with-temp-text "* A <point>long headline"
  3222. (visual-line-mode)
  3223. (dotimes (i 1000) (insert "very "))
  3224. (goto-char (point-max))
  3225. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line))
  3226. (bobp)))
  3227. ;; At an headline with special movement, first move at beginning of
  3228. ;; title, then at the beginning of line, rinse, repeat.
  3229. (should
  3230. (org-test-with-temp-text "* TODO Headline<point>"
  3231. (let ((org-special-ctrl-a/e t))
  3232. (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
  3233. (progn (org-beginning-of-line) (bolp))
  3234. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3235. (should
  3236. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3237. (let ((org-special-ctrl-a/e t))
  3238. (org-beginning-of-line)
  3239. (looking-at "Headline"))))
  3240. (should
  3241. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3242. (let ((org-special-ctrl-a/e '(t . nil)))
  3243. (org-beginning-of-line)
  3244. (looking-at "Headline"))))
  3245. (should-not
  3246. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3247. (let ((org-special-ctrl-a/e '(nil . nil)))
  3248. (org-beginning-of-line)
  3249. (looking-at "Headline"))))
  3250. ;; At an headline with reversed movement, first move to beginning of
  3251. ;; line, then to the beginning of title.
  3252. (should
  3253. (org-test-with-temp-text "* TODO Headline<point>"
  3254. (let ((org-special-ctrl-a/e 'reversed)
  3255. (this-command last-command))
  3256. (and (progn (org-beginning-of-line) (bolp))
  3257. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3258. (should
  3259. (org-test-with-temp-text "* TODO Headline<point>"
  3260. (let ((org-special-ctrl-a/e '(reversed . nil))
  3261. (this-command last-command))
  3262. (and (progn (org-beginning-of-line) (bolp))
  3263. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3264. (should-not
  3265. (org-test-with-temp-text "* TODO Headline<point>"
  3266. (let ((org-special-ctrl-a/e '(t . nil))
  3267. (this-command last-command))
  3268. (and (progn (org-beginning-of-line) (bolp))
  3269. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3270. ;; At an item with special movement, first move after to beginning
  3271. ;; of title, then to the beginning of line, rinse, repeat.
  3272. (should
  3273. (org-test-with-temp-text "- [ ] Item<point>"
  3274. (let ((org-special-ctrl-a/e t))
  3275. (and (progn (org-beginning-of-line) (looking-at-p "Item"))
  3276. (progn (org-beginning-of-line) (bolp))
  3277. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3278. ;; At an item with reversed movement, first move to beginning of
  3279. ;; line, then to the beginning of title.
  3280. (should
  3281. (org-test-with-temp-text "- [X] Item<point>"
  3282. (let ((org-special-ctrl-a/e 'reversed)
  3283. (this-command last-command))
  3284. (and (progn (org-beginning-of-line) (bolp))
  3285. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3286. ;; Leave point before invisible characters at column 0.
  3287. (should
  3288. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3289. (let ((org-special-ctrl-a/e nil))
  3290. (org-beginning-of-line)
  3291. (bolp))))
  3292. (should
  3293. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3294. (let ((org-special-ctrl-a/e t))
  3295. (org-beginning-of-line)
  3296. (bolp))))
  3297. (should
  3298. (org-test-with-temp-text "[[http<point>://orgmode.org]]"
  3299. (visual-line-mode)
  3300. (org-beginning-of-line)
  3301. (bolp)))
  3302. ;; Special case: Do not error when the buffer contains only a single
  3303. ;; asterisk.
  3304. (should
  3305. (org-test-with-temp-text "*<point>"
  3306. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line) t)))
  3307. (should
  3308. (org-test-with-temp-text "*<point>"
  3309. (let ((org-special-ctrl-a/e nil)) (org-beginning-of-line) t))))
  3310. (ert-deftest test-org/end-of-line ()
  3311. "Test `org-end-of-line' specifications."
  3312. ;; Standard test.
  3313. (should
  3314. (org-test-with-temp-text "Some text\nSome other text"
  3315. (org-end-of-line)
  3316. (eolp)))
  3317. ;; With `visual-line-mode' active, move to end of visible line.
  3318. ;; However, never go past ellipsis.
  3319. (should-not
  3320. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3321. (visual-line-mode)
  3322. (dotimes (i 1000) (insert "very "))
  3323. (goto-char (point-min))
  3324. (org-end-of-line)
  3325. (eolp)))
  3326. (should-not
  3327. (org-test-with-temp-text "* A short headline\nSome contents"
  3328. (visual-line-mode)
  3329. (org-overview)
  3330. (org-end-of-line)
  3331. (eobp)))
  3332. ;; In a wide headline, with `visual-line-mode', prefer going to end
  3333. ;; of visible line if tags, or end of line, are farther.
  3334. (should-not
  3335. (org-test-with-temp-text "* A <point>long headline"
  3336. (visual-line-mode)
  3337. (dotimes (i 1000) (insert "very "))
  3338. (goto-char (point-min))
  3339. (org-end-of-line)
  3340. (eolp)))
  3341. (should-not
  3342. (org-test-with-temp-text "* A <point>long headline :tag:"
  3343. (visual-line-mode)
  3344. (dotimes (i 1000) (insert "very "))
  3345. (goto-char (point-min))
  3346. (org-end-of-line)
  3347. (eolp)))
  3348. ;; At an headline without special movement, go to end of line.
  3349. ;; However, never go past ellipsis.
  3350. (should
  3351. (org-test-with-temp-text "* Headline2b :tag:\n"
  3352. (let ((org-special-ctrl-a/e nil))
  3353. (and (progn (org-end-of-line) (eolp))
  3354. (progn (org-end-of-line) (eolp))))))
  3355. (should
  3356. (org-test-with-temp-text "* Headline2b :tag:\n"
  3357. (let ((org-special-ctrl-a/e '(t . nil)))
  3358. (and (progn (org-end-of-line) (eolp))
  3359. (progn (org-end-of-line) (eolp))))))
  3360. (should
  3361. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3362. (org-overview)
  3363. (let ((org-special-ctrl-a/e nil))
  3364. (org-end-of-line)
  3365. (= 1 (line-beginning-position)))))
  3366. ;; At an headline with special movement, first move before tags,
  3367. ;; then at the end of line, rinse, repeat. However, never go past
  3368. ;; ellipsis.
  3369. (should
  3370. (org-test-with-temp-text "* Headline1 :tag:\n"
  3371. (let ((org-special-ctrl-a/e t))
  3372. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3373. (progn (org-end-of-line) (eolp))
  3374. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3375. (should
  3376. (org-test-with-temp-text "* Headline1 :tag:\n"
  3377. (let ((org-special-ctrl-a/e '(nil . t)))
  3378. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3379. (progn (org-end-of-line) (eolp))
  3380. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3381. (should-not
  3382. (org-test-with-temp-text "* Headline1 :tag:\n"
  3383. (let ((org-special-ctrl-a/e '(nil . nil)))
  3384. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3385. (progn (org-end-of-line) (eolp))
  3386. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3387. (should
  3388. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3389. (org-overview)
  3390. (let ((org-special-ctrl-a/e t))
  3391. (org-end-of-line)
  3392. (org-end-of-line)
  3393. (= 1 (line-beginning-position)))))
  3394. ;; At an headline, with reversed movement, first go to end of line,
  3395. ;; then before tags. However, never go past ellipsis.
  3396. (should
  3397. (org-test-with-temp-text "* Headline3 :tag:\n"
  3398. (let ((org-special-ctrl-a/e 'reversed)
  3399. (this-command last-command))
  3400. (and (progn (org-end-of-line) (eolp))
  3401. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3402. (should
  3403. (org-test-with-temp-text "* Headline3 :tag:\n"
  3404. (let ((org-special-ctrl-a/e '(nil . reversed))
  3405. (this-command last-command))
  3406. (and (progn (org-end-of-line) (eolp))
  3407. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3408. (should-not
  3409. (org-test-with-temp-text "* Headline3 :tag:\n"
  3410. (let ((org-special-ctrl-a/e '(nil . t))
  3411. (this-command last-command))
  3412. (and (progn (org-end-of-line) (eolp))
  3413. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3414. (should
  3415. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3416. (org-overview)
  3417. (let ((org-special-ctrl-a/e 'reversed))
  3418. (org-end-of-line)
  3419. (= 1 (line-beginning-position)))))
  3420. ;; At a block without hidden contents.
  3421. (should
  3422. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3423. (progn (org-end-of-line) (eolp))))
  3424. ;; At a block with hidden contents.
  3425. (should-not
  3426. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3427. (let ((org-special-ctrl-a/e t))
  3428. (org-hide-block-toggle)
  3429. (org-end-of-line)
  3430. (eobp))))
  3431. ;; Get past invisible characters at the end of line.
  3432. (should
  3433. (org-test-with-temp-text "[[https://orgmode.org]]"
  3434. (org-end-of-line)
  3435. (eolp))))
  3436. (ert-deftest test-org/open-line ()
  3437. "Test `org-open-line' specifications."
  3438. ;; Call `open-line' outside of tables.
  3439. (should
  3440. (equal "\nText"
  3441. (org-test-with-temp-text "Text"
  3442. (org-open-line 1)
  3443. (buffer-string))))
  3444. ;; At a table, create a row above.
  3445. (should
  3446. (equal "\n| |\n| a |"
  3447. (org-test-with-temp-text "\n<point>| a |"
  3448. (org-open-line 1)
  3449. (buffer-string))))
  3450. ;; At the very first character of the buffer, also call `open-line'.
  3451. (should
  3452. (equal "\n| a |"
  3453. (org-test-with-temp-text "| a |"
  3454. (org-open-line 1)
  3455. (buffer-string))))
  3456. ;; Narrowing does not count.
  3457. (should
  3458. (equal "Text\n| |\n| a |"
  3459. (org-test-with-temp-text "Text\n<point>| a |"
  3460. (narrow-to-region (point) (point-max))
  3461. (org-open-line 1)
  3462. (widen)
  3463. (buffer-string)))))
  3464. (ert-deftest test-org/forward-sentence ()
  3465. "Test `org-forward-sentence' specifications."
  3466. ;; At the end of a table cell, move to the end of the next one.
  3467. (should
  3468. (org-test-with-temp-text "| a<point> | b |"
  3469. (org-forward-sentence)
  3470. (looking-at " |$")))
  3471. ;; Elsewhere in a cell, move to its end.
  3472. (should
  3473. (org-test-with-temp-text "| a<point>c | b |"
  3474. (org-forward-sentence)
  3475. (looking-at " | b |$")))
  3476. ;; Otherwise, simply call `forward-sentence'.
  3477. (should
  3478. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3479. (org-forward-sentence)
  3480. (looking-at " Sentence 2.")))
  3481. (should
  3482. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3483. (org-forward-sentence)
  3484. (org-forward-sentence)
  3485. (eobp)))
  3486. ;; At the end of an element, jump to the next one, without stopping
  3487. ;; on blank lines in-between.
  3488. (should
  3489. (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
  3490. (org-forward-sentence)
  3491. (eobp)))
  3492. ;; Headlines are considered to be sentences by themselves, even if
  3493. ;; they do not end with a full stop.
  3494. (should
  3495. (equal
  3496. "* Headline"
  3497. (org-test-with-temp-text "* <point>Headline\nSentence."
  3498. (org-forward-sentence)
  3499. (buffer-substring-no-properties (line-beginning-position) (point)))))
  3500. (should
  3501. (org-test-with-temp-text "* Headline<point>\nSentence."
  3502. (org-forward-sentence)
  3503. (eobp)))
  3504. (should
  3505. (org-test-with-temp-text "Sentence.<point>\n\n* Headline\n\nSentence 2."
  3506. (org-forward-sentence)
  3507. (and (org-at-heading-p) (eolp)))))
  3508. (ert-deftest test-org/backward-sentence ()
  3509. "Test `org-backward-sentence' specifications."
  3510. ;; At the beginning of a table cell, move to the beginning of the
  3511. ;; previous one.
  3512. (should
  3513. (org-test-with-temp-text "| a | <point>b |"
  3514. (org-backward-sentence)
  3515. (looking-at "a | b |$")))
  3516. ;; Elsewhere in a cell, move to its beginning.
  3517. (should
  3518. (org-test-with-temp-text "| a | b<point>c |"
  3519. (org-backward-sentence)
  3520. (looking-at "bc |$")))
  3521. ;; Otherwise, simply call `backward-sentence'.
  3522. (should
  3523. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3524. (org-backward-sentence)
  3525. (looking-at "Sentence 2.")))
  3526. (should
  3527. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3528. (org-backward-sentence)
  3529. (org-backward-sentence)
  3530. (bobp)))
  3531. ;; Make sure to hit the beginning of a sentence on the same line as
  3532. ;; an item.
  3533. (should
  3534. (org-test-with-temp-text "- Line 1\n line <point>2."
  3535. (org-backward-sentence)
  3536. (looking-at "Line 1"))))
  3537. (ert-deftest test-org/forward-paragraph ()
  3538. "Test `org-forward-paragraph' specifications."
  3539. ;; At end of buffer, do not return an error.
  3540. (should
  3541. (org-test-with-temp-text "Paragraph"
  3542. (goto-char (point-max))
  3543. (org-forward-paragraph)
  3544. t))
  3545. ;; Standard test.
  3546. (should
  3547. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  3548. (org-forward-paragraph)
  3549. (looking-at "P2")))
  3550. ;; Ignore depth.
  3551. (should
  3552. (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
  3553. (org-forward-paragraph)
  3554. (looking-at "P1")))
  3555. ;; Do not enter elements with invisible contents.
  3556. (should
  3557. (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
  3558. (org-hide-block-toggle)
  3559. (org-forward-paragraph)
  3560. (looking-at "P3")))
  3561. ;; On an affiliated keyword, jump to the beginning of the element.
  3562. (should
  3563. (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
  3564. (org-forward-paragraph)
  3565. (looking-at "Para")))
  3566. ;; On an item or a footnote definition, move to the second element
  3567. ;; inside, if any.
  3568. (should
  3569. (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
  3570. (org-forward-paragraph)
  3571. (looking-at " Paragraph")))
  3572. (should
  3573. (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
  3574. (org-forward-paragraph)
  3575. (looking-at "Paragraph")))
  3576. ;; On an item, or a footnote definition, when the first line is
  3577. ;; empty, move to the first item.
  3578. (should
  3579. (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
  3580. (org-forward-paragraph)
  3581. (looking-at " Paragraph")))
  3582. (should
  3583. (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
  3584. (org-forward-paragraph)
  3585. (looking-at "Paragraph")))
  3586. ;; On a table (resp. a property drawer) do not move through table
  3587. ;; rows (resp. node properties).
  3588. (should
  3589. (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
  3590. (org-forward-paragraph)
  3591. (looking-at "Paragraph")))
  3592. (should
  3593. (org-test-with-temp-text
  3594. "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
  3595. (org-forward-paragraph)
  3596. (looking-at "Paragraph")))
  3597. ;; On a verse or source block, stop after blank lines.
  3598. (should
  3599. (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
  3600. (org-forward-paragraph)
  3601. (looking-at "L2")))
  3602. (should
  3603. (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
  3604. (org-forward-paragraph)
  3605. (looking-at "L2"))))
  3606. (ert-deftest test-org/backward-paragraph ()
  3607. "Test `org-backward-paragraph' specifications."
  3608. ;; Do not error at beginning of buffer.
  3609. (should
  3610. (org-test-with-temp-text "Paragraph"
  3611. (org-backward-paragraph)
  3612. t))
  3613. ;; Regular test.
  3614. (should
  3615. (org-test-with-temp-text "P1\n\nP2\n\nP3<point>"
  3616. (org-backward-paragraph)
  3617. (looking-at "P3")))
  3618. (should
  3619. (org-test-with-temp-text "P1\n\nP2\n\n<point>P3"
  3620. (org-backward-paragraph)
  3621. (looking-at-p "P2")))
  3622. ;; Ignore depth.
  3623. (should
  3624. (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\n<point>P3"
  3625. (org-backward-paragraph)
  3626. (looking-at-p "P2")))
  3627. ;; Ignore invisible elements.
  3628. (should
  3629. (org-test-with-temp-text "* H1\n P1\n* H2"
  3630. (org-cycle)
  3631. (goto-char (point-max))
  3632. (beginning-of-line)
  3633. (org-backward-paragraph)
  3634. (bobp)))
  3635. ;; On an affiliated keyword, jump to the first one.
  3636. (should
  3637. (org-test-with-temp-text
  3638. "P1\n#+name: n\n#+caption: c1\n#+caption: <point>c2\nP2"
  3639. (org-backward-paragraph)
  3640. (looking-at-p "#\\+name")))
  3641. ;; On the second element in an item or a footnote definition, jump
  3642. ;; to item or the definition.
  3643. (should
  3644. (org-test-with-temp-text "- line1\n\n<point> line2"
  3645. (org-backward-paragraph)
  3646. (looking-at-p "- line1")))
  3647. (should
  3648. (org-test-with-temp-text "[fn:1] line1\n\n<point> line2"
  3649. (org-backward-paragraph)
  3650. (looking-at-p "\\[fn:1\\] line1")))
  3651. ;; On a table (resp. a property drawer), ignore table rows
  3652. ;; (resp. node properties).
  3653. (should
  3654. (org-test-with-temp-text "| a | b |\n| c | d |\n<point>P1"
  3655. (org-backward-paragraph)
  3656. (bobp)))
  3657. (should
  3658. (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
  3659. (org-backward-paragraph)
  3660. (looking-at-p ":PROPERTIES:")))
  3661. ;; On a comment, example, src and verse blocks, stop before blank
  3662. ;; lines.
  3663. (should
  3664. (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\n<point>L3\n#+END_VERSE"
  3665. (org-backward-paragraph)
  3666. (looking-at-p "L2")))
  3667. (should
  3668. (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\n<point>L3#+END_SRC"
  3669. (org-backward-paragraph)
  3670. (looking-at-p "L2")))
  3671. ;; In comment, example, export, src and verse blocks, stop below
  3672. ;; opening line when called from within the block.
  3673. (should
  3674. (org-test-with-temp-text "#+BEGIN_VERSE\nL1\nL2<point>\n#+END_VERSE"
  3675. (org-backward-paragraph)
  3676. (looking-at-p "L1")))
  3677. (should
  3678. (org-test-with-temp-text "#+BEGIN_EXAMPLE\nL1\nL2<point>\n#+END_EXAMPLE"
  3679. (org-backward-paragraph)
  3680. (looking-at-p "L1")))
  3681. ;; When called from the opening line itself, however, move to
  3682. ;; beginning of block.
  3683. (should
  3684. (org-test-with-temp-text "#+BEGIN_<point>EXAMPLE\nL1\n#+END_EXAMPLE"
  3685. (org-backward-paragraph)
  3686. (bobp)))
  3687. ;; Pathological case: on an empty heading, move to its beginning.
  3688. (should
  3689. (org-test-with-temp-text "* <point>H"
  3690. (org-backward-paragraph)
  3691. (bobp))))
  3692. (ert-deftest test-org/forward-element ()
  3693. "Test `org-forward-element' specifications."
  3694. ;; 1. At EOB: should error.
  3695. (org-test-with-temp-text "Some text\n"
  3696. (goto-char (point-max))
  3697. (should-error (org-forward-element)))
  3698. ;; 2. Standard move: expected to ignore blank lines.
  3699. (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
  3700. (org-forward-element)
  3701. (should (looking-at (regexp-quote "Second paragraph."))))
  3702. ;; 3. Headline tests.
  3703. (org-test-with-temp-text "
  3704. * Head 1
  3705. ** Head 1.1
  3706. *** Head 1.1.1
  3707. ** Head 1.2"
  3708. ;; 3.1. At an headline beginning: move to next headline at the
  3709. ;; same level.
  3710. (goto-line 3)
  3711. (org-forward-element)
  3712. (should (looking-at (regexp-quote "** Head 1.2")))
  3713. ;; 3.2. At an headline beginning: move to parent headline if no
  3714. ;; headline at the same level.
  3715. (goto-line 3)
  3716. (org-forward-element)
  3717. (should (looking-at (regexp-quote "** Head 1.2"))))
  3718. ;; 4. Greater element tests.
  3719. (org-test-with-temp-text
  3720. "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
  3721. ;; 4.1. At a greater element: expected to skip contents.
  3722. (org-forward-element)
  3723. (should (looking-at (regexp-quote "Outside.")))
  3724. ;; 4.2. At the end of greater element contents: expected to skip
  3725. ;; to the end of the greater element.
  3726. (goto-line 2)
  3727. (org-forward-element)
  3728. (should (looking-at (regexp-quote "Outside."))))
  3729. ;; 5. List tests.
  3730. (org-test-with-temp-text "
  3731. - item1
  3732. - sub1
  3733. - sub2
  3734. - sub3
  3735. Inner paragraph.
  3736. - item2
  3737. Outside."
  3738. ;; 5.1. At list top point: expected to move to the element after
  3739. ;; the list.
  3740. (goto-line 2)
  3741. (org-forward-element)
  3742. (should (looking-at (regexp-quote "Outside.")))
  3743. ;; 5.2. Special case: at the first line of a sub-list, but not at
  3744. ;; beginning of line, move to next item.
  3745. (goto-line 2)
  3746. (forward-char)
  3747. (org-forward-element)
  3748. (should (looking-at "- item2"))
  3749. (goto-line 4)
  3750. (forward-char)
  3751. (org-forward-element)
  3752. (should (looking-at " - sub2"))
  3753. ;; 5.3 At sub-list beginning: expected to move after the sub-list.
  3754. (goto-line 4)
  3755. (org-forward-element)
  3756. (should (looking-at (regexp-quote " Inner paragraph.")))
  3757. ;; 5.4. At sub-list end: expected to move outside the sub-list.
  3758. (goto-line 8)
  3759. (org-forward-element)
  3760. (should (looking-at (regexp-quote " Inner paragraph.")))
  3761. ;; 5.5. At an item: expected to move to next item, if any.
  3762. (goto-line 6)
  3763. (org-forward-element)
  3764. (should (looking-at " - sub3"))))
  3765. (ert-deftest test-org/backward-element ()
  3766. "Test `org-backward-element' specifications."
  3767. ;; 1. Should error at BOB.
  3768. (org-test-with-temp-text " \nParagraph."
  3769. (should-error (org-backward-element)))
  3770. ;; 2. Should move at BOB when called on the first element in buffer.
  3771. (should
  3772. (org-test-with-temp-text "\n#+TITLE: test"
  3773. (progn (forward-line)
  3774. (org-backward-element)
  3775. (bobp))))
  3776. ;; 3. Not at the beginning of an element: move at its beginning.
  3777. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  3778. (goto-line 3)
  3779. (end-of-line)
  3780. (org-backward-element)
  3781. (should (looking-at (regexp-quote "Paragraph2."))))
  3782. ;; 4. Headline tests.
  3783. (org-test-with-temp-text "
  3784. * Head 1
  3785. ** Head 1.1
  3786. *** Head 1.1.1
  3787. ** Head 1.2"
  3788. ;; 4.1. At an headline beginning: move to previous headline at the
  3789. ;; same level.
  3790. (goto-line 5)
  3791. (org-backward-element)
  3792. (should (looking-at (regexp-quote "** Head 1.1")))
  3793. ;; 4.2. At an headline beginning: move to parent headline if no
  3794. ;; headline at the same level.
  3795. (goto-line 3)
  3796. (org-backward-element)
  3797. (should (looking-at (regexp-quote "* Head 1")))
  3798. ;; 4.3. At the first top-level headline: should error.
  3799. (goto-line 2)
  3800. (should-error (org-backward-element)))
  3801. ;; 5. At beginning of first element inside a greater element:
  3802. ;; expected to move to greater element's beginning.
  3803. (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
  3804. (goto-line 3)
  3805. (org-backward-element)
  3806. (should (looking-at "#\\+BEGIN_CENTER")))
  3807. ;; 6. At the beginning of the first element in a section: should
  3808. ;; move back to headline, if any.
  3809. (should
  3810. (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
  3811. (progn (goto-char (point-max))
  3812. (beginning-of-line)
  3813. (org-backward-element)
  3814. (org-at-heading-p))))
  3815. ;; 7. List tests.
  3816. (org-test-with-temp-text "
  3817. - item1
  3818. - sub1
  3819. - sub2
  3820. - sub3
  3821. Inner paragraph.
  3822. - item2
  3823. Outside."
  3824. ;; 7.1. At beginning of sub-list: expected to move to the
  3825. ;; paragraph before it.
  3826. (goto-line 4)
  3827. (org-backward-element)
  3828. (should (looking-at "item1"))
  3829. ;; 7.2. At an item in a list: expected to move at previous item.
  3830. (goto-line 8)
  3831. (org-backward-element)
  3832. (should (looking-at " - sub2"))
  3833. (goto-line 12)
  3834. (org-backward-element)
  3835. (should (looking-at "- item1"))
  3836. ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
  3837. ;; beginning.
  3838. (goto-line 10)
  3839. (org-backward-element)
  3840. (should (looking-at " - sub1"))
  3841. (goto-line 15)
  3842. (org-backward-element)
  3843. (should (looking-at "- item1"))
  3844. ;; 7.4. At blank-lines before list end: expected to move to top
  3845. ;; item.
  3846. (goto-line 14)
  3847. (org-backward-element)
  3848. (should (looking-at "- item1"))))
  3849. (ert-deftest test-org/up-element ()
  3850. "Test `org-up-element' specifications."
  3851. ;; 1. At BOB or with no surrounding element: should error.
  3852. (org-test-with-temp-text "Paragraph."
  3853. (should-error (org-up-element)))
  3854. (org-test-with-temp-text "* Head1\n* Head2"
  3855. (goto-line 2)
  3856. (should-error (org-up-element)))
  3857. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  3858. (goto-line 3)
  3859. (should-error (org-up-element)))
  3860. ;; 2. At an headline: move to parent headline.
  3861. (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
  3862. (goto-line 3)
  3863. (org-up-element)
  3864. (should (looking-at "\\* Head1")))
  3865. ;; 3. Inside a greater element: move to greater element beginning.
  3866. (org-test-with-temp-text
  3867. "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
  3868. (goto-line 3)
  3869. (org-up-element)
  3870. (should (looking-at "#\\+BEGIN_CENTER")))
  3871. ;; 4. List tests.
  3872. (org-test-with-temp-text "* Top
  3873. - item1
  3874. - sub1
  3875. - sub2
  3876. Paragraph within sub2.
  3877. - item2"
  3878. ;; 4.1. Within an item: move to the item beginning.
  3879. (goto-line 8)
  3880. (org-up-element)
  3881. (should (looking-at " - sub2"))
  3882. ;; 4.2. At an item in a sub-list: move to parent item.
  3883. (goto-line 4)
  3884. (org-up-element)
  3885. (should (looking-at "- item1"))
  3886. ;; 4.3. At an item in top list: move to beginning of whole list.
  3887. (goto-line 10)
  3888. (org-up-element)
  3889. (should (looking-at "- item1"))
  3890. ;; 4.4. Special case. At very top point: should move to parent of
  3891. ;; list.
  3892. (goto-line 2)
  3893. (org-up-element)
  3894. (should (looking-at "\\* Top"))))
  3895. (ert-deftest test-org/down-element ()
  3896. "Test `org-down-element' specifications."
  3897. ;; Error when the element hasn't got a recursive type.
  3898. (org-test-with-temp-text "Paragraph."
  3899. (should-error (org-down-element)))
  3900. ;; Error when the element has no contents
  3901. (org-test-with-temp-text "* Headline"
  3902. (should-error (org-down-element)))
  3903. ;; When at a plain-list, move to first item.
  3904. (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
  3905. (goto-line 2)
  3906. (org-down-element)
  3907. (should (looking-at " - Item 1.1")))
  3908. (org-test-with-temp-text "#+NAME: list\n- Item 1"
  3909. (org-down-element)
  3910. (should (looking-at " Item 1")))
  3911. ;; When at a table, move to first row
  3912. (org-test-with-temp-text "#+NAME: table\n| a | b |"
  3913. (org-down-element)
  3914. (should (looking-at " a | b |")))
  3915. ;; Otherwise, move inside the greater element.
  3916. (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
  3917. (org-down-element)
  3918. (should (looking-at "Paragraph"))))
  3919. (ert-deftest test-org/drag-element-backward ()
  3920. "Test `org-drag-element-backward' specifications."
  3921. ;; Standard test.
  3922. (should
  3923. (equal
  3924. "#+key2: val2\n#+key1: val1\n#+key3: val3"
  3925. (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
  3926. (org-drag-element-backward)
  3927. (buffer-string))))
  3928. (should
  3929. (equal
  3930. "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
  3931. (org-test-with-temp-text
  3932. "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
  3933. (org-drag-element-backward)
  3934. (buffer-string))))
  3935. ;; Preserve blank lines.
  3936. (should
  3937. (equal "Paragraph 2\n\n\nPara1\n\nPara3"
  3938. (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
  3939. (org-drag-element-backward)
  3940. (buffer-string))))
  3941. ;; Preserve column.
  3942. (should
  3943. (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
  3944. (org-drag-element-backward)
  3945. (looking-at-p "2")))
  3946. ;; Error when trying to move first element of buffer.
  3947. (should-error
  3948. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  3949. (org-drag-element-backward))
  3950. :type 'user-error)
  3951. ;; Error when trying to swap nested elements.
  3952. (should-error
  3953. (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
  3954. (org-drag-element-backward))
  3955. :type 'user-error)
  3956. ;; Error when trying to swap an headline element and a non-headline
  3957. ;; element.
  3958. (should-error
  3959. (org-test-with-temp-text "Test.\n<point>* Head 1"
  3960. (org-drag-element-backward))
  3961. :type 'error)
  3962. ;; Error when called before first element.
  3963. (should-error
  3964. (org-test-with-temp-text "\n<point>"
  3965. (org-drag-element-backward))
  3966. :type 'user-error)
  3967. ;; Preserve visibility of elements and their contents.
  3968. (should
  3969. (equal '((63 . 82) (26 . 48))
  3970. (org-test-with-temp-text "
  3971. #+BEGIN_CENTER
  3972. Text.
  3973. #+END_CENTER
  3974. - item 1
  3975. #+BEGIN_QUOTE
  3976. Text.
  3977. #+END_QUOTE"
  3978. (while (search-forward "BEGIN_" nil t) (org-cycle))
  3979. (search-backward "- item 1")
  3980. (org-drag-element-backward)
  3981. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  3982. (overlays-in (point-min) (point-max))))))
  3983. ;; Pathological case: handle call with point in blank lines right
  3984. ;; after a headline.
  3985. (should
  3986. (equal "* H2\n\n* H1\nText\n"
  3987. (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
  3988. (org-drag-element-backward)
  3989. (buffer-string)))))
  3990. (ert-deftest test-org/drag-element-forward ()
  3991. "Test `org-drag-element-forward' specifications."
  3992. ;; 1. Error when trying to move first element of buffer.
  3993. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  3994. (goto-line 3)
  3995. (should-error (org-drag-element-forward)))
  3996. ;; 2. Error when trying to swap nested elements.
  3997. (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
  3998. (forward-line)
  3999. (should-error (org-drag-element-forward)))
  4000. ;; 3. Error when trying to swap a non-headline element and an
  4001. ;; headline.
  4002. (org-test-with-temp-text "Test.\n* Head 1"
  4003. (should-error (org-drag-element-forward)))
  4004. ;; 4. Error when called before first element.
  4005. (should-error
  4006. (org-test-with-temp-text "\n"
  4007. (forward-line)
  4008. (org-drag-element-backward))
  4009. :type 'user-error)
  4010. ;; 5. Otherwise, swap elements, preserving column and blank lines
  4011. ;; between elements.
  4012. (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
  4013. (search-forward "graph")
  4014. (org-drag-element-forward)
  4015. (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
  4016. (should (looking-at " 1")))
  4017. ;; 5. Preserve visibility of elements and their contents.
  4018. (org-test-with-temp-text "
  4019. #+BEGIN_CENTER
  4020. Text.
  4021. #+END_CENTER
  4022. - item 1
  4023. #+BEGIN_QUOTE
  4024. Text.
  4025. #+END_QUOTE"
  4026. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4027. (search-backward "#+BEGIN_CENTER")
  4028. (org-drag-element-forward)
  4029. (should
  4030. (equal
  4031. '((63 . 82) (26 . 48))
  4032. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4033. (overlays-in (point-min) (point-max)))))))
  4034. (ert-deftest test-org/next-block ()
  4035. "Test `org-next-block' specifications."
  4036. ;; Regular test.
  4037. (should
  4038. (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  4039. (org-next-block 1)
  4040. (looking-at "#\\+BEGIN_CENTER")))
  4041. ;; Ignore case.
  4042. (should
  4043. (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
  4044. (let ((case-fold-search nil))
  4045. (org-next-block 1)
  4046. (looking-at "#\\+begin_center"))))
  4047. ;; Ignore current line.
  4048. (should
  4049. (org-test-with-temp-text
  4050. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
  4051. (org-next-block 1)
  4052. (looking-at "#\\+BEGIN_CENTER")))
  4053. ;; Throw an error when no block is found.
  4054. (should-error
  4055. (org-test-with-temp-text "Paragraph"
  4056. (org-next-block 1)))
  4057. ;; With an argument, skip many blocks at once.
  4058. (should
  4059. (org-test-with-temp-text
  4060. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4061. (org-next-block 2)
  4062. (looking-at "#\\+BEGIN_QUOTE")))
  4063. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4064. (should
  4065. (org-test-with-temp-text
  4066. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4067. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4068. (looking-at "#\\+BEGIN_QUOTE")))
  4069. ;; Optional argument is also case-insensitive.
  4070. (should
  4071. (org-test-with-temp-text
  4072. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
  4073. (let ((case-fold-search nil))
  4074. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4075. (looking-at "#\\+begin_quote")))))
  4076. (ert-deftest test-org/insert-structure-template ()
  4077. "Test `org-insert-structure-template'."
  4078. ;; Test in empty buffer.
  4079. (should
  4080. (string= "#+begin_foo\n#+end_foo\n"
  4081. (org-test-with-temp-text ""
  4082. (org-insert-structure-template "foo")
  4083. (buffer-string))))
  4084. ;; Test with multiple lines in buffer.
  4085. (should
  4086. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4087. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4088. (transient-mark-mode 1)
  4089. (org-mark-element)
  4090. (org-insert-structure-template "foo")
  4091. (buffer-string))))
  4092. ;; Mark only the current line.
  4093. (should
  4094. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4095. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4096. (transient-mark-mode 1)
  4097. (set-mark (point-min))
  4098. (end-of-line)
  4099. (org-insert-structure-template "foo")
  4100. (buffer-string))))
  4101. ;; Middle of paragraph.
  4102. (should
  4103. (string= "p1\n#+begin_foo\np2\n#+end_foo\np3"
  4104. (org-test-with-temp-text "p1\n<point>p2\np3"
  4105. (set-mark (line-beginning-position))
  4106. (end-of-line)
  4107. (activate-mark)
  4108. (org-insert-structure-template "foo")
  4109. (buffer-string))))
  4110. ;; Test with text in buffer, no region, no final newline.
  4111. (should
  4112. (string= "#+begin_foo\nI'm a paragraph.\n#+end_foo\n"
  4113. (org-test-with-temp-text "I'm a paragraph."
  4114. (org-mark-element)
  4115. (org-insert-structure-template "foo")
  4116. (buffer-string))))
  4117. ;; Test with text in buffer and region set.
  4118. (should
  4119. (string= "#+begin_foo\nI'm a paragraph\n\nI'm a second paragrah\n#+end_foo\n"
  4120. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragrah"
  4121. (set-mark (point))
  4122. (goto-char (point-max))
  4123. (org-insert-structure-template "foo")
  4124. (buffer-string))))
  4125. ;; Test with example escaping.
  4126. (should
  4127. (string= "#+begin_example\n,* Heading\n#+end_example\n"
  4128. (org-test-with-temp-text "* Heading"
  4129. (org-mark-element)
  4130. (org-insert-structure-template "example")
  4131. (buffer-string))))
  4132. ;; Test with indentation.
  4133. (should
  4134. (string= " #+begin_foo\n This is a paragraph\n #+end_foo\n"
  4135. (org-test-with-temp-text " This is a paragraph"
  4136. (org-mark-element)
  4137. (org-insert-structure-template "foo")
  4138. (buffer-string))))
  4139. (should
  4140. (string= " #+begin_foo\n Line 1\n Line2\n #+end_foo\n"
  4141. (org-test-with-temp-text " Line 1\n Line2"
  4142. (org-mark-element)
  4143. (org-insert-structure-template "foo")
  4144. (buffer-string))))
  4145. ;; Test point location.
  4146. (should
  4147. (string= "#+begin_foo\n"
  4148. (org-test-with-temp-text ""
  4149. (org-insert-structure-template "foo")
  4150. (buffer-substring (point-min) (point)))))
  4151. (should
  4152. (string= "#+begin_src "
  4153. (org-test-with-temp-text ""
  4154. (org-insert-structure-template "src")
  4155. (buffer-substring (point-min) (point))))))
  4156. (ert-deftest test-org/previous-block ()
  4157. "Test `org-previous-block' specifications."
  4158. ;; Regular test.
  4159. (should
  4160. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
  4161. (org-previous-block 1)
  4162. (looking-at "#\\+BEGIN_CENTER")))
  4163. ;; Ignore case.
  4164. (should
  4165. (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
  4166. (let ((case-fold-search nil))
  4167. (org-previous-block 1)
  4168. (looking-at "#\\+begin_center"))))
  4169. ;; Ignore current line.
  4170. (should
  4171. (org-test-with-temp-text
  4172. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
  4173. (org-previous-block 1)
  4174. (looking-at "#\\+BEGIN_QUOTE")))
  4175. ;; Throw an error when no block is found.
  4176. (should-error
  4177. (org-test-with-temp-text "Paragraph<point>"
  4178. (org-previous-block 1)))
  4179. ;; With an argument, skip many blocks at once.
  4180. (should
  4181. (org-test-with-temp-text
  4182. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4183. (org-previous-block 2)
  4184. (looking-at "#\\+BEGIN_CENTER")))
  4185. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4186. (should
  4187. (org-test-with-temp-text
  4188. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4189. (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4190. (looking-at "#\\+BEGIN_QUOTE")))
  4191. ;; Optional argument is also case-insensitive.
  4192. (should
  4193. (org-test-with-temp-text
  4194. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
  4195. (let ((case-fold-search nil))
  4196. (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4197. (looking-at "#\\+begin_quote")))))
  4198. ;;; Outline structure
  4199. (ert-deftest test-org/demote ()
  4200. "Test `org-demote' specifications."
  4201. ;; Add correct number of stars according to `org-odd-levels-only'.
  4202. (should
  4203. (= 2
  4204. (org-test-with-temp-text "* H"
  4205. (let ((org-odd-levels-only nil)) (org-demote))
  4206. (org-current-level))))
  4207. (should
  4208. (= 3
  4209. (org-test-with-temp-text "* H"
  4210. (let ((org-odd-levels-only t)) (org-demote))
  4211. (org-current-level))))
  4212. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4213. (should
  4214. (org-test-with-temp-text "* H :tag:"
  4215. (let ((org-tags-column 10)
  4216. (org-auto-align-tags t)
  4217. (org-odd-levels-only nil))
  4218. (org-demote))
  4219. (org-move-to-column 10)
  4220. (looking-at-p ":tag:$")))
  4221. (should-not
  4222. (org-test-with-temp-text "* H :tag:"
  4223. (let ((org-tags-column 10)
  4224. (org-auto-align-tags nil)
  4225. (org-odd-levels-only nil))
  4226. (org-demote))
  4227. (org-move-to-column 10)
  4228. (looking-at-p ":tag:$")))
  4229. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4230. ;; info and property drawers accordingly.
  4231. (should
  4232. (= 3
  4233. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4234. (let ((org-odd-levels-only nil)
  4235. (org-adapt-indentation t))
  4236. (org-demote))
  4237. (forward-line)
  4238. (org-get-indentation))))
  4239. (should
  4240. (= 3
  4241. (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4242. (let ((org-odd-levels-only nil)
  4243. (org-adapt-indentation t))
  4244. (org-demote))
  4245. (forward-line)
  4246. (org-get-indentation))))
  4247. (should-not
  4248. (= 3
  4249. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4250. (let ((org-odd-levels-only nil)
  4251. (org-adapt-indentation nil))
  4252. (org-demote))
  4253. (forward-line)
  4254. (org-get-indentation))))
  4255. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4256. ;; section accordingly. Ignore, however, footnote definitions and
  4257. ;; inlinetasks boundaries.
  4258. (should
  4259. (= 3
  4260. (org-test-with-temp-text "* H\n Paragraph"
  4261. (let ((org-odd-levels-only nil)
  4262. (org-adapt-indentation t))
  4263. (org-demote))
  4264. (forward-line)
  4265. (org-get-indentation))))
  4266. (should
  4267. (= 2
  4268. (org-test-with-temp-text "* H\n Paragraph"
  4269. (let ((org-odd-levels-only nil)
  4270. (org-adapt-indentation nil))
  4271. (org-demote))
  4272. (forward-line)
  4273. (org-get-indentation))))
  4274. (should
  4275. (zerop
  4276. (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
  4277. (let ((org-odd-levels-only nil)
  4278. (org-adapt-indentation t))
  4279. (org-demote))
  4280. (goto-char (point-max))
  4281. (org-get-indentation))))
  4282. (should
  4283. (= 3
  4284. (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
  4285. (let ((org-odd-levels-only nil)
  4286. (org-adapt-indentation t))
  4287. (org-demote))
  4288. (goto-char (point-max))
  4289. (org-get-indentation))))
  4290. (when (featurep 'org-inlinetask)
  4291. (should
  4292. (zerop
  4293. (let ((org-inlinetask-min-level 5)
  4294. (org-adapt-indentation t))
  4295. (org-test-with-temp-text "* H\n***** I\n***** END"
  4296. (org-demote)
  4297. (forward-line)
  4298. (org-get-indentation))))))
  4299. (when (featurep 'org-inlinetask)
  4300. (should
  4301. (= 3
  4302. (let ((org-inlinetask-min-level 5)
  4303. (org-adapt-indentation t))
  4304. (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
  4305. (org-demote)
  4306. (forward-line 2)
  4307. (org-get-indentation))))))
  4308. ;; Ignore contents of source blocks or example blocks when
  4309. ;; indentation should be preserved (through
  4310. ;; `org-src-preserve-indentation' or "-i" flag).
  4311. (should-not
  4312. (zerop
  4313. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4314. (let ((org-adapt-indentation t)
  4315. (org-src-preserve-indentation nil))
  4316. (org-demote))
  4317. (forward-line 2)
  4318. (org-get-indentation))))
  4319. (should
  4320. (zerop
  4321. (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
  4322. (let ((org-adapt-indentation t)
  4323. (org-src-preserve-indentation t))
  4324. (org-demote))
  4325. (forward-line 2)
  4326. (org-get-indentation))))
  4327. (should
  4328. (zerop
  4329. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4330. (let ((org-adapt-indentation t)
  4331. (org-src-preserve-indentation t))
  4332. (org-demote))
  4333. (forward-line 2)
  4334. (org-get-indentation))))
  4335. (should
  4336. (zerop
  4337. (org-test-with-temp-text
  4338. "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
  4339. (let ((org-adapt-indentation t)
  4340. (org-src-preserve-indentation nil))
  4341. (org-demote))
  4342. (forward-line 2)
  4343. (org-get-indentation)))))
  4344. (ert-deftest test-org/promote ()
  4345. "Test `org-promote' specifications."
  4346. ;; Return an error if headline is to be promoted to level 0, unless
  4347. ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
  4348. ;; headline becomes a comment.
  4349. (should-error
  4350. (org-test-with-temp-text "* H"
  4351. (let ((org-allow-promoting-top-level-subtree nil)) (org-promote))))
  4352. (should
  4353. (equal "# H"
  4354. (org-test-with-temp-text "* H"
  4355. (let ((org-allow-promoting-top-level-subtree t)) (org-promote))
  4356. (buffer-string))))
  4357. ;; Remove correct number of stars according to
  4358. ;; `org-odd-levels-only'.
  4359. (should
  4360. (= 2
  4361. (org-test-with-temp-text "*** H"
  4362. (let ((org-odd-levels-only nil)) (org-promote))
  4363. (org-current-level))))
  4364. (should
  4365. (= 1
  4366. (org-test-with-temp-text "*** H"
  4367. (let ((org-odd-levels-only t)) (org-promote))
  4368. (org-current-level))))
  4369. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4370. (should
  4371. (org-test-with-temp-text "** H :tag:"
  4372. (let ((org-tags-column 10)
  4373. (org-auto-align-tags t)
  4374. (org-odd-levels-only nil))
  4375. (org-promote))
  4376. (org-move-to-column 10)
  4377. (looking-at-p ":tag:$")))
  4378. (should-not
  4379. (org-test-with-temp-text "** H :tag:"
  4380. (let ((org-tags-column 10)
  4381. (org-auto-align-tags nil)
  4382. (org-odd-levels-only nil))
  4383. (org-promote))
  4384. (org-move-to-column 10)
  4385. (looking-at-p ":tag:$")))
  4386. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4387. ;; info and property drawers.
  4388. (should
  4389. (= 2
  4390. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4391. (let ((org-odd-levels-only nil)
  4392. (org-adapt-indentation t))
  4393. (org-promote))
  4394. (forward-line)
  4395. (org-get-indentation))))
  4396. (should
  4397. (= 2
  4398. (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4399. (let ((org-odd-levels-only nil)
  4400. (org-adapt-indentation t))
  4401. (org-promote))
  4402. (forward-line)
  4403. (org-get-indentation))))
  4404. (should-not
  4405. (= 2
  4406. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4407. (let ((org-odd-levels-only nil)
  4408. (org-adapt-indentation nil))
  4409. (org-promote))
  4410. (forward-line)
  4411. (org-get-indentation))))
  4412. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4413. ;; section accordingly. Ignore, however, footnote definitions and
  4414. ;; inlinetasks boundaries.
  4415. (should
  4416. (= 2
  4417. (org-test-with-temp-text "** H\n Paragraph"
  4418. (let ((org-odd-levels-only nil)
  4419. (org-adapt-indentation t))
  4420. (org-promote))
  4421. (forward-line)
  4422. (org-get-indentation))))
  4423. (should-not
  4424. (= 2
  4425. (org-test-with-temp-text "** H\n Paragraph"
  4426. (let ((org-odd-levels-only nil)
  4427. (org-adapt-indentation nil))
  4428. (org-promote))
  4429. (forward-line)
  4430. (org-get-indentation))))
  4431. (should
  4432. (= 2
  4433. (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
  4434. (let ((org-odd-levels-only nil)
  4435. (org-adapt-indentation t))
  4436. (org-promote))
  4437. (forward-line)
  4438. (org-get-indentation))))
  4439. (when (featurep 'org-inlinetask)
  4440. (should
  4441. (zerop
  4442. (let ((org-inlinetask-min-level 5)
  4443. (org-adapt-indentation t))
  4444. (org-test-with-temp-text "** H\n***** I\n***** END"
  4445. (org-promote)
  4446. (forward-line)
  4447. (org-get-indentation))))))
  4448. (when (featurep 'org-inlinetask)
  4449. (should
  4450. (= 2
  4451. (let ((org-inlinetask-min-level 5)
  4452. (org-adapt-indentation t))
  4453. (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
  4454. (org-promote)
  4455. (forward-line 2)
  4456. (org-get-indentation))))))
  4457. ;; Give up shifting if it would break document's structure
  4458. ;; otherwise.
  4459. (should
  4460. (= 3
  4461. (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
  4462. (let ((org-odd-levels-only nil)
  4463. (org-adapt-indentation t))
  4464. (org-promote))
  4465. (forward-line)
  4466. (org-get-indentation))))
  4467. (should
  4468. (= 3
  4469. (org-test-with-temp-text "** H\n Paragraph\n * list."
  4470. (let ((org-odd-levels-only nil)
  4471. (org-adapt-indentation t))
  4472. (org-promote))
  4473. (forward-line)
  4474. (org-get-indentation))))
  4475. ;; Ignore contents of source blocks or example blocks when
  4476. ;; indentation should be preserved (through
  4477. ;; `org-src-preserve-indentation' or "-i" flag).
  4478. (should-not
  4479. (zerop
  4480. (org-test-with-temp-text
  4481. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  4482. (let ((org-adapt-indentation t)
  4483. (org-src-preserve-indentation nil)
  4484. (org-odd-levels-only nil))
  4485. (org-promote))
  4486. (forward-line)
  4487. (org-get-indentation))))
  4488. (should
  4489. (zerop
  4490. (org-test-with-temp-text
  4491. "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
  4492. (let ((org-adapt-indentation t)
  4493. (org-src-preserve-indentation t)
  4494. (org-odd-levels-only nil))
  4495. (org-promote))
  4496. (forward-line)
  4497. (org-get-indentation))))
  4498. (should
  4499. (zerop
  4500. (org-test-with-temp-text
  4501. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  4502. (let ((org-adapt-indentation t)
  4503. (org-src-preserve-indentation t)
  4504. (org-odd-levels-only nil))
  4505. (org-promote))
  4506. (forward-line)
  4507. (org-get-indentation))))
  4508. (should
  4509. (zerop
  4510. (org-test-with-temp-text
  4511. "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
  4512. (let ((org-adapt-indentation t)
  4513. (org-src-preserve-indentation nil)
  4514. (org-odd-levels-only nil))
  4515. (org-promote))
  4516. (forward-line)
  4517. (org-get-indentation)))))
  4518. (ert-deftest test-org/org-get-valid-level ()
  4519. "Test function `org-get-valid-level' specifications."
  4520. (let ((org-odd-levels-only nil))
  4521. (should (equal 1 (org-get-valid-level 0 0)))
  4522. (should (equal 1 (org-get-valid-level 0 1)))
  4523. (should (equal 2 (org-get-valid-level 0 2)))
  4524. (should (equal 3 (org-get-valid-level 0 3)))
  4525. (should (equal 1 (org-get-valid-level 1 0)))
  4526. (should (equal 2 (org-get-valid-level 1 1)))
  4527. (should (equal 23 (org-get-valid-level 1 22)))
  4528. (should (equal 1 (org-get-valid-level 1 -1)))
  4529. (should (equal 1 (org-get-valid-level 2 -1))))
  4530. (let ((org-odd-levels-only t))
  4531. (should (equal 1 (org-get-valid-level 0 0)))
  4532. (should (equal 1 (org-get-valid-level 0 1)))
  4533. (should (equal 3 (org-get-valid-level 0 2)))
  4534. (should (equal 5 (org-get-valid-level 0 3)))
  4535. (should (equal 1 (org-get-valid-level 1 0)))
  4536. (should (equal 3 (org-get-valid-level 1 1)))
  4537. (should (equal 3 (org-get-valid-level 2 1)))
  4538. (should (equal 5 (org-get-valid-level 3 1)))
  4539. (should (equal 5 (org-get-valid-level 4 1)))
  4540. (should (equal 43 (org-get-valid-level 1 21)))
  4541. (should (equal 1 (org-get-valid-level 1 -1)))
  4542. (should (equal 1 (org-get-valid-level 2 -1)))
  4543. (should (equal 1 (org-get-valid-level 3 -1)))
  4544. (should (equal 3 (org-get-valid-level 4 -1)))
  4545. (should (equal 3 (org-get-valid-level 5 -1)))))
  4546. ;;; Planning
  4547. (ert-deftest test-org/at-planning-p ()
  4548. "Test `org-at-planning-p' specifications."
  4549. ;; Regular test.
  4550. (should
  4551. (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
  4552. (org-at-planning-p)))
  4553. (should-not
  4554. (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
  4555. (org-at-planning-p)))
  4556. ;; Correctly find planning attached to inlinetasks.
  4557. (when (featurep 'org-inlinetask)
  4558. (should
  4559. (org-test-with-temp-text
  4560. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
  4561. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4562. (should-not
  4563. (org-test-with-temp-text
  4564. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  4565. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4566. (should-not
  4567. (org-test-with-temp-text
  4568. "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  4569. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4570. (should-not
  4571. (org-test-with-temp-text
  4572. "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
  4573. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
  4574. (ert-deftest test-org/add-planning-info ()
  4575. "Test `org-add-planning-info'."
  4576. ;; Create deadline when `org-adapt-indentation' is non-nil.
  4577. (should
  4578. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4579. (org-test-with-temp-text "* H\nParagraph<point>"
  4580. (let ((org-adapt-indentation t))
  4581. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4582. (replace-regexp-in-string
  4583. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4584. nil nil 1))))
  4585. ;; Create deadline when `org-adapt-indentation' is nil.
  4586. (should
  4587. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  4588. (org-test-with-temp-text "* H\nParagraph<point>"
  4589. (let ((org-adapt-indentation nil))
  4590. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4591. (replace-regexp-in-string
  4592. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4593. nil nil 1))))
  4594. ;; Update deadline when `org-adapt-indentation' is non-nil.
  4595. (should
  4596. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4597. (org-test-with-temp-text "\
  4598. * H
  4599. DEADLINE: <2015-06-24 Wed>
  4600. Paragraph<point>"
  4601. (let ((org-adapt-indentation t))
  4602. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4603. (replace-regexp-in-string
  4604. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4605. nil nil 1))))
  4606. ;; Update deadline when `org-adapt-indentation' is nil.
  4607. (should
  4608. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  4609. (org-test-with-temp-text "\
  4610. * H
  4611. DEADLINE: <2015-06-24 Wed>
  4612. Paragraph<point>"
  4613. (let ((org-adapt-indentation nil))
  4614. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4615. (replace-regexp-in-string
  4616. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4617. nil nil 1))))
  4618. ;; Schedule when `org-adapt-indentation' is non-nil.
  4619. (should
  4620. (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
  4621. (org-test-with-temp-text "* H\nParagraph<point>"
  4622. (let ((org-adapt-indentation t))
  4623. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  4624. (replace-regexp-in-string
  4625. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4626. nil nil 1))))
  4627. ;; Schedule when `org-adapt-indentation' is nil.
  4628. (should
  4629. (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
  4630. (org-test-with-temp-text "* H\nParagraph<point>"
  4631. (let ((org-adapt-indentation nil))
  4632. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  4633. (replace-regexp-in-string
  4634. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4635. nil nil 1))))
  4636. ;; Add deadline when scheduled.
  4637. (should
  4638. (equal "\
  4639. * H
  4640. DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
  4641. Paragraph"
  4642. (org-test-with-temp-text "\
  4643. * H
  4644. SCHEDULED: <2015-06-24 Wed>
  4645. Paragraph<point>"
  4646. (let ((org-adapt-indentation t))
  4647. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4648. (replace-regexp-in-string
  4649. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4650. nil nil 1))))
  4651. ;; Remove middle entry.
  4652. (should
  4653. (equal "\
  4654. * H
  4655. CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
  4656. Paragraph"
  4657. (org-test-with-temp-text "\
  4658. * H
  4659. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  4660. Paragraph<point>"
  4661. (let ((org-adapt-indentation t))
  4662. (org-add-planning-info nil nil 'deadline))
  4663. (replace-regexp-in-string
  4664. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  4665. nil nil 1))))
  4666. ;; Remove last entry and then middle entry (order should not
  4667. ;; matter).
  4668. (should
  4669. (equal "\
  4670. * H
  4671. CLOSED: [2015-06-24]
  4672. Paragraph"
  4673. (org-test-with-temp-text "\
  4674. * H
  4675. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  4676. Paragraph<point>"
  4677. (let ((org-adapt-indentation t))
  4678. (org-add-planning-info nil nil 'scheduled 'deadline))
  4679. (replace-regexp-in-string
  4680. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  4681. nil nil 1))))
  4682. ;; Remove closed when `org-adapt-indentation' is non-nil.
  4683. (should
  4684. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4685. (org-test-with-temp-text "\
  4686. * H
  4687. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  4688. Paragraph<point>"
  4689. (let ((org-adapt-indentation t))
  4690. (org-add-planning-info nil nil 'closed))
  4691. (replace-regexp-in-string
  4692. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4693. nil nil 1))))
  4694. (should
  4695. (equal "* H\n Paragraph"
  4696. (org-test-with-temp-text "\
  4697. * H
  4698. CLOSED: [2015-06-25 Thu]
  4699. Paragraph<point>"
  4700. (let ((org-adapt-indentation t))
  4701. (org-add-planning-info nil nil 'closed))
  4702. (replace-regexp-in-string
  4703. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4704. nil nil 1))))
  4705. ;; Remove closed when `org-adapt-indentation' is nil.
  4706. (should
  4707. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  4708. (org-test-with-temp-text "\
  4709. * H
  4710. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  4711. Paragraph<point>"
  4712. (let ((org-adapt-indentation nil))
  4713. (org-add-planning-info nil nil 'closed))
  4714. (replace-regexp-in-string
  4715. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4716. nil nil 1))))
  4717. (should
  4718. (equal "* H\nParagraph"
  4719. (org-test-with-temp-text "\
  4720. * H
  4721. CLOSED: [2015-06-25 Thu]
  4722. Paragraph<point>"
  4723. (let ((org-adapt-indentation nil))
  4724. (org-add-planning-info nil nil 'closed))
  4725. (replace-regexp-in-string
  4726. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4727. nil nil 1))))
  4728. ;; Remove closed entry and delete empty line.
  4729. (should
  4730. (equal "\
  4731. * H
  4732. Paragraph"
  4733. (org-test-with-temp-text "\
  4734. * H
  4735. CLOSED: [2015-06-24 Wed]
  4736. Paragraph<point>"
  4737. (let ((org-adapt-indentation t))
  4738. (org-add-planning-info nil nil 'closed))
  4739. (replace-regexp-in-string
  4740. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4741. nil nil 1))))
  4742. ;; Remove one entry and update another.
  4743. (should
  4744. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4745. (org-test-with-temp-text "\
  4746. * H
  4747. SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
  4748. Paragraph<point>"
  4749. (let ((org-adapt-indentation t))
  4750. (org-add-planning-info 'deadline "<2015-06-25 Thu>" 'scheduled))
  4751. (replace-regexp-in-string
  4752. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4753. nil nil 1)))))
  4754. (ert-deftest test-org/deadline ()
  4755. "Test `org-deadline' specifications."
  4756. ;; Insert a new value or replace existing one.
  4757. (should
  4758. (equal "* H\nDEADLINE: <2012-03-29>"
  4759. (org-test-with-temp-text "* H"
  4760. (let ((org-adapt-indentation nil)
  4761. (org-last-inserted-timestamp nil))
  4762. (org-deadline nil "<2012-03-29 Tue>"))
  4763. (replace-regexp-in-string
  4764. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4765. nil nil 1))))
  4766. (should
  4767. (equal "* H\nDEADLINE: <2014-03-04>"
  4768. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  4769. (let ((org-adapt-indentation nil)
  4770. (org-last-inserted-timestamp nil))
  4771. (org-deadline nil "<2014-03-04 Thu>"))
  4772. (replace-regexp-in-string
  4773. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4774. nil nil 1))))
  4775. ;; Accept delta time, e.g., "+2d".
  4776. (should
  4777. (equal "* H\nDEADLINE: <2015-03-04>"
  4778. (org-test-at-time "2014-03-04"
  4779. (org-test-with-temp-text "* H"
  4780. (let ((org-adapt-indentation nil)
  4781. (org-last-inserted-timestamp nil))
  4782. (org-deadline nil "+1y"))
  4783. (replace-regexp-in-string
  4784. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  4785. ;; Preserve repeater.
  4786. (should
  4787. (equal "* H\nDEADLINE: <2012-03-29 +2y>"
  4788. (org-test-with-temp-text "* H"
  4789. (let ((org-adapt-indentation nil)
  4790. (org-last-inserted-timestamp nil))
  4791. (org-deadline nil "<2012-03-29 Tue +2y>"))
  4792. (replace-regexp-in-string
  4793. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  4794. ;; Remove CLOSED keyword, if any.
  4795. (should
  4796. (equal "* H\nDEADLINE: <2012-03-29>"
  4797. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  4798. (let ((org-adapt-indentation nil)
  4799. (org-last-inserted-timestamp nil))
  4800. (org-deadline nil "<2012-03-29 Tue>"))
  4801. (replace-regexp-in-string
  4802. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  4803. ;; With C-u argument, remove DEADLINE keyword.
  4804. (should
  4805. (equal "* H\n"
  4806. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  4807. (let ((org-adapt-indentation nil)
  4808. (org-last-inserted-timestamp nil))
  4809. (org-deadline '(4)))
  4810. (buffer-string))))
  4811. (should
  4812. (equal "* H"
  4813. (org-test-with-temp-text "* H"
  4814. (let ((org-adapt-indentation nil)
  4815. (org-last-inserted-timestamp nil))
  4816. (org-deadline '(4)))
  4817. (buffer-string))))
  4818. ;; With C-u C-u argument, prompt for a delay cookie.
  4819. (should
  4820. (equal "* H\nDEADLINE: <2012-03-29 -705d>"
  4821. (cl-letf (((symbol-function 'org-read-date)
  4822. (lambda (&rest args)
  4823. (apply #'encode-time
  4824. (org-parse-time-string "2014-03-04")))))
  4825. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  4826. (let ((org-adapt-indentation nil)
  4827. (org-last-inserted-timestamp nil))
  4828. (org-deadline '(16)))
  4829. (buffer-string)))))
  4830. (should-error
  4831. (cl-letf (((symbol-function 'org-read-date)
  4832. (lambda (&rest args)
  4833. (apply #'encode-time
  4834. (org-parse-time-string "2014-03-04")))))
  4835. (org-test-with-temp-text "* H"
  4836. (let ((org-adapt-indentation nil)
  4837. (org-last-inserted-timestamp nil))
  4838. (org-deadline '(16)))
  4839. (buffer-string))))
  4840. ;; When a region is active and
  4841. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  4842. ;; same value in all headlines in region.
  4843. (should
  4844. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  4845. (org-test-with-temp-text "* H1\n* H2"
  4846. (let ((org-adapt-indentation nil)
  4847. (org-last-inserted-timestamp nil)
  4848. (org-loop-over-headlines-in-active-region t))
  4849. (transient-mark-mode 1)
  4850. (push-mark (point) t t)
  4851. (goto-char (point-max))
  4852. (org-deadline nil "2012-03-29"))
  4853. (replace-regexp-in-string
  4854. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  4855. (should-not
  4856. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  4857. (org-test-with-temp-text "* H1\n* H2"
  4858. (let ((org-adapt-indentation nil)
  4859. (org-last-inserted-timestamp nil)
  4860. (org-loop-over-headlines-in-active-region nil))
  4861. (transient-mark-mode 1)
  4862. (push-mark (point) t t)
  4863. (goto-char (point-max))
  4864. (org-deadline nil "2012-03-29"))
  4865. (replace-regexp-in-string
  4866. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  4867. (ert-deftest test-org/schedule ()
  4868. "Test `org-schedule' specifications."
  4869. ;; Insert a new value or replace existing one.
  4870. (should
  4871. (equal "* H\nSCHEDULED: <2012-03-29>"
  4872. (org-test-with-temp-text "* H"
  4873. (let ((org-adapt-indentation nil)
  4874. (org-last-inserted-timestamp nil))
  4875. (org-schedule nil "<2012-03-29 Tue>"))
  4876. (replace-regexp-in-string
  4877. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4878. nil nil 1))))
  4879. (should
  4880. (equal "* H\nSCHEDULED: <2014-03-04>"
  4881. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  4882. (let ((org-adapt-indentation nil)
  4883. (org-last-inserted-timestamp nil))
  4884. (org-schedule nil "<2014-03-04 Thu>"))
  4885. (replace-regexp-in-string
  4886. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4887. nil nil 1))))
  4888. ;; Accept delta time, e.g., "+2d".
  4889. (should
  4890. (equal "* H\nSCHEDULED: <2015-03-04>"
  4891. (org-test-at-time "2014-03-04"
  4892. (org-test-with-temp-text "* H"
  4893. (let ((org-adapt-indentation nil)
  4894. (org-last-inserted-timestamp nil))
  4895. (org-schedule nil "+1y"))
  4896. (replace-regexp-in-string
  4897. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  4898. ;; Preserve repeater.
  4899. (should
  4900. (equal "* H\nSCHEDULED: <2012-03-29 +2y>"
  4901. (org-test-with-temp-text "* H"
  4902. (let ((org-adapt-indentation nil)
  4903. (org-last-inserted-timestamp nil))
  4904. (org-schedule nil "<2012-03-29 Tue +2y>"))
  4905. (replace-regexp-in-string
  4906. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  4907. ;; Remove CLOSED keyword, if any.
  4908. (should
  4909. (equal "* H\nSCHEDULED: <2012-03-29>"
  4910. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  4911. (let ((org-adapt-indentation nil)
  4912. (org-last-inserted-timestamp nil))
  4913. (org-schedule nil "<2012-03-29 Tue>"))
  4914. (replace-regexp-in-string
  4915. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  4916. ;; With C-u argument, remove SCHEDULED keyword.
  4917. (should
  4918. (equal "* H\n"
  4919. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  4920. (let ((org-adapt-indentation nil)
  4921. (org-last-inserted-timestamp nil))
  4922. (org-schedule '(4)))
  4923. (buffer-string))))
  4924. (should
  4925. (equal "* H"
  4926. (org-test-with-temp-text "* H"
  4927. (let ((org-adapt-indentation nil)
  4928. (org-last-inserted-timestamp nil))
  4929. (org-schedule '(4)))
  4930. (buffer-string))))
  4931. ;; With C-u C-u argument, prompt for a delay cookie.
  4932. (should
  4933. (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
  4934. (cl-letf (((symbol-function 'org-read-date)
  4935. (lambda (&rest args)
  4936. (apply #'encode-time
  4937. (org-parse-time-string "2014-03-04")))))
  4938. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  4939. (let ((org-adapt-indentation nil)
  4940. (org-last-inserted-timestamp nil))
  4941. (org-schedule '(16)))
  4942. (buffer-string)))))
  4943. (should-error
  4944. (cl-letf (((symbol-function 'org-read-date)
  4945. (lambda (&rest args)
  4946. (apply #'encode-time
  4947. (org-parse-time-string "2014-03-04")))))
  4948. (org-test-with-temp-text "* H"
  4949. (let ((org-adapt-indentation nil)
  4950. (org-last-inserted-timestamp nil))
  4951. (org-schedule '(16)))
  4952. (buffer-string))))
  4953. ;; When a region is active and
  4954. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  4955. ;; same value in all headlines in region.
  4956. (should
  4957. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  4958. (org-test-with-temp-text "* H1\n* H2"
  4959. (let ((org-adapt-indentation nil)
  4960. (org-last-inserted-timestamp nil)
  4961. (org-loop-over-headlines-in-active-region t))
  4962. (transient-mark-mode 1)
  4963. (push-mark (point) t t)
  4964. (goto-char (point-max))
  4965. (org-schedule nil "2012-03-29"))
  4966. (replace-regexp-in-string
  4967. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  4968. (should-not
  4969. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  4970. (org-test-with-temp-text "* H1\n* H2"
  4971. (let ((org-adapt-indentation nil)
  4972. (org-last-inserted-timestamp nil)
  4973. (org-loop-over-headlines-in-active-region nil))
  4974. (transient-mark-mode 1)
  4975. (push-mark (point) t t)
  4976. (goto-char (point-max))
  4977. (org-schedule nil "2012-03-29"))
  4978. (replace-regexp-in-string
  4979. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  4980. (should
  4981. ;; check if a repeater survives re-scheduling.
  4982. (string-match-p
  4983. "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
  4984. (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
  4985. (let ((org-adapt-indentation nil)
  4986. (org-last-inserted-timestamp nil))
  4987. (org-schedule nil "2017-02-01"))
  4988. (buffer-string)))))
  4989. ;;; Property API
  4990. (ert-deftest test-org/buffer-property-keys ()
  4991. "Test `org-buffer-property-keys' specifications."
  4992. ;; Retrieve properties across siblings.
  4993. (should
  4994. (equal '("A" "B")
  4995. (org-test-with-temp-text "
  4996. * H1
  4997. :PROPERTIES:
  4998. :A: 1
  4999. :END:
  5000. * H2
  5001. :PROPERTIES:
  5002. :B: 1
  5003. :END:"
  5004. (org-buffer-property-keys))))
  5005. ;; Retrieve properties across children.
  5006. (should
  5007. (equal '("A" "B")
  5008. (org-test-with-temp-text "
  5009. * H1
  5010. :PROPERTIES:
  5011. :A: 1
  5012. :END:
  5013. ** H2
  5014. :PROPERTIES:
  5015. :B: 1
  5016. :END:"
  5017. (org-buffer-property-keys))))
  5018. ;; Retrieve muliple properties in the same drawer.
  5019. (should
  5020. (equal '("A" "B")
  5021. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5022. (org-buffer-property-keys))))
  5023. ;; Ignore extension symbol in property name.
  5024. (should
  5025. (equal '("A")
  5026. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5027. (org-buffer-property-keys))))
  5028. ;; With non-nil COLUMNS, extract property names from columns.
  5029. (should
  5030. (equal '("A" "B")
  5031. (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
  5032. (org-buffer-property-keys nil nil t))))
  5033. (should
  5034. (equal '("A" "B" "COLUMNS")
  5035. (org-test-with-temp-text
  5036. "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
  5037. (org-buffer-property-keys nil nil t))))
  5038. ;; In COLUMNS, ignore title and summary-type.
  5039. (should
  5040. (equal '("A")
  5041. (org-test-with-temp-text "#+COLUMNS: %A(Foo)"
  5042. (org-buffer-property-keys nil nil t))))
  5043. (should
  5044. (equal '("A")
  5045. (org-test-with-temp-text "#+COLUMNS: %A{Foo}"
  5046. (org-buffer-property-keys nil nil t))))
  5047. (should
  5048. (equal '("A")
  5049. (org-test-with-temp-text "#+COLUMNS: %A(Foo){Bar}"
  5050. (org-buffer-property-keys nil nil t)))))
  5051. (ert-deftest test-org/property-values ()
  5052. "Test `org-property-values' specifications."
  5053. ;; Regular test.
  5054. (should
  5055. (equal '("2" "1")
  5056. (org-test-with-temp-text
  5057. "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
  5058. (org-property-values "A"))))
  5059. ;; Ignore empty values.
  5060. (should-not
  5061. (org-test-with-temp-text
  5062. "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
  5063. (org-property-values "A")))
  5064. ;; Take into consideration extended values.
  5065. (should
  5066. (equal '("1 2")
  5067. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5068. (org-property-values "A")))))
  5069. (ert-deftest test-org/set-property ()
  5070. "Test `org-set-property' specifications."
  5071. (should
  5072. (equal
  5073. ":PROPERTIES:\n:TEST: t\n:END:\n"
  5074. (org-test-with-temp-text ""
  5075. (let ((org-property-format "%s %s"))
  5076. (org-set-property "TEST" "t"))
  5077. (buffer-string))))
  5078. (should
  5079. (equal
  5080. "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5081. (org-test-with-temp-text "* H"
  5082. (let ((org-adapt-indentation nil)
  5083. (org-property-format "%s %s"))
  5084. (org-set-property "TEST" "t"))
  5085. (buffer-string)))))
  5086. (ert-deftest test-org/delete-property ()
  5087. "Test `org-delete-property' specifications."
  5088. (should
  5089. (equal
  5090. ""
  5091. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5092. (org-delete-property "TEST")
  5093. (buffer-string))))
  5094. (should
  5095. (equal
  5096. ":PROPERTIES:\n:TEST1: t\n:END:\n"
  5097. (org-test-with-temp-text ":PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5098. (org-delete-property "TEST2")
  5099. (buffer-string))))
  5100. (should
  5101. (equal
  5102. "* H\n"
  5103. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5104. (org-delete-property "TEST")
  5105. (buffer-string))))
  5106. (should
  5107. (equal
  5108. "* H\n:PROPERTIES:\n:TEST1: t\n:END:\n"
  5109. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5110. (org-delete-property "TEST2")
  5111. (buffer-string)))))
  5112. (ert-deftest test-org/delete-property-globally ()
  5113. "Test `org-delete-property-global' specifications."
  5114. (should
  5115. (equal
  5116. ""
  5117. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5118. (org-delete-property-globally "TEST")
  5119. (buffer-string))))
  5120. (should
  5121. (equal
  5122. "* H\n"
  5123. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n* H\n:PROPERTIES:\n:TEST: nil\n:END:"
  5124. (org-delete-property-globally "TEST")
  5125. (buffer-string)))))
  5126. (ert-deftest test-org/find-property ()
  5127. "Test `org-find-property' specifications."
  5128. ;; Regular test.
  5129. (should
  5130. (= 1
  5131. (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
  5132. (org-find-property "prop"))))
  5133. ;; Find properties in top-level property drawer.
  5134. (should
  5135. (= 1
  5136. (org-test-with-temp-text ":PROPERTIES:\n:PROP: value\n:END:"
  5137. (org-find-property "prop"))))
  5138. ;; Ignore false positives.
  5139. (should
  5140. (= 27
  5141. (org-test-with-temp-text
  5142. "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
  5143. (org-find-property "A"))))
  5144. ;; Return first entry found in buffer.
  5145. (should
  5146. (= 1
  5147. (org-test-with-temp-text
  5148. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5149. (org-find-property "A"))))
  5150. ;; Only search visible part of the buffer.
  5151. (should
  5152. (= 31
  5153. (org-test-with-temp-text
  5154. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5155. (org-narrow-to-subtree)
  5156. (org-find-property "A"))))
  5157. ;; With optional argument, only find entries with a specific value.
  5158. (should-not
  5159. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5160. (org-find-property "A" "2")))
  5161. (should
  5162. (= 31
  5163. (org-test-with-temp-text
  5164. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
  5165. (org-find-property "A" "2"))))
  5166. ;; Use "nil" for explicit nil values.
  5167. (should
  5168. (= 31
  5169. (org-test-with-temp-text
  5170. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
  5171. (org-find-property "A" "nil")))))
  5172. (ert-deftest test-org/entry-delete ()
  5173. "Test `org-entry-delete' specifications."
  5174. ;; Regular test.
  5175. (should
  5176. (string-match
  5177. " *:PROPERTIES:\n *:B: +2\n *:END:"
  5178. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5179. (org-entry-delete (point) "A")
  5180. (buffer-string))))
  5181. ;; Also remove accumulated properties.
  5182. (should-not
  5183. (string-match
  5184. ":A"
  5185. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
  5186. (org-entry-delete (point) "A")
  5187. (buffer-string))))
  5188. ;; When last property is removed, remove the property drawer.
  5189. (should-not
  5190. (string-match
  5191. ":PROPERTIES:"
  5192. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
  5193. (org-entry-delete (point) "A")
  5194. (buffer-string))))
  5195. ;; Return a non-nil value when some property was removed.
  5196. (should
  5197. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5198. (org-entry-delete (point) "A")))
  5199. (should-not
  5200. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5201. (org-entry-delete (point) "C")))
  5202. ;; Special properties cannot be located in a drawer. Allow to
  5203. ;; remove them anyway, in case of user error.
  5204. (should
  5205. (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
  5206. (org-entry-delete (point) "SCHEDULED"))))
  5207. (ert-deftest test-org/entry-get ()
  5208. "Test `org-entry-get' specifications."
  5209. ;; Regular test.
  5210. (should
  5211. (equal "1"
  5212. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:"
  5213. (org-entry-get (point) "A"))))
  5214. (should
  5215. (equal "1"
  5216. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5217. (org-entry-get (point) "A"))))
  5218. ;; Ignore case.
  5219. (should
  5220. (equal "1"
  5221. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5222. (org-entry-get (point) "a"))))
  5223. ;; Handle extended values, both before and after base value.
  5224. (should
  5225. (equal "1 2 3"
  5226. (org-test-with-temp-text
  5227. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5228. (org-entry-get (point) "A"))))
  5229. ;; Empty values are returned as the empty string.
  5230. (should
  5231. (equal ""
  5232. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
  5233. (org-entry-get (point) "A"))))
  5234. ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
  5235. ;; otherwise, return nil.
  5236. (should-not
  5237. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5238. (org-entry-get (point) "A")))
  5239. (should
  5240. (equal "nil"
  5241. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5242. (org-entry-get (point) "A" nil t))))
  5243. ;; Return nil when no property is found, independently on the
  5244. ;; LITERAL-NIL argument.
  5245. (should-not
  5246. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5247. (org-entry-get (point) "B")))
  5248. (should-not
  5249. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5250. (org-entry-get (point) "B" nil t)))
  5251. ;; Handle inheritance, when allowed. Include extended values and
  5252. ;; possibly global values.
  5253. (should
  5254. (equal
  5255. "1"
  5256. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:\n* H"
  5257. (org-entry-get (point-max) "A" t))))
  5258. (should
  5259. (equal
  5260. "1"
  5261. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5262. (org-entry-get (point-max) "A" t))))
  5263. (should
  5264. (equal
  5265. "1"
  5266. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5267. (let ((org-use-property-inheritance t))
  5268. (org-entry-get (point-max) "A" 'selective)))))
  5269. (should-not
  5270. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5271. (let ((org-use-property-inheritance nil))
  5272. (org-entry-get (point-max) "A" 'selective))))
  5273. (should
  5274. (equal
  5275. "1 2"
  5276. (org-test-with-temp-text
  5277. ":PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5278. (org-entry-get (point-max) "A" t))))
  5279. (should
  5280. (equal
  5281. "1 2"
  5282. (org-test-with-temp-text
  5283. "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5284. (org-entry-get (point-max) "A" t))))
  5285. (should
  5286. (equal
  5287. "1 2"
  5288. (org-test-with-temp-text
  5289. ":PROPERTIES:\n:A: 1\n:END:\n* H1\n* H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5290. (org-entry-get (point-max) "A" t))))
  5291. (should
  5292. (equal
  5293. "1 2"
  5294. (org-test-with-temp-text
  5295. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2.1\n* H2.2\n:PROPERTIES:\n:A+: 2\n:END:"
  5296. (org-entry-get (point-max) "A" t))))
  5297. (should
  5298. (equal "1"
  5299. (org-test-with-temp-text
  5300. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
  5301. (org-mode-restart)
  5302. (org-entry-get (point-max) "A" t))))
  5303. (should
  5304. (equal "0 1"
  5305. (org-test-with-temp-text
  5306. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
  5307. (org-mode-restart)
  5308. (org-entry-get (point-max) "A" t))))
  5309. ;; document level property-drawer has precedance over
  5310. ;; global-property by PROPERTY-keyword.
  5311. (should
  5312. (equal "0 2"
  5313. (org-test-with-temp-text
  5314. ":PROPERTIES:\n:A: 0\n:END:\n#+PROPERTY: A 1\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5315. (org-mode-restart)
  5316. (org-entry-get (point-max) "A" t)))))
  5317. (ert-deftest test-org/entry-properties ()
  5318. "Test `org-entry-properties' specifications."
  5319. ;; Get "ITEM" property.
  5320. (should
  5321. (equal "H"
  5322. (org-test-with-temp-text "* TODO H"
  5323. (cdr (assoc "ITEM" (org-entry-properties nil "ITEM"))))))
  5324. (should
  5325. (equal "H"
  5326. (org-test-with-temp-text "* TODO H"
  5327. (cdr (assoc "ITEM" (org-entry-properties))))))
  5328. ;; Get "TODO" property. TODO keywords are case sensitive.
  5329. (should
  5330. (equal "TODO"
  5331. (org-test-with-temp-text "* TODO H"
  5332. (cdr (assoc "TODO" (org-entry-properties nil "TODO"))))))
  5333. (should
  5334. (equal "TODO"
  5335. (org-test-with-temp-text "* TODO H"
  5336. (cdr (assoc "TODO" (org-entry-properties))))))
  5337. (should-not
  5338. (org-test-with-temp-text "* H"
  5339. (assoc "TODO" (org-entry-properties nil "TODO"))))
  5340. (should-not
  5341. (org-test-with-temp-text "* todo H"
  5342. (assoc "TODO" (org-entry-properties nil "TODO"))))
  5343. ;; Get "PRIORITY" property.
  5344. (should
  5345. (equal "A"
  5346. (org-test-with-temp-text "* [#A] H"
  5347. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  5348. (should
  5349. (equal "A"
  5350. (org-test-with-temp-text "* [#A] H"
  5351. (cdr (assoc "PRIORITY" (org-entry-properties))))))
  5352. (should
  5353. (equal (char-to-string org-priority-default)
  5354. (org-test-with-temp-text "* H"
  5355. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  5356. ;; Get "FILE" property.
  5357. (should
  5358. (org-test-with-temp-text-in-file "* H\nParagraph"
  5359. (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil "FILE")))
  5360. (buffer-file-name))))
  5361. (should
  5362. (org-test-with-temp-text-in-file "* H\nParagraph"
  5363. (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
  5364. (buffer-file-name))))
  5365. (should-not
  5366. (org-test-with-temp-text "* H\nParagraph"
  5367. (cdr (assoc "FILE" (org-entry-properties nil "FILE")))))
  5368. ;; Get "TAGS" property.
  5369. (should
  5370. (equal ":tag1:tag2:"
  5371. (org-test-with-temp-text "* H :tag1:tag2:"
  5372. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS"))))))
  5373. (should
  5374. (equal ":tag1:tag2:"
  5375. (org-test-with-temp-text "* H :tag1:tag2:"
  5376. (cdr (assoc "TAGS" (org-entry-properties))))))
  5377. (should-not
  5378. (org-test-with-temp-text "* H"
  5379. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS")))))
  5380. ;; Get "ALLTAGS" property.
  5381. (should
  5382. (equal ":tag1:tag2:"
  5383. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  5384. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS"))))))
  5385. (should
  5386. (equal ":tag1:tag2:"
  5387. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  5388. (cdr (assoc "ALLTAGS" (org-entry-properties))))))
  5389. (should-not
  5390. (org-test-with-temp-text "* H"
  5391. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS")))))
  5392. ;; Get "BLOCKED" property.
  5393. (should
  5394. (equal "t"
  5395. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  5396. (let ((org-enforce-todo-dependencies t)
  5397. (org-blocker-hook
  5398. '(org-block-todo-from-children-or-siblings-or-parent)))
  5399. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  5400. (should
  5401. (equal ""
  5402. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  5403. (let ((org-enforce-todo-dependencies t)
  5404. (org-blocker-hook
  5405. '(org-block-todo-from-children-or-siblings-or-parent)))
  5406. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  5407. ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
  5408. (should
  5409. (equal
  5410. "[2012-03-29 thu.]"
  5411. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  5412. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED"))))))
  5413. (should
  5414. (equal
  5415. "[2012-03-29 thu.]"
  5416. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  5417. (cdr (assoc "CLOSED" (org-entry-properties))))))
  5418. (should-not
  5419. (org-test-with-temp-text "* H"
  5420. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED")))))
  5421. (should
  5422. (equal
  5423. "<2014-03-04 tue.>"
  5424. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5425. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE"))))))
  5426. (should
  5427. (equal
  5428. "<2014-03-04 tue.>"
  5429. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5430. (cdr (assoc "DEADLINE" (org-entry-properties))))))
  5431. (should-not
  5432. (org-test-with-temp-text "* H"
  5433. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE")))))
  5434. (should
  5435. (equal
  5436. "<2014-03-04 tue.>"
  5437. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5438. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED"))))))
  5439. (should
  5440. (equal
  5441. "<2014-03-04 tue.>"
  5442. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5443. (cdr (assoc "SCHEDULED" (org-entry-properties))))))
  5444. (should-not
  5445. (org-test-with-temp-text "* H"
  5446. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED")))))
  5447. ;; Get "CATEGORY"
  5448. (should
  5449. (equal "cat"
  5450. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  5451. (cdr (assoc "CATEGORY" (org-entry-properties))))))
  5452. (should
  5453. (equal "cat"
  5454. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  5455. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5456. (should
  5457. (equal "cat"
  5458. (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
  5459. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5460. (should
  5461. (equal "cat2"
  5462. (org-test-with-temp-text
  5463. (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  5464. "\n"
  5465. "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
  5466. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5467. ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
  5468. (should
  5469. (equal "<2012-03-29 thu.>"
  5470. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
  5471. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  5472. (should
  5473. (equal "[2012-03-29 thu.]"
  5474. (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
  5475. (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
  5476. (should
  5477. (equal "<2012-03-29 thu.>"
  5478. (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
  5479. (cdr (assoc "TIMESTAMP" (org-entry-properties nil "TIMESTAMP"))))))
  5480. (should
  5481. (equal "[2014-03-04 tue.]"
  5482. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
  5483. (cdr (assoc "TIMESTAMP_IA"
  5484. (org-entry-properties nil "TIMESTAMP_IA"))))))
  5485. (should-not
  5486. (equal "<2012-03-29 thu.>"
  5487. (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
  5488. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  5489. ;; Get standard properties.
  5490. (should
  5491. (equal "1"
  5492. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5493. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5494. ;; Handle extended properties.
  5495. (should
  5496. (equal "1 2 3"
  5497. (org-test-with-temp-text
  5498. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5499. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5500. (should
  5501. (equal "1 2 3"
  5502. (org-test-with-temp-text
  5503. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
  5504. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5505. ;; Ignore forbidden (special) properties.
  5506. (should-not
  5507. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
  5508. (cdr (assoc "TODO" (org-entry-properties nil 'standard))))))
  5509. (ert-deftest test-org/entry-put ()
  5510. "Test `org-entry-put' specifications."
  5511. ;; Error when not a string or nil.
  5512. (should-error
  5513. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5514. (org-entry-put 1 "test" 2)))
  5515. ;; Error when property name is invalid.
  5516. (should-error
  5517. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5518. (org-entry-put 1 "no space" "value")))
  5519. (should-error
  5520. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5521. (org-entry-put 1 "" "value")))
  5522. ;; Set "TODO" property.
  5523. (should
  5524. (string-match (regexp-quote " TODO H")
  5525. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  5526. (org-entry-put (point) "TODO" "TODO")
  5527. (buffer-string))))
  5528. (should
  5529. (string-match (regexp-quote "* H")
  5530. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  5531. (org-entry-put (point) "TODO" nil)
  5532. (buffer-string))))
  5533. ;; Set "PRIORITY" property.
  5534. (should
  5535. (equal "* [#A] H"
  5536. (org-test-with-temp-text "* [#B] H"
  5537. (org-entry-put (point) "PRIORITY" "A")
  5538. (buffer-string))))
  5539. (should
  5540. (equal "* H"
  5541. (org-test-with-temp-text "* [#B] H"
  5542. (org-entry-put (point) "PRIORITY" nil)
  5543. (buffer-string))))
  5544. ;; Set "SCHEDULED" property.
  5545. (should
  5546. (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
  5547. (org-test-with-temp-text "* H"
  5548. (org-entry-put (point) "SCHEDULED" "2014-03-04")
  5549. (buffer-string))))
  5550. (should
  5551. (string= "* H\n"
  5552. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5553. (org-entry-put (point) "SCHEDULED" nil)
  5554. (buffer-string))))
  5555. (should
  5556. (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
  5557. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5558. (org-entry-put (point) "SCHEDULED" "earlier")
  5559. (buffer-string))))
  5560. (should
  5561. (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
  5562. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5563. (org-entry-put (point) "SCHEDULED" "later")
  5564. (buffer-string))))
  5565. ;; Set "DEADLINE" property.
  5566. (should
  5567. (string-match "^ *DEADLINE: <2014-03-04 .*?>"
  5568. (org-test-with-temp-text "* H"
  5569. (org-entry-put (point) "DEADLINE" "2014-03-04")
  5570. (buffer-string))))
  5571. (should
  5572. (string= "* H\n"
  5573. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5574. (org-entry-put (point) "DEADLINE" nil)
  5575. (buffer-string))))
  5576. (should
  5577. (string-match "^ *DEADLINE: <2014-03-03 .*?>"
  5578. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5579. (org-entry-put (point) "DEADLINE" "earlier")
  5580. (buffer-string))))
  5581. (should
  5582. (string-match "^ *DEADLINE: <2014-03-05 .*?>"
  5583. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5584. (org-entry-put (point) "DEADLINE" "later")
  5585. (buffer-string))))
  5586. ;; Set "CATEGORY" property
  5587. (should
  5588. (string-match "^ *:CATEGORY: cat"
  5589. (org-test-with-temp-text "* H"
  5590. (org-entry-put (point) "CATEGORY" "cat")
  5591. (buffer-string))))
  5592. ;; Regular properties, with or without pre-existing drawer.
  5593. (should
  5594. (string-match "^ *:A: +2$"
  5595. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5596. (org-entry-put (point) "A" "2")
  5597. (buffer-string))))
  5598. (should
  5599. (string-match "^ *:A: +1$"
  5600. (org-test-with-temp-text "* H"
  5601. (org-entry-put (point) "A" "1")
  5602. (buffer-string))))
  5603. ;; Special case: two consecutive headlines.
  5604. (should
  5605. (string-match "\\* A\n *:PROPERTIES:"
  5606. (org-test-with-temp-text "* A\n** B"
  5607. (org-entry-put (point) "A" "1")
  5608. (buffer-string)))))
  5609. (ert-deftest test-org/refresh-properties ()
  5610. "Test `org-refresh-properties' specifications."
  5611. (should
  5612. (equal "1"
  5613. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5614. (org-refresh-properties "A" 'org-test)
  5615. (get-text-property (point) 'org-test))))
  5616. (should-not
  5617. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5618. (org-refresh-properties "B" 'org-test)
  5619. (get-text-property (point) 'org-test)))
  5620. ;; Handle properties only defined with extension syntax, i.e.,
  5621. ;; "PROPERTY+".
  5622. (should
  5623. (equal "1"
  5624. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
  5625. (org-refresh-properties "A" 'org-test)
  5626. (get-text-property (point) 'org-test))))
  5627. ;; When property is inherited, add text property to the whole
  5628. ;; sub-tree.
  5629. (should
  5630. (equal "1"
  5631. (org-test-with-temp-text
  5632. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
  5633. (let ((org-use-property-inheritance t))
  5634. (org-refresh-properties "A" 'org-test))
  5635. (get-text-property (point) 'org-test))))
  5636. ;; When a document level property-drawer is used, those properties
  5637. ;; should work exactly like headline-properties as if at a
  5638. ;; headline-level 0.
  5639. (should
  5640. (equal "1"
  5641. (org-test-with-temp-text
  5642. ":PROPERTIES:\n:A: 1\n:END:\n"
  5643. (org-mode-restart)
  5644. (let ((org-use-property-inheritance t))
  5645. (org-refresh-properties "A" 'org-test))
  5646. (get-text-property (point) 'org-test))))
  5647. (should-not
  5648. (equal "1"
  5649. (org-test-with-temp-text
  5650. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  5651. (org-mode-restart)
  5652. (let ((org-use-property-inheritance nil))
  5653. (org-refresh-properties "A" 'org-test))
  5654. (get-text-property (point) 'org-test))))
  5655. (should
  5656. (equal "1"
  5657. (org-test-with-temp-text
  5658. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  5659. (org-mode-restart)
  5660. (let ((org-use-property-inheritance t))
  5661. (org-refresh-properties "A" 'org-test))
  5662. (get-text-property (point) 'org-test))))
  5663. (should
  5664. (equal "2"
  5665. (org-test-with-temp-text
  5666. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1\n:PROPERTIES:\n:A: 2\n:END:"
  5667. (org-mode-restart)
  5668. (let ((org-use-property-inheritance t))
  5669. (org-refresh-properties "A" 'org-test))
  5670. (get-text-property (point) 'org-test))))
  5671. ;; When property is inherited, use global value across the whole
  5672. ;; buffer. However local values have precedence, as well as the
  5673. ;; document level property-drawer.
  5674. (should-not
  5675. (equal "1"
  5676. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  5677. (org-mode-restart)
  5678. (let ((org-use-property-inheritance nil))
  5679. (org-refresh-properties "A" 'org-test))
  5680. (get-text-property (point) 'org-test))))
  5681. (should
  5682. (equal "1"
  5683. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  5684. (org-mode-restart)
  5685. (let ((org-use-property-inheritance t))
  5686. (org-refresh-properties "A" 'org-test))
  5687. (get-text-property (point) 'org-test))))
  5688. (should
  5689. (equal "2"
  5690. (org-test-with-temp-text
  5691. "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
  5692. (org-mode-restart)
  5693. (let ((org-use-property-inheritance t))
  5694. (org-refresh-properties "A" 'org-test))
  5695. (get-text-property (point) 'org-test))))
  5696. ;; When both keyword-property and document-level property-block is
  5697. ;; defined, the property-block has precedance.
  5698. (should
  5699. (equal "1"
  5700. (org-test-with-temp-text
  5701. ":PROPERTIES:\n:A: 1\n:END:\n#+PROPERTY: A 2\n<point>* H1"
  5702. (org-mode-restart)
  5703. (let ((org-use-property-inheritance t))
  5704. (org-refresh-properties "A" 'org-test))
  5705. (get-text-property (point) 'org-test)))))
  5706. (ert-deftest test-org/refresh-category-properties ()
  5707. "Test `org-refresh-category-properties' specifications"
  5708. (should
  5709. (equal "cat1"
  5710. (org-test-with-temp-text
  5711. ":PROPERTIES:\n:CATEGORY: cat1\n:END:"
  5712. (org-refresh-category-properties)
  5713. (get-text-property (point) 'org-category))))
  5714. (should
  5715. (equal "cat1"
  5716. (org-test-with-temp-text
  5717. "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  5718. (org-refresh-category-properties)
  5719. (get-text-property (point) 'org-category))))
  5720. ;; Even though property-inheritance is deactivated, category
  5721. ;; property should be inherited. As described in
  5722. ;; `org-use-property-inheritance'.
  5723. (should
  5724. (equal "cat1"
  5725. (org-test-with-temp-text
  5726. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  5727. (org-mode-restart)
  5728. (let ((org-use-property-inheritance nil))
  5729. (org-refresh-category-properties))
  5730. (get-text-property (point) 'org-category))))
  5731. (should
  5732. (equal "cat1"
  5733. (org-test-with-temp-text
  5734. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  5735. (org-mode-restart)
  5736. (let ((org-use-property-inheritance t))
  5737. (org-refresh-category-properties))
  5738. (get-text-property (point) 'org-category))))
  5739. (should
  5740. (equal "cat2"
  5741. (org-test-with-temp-text
  5742. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H\n:PROPERTIES:\n:CATEGORY: cat2\n:END:\n"
  5743. (org-mode-restart)
  5744. (let ((org-use-property-inheritance t))
  5745. (org-refresh-category-properties))
  5746. (get-text-property (point) 'org-category)))))
  5747. ;;; Refile
  5748. (ert-deftest test-org/refile-get-targets ()
  5749. "Test `org-refile-get-targets' specifications."
  5750. ;; :maxlevel includes all headings above specified value.
  5751. (should
  5752. (equal '("H1" "H2" "H3")
  5753. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  5754. (let ((org-refile-use-outline-path nil)
  5755. (org-refile-targets `((nil :maxlevel . 3))))
  5756. (mapcar #'car (org-refile-get-targets))))))
  5757. (should
  5758. (equal '("H1" "H2")
  5759. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  5760. (let ((org-refile-use-outline-path nil)
  5761. (org-refile-targets `((nil :maxlevel . 2))))
  5762. (mapcar #'car (org-refile-get-targets))))))
  5763. ;; :level limits targets to headlines with the specified level.
  5764. (should
  5765. (equal '("H2")
  5766. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  5767. (let ((org-refile-use-outline-path nil)
  5768. (org-refile-targets `((nil :level . 2))))
  5769. (mapcar #'car (org-refile-get-targets))))))
  5770. ;; :tag limits targets to headlines with specified tag.
  5771. (should
  5772. (equal '("H1")
  5773. (org-test-with-temp-text "* H1 :foo:\n** H2\n*** H3 :bar:"
  5774. (let ((org-refile-use-outline-path nil)
  5775. (org-refile-targets `((nil :tag . "foo"))))
  5776. (mapcar #'car (org-refile-get-targets))))))
  5777. ;; :todo limits targets to headlines with specified TODO keyword.
  5778. (should
  5779. (equal '("H2")
  5780. (org-test-with-temp-text "* H1\n** TODO H2\n*** DONE H3"
  5781. (let ((org-refile-use-outline-path nil)
  5782. (org-refile-targets `((nil :todo . "TODO"))))
  5783. (mapcar #'car (org-refile-get-targets))))))
  5784. ;; :regexp filters targets matching provided regexp.
  5785. (should
  5786. (equal '("F2" "F3")
  5787. (org-test-with-temp-text "* H1\n** F2\n*** F3"
  5788. (let ((org-refile-use-outline-path nil)
  5789. (org-refile-targets `((nil :regexp . "F"))))
  5790. (mapcar #'car (org-refile-get-targets))))))
  5791. ;; A nil `org-refile-targets' includes only top level headlines in
  5792. ;; current buffer.
  5793. (should
  5794. (equal '("H1" "H2")
  5795. (org-test-with-temp-text "* H1\n** S1\n* H2"
  5796. (let ((org-refile-use-outline-path nil)
  5797. (org-refile-targets nil))
  5798. (mapcar #'car (org-refile-get-targets))))))
  5799. ;; Return value is the union of the targets according to all the
  5800. ;; defined rules. However, prevent duplicates.
  5801. (should
  5802. (equal '("F2" "F3" "H1")
  5803. (org-test-with-temp-text "* TODO H1\n** F2\n*** F3"
  5804. (let ((org-refile-use-outline-path nil)
  5805. (org-refile-targets `((nil :regexp . "F")
  5806. (nil :todo . "TODO"))))
  5807. (mapcar #'car (org-refile-get-targets))))))
  5808. (should
  5809. (equal '("F2" "F3" "H1")
  5810. (org-test-with-temp-text "* TODO H1\n** TODO F2\n*** F3"
  5811. (let ((org-refile-use-outline-path nil)
  5812. (org-refile-targets `((nil :regexp . "F")
  5813. (nil :todo . "TODO"))))
  5814. (mapcar #'car (org-refile-get-targets))))))
  5815. ;; When `org-refile-use-outline-path' is non-nil, provide targets as
  5816. ;; paths.
  5817. (should
  5818. (equal '("H1" "H1/H2" "H1/H2/H3")
  5819. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  5820. (let ((org-refile-use-outline-path t)
  5821. (org-refile-targets `((nil :maxlevel . 3))))
  5822. (mapcar #'car (org-refile-get-targets))))))
  5823. ;; When providing targets as paths, escape forward slashes in
  5824. ;; headings with backslashes.
  5825. (should
  5826. (equal '("H1\\/foo")
  5827. (org-test-with-temp-text "* H1/foo"
  5828. (let ((org-refile-use-outline-path t)
  5829. (org-refile-targets `((nil :maxlevel . 1))))
  5830. (mapcar #'car (org-refile-get-targets))))))
  5831. ;; When `org-refile-use-outline-path' is `file', include file name
  5832. ;; without directory in targets.
  5833. (should
  5834. (org-test-with-temp-text-in-file "* H1"
  5835. (let* ((filename (buffer-file-name))
  5836. (org-refile-use-outline-path 'file)
  5837. (org-refile-targets `(((,filename) :level . 1))))
  5838. (member (file-name-nondirectory filename)
  5839. (mapcar #'car (org-refile-get-targets))))))
  5840. ;; When `org-refile-use-outline-path' is `full-file-path', include
  5841. ;; full file name.
  5842. (should
  5843. (org-test-with-temp-text-in-file "* H1"
  5844. (let* ((filename (file-truename (buffer-file-name)))
  5845. (org-refile-use-outline-path 'full-file-path)
  5846. (org-refile-targets `(((,filename) :level . 1))))
  5847. (member filename (mapcar #'car (org-refile-get-targets))))))
  5848. ;; When `org-refile-use-outline-path' is `buffer-name', include
  5849. ;; buffer name.
  5850. (should
  5851. (org-test-with-temp-text "* H1"
  5852. (let* ((org-refile-use-outline-path 'buffer-name)
  5853. (org-refile-targets `((nil :level . 1))))
  5854. (member (buffer-name) (mapcar #'car (org-refile-get-targets)))))))
  5855. ;;; Sparse trees
  5856. (ert-deftest test-org/match-sparse-tree ()
  5857. "Test `org-match-sparse-tree' specifications."
  5858. ;; Match tags.
  5859. (should-not
  5860. (org-test-with-temp-text "* H\n** H1 :tag:"
  5861. (org-match-sparse-tree nil "tag")
  5862. (search-forward "H1")
  5863. (org-invisible-p2)))
  5864. (should
  5865. (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
  5866. (org-match-sparse-tree nil "tag")
  5867. (search-forward "H2")
  5868. (org-invisible-p2)))
  5869. ;; "-" operator for tags.
  5870. (should-not
  5871. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  5872. (org-match-sparse-tree nil "tag1-tag2")
  5873. (search-forward "H1")
  5874. (org-invisible-p2)))
  5875. (should
  5876. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  5877. (org-match-sparse-tree nil "tag1-tag2")
  5878. (search-forward "H2")
  5879. (org-invisible-p2)))
  5880. ;; "&" operator for tags.
  5881. (should
  5882. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  5883. (org-match-sparse-tree nil "tag1&tag2")
  5884. (search-forward "H1")
  5885. (org-invisible-p2)))
  5886. (should-not
  5887. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  5888. (org-match-sparse-tree nil "tag1&tag2")
  5889. (search-forward "H2")
  5890. (org-invisible-p2)))
  5891. ;; "|" operator for tags.
  5892. (should-not
  5893. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  5894. (org-match-sparse-tree nil "tag1|tag2")
  5895. (search-forward "H1")
  5896. (org-invisible-p2)))
  5897. (should-not
  5898. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  5899. (org-match-sparse-tree nil "tag1|tag2")
  5900. (search-forward "H2")
  5901. (org-invisible-p2)))
  5902. ;; Regexp match on tags.
  5903. (should-not
  5904. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  5905. (org-match-sparse-tree nil "{^tag.*}")
  5906. (search-forward "H1")
  5907. (org-invisible-p2)))
  5908. (should
  5909. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  5910. (org-match-sparse-tree nil "{^tag.*}")
  5911. (search-forward "H2")
  5912. (org-invisible-p2)))
  5913. ;; Match group tags.
  5914. (should-not
  5915. (org-test-with-temp-text
  5916. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  5917. (org-match-sparse-tree nil "work")
  5918. (search-forward "H1")
  5919. (org-invisible-p2)))
  5920. (should-not
  5921. (org-test-with-temp-text
  5922. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  5923. (org-match-sparse-tree nil "work")
  5924. (search-forward "H2")
  5925. (org-invisible-p2)))
  5926. ;; Match group tags with hard brackets.
  5927. (should-not
  5928. (org-test-with-temp-text
  5929. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  5930. (org-match-sparse-tree nil "work")
  5931. (search-forward "H1")
  5932. (org-invisible-p2)))
  5933. (should-not
  5934. (org-test-with-temp-text
  5935. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  5936. (org-match-sparse-tree nil "work")
  5937. (search-forward "H2")
  5938. (org-invisible-p2)))
  5939. ;; Match tags in hierarchies
  5940. (should-not
  5941. (org-test-with-temp-text
  5942. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  5943. #+TAGS: [ Lev_2 : Lev_3 ]\n
  5944. #+TAGS: { Lev_3 : Lev_4 }\n
  5945. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  5946. (org-match-sparse-tree nil "Lev_1")
  5947. (search-forward "H4")
  5948. (org-invisible-p2)))
  5949. (should-not
  5950. (org-test-with-temp-text
  5951. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  5952. #+TAGS: [ Lev_2 : Lev_3 ]\n
  5953. #+TAGS: { Lev_3 : Lev_4 }\n
  5954. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  5955. (org-match-sparse-tree nil "Lev_1+Lev_3")
  5956. (search-forward "H4")
  5957. (org-invisible-p2)))
  5958. ;; Match regular expressions in tags
  5959. (should-not
  5960. (org-test-with-temp-text
  5961. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
  5962. (org-match-sparse-tree nil "Lev")
  5963. (search-forward "H1")
  5964. (org-invisible-p2)))
  5965. (should
  5966. (org-test-with-temp-text
  5967. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
  5968. (org-match-sparse-tree nil "Lev")
  5969. (search-forward "H1")
  5970. (org-invisible-p2)))
  5971. ;; Match properties.
  5972. (should
  5973. (org-test-with-temp-text
  5974. "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
  5975. (org-match-sparse-tree nil "A=\"1\"")
  5976. (search-forward "H2")
  5977. (org-invisible-p2)))
  5978. (should-not
  5979. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  5980. (org-match-sparse-tree nil "A=\"1\"")
  5981. (search-forward "H2")
  5982. (org-invisible-p2)))
  5983. ;; Case is not significant when matching properties.
  5984. (should-not
  5985. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  5986. (org-match-sparse-tree nil "a=\"1\"")
  5987. (search-forward "H2")
  5988. (org-invisible-p2)))
  5989. (should-not
  5990. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
  5991. (org-match-sparse-tree nil "A=\"1\"")
  5992. (search-forward "H2")
  5993. (org-invisible-p2)))
  5994. ;; Match special LEVEL property.
  5995. (should-not
  5996. (org-test-with-temp-text "* H\n** H1\n*** H2"
  5997. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  5998. (search-forward "H1")
  5999. (org-invisible-p2)))
  6000. (should
  6001. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6002. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6003. (search-forward "H2")
  6004. (org-invisible-p2)))
  6005. ;; Comparison operators when matching properties.
  6006. (should
  6007. (org-test-with-temp-text
  6008. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6009. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6010. (search-forward "H1")
  6011. (org-invisible-p2)))
  6012. (should-not
  6013. (org-test-with-temp-text
  6014. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6015. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6016. (search-forward "H2")
  6017. (org-invisible-p2)))
  6018. ;; Regexp match on properties values.
  6019. (should-not
  6020. (org-test-with-temp-text
  6021. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6022. (org-match-sparse-tree nil "A={f.*}")
  6023. (search-forward "H1")
  6024. (org-invisible-p2)))
  6025. (should
  6026. (org-test-with-temp-text
  6027. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6028. (org-match-sparse-tree nil "A={f.*}")
  6029. (search-forward "H2")
  6030. (org-invisible-p2)))
  6031. ;; With an optional argument, limit match to TODO entries.
  6032. (should-not
  6033. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6034. (org-match-sparse-tree t "tag")
  6035. (search-forward "H1")
  6036. (org-invisible-p2)))
  6037. (should
  6038. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6039. (org-match-sparse-tree t "tag")
  6040. (search-forward "H2")
  6041. (org-invisible-p2))))
  6042. (ert-deftest test-org/occur ()
  6043. "Test `org-occur' specifications."
  6044. ;; Count number of matches.
  6045. (should
  6046. (= 1
  6047. (org-test-with-temp-text "* H\nA\n* H2"
  6048. (org-occur "A"))))
  6049. (should
  6050. (= 2
  6051. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6052. (org-occur "A"))))
  6053. ;; Test CALLBACK optional argument.
  6054. (should
  6055. (= 0
  6056. (org-test-with-temp-text "* H\nA\n* H2"
  6057. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6058. (should
  6059. (= 1
  6060. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6061. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6062. ;; Case-fold searches according to `org-occur-case-fold-search'.
  6063. (should
  6064. (= 2
  6065. (org-test-with-temp-text "Aa"
  6066. (let ((org-occur-case-fold-search t)) (org-occur "A")))))
  6067. (should
  6068. (= 2
  6069. (org-test-with-temp-text "Aa"
  6070. (let ((org-occur-case-fold-search t)) (org-occur "a")))))
  6071. (should
  6072. (= 1
  6073. (org-test-with-temp-text "Aa"
  6074. (let ((org-occur-case-fold-search nil)) (org-occur "A")))))
  6075. (should
  6076. (= 1
  6077. (org-test-with-temp-text "Aa"
  6078. (let ((org-occur-case-fold-search nil)) (org-occur "a")))))
  6079. (should
  6080. (= 1
  6081. (org-test-with-temp-text "Aa"
  6082. (let ((org-occur-case-fold-search 'smart)) (org-occur "A")))))
  6083. (should
  6084. (= 2
  6085. (org-test-with-temp-text "Aa"
  6086. (let ((org-occur-case-fold-search 'smart)) (org-occur "a"))))))
  6087. ;;; Tags
  6088. (ert-deftest test-org/tag-string-to-alist ()
  6089. "Test `org-tag-string-to-alist' specifications."
  6090. ;; Tag without selection key.
  6091. (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
  6092. ;; Tag with selection key.
  6093. (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t))))
  6094. ;; Tag group.
  6095. (should
  6096. (equal
  6097. (org-tag-string-to-alist "[ group : t1 t2 ]")
  6098. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag))))
  6099. ;; Mutually exclusive tags.
  6100. (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
  6101. '((:startgroup) ("tag1") ("tag2") (:endgroup))))
  6102. (should
  6103. (equal
  6104. (org-tag-string-to-alist "{ group : tag1 tag2 }")
  6105. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))))
  6106. (ert-deftest test-org/tag-alist-to-string ()
  6107. "Test `org-tag-alist-to-string' specifications."
  6108. (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
  6109. (should (equal (org-tag-alist-to-string '(("tag1" . ?t))) "tag1(t)"))
  6110. (should
  6111. (equal
  6112. (org-tag-alist-to-string
  6113. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6114. "[ group : t1 t2 ]"))
  6115. (should
  6116. (equal (org-tag-alist-to-string
  6117. '((:startgroup) ("tag1") ("tag2") (:endgroup)))
  6118. "{ tag1 tag2 }"))
  6119. (should
  6120. (equal
  6121. (org-tag-alist-to-string
  6122. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))
  6123. "{ group : tag1 tag2 }")))
  6124. (ert-deftest test-org/tag-alist-to-groups ()
  6125. "Test `org-tag-alist-to-groups' specifications."
  6126. (should
  6127. (equal (org-tag-alist-to-groups
  6128. '((:startgroup) ("group") (:grouptags) ("t1") ("t2") (:endgroup)))
  6129. '(("group" "t1" "t2"))))
  6130. (should
  6131. (equal
  6132. (org-tag-alist-to-groups
  6133. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6134. '(("group" "t1" "t2"))))
  6135. (should-not
  6136. (org-tag-alist-to-groups
  6137. '((:startgroup) ("group") ("t1") ("t2") (:endgroup)))))
  6138. (ert-deftest test-org/tag-align ()
  6139. "Test tags alignment."
  6140. ;; Test aligning tags with different display width.
  6141. (should
  6142. ;; 12345678901234567890
  6143. (equal "* Test :abc:"
  6144. (org-test-with-temp-text "* Test :abc:"
  6145. (let ((org-tags-column -20)
  6146. (indent-tabs-mode nil))
  6147. (org-fix-tags-on-the-fly))
  6148. (buffer-string))))
  6149. (should
  6150. ;; 12345678901234567890
  6151. (equal "* Test :日本語:"
  6152. (org-test-with-temp-text "* Test :日本語:"
  6153. (let ((org-tags-column -20)
  6154. (indent-tabs-mode nil))
  6155. (org-fix-tags-on-the-fly))
  6156. (buffer-string))))
  6157. ;; Make sure aligning tags do not skip invisible text.
  6158. (should
  6159. (equal "* [[linkx]] :tag:"
  6160. (org-test-with-temp-text "* [[link<point>]] :tag:"
  6161. (let ((org-tags-column 0))
  6162. (org-fix-tags-on-the-fly)
  6163. (insert "x")
  6164. (buffer-string)))))
  6165. ;; Aligning tags preserve position.
  6166. (should
  6167. (= 6 (org-test-with-temp-text "* 345 <point> :tag:"
  6168. (let ((org-tags-column 78)
  6169. (indent-tabs-mode nil))
  6170. (org-fix-tags-on-the-fly))
  6171. (current-column))))
  6172. ;; Aligning all tags in visible buffer.
  6173. (should
  6174. ;; 12345678901234567890
  6175. (equal (concat "* Level 1 :abc:\n"
  6176. "** Level 2 :def:")
  6177. (org-test-with-temp-text (concat "* Level 1 :abc:\n"
  6178. "** Level 2 :def:")
  6179. (let ((org-tags-column -20)
  6180. (indent-tabs-mode nil))
  6181. ;; (org-align-tags :all) must work even when the point
  6182. ;; is at the end of the buffer.
  6183. (goto-char (point-max))
  6184. (org-align-tags :all))
  6185. (buffer-string)))))
  6186. (ert-deftest test-org/get-tags ()
  6187. "Test `org-get-tags' specifications."
  6188. ;; Standard test.
  6189. (should
  6190. (equal '("foo")
  6191. (org-test-with-temp-text "* Test :foo:" (org-get-tags))))
  6192. (should
  6193. (equal '("foo" "bar")
  6194. (org-test-with-temp-text "* Test :foo:bar:" (org-get-tags))))
  6195. ;; Return nil when there is no tag.
  6196. (should-not
  6197. (org-test-with-temp-text "* Test" (org-get-tags)))
  6198. ;; Tags are inherited from parent headlines.
  6199. (should
  6200. (equal '("tag")
  6201. (let ((org-use-tag-inheritance t))
  6202. (org-test-with-temp-text "* H0 :foo:\n* H1 :tag:\n<point>** H2"
  6203. (org-get-tags)))))
  6204. ;; Tags are inherited from `org-file-tags'.
  6205. (should
  6206. (equal '("tag")
  6207. (org-test-with-temp-text "* H1"
  6208. (let ((org-file-tags '("tag"))
  6209. (org-use-tag-inheritance t))
  6210. (org-get-tags)))))
  6211. ;; Only inherited tags have the `inherited' text property.
  6212. (should
  6213. (get-text-property 0 'inherited
  6214. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6215. (let ((org-use-tag-inheritance t))
  6216. (assoc-string "foo" (org-get-tags))))))
  6217. (should-not
  6218. (get-text-property 0 'inherited
  6219. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6220. (let ((org-use-tag-inheritance t))
  6221. (assoc-string "bar" (org-get-tags))))))
  6222. ;; Obey to `org-use-tag-inheritance'.
  6223. (should-not
  6224. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6225. (let ((org-use-tag-inheritance nil))
  6226. (assoc-string "foo" (org-get-tags)))))
  6227. (should-not
  6228. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6229. (let ((org-use-tag-inheritance nil)
  6230. (org-file-tags '("foo")))
  6231. (assoc-string "foo" (org-get-tags)))))
  6232. (should-not
  6233. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6234. (let ((org-use-tag-inheritance '("bar")))
  6235. (assoc-string "foo" (org-get-tags)))))
  6236. (should
  6237. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6238. (let ((org-use-tag-inheritance '("bar")))
  6239. (assoc-string "bar" (org-get-tags)))))
  6240. (should-not
  6241. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6242. (let ((org-use-tag-inheritance "b.*"))
  6243. (assoc-string "foo" (org-get-tags)))))
  6244. (should
  6245. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6246. (let ((org-use-tag-inheritance "b.*"))
  6247. (assoc-string "bar" (org-get-tags)))))
  6248. ;; When optional argument LOCAL is non-nil, ignore tag inheritance.
  6249. (should
  6250. (equal '("baz")
  6251. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6252. (let ((org-use-tag-inheritance t))
  6253. (org-get-tags nil t)))))
  6254. ;; When optional argument POS is non-nil, get tags there instead.
  6255. (should
  6256. (equal '("foo")
  6257. (org-test-with-temp-text "* H1 :foo:\n* <point>H2 :bar:"
  6258. (org-get-tags 1))))
  6259. ;; Make sure tags excluded from inheritance are returned if local
  6260. (should
  6261. (equal '("foo")
  6262. (org-test-with-temp-text "* Test :foo:"
  6263. (let ((org-use-tag-inheritance t)
  6264. (org-tags-exclude-from-inheritance '("foo")))
  6265. (org-get-tags)))))
  6266. ;; Test the collection of tags from #+filetags and parent tags.
  6267. (should
  6268. (equal '("a" "b" "c" "d")
  6269. (org-test-with-temp-text (concat "#+filetags: a\n"
  6270. "* Level 1 :b:\n"
  6271. "** Level 2 :c:\n"
  6272. "*** Level 3 :d:\n"
  6273. "<point>")
  6274. (let ((org-use-tag-inheritance t))
  6275. (org-mode-restart) ;So that `org-file-tags' get populated from #+filetags
  6276. (org-get-tags)))))
  6277. ;; Pathological case: tagged headline with an empty body.
  6278. (should (org-test-with-temp-text "* :tag:" (org-get-tags))))
  6279. (ert-deftest test-org/set-tags ()
  6280. "Test `org-set-tags' specifications."
  6281. ;; Throw an error on invalid data.
  6282. (should-error
  6283. (org-test-with-temp-text "* H"
  6284. (org-set-tags 'foo)))
  6285. ;; `nil', an empty, and a blank string remove all tags.
  6286. (should
  6287. (equal "* H"
  6288. (org-test-with-temp-text "* H :tag1:tag2:"
  6289. (org-set-tags nil)
  6290. (buffer-string))))
  6291. (should
  6292. (equal "* H"
  6293. (org-test-with-temp-text "* H :tag1:tag2:"
  6294. (org-set-tags "")
  6295. (buffer-string))))
  6296. (should
  6297. (equal "* H"
  6298. (org-test-with-temp-text "* H :tag1:tag2:"
  6299. (org-set-tags " ")
  6300. (buffer-string))))
  6301. ;; If there's nothing to remove, just bail out.
  6302. (should
  6303. (equal "* H"
  6304. (org-test-with-temp-text "* H"
  6305. (org-set-tags nil)
  6306. (buffer-string))))
  6307. (should
  6308. (equal "* "
  6309. (org-test-with-temp-text "* "
  6310. (org-set-tags nil)
  6311. (buffer-string))))
  6312. ;; If DATA is a tag string, set current tags to it, even if it means
  6313. ;; replacing old tags.
  6314. (should
  6315. (equal "* H :tag0:"
  6316. (org-test-with-temp-text "* H :tag1:tag2:"
  6317. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  6318. (buffer-string))))
  6319. (should
  6320. (equal "* H :tag0:"
  6321. (org-test-with-temp-text "* H"
  6322. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  6323. (buffer-string))))
  6324. ;; If DATA is a list, set tags to this list, even if it means
  6325. ;; replacing old tags.
  6326. (should
  6327. (equal "* H :tag0:"
  6328. (org-test-with-temp-text "* H :tag1:tag2:"
  6329. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6330. (buffer-string))))
  6331. (should
  6332. (equal "* H :tag0:"
  6333. (org-test-with-temp-text "* H"
  6334. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6335. (buffer-string))))
  6336. ;; When set, apply `org-tags-sort-function'.
  6337. (should
  6338. (equal "* H :a:b:"
  6339. (org-test-with-temp-text "* H"
  6340. (let ((org-tags-column 1)
  6341. (org-tags-sort-function #'string<))
  6342. (org-set-tags '("b" "a"))
  6343. (buffer-string)))))
  6344. ;; When new tags are identical to the previous ones, still align.
  6345. (should
  6346. (equal "* H :foo:"
  6347. (org-test-with-temp-text "* H :foo:"
  6348. (let ((org-tags-column 1))
  6349. (org-set-tags '("foo"))
  6350. (buffer-string)))))
  6351. ;; When tags have been changed, run `org-after-tags-change-hook'.
  6352. (should
  6353. (catch :return
  6354. (org-test-with-temp-text "* H :foo:"
  6355. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  6356. (org-set-tags '("bar"))
  6357. nil))))
  6358. (should-not
  6359. (catch :return
  6360. (org-test-with-temp-text "* H :foo:"
  6361. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  6362. (org-set-tags '("foo"))
  6363. nil))))
  6364. ;; Special case: handle empty headlines.
  6365. (should
  6366. (equal "* :tag0:"
  6367. (org-test-with-temp-text "* "
  6368. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6369. (buffer-string))))
  6370. ;; Modify buffer only when a tag change happens or alignment is
  6371. ;; done.
  6372. (should-not
  6373. (org-test-with-temp-text "* H :foo:"
  6374. (set-buffer-modified-p nil)
  6375. (let ((org-tags-column 1)) (org-set-tags '("foo")))
  6376. (buffer-modified-p)))
  6377. (should
  6378. (org-test-with-temp-text "* H :foo:"
  6379. (set-buffer-modified-p nil)
  6380. (let ((org-tags-column 10)) (org-set-tags '("foo")))
  6381. (buffer-modified-p)))
  6382. (should
  6383. (org-test-with-temp-text "* H :foo:"
  6384. (set-buffer-modified-p nil)
  6385. (let ((org-tags-column 10)) (org-set-tags '("bar")))
  6386. (buffer-modified-p)))
  6387. ;; Pathological case: when setting tags of a folded headline, do not
  6388. ;; let new tags being sucked into invisibility.
  6389. (should-not
  6390. (org-test-with-temp-text "* H1\nContent\n* H2\n\n Other Content"
  6391. ;; Show only headlines
  6392. (org-content)
  6393. ;; Set NEXT tag on current entry
  6394. (org-set-tags ":NEXT:")
  6395. ;; Move point to that NEXT tag
  6396. (search-forward "NEXT") (backward-word)
  6397. ;; And it should be visible (i.e. no overlays)
  6398. (overlays-at (point)))))
  6399. (ert-deftest test-org/set-tags-command ()
  6400. "Test `org-set-tags-command' specifications"
  6401. ;; Set tags at current headline.
  6402. (should
  6403. (equal "* H1 :foo:"
  6404. (org-test-with-temp-text "* H1"
  6405. (cl-letf (((symbol-function 'completing-read)
  6406. (lambda (&rest args) ":foo:")))
  6407. (let ((org-use-fast-tag-selection nil)
  6408. (org-tags-column 1))
  6409. (org-set-tags-command)))
  6410. (buffer-string))))
  6411. ;; Preserve position when called from the section below.
  6412. (should
  6413. (equal "* H1 :foo:\nContents"
  6414. (org-test-with-temp-text "* H1\n<point>Contents"
  6415. (cl-letf (((symbol-function 'completing-read)
  6416. (lambda (&rest args) ":foo:")))
  6417. (let ((org-use-fast-tag-selection nil)
  6418. (org-tags-column 1))
  6419. (org-set-tags-command)))
  6420. (buffer-string))))
  6421. (should-not
  6422. (equal "* H1 :foo:\nContents2"
  6423. (org-test-with-temp-text "* H1\n<point>Contents2"
  6424. (cl-letf (((symbol-function 'completing-read)
  6425. (lambda (&rest args) ":foo:")))
  6426. (let ((org-use-fast-tag-selection nil)
  6427. (org-tags-column 1))
  6428. (org-set-tags-command)))
  6429. (org-at-heading-p))))
  6430. ;; Strip all forbidden characters from user-entered tags.
  6431. (should
  6432. (equal "* H1 :foo:"
  6433. (org-test-with-temp-text "* H1"
  6434. (cl-letf (((symbol-function 'completing-read)
  6435. (lambda (&rest args) ": foo *:")))
  6436. (let ((org-use-fast-tag-selection nil)
  6437. (org-tags-column 1))
  6438. (org-set-tags-command)))
  6439. (buffer-string))))
  6440. ;; When a region is active and
  6441. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  6442. ;; same value in all headlines in region.
  6443. (should
  6444. (equal "* H1 :foo:\nContents\n* H2 :foo:"
  6445. (org-test-with-temp-text "* H1\nContents\n* H2"
  6446. (cl-letf (((symbol-function 'completing-read)
  6447. (lambda (&rest args) ":foo:")))
  6448. (let ((org-use-fast-tag-selection nil)
  6449. (org-loop-over-headlines-in-active-region t)
  6450. (org-tags-column 1))
  6451. (transient-mark-mode 1)
  6452. (push-mark (point) t t)
  6453. (goto-char (point-max))
  6454. (org-set-tags-command)))
  6455. (buffer-string))))
  6456. (should
  6457. (equal "* H1\nContents\n* H2 :foo:"
  6458. (org-test-with-temp-text "* H1\nContents\n* H2"
  6459. (cl-letf (((symbol-function 'completing-read)
  6460. (lambda (&rest args) ":foo:")))
  6461. (let ((org-use-fast-tag-selection nil)
  6462. (org-loop-over-headlines-in-active-region nil)
  6463. (org-tags-column 1))
  6464. (transient-mark-mode 1)
  6465. (push-mark (point) t t)
  6466. (goto-char (point-max))
  6467. (org-set-tags-command)))
  6468. (buffer-string))))
  6469. ;; With a C-u prefix argument, align all tags in the buffer.
  6470. (should
  6471. (equal "* H1 :foo:\n* H2 :bar:"
  6472. (org-test-with-temp-text "* H1 :foo:\n* H2 :bar:"
  6473. (let ((org-tags-column 1)) (org-set-tags-command '(4)))
  6474. (buffer-string))))
  6475. ;; Point does not move with empty headline.
  6476. (should
  6477. (equal ":foo:"
  6478. (org-test-with-temp-text "* <point>"
  6479. (cl-letf (((symbol-function 'completing-read)
  6480. (lambda (&rest args) ":foo:")))
  6481. (let ((org-use-fast-tag-selection nil)
  6482. (org-tags-column 1))
  6483. (org-set-tags-command)))
  6484. (buffer-substring (point) (line-end-position)))))
  6485. ;; Point does not move at start of line.
  6486. (should
  6487. (equal "* H1 :foo:"
  6488. (org-test-with-temp-text "* H1"
  6489. (cl-letf (((symbol-function 'completing-read)
  6490. (lambda (&rest args) ":foo:")))
  6491. (let ((org-use-fast-tag-selection nil)
  6492. (org-tags-column 1))
  6493. (org-set-tags-command)))
  6494. (buffer-substring (point) (line-end-position)))))
  6495. ;; Point does not move when within *'s.
  6496. (should
  6497. (equal "* H1 :foo:"
  6498. (org-test-with-temp-text "*<point>* H1"
  6499. (cl-letf (((symbol-function 'completing-read)
  6500. (lambda (&rest args) ":foo:")))
  6501. (let ((org-use-fast-tag-selection nil)
  6502. (org-tags-column 1))
  6503. (org-set-tags-command)))
  6504. (buffer-substring (point) (line-end-position)))))
  6505. ;; Point workaround does not get fooled when looking at a space.
  6506. (should
  6507. (equal " b :foo:"
  6508. (org-test-with-temp-text "* a<point> b"
  6509. (cl-letf (((symbol-function 'completing-read)
  6510. (lambda (&rest args) ":foo:")))
  6511. (let ((org-use-fast-tag-selection nil)
  6512. (org-tags-column 1))
  6513. (org-set-tags-command)))
  6514. (buffer-substring (point) (line-end-position))))))
  6515. (ert-deftest test-org/toggle-tag ()
  6516. "Test `org-toggle-tag' specifications."
  6517. ;; Insert missing tag.
  6518. (should
  6519. (equal "* H :tag:"
  6520. (org-test-with-temp-text "* H"
  6521. (let ((org-tags-column 1)) (org-toggle-tag "tag"))
  6522. (buffer-string))))
  6523. (should
  6524. (equal "* H :tag1:tag2:"
  6525. (org-test-with-temp-text "* H :tag1:"
  6526. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  6527. (buffer-string))))
  6528. ;; Remove existing tag.
  6529. (should
  6530. (equal "* H"
  6531. (org-test-with-temp-text "* H :tag:"
  6532. (org-toggle-tag "tag")
  6533. (buffer-string))))
  6534. (should
  6535. (equal "* H :tag1:"
  6536. (org-test-with-temp-text "* H :tag1:tag2:"
  6537. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  6538. (buffer-string))))
  6539. (should
  6540. (equal "* H :tag2:"
  6541. (org-test-with-temp-text "* H :tag1:tag2:"
  6542. (let ((org-tags-column 1)) (org-toggle-tag "tag1"))
  6543. (buffer-string))))
  6544. ;; With optional argument ONOFF set to `on', try to insert the tag,
  6545. ;; even if its already there.
  6546. (should
  6547. (equal "* H :tag:"
  6548. (org-test-with-temp-text "* H"
  6549. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  6550. (buffer-string))))
  6551. (should
  6552. (equal "* H :tag:"
  6553. (org-test-with-temp-text "* H :tag:"
  6554. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  6555. (buffer-string))))
  6556. ;; With optional argument ONOFF set to `off', try to remove the tag,
  6557. ;; even if its not there.
  6558. (should
  6559. (equal "* H"
  6560. (org-test-with-temp-text "* H :tag:"
  6561. (org-toggle-tag "tag" 'off)
  6562. (buffer-string))))
  6563. (should
  6564. (equal "* H :tag:"
  6565. (org-test-with-temp-text "* H :tag:"
  6566. (let ((org-tags-column 1)) (org-toggle-tag "foo" 'off))
  6567. (buffer-string))))
  6568. ;; Special case: Handle properly tag inheritance. In particular, do
  6569. ;; not set inherited tags.
  6570. (should
  6571. (equal "* H1 :tag:\n** H2 :tag2:tag:"
  6572. (org-test-with-temp-text "* H1 :tag:\n** <point>H2 :tag2:"
  6573. (let ((org-use-tag-inheritance t)
  6574. (org-tags-column 1))
  6575. (org-toggle-tag "tag"))
  6576. (buffer-string))))
  6577. (should
  6578. (equal "* H1 :tag1:tag2:\n** H2 :foo:"
  6579. (org-test-with-temp-text "* H1 :tag1:tag2:\n** <point>H2"
  6580. (let ((org-use-tag-inheritance t)
  6581. (org-tags-column 1))
  6582. (org-toggle-tag "foo"))
  6583. (buffer-string)))))
  6584. (ert-deftest test-org/tags-expand ()
  6585. "Test `org-tags-expand' specifications."
  6586. ;; Expand tag groups as a regexp enclosed within curly brackets.
  6587. (should
  6588. (equal "{\\<[ABC]\\>}"
  6589. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6590. (org-mode-restart)
  6591. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  6592. (should
  6593. (equal "{\\<\\(?:Aa\\|Bb\\|Cc\\)\\>}"
  6594. (org-test-with-temp-text "#+TAGS: [ Aa : Bb Cc ]"
  6595. (org-mode-restart)
  6596. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "Aa")))))
  6597. ;; Preserve operator before the regexp.
  6598. (should
  6599. (equal "+{\\<[ABC]\\>}"
  6600. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6601. (org-mode-restart)
  6602. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "+A")))))
  6603. (should
  6604. (equal "-{\\<[ABC]\\>}"
  6605. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6606. (org-mode-restart)
  6607. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "-A")))))
  6608. ;; Handle "|" syntax.
  6609. (should
  6610. (equal "{\\<[ABC]\\>}|D"
  6611. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6612. (org-mode-restart)
  6613. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|D")))))
  6614. ;; Handle nested groups.
  6615. (should
  6616. (equal "{\\<[A-D]\\>}"
  6617. (org-test-with-temp-text "#+TAGS: [ A : B C ]\n#+TAGS: [ B : D ]"
  6618. (org-mode-restart)
  6619. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  6620. ;; Expand multiple occurrences of the same group.
  6621. (should
  6622. (equal "{\\<[ABC]\\>}|{\\<[ABC]\\>}"
  6623. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6624. (org-mode-restart)
  6625. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|A")))))
  6626. ;; Preserve regexp matches.
  6627. (should
  6628. (equal "{A+}"
  6629. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6630. (org-mode-restart)
  6631. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "{A+}"))))))
  6632. ;;; TODO keywords
  6633. (ert-deftest test-org/auto-repeat-maybe ()
  6634. "Test `org-auto-repeat-maybe' specifications."
  6635. ;; Do not auto repeat when there is no valid time stamp with
  6636. ;; a repeater in the entry.
  6637. (should-not
  6638. (string-prefix-p
  6639. "* TODO H"
  6640. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6641. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
  6642. (org-todo "DONE")
  6643. (buffer-string)))))
  6644. (should-not
  6645. (string-prefix-p
  6646. "* TODO H"
  6647. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6648. (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
  6649. (org-todo "DONE")
  6650. (buffer-string)))))
  6651. ;; When switching to DONE state, switch back to first TODO keyword
  6652. ;; in sequence, or the same keyword if they have different types.
  6653. (should
  6654. (string-prefix-p
  6655. "* TODO H"
  6656. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6657. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  6658. (org-todo "DONE")
  6659. (buffer-string)))))
  6660. (should
  6661. (string-prefix-p
  6662. "* KWD1 H"
  6663. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  6664. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  6665. (org-todo "DONE")
  6666. (buffer-string)))))
  6667. (should
  6668. (string-prefix-p
  6669. "* KWD2 H"
  6670. (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
  6671. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  6672. (org-todo "DONE")
  6673. (buffer-string)))))
  6674. ;; If there was no TODO keyword in the first place, do not insert
  6675. ;; any either.
  6676. (should
  6677. (string-prefix-p
  6678. "* H"
  6679. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6680. (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
  6681. (org-todo "DONE")
  6682. (buffer-string)))))
  6683. ;; Revert to REPEAT_TO_STATE, if set.
  6684. (should
  6685. (string-prefix-p
  6686. "* KWD2 H"
  6687. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  6688. (org-test-with-temp-text
  6689. "* KWD2 H
  6690. :PROPERTIES:
  6691. :REPEAT_TO_STATE: KWD2
  6692. :END:
  6693. <2012-03-29 Thu +2y>"
  6694. (org-todo "DONE")
  6695. (buffer-string)))))
  6696. ;; When switching to DONE state, update base date. If there are
  6697. ;; multiple repeated time stamps, update them all.
  6698. (should
  6699. (string-match-p
  6700. "<2014-03-29 .* \\+2y>"
  6701. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6702. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  6703. (org-todo "DONE")
  6704. (buffer-string)))))
  6705. (should
  6706. (string-match-p
  6707. "<2015-03-04 .* \\+1y>"
  6708. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6709. (org-test-with-temp-text
  6710. "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
  6711. (org-todo "DONE")
  6712. (buffer-string)))))
  6713. ;; Throw an error if repeater unit is the hour and no time is
  6714. ;; provided in the time-stamp.
  6715. (should-error
  6716. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6717. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
  6718. (org-todo "DONE")
  6719. (buffer-string))))
  6720. ;; Handle every repeater type using hours step.
  6721. (should
  6722. (string-match-p
  6723. "2014-03-04 .* 02:00"
  6724. (org-test-at-time "<2014-03-04 02:35>"
  6725. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 +8h>"
  6726. (org-todo "DONE")
  6727. (buffer-string)))))
  6728. (should
  6729. (string-match-p
  6730. "2014-03-04 .* 10:00"
  6731. (org-test-at-time "<2014-03-04 02:35>"
  6732. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 ++8h>"
  6733. (org-todo "DONE")
  6734. (buffer-string)))))
  6735. (should
  6736. (string-match-p
  6737. "2014-03-04 .* 10:35"
  6738. (org-test-at-time "<2014-03-04 02:35>"
  6739. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 .+8h>"
  6740. (org-todo "DONE")
  6741. (buffer-string)))))
  6742. ;; Do not repeat inactive time stamps with a repeater.
  6743. (should-not
  6744. (string-match-p
  6745. "\\[2014-03-29 .* \\+2y\\]"
  6746. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6747. (org-test-with-temp-text
  6748. "* TODO H\n[2012-03-29 Thu. +2y]"
  6749. (org-todo "DONE")
  6750. (buffer-string)))))
  6751. ;; Do not repeat commented time stamps.
  6752. (should-not
  6753. (string-prefix-p
  6754. "<2015-03-04 .* \\+1y>"
  6755. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6756. (org-test-with-temp-text
  6757. "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
  6758. (org-todo "DONE")
  6759. (buffer-string)))))
  6760. (should-not
  6761. (string-prefix-p
  6762. "<2015-03-04 .* \\+1y>"
  6763. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6764. (org-test-with-temp-text
  6765. "* TODO H
  6766. <2012-03-29 Thu. +2y>
  6767. #+BEGIN_EXAMPLE
  6768. <2014-03-04 Tue +1y>
  6769. #+END_EXAMPLE"
  6770. (org-todo "DONE")
  6771. (buffer-string)))))
  6772. ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
  6773. ;; entry, record time of last repeat.
  6774. (should-not
  6775. (string-match-p
  6776. ":LAST_REPEAT:"
  6777. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  6778. (org-log-repeat nil))
  6779. (cl-letf (((symbol-function 'org-add-log-setup)
  6780. (lambda (&rest args) nil)))
  6781. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  6782. (org-todo "DONE")
  6783. (buffer-string))))))
  6784. (should
  6785. (string-match-p
  6786. ":LAST_REPEAT:"
  6787. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  6788. (org-log-repeat t))
  6789. (cl-letf (((symbol-function 'org-add-log-setup)
  6790. (lambda (&rest args) nil)))
  6791. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  6792. (org-todo "DONE")
  6793. (buffer-string))))))
  6794. (should
  6795. (string-match-p
  6796. ":LAST_REPEAT:"
  6797. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6798. (cl-letf (((symbol-function 'org-add-log-setup)
  6799. (lambda (&rest args) nil)))
  6800. (org-test-with-temp-text
  6801. "* TODO H\n<2012-03-29 Thu +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
  6802. (org-todo "DONE")
  6803. (buffer-string))))))
  6804. ;; When a SCHEDULED entry has no repeater, remove it upon repeating
  6805. ;; the entry as it is no longer relevant.
  6806. (should-not
  6807. (string-match-p
  6808. "^SCHEDULED:"
  6809. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6810. (org-test-with-temp-text
  6811. "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
  6812. (org-todo "DONE")
  6813. (buffer-string)))))
  6814. ;; Properly advance repeater even when a clock entry is specified
  6815. ;; and `org-log-repeat' is nil.
  6816. (should
  6817. (string-match-p
  6818. "SCHEDULED: <2014-03-29"
  6819. (let ((org-log-repeat nil)
  6820. (org-todo-keywords '((sequence "TODO" "DONE"))))
  6821. (org-test-with-temp-text
  6822. "* TODO H
  6823. SCHEDULED: <2012-03-29 Thu +2y>
  6824. CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] => 6:40"
  6825. (org-todo "DONE")
  6826. (buffer-string))))))
  6827. ;;; Timestamps API
  6828. (ert-deftest test-org/at-timestamp-p ()
  6829. "Test `org-at-timestamp-p' specifications."
  6830. (should
  6831. (org-test-with-temp-text "<2012-03-29 Thu>"
  6832. (org-at-timestamp-p)))
  6833. (should-not
  6834. (org-test-with-temp-text "2012-03-29 Thu"
  6835. (org-at-timestamp-p)))
  6836. ;; Test return values.
  6837. (should
  6838. (eq 'bracket
  6839. (org-test-with-temp-text "<2012-03-29 Thu>"
  6840. (org-at-timestamp-p))))
  6841. (should
  6842. (eq 'year
  6843. (org-test-with-temp-text "<<point>2012-03-29 Thu>"
  6844. (org-at-timestamp-p))))
  6845. (should
  6846. (eq 'month
  6847. (org-test-with-temp-text "<2012-<point>03-29 Thu>"
  6848. (org-at-timestamp-p))))
  6849. (should
  6850. (eq 'day
  6851. (org-test-with-temp-text "<2012-03-<point>29 Thu>"
  6852. (org-at-timestamp-p))))
  6853. (should
  6854. (eq 'day
  6855. (org-test-with-temp-text "<2012-03-29 T<point>hu>"
  6856. (org-at-timestamp-p))))
  6857. (should
  6858. (wholenump
  6859. (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
  6860. (org-at-timestamp-p))))
  6861. (should
  6862. (eq 'bracket
  6863. (org-test-with-temp-text "<2012-03-29 Thu<point>>"
  6864. (org-at-timestamp-p))))
  6865. (should
  6866. (eq 'after
  6867. (org-test-with-temp-text "<2012-03-29 Thu><point>»"
  6868. (org-at-timestamp-p))))
  6869. ;; Test `inactive' optional argument.
  6870. (should
  6871. (org-test-with-temp-text "[2012-03-29 Thu]"
  6872. (org-at-timestamp-p 'inactive)))
  6873. (should-not
  6874. (org-test-with-temp-text "[2012-03-29 Thu]"
  6875. (org-at-timestamp-p)))
  6876. ;; When optional argument is `agenda', recognize time-stamps in
  6877. ;; planning info line, property drawers and clocks.
  6878. (should
  6879. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  6880. (org-at-timestamp-p 'agenda)))
  6881. (should-not
  6882. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  6883. (org-at-timestamp-p)))
  6884. (should
  6885. (org-test-with-temp-text
  6886. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  6887. (org-at-timestamp-p 'agenda)))
  6888. (should-not
  6889. (org-test-with-temp-text
  6890. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  6891. (org-at-timestamp-p)))
  6892. (should
  6893. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  6894. (let ((org-agenda-include-inactive-timestamps t))
  6895. (org-at-timestamp-p 'agenda))))
  6896. (should-not
  6897. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  6898. (let ((org-agenda-include-inactive-timestamps t))
  6899. (org-at-timestamp-p))))
  6900. (should-not
  6901. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  6902. (let ((org-agenda-include-inactive-timestamps t))
  6903. (org-at-timestamp-p 'inactive))))
  6904. ;; When optional argument is `lax', match any part of the document
  6905. ;; with Org timestamp syntax.
  6906. (should
  6907. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  6908. (org-at-timestamp-p 'lax)))
  6909. (should-not
  6910. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  6911. (org-at-timestamp-p)))
  6912. (should
  6913. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  6914. (org-at-timestamp-p 'lax)))
  6915. (should-not
  6916. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  6917. (org-at-timestamp-p)))
  6918. (should
  6919. (org-test-with-temp-text
  6920. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  6921. (org-at-timestamp-p 'lax)))
  6922. (should-not
  6923. (org-test-with-temp-text
  6924. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  6925. (org-at-timestamp-p)))
  6926. ;; Optional argument `lax' also matches inactive timestamps.
  6927. (should
  6928. (org-test-with-temp-text "# [2012-03-29 Thu]<point>"
  6929. (org-at-timestamp-p 'lax))))
  6930. (ert-deftest test-org/time-stamp ()
  6931. "Test `org-time-stamp' specifications."
  6932. ;; Insert chosen time stamp at point.
  6933. (should
  6934. (string-match
  6935. "Te<2014-03-04 .*?>xt"
  6936. (org-test-with-temp-text "Te<point>xt"
  6937. (cl-letf (((symbol-function 'org-read-date)
  6938. (lambda (&rest args)
  6939. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  6940. (org-time-stamp nil)
  6941. (buffer-string)))))
  6942. ;; With a prefix argument, also insert time.
  6943. (should
  6944. (string-match
  6945. "Te<2014-03-04 .*? 00:41>xt"
  6946. (org-test-with-temp-text "Te<point>xt"
  6947. (cl-letf (((symbol-function 'org-read-date)
  6948. (lambda (&rest args)
  6949. (apply #'encode-time
  6950. (org-parse-time-string "2014-03-04 00:41")))))
  6951. (org-time-stamp '(4))
  6952. (buffer-string)))))
  6953. ;; With two universal prefix arguments, insert an active timestamp
  6954. ;; with the current time without prompting the user.
  6955. (should
  6956. (string-match
  6957. "Te<2014-03-04 .*? 00:41>xt"
  6958. (org-test-with-temp-text "Te<point>xt"
  6959. (org-test-at-time "2014-03-04 00:41"
  6960. (org-time-stamp '(16))
  6961. (buffer-string)))))
  6962. ;; When optional argument is non-nil, insert an inactive timestamp.
  6963. (should
  6964. (string-match
  6965. "Te\\[2014-03-04 .*?\\]xt"
  6966. (org-test-with-temp-text "Te<point>xt"
  6967. (cl-letf (((symbol-function 'org-read-date)
  6968. (lambda (&rest args)
  6969. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  6970. (org-time-stamp nil t)
  6971. (buffer-string)))))
  6972. ;; When called from a timestamp, replace existing one.
  6973. (should
  6974. (string-match
  6975. "<2014-03-04 .*?>"
  6976. (org-test-with-temp-text "<2012-03-29<point> thu.>"
  6977. (cl-letf (((symbol-function 'org-read-date)
  6978. (lambda (&rest args)
  6979. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  6980. (org-time-stamp nil)
  6981. (buffer-string)))))
  6982. (should
  6983. (string-match
  6984. "<2014-03-04 .*?>--<2014-03-04 .*?>"
  6985. (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
  6986. (cl-letf (((symbol-function 'org-read-date)
  6987. (lambda (&rest args)
  6988. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  6989. (org-time-stamp nil)
  6990. (buffer-string)))))
  6991. ;; When replacing a timestamp, preserve repeater, if any.
  6992. (should
  6993. (string-match
  6994. "<2014-03-04 .*? \\+2y>"
  6995. (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
  6996. (cl-letf (((symbol-function 'org-read-date)
  6997. (lambda (&rest args)
  6998. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  6999. (org-time-stamp nil)
  7000. (buffer-string)))))
  7001. ;; When called twice in a raw, build a date range.
  7002. (should
  7003. (string-match
  7004. "<2012-03-29 .*?>--<2014-03-04 .*?>"
  7005. (org-test-with-temp-text "<2012-03-29 thu.><point>"
  7006. (cl-letf (((symbol-function 'org-read-date)
  7007. (lambda (&rest args)
  7008. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7009. (let ((last-command 'org-time-stamp)
  7010. (this-command 'org-time-stamp))
  7011. (org-time-stamp nil))
  7012. (buffer-string))))))
  7013. (ert-deftest test-org/timestamp-has-time-p ()
  7014. "Test `org-timestamp-has-time-p' specifications."
  7015. ;; With time.
  7016. (should
  7017. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7018. (org-timestamp-has-time-p (org-element-context))))
  7019. ;; Without time.
  7020. (should-not
  7021. (org-test-with-temp-text "<2012-03-29 Thu>"
  7022. (org-timestamp-has-time-p (org-element-context)))))
  7023. (ert-deftest test-org/get-repeat ()
  7024. "Test `org-get-repeat' specifications."
  7025. (should
  7026. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
  7027. (org-get-repeat)))
  7028. (should-not
  7029. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
  7030. (org-get-repeat)))
  7031. ;; Return proper repeat string.
  7032. (should
  7033. (equal "+2y"
  7034. (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
  7035. (org-get-repeat))))
  7036. ;; Prevent false positive (commented or verbatim time stamps)
  7037. (should-not
  7038. (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
  7039. (org-get-repeat)))
  7040. (should-not
  7041. (org-test-with-temp-text
  7042. "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
  7043. (org-get-repeat)))
  7044. ;; Return nil when called before first heading.
  7045. (should-not
  7046. (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
  7047. (org-get-repeat)))
  7048. ;; When called with an optional argument, extract repeater from that
  7049. ;; string instead.
  7050. (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
  7051. (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
  7052. (ert-deftest test-org/timestamp-format ()
  7053. "Test `org-timestamp-format' specifications."
  7054. ;; Regular test.
  7055. (should
  7056. (equal
  7057. "2012-03-29 16:40"
  7058. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7059. (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
  7060. ;; Range end.
  7061. (should
  7062. (equal
  7063. "2012-03-29"
  7064. (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
  7065. (org-timestamp-format (org-element-context) "%Y-%m-%d" t)))))
  7066. (ert-deftest test-org/timestamp-split-range ()
  7067. "Test `org-timestamp-split-range' specifications."
  7068. ;; Extract range start (active).
  7069. (should
  7070. (equal '(2012 3 29)
  7071. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7072. (let ((ts (org-timestamp-split-range (org-element-context))))
  7073. (mapcar (lambda (p) (org-element-property p ts))
  7074. '(:year-end :month-end :day-end))))))
  7075. ;; Extract range start (inactive)
  7076. (should
  7077. (equal '(2012 3 29)
  7078. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7079. (let ((ts (org-timestamp-split-range (org-element-context))))
  7080. (mapcar (lambda (p) (org-element-property p ts))
  7081. '(:year-end :month-end :day-end))))))
  7082. ;; Extract range end (active).
  7083. (should
  7084. (equal '(2012 3 30)
  7085. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7086. (let ((ts (org-timestamp-split-range
  7087. (org-element-context) t)))
  7088. (mapcar (lambda (p) (org-element-property p ts))
  7089. '(:year-end :month-end :day-end))))))
  7090. ;; Extract range end (inactive)
  7091. (should
  7092. (equal '(2012 3 30)
  7093. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7094. (let ((ts (org-timestamp-split-range
  7095. (org-element-context) t)))
  7096. (mapcar (lambda (p) (org-element-property p ts))
  7097. '(:year-end :month-end :day-end))))))
  7098. ;; Return the timestamp if not a range.
  7099. (should
  7100. (org-test-with-temp-text "[2012-03-29 Thu]"
  7101. (let* ((ts-orig (org-element-context))
  7102. (ts-copy (org-timestamp-split-range ts-orig)))
  7103. (eq ts-orig ts-copy))))
  7104. (should
  7105. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7106. (let* ((ts-orig (org-element-context))
  7107. (ts-copy (org-timestamp-split-range ts-orig)))
  7108. (eq ts-orig ts-copy)))))
  7109. (ert-deftest test-org/timestamp-translate ()
  7110. "Test `org-timestamp-translate' specifications."
  7111. ;; Translate whole date range.
  7112. (should
  7113. (equal "<29>--<30>"
  7114. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7115. (let ((org-display-custom-times t)
  7116. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7117. (org-timestamp-translate (org-element-context))))))
  7118. ;; Translate date range start.
  7119. (should
  7120. (equal "<29>"
  7121. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7122. (let ((org-display-custom-times t)
  7123. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7124. (org-timestamp-translate (org-element-context) 'start)))))
  7125. ;; Translate date range end.
  7126. (should
  7127. (equal "<30>"
  7128. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7129. (let ((org-display-custom-times t)
  7130. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7131. (org-timestamp-translate (org-element-context) 'end)))))
  7132. ;; Translate time range.
  7133. (should
  7134. (equal "<08>--<16>"
  7135. (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
  7136. (let ((org-display-custom-times t)
  7137. (org-time-stamp-custom-formats '("<%d>" . "<%H>")))
  7138. (org-timestamp-translate (org-element-context))))))
  7139. ;; Translate non-range timestamp.
  7140. (should
  7141. (equal "<29>"
  7142. (org-test-with-temp-text "<2012-03-29 Thu>"
  7143. (let ((org-display-custom-times t)
  7144. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7145. (org-timestamp-translate (org-element-context))))))
  7146. ;; Do not change `diary' timestamps.
  7147. (should
  7148. (equal "<%%(org-float t 4 2)>"
  7149. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7150. (let ((org-display-custom-times t)
  7151. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7152. (org-timestamp-translate (org-element-context)))))))
  7153. (ert-deftest test-org/timestamp-from-string ()
  7154. "Test `org-timestamp-from-string' specifications."
  7155. ;; Return nil if argument is not a valid Org timestamp.
  7156. (should-not (org-timestamp-from-string ""))
  7157. (should-not (org-timestamp-from-string nil))
  7158. (should-not (org-timestamp-from-string "<2012-03-29"))
  7159. ;; Otherwise, return a valid Org timestamp object.
  7160. (should
  7161. (string-match-p "<2012-03-29 .+>"
  7162. (org-element-interpret-data
  7163. (org-timestamp-from-string "<2012-03-29 Thu>"))))
  7164. (should
  7165. (string-match-p "[2014-03-04 .+]"
  7166. (org-element-interpret-data
  7167. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  7168. (ert-deftest test-org/timestamp-from-time ()
  7169. "Test `org-timestamp-from-time' specifications."
  7170. ;; Standard test.
  7171. (should
  7172. (string-match-p
  7173. "<2012-03-29 .+>"
  7174. (org-element-interpret-data
  7175. (org-timestamp-from-time
  7176. (apply #'encode-time
  7177. (org-parse-time-string "<2012-03-29 Thu 16:40>"))))))
  7178. ;; When optional argument WITH-TIME is non-nil, provide time
  7179. ;; information.
  7180. (should
  7181. (string-match-p
  7182. "<2012-03-29 .+ 16:40>"
  7183. (org-element-interpret-data
  7184. (org-timestamp-from-time
  7185. (apply #'encode-time
  7186. (org-parse-time-string "<2012-03-29 Thu 16:40>"))
  7187. t))))
  7188. ;; When optional argument INACTIVE is non-nil, return an inactive
  7189. ;; timestamp.
  7190. (should
  7191. (string-match-p
  7192. "[2012-03-29 .+]"
  7193. (org-element-interpret-data
  7194. (org-timestamp-from-time
  7195. (apply #'encode-time
  7196. (org-parse-time-string "<2012-03-29 Thu 16:40>"))
  7197. nil t)))))
  7198. (ert-deftest test-org/timestamp-to-time ()
  7199. "Test `org-timestamp-to-time' specifications."
  7200. (should
  7201. (equal "2014-03-04"
  7202. (format-time-string
  7203. "%Y-%m-%d"
  7204. (org-timestamp-to-time
  7205. (org-timestamp-from-string "<2014-03-04 Tue>")))))
  7206. (should
  7207. (equal "2014-03-04"
  7208. (format-time-string
  7209. "%Y-%m-%d"
  7210. (org-timestamp-to-time
  7211. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  7212. (should
  7213. (equal "2012-03-29 08:30"
  7214. (format-time-string
  7215. "%Y-%m-%d %H:%M"
  7216. (org-timestamp-to-time
  7217. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")))))
  7218. (should
  7219. (equal "2012-03-29"
  7220. (format-time-string
  7221. "%Y-%m-%d"
  7222. (org-timestamp-to-time
  7223. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")))))
  7224. (should
  7225. (equal "2012-03-29"
  7226. (format-time-string
  7227. "%Y-%m-%d"
  7228. (org-timestamp-to-time
  7229. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")))))
  7230. ;; When optional argument END is non-nil, use end of date range or
  7231. ;; time range.
  7232. (should
  7233. (equal "2012-03-29 16:40"
  7234. (format-time-string
  7235. "%Y-%m-%d %H:%M"
  7236. (org-timestamp-to-time
  7237. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")
  7238. t))))
  7239. (should
  7240. (equal "2014-03-04"
  7241. (format-time-string
  7242. "%Y-%m-%d"
  7243. (org-timestamp-to-time
  7244. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")
  7245. t))))
  7246. (should
  7247. (equal "2014-03-04"
  7248. (format-time-string
  7249. "%Y-%m-%d"
  7250. (org-timestamp-to-time
  7251. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")
  7252. t)))))
  7253. ;;; Visibility
  7254. (ert-deftest test-org/hide-drawer-toggle ()
  7255. "Test `org-hide-drawer-toggle' specifications."
  7256. ;; Error when not at a drawer.
  7257. (should-error
  7258. (org-test-with-temp-text ":fake-drawer:\ncontents"
  7259. (org-hide-drawer-toggle 'off)
  7260. (get-char-property (line-end-position) 'invisible)))
  7261. (should-error
  7262. (org-test-with-temp-text
  7263. "#+begin_example\n<point>:D:\nc\n:END:\n#+end_example"
  7264. (org-hide-drawer-toggle t)))
  7265. ;; Hide drawer.
  7266. (should
  7267. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7268. (org-hide-drawer-toggle)
  7269. (get-char-property (line-end-position) 'invisible)))
  7270. ;; Show drawer unconditionally when optional argument is `off'.
  7271. (should-not
  7272. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7273. (org-hide-drawer-toggle)
  7274. (org-hide-drawer-toggle 'off)
  7275. (get-char-property (line-end-position) 'invisible)))
  7276. ;; Hide drawer unconditionally when optional argument is non-nil.
  7277. (should
  7278. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7279. (org-hide-drawer-toggle t)
  7280. (get-char-property (line-end-position) 'invisible)))
  7281. ;; Do not hide drawer when called from final blank lines.
  7282. (should-not
  7283. (org-test-with-temp-text ":drawer:\ncontents\n:end:\n\n<point>"
  7284. (org-hide-drawer-toggle)
  7285. (goto-char (point-min))
  7286. (get-char-property (line-end-position) 'invisible)))
  7287. ;; Don't leave point in an invisible part of the buffer when hiding
  7288. ;; a drawer away.
  7289. (should-not
  7290. (org-test-with-temp-text ":drawer:\ncontents\n<point>:end:"
  7291. (org-hide-drawer-toggle)
  7292. (get-char-property (point) 'invisible))))
  7293. (ert-deftest test-org/hide-block-toggle ()
  7294. "Test `org-hide-block-toggle' specifications."
  7295. ;; Error when not at a block.
  7296. (should-error
  7297. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
  7298. (org-hide-block-toggle 'off)
  7299. (get-char-property (line-end-position) 'invisible)))
  7300. ;; Hide block.
  7301. (should
  7302. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  7303. (org-hide-block-toggle)
  7304. (get-char-property (line-end-position) 'invisible)))
  7305. (should
  7306. (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
  7307. (org-hide-block-toggle)
  7308. (get-char-property (line-end-position) 'invisible)))
  7309. ;; Show block unconditionally when optional argument is `off'.
  7310. (should-not
  7311. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7312. (org-hide-block-toggle)
  7313. (org-hide-block-toggle 'off)
  7314. (get-char-property (line-end-position) 'invisible)))
  7315. (should-not
  7316. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7317. (org-hide-block-toggle 'off)
  7318. (get-char-property (line-end-position) 'invisible)))
  7319. ;; Hide block unconditionally when optional argument is non-nil.
  7320. (should
  7321. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7322. (org-hide-block-toggle t)
  7323. (get-char-property (line-end-position) 'invisible)))
  7324. (should
  7325. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7326. (org-hide-block-toggle)
  7327. (org-hide-block-toggle t)
  7328. (get-char-property (line-end-position) 'invisible)))
  7329. ;; Do not hide block when called from final blank lines.
  7330. (should-not
  7331. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
  7332. (org-hide-block-toggle)
  7333. (goto-char (point-min))
  7334. (get-char-property (line-end-position) 'invisible)))
  7335. ;; Don't leave point in an invisible part of the buffer when hiding
  7336. ;; a block away.
  7337. (should-not
  7338. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
  7339. (org-hide-block-toggle)
  7340. (get-char-property (point) 'invisible))))
  7341. (ert-deftest test-org/hide-block-toggle-maybe ()
  7342. "Test `org-hide-block-toggle-maybe' specifications."
  7343. (should
  7344. (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
  7345. (org-hide-block-toggle-maybe)))
  7346. (should-not
  7347. (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
  7348. (ert-deftest test-org/show-set-visibility ()
  7349. "Test `org-show-set-visibility' specifications."
  7350. ;; Do not throw an error before first heading.
  7351. (should
  7352. (org-test-with-temp-text "Preamble\n* Headline"
  7353. (org-show-set-visibility 'tree)
  7354. t))
  7355. ;; Test all visibility spans, both on headline and in entry.
  7356. (let ((list-visible-lines
  7357. (lambda (state headerp)
  7358. (org-test-with-temp-text "* Grandmother (0)
  7359. ** Uncle (1)
  7360. *** Heir (2)
  7361. ** Father (3)
  7362. Ancestor text (4)
  7363. *** Sister (5)
  7364. Sibling text (6)
  7365. *** Self (7)
  7366. Match (8)
  7367. **** First born (9)
  7368. Child text (10)
  7369. **** The other child (11)
  7370. *** Brother (12)
  7371. ** Aunt (13)
  7372. "
  7373. (org-cycle t)
  7374. (search-forward (if headerp "Self" "Match"))
  7375. (org-show-set-visibility state)
  7376. (goto-char (point-min))
  7377. (let (result (line 0))
  7378. (while (not (eobp))
  7379. (unless (org-invisible-p2) (push line result))
  7380. (cl-incf line)
  7381. (forward-line))
  7382. (nreverse result))))))
  7383. (should (equal '(0 7) (funcall list-visible-lines 'minimal t)))
  7384. (should (equal '(0 7 8) (funcall list-visible-lines 'minimal nil)))
  7385. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local t)))
  7386. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local nil)))
  7387. (should (equal '(0 3 7) (funcall list-visible-lines 'ancestors t)))
  7388. (should (equal '(0 3 7 8) (funcall list-visible-lines 'ancestors nil)))
  7389. (should (equal '(0 3 5 7 12) (funcall list-visible-lines 'lineage t)))
  7390. (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines 'lineage nil)))
  7391. (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines 'tree t)))
  7392. (should (equal '(0 1 3 5 7 8 9 11 12 13)
  7393. (funcall list-visible-lines 'tree nil)))
  7394. (should (equal '(0 1 3 4 5 7 12 13)
  7395. (funcall list-visible-lines 'canonical t)))
  7396. (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
  7397. (funcall list-visible-lines 'canonical nil))))
  7398. ;; When point is hidden in a drawer or a block, make sure to make it
  7399. ;; visible.
  7400. (should-not
  7401. (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
  7402. (org-hide-block-toggle)
  7403. (search-forward "Text")
  7404. (org-show-set-visibility 'minimal)
  7405. (org-invisible-p2)))
  7406. (should-not
  7407. (org-test-with-temp-text ":DRAWER:\nText\n:END:"
  7408. (org-hide-drawer-toggle)
  7409. (search-forward "Text")
  7410. (org-show-set-visibility 'minimal)
  7411. (org-invisible-p2)))
  7412. (should-not
  7413. (org-test-with-temp-text
  7414. "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
  7415. (org-hide-drawer-toggle)
  7416. (forward-line -1)
  7417. (org-hide-block-toggle)
  7418. (search-forward "Text")
  7419. (org-show-set-visibility 'minimal)
  7420. (org-invisible-p2))))
  7421. (defun test-org/copy-visible ()
  7422. "Test `org-copy-visible' specifications."
  7423. (should
  7424. (equal "Foo"
  7425. (org-test-with-temp-text "Foo"
  7426. (let ((kill-ring nil))
  7427. (org-copy-visible (point-min) (point-max))
  7428. (current-kill 0 t)))))
  7429. ;; Skip invisible characters by text property.
  7430. (should
  7431. (equal "Foo"
  7432. (org-test-with-temp-text #("F<hidden>oo" 1 7 (invisible t))
  7433. (let ((kill-ring nil))
  7434. (org-copy-visible (point-min) (point-max))
  7435. (current-kill 0 t)))))
  7436. ;; Skip invisible characters by overlay.
  7437. (should
  7438. (equal "Foo"
  7439. (org-test-with-temp-text "F<hidden>oo"
  7440. (let ((o (make-overlay 2 10)))
  7441. (overlay-put o 'invisible t))
  7442. (let ((kill-ring nil))
  7443. (org-copy-visible (point-min) (point-max))
  7444. (current-kill 0 t)))))
  7445. ;; Handle invisible characters at the beginning and the end of the
  7446. ;; buffer.
  7447. (should
  7448. (equal "Foo"
  7449. (org-test-with-temp-text #("<hidden>Foo" 0 8 (invisible t))
  7450. (let ((kill-ring nil))
  7451. (org-copy-visible (point-min) (point-max))
  7452. (current-kill 0 t)))))
  7453. (should
  7454. (equal "Foo"
  7455. (org-test-with-temp-text #("Foo<hidden>" 3 11 (invisible t))
  7456. (let ((kill-ring nil))
  7457. (org-copy-visible (point-min) (point-max))
  7458. (current-kill 0 t)))))
  7459. ;; Handle multiple visible parts.
  7460. (should
  7461. (equal "abc"
  7462. (org-test-with-temp-text
  7463. #("aXbXc" 1 2 (invisible t) 3 4 (invisible t))
  7464. (let ((kill-ring nil))
  7465. (org-copy-visible (point-min) (point-max))
  7466. (current-kill 0 t))))))
  7467. (ert-deftest test-org/set-visibility-according-to-property ()
  7468. "Test `org-set-visibility-according-to-property' specifications."
  7469. ;; "folded" state.
  7470. (should
  7471. (org-test-with-temp-text
  7472. "
  7473. * a
  7474. :PROPERTIES:
  7475. :VISIBILITY: folded
  7476. :END:
  7477. ** <point>b"
  7478. (org-set-visibility-according-to-property)
  7479. (invisible-p (point))))
  7480. ;; "children" state.
  7481. (should
  7482. (org-test-with-temp-text
  7483. "
  7484. * a
  7485. :PROPERTIES:
  7486. :VISIBILITY: children
  7487. :END:
  7488. ** b
  7489. <point>Contents
  7490. ** c"
  7491. (org-set-visibility-according-to-property)
  7492. (invisible-p (point))))
  7493. (should
  7494. (org-test-with-temp-text
  7495. "
  7496. * a
  7497. :PROPERTIES:
  7498. :VISIBILITY: children
  7499. :END:
  7500. ** b
  7501. Contents
  7502. *** <point>c"
  7503. (org-set-visibility-according-to-property)
  7504. (invisible-p (point))))
  7505. ;; "content" state.
  7506. (should
  7507. (org-test-with-temp-text
  7508. "
  7509. * a
  7510. :PROPERTIES:
  7511. :VISIBILITY: content
  7512. :END:
  7513. ** b
  7514. <point>Contents
  7515. *** c"
  7516. (org-set-visibility-according-to-property)
  7517. (invisible-p (point))))
  7518. (should
  7519. (org-test-with-temp-text
  7520. "
  7521. * a
  7522. :PROPERTIES:
  7523. :VISIBILITY: content
  7524. :END:
  7525. ** b
  7526. Contents
  7527. *** <point>c"
  7528. (org-set-visibility-according-to-property)
  7529. (not (invisible-p (point)))))
  7530. ;; "showall" state.
  7531. (should
  7532. (org-test-with-temp-text
  7533. "
  7534. * a
  7535. :PROPERTIES:
  7536. :VISIBILITY: showall
  7537. :END:
  7538. ** b
  7539. <point>Contents
  7540. *** c"
  7541. (org-set-visibility-according-to-property)
  7542. (not (invisible-p (point)))))
  7543. (should
  7544. (org-test-with-temp-text
  7545. "
  7546. * a
  7547. :PROPERTIES:
  7548. :VISIBILITY: showall
  7549. :END:
  7550. ** b
  7551. Contents
  7552. *** <point>c"
  7553. (org-set-visibility-according-to-property)
  7554. (not (invisible-p (point)))))
  7555. ;; When VISIBILITY properties are nested, ignore inner ones.
  7556. (should
  7557. (org-test-with-temp-text
  7558. "
  7559. * A
  7560. :PROPERTIES:
  7561. :VISIBILITY: folded
  7562. :END:
  7563. ** <point>B
  7564. :PROPERTIES:
  7565. :VISIBILITY: folded
  7566. :END:"
  7567. (org-set-visibility-according-to-property)
  7568. (invisible-p (point)))))
  7569. (ert-deftest test-org/visibility-show-branches ()
  7570. "Test visibility of inline archived subtrees."
  7571. (org-test-with-temp-text
  7572. "* Foo<point>
  7573. ** Bar :ARCHIVE:
  7574. *** Baz
  7575. "
  7576. (org-kill-note-or-show-branches)
  7577. (should (org-invisible-p (- (point-max) 2)))))
  7578. ;;; Yank and Kill
  7579. (ert-deftest test-org/paste-subtree ()
  7580. "Test `org-paste-subtree' specifications."
  7581. ;; Return an error if text to yank is not a set of subtrees.
  7582. (should-error (org-paste-subtree nil "Text"))
  7583. ;; Adjust level according to current one.
  7584. (should
  7585. (equal "* H\n* Text\n"
  7586. (org-test-with-temp-text "* H\n<point>"
  7587. (org-paste-subtree nil "* Text")
  7588. (buffer-string))))
  7589. (should
  7590. (equal "* H1\n** H2\n** Text\n"
  7591. (org-test-with-temp-text "* H1\n** H2\n<point>"
  7592. (org-paste-subtree nil "* Text")
  7593. (buffer-string))))
  7594. ;; When not on a heading, move to next heading before yanking.
  7595. (should
  7596. (equal "* H1\nParagraph\n* Text\n* H2"
  7597. (org-test-with-temp-text "* H1\n<point>Paragraph\n* H2"
  7598. (org-paste-subtree nil "* Text")
  7599. (buffer-string))))
  7600. ;; If point is between two headings, use the deepest level.
  7601. (should
  7602. (equal "* H1\n\n* Text\n* H2"
  7603. (org-test-with-temp-text "* H1\n<point>\n* H2"
  7604. (org-paste-subtree nil "* Text")
  7605. (buffer-string))))
  7606. (should
  7607. (equal "** H1\n\n** Text\n* H2"
  7608. (org-test-with-temp-text "** H1\n<point>\n* H2"
  7609. (org-paste-subtree nil "* Text")
  7610. (buffer-string))))
  7611. (should
  7612. (equal "* H1\n\n** Text\n** H2"
  7613. (org-test-with-temp-text "* H1\n<point>\n** H2"
  7614. (org-paste-subtree nil "* Text")
  7615. (buffer-string))))
  7616. ;; When on an empty heading, after the stars, deduce the new level
  7617. ;; from the number of stars.
  7618. (should
  7619. (equal "*** Text\n"
  7620. (org-test-with-temp-text "*** <point>"
  7621. (org-paste-subtree nil "* Text")
  7622. (buffer-string))))
  7623. ;; Optional argument LEVEL forces a level for the subtree.
  7624. (should
  7625. (equal "* H\n*** Text\n"
  7626. (org-test-with-temp-text "* H<point>"
  7627. (org-paste-subtree 3 "* Text")
  7628. (buffer-string)))))
  7629. (ert-deftest test-org/cut-and-paste-subtree ()
  7630. "Test `org-cut-subtree' and `org-paste-subtree'."
  7631. (should
  7632. (equal
  7633. "* Two
  7634. two
  7635. * One
  7636. "
  7637. (org-test-with-temp-text
  7638. "* One
  7639. <point>* Two
  7640. two
  7641. "
  7642. (call-interactively #'org-cut-subtree)
  7643. (goto-char (point-min))
  7644. (call-interactively #'org-paste-subtree)
  7645. (buffer-string))))
  7646. (should
  7647. (equal
  7648. "* One
  7649. * Two
  7650. "
  7651. (org-test-with-temp-text
  7652. "* One
  7653. <point>* Two
  7654. "
  7655. (call-interactively #'org-cut-subtree)
  7656. (backward-char)
  7657. (call-interactively #'org-paste-subtree)
  7658. (buffer-string)))))
  7659. (provide 'test-org)
  7660. ;;; test-org.el ends here