test-org.el 267 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246
  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/fill-paragraph ()
  672. "Test `org-fill-paragraph' specifications."
  673. ;; Regular test.
  674. (should
  675. (equal "012345678\n9"
  676. (org-test-with-temp-text "012345678 9"
  677. (let ((fill-column 10))
  678. (org-fill-paragraph)
  679. (buffer-string)))))
  680. ;; Fill paragraph even at end of buffer.
  681. (should
  682. (equal "012345678\n9\n"
  683. (org-test-with-temp-text "012345678 9\n<point>"
  684. (let ((fill-column 10))
  685. (org-fill-paragraph)
  686. (buffer-string)))))
  687. ;; Between two paragraphs, fill the next one.
  688. (should
  689. (equal "012345678 9\n\n012345678\n9"
  690. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  691. (let ((fill-column 10))
  692. (org-fill-paragraph)
  693. (buffer-string)))))
  694. (should
  695. (equal "012345678\n9\n\n012345678 9"
  696. (org-test-with-temp-text "012345678 9<point>\n\n012345678 9"
  697. (let ((fill-column 10))
  698. (org-fill-paragraph)
  699. (buffer-string)))))
  700. ;; Fill paragraph in a comment block.
  701. (should
  702. (equal "#+begin_comment\n012345678\n9\n#+end_comment"
  703. (org-test-with-temp-text
  704. "#+begin_comment\n<point>012345678 9\n#+end_comment"
  705. (let ((fill-column 10))
  706. (org-fill-paragraph)
  707. (buffer-string)))))
  708. ;; When a region is selected, fill every paragraph in the region.
  709. (should
  710. (equal "012345678\n9\n\n012345678\n9"
  711. (org-test-with-temp-text "012345678 9\n\n012345678 9"
  712. (let ((fill-column 10))
  713. (transient-mark-mode 1)
  714. (push-mark (point-min) t t)
  715. (goto-char (point-max))
  716. (call-interactively #'org-fill-paragraph)
  717. (buffer-string)))))
  718. (should
  719. (equal "012345678\n9\n\n012345678 9"
  720. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  721. (let ((fill-column 10))
  722. (transient-mark-mode 1)
  723. (push-mark (point) t t)
  724. (goto-char (point-min))
  725. (call-interactively #'org-fill-paragraph)
  726. (buffer-string)))))
  727. (should
  728. (equal "012345678 9\n\n012345678\n9"
  729. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  730. (let ((fill-column 10))
  731. (transient-mark-mode 1)
  732. (push-mark (point) t t)
  733. (goto-char (point-max))
  734. (call-interactively #'org-fill-paragraph)
  735. (buffer-string))))))
  736. (ert-deftest test-org/auto-fill-function ()
  737. "Test auto-filling features."
  738. ;; Auto fill paragraph.
  739. (should
  740. (equal "12345\n7890"
  741. (org-test-with-temp-text "12345 7890"
  742. (let ((fill-column 5))
  743. (end-of-line)
  744. (org-auto-fill-function)
  745. (buffer-string)))))
  746. ;; Auto fill first paragraph in an item.
  747. (should
  748. (equal "- 12345\n 7890"
  749. (org-test-with-temp-text "- 12345 7890"
  750. (let ((fill-column 7))
  751. (end-of-line)
  752. (org-auto-fill-function)
  753. (buffer-string)))))
  754. ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
  755. (should
  756. (equal "> 12345\n 7890"
  757. (org-test-with-temp-text "> 12345 7890"
  758. (let ((fill-column 10)
  759. (adaptive-fill-regexp "[ \t]*>+[ \t]*")
  760. (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
  761. (end-of-line)
  762. (org-auto-fill-function)
  763. (buffer-string)))))
  764. (should
  765. (equal "> 12345\n> 12345\n> 7890"
  766. (org-test-with-temp-text "> 12345\n> 12345 7890"
  767. (let ((fill-column 10)
  768. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  769. (goto-char (point-max))
  770. (org-auto-fill-function)
  771. (buffer-string)))))
  772. (should-not
  773. (equal " 12345\n *12345\n *12345"
  774. (org-test-with-temp-text " 12345\n *12345 12345"
  775. (let ((fill-column 10)
  776. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  777. (goto-char (point-max))
  778. (org-auto-fill-function)
  779. (buffer-string)))))
  780. ;; Auto fill comments.
  781. (should
  782. (equal " # 12345\n # 7890"
  783. (org-test-with-temp-text " # 12345 7890"
  784. (let ((fill-column 10))
  785. (end-of-line)
  786. (org-auto-fill-function)
  787. (buffer-string)))))
  788. ;; A hash within a line isn't a comment.
  789. (should-not
  790. (equal "12345 # 7890\n# 1"
  791. (org-test-with-temp-text "12345 # 7890 1"
  792. (let ((fill-column 12))
  793. (end-of-line)
  794. (org-auto-fill-function)
  795. (buffer-string)))))
  796. ;; Correctly interpret empty prefix.
  797. (should-not
  798. (equal "# a\n# b\nRegular\n# paragraph"
  799. (org-test-with-temp-text "# a\n# b\nRegular paragraph"
  800. (let ((fill-column 12))
  801. (end-of-line 3)
  802. (org-auto-fill-function)
  803. (buffer-string)))))
  804. ;; Comment block: auto fill contents.
  805. (should
  806. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  807. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  808. (let ((fill-column 5))
  809. (forward-line)
  810. (end-of-line)
  811. (org-auto-fill-function)
  812. (buffer-string)))))
  813. (should
  814. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  815. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  816. (let ((fill-column 5))
  817. (forward-line)
  818. (end-of-line)
  819. (org-auto-fill-function)
  820. (buffer-string)))))
  821. ;; Do not fill if a new item could be created.
  822. (should-not
  823. (equal "12345\n- 90"
  824. (org-test-with-temp-text "12345 - 90"
  825. (let ((fill-column 5))
  826. (end-of-line)
  827. (org-auto-fill-function)
  828. (buffer-string)))))
  829. ;; Do not fill if a line break could be introduced.
  830. (should-not
  831. (equal "123\\\\\n7890"
  832. (org-test-with-temp-text "123\\\\ 7890"
  833. (let ((fill-column 6))
  834. (end-of-line)
  835. (org-auto-fill-function)
  836. (buffer-string)))))
  837. ;; Do not fill affiliated keywords.
  838. (should-not
  839. (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
  840. (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
  841. (let ((fill-column 20))
  842. (end-of-line)
  843. (org-auto-fill-function)
  844. (buffer-string))))))
  845. ;;; Indentation
  846. (ert-deftest test-org/indent-line ()
  847. "Test `org-indent-line' specifications."
  848. ;; Do not indent diary sexps, footnote definitions or headlines.
  849. (should
  850. (zerop
  851. (org-test-with-temp-text "%%(org-calendar-holiday)"
  852. (org-indent-line)
  853. (org-get-indentation))))
  854. (should
  855. (zerop
  856. (org-test-with-temp-text "[fn:1] fn"
  857. (let ((org-adapt-indentation t)) (org-indent-line))
  858. (org-get-indentation))))
  859. (should
  860. (zerop
  861. (org-test-with-temp-text "* H"
  862. (org-indent-line)
  863. (org-get-indentation))))
  864. ;; Do not indent before first headline.
  865. (should
  866. (zerop
  867. (org-test-with-temp-text ""
  868. (org-indent-line)
  869. (org-get-indentation))))
  870. ;; Indent according to headline level otherwise, unless
  871. ;; `org-adapt-indentation' is nil.
  872. (should
  873. (= 2
  874. (org-test-with-temp-text "* H\n<point>A"
  875. (let ((org-adapt-indentation t)) (org-indent-line))
  876. (org-get-indentation))))
  877. (should
  878. (= 2
  879. (org-test-with-temp-text "* H\n<point>\nA"
  880. (let ((org-adapt-indentation t)) (org-indent-line))
  881. (org-get-indentation))))
  882. (should
  883. (zerop
  884. (org-test-with-temp-text "* H\n<point>A"
  885. (let ((org-adapt-indentation nil)) (org-indent-line))
  886. (org-get-indentation))))
  887. ;; Indenting preserves point position.
  888. (should
  889. (org-test-with-temp-text "* H\nA<point>B"
  890. (let ((org-adapt-indentation t)) (org-indent-line))
  891. (looking-at "B")))
  892. ;; Do not change indentation at an item or a LaTeX environment.
  893. (should
  894. (= 1
  895. (org-test-with-temp-text "* H\n<point> - A"
  896. (let ((org-adapt-indentation t)) (org-indent-line))
  897. (org-get-indentation))))
  898. (should
  899. (= 1
  900. (org-test-with-temp-text
  901. "\\begin{equation}\n <point>1+1=2\n\\end{equation}"
  902. (org-indent-line)
  903. (org-get-indentation))))
  904. ;; On blank lines at the end of a list, indent like last element
  905. ;; within it if the line is still in the list. If the last element
  906. ;; is an item, indent like its contents. Otherwise, indent like the
  907. ;; whole list.
  908. (should
  909. (= 4
  910. (org-test-with-temp-text "* H\n- A\n - AA\n<point>"
  911. (let ((org-adapt-indentation t)) (org-indent-line))
  912. (org-get-indentation))))
  913. (should
  914. (= 4
  915. (org-test-with-temp-text "* H\n- A\n -\n\n<point>"
  916. (let ((org-adapt-indentation t)) (org-indent-line))
  917. (org-get-indentation))))
  918. (should
  919. (zerop
  920. (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n<point>"
  921. (let ((org-adapt-indentation t)) (org-indent-line))
  922. (org-get-indentation))))
  923. (should
  924. (= 4
  925. (org-test-with-temp-text "* H\n- A\n - \n<point>"
  926. (let ((org-adapt-indentation t)) (org-indent-line))
  927. (org-get-indentation))))
  928. (should
  929. (= 4
  930. (org-test-with-temp-text
  931. "* H\n - \n #+BEGIN_SRC emacs-lisp\n t\n #+END_SRC\n<point>"
  932. (let ((org-adapt-indentation t)) (org-indent-line))
  933. (org-get-indentation))))
  934. (should
  935. (= 2
  936. (org-test-with-temp-text "- A\n B\n\n<point>"
  937. (let ((org-adapt-indentation nil)) (org-indent-line))
  938. (org-get-indentation))))
  939. (should
  940. (= 2
  941. (org-test-with-temp-text
  942. "- A\n \begin{cases} 1 + 1\n \end{cases}\n\n<point>"
  943. (let ((org-adapt-indentation nil)) (org-indent-line))
  944. (org-get-indentation))))
  945. ;; Likewise, on a blank line at the end of a footnote definition,
  946. ;; indent at column 0 if line belongs to the definition. Otherwise,
  947. ;; indent like the definition itself.
  948. (should
  949. (zerop
  950. (org-test-with-temp-text "* H\n[fn:1] Definition\n<point>"
  951. (let ((org-adapt-indentation t)) (org-indent-line))
  952. (org-get-indentation))))
  953. (should
  954. (zerop
  955. (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n<point>"
  956. (let ((org-adapt-indentation t)) (org-indent-line))
  957. (org-get-indentation))))
  958. ;; After the end of the contents of a greater element, indent like
  959. ;; the beginning of the element.
  960. (should
  961. (= 1
  962. (org-test-with-temp-text
  963. " #+BEGIN_CENTER\n Contents\n<point>#+END_CENTER"
  964. (org-indent-line)
  965. (org-get-indentation))))
  966. ;; On blank lines after a paragraph, indent like its last non-empty
  967. ;; line.
  968. (should
  969. (= 1
  970. (org-test-with-temp-text " Paragraph\n\n<point>"
  971. (org-indent-line)
  972. (org-get-indentation))))
  973. ;; At the first line of an element, indent like previous element's
  974. ;; first line, ignoring footnotes definitions and inline tasks, or
  975. ;; according to parent.
  976. (let ((org-adapt-indentation t))
  977. (should
  978. (= 2
  979. (org-test-with-temp-text "A\n\n B\n\nC<point>"
  980. (org-indent-line)
  981. (org-get-indentation))))
  982. (should
  983. (= 1
  984. (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC<point>"
  985. (org-indent-line)
  986. (org-get-indentation))))
  987. (should
  988. (= 1
  989. (org-test-with-temp-text
  990. " #+BEGIN_CENTER\n<point> Contents\n#+END_CENTER"
  991. (org-indent-line)
  992. (org-get-indentation)))))
  993. ;; Within code part of a source block, use language major mode if
  994. ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
  995. ;; according to line above.
  996. (should
  997. (= 6
  998. (org-test-with-temp-text
  999. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  1000. (let ((org-src-tab-acts-natively t)
  1001. (org-edit-src-content-indentation 0))
  1002. (org-indent-line))
  1003. (org-get-indentation))))
  1004. (should
  1005. (= 1
  1006. (org-test-with-temp-text
  1007. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  1008. (let ((org-src-tab-acts-natively nil)
  1009. (org-edit-src-content-indentation 0))
  1010. (org-indent-line))
  1011. (org-get-indentation))))
  1012. ;; Otherwise, indent like the first non-blank line above.
  1013. (should
  1014. (zerop
  1015. (org-test-with-temp-text
  1016. "#+BEGIN_CENTER\nline1\n\n<point> line2\n#+END_CENTER"
  1017. (org-indent-line)
  1018. (org-get-indentation))))
  1019. ;; Align node properties according to `org-property-format'. Handle
  1020. ;; nicely empty values.
  1021. (should
  1022. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1023. (org-test-with-temp-text
  1024. "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
  1025. (let ((org-property-format "%-10s %s")) (org-indent-line))
  1026. (buffer-string))))
  1027. (should
  1028. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1029. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
  1030. (let ((org-property-format "%-10s %s")) (org-indent-line))
  1031. (buffer-string)))))
  1032. (ert-deftest test-org/indent-region ()
  1033. "Test `org-indent-region' specifications."
  1034. ;; Indent paragraph.
  1035. (let ((org-adapt-indentation t))
  1036. (should
  1037. (equal "A\nB\nC"
  1038. (org-test-with-temp-text " A\nB\n C"
  1039. (org-indent-region (point-min) (point-max))
  1040. (buffer-string)))))
  1041. ;; Indent greater elements along with their contents.
  1042. (should
  1043. (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
  1044. (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
  1045. (org-indent-region (point-min) (point-max))
  1046. (buffer-string))))
  1047. ;; Ignore contents of verse blocks. Only indent block delimiters.
  1048. (should
  1049. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1050. (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1051. (org-indent-region (point-min) (point-max))
  1052. (buffer-string))))
  1053. (let ((org-adapt-indentation t))
  1054. (should
  1055. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1056. (org-test-with-temp-text " #+BEGIN_VERSE\n A\n B\n #+END_VERSE"
  1057. (org-indent-region (point-min) (point-max))
  1058. (buffer-string)))))
  1059. ;; Indent example blocks as a single block, unless indentation
  1060. ;; should be preserved. In this case only indent the block markers.
  1061. (should
  1062. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1063. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1064. (org-indent-region (point-min) (point-max))
  1065. (buffer-string))))
  1066. (let ((org-adapt-indentation t))
  1067. (should
  1068. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1069. (org-test-with-temp-text " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1070. (org-indent-region (point-min) (point-max))
  1071. (buffer-string))))
  1072. (should
  1073. (equal "#+BEGIN_EXAMPLE -i\n A\n B\n#+END_EXAMPLE"
  1074. (org-test-with-temp-text
  1075. " #+BEGIN_EXAMPLE -i\n A\n B\n #+END_EXAMPLE"
  1076. (org-indent-region (point-min) (point-max))
  1077. (buffer-string))))
  1078. (should
  1079. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1080. (org-test-with-temp-text
  1081. " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1082. (let ((org-src-preserve-indentation t))
  1083. (org-indent-region (point-min) (point-max)))
  1084. (buffer-string)))))
  1085. ;; Treat export blocks as a whole.
  1086. (should
  1087. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1088. (org-test-with-temp-text "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1089. (org-indent-region (point-min) (point-max))
  1090. (buffer-string))))
  1091. (let ((org-adapt-indentation t))
  1092. (should
  1093. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1094. (org-test-with-temp-text
  1095. " #+BEGIN_EXPORT latex\n A\n B\n #+END_EXPORT"
  1096. (org-indent-region (point-min) (point-max))
  1097. (buffer-string)))))
  1098. ;; Indent according to mode if `org-src-tab-acts-natively' is
  1099. ;; non-nil. Otherwise, do not indent code at all.
  1100. (should
  1101. (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
  1102. (org-test-with-temp-text
  1103. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1104. (let ((org-src-tab-acts-natively t)
  1105. (org-edit-src-content-indentation 0))
  1106. (org-indent-region (point-min) (point-max)))
  1107. (buffer-string))))
  1108. (should
  1109. (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1110. (org-test-with-temp-text
  1111. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1112. (let ((org-src-tab-acts-natively nil)
  1113. (org-edit-src-content-indentation 0))
  1114. (org-indent-region (point-min) (point-max)))
  1115. (buffer-string))))
  1116. ;; Align node properties according to `org-property-format'. Handle
  1117. ;; nicely empty values.
  1118. (should
  1119. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1120. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
  1121. (let ((org-property-format "%-10s %s")
  1122. (org-adapt-indentation nil))
  1123. (org-indent-region (point) (point-max)))
  1124. (buffer-string))))
  1125. (should
  1126. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1127. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
  1128. (let ((org-property-format "%-10s %s")
  1129. (org-adapt-indentation nil))
  1130. (org-indent-region (point) (point-max)))
  1131. (buffer-string))))
  1132. ;; Indent plain lists.
  1133. (let ((org-adapt-indentation t))
  1134. (should
  1135. (equal "- A\n B\n - C\n\n D"
  1136. (org-test-with-temp-text "- A\n B\n - C\n\n D"
  1137. (org-indent-region (point-min) (point-max))
  1138. (buffer-string))))
  1139. (should
  1140. (equal "- A\n\n- B"
  1141. (org-test-with-temp-text " - A\n\n - B"
  1142. (org-indent-region (point-min) (point-max))
  1143. (buffer-string)))))
  1144. ;; Indent footnote definitions.
  1145. (should
  1146. (equal "[fn:1] Definition\n\nDefinition"
  1147. (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
  1148. (org-indent-region (point-min) (point-max))
  1149. (buffer-string))))
  1150. ;; Special case: Start indenting on a blank line.
  1151. (should
  1152. (equal "\nParagraph"
  1153. (org-test-with-temp-text "\n Paragraph"
  1154. (org-indent-region (point-min) (point-max))
  1155. (buffer-string)))))
  1156. ;;; Editing
  1157. (ert-deftest test-org/delete-indentation ()
  1158. "Test `org-delete-indentation' specifications."
  1159. ;; Regular test.
  1160. (should (equal "foo bar"
  1161. (org-test-with-temp-text
  1162. "foo \n bar<point>"
  1163. (org-delete-indentation)
  1164. (buffer-string))))
  1165. ;; With optional argument.
  1166. (should (equal "foo bar"
  1167. (org-test-with-temp-text
  1168. "foo<point> \n bar"
  1169. (org-delete-indentation t)
  1170. (buffer-string))))
  1171. ;; At headline text should be appended to the headline text.
  1172. (should
  1173. (equal"* foo bar :tag:"
  1174. (let (org-auto-align-tags)
  1175. (org-test-with-temp-text
  1176. "* foo :tag:\n bar<point>"
  1177. (org-delete-indentation)
  1178. (buffer-string)))))
  1179. (should
  1180. (equal "* foo bar :tag:"
  1181. (let (org-auto-align-tags)
  1182. (org-test-with-temp-text
  1183. "* foo <point>:tag:\n bar"
  1184. (org-delete-indentation t)
  1185. (buffer-string))))))
  1186. (ert-deftest test-org/return ()
  1187. "Test `org-return' specifications."
  1188. ;; Regular test.
  1189. (should
  1190. (equal "Para\ngraph"
  1191. (org-test-with-temp-text "Para<point>graph"
  1192. (org-return)
  1193. (buffer-string))))
  1194. ;; With optional argument, indent line.
  1195. (should
  1196. (equal " Para\n graph"
  1197. (org-test-with-temp-text " Para<point>graph"
  1198. (org-return t)
  1199. (buffer-string))))
  1200. ;; On a table, call `org-table-next-row'.
  1201. (should
  1202. (org-test-with-temp-text "| <point>a |\n| b |"
  1203. (org-return)
  1204. (looking-at-p "b")))
  1205. ;; Open link or timestamp under point when `org-return-follows-link'
  1206. ;; is non-nil.
  1207. (should
  1208. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1209. (let ((org-return-follows-link t)
  1210. (org-link-search-must-match-exact-headline nil))
  1211. (org-return))
  1212. (looking-at-p "<<target>>")))
  1213. (should-not
  1214. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1215. (let ((org-return-follows-link nil)) (org-return))
  1216. (looking-at-p "<<target>>")))
  1217. (should
  1218. (org-test-with-temp-text "* [[b][a<point>]]\n* b"
  1219. (let ((org-return-follows-link t)) (org-return))
  1220. (looking-at-p "* b")))
  1221. (should
  1222. (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
  1223. (let ((org-return-follows-link t)
  1224. (org-link-search-must-match-exact-headline nil))
  1225. (org-return))
  1226. (looking-at-p "<<target>>")))
  1227. (should-not
  1228. (org-test-with-temp-text "Link [[target]]<point> <<target>>"
  1229. (let ((org-return-follows-link t)
  1230. (org-link-search-must-match-exact-headline nil))
  1231. (org-return))
  1232. (looking-at-p "<<target>>")))
  1233. ;; When `org-return-follows-link' is non-nil, tolerate links and
  1234. ;; timestamps in comments, node properties, etc.
  1235. (should
  1236. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1237. (let ((org-return-follows-link t)
  1238. (org-link-search-must-match-exact-headline nil))
  1239. (org-return))
  1240. (looking-at-p "<<target>>")))
  1241. (should-not
  1242. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1243. (let ((org-return-follows-link nil)) (org-return))
  1244. (looking-at-p "<<target>>")))
  1245. (should-not
  1246. (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
  1247. (let ((org-return-follows-link t)
  1248. (org-link-search-must-match-exact-headline nil))
  1249. (org-return))
  1250. (looking-at-p "<<target>>")))
  1251. ;; Non-nil `org-return-follows-link' ignores read-only state of
  1252. ;; a buffer.
  1253. (should
  1254. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1255. (let ((org-return-follows-link t)
  1256. (org-link-search-must-match-exact-headline nil))
  1257. (setq buffer-read-only t)
  1258. (call-interactively #'org-return))
  1259. (looking-at-p "<<target>>")))
  1260. ;; `org-return-follows-link' handle multi-line lines.
  1261. (should
  1262. (org-test-with-temp-text
  1263. "[[target][This is a very\n long description<point>]]\n <<target>>"
  1264. (let ((org-return-follows-link t)
  1265. (org-link-search-must-match-exact-headline nil))
  1266. (org-return))
  1267. (looking-at-p "<<target>>")))
  1268. (should-not
  1269. (org-test-with-temp-text
  1270. "[[target][This is a very\n long description]]<point>\n <<target>>"
  1271. (let ((org-return-follows-link t)
  1272. (org-link-search-must-match-exact-headline nil))
  1273. (org-return))
  1274. (looking-at-p "<<target>>")))
  1275. ;; However, do not open link when point is in a table.
  1276. (should
  1277. (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
  1278. (let ((org-return-follows-link t)) (org-return))
  1279. (looking-at-p "between")))
  1280. ;; Special case: in a list, when indenting, do not break structure.
  1281. (should
  1282. (equal "- A\n B"
  1283. (org-test-with-temp-text "- A <point>B"
  1284. (org-return t)
  1285. (buffer-string))))
  1286. (should
  1287. (equal "- A\n\n- B"
  1288. (org-test-with-temp-text "- A\n<point>- B"
  1289. (org-return t)
  1290. (buffer-string))))
  1291. ;; On tags part of a headline, add a newline below it instead of
  1292. ;; breaking it.
  1293. (should
  1294. (equal "* H :tag:\n"
  1295. (org-test-with-temp-text "* H :<point>tag:"
  1296. (org-return)
  1297. (buffer-string))))
  1298. ;; Before headline text, add a newline below it instead of breaking
  1299. ;; it.
  1300. (should
  1301. (equal "* TODO H :tag:\n"
  1302. (org-test-with-temp-text "* <point>TODO H :tag:"
  1303. (org-return)
  1304. (buffer-string))))
  1305. (should
  1306. (equal "* TODO [#B] H :tag:\n"
  1307. (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
  1308. (org-return)
  1309. (buffer-string))))
  1310. (should ;TODO are case-sensitive
  1311. (equal "* \nTodo"
  1312. (org-test-with-temp-text "* <point>Todo"
  1313. (org-return)
  1314. (buffer-string))))
  1315. ;; At headline text, break headline text but preserve tags.
  1316. (should
  1317. (equal "* TODO [#B] foo :tag:\nbar"
  1318. (let (org-auto-align-tags)
  1319. (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
  1320. (org-return)
  1321. (buffer-string)))))
  1322. ;; At bol of headline insert newline.
  1323. (should
  1324. (equal "\n* h"
  1325. (org-test-with-temp-text "<point>* h"
  1326. (org-return)
  1327. (buffer-string))))
  1328. ;; Refuse to leave invalid headline in buffer.
  1329. (should
  1330. (equal "* h\n"
  1331. (org-test-with-temp-text "*<point> h"
  1332. (org-return)
  1333. (buffer-string))))
  1334. ;; Before first column or after last one in a table, split the
  1335. ;; table.
  1336. (should
  1337. (equal "| a |\n\n| b |"
  1338. (org-test-with-temp-text "| a |\n<point>| b |"
  1339. (org-return)
  1340. (buffer-string))))
  1341. (should
  1342. (equal "| a |\n\n| b |"
  1343. (org-test-with-temp-text "| a |<point>\n| b |"
  1344. (org-return)
  1345. (buffer-string))))
  1346. ;; Do not auto-fill on hitting <RET> inside a property drawer.
  1347. (should
  1348. (equal "* Heading\n:PROPERTIES:\n:SOME_PROP: This is a very long property value that goes beyond the fill-column. But this is inside a property drawer, so the auto-filling should be disabled.\n\n:END:"
  1349. (org-test-with-temp-text "* Heading\n:PROPERTIES:\n:SOME_PROP: This is a very long property value that goes beyond the fill-column. But this is inside a property drawer, so the auto-filling should be disabled.<point>\n:END:"
  1350. (setq-local fill-column 10)
  1351. (auto-fill-mode 1)
  1352. (org-return)
  1353. (buffer-string)))))
  1354. (ert-deftest test-org/with-electric-indent ()
  1355. "Test RET and C-j specifications with `electric-indent-mode' on."
  1356. ;; Call commands interactively, since this is how `newline' knows it
  1357. ;; must run `post-self-insert-hook'.
  1358. ;;
  1359. ;; RET, like `newline', should indent.
  1360. (should
  1361. (equal " Para\n graph"
  1362. (org-test-with-temp-text " Para<point>graph"
  1363. (electric-indent-local-mode 1)
  1364. (call-interactively 'org-return)
  1365. (buffer-string))))
  1366. (should
  1367. (equal "- item1\n item2"
  1368. (org-test-with-temp-text "- item1<point>item2"
  1369. (electric-indent-local-mode 1)
  1370. (call-interactively 'org-return)
  1371. (buffer-string))))
  1372. ;; TODO: test more values of `org-adapt-indentation'.
  1373. (let ((org-adapt-indentation t))
  1374. (should
  1375. (equal "* heading\n body"
  1376. (org-test-with-temp-text "* heading<point>body"
  1377. (electric-indent-local-mode 1)
  1378. (call-interactively 'org-return)
  1379. (buffer-string)))))
  1380. ;; C-j, like `electric-newline-and-maybe-indent', should not indent.
  1381. (should
  1382. (equal " Para\ngraph"
  1383. (org-test-with-temp-text " Para<point>graph"
  1384. (electric-indent-local-mode 1)
  1385. (call-interactively 'org-return-and-maybe-indent)
  1386. (buffer-string))))
  1387. (should
  1388. (equal "- item1\nitem2"
  1389. (org-test-with-temp-text "- item1<point>item2"
  1390. (electric-indent-local-mode 1)
  1391. (call-interactively 'org-return-and-maybe-indent)
  1392. (buffer-string))))
  1393. ;; TODO: test more values of `org-adapt-indentation'.
  1394. (let ((org-adapt-indentation t))
  1395. (should
  1396. (equal "* heading\nbody"
  1397. (org-test-with-temp-text "* heading<point>body"
  1398. (electric-indent-local-mode 1)
  1399. (call-interactively 'org-return-and-maybe-indent)
  1400. (buffer-string))))))
  1401. (ert-deftest test-org/without-electric-indent ()
  1402. "Test RET and C-j specifications with `electric-indent-mode' off."
  1403. ;; Call commands interactively, since this is how `newline' knows it
  1404. ;; must run `post-self-insert-hook'.
  1405. ;;
  1406. ;; RET, like `newline', should not indent.
  1407. (should
  1408. (equal " Para\ngraph"
  1409. (org-test-with-temp-text " Para<point>graph"
  1410. (electric-indent-local-mode 0)
  1411. (call-interactively 'org-return)
  1412. (buffer-string))))
  1413. (should
  1414. (equal "- item1\nitem2"
  1415. (org-test-with-temp-text "- item1<point>item2"
  1416. (electric-indent-local-mode 0)
  1417. (call-interactively 'org-return)
  1418. (buffer-string))))
  1419. (should
  1420. (equal "* heading\nbody"
  1421. (org-test-with-temp-text "* heading<point>body"
  1422. (electric-indent-local-mode 0)
  1423. (call-interactively 'org-return)
  1424. (buffer-string))))
  1425. ;; C-j, like `electric-newline-and-maybe-indent', should indent.
  1426. (should
  1427. (equal " Para\n graph"
  1428. (org-test-with-temp-text " Para<point>graph"
  1429. (electric-indent-local-mode 0)
  1430. (call-interactively 'org-return-and-maybe-indent)
  1431. (buffer-string))))
  1432. (should
  1433. (equal "- item1\n item2"
  1434. (org-test-with-temp-text "- item1<point>item2"
  1435. (electric-indent-local-mode 0)
  1436. (call-interactively 'org-return-and-maybe-indent)
  1437. (buffer-string))))
  1438. ;; TODO: test more values of `org-adapt-indentation'.
  1439. (let ((org-adapt-indentation t))
  1440. (should
  1441. (equal "* heading\n body"
  1442. (org-test-with-temp-text "* heading<point>body"
  1443. (electric-indent-local-mode 0)
  1444. (call-interactively 'org-return-and-maybe-indent)
  1445. (buffer-string))))))
  1446. (ert-deftest test-org/meta-return ()
  1447. "Test M-RET (`org-meta-return') specifications."
  1448. ;; In a table field insert a row above.
  1449. (should
  1450. (org-test-with-temp-text "| a |"
  1451. (forward-char)
  1452. (org-meta-return)
  1453. (forward-line -1)
  1454. (looking-at "| |$")))
  1455. ;; In a paragraph change current line into a header.
  1456. (should
  1457. (org-test-with-temp-text "a"
  1458. (org-meta-return)
  1459. (beginning-of-line)
  1460. (looking-at "\* a$")))
  1461. ;; In an item insert an item, in this case above.
  1462. (should
  1463. (org-test-with-temp-text "- a"
  1464. (org-meta-return)
  1465. (beginning-of-line)
  1466. (looking-at "- $")))
  1467. ;; In a drawer and item insert an item, in this case above.
  1468. (should
  1469. (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
  1470. (forward-line)
  1471. (org-meta-return)
  1472. (beginning-of-line)
  1473. (looking-at "- $"))))
  1474. (ert-deftest test-org/insert-heading ()
  1475. "Test `org-insert-heading' specifications."
  1476. ;; In an empty buffer, insert a new headline.
  1477. (should
  1478. (equal "* "
  1479. (org-test-with-temp-text ""
  1480. (org-insert-heading)
  1481. (buffer-string))))
  1482. ;; At the beginning of a line, turn it into a headline.
  1483. (should
  1484. (equal "* P"
  1485. (org-test-with-temp-text "<point>P"
  1486. (org-insert-heading)
  1487. (buffer-string))))
  1488. ;; In the middle of a line, split the line if allowed, otherwise,
  1489. ;; insert the headline at its end.
  1490. (should
  1491. (equal "Para\n* graph"
  1492. (org-test-with-temp-text "Para<point>graph"
  1493. (let ((org-M-RET-may-split-line '((default . t))))
  1494. (org-insert-heading))
  1495. (buffer-string))))
  1496. (should
  1497. (equal "Paragraph\n* "
  1498. (org-test-with-temp-text "Para<point>graph"
  1499. (let ((org-M-RET-may-split-line '((default . nil))))
  1500. (org-insert-heading))
  1501. (buffer-string))))
  1502. ;; At the beginning of a headline, create one above.
  1503. (should
  1504. (equal "* \n* H"
  1505. (org-test-with-temp-text "* H"
  1506. (org-insert-heading)
  1507. (buffer-string))))
  1508. ;; In the middle of a headline, split it if allowed.
  1509. (should
  1510. (equal "* H\n* 1"
  1511. (org-test-with-temp-text "* H<point>1"
  1512. (let ((org-M-RET-may-split-line '((headline . t))))
  1513. (org-insert-heading))
  1514. (buffer-string))))
  1515. (should
  1516. (equal "* H1\n* "
  1517. (org-test-with-temp-text "* H<point>1"
  1518. (let ((org-M-RET-may-split-line '((headline . nil))))
  1519. (org-insert-heading))
  1520. (buffer-string))))
  1521. ;; However, splitting cannot happen on TODO keywords, priorities or
  1522. ;; tags.
  1523. (should
  1524. (equal "* TODO H1\n* "
  1525. (org-test-with-temp-text "* TO<point>DO H1"
  1526. (let ((org-M-RET-may-split-line '((headline . t))))
  1527. (org-insert-heading))
  1528. (buffer-string))))
  1529. (should
  1530. (equal "* [#A] H1\n* "
  1531. (org-test-with-temp-text "* [#<point>A] H1"
  1532. (let ((org-M-RET-may-split-line '((headline . t))))
  1533. (org-insert-heading))
  1534. (buffer-string))))
  1535. (should
  1536. (equal "* H1 :tag:\n* "
  1537. (org-test-with-temp-text "* H1 :ta<point>g:"
  1538. (let ((org-M-RET-may-split-line '((headline . t))))
  1539. (org-insert-heading))
  1540. (buffer-string))))
  1541. ;; New headline level depends on the level of the headline above.
  1542. (should
  1543. (equal "** H\n** P"
  1544. (org-test-with-temp-text "** H\n<point>P"
  1545. (org-insert-heading)
  1546. (buffer-string))))
  1547. (should
  1548. (equal "** H\nPara\n** graph"
  1549. (org-test-with-temp-text "** H\nPara<point>graph"
  1550. (let ((org-M-RET-may-split-line '((default . t))))
  1551. (org-insert-heading))
  1552. (buffer-string))))
  1553. (should
  1554. (equal "** \n** H"
  1555. (org-test-with-temp-text "** H"
  1556. (org-insert-heading)
  1557. (buffer-string))))
  1558. ;; When called with one universal argument, insert a new headline at
  1559. ;; the end of the current subtree, independently on the position of
  1560. ;; point.
  1561. (should
  1562. (equal
  1563. "* H1\n** H2\n* "
  1564. (org-test-with-temp-text "* H1\n** H2"
  1565. (let ((org-insert-heading-respect-content nil))
  1566. (org-insert-heading '(4)))
  1567. (buffer-string))))
  1568. (should
  1569. (equal
  1570. "* H1\n** H2\n* "
  1571. (org-test-with-temp-text "* H<point>1\n** H2"
  1572. (let ((org-insert-heading-respect-content nil))
  1573. (org-insert-heading '(4)))
  1574. (buffer-string))))
  1575. ;; When called with two universal arguments, insert a new headline
  1576. ;; at the end of the grandparent subtree.
  1577. (should
  1578. (equal "* H1\n** H3\n- item\n** H2\n** "
  1579. (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
  1580. (let ((org-insert-heading-respect-content nil))
  1581. (org-insert-heading '(16)))
  1582. (buffer-string))))
  1583. ;; When optional TOP-LEVEL argument is non-nil, always insert
  1584. ;; a level 1 heading.
  1585. (should
  1586. (equal "* H1\n** H2\n* "
  1587. (org-test-with-temp-text "* H1\n** H2<point>"
  1588. (org-insert-heading nil nil t)
  1589. (buffer-string))))
  1590. (should
  1591. (equal "* H1\n- item\n* "
  1592. (org-test-with-temp-text "* H1\n- item<point>"
  1593. (org-insert-heading nil nil t)
  1594. (buffer-string))))
  1595. ;; Obey `org-blank-before-new-entry'.
  1596. (should
  1597. (equal "* H1\n\n* "
  1598. (org-test-with-temp-text "* H1<point>"
  1599. (let ((org-blank-before-new-entry '((heading . t))))
  1600. (org-insert-heading))
  1601. (buffer-string))))
  1602. (should
  1603. (equal "* H1\n* "
  1604. (org-test-with-temp-text "* H1<point>"
  1605. (let ((org-blank-before-new-entry '((heading . nil))))
  1606. (org-insert-heading))
  1607. (buffer-string))))
  1608. (should
  1609. (equal "* H1\n* H2\n* "
  1610. (org-test-with-temp-text "* H1\n* H2<point>"
  1611. (let ((org-blank-before-new-entry '((heading . auto))))
  1612. (org-insert-heading))
  1613. (buffer-string))))
  1614. (should
  1615. (equal "* H1\n\n* H2\n\n* "
  1616. (org-test-with-temp-text "* H1\n\n* H2<point>"
  1617. (let ((org-blank-before-new-entry '((heading . auto))))
  1618. (org-insert-heading))
  1619. (buffer-string))))
  1620. ;; Corner case: correctly insert a headline after an empty one.
  1621. (should
  1622. (equal "* \n* "
  1623. (org-test-with-temp-text "* <point>"
  1624. (org-insert-heading)
  1625. (buffer-string))))
  1626. (should
  1627. (org-test-with-temp-text "* <point>\n"
  1628. (org-insert-heading)
  1629. (looking-at-p "\n\\'")))
  1630. ;; Do not insert spurious headlines when inserting a new headline.
  1631. (should
  1632. (equal "* H1\n* H2\n* \n"
  1633. (org-test-with-temp-text "* H1\n* H2<point>\n"
  1634. (org-insert-heading)
  1635. (buffer-string))))
  1636. ;; Preserve visibility at beginning of line. In particular, when
  1637. ;; removing spurious blank lines, do not visually merge heading with
  1638. ;; the line visible above.
  1639. (should-not
  1640. (org-test-with-temp-text "* H1<point>\nContents\n\n* H2\n"
  1641. (org-overview)
  1642. (let ((org-blank-before-new-entry '((heading . nil))))
  1643. (org-insert-heading '(4)))
  1644. (invisible-p (line-end-position 0))))
  1645. ;; Properly handle empty lines when forcing a headline below current
  1646. ;; one.
  1647. (should
  1648. (equal "* H1\n\n* H\n\n* "
  1649. (org-test-with-temp-text "* H1\n\n* H<point>"
  1650. (let ((org-blank-before-new-entry '((heading . t))))
  1651. (org-insert-heading '(4))
  1652. (buffer-string))))))
  1653. (ert-deftest test-org/insert-todo-heading-respect-content ()
  1654. "Test `org-insert-todo-heading-respect-content' specifications."
  1655. ;; Create a TODO heading.
  1656. (should
  1657. (org-test-with-temp-text "* H1\n Body"
  1658. (org-insert-todo-heading-respect-content)
  1659. (nth 2 (org-heading-components))))
  1660. ;; Add headline at the end of the first subtree
  1661. (should
  1662. (equal
  1663. "* TODO "
  1664. (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
  1665. (org-insert-todo-heading-respect-content)
  1666. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1667. ;; In a list, do not create a new item.
  1668. (should
  1669. (equal
  1670. "* TODO "
  1671. (org-test-with-temp-text "* H\n- an item\n- another one"
  1672. (search-forward "an ")
  1673. (org-insert-todo-heading-respect-content)
  1674. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1675. ;; Use the same TODO keyword as current heading.
  1676. (should
  1677. (equal
  1678. "* TODO \n"
  1679. (org-test-with-temp-text "* TODO\n** WAITING\n"
  1680. (org-insert-todo-heading-respect-content)
  1681. (buffer-substring-no-properties (line-beginning-position) (point-max))))))
  1682. (ert-deftest test-org/clone-with-time-shift ()
  1683. "Test `org-clone-subtree-with-time-shift'."
  1684. ;; Raise an error before first heading.
  1685. (should-error
  1686. (org-test-with-temp-text ""
  1687. (org-clone-subtree-with-time-shift 1)))
  1688. ;; Raise an error on invalid number of clones.
  1689. (should-error
  1690. (org-test-with-temp-text "* Clone me"
  1691. (org-clone-subtree-with-time-shift -1)))
  1692. ;; Clone non-repeating once.
  1693. (should
  1694. (equal "\
  1695. * H1\n<2015-06-21>
  1696. * H1\n<2015-06-23>
  1697. "
  1698. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1699. (org-clone-subtree-with-time-shift 1 "+2d")
  1700. (replace-regexp-in-string
  1701. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1702. nil nil 1))))
  1703. ;; Clone repeating once.
  1704. (should
  1705. (equal "\
  1706. * H1\n<2015-06-21>
  1707. * H1\n<2015-06-23>
  1708. * H1\n<2015-06-25 +1w>
  1709. "
  1710. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1711. (org-clone-subtree-with-time-shift 1 "+2d")
  1712. (replace-regexp-in-string
  1713. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1714. nil nil 1))))
  1715. ;; Clone repeating once in backward.
  1716. (should
  1717. (equal "\
  1718. * H1\n<2015-06-21>
  1719. * H1\n<2015-06-19>
  1720. * H1\n<2015-06-17 +1w>
  1721. "
  1722. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1723. (org-clone-subtree-with-time-shift 1 "-2d")
  1724. (replace-regexp-in-string
  1725. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1726. nil nil 1))))
  1727. ;; Clone non-repeating zero times.
  1728. (should
  1729. (equal "\
  1730. * H1\n<2015-06-21>
  1731. "
  1732. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1733. (org-clone-subtree-with-time-shift 0 "+2d")
  1734. (replace-regexp-in-string
  1735. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1736. nil nil 1))))
  1737. ;; Clone repeating "zero" times.
  1738. (should
  1739. (equal "\
  1740. * H1\n<2015-06-21>
  1741. * H1\n<2015-06-23 +1w>
  1742. "
  1743. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1744. (org-clone-subtree-with-time-shift 0 "+2d")
  1745. (replace-regexp-in-string
  1746. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1747. nil nil 1))))
  1748. ;; Clone with blank SHIFT argument.
  1749. (should
  1750. (string-prefix-p
  1751. "* H <2012-03-29"
  1752. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1753. (org-clone-subtree-with-time-shift 1 "")
  1754. (buffer-substring-no-properties (line-beginning-position 2)
  1755. (line-end-position 2)))))
  1756. ;; Find time stamps before point. If SHIFT is not specified, ask
  1757. ;; for a time shift.
  1758. (should
  1759. (string-prefix-p
  1760. "* H <2012-03-30"
  1761. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1762. (org-clone-subtree-with-time-shift 1 "+1d")
  1763. (buffer-substring-no-properties (line-beginning-position 2)
  1764. (line-end-position 2)))))
  1765. (should
  1766. (string-prefix-p
  1767. "* H <2014-03-05"
  1768. (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
  1769. (cl-letf (((symbol-function 'read-from-minibuffer)
  1770. (lambda (&rest args) "+1d")))
  1771. (org-clone-subtree-with-time-shift 1))
  1772. (buffer-substring-no-properties (line-beginning-position 2)
  1773. (line-end-position 2))))))
  1774. ;;; Fixed-Width Areas
  1775. (ert-deftest test-org/toggle-fixed-width ()
  1776. "Test `org-toggle-fixed-width' specifications."
  1777. ;; No region: Toggle on fixed-width marker in paragraphs.
  1778. (should
  1779. (equal ": A"
  1780. (org-test-with-temp-text "A"
  1781. (org-toggle-fixed-width)
  1782. (buffer-string))))
  1783. ;; No region: Toggle off fixed-width markers in fixed-width areas.
  1784. (should
  1785. (equal "A"
  1786. (org-test-with-temp-text ": A"
  1787. (org-toggle-fixed-width)
  1788. (buffer-string))))
  1789. ;; No region: Toggle on marker in blank lines after elements or just
  1790. ;; after a headline.
  1791. (should
  1792. (equal "* H\n: "
  1793. (org-test-with-temp-text "* H\n"
  1794. (forward-line)
  1795. (org-toggle-fixed-width)
  1796. (buffer-string))))
  1797. (should
  1798. (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
  1799. (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
  1800. (goto-char (point-max))
  1801. (org-toggle-fixed-width)
  1802. (buffer-string))))
  1803. ;; No region: Toggle on marker in front of one line elements (e.g.,
  1804. ;; headlines, clocks)
  1805. (should
  1806. (equal ": * Headline"
  1807. (org-test-with-temp-text "* Headline"
  1808. (org-toggle-fixed-width)
  1809. (buffer-string))))
  1810. (should
  1811. (equal ": #+KEYWORD: value"
  1812. (org-test-with-temp-text "#+KEYWORD: value"
  1813. (org-toggle-fixed-width)
  1814. (buffer-string))))
  1815. ;; No region: error in other situations.
  1816. (should-error
  1817. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
  1818. (forward-line)
  1819. (org-toggle-fixed-width)
  1820. (buffer-string)))
  1821. ;; No region: Indentation is preserved.
  1822. (should
  1823. (equal "- A\n : B"
  1824. (org-test-with-temp-text "- A\n B"
  1825. (forward-line)
  1826. (org-toggle-fixed-width)
  1827. (buffer-string))))
  1828. ;; Region: If it contains only fixed-width elements and blank lines,
  1829. ;; toggle off fixed-width markup.
  1830. (should
  1831. (equal "A\n\nB"
  1832. (org-test-with-temp-text ": A\n\n: B"
  1833. (transient-mark-mode 1)
  1834. (push-mark (point) t t)
  1835. (goto-char (point-max))
  1836. (org-toggle-fixed-width)
  1837. (buffer-string))))
  1838. ;; Region: If it contains anything else, toggle on fixed-width but
  1839. ;; not on fixed-width areas.
  1840. (should
  1841. (equal ": A\n: \n: B\n: \n: C"
  1842. (org-test-with-temp-text "A\n\n: B\n\nC"
  1843. (transient-mark-mode 1)
  1844. (push-mark (point) t t)
  1845. (goto-char (point-max))
  1846. (org-toggle-fixed-width)
  1847. (buffer-string))))
  1848. ;; Region: Ignore blank lines at its end, unless it contains only
  1849. ;; such lines.
  1850. (should
  1851. (equal ": A\n\n"
  1852. (org-test-with-temp-text "A\n\n"
  1853. (transient-mark-mode 1)
  1854. (push-mark (point) t t)
  1855. (goto-char (point-max))
  1856. (org-toggle-fixed-width)
  1857. (buffer-string))))
  1858. (should
  1859. (equal ": \n: \n"
  1860. (org-test-with-temp-text "\n\n"
  1861. (transient-mark-mode 1)
  1862. (push-mark (point) t t)
  1863. (goto-char (point-max))
  1864. (org-toggle-fixed-width)
  1865. (buffer-string)))))
  1866. (ert-deftest test-org/kill-line ()
  1867. "Test `org-kill-line' specifications."
  1868. ;; At the beginning of a line, kill whole line.
  1869. (should
  1870. (equal ""
  1871. (org-test-with-temp-text "abc"
  1872. (org-kill-line)
  1873. (buffer-string))))
  1874. ;; In the middle of a line, kill line until its end.
  1875. (should
  1876. (equal "a"
  1877. (org-test-with-temp-text "a<point>bc"
  1878. (org-kill-line)
  1879. (buffer-string))))
  1880. ;; Do not kill newline character.
  1881. (should
  1882. (equal "\n123"
  1883. (org-test-with-temp-text "abc\n123"
  1884. (org-kill-line)
  1885. (buffer-string))))
  1886. (should
  1887. (equal "a\n123"
  1888. (org-test-with-temp-text "a<point>bc\n123"
  1889. (org-kill-line)
  1890. (buffer-string))))
  1891. ;; When `org-special-ctrl-k' is non-nil and point is at a headline,
  1892. ;; kill until tags.
  1893. (should
  1894. (equal "* A :tag:"
  1895. (org-test-with-temp-text "* A<point>B :tag:"
  1896. (let ((org-special-ctrl-k t)
  1897. (org-tags-column 0))
  1898. (org-kill-line))
  1899. (buffer-string))))
  1900. ;; If point is on tags, only kill part left until the end of line.
  1901. (should
  1902. (equal "* A :tag:"
  1903. (org-test-with-temp-text "* A :tag:<point>tag2:"
  1904. (let ((org-special-ctrl-k t)
  1905. (org-tags-column 0))
  1906. (org-kill-line))
  1907. (buffer-string))))
  1908. ;; However, if point is at the beginning of the line, kill whole
  1909. ;; headline.
  1910. (should
  1911. (equal ""
  1912. (org-test-with-temp-text "* AB :tag:"
  1913. (let ((org-special-ctrl-k t)
  1914. (org-tags-column 0))
  1915. (org-kill-line))
  1916. (buffer-string))))
  1917. ;; When `org-ctrl-k-protect-subtree' is non-nil, and point is in
  1918. ;; invisible text, ask before removing it. When set to `error',
  1919. ;; throw an error.
  1920. (should-error
  1921. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  1922. (org-overview)
  1923. (let ((org-special-ctrl-k nil)
  1924. (org-ctrl-k-protect-subtree t))
  1925. (cl-letf (((symbol-function 'y-or-n-p) 'ignore))
  1926. (org-kill-line)))))
  1927. (should-error
  1928. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  1929. (org-overview)
  1930. (let ((org-special-ctrl-k nil)
  1931. (org-ctrl-k-protect-subtree 'error))
  1932. (org-kill-line)))))
  1933. ;;; Headline
  1934. (ert-deftest test-org/get-heading ()
  1935. "Test `org-get-heading' specifications."
  1936. ;; Return current heading, even if point is not on it.
  1937. (should
  1938. (equal "H"
  1939. (org-test-with-temp-text "* H"
  1940. (org-get-heading))))
  1941. (should
  1942. (equal "H"
  1943. (org-test-with-temp-text "* H\nText<point>"
  1944. (org-get-heading))))
  1945. ;; Without any optional argument, return TODO keyword, priority
  1946. ;; cookie, COMMENT keyword and tags.
  1947. (should
  1948. (equal "TODO H"
  1949. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  1950. (org-get-heading))))
  1951. (should
  1952. (equal "[#A] H"
  1953. (org-test-with-temp-text "* [#A] H"
  1954. (org-get-heading))))
  1955. (should
  1956. (equal "COMMENT H"
  1957. (org-test-with-temp-text "* COMMENT H"
  1958. (org-get-heading))))
  1959. (should
  1960. (equal "H :tag:"
  1961. (org-test-with-temp-text "* H :tag:"
  1962. (org-get-heading))))
  1963. ;; With NO-TAGS argument, ignore tags.
  1964. (should
  1965. (equal "TODO H"
  1966. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  1967. (org-get-heading t))))
  1968. (should
  1969. (equal "H"
  1970. (org-test-with-temp-text "* H :tag:"
  1971. (org-get-heading t))))
  1972. ;; With NO-TODO, ignore TODO keyword.
  1973. (should
  1974. (equal "H"
  1975. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  1976. (org-get-heading nil t))))
  1977. (should
  1978. (equal "H :tag:"
  1979. (org-test-with-temp-text "* H :tag:"
  1980. (org-get-heading nil t))))
  1981. ;; TODO keywords are case-sensitive.
  1982. (should
  1983. (equal "Todo H"
  1984. (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
  1985. (org-get-heading nil t))))
  1986. ;; With NO-PRIORITY, ignore priority.
  1987. (should
  1988. (equal "H"
  1989. (org-test-with-temp-text "* [#A] H"
  1990. (org-get-heading nil nil t))))
  1991. (should
  1992. (equal "H"
  1993. (org-test-with-temp-text "* H"
  1994. (org-get-heading nil nil t))))
  1995. (should
  1996. (equal "TODO H"
  1997. (org-test-with-temp-text "* TODO [#A] H"
  1998. (org-get-heading nil nil t))))
  1999. ;; With NO-COMMENT, ignore COMMENT keyword.
  2000. (should
  2001. (equal "H"
  2002. (org-test-with-temp-text "* COMMENT H"
  2003. (org-get-heading nil nil nil t))))
  2004. (should
  2005. (equal "H"
  2006. (org-test-with-temp-text "* H"
  2007. (org-get-heading nil nil nil t))))
  2008. (should
  2009. (equal "TODO [#A] H"
  2010. (org-test-with-temp-text "* TODO [#A] COMMENT H"
  2011. (org-get-heading nil nil nil t))))
  2012. ;; On an empty headline, return value is consistent.
  2013. (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
  2014. (should (equal "" (org-test-with-temp-text "* " (org-get-heading t))))
  2015. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t))))
  2016. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t))))
  2017. (should
  2018. (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t)))))
  2019. (ert-deftest test-org/in-commented-heading-p ()
  2020. "Test `org-in-commented-heading-p' specifications."
  2021. ;; Commented headline.
  2022. (should
  2023. (org-test-with-temp-text "* COMMENT Headline\nBody"
  2024. (goto-char (point-max))
  2025. (org-in-commented-heading-p)))
  2026. ;; Commented ancestor.
  2027. (should
  2028. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  2029. (goto-char (point-max))
  2030. (org-in-commented-heading-p)))
  2031. ;; Comment keyword is case-sensitive.
  2032. (should-not
  2033. (org-test-with-temp-text "* Comment Headline\nBody"
  2034. (goto-char (point-max))
  2035. (org-in-commented-heading-p)))
  2036. ;; Keyword is standalone.
  2037. (should-not
  2038. (org-test-with-temp-text "* COMMENTHeadline\nBody"
  2039. (goto-char (point-max))
  2040. (org-in-commented-heading-p)))
  2041. ;; Optional argument.
  2042. (should-not
  2043. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  2044. (goto-char (point-max))
  2045. (org-in-commented-heading-p t))))
  2046. (ert-deftest test-org/in-archived-heading-p ()
  2047. "Test `org-in-archived-heading-p' specifications."
  2048. ;; Archived headline.
  2049. (should
  2050. (org-test-with-temp-text "* Headline :ARCHIVE:\nBody"
  2051. (goto-char (point-max))
  2052. (org-in-archived-heading-p)))
  2053. ;; Archived ancestor.
  2054. (should
  2055. (org-test-with-temp-text "* Headline :ARCHIVE:\n** Level 2\nBody"
  2056. (goto-char (point-max))
  2057. (org-in-archived-heading-p)))
  2058. ;; Optional argument.
  2059. (should-not
  2060. (org-test-with-temp-text "* Headline :ARCHIVE:\n** Level 2\nBody"
  2061. (goto-char (point-max))
  2062. (org-in-archived-heading-p t)))
  2063. ;; Archive tag containing ARCHIVE as substring
  2064. (should-not
  2065. (org-test-with-temp-text "* Headline :NOARCHIVE:\n** Level 2\nBody"
  2066. (goto-char (point-max))
  2067. (org-in-archived-heading-p))))
  2068. (ert-deftest test-org/entry-blocked-p ()
  2069. ;; Check other dependencies.
  2070. (should
  2071. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  2072. (let ((org-enforce-todo-dependencies t)
  2073. (org-blocker-hook
  2074. '(org-block-todo-from-children-or-siblings-or-parent)))
  2075. (org-entry-blocked-p))))
  2076. (should-not
  2077. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  2078. (let ((org-enforce-todo-dependencies t)
  2079. (org-blocker-hook
  2080. '(org-block-todo-from-children-or-siblings-or-parent)))
  2081. (org-entry-blocked-p))))
  2082. ;; Entry without a TODO keyword or with a DONE keyword cannot be
  2083. ;; blocked.
  2084. (should-not
  2085. (org-test-with-temp-text "* Blocked\n** TODO one"
  2086. (let ((org-enforce-todo-dependencies t)
  2087. (org-blocker-hook
  2088. '(org-block-todo-from-children-or-siblings-or-parent)))
  2089. (org-entry-blocked-p))))
  2090. (should-not
  2091. (org-test-with-temp-text "* DONE Blocked\n** TODO one"
  2092. (let ((org-enforce-todo-dependencies t)
  2093. (org-blocker-hook
  2094. '(org-block-todo-from-children-or-siblings-or-parent)))
  2095. (org-entry-blocked-p))))
  2096. ;; Follow :ORDERED: specifications.
  2097. (should
  2098. (org-test-with-temp-text
  2099. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
  2100. (let ((org-enforce-todo-dependencies t)
  2101. (org-blocker-hook
  2102. '(org-block-todo-from-children-or-siblings-or-parent)))
  2103. (org-entry-blocked-p))))
  2104. (should-not
  2105. (org-test-with-temp-text
  2106. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
  2107. (let ((org-enforce-todo-dependencies t)
  2108. (org-blocker-hook
  2109. '(org-block-todo-from-children-or-siblings-or-parent)))
  2110. (org-entry-blocked-p)))))
  2111. (ert-deftest test-org/get-outline-path ()
  2112. "Test `org-get-outline-path' specifications."
  2113. ;; Top-level headlines have no outline path.
  2114. (should-not
  2115. (org-test-with-temp-text "* H"
  2116. (org-get-outline-path)))
  2117. ;; Otherwise, outline path is the path leading to the headline.
  2118. (should
  2119. (equal '("H")
  2120. (org-test-with-temp-text "* H\n** S<point>"
  2121. (org-get-outline-path))))
  2122. ;; Find path even when point is not on a headline.
  2123. (should
  2124. (equal '("H")
  2125. (org-test-with-temp-text "* H\n** S\nText<point>"
  2126. (org-get-outline-path))))
  2127. ;; TODO keywords, tags and statistics cookies are ignored.
  2128. (should
  2129. (equal '("H")
  2130. (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
  2131. (org-get-outline-path))))
  2132. ;; Links are replaced with their description or their path.
  2133. (should
  2134. (equal '("Org")
  2135. (org-test-with-temp-text
  2136. "* [[https://orgmode.org][Org]]\n** S<point>"
  2137. (org-get-outline-path))))
  2138. (should
  2139. (equal '("https://orgmode.org")
  2140. (org-test-with-temp-text
  2141. "* [[https://orgmode.org]]\n** S<point>"
  2142. (org-get-outline-path))))
  2143. ;; When WITH-SELF is non-nil, include current heading.
  2144. (should
  2145. (equal '("H")
  2146. (org-test-with-temp-text "* H"
  2147. (org-get-outline-path t))))
  2148. (should
  2149. (equal '("H" "S")
  2150. (org-test-with-temp-text "* H\n** S\nText<point>"
  2151. (org-get-outline-path t))))
  2152. ;; Using cache is transparent to the user.
  2153. (should
  2154. (equal '("H")
  2155. (org-test-with-temp-text "* H\n** S<point>"
  2156. (setq org-outline-path-cache nil)
  2157. (org-get-outline-path nil t))))
  2158. ;; Do not corrupt cache when finding outline path in distant part of
  2159. ;; the buffer.
  2160. (should
  2161. (equal '("H2")
  2162. (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
  2163. (setq org-outline-path-cache nil)
  2164. (org-get-outline-path nil t)
  2165. (search-forward "S2")
  2166. (org-get-outline-path nil t))))
  2167. ;; Do not choke on empty headlines.
  2168. (should
  2169. (org-test-with-temp-text "* H\n** <point>"
  2170. (org-get-outline-path)))
  2171. (should
  2172. (org-test-with-temp-text "* \n** H<point>"
  2173. (org-get-outline-path))))
  2174. (ert-deftest test-org/format-outline-path ()
  2175. "Test `org-format-outline-path' specifications."
  2176. (should
  2177. (string= (org-format-outline-path (list "one" "two" "three"))
  2178. "one/two/three"))
  2179. ;; Empty path.
  2180. (should
  2181. (string= (org-format-outline-path '())
  2182. ""))
  2183. (should
  2184. (string= (org-format-outline-path '(nil))
  2185. ""))
  2186. ;; Empty path and prefix.
  2187. (should
  2188. (string= (org-format-outline-path '() nil ">>")
  2189. ">>"))
  2190. ;; Trailing whitespace in headings.
  2191. (should
  2192. (string= (org-format-outline-path (list "one\t" "tw o " "three "))
  2193. "one/tw o/three"))
  2194. ;; Non-default prefix and separators.
  2195. (should
  2196. (string= (org-format-outline-path (list "one" "two" "three") nil ">>" "|")
  2197. ">>|one|two|three"))
  2198. ;; Truncate.
  2199. (should
  2200. (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
  2201. "one/two/.."))
  2202. ;; Give a very narrow width.
  2203. (should
  2204. (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
  2205. "on"))
  2206. ;; Give a prefix that extends beyond the width.
  2207. (should
  2208. (string= (org-format-outline-path (list "one" "two" "three" "four") 10
  2209. ">>>>>>>>>>")
  2210. ">>>>>>>>..")))
  2211. (ert-deftest test-org/map-entries ()
  2212. "Test `org-map-entries' specifications."
  2213. ;; Full match.
  2214. (should
  2215. (equal '(1 11)
  2216. (org-test-with-temp-text "* Level 1\n** Level 2"
  2217. (org-map-entries #'point))))
  2218. ;; Level match.
  2219. (should
  2220. (equal '(1)
  2221. (org-test-with-temp-text "* Level 1\n** Level 2"
  2222. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL=1")))))
  2223. (should
  2224. (equal '(11)
  2225. (org-test-with-temp-text "* Level 1\n** Level 2"
  2226. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL>1")))))
  2227. ;; Tag match.
  2228. (should
  2229. (equal '(11)
  2230. (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
  2231. (org-map-entries #'point "yes"))))
  2232. (should
  2233. (equal '(14)
  2234. (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
  2235. (org-map-entries #'point "+yes-a"))))
  2236. (should
  2237. (equal '(11 23)
  2238. (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
  2239. (org-map-entries #'point "{yes?}"))))
  2240. ;; Priority match.
  2241. (should
  2242. (equal '(1)
  2243. (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
  2244. (org-map-entries #'point "PRIORITY=\"A\""))))
  2245. ;; Date match.
  2246. (should
  2247. (equal '(36)
  2248. (org-test-with-temp-text "
  2249. * H1
  2250. SCHEDULED: <2012-03-29 thu.>
  2251. * H2
  2252. SCHEDULED: <2014-03-04 tue.>"
  2253. (org-map-entries #'point "SCHEDULED=\"<2014-03-04 tue.>\""))))
  2254. (should
  2255. (equal '(2)
  2256. (org-test-with-temp-text "
  2257. * H1
  2258. SCHEDULED: <2012-03-29 thu.>
  2259. * H2
  2260. SCHEDULED: <2014-03-04 tue.>"
  2261. (org-map-entries #'point "SCHEDULED<\"<2013-01-01>\""))))
  2262. ;; Regular property match.
  2263. (should
  2264. (equal '(2)
  2265. (org-test-with-temp-text "
  2266. * H1
  2267. :PROPERTIES:
  2268. :TEST: 1
  2269. :END:
  2270. * H2
  2271. :PROPERTIES:
  2272. :TEST: 2
  2273. :END:"
  2274. (org-map-entries #'point "TEST=1"))))
  2275. ;; Multiple criteria.
  2276. (should
  2277. (equal '(23)
  2278. (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
  2279. (let (org-odd-levels-only
  2280. (org-use-tag-inheritance nil))
  2281. (org-map-entries #'point "yes+LEVEL=1")))))
  2282. ;; "or" criteria.
  2283. (should
  2284. (equal '(12 24)
  2285. (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
  2286. (let (org-odd-levels-only)
  2287. (org-map-entries #'point "LEVEL=2|no")))))
  2288. (should
  2289. (equal '(1 12)
  2290. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
  2291. (let (org-odd-levels-only)
  2292. (org-map-entries #'point "yes|no")))))
  2293. ;; "and" criteria.
  2294. (should
  2295. (equal '(22)
  2296. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
  2297. (let (org-odd-levels-only)
  2298. (org-map-entries #'point "yes&no"))))))
  2299. (ert-deftest test-org/edit-headline ()
  2300. "Test `org-edit-headline' specifications."
  2301. (should
  2302. (equal "* B"
  2303. (org-test-with-temp-text "* A"
  2304. (org-edit-headline "B")
  2305. (buffer-string))))
  2306. ;; Handle empty headings.
  2307. (should
  2308. (equal "* "
  2309. (org-test-with-temp-text "* A"
  2310. (org-edit-headline "")
  2311. (buffer-string))))
  2312. (should
  2313. (equal "* A"
  2314. (org-test-with-temp-text "* "
  2315. (org-edit-headline "A")
  2316. (buffer-string))))
  2317. ;; Handle TODO keywords and priority cookies.
  2318. (should
  2319. (equal "* TODO B"
  2320. (org-test-with-temp-text "* TODO A"
  2321. (org-edit-headline "B")
  2322. (buffer-string))))
  2323. (should
  2324. (equal "* [#A] B"
  2325. (org-test-with-temp-text "* [#A] A"
  2326. (org-edit-headline "B")
  2327. (buffer-string))))
  2328. (should
  2329. (equal "* TODO [#A] B"
  2330. (org-test-with-temp-text "* TODO [#A] A"
  2331. (org-edit-headline "B")
  2332. (buffer-string))))
  2333. ;; Handle tags.
  2334. (equal "* B :tag:"
  2335. (org-test-with-temp-text "* A :tag:"
  2336. (let ((org-tags-column 4)) (org-edit-headline "B"))
  2337. (buffer-string))))
  2338. ;;; Keywords
  2339. (ert-deftest test-org/set-regexps-and-options ()
  2340. "Test `org-set-regexps-and-options' specifications."
  2341. ;; TAGS keyword.
  2342. (should
  2343. (equal '(("A"))
  2344. (let ((org-tag-alist '(("A")))
  2345. (org-tag-persistent-alist nil))
  2346. (org-test-with-temp-text ""
  2347. (org-mode-restart)
  2348. org-current-tag-alist))))
  2349. (should
  2350. (equal '(("B"))
  2351. (let ((org-tag-alist '(("A")))
  2352. (org-tag-persistent-alist nil))
  2353. (org-test-with-temp-text "#+TAGS: B"
  2354. (org-mode-restart)
  2355. org-current-tag-alist))))
  2356. (should
  2357. (equal '(("C") ("B"))
  2358. (let ((org-tag-alist '(("A")))
  2359. (org-tag-persistent-alist '(("C"))))
  2360. (org-test-with-temp-text "#+TAGS: B"
  2361. (org-mode-restart)
  2362. org-current-tag-alist))))
  2363. (should
  2364. (equal '(("B"))
  2365. (let ((org-tag-alist '(("A")))
  2366. (org-tag-persistent-alist '(("C"))))
  2367. (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
  2368. (org-mode-restart)
  2369. org-current-tag-alist))))
  2370. (should
  2371. (equal '(("A" . ?a) ("B") ("C"))
  2372. (let ((org-tag-persistant-alist nil))
  2373. (org-test-with-temp-text "#+TAGS: A(a) B C"
  2374. (org-mode-restart)
  2375. org-current-tag-alist))))
  2376. (should
  2377. (equal '(("A") (:newline) ("B"))
  2378. (let ((org-tag-persistent-alist nil))
  2379. (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
  2380. (org-mode-restart)
  2381. org-current-tag-alist))))
  2382. (should
  2383. (equal '((:startgroup) ("A") ("B") (:endgroup) ("C"))
  2384. (let ((org-tag-persistent-alist nil))
  2385. (org-test-with-temp-text "#+TAGS: { A B } C"
  2386. (org-mode-restart)
  2387. org-current-tag-alist))))
  2388. (should
  2389. (equal '((:startgroup) ("A") (:grouptags) ("B") ("C") (:endgroup))
  2390. (let ((org-tag-persistent-alist nil))
  2391. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2392. (org-mode-restart)
  2393. org-current-tag-alist))))
  2394. (should
  2395. (equal '(("A" "B" "C"))
  2396. (let ((org-tag-persistent-alist nil))
  2397. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2398. (org-mode-restart)
  2399. org-tag-groups-alist))))
  2400. (should
  2401. (equal '((:startgrouptag) ("A") (:grouptags) ("B") ("C") (:endgrouptag))
  2402. (let ((org-tag-persistent-alist nil))
  2403. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2404. (org-mode-restart)
  2405. org-current-tag-alist))))
  2406. (should
  2407. (equal '(("A" "B" "C"))
  2408. (let ((org-tag-persistent-alist nil))
  2409. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2410. (org-mode-restart)
  2411. org-tag-groups-alist))))
  2412. (should-not
  2413. (let ((org-tag-alist '(("A"))))
  2414. (org-test-with-temp-text "#+TAGS:"
  2415. (org-mode-restart)
  2416. org-current-tag-alist)))
  2417. ;; FILETAGS keyword.
  2418. (should
  2419. (equal '("A" "B" "C")
  2420. (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
  2421. (org-mode-restart)
  2422. org-file-tags)))
  2423. ;; PROPERTY keyword. Property names are case-insensitive.
  2424. (should
  2425. (equal "foo=1"
  2426. (org-test-with-temp-text "#+PROPERTY: var foo=1"
  2427. (org-mode-restart)
  2428. (cdr (assoc "var" org-keyword-properties)))))
  2429. (should
  2430. (equal
  2431. "foo=1 bar=2"
  2432. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
  2433. (org-mode-restart)
  2434. (cdr (assoc "var" org-keyword-properties)))))
  2435. (should
  2436. (equal
  2437. "foo=1 bar=2"
  2438. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
  2439. (org-mode-restart)
  2440. (cdr (assoc "var" org-keyword-properties)))))
  2441. ;; ARCHIVE keyword.
  2442. (should
  2443. (equal "%s_done::"
  2444. (org-test-with-temp-text "#+ARCHIVE: %s_done::"
  2445. (org-mode-restart)
  2446. org-archive-location)))
  2447. ;; CATEGORY keyword.
  2448. (should
  2449. (eq 'test
  2450. (org-test-with-temp-text "#+CATEGORY: test"
  2451. (org-mode-restart)
  2452. org-category)))
  2453. (should
  2454. (equal "test"
  2455. (org-test-with-temp-text "#+CATEGORY: test"
  2456. (org-mode-restart)
  2457. (cdr (assoc "CATEGORY" org-keyword-properties)))))
  2458. ;; COLUMNS keyword.
  2459. (should
  2460. (equal "%25ITEM %TAGS %PRIORITY %TODO"
  2461. (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
  2462. (org-mode-restart)
  2463. org-columns-default-format)))
  2464. ;; CONSTANTS keyword. Constants names are case sensitive.
  2465. (should
  2466. (equal '("299792458." "3.14")
  2467. (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
  2468. (org-mode-restart)
  2469. (mapcar
  2470. (lambda (n) (cdr (assoc n org-table-formula-constants-local)))
  2471. '("c" "pi")))))
  2472. (should
  2473. (equal "3.14"
  2474. (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
  2475. (org-mode-restart)
  2476. (cdr (assoc "pi" org-table-formula-constants-local)))))
  2477. (should
  2478. (equal "22/7"
  2479. (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
  2480. (org-mode-restart)
  2481. (cdr (assoc "PI" org-table-formula-constants-local)))))
  2482. ;; LINK keyword.
  2483. (should
  2484. (equal
  2485. '("url1" "url2")
  2486. (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
  2487. (org-mode-restart)
  2488. (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local)))
  2489. '("a" "b")))))
  2490. ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
  2491. (should
  2492. (equal
  2493. '(?X ?Z ?Y)
  2494. (org-test-with-temp-text "#+PRIORITIES: X Z Y"
  2495. (org-mode-restart)
  2496. (list org-priority-highest org-priority-lowest org-priority-default))))
  2497. (should
  2498. (equal
  2499. '(?A ?C ?B)
  2500. (org-test-with-temp-text "#+PRIORITIES: X Z"
  2501. (org-mode-restart)
  2502. (list org-priority-highest org-priority-lowest org-priority-default))))
  2503. ;; STARTUP keyword.
  2504. (should
  2505. (equal '(t t)
  2506. (org-test-with-temp-text "#+STARTUP: fold odd"
  2507. (org-mode-restart)
  2508. (list org-startup-folded org-odd-levels-only))))
  2509. ;; TODO keywords.
  2510. (should
  2511. (equal '(("A" "B") ("C"))
  2512. (org-test-with-temp-text "#+TODO: A B | C"
  2513. (org-mode-restart)
  2514. (list org-not-done-keywords org-done-keywords))))
  2515. (should
  2516. (equal '(("A" "C") ("B" "D"))
  2517. (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
  2518. (org-mode-restart)
  2519. (list org-not-done-keywords org-done-keywords))))
  2520. (should
  2521. (equal '(("A" "B") ("C"))
  2522. (org-test-with-temp-text "#+TYP_TODO: A B | C"
  2523. (org-mode-restart)
  2524. (list org-not-done-keywords org-done-keywords))))
  2525. (should
  2526. (equal '((:startgroup) ("A" . ?a) (:endgroup))
  2527. (org-test-with-temp-text "#+TODO: A(a)"
  2528. (org-mode-restart)
  2529. org-todo-key-alist)))
  2530. (should
  2531. (equal '(("D" note nil) ("C" time nil) ("B" note time))
  2532. (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
  2533. (org-mode-restart)
  2534. org-todo-log-states)))
  2535. ;; Enter SETUPFILE keyword.
  2536. (should
  2537. (equal "1"
  2538. (org-test-with-temp-text
  2539. (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
  2540. (org-mode-restart)
  2541. (cdr (assoc "a" org-keyword-properties))))))
  2542. ;;; Links
  2543. ;;;; Coderefs
  2544. (ert-deftest test-org/coderef ()
  2545. "Test coderef links specifications."
  2546. (should
  2547. (org-test-with-temp-text "
  2548. #+BEGIN_SRC emacs-lisp
  2549. \(+ 1 1) (ref:sc)
  2550. #+END_SRC
  2551. \[[(sc)<point>]]"
  2552. (org-open-at-point)
  2553. (looking-at "(ref:sc)")))
  2554. ;; Find coderef even with alternate label format.
  2555. (should
  2556. (org-test-with-temp-text "
  2557. #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
  2558. \(+ 1 1) {ref:sc}
  2559. #+END_SRC
  2560. \[[(sc)<point>]]"
  2561. (org-open-at-point)
  2562. (looking-at "{ref:sc}"))))
  2563. ;;;; Custom ID
  2564. (ert-deftest test-org/custom-id ()
  2565. "Test custom ID links specifications."
  2566. (should
  2567. (org-test-with-temp-text
  2568. "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2569. (org-open-at-point)
  2570. (looking-at-p "\\* H1")))
  2571. ;; Handle escape characters.
  2572. (should
  2573. (org-test-with-temp-text
  2574. "* H1\n:PROPERTIES:\n:CUSTOM_ID: [%]\n:END:\n* H2\n[[#\\[%\\]<point>]]"
  2575. (org-open-at-point)
  2576. (looking-at-p "\\* H1")))
  2577. ;; Throw an error on false positives.
  2578. (should-error
  2579. (org-test-with-temp-text
  2580. "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2581. (org-open-at-point)
  2582. (looking-at-p "\\* H1"))))
  2583. ;;;; Fuzzy Links
  2584. ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
  2585. ;; a named element (#+name: text) and to headlines (* Text).
  2586. (ert-deftest test-org/fuzzy-links ()
  2587. "Test fuzzy links specifications."
  2588. ;; Fuzzy link goes in priority to a matching target.
  2589. (should
  2590. (org-test-with-temp-text
  2591. "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
  2592. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2593. (looking-at "<<Test>>")))
  2594. ;; Then fuzzy link points to an element with a given name.
  2595. (should
  2596. (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
  2597. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2598. (looking-at "#\\+NAME: Test")))
  2599. ;; A target still lead to a matching headline otherwise.
  2600. (should
  2601. (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
  2602. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2603. (looking-at "\\* Head2")))
  2604. ;; With a leading star in link, enforce heading match.
  2605. (should
  2606. (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
  2607. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2608. (looking-at "\\* Test")))
  2609. ;; With a leading star in link, enforce exact heading match, even
  2610. ;; with `org-link-search-must-match-exact-headline' set to nil.
  2611. (should-error
  2612. (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
  2613. (let ((org-link-search-must-match-exact-headline nil))
  2614. (org-open-at-point))))
  2615. ;; Handle non-nil `org-link-search-must-match-exact-headline'.
  2616. (should
  2617. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
  2618. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2619. (looking-at "\\* Test")))
  2620. (should
  2621. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
  2622. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2623. (looking-at "\\* Test")))
  2624. ;; Heading match should not care about spaces, cookies, TODO
  2625. ;; keywords, priorities, and tags. However, TODO keywords are
  2626. ;; case-sensitive.
  2627. (should
  2628. (let ((first-line
  2629. "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
  2630. (org-test-with-temp-text
  2631. (concat first-line "\nFoo Bar\n<point>[[*Test 1 2]]")
  2632. (let ((org-link-search-must-match-exact-headline nil)
  2633. (org-todo-regexp "TODO"))
  2634. (org-open-at-point))
  2635. (looking-at (regexp-quote first-line)))))
  2636. (should-error
  2637. (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
  2638. (let ((org-link-search-must-match-exact-headline nil)
  2639. (org-todo-regexp "TODO"))
  2640. (org-open-at-point))))
  2641. ;; Heading match should still be exact.
  2642. (should-error
  2643. (org-test-with-temp-text "
  2644. ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
  2645. Foo Bar
  2646. <point>[[*Test 1]]"
  2647. (let ((org-link-search-must-match-exact-headline nil)
  2648. (org-todo-regexp "TODO"))
  2649. (org-open-at-point))))
  2650. (should
  2651. (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
  2652. (let ((org-link-search-must-match-exact-headline nil)
  2653. (org-todo-regexp "TODO"))
  2654. (org-open-at-point))
  2655. (looking-at-p (regexp-quote "** Test 1 2"))))
  2656. ;; Heading match ignores COMMENT keyword.
  2657. (should
  2658. (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
  2659. (org-open-at-point)
  2660. (looking-at "\\* COMMENT Test")))
  2661. (should
  2662. (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
  2663. (org-open-at-point)
  2664. (looking-at "\\* TODO COMMENT Test")))
  2665. ;; Correctly un-escape fuzzy links.
  2666. (should
  2667. (org-test-with-temp-text "* [foo]\n[[*\\[foo\\]][With escaped characters]]"
  2668. (org-open-at-point)
  2669. (bobp)))
  2670. ;; Match search strings containing newline characters, including
  2671. ;; blank lines.
  2672. (should
  2673. (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
  2674. (let ((file (buffer-file-name)))
  2675. (goto-char (point-max))
  2676. (insert (format "[[file:%s::line1 line2]]" file))
  2677. (beginning-of-line)
  2678. (let ((org-link-search-must-match-exact-headline nil))
  2679. (org-open-at-point 0))
  2680. (looking-at-p "line1"))))
  2681. (should
  2682. (org-test-with-temp-text-in-file "Paragraph\n\nline1\n\nline2\n\n"
  2683. (let ((file (buffer-file-name)))
  2684. (goto-char (point-max))
  2685. (insert (format "[[file:%s::line1 line2]]" file))
  2686. (beginning-of-line)
  2687. (let ((org-link-search-must-match-exact-headline nil))
  2688. (org-open-at-point 0))
  2689. (looking-at-p "line1")))))
  2690. ;;;; Open at point
  2691. (ert-deftest test-org/open-at-point/keyword ()
  2692. "Does `org-open-at-point' open link in a keyword line?"
  2693. (should
  2694. (org-test-with-temp-text
  2695. "<<top>>\n#+KEYWORD: <point>[[top]]"
  2696. (org-open-at-point) t))
  2697. (should
  2698. (org-test-with-temp-text
  2699. "* H\n<<top>>\n#+KEYWORD: <point>[[top]]"
  2700. (org-open-at-point) t)))
  2701. (ert-deftest test-org/open-at-point/property ()
  2702. "Does `org-open-at-point' open link in property drawer?"
  2703. (should
  2704. (org-test-with-temp-text
  2705. "* Headline
  2706. :PROPERTIES:
  2707. :URL: <point>[[*Headline]]
  2708. :END:"
  2709. (org-open-at-point) t)))
  2710. (ert-deftest test-org/open-at-point/comment ()
  2711. "Does `org-open-at-point' open link in a commented line?"
  2712. (should
  2713. (org-test-with-temp-text
  2714. "<<top>>\n# <point>[[top]]"
  2715. (org-open-at-point) t))
  2716. (should
  2717. (org-test-with-temp-text
  2718. "* H\n<<top>>\n# <point>[[top]]"
  2719. (org-open-at-point) t)))
  2720. (ert-deftest test-org/open-at-point/inline-image ()
  2721. "Test `org-open-at-point' on nested links."
  2722. (should
  2723. (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
  2724. (org-open-at-point)
  2725. (bobp))))
  2726. (ert-deftest test-org/open-at-point/radio-target ()
  2727. "Test `org-open-at-point' on radio targets."
  2728. (should
  2729. (org-test-with-temp-text "<<<target>>> <point>target"
  2730. (org-update-radio-target-regexp)
  2731. (org-open-at-point)
  2732. (eq (org-element-type (org-element-context)) 'radio-target))))
  2733. (ert-deftest test-org/open-at-point/tag ()
  2734. "Test `org-open-at-point' on tags."
  2735. (should
  2736. (org-test-with-temp-text "* H :<point>tag:"
  2737. (catch :result
  2738. (cl-letf (((symbol-function 'org-tags-view)
  2739. (lambda (&rest args) (throw :result t))))
  2740. (org-open-at-point)
  2741. nil))))
  2742. (should-not
  2743. (org-test-with-temp-text-in-file "* H<point> :tag:"
  2744. (catch :result
  2745. (cl-letf (((symbol-function 'org-tags-view)
  2746. (lambda (&rest args) (throw :result t))))
  2747. ;; When point isn't on a tag it's going to try other things,
  2748. ;; possibly trying to open attachments which will return an
  2749. ;; error if there isn't an attachment. Suppress that error.
  2750. (ignore-errors
  2751. (org-open-at-point))
  2752. nil)))))
  2753. ;;; Node Properties
  2754. (ert-deftest test-org/accumulated-properties-in-drawers ()
  2755. "Ensure properties accumulate in subtree drawers."
  2756. (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
  2757. (org-babel-next-src-block)
  2758. (should (equal '(2 1) (org-babel-execute-src-block)))))
  2759. (ert-deftest test-org/custom-properties ()
  2760. "Test custom properties specifications."
  2761. ;; Standard test.
  2762. (should
  2763. (let ((org-custom-properties '("FOO")))
  2764. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2765. (org-toggle-custom-properties-visibility)
  2766. (org-invisible-p2))))
  2767. ;; Properties are case-insensitive.
  2768. (should
  2769. (let ((org-custom-properties '("FOO")))
  2770. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
  2771. (org-toggle-custom-properties-visibility)
  2772. (org-invisible-p2))))
  2773. (should
  2774. (let ((org-custom-properties '("foo")))
  2775. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2776. (org-toggle-custom-properties-visibility)
  2777. (org-invisible-p2))))
  2778. ;; Multiple custom properties in the same drawer.
  2779. (should
  2780. (let ((org-custom-properties '("FOO" "BAR")))
  2781. (org-test-with-temp-text
  2782. "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
  2783. (org-toggle-custom-properties-visibility)
  2784. (and (org-invisible-p2)
  2785. (not (progn (forward-line) (org-invisible-p2)))
  2786. (progn (forward-line) (org-invisible-p2))))))
  2787. ;; Hide custom properties with an empty value.
  2788. (should
  2789. (let ((org-custom-properties '("FOO")))
  2790. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
  2791. (org-toggle-custom-properties-visibility)
  2792. (org-invisible-p2))))
  2793. ;; Do not hide fake properties.
  2794. (should-not
  2795. (let ((org-custom-properties '("FOO")))
  2796. (org-test-with-temp-text ":FOO: val\n"
  2797. (org-toggle-custom-properties-visibility)
  2798. (org-invisible-p2))))
  2799. (should-not
  2800. (let ((org-custom-properties '("A")))
  2801. (org-test-with-temp-text
  2802. "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
  2803. (org-toggle-custom-properties-visibility)
  2804. (org-invisible-p2)))))
  2805. ;;; Mark Region
  2806. (ert-deftest test-org/mark-element ()
  2807. "Test `org-mark-element' specifications."
  2808. ;; Mark beginning and end of element.
  2809. (should
  2810. (equal '(t t)
  2811. (org-test-with-temp-text "Para<point>graph"
  2812. (org-mark-element)
  2813. (list (bobp) (= (mark) (point-max))))))
  2814. (should
  2815. (equal '(t t)
  2816. (org-test-with-temp-text "P1\n\nPara<point>graph\n\nP2"
  2817. (org-mark-element)
  2818. (list (looking-at "Paragraph")
  2819. (org-with-point-at (mark) (looking-at "P2"))))))
  2820. ;; Do not set mark past (point-max).
  2821. (should
  2822. (org-test-with-temp-text "Para<point>graph"
  2823. (narrow-to-region 2 6)
  2824. (org-mark-element)
  2825. (= 6 (mark)))))
  2826. (ert-deftest test-org/mark-subtree ()
  2827. "Test `org-mark-subtree' specifications."
  2828. ;; Error when point is before first headline.
  2829. (should-error
  2830. (org-test-with-temp-text "Paragraph\n* Headline\nBody"
  2831. (progn (transient-mark-mode 1)
  2832. (org-mark-subtree))))
  2833. ;; Without argument, mark current subtree.
  2834. (should
  2835. (equal
  2836. '(12 32)
  2837. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  2838. (progn (transient-mark-mode 1)
  2839. (forward-line 2)
  2840. (org-mark-subtree)
  2841. (list (region-beginning) (region-end))))))
  2842. ;; With an argument, move ARG up.
  2843. (should
  2844. (equal
  2845. '(1 32)
  2846. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  2847. (progn (transient-mark-mode 1)
  2848. (forward-line 2)
  2849. (org-mark-subtree 1)
  2850. (list (region-beginning) (region-end))))))
  2851. ;; Do not get fooled by inlinetasks.
  2852. (when (featurep 'org-inlinetask)
  2853. (should
  2854. (= 1
  2855. (org-test-with-temp-text "* Headline\n*************** Task\nContents"
  2856. (progn (transient-mark-mode 1)
  2857. (forward-line 1)
  2858. (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
  2859. (region-beginning)))))))
  2860. ;;; Miscellaneous
  2861. (ert-deftest test-org/sort-entries ()
  2862. "Test `org-sort-entries'."
  2863. ;; Sort alphabetically.
  2864. (should
  2865. (equal "\n* abc\n* def\n* xyz\n"
  2866. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  2867. (org-sort-entries nil ?a)
  2868. (buffer-string))))
  2869. (should
  2870. (equal "\n* xyz\n* def\n* abc\n"
  2871. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  2872. (org-sort-entries nil ?A)
  2873. (buffer-string))))
  2874. (should
  2875. (equal "\n* \n* klm\n* xyz\n"
  2876. (org-test-with-temp-text "\n* xyz\n* \n* klm\n"
  2877. (org-sort-entries nil ?a)
  2878. (buffer-string))))
  2879. ;; Sort numerically.
  2880. (should
  2881. (equal "\n* 1\n* 2\n* 10\n"
  2882. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  2883. (org-sort-entries nil ?n)
  2884. (buffer-string))))
  2885. (should
  2886. (equal "\n* 10\n* 2\n* 1\n"
  2887. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  2888. (org-sort-entries nil ?N)
  2889. (buffer-string))))
  2890. (should
  2891. (equal "\n* \n* 1\n* 2\n"
  2892. (org-test-with-temp-text "\n* 1\n* \n* 2\n"
  2893. (org-sort-entries nil ?n)
  2894. (buffer-string))))
  2895. ;; Sort by custom function.
  2896. (should
  2897. (equal "\n* b\n* aa\n* ccc\n"
  2898. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  2899. (org-sort-entries nil ?f
  2900. (lambda ()
  2901. (length (buffer-substring (point-at-bol)
  2902. (point-at-eol))))
  2903. #'<)
  2904. (buffer-string))))
  2905. (should
  2906. (equal "\n* ccc\n* aa\n* b\n"
  2907. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  2908. (org-sort-entries nil ?F
  2909. (lambda ()
  2910. (length (buffer-substring (point-at-bol)
  2911. (point-at-eol))))
  2912. #'<)
  2913. (buffer-string))))
  2914. ;; Sort by TODO keyword.
  2915. (should
  2916. (equal "\n* TODO h1\n* TODO h3\n* DONE h2\n"
  2917. (org-test-with-temp-text
  2918. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  2919. (org-sort-entries nil ?o)
  2920. (buffer-string))))
  2921. (should
  2922. (equal "\n* DONE h2\n* TODO h1\n* TODO h3\n"
  2923. (org-test-with-temp-text
  2924. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  2925. (org-sort-entries nil ?O)
  2926. (buffer-string))))
  2927. ;; Sort by priority.
  2928. (should
  2929. (equal "\n* [#A] h2\n* [#B] h3\n* [#C] h1\n"
  2930. (org-test-with-temp-text
  2931. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  2932. (org-sort-entries nil ?p)
  2933. (buffer-string))))
  2934. (should
  2935. (equal "\n* [#C] h1\n* [#B] h3\n* [#A] h2\n"
  2936. (org-test-with-temp-text
  2937. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  2938. (org-sort-entries nil ?P)
  2939. (buffer-string))))
  2940. ;; Sort by creation time.
  2941. (should
  2942. (equal "
  2943. * h3
  2944. [2017-05-08 Mon]
  2945. * h2
  2946. [2017-05-09 Tue]
  2947. * h1
  2948. [2018-05-09 Wed]
  2949. "
  2950. (org-test-with-temp-text
  2951. "
  2952. * h1
  2953. [2018-05-09 Wed]
  2954. * h2
  2955. [2017-05-09 Tue]
  2956. * h3
  2957. [2017-05-08 Mon]
  2958. "
  2959. (org-sort-entries nil ?c)
  2960. (buffer-string))))
  2961. ;; Sort by scheduled date.
  2962. (should
  2963. (equal "
  2964. * TODO h4
  2965. SCHEDULED: <2017-05-06 Sat>
  2966. * TODO h3
  2967. SCHEDULED: <2017-05-08 Mon>
  2968. * TODO h2
  2969. DEADLINE: <2017-05-09 Tue>
  2970. * TODO h1
  2971. DEADLINE: <2017-05-07 Sun>
  2972. "
  2973. (org-test-with-temp-text
  2974. "
  2975. * TODO h2
  2976. DEADLINE: <2017-05-09 Tue>
  2977. * TODO h1
  2978. DEADLINE: <2017-05-07 Sun>
  2979. * TODO h3
  2980. SCHEDULED: <2017-05-08 Mon>
  2981. * TODO h4
  2982. SCHEDULED: <2017-05-06 Sat>
  2983. "
  2984. (org-sort-entries nil ?s)
  2985. (buffer-string))))
  2986. ;; Sort by deadline date.
  2987. (should
  2988. (equal "
  2989. * TODO h1
  2990. DEADLINE: <2017-05-07 Sun>
  2991. * TODO h2
  2992. DEADLINE: <2017-05-09 Tue>
  2993. * TODO h3
  2994. SCHEDULED: <2017-05-08 Mon>
  2995. * TODO h4
  2996. SCHEDULED: <2017-05-06 Sat>
  2997. "
  2998. (org-test-with-temp-text
  2999. "
  3000. * TODO h2
  3001. DEADLINE: <2017-05-09 Tue>
  3002. * TODO h1
  3003. DEADLINE: <2017-05-07 Sun>
  3004. * TODO h3
  3005. SCHEDULED: <2017-05-08 Mon>
  3006. * TODO h4
  3007. SCHEDULED: <2017-05-06 Sat>
  3008. "
  3009. (org-sort-entries nil ?d)
  3010. (buffer-string))))
  3011. ;; Sort by any date/time
  3012. (should
  3013. (equal "
  3014. * TODO h4
  3015. SCHEDULED: <2017-05-06 Sat>
  3016. * TODO h1
  3017. DEADLINE: <2017-05-07 Sun>
  3018. * TODO h3
  3019. SCHEDULED: <2017-05-08 Mon>
  3020. * TODO h2
  3021. DEADLINE: <2017-05-09 Tue>
  3022. "
  3023. (org-test-with-temp-text
  3024. "
  3025. * TODO h2
  3026. DEADLINE: <2017-05-09 Tue>
  3027. * TODO h1
  3028. DEADLINE: <2017-05-07 Sun>
  3029. * TODO h3
  3030. SCHEDULED: <2017-05-08 Mon>
  3031. * TODO h4
  3032. SCHEDULED: <2017-05-06 Sat>
  3033. "
  3034. (org-sort-entries nil ?t)
  3035. (buffer-string))))
  3036. ;; Sort by clocking time.
  3037. (should
  3038. (equal "
  3039. * clocked h2
  3040. :LOGBOOK:
  3041. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3042. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  3043. :END:
  3044. * clocked h1
  3045. :LOGBOOK:
  3046. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3047. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  3048. :END:
  3049. "
  3050. (org-test-with-temp-text
  3051. "
  3052. * clocked h1
  3053. :LOGBOOK:
  3054. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3055. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  3056. :END:
  3057. * clocked h2
  3058. :LOGBOOK:
  3059. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3060. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  3061. :END:
  3062. "
  3063. (org-sort-entries nil ?k)
  3064. (buffer-string))))
  3065. ;; Preserve file local variables when sorting.
  3066. (should
  3067. (equal "\n* A\n* B\n# Local Variables:\n# foo: t\n# End:\n"
  3068. (org-test-with-temp-text
  3069. "\n* B\n* A\n# Local Variables:\n# foo: t\n# End:"
  3070. (org-sort-entries nil ?a)
  3071. (buffer-string)))))
  3072. (ert-deftest test-org/string-collate-greaterp ()
  3073. "Test `org-string-collate-greaterp' specifications."
  3074. (should (org-string-collate-greaterp "def" "abc"))
  3075. (should-not (org-string-collate-greaterp "abc" "def")))
  3076. (ert-deftest test-org/file-contents ()
  3077. "Test `org-file-contents' specifications."
  3078. ;; Open files.
  3079. (should
  3080. (string= "#+BIND: variable value
  3081. #+DESCRIPTION: l2
  3082. #+LANGUAGE: en
  3083. #+SELECT_TAGS: b
  3084. #+TITLE: b
  3085. #+PROPERTY: a 1
  3086. " (org-file-contents (expand-file-name "setupfile3.org"
  3087. (concat org-test-dir "examples/")))))
  3088. ;; Throw error when trying to access an invalid file.
  3089. (should-error (org-file-contents "this-file-must-not-exist"))
  3090. ;; Try to access an invalid file, but do not throw an error.
  3091. (should
  3092. (progn (org-file-contents "this-file-must-not-exist" :noerror) t))
  3093. ;; Open URL.
  3094. (should
  3095. (string= "foo"
  3096. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3097. (unwind-protect
  3098. ;; Simulate successful retrieval of a URL.
  3099. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3100. (lambda (&rest_)
  3101. (with-current-buffer buffer
  3102. (insert "HTTP/1.1 200 OK\n\nfoo"))
  3103. buffer)))
  3104. (org-file-contents "http://some-valid-url"))
  3105. (kill-buffer buffer)))))
  3106. ;; Throw error when trying to access an invalid URL.
  3107. (should-error
  3108. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3109. (unwind-protect
  3110. ;; Simulate unsuccessful retrieval of a URL.
  3111. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3112. (lambda (&rest_)
  3113. (with-current-buffer buffer
  3114. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3115. buffer)))
  3116. (org-file-contents "http://this-url-must-not-exist"))
  3117. (kill-buffer buffer))))
  3118. ;; Try to access an invalid URL, but do not throw an error.
  3119. (should-error
  3120. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3121. (unwind-protect
  3122. ;; Simulate unsuccessful retrieval of a URL.
  3123. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3124. (lambda (&rest_)
  3125. (with-current-buffer buffer
  3126. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3127. buffer)))
  3128. (org-file-contents "http://this-url-must-not-exist"))
  3129. (kill-buffer buffer))))
  3130. (should
  3131. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3132. (unwind-protect
  3133. ;; Simulate unsuccessful retrieval of a URL.
  3134. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3135. (lambda (&rest_)
  3136. (with-current-buffer buffer
  3137. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3138. buffer)))
  3139. (org-file-contents "http://this-url-must-not-exist" :noerror))
  3140. (kill-buffer buffer))
  3141. t)))
  3142. ;;; Navigation
  3143. (ert-deftest test-org/next-visible-heading ()
  3144. "Test `org-next-visible-heading' specifications."
  3145. ;; Move to the beginning of the next headline, taking into
  3146. ;; consideration ARG.
  3147. (should
  3148. (org-test-with-temp-text "* H1\n* H2"
  3149. (org-next-visible-heading 1)
  3150. (looking-at "\\* H2")))
  3151. (should
  3152. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3153. (org-next-visible-heading 2)
  3154. (looking-at "\\* H3")))
  3155. ;; Ignore invisible headlines.
  3156. (should
  3157. (org-test-with-temp-text "* H1\n** H2\n* H3"
  3158. (org-cycle)
  3159. (org-next-visible-heading 1)
  3160. (looking-at "\\* H3")))
  3161. ;; Move point between headlines, not on blank lines between.
  3162. (should
  3163. (org-test-with-temp-text "* H1\n** H2\n\n\n\n* H3"
  3164. (let ((org-cycle-separator-lines 1))
  3165. (org-cycle)
  3166. (org-next-visible-heading 1))
  3167. (looking-at "\\* H3")))
  3168. ;; Move at end of buffer when there is no more headline.
  3169. (should
  3170. (org-test-with-temp-text "* H1"
  3171. (org-next-visible-heading 1)
  3172. (eobp)))
  3173. (should
  3174. (org-test-with-temp-text "* H1\n* H2"
  3175. (org-next-visible-heading 2)
  3176. (eobp)))
  3177. ;; With a negative argument, move backwards.
  3178. (should
  3179. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3180. (org-next-visible-heading -1)
  3181. (looking-at "\\* H2")))
  3182. (should
  3183. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3184. (org-next-visible-heading -2)
  3185. (looking-at "\\* H1"))))
  3186. (ert-deftest test-org/previous-visible-heading ()
  3187. "Test `org-previous-visible-heading' specifications."
  3188. ;; Move to the beginning of the next headline, taking into
  3189. ;; consideration ARG.
  3190. (should
  3191. (org-test-with-temp-text "* H1\n<point>* H2"
  3192. (org-previous-visible-heading 1)
  3193. (looking-at "\\* H1")))
  3194. (should
  3195. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3196. (org-previous-visible-heading 2)
  3197. (looking-at "\\* H1")))
  3198. ;; Ignore invisible headlines.
  3199. (should
  3200. (org-test-with-temp-text "* H1\n** H2\n<point>* H3"
  3201. (org-overview)
  3202. (org-previous-visible-heading 1)
  3203. (looking-at "\\* H1")))
  3204. ;; Move point between headlines, not on blank lines between.
  3205. (should
  3206. (org-test-with-temp-text "* H1\n\n\n\n** H2\n<point>* H3"
  3207. (let ((org-cycle-separator-lines 1))
  3208. (org-overview)
  3209. (org-previous-visible-heading 1))
  3210. (looking-at "\\* H1")))
  3211. ;; Move at end of buffer when there is no more headline.
  3212. (should
  3213. (org-test-with-temp-text "* H1"
  3214. (org-previous-visible-heading 1)
  3215. (bobp)))
  3216. (should
  3217. (org-test-with-temp-text "* H1\n* <point>H2"
  3218. (org-previous-visible-heading 2)
  3219. (bobp)))
  3220. ;; Invisible parts may not start at a headline, i.e., when revealing
  3221. ;; parts of the buffer. Handle this.
  3222. (should
  3223. (org-test-with-temp-text "* Main\n** H1\nFoo\n** H2\nBar\n** H3\nBaz"
  3224. (org-overview)
  3225. (search-forward "H1")
  3226. (org-show-context 'minimal)
  3227. (org-cycle)
  3228. (search-forward "H3")
  3229. (org-show-context 'minimal)
  3230. ;; At this point, buffer displays, with point at "|",
  3231. ;;
  3232. ;; * Main
  3233. ;; ** H1
  3234. ;; Foo
  3235. ;; ** H3|
  3236. (org-previous-visible-heading 1)
  3237. (looking-at "\\*+ H1"))))
  3238. (ert-deftest test-org/forward-heading-same-level ()
  3239. "Test `org-forward-heading-same-level' specifications."
  3240. ;; Test navigation at top level, forward and backward.
  3241. (should
  3242. (equal "* H2"
  3243. (org-test-with-temp-text "* H1\n* H2"
  3244. (org-forward-heading-same-level 1)
  3245. (buffer-substring-no-properties (point) (line-end-position)))))
  3246. (should
  3247. (equal "* H1"
  3248. (org-test-with-temp-text "* H1\n<point>* H2"
  3249. (org-forward-heading-same-level -1)
  3250. (buffer-substring-no-properties (point) (line-end-position)))))
  3251. ;; Test navigation in a sub-tree, forward and backward.
  3252. (should
  3253. (equal "* H2"
  3254. (org-test-with-temp-text "* H1\n** H11\n** H12\n* H2"
  3255. (org-forward-heading-same-level 1)
  3256. (buffer-substring-no-properties (point) (line-end-position)))))
  3257. (should
  3258. (equal "* H1"
  3259. (org-test-with-temp-text "* H1\n** H11\n** H12\n<point>* H2"
  3260. (org-forward-heading-same-level -1)
  3261. (buffer-substring-no-properties (point) (line-end-position)))))
  3262. ;; Stop at first or last sub-heading.
  3263. (should-not
  3264. (equal "* H2"
  3265. (org-test-with-temp-text "* H1\n** H11\n<point>** H12\n* H2"
  3266. (org-forward-heading-same-level 1)
  3267. (buffer-substring-no-properties (point) (line-end-position)))))
  3268. (should-not
  3269. (equal "* H2"
  3270. (org-test-with-temp-text "* H1\n<point>** H11\n** H12\n* H2"
  3271. (org-forward-heading-same-level -1)
  3272. (buffer-substring-no-properties (point) (line-end-position)))))
  3273. ;; Allow multiple moves.
  3274. (should
  3275. (equal "* H3"
  3276. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3277. (org-forward-heading-same-level 2)
  3278. (buffer-substring-no-properties (point) (line-end-position)))))
  3279. (should
  3280. (equal "* H1"
  3281. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3282. (org-forward-heading-same-level -2)
  3283. (buffer-substring-no-properties (point) (line-end-position)))))
  3284. ;; Ignore spurious moves when first (or last) sibling is reached.
  3285. (should
  3286. (equal "** H3"
  3287. (org-test-with-temp-text "* First\n<point>** H1\n** H2\n** H3\n* Last"
  3288. (org-forward-heading-same-level 100)
  3289. (buffer-substring-no-properties (point) (line-end-position)))))
  3290. (should
  3291. (equal "** H1"
  3292. (org-test-with-temp-text "* First\n** H1\n** H2\n<point>** H3\n* Last"
  3293. (org-forward-heading-same-level -100)
  3294. (buffer-substring-no-properties (point) (line-end-position))))))
  3295. (ert-deftest test-org/end-of-meta-data ()
  3296. "Test `org-end-of-meta-data' specifications."
  3297. ;; Skip planning line.
  3298. (should
  3299. (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
  3300. (org-end-of-meta-data)
  3301. (eobp)))
  3302. ;; Skip properties drawer.
  3303. (should
  3304. (org-test-with-temp-text
  3305. "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
  3306. (org-end-of-meta-data)
  3307. (eobp)))
  3308. ;; Skip both.
  3309. (should
  3310. (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
  3311. (org-end-of-meta-data)
  3312. (eobp)))
  3313. ;; Nothing to skip, go to first line.
  3314. (should
  3315. (org-test-with-temp-text "* Headline\nContents"
  3316. (org-end-of-meta-data)
  3317. (looking-at "Contents")))
  3318. ;; With option argument, skip empty lines, regular drawers and
  3319. ;; clocking lines.
  3320. (should
  3321. (org-test-with-temp-text "* Headline\n\nContents"
  3322. (org-end-of-meta-data t)
  3323. (looking-at "Contents")))
  3324. (should
  3325. (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
  3326. (org-end-of-meta-data t)
  3327. (looking-at "Contents")))
  3328. (should
  3329. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
  3330. (org-end-of-meta-data t)
  3331. (looking-at "Contents")))
  3332. ;; Special case: do not skip incomplete drawers.
  3333. (should
  3334. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
  3335. (org-end-of-meta-data t)
  3336. (looking-at ":LOGBOOK:")))
  3337. ;; Special case: Be careful about consecutive headlines.
  3338. (should-not
  3339. (org-test-with-temp-text "* H1\n*H2\nContents"
  3340. (org-end-of-meta-data t)
  3341. (looking-at "Contents"))))
  3342. (ert-deftest test-org/shiftright-heading ()
  3343. "Test `org-shiftright' on headings."
  3344. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  3345. (should
  3346. (equal "* TODO a1\n** a2\n* DONE b1\n"
  3347. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3348. (org-shiftright)
  3349. (buffer-string))))
  3350. (should
  3351. (equal "* TODO a1\n** TODO a2\n* b1\n"
  3352. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3353. (let ((org-loop-over-headlines-in-active-region t))
  3354. (transient-mark-mode 1)
  3355. (push-mark (point) t t)
  3356. (search-forward "* DONE b1")
  3357. (org-shiftright))
  3358. (buffer-string))))
  3359. (should
  3360. (equal "* TODO a1\n** a2\n* b1\n"
  3361. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3362. (let ((org-loop-over-headlines-in-active-region 'start-level))
  3363. (transient-mark-mode 1)
  3364. (push-mark (point) t t)
  3365. (search-forward "* DONE b1")
  3366. (org-shiftright))
  3367. (buffer-string))))))
  3368. (ert-deftest test-org/beginning-of-line ()
  3369. "Test `org-beginning-of-line' specifications."
  3370. ;; Move to beginning of line. If current line in invisible, move to
  3371. ;; beginning of visible line instead.
  3372. (should
  3373. (org-test-with-temp-text "Some text\nSome other text<point>"
  3374. (org-beginning-of-line)
  3375. (bolp)))
  3376. (should
  3377. (org-test-with-temp-text "* H1\n** H2<point>"
  3378. (org-overview)
  3379. (org-beginning-of-line)
  3380. (= (line-beginning-position) 1)))
  3381. ;; With `visual-line-mode' active, move to beginning of visual line.
  3382. (should-not
  3383. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3384. (visual-line-mode)
  3385. (dotimes (i 1000) (insert "very "))
  3386. (org-beginning-of-line)
  3387. (bolp)))
  3388. ;; In a wide headline, with `visual-line-mode', prefer going to the
  3389. ;; beginning of a visual line than to the logical beginning of line,
  3390. ;; even if special movement is active.
  3391. (should-not
  3392. (org-test-with-temp-text "* A <point>long headline"
  3393. (visual-line-mode)
  3394. (dotimes (i 1000) (insert "very "))
  3395. (goto-char (point-max))
  3396. (org-beginning-of-line)
  3397. (bobp)))
  3398. (should-not
  3399. (org-test-with-temp-text "* A <point>long headline"
  3400. (visual-line-mode)
  3401. (dotimes (i 1000) (insert "very "))
  3402. (goto-char (point-max))
  3403. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line))
  3404. (bobp)))
  3405. ;; At an headline with special movement, first move at beginning of
  3406. ;; title, then at the beginning of line, rinse, repeat.
  3407. (should
  3408. (org-test-with-temp-text "* TODO Headline<point>"
  3409. (let ((org-special-ctrl-a/e t))
  3410. (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
  3411. (progn (org-beginning-of-line) (bolp))
  3412. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3413. (should
  3414. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3415. (let ((org-special-ctrl-a/e t))
  3416. (org-beginning-of-line)
  3417. (looking-at "Headline"))))
  3418. (should
  3419. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3420. (let ((org-special-ctrl-a/e '(t . nil)))
  3421. (org-beginning-of-line)
  3422. (looking-at "Headline"))))
  3423. (should-not
  3424. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3425. (let ((org-special-ctrl-a/e '(nil . nil)))
  3426. (org-beginning-of-line)
  3427. (looking-at "Headline"))))
  3428. ;; At an headline with reversed movement, first move to beginning of
  3429. ;; line, then to the beginning of title.
  3430. (should
  3431. (org-test-with-temp-text "* TODO Headline<point>"
  3432. (let ((org-special-ctrl-a/e 'reversed)
  3433. (this-command last-command))
  3434. (and (progn (org-beginning-of-line) (bolp))
  3435. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3436. (should
  3437. (org-test-with-temp-text "* TODO Headline<point>"
  3438. (let ((org-special-ctrl-a/e '(reversed . nil))
  3439. (this-command last-command))
  3440. (and (progn (org-beginning-of-line) (bolp))
  3441. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3442. (should-not
  3443. (org-test-with-temp-text "* TODO Headline<point>"
  3444. (let ((org-special-ctrl-a/e '(t . nil))
  3445. (this-command last-command))
  3446. (and (progn (org-beginning-of-line) (bolp))
  3447. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3448. ;; At an item with special movement, first move after to beginning
  3449. ;; of title, then to the beginning of line, rinse, repeat.
  3450. (should
  3451. (org-test-with-temp-text "- [ ] Item<point>"
  3452. (let ((org-special-ctrl-a/e t))
  3453. (and (progn (org-beginning-of-line) (looking-at-p "Item"))
  3454. (progn (org-beginning-of-line) (bolp))
  3455. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3456. ;; At an item with reversed movement, first move to beginning of
  3457. ;; line, then to the beginning of title.
  3458. (should
  3459. (org-test-with-temp-text "- [X] Item<point>"
  3460. (let ((org-special-ctrl-a/e 'reversed)
  3461. (this-command last-command))
  3462. (and (progn (org-beginning-of-line) (bolp))
  3463. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3464. ;; Leave point before invisible characters at column 0.
  3465. (should
  3466. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3467. (let ((org-special-ctrl-a/e nil))
  3468. (org-beginning-of-line)
  3469. (bolp))))
  3470. (should
  3471. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3472. (let ((org-special-ctrl-a/e t))
  3473. (org-beginning-of-line)
  3474. (bolp))))
  3475. (should
  3476. (org-test-with-temp-text "[[http<point>://orgmode.org]]"
  3477. (visual-line-mode)
  3478. (org-beginning-of-line)
  3479. (bolp)))
  3480. ;; Special case: Do not error when the buffer contains only a single
  3481. ;; asterisk.
  3482. (should
  3483. (org-test-with-temp-text "*<point>"
  3484. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line) t)))
  3485. (should
  3486. (org-test-with-temp-text "*<point>"
  3487. (let ((org-special-ctrl-a/e nil)) (org-beginning-of-line) t))))
  3488. (ert-deftest test-org/end-of-line ()
  3489. "Test `org-end-of-line' specifications."
  3490. ;; Standard test.
  3491. (should
  3492. (org-test-with-temp-text "Some text\nSome other text"
  3493. (org-end-of-line)
  3494. (eolp)))
  3495. ;; With `visual-line-mode' active, move to end of visible line.
  3496. ;; However, never go past ellipsis.
  3497. (should-not
  3498. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3499. (visual-line-mode)
  3500. (dotimes (i 1000) (insert "very "))
  3501. (goto-char (point-min))
  3502. (org-end-of-line)
  3503. (eolp)))
  3504. (should-not
  3505. (org-test-with-temp-text "* A short headline\nSome contents"
  3506. (visual-line-mode)
  3507. (org-overview)
  3508. (org-end-of-line)
  3509. (eobp)))
  3510. ;; In a wide headline, with `visual-line-mode', prefer going to end
  3511. ;; of visible line if tags, or end of line, are farther.
  3512. (should-not
  3513. (org-test-with-temp-text "* A <point>long headline"
  3514. (visual-line-mode)
  3515. (dotimes (i 1000) (insert "very "))
  3516. (goto-char (point-min))
  3517. (org-end-of-line)
  3518. (eolp)))
  3519. (should-not
  3520. (org-test-with-temp-text "* A <point>long headline :tag:"
  3521. (visual-line-mode)
  3522. (dotimes (i 1000) (insert "very "))
  3523. (goto-char (point-min))
  3524. (org-end-of-line)
  3525. (eolp)))
  3526. ;; At an headline without special movement, go to end of line.
  3527. ;; However, never go past ellipsis.
  3528. (should
  3529. (org-test-with-temp-text "* Headline2b :tag:\n"
  3530. (let ((org-special-ctrl-a/e nil))
  3531. (and (progn (org-end-of-line) (eolp))
  3532. (progn (org-end-of-line) (eolp))))))
  3533. (should
  3534. (org-test-with-temp-text "* Headline2b :tag:\n"
  3535. (let ((org-special-ctrl-a/e '(t . nil)))
  3536. (and (progn (org-end-of-line) (eolp))
  3537. (progn (org-end-of-line) (eolp))))))
  3538. (should
  3539. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3540. (org-overview)
  3541. (let ((org-special-ctrl-a/e nil))
  3542. (org-end-of-line)
  3543. (= 1 (line-beginning-position)))))
  3544. ;; At an headline with special movement, first move before tags,
  3545. ;; then at the end of line, rinse, repeat. However, never go past
  3546. ;; ellipsis.
  3547. (should
  3548. (org-test-with-temp-text "* Headline1 :tag:\n"
  3549. (let ((org-special-ctrl-a/e t))
  3550. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3551. (progn (org-end-of-line) (eolp))
  3552. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3553. (should
  3554. (org-test-with-temp-text "* Headline1 :tag:\n"
  3555. (let ((org-special-ctrl-a/e '(nil . t)))
  3556. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3557. (progn (org-end-of-line) (eolp))
  3558. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3559. (should-not
  3560. (org-test-with-temp-text "* Headline1 :tag:\n"
  3561. (let ((org-special-ctrl-a/e '(nil . nil)))
  3562. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3563. (progn (org-end-of-line) (eolp))
  3564. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3565. (should
  3566. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3567. (org-overview)
  3568. (let ((org-special-ctrl-a/e t))
  3569. (org-end-of-line)
  3570. (org-end-of-line)
  3571. (= 1 (line-beginning-position)))))
  3572. ;; At an headline, with reversed movement, first go to end of line,
  3573. ;; then before tags. However, never go past ellipsis.
  3574. (should
  3575. (org-test-with-temp-text "* Headline3 :tag:\n"
  3576. (let ((org-special-ctrl-a/e 'reversed)
  3577. (this-command last-command))
  3578. (and (progn (org-end-of-line) (eolp))
  3579. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3580. (should
  3581. (org-test-with-temp-text "* Headline3 :tag:\n"
  3582. (let ((org-special-ctrl-a/e '(nil . reversed))
  3583. (this-command last-command))
  3584. (and (progn (org-end-of-line) (eolp))
  3585. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3586. (should-not
  3587. (org-test-with-temp-text "* Headline3 :tag:\n"
  3588. (let ((org-special-ctrl-a/e '(nil . t))
  3589. (this-command last-command))
  3590. (and (progn (org-end-of-line) (eolp))
  3591. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3592. (should
  3593. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3594. (org-overview)
  3595. (let ((org-special-ctrl-a/e 'reversed))
  3596. (org-end-of-line)
  3597. (= 1 (line-beginning-position)))))
  3598. ;; At a block without hidden contents.
  3599. (should
  3600. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3601. (progn (org-end-of-line) (eolp))))
  3602. ;; At a block with hidden contents.
  3603. (should-not
  3604. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3605. (let ((org-special-ctrl-a/e t))
  3606. (org-hide-block-toggle)
  3607. (org-end-of-line)
  3608. (eobp))))
  3609. ;; Get past invisible characters at the end of line.
  3610. (should
  3611. (org-test-with-temp-text "[[https://orgmode.org]]"
  3612. (org-end-of-line)
  3613. (eolp))))
  3614. (ert-deftest test-org/open-line ()
  3615. "Test `org-open-line' specifications."
  3616. ;; Call `open-line' outside of tables.
  3617. (should
  3618. (equal "\nText"
  3619. (org-test-with-temp-text "Text"
  3620. (org-open-line 1)
  3621. (buffer-string))))
  3622. ;; At a table, create a row above.
  3623. (should
  3624. (equal "\n| |\n| a |"
  3625. (org-test-with-temp-text "\n<point>| a |"
  3626. (org-open-line 1)
  3627. (buffer-string))))
  3628. ;; At the very first character of the buffer, also call `open-line'.
  3629. (should
  3630. (equal "\n| a |"
  3631. (org-test-with-temp-text "| a |"
  3632. (org-open-line 1)
  3633. (buffer-string))))
  3634. ;; Narrowing does not count.
  3635. (should
  3636. (equal "Text\n| |\n| a |"
  3637. (org-test-with-temp-text "Text\n<point>| a |"
  3638. (narrow-to-region (point) (point-max))
  3639. (org-open-line 1)
  3640. (widen)
  3641. (buffer-string)))))
  3642. (ert-deftest test-org/forward-sentence ()
  3643. "Test `org-forward-sentence' specifications."
  3644. ;; At the end of a table cell, move to the end of the next one.
  3645. (should
  3646. (org-test-with-temp-text "| a<point> | b |"
  3647. (org-forward-sentence)
  3648. (looking-at " |$")))
  3649. ;; Elsewhere in a cell, move to its end.
  3650. (should
  3651. (org-test-with-temp-text "| a<point>c | b |"
  3652. (org-forward-sentence)
  3653. (looking-at " | b |$")))
  3654. ;; Otherwise, simply call `forward-sentence'.
  3655. (should
  3656. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3657. (org-forward-sentence)
  3658. (looking-at " Sentence 2.")))
  3659. (should
  3660. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3661. (org-forward-sentence)
  3662. (org-forward-sentence)
  3663. (eobp)))
  3664. ;; At the end of an element, jump to the next one, without stopping
  3665. ;; on blank lines in-between.
  3666. (should
  3667. (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
  3668. (org-forward-sentence)
  3669. (eobp)))
  3670. ;; Headlines are considered to be sentences by themselves, even if
  3671. ;; they do not end with a full stop.
  3672. (should
  3673. (equal
  3674. "* Headline"
  3675. (org-test-with-temp-text "* <point>Headline\nSentence."
  3676. (org-forward-sentence)
  3677. (buffer-substring-no-properties (line-beginning-position) (point)))))
  3678. (should
  3679. (org-test-with-temp-text "* Headline<point>\nSentence."
  3680. (org-forward-sentence)
  3681. (eobp)))
  3682. (should
  3683. (org-test-with-temp-text "Sentence.<point>\n\n* Headline\n\nSentence 2."
  3684. (org-forward-sentence)
  3685. (and (org-at-heading-p) (eolp)))))
  3686. (ert-deftest test-org/backward-sentence ()
  3687. "Test `org-backward-sentence' specifications."
  3688. ;; At the beginning of a table cell, move to the beginning of the
  3689. ;; previous one.
  3690. (should
  3691. (org-test-with-temp-text "| a | <point>b |"
  3692. (org-backward-sentence)
  3693. (looking-at "a | b |$")))
  3694. ;; Elsewhere in a cell, move to its beginning.
  3695. (should
  3696. (org-test-with-temp-text "| a | b<point>c |"
  3697. (org-backward-sentence)
  3698. (looking-at "bc |$")))
  3699. ;; Otherwise, simply call `backward-sentence'.
  3700. (should
  3701. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3702. (org-backward-sentence)
  3703. (looking-at "Sentence 2.")))
  3704. (should
  3705. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3706. (org-backward-sentence)
  3707. (org-backward-sentence)
  3708. (bobp)))
  3709. ;; Make sure to hit the beginning of a sentence on the same line as
  3710. ;; an item.
  3711. (should
  3712. (org-test-with-temp-text "- Line 1\n line <point>2."
  3713. (org-backward-sentence)
  3714. (looking-at "Line 1"))))
  3715. (ert-deftest test-org/forward-paragraph ()
  3716. "Test `org-forward-paragraph' specifications."
  3717. ;; At end of buffer, do not return an error.
  3718. (should
  3719. (org-test-with-temp-text "Paragraph"
  3720. (goto-char (point-max))
  3721. (org-forward-paragraph)
  3722. t))
  3723. ;; Standard test.
  3724. (should
  3725. (= 2
  3726. (org-test-with-temp-text "P1\n\nP2"
  3727. (org-forward-paragraph)
  3728. (org-current-line))))
  3729. (should
  3730. (= 2
  3731. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  3732. (org-forward-paragraph)
  3733. (org-current-line))))
  3734. ;; Enter greater elements.
  3735. (should
  3736. (= 2
  3737. (org-test-with-temp-text "#+begin_center\nP1\n#+end_center\nP2"
  3738. (org-forward-paragraph)
  3739. (org-current-line))))
  3740. ;; Do not enter elements with invisible contents.
  3741. (should
  3742. (= 4
  3743. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  3744. (org-cycle)
  3745. (org-forward-paragraph)
  3746. (org-current-line))))
  3747. (should
  3748. (= 6
  3749. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\nP3"
  3750. (org-hide-block-toggle)
  3751. (org-forward-paragraph)
  3752. (org-current-line))))
  3753. ;; On an item or a footnote definition, move past the first element
  3754. ;; inside, if any.
  3755. (should
  3756. (= 2
  3757. (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
  3758. (org-forward-paragraph)
  3759. (org-current-line))))
  3760. (should
  3761. (= 2
  3762. (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
  3763. (org-forward-paragraph)
  3764. (org-current-line))))
  3765. ;; On a table (resp. a property drawer) do not move through table
  3766. ;; rows (resp. node properties).
  3767. (should
  3768. (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
  3769. (org-forward-paragraph)
  3770. (looking-at "Paragraph")))
  3771. (should
  3772. (org-test-with-temp-text
  3773. "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
  3774. (org-forward-paragraph)
  3775. (looking-at "Paragraph")))
  3776. ;; Skip consecutive keywords, clocks and diary S-exps.
  3777. (should
  3778. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n"
  3779. (org-forward-paragraph)
  3780. (eobp)))
  3781. (should
  3782. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n"
  3783. (org-forward-paragraph)
  3784. (eobp)))
  3785. (should
  3786. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n"
  3787. (org-forward-paragraph)
  3788. (eobp)))
  3789. (should-not
  3790. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n"
  3791. (org-forward-paragraph)
  3792. (eobp)))
  3793. (should-not
  3794. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n"
  3795. (org-forward-paragraph)
  3796. (eobp)))
  3797. ;; In a plain list with one item every line, skip the whole list,
  3798. ;; even with point in the middle of the list.
  3799. (should
  3800. (org-test-with-temp-text "- A\n - B\n- C\n"
  3801. (org-forward-paragraph)
  3802. (eobp)))
  3803. (should
  3804. (org-test-with-temp-text "- A\n - <point>B\n- C\n"
  3805. (org-forward-paragraph)
  3806. (eobp)))
  3807. ;; On a comment, verse or source block, stop at "contents"
  3808. ;; boundaries and blank lines.
  3809. (should
  3810. (= 2
  3811. (org-test-with-temp-text "#+begin_src emacs-lisp\nL1\n\nL2\n#+end_src"
  3812. (org-forward-paragraph)
  3813. (org-current-line))))
  3814. (should
  3815. (= 3
  3816. (org-test-with-temp-text "#+begin_verse\n<point>L1\n\nL2\n#+end_verse"
  3817. (org-forward-paragraph)
  3818. (org-current-line))))
  3819. (should
  3820. (= 5
  3821. (org-test-with-temp-text "#+begin_comment\nL1\n\n<point>L2\n#+end_comment"
  3822. (org-forward-paragraph)
  3823. (org-current-line))))
  3824. ;; Being on an affiliated keyword shouldn't make any difference.
  3825. (should
  3826. (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
  3827. (org-forward-paragraph)
  3828. (eobp))))
  3829. (ert-deftest test-org/backward-paragraph ()
  3830. "Test `org-backward-paragraph' specifications."
  3831. ;; Do not error at beginning of buffer.
  3832. (should
  3833. (org-test-with-temp-text "Paragraph"
  3834. (org-backward-paragraph)
  3835. t))
  3836. ;; At blank lines at the very beginning of a buffer, move to
  3837. ;; point-min.
  3838. (should
  3839. (org-test-with-temp-text "\n\n<point>\n\nParagraph"
  3840. (org-backward-paragraph)
  3841. (bobp)))
  3842. ;; Regular test.
  3843. (should
  3844. (= 2
  3845. (org-test-with-temp-text "P1\n\nP2<point>"
  3846. (org-backward-paragraph)
  3847. (org-current-line))))
  3848. (should
  3849. (= 4
  3850. (org-test-with-temp-text "P1\n\nP2\n\nP3<point>"
  3851. (org-backward-paragraph)
  3852. (org-current-line))))
  3853. ;; Try to move on the line above current element.
  3854. (should
  3855. (= 2
  3856. (org-test-with-temp-text "\n\n<point>Paragraph"
  3857. (org-backward-paragraph)
  3858. (org-current-line))))
  3859. ;; Do not leave point in an invisible area.
  3860. (should
  3861. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  3862. (org-cycle)
  3863. (goto-char (point-max))
  3864. (beginning-of-line)
  3865. (org-backward-paragraph)
  3866. (bobp)))
  3867. (should
  3868. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\n"
  3869. (org-hide-block-toggle)
  3870. (goto-char (point-max))
  3871. (org-backward-paragraph)
  3872. (bobp)))
  3873. ;; On the first element in an item or a footnote definition, jump
  3874. ;; before the footnote or the item.
  3875. (should
  3876. (org-test-with-temp-text "- line1<point>"
  3877. (org-backward-paragraph)
  3878. (bobp)))
  3879. (should
  3880. (org-test-with-temp-text "[fn:1] line1n<point>"
  3881. (org-backward-paragraph)
  3882. (bobp)))
  3883. ;; On the second element in an item or a footnote definition, jump
  3884. ;; to item or the definition.
  3885. (should
  3886. (= 2
  3887. (org-test-with-temp-text "- line1\n\n<point> line2"
  3888. (org-backward-paragraph)
  3889. (org-current-line))))
  3890. (should
  3891. (= 2
  3892. (org-test-with-temp-text "[fn:1] line1\n\n<point> line2"
  3893. (org-backward-paragraph)
  3894. (org-current-line))))
  3895. ;; On a table (resp. a property drawer), ignore table rows
  3896. ;; (resp. node properties).
  3897. (should
  3898. (org-test-with-temp-text "| a | b |\n| c | d |\n<point>P1"
  3899. (org-backward-paragraph)
  3900. (bobp)))
  3901. (should
  3902. (= 2
  3903. (org-test-with-temp-text
  3904. "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
  3905. (org-backward-paragraph)
  3906. (org-current-line))))
  3907. ;; In a plain list with one item every line, skip the whole list,
  3908. ;; even with point in the middle of the list.
  3909. (should
  3910. (org-test-with-temp-text "- A\n - B\n- C\n<point>"
  3911. (org-backward-paragraph)
  3912. (bobp)))
  3913. (should
  3914. (org-test-with-temp-text "- A\n - B\n- <point>C\n"
  3915. (org-backward-paragraph)
  3916. (bobp)))
  3917. ;; Skip consecutive keywords, clocks and diary S-exps.
  3918. (should
  3919. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n<point>"
  3920. (org-backward-paragraph)
  3921. (bobp)))
  3922. (should
  3923. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n<point>"
  3924. (org-backward-paragraph)
  3925. (bobp)))
  3926. (should
  3927. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n<point>"
  3928. (org-backward-paragraph)
  3929. (bobp)))
  3930. (should-not
  3931. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n<point>"
  3932. (org-backward-paragraph)
  3933. (bobp)))
  3934. (should-not
  3935. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n<point>"
  3936. (org-backward-paragraph)
  3937. (bobp)))
  3938. ;; On a comment, example, source and verse blocks, stop at blank
  3939. ;; lines.
  3940. (should
  3941. (= 1
  3942. (org-test-with-temp-text
  3943. "#+begin_comment\n<point>L1\n\nL2\n\nL3\n#+end_comment"
  3944. (org-backward-paragraph)
  3945. (org-current-line))))
  3946. (should
  3947. (= 2
  3948. (org-test-with-temp-text
  3949. "#+begin_verse\nL1\n\n<point>L2\n\nL3\n#+end_verse"
  3950. (org-backward-paragraph)
  3951. (org-current-line))))
  3952. (should
  3953. (= 3
  3954. (org-test-with-temp-text
  3955. "#+begin_src emacs-lisp\nL1\n\nL2\n\n<point>L3\n#+end_src"
  3956. (org-backward-paragraph)
  3957. (org-current-line))))
  3958. ;; When called from the opening line itself, however, move to
  3959. ;; beginning of block.
  3960. (should
  3961. (org-test-with-temp-text "#+begin_<point>example\nL1\n#+end_example"
  3962. (org-backward-paragraph)
  3963. (bobp)))
  3964. ;; On an empty heading, move above it.
  3965. (should
  3966. (org-test-with-temp-text "\n* <point>"
  3967. (org-backward-paragraph)
  3968. (bobp)))
  3969. (should
  3970. (org-test-with-temp-text "\n* \n<point>"
  3971. (org-backward-paragraph)
  3972. (bobp))))
  3973. (ert-deftest test-org/forward-element ()
  3974. "Test `org-forward-element' specifications."
  3975. ;; 1. At EOB: should error.
  3976. (org-test-with-temp-text "Some text\n"
  3977. (goto-char (point-max))
  3978. (should-error (org-forward-element)))
  3979. ;; 2. Standard move: expected to ignore blank lines.
  3980. (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
  3981. (org-forward-element)
  3982. (should (looking-at (regexp-quote "Second paragraph."))))
  3983. ;; 3. Headline tests.
  3984. (org-test-with-temp-text "
  3985. * Head 1
  3986. ** Head 1.1
  3987. *** Head 1.1.1
  3988. ** Head 1.2"
  3989. ;; 3.1. At an headline beginning: move to next headline at the
  3990. ;; same level.
  3991. (goto-line 3)
  3992. (org-forward-element)
  3993. (should (looking-at (regexp-quote "** Head 1.2")))
  3994. ;; 3.2. At an headline beginning: move to parent headline if no
  3995. ;; headline at the same level.
  3996. (goto-line 3)
  3997. (org-forward-element)
  3998. (should (looking-at (regexp-quote "** Head 1.2"))))
  3999. ;; 4. Greater element tests.
  4000. (org-test-with-temp-text
  4001. "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
  4002. ;; 4.1. At a greater element: expected to skip contents.
  4003. (org-forward-element)
  4004. (should (looking-at (regexp-quote "Outside.")))
  4005. ;; 4.2. At the end of greater element contents: expected to skip
  4006. ;; to the end of the greater element.
  4007. (goto-line 2)
  4008. (org-forward-element)
  4009. (should (looking-at (regexp-quote "Outside."))))
  4010. ;; 5. List tests.
  4011. (org-test-with-temp-text "
  4012. - item1
  4013. - sub1
  4014. - sub2
  4015. - sub3
  4016. Inner paragraph.
  4017. - item2
  4018. Outside."
  4019. ;; 5.1. At list top point: expected to move to the element after
  4020. ;; the list.
  4021. (goto-line 2)
  4022. (org-forward-element)
  4023. (should (looking-at (regexp-quote "Outside.")))
  4024. ;; 5.2. Special case: at the first line of a sub-list, but not at
  4025. ;; beginning of line, move to next item.
  4026. (goto-line 2)
  4027. (forward-char)
  4028. (org-forward-element)
  4029. (should (looking-at "- item2"))
  4030. (goto-line 4)
  4031. (forward-char)
  4032. (org-forward-element)
  4033. (should (looking-at " - sub2"))
  4034. ;; 5.3 At sub-list beginning: expected to move after the sub-list.
  4035. (goto-line 4)
  4036. (org-forward-element)
  4037. (should (looking-at (regexp-quote " Inner paragraph.")))
  4038. ;; 5.4. At sub-list end: expected to move outside the sub-list.
  4039. (goto-line 8)
  4040. (org-forward-element)
  4041. (should (looking-at (regexp-quote " Inner paragraph.")))
  4042. ;; 5.5. At an item: expected to move to next item, if any.
  4043. (goto-line 6)
  4044. (org-forward-element)
  4045. (should (looking-at " - sub3"))))
  4046. (ert-deftest test-org/backward-element ()
  4047. "Test `org-backward-element' specifications."
  4048. ;; 1. Should error at BOB.
  4049. (org-test-with-temp-text " \nParagraph."
  4050. (should-error (org-backward-element)))
  4051. ;; 2. Should move at BOB when called on the first element in buffer.
  4052. (should
  4053. (org-test-with-temp-text "\n#+TITLE: test"
  4054. (progn (forward-line)
  4055. (org-backward-element)
  4056. (bobp))))
  4057. ;; 3. Not at the beginning of an element: move at its beginning.
  4058. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  4059. (goto-line 3)
  4060. (end-of-line)
  4061. (org-backward-element)
  4062. (should (looking-at (regexp-quote "Paragraph2."))))
  4063. ;; 4. Headline tests.
  4064. (org-test-with-temp-text "
  4065. * Head 1
  4066. ** Head 1.1
  4067. *** Head 1.1.1
  4068. ** Head 1.2"
  4069. ;; 4.1. At an headline beginning: move to previous headline at the
  4070. ;; same level.
  4071. (goto-line 5)
  4072. (org-backward-element)
  4073. (should (looking-at (regexp-quote "** Head 1.1")))
  4074. ;; 4.2. At an headline beginning: move to parent headline if no
  4075. ;; headline at the same level.
  4076. (goto-line 3)
  4077. (org-backward-element)
  4078. (should (looking-at (regexp-quote "* Head 1")))
  4079. ;; 4.3. At the first top-level headline: should error.
  4080. (goto-line 2)
  4081. (should-error (org-backward-element)))
  4082. ;; 5. At beginning of first element inside a greater element:
  4083. ;; expected to move to greater element's beginning.
  4084. (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
  4085. (goto-line 3)
  4086. (org-backward-element)
  4087. (should (looking-at "#\\+BEGIN_CENTER")))
  4088. ;; 6. At the beginning of the first element in a section: should
  4089. ;; move back to headline, if any.
  4090. (should
  4091. (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
  4092. (progn (goto-char (point-max))
  4093. (beginning-of-line)
  4094. (org-backward-element)
  4095. (org-at-heading-p))))
  4096. ;; 7. List tests.
  4097. (org-test-with-temp-text "
  4098. - item1
  4099. - sub1
  4100. - sub2
  4101. - sub3
  4102. Inner paragraph.
  4103. - item2
  4104. Outside."
  4105. ;; 7.1. At beginning of sub-list: expected to move to the
  4106. ;; paragraph before it.
  4107. (goto-line 4)
  4108. (org-backward-element)
  4109. (should (looking-at "item1"))
  4110. ;; 7.2. At an item in a list: expected to move at previous item.
  4111. (goto-line 8)
  4112. (org-backward-element)
  4113. (should (looking-at " - sub2"))
  4114. (goto-line 12)
  4115. (org-backward-element)
  4116. (should (looking-at "- item1"))
  4117. ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
  4118. ;; beginning.
  4119. (goto-line 10)
  4120. (org-backward-element)
  4121. (should (looking-at " - sub1"))
  4122. (goto-line 15)
  4123. (org-backward-element)
  4124. (should (looking-at "- item1"))
  4125. ;; 7.4. At blank-lines before list end: expected to move to top
  4126. ;; item.
  4127. (goto-line 14)
  4128. (org-backward-element)
  4129. (should (looking-at "- item1"))))
  4130. (ert-deftest test-org/up-element ()
  4131. "Test `org-up-element' specifications."
  4132. ;; 1. At BOB or with no surrounding element: should error.
  4133. (org-test-with-temp-text "Paragraph."
  4134. (should-error (org-up-element)))
  4135. (org-test-with-temp-text "* Head1\n* Head2"
  4136. (goto-line 2)
  4137. (should-error (org-up-element)))
  4138. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  4139. (goto-line 3)
  4140. (should-error (org-up-element)))
  4141. ;; 2. At an headline: move to parent headline.
  4142. (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
  4143. (goto-line 3)
  4144. (org-up-element)
  4145. (should (looking-at "\\* Head1")))
  4146. ;; 3. Inside a greater element: move to greater element beginning.
  4147. (org-test-with-temp-text
  4148. "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
  4149. (goto-line 3)
  4150. (org-up-element)
  4151. (should (looking-at "#\\+BEGIN_CENTER")))
  4152. ;; 4. List tests.
  4153. (org-test-with-temp-text "* Top
  4154. - item1
  4155. - sub1
  4156. - sub2
  4157. Paragraph within sub2.
  4158. - item2"
  4159. ;; 4.1. Within an item: move to the item beginning.
  4160. (goto-line 8)
  4161. (org-up-element)
  4162. (should (looking-at " - sub2"))
  4163. ;; 4.2. At an item in a sub-list: move to parent item.
  4164. (goto-line 4)
  4165. (org-up-element)
  4166. (should (looking-at "- item1"))
  4167. ;; 4.3. At an item in top list: move to beginning of whole list.
  4168. (goto-line 10)
  4169. (org-up-element)
  4170. (should (looking-at "- item1"))
  4171. ;; 4.4. Special case. At very top point: should move to parent of
  4172. ;; list.
  4173. (goto-line 2)
  4174. (org-up-element)
  4175. (should (looking-at "\\* Top"))))
  4176. (ert-deftest test-org/down-element ()
  4177. "Test `org-down-element' specifications."
  4178. ;; Error when the element hasn't got a recursive type.
  4179. (org-test-with-temp-text "Paragraph."
  4180. (should-error (org-down-element)))
  4181. ;; Error when the element has no contents
  4182. (org-test-with-temp-text "* Headline"
  4183. (should-error (org-down-element)))
  4184. ;; When at a plain-list, move to first item.
  4185. (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
  4186. (goto-line 2)
  4187. (org-down-element)
  4188. (should (looking-at " - Item 1.1")))
  4189. (org-test-with-temp-text "#+NAME: list\n- Item 1"
  4190. (org-down-element)
  4191. (should (looking-at " Item 1")))
  4192. ;; When at a table, move to first row
  4193. (org-test-with-temp-text "#+NAME: table\n| a | b |"
  4194. (org-down-element)
  4195. (should (looking-at " a | b |")))
  4196. ;; Otherwise, move inside the greater element.
  4197. (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
  4198. (org-down-element)
  4199. (should (looking-at "Paragraph"))))
  4200. (ert-deftest test-org/drag-element-backward ()
  4201. "Test `org-drag-element-backward' specifications."
  4202. ;; Standard test.
  4203. (should
  4204. (equal
  4205. "#+key2: val2\n#+key1: val1\n#+key3: val3"
  4206. (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
  4207. (org-drag-element-backward)
  4208. (buffer-string))))
  4209. (should
  4210. (equal
  4211. "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
  4212. (org-test-with-temp-text
  4213. "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
  4214. (org-drag-element-backward)
  4215. (buffer-string))))
  4216. ;; Preserve blank lines.
  4217. (should
  4218. (equal "Paragraph 2\n\n\nPara1\n\nPara3"
  4219. (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
  4220. (org-drag-element-backward)
  4221. (buffer-string))))
  4222. ;; Preserve column.
  4223. (should
  4224. (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
  4225. (org-drag-element-backward)
  4226. (looking-at-p "2")))
  4227. ;; Error when trying to move first element of buffer.
  4228. (should-error
  4229. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4230. (org-drag-element-backward))
  4231. :type 'user-error)
  4232. ;; Error when trying to swap nested elements.
  4233. (should-error
  4234. (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
  4235. (org-drag-element-backward))
  4236. :type 'user-error)
  4237. ;; Error when trying to swap an headline element and a non-headline
  4238. ;; element.
  4239. (should-error
  4240. (org-test-with-temp-text "Test.\n<point>* Head 1"
  4241. (org-drag-element-backward))
  4242. :type 'error)
  4243. ;; Error when called before first element.
  4244. (should-error
  4245. (org-test-with-temp-text "\n<point>"
  4246. (org-drag-element-backward))
  4247. :type 'user-error)
  4248. ;; Preserve visibility of elements and their contents.
  4249. (should
  4250. (equal '((63 . 82) (26 . 48))
  4251. (org-test-with-temp-text "
  4252. #+BEGIN_CENTER
  4253. Text.
  4254. #+END_CENTER
  4255. - item 1
  4256. #+BEGIN_QUOTE
  4257. Text.
  4258. #+END_QUOTE"
  4259. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4260. (search-backward "- item 1")
  4261. (org-drag-element-backward)
  4262. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4263. (overlays-in (point-min) (point-max))))))
  4264. ;; Pathological case: handle call with point in blank lines right
  4265. ;; after a headline.
  4266. (should
  4267. (equal "* H2\n\n* H1\nText\n"
  4268. (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
  4269. (org-drag-element-backward)
  4270. (buffer-string)))))
  4271. (ert-deftest test-org/drag-element-forward ()
  4272. "Test `org-drag-element-forward' specifications."
  4273. ;; 1. Error when trying to move first element of buffer.
  4274. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4275. (goto-line 3)
  4276. (should-error (org-drag-element-forward)))
  4277. ;; 2. Error when trying to swap nested elements.
  4278. (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
  4279. (forward-line)
  4280. (should-error (org-drag-element-forward)))
  4281. ;; 3. Error when trying to swap a non-headline element and an
  4282. ;; headline.
  4283. (org-test-with-temp-text "Test.\n* Head 1"
  4284. (should-error (org-drag-element-forward)))
  4285. ;; 4. Error when called before first element.
  4286. (should-error
  4287. (org-test-with-temp-text "\n"
  4288. (forward-line)
  4289. (org-drag-element-backward))
  4290. :type 'user-error)
  4291. ;; 5. Otherwise, swap elements, preserving column and blank lines
  4292. ;; between elements.
  4293. (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
  4294. (search-forward "graph")
  4295. (org-drag-element-forward)
  4296. (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
  4297. (should (looking-at " 1")))
  4298. ;; 5. Preserve visibility of elements and their contents.
  4299. (org-test-with-temp-text "
  4300. #+BEGIN_CENTER
  4301. Text.
  4302. #+END_CENTER
  4303. - item 1
  4304. #+BEGIN_QUOTE
  4305. Text.
  4306. #+END_QUOTE"
  4307. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4308. (search-backward "#+BEGIN_CENTER")
  4309. (org-drag-element-forward)
  4310. (should
  4311. (equal
  4312. '((63 . 82) (26 . 48))
  4313. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4314. (overlays-in (point-min) (point-max)))))))
  4315. (ert-deftest test-org/next-block ()
  4316. "Test `org-next-block' specifications."
  4317. ;; Regular test.
  4318. (should
  4319. (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  4320. (org-next-block 1)
  4321. (looking-at "#\\+BEGIN_CENTER")))
  4322. ;; Ignore case.
  4323. (should
  4324. (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
  4325. (let ((case-fold-search nil))
  4326. (org-next-block 1)
  4327. (looking-at "#\\+begin_center"))))
  4328. ;; Ignore current line.
  4329. (should
  4330. (org-test-with-temp-text
  4331. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
  4332. (org-next-block 1)
  4333. (looking-at "#\\+BEGIN_CENTER")))
  4334. ;; Throw an error when no block is found.
  4335. (should-error
  4336. (org-test-with-temp-text "Paragraph"
  4337. (org-next-block 1)))
  4338. ;; With an argument, skip many blocks at once.
  4339. (should
  4340. (org-test-with-temp-text
  4341. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4342. (org-next-block 2)
  4343. (looking-at "#\\+BEGIN_QUOTE")))
  4344. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4345. (should
  4346. (org-test-with-temp-text
  4347. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4348. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4349. (looking-at "#\\+BEGIN_QUOTE")))
  4350. ;; Optional argument is also case-insensitive.
  4351. (should
  4352. (org-test-with-temp-text
  4353. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
  4354. (let ((case-fold-search nil))
  4355. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4356. (looking-at "#\\+begin_quote")))))
  4357. (ert-deftest test-org/insert-structure-template ()
  4358. "Test `org-insert-structure-template'."
  4359. ;; Test in empty buffer.
  4360. (should
  4361. (string= "#+begin_foo\n#+end_foo\n"
  4362. (org-test-with-temp-text ""
  4363. (org-insert-structure-template "foo")
  4364. (buffer-string))))
  4365. ;; Test with multiple lines in buffer.
  4366. (should
  4367. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4368. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4369. (transient-mark-mode 1)
  4370. (org-mark-element)
  4371. (org-insert-structure-template "foo")
  4372. (buffer-string))))
  4373. ;; Mark only the current line.
  4374. (should
  4375. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4376. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4377. (transient-mark-mode 1)
  4378. (set-mark (point-min))
  4379. (end-of-line)
  4380. (org-insert-structure-template "foo")
  4381. (buffer-string))))
  4382. ;; Middle of paragraph.
  4383. (should
  4384. (string= "p1\n#+begin_foo\np2\n#+end_foo\np3"
  4385. (org-test-with-temp-text "p1\n<point>p2\np3"
  4386. (set-mark (line-beginning-position))
  4387. (end-of-line)
  4388. (activate-mark)
  4389. (org-insert-structure-template "foo")
  4390. (buffer-string))))
  4391. ;; Test with text in buffer, no region, no final newline.
  4392. (should
  4393. (string= "#+begin_foo\nI'm a paragraph.\n#+end_foo\n"
  4394. (org-test-with-temp-text "I'm a paragraph."
  4395. (org-mark-element)
  4396. (org-insert-structure-template "foo")
  4397. (buffer-string))))
  4398. ;; Test with text in buffer and region set.
  4399. (should
  4400. (string= "#+begin_foo\nI'm a paragraph\n\nI'm a second paragrah\n#+end_foo\n"
  4401. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragrah"
  4402. (set-mark (point))
  4403. (goto-char (point-max))
  4404. (org-insert-structure-template "foo")
  4405. (buffer-string))))
  4406. ;; Test with example escaping.
  4407. (should
  4408. (string= "#+begin_example\n,* Heading\n#+end_example\n"
  4409. (org-test-with-temp-text "* Heading"
  4410. (org-mark-element)
  4411. (org-insert-structure-template "example")
  4412. (buffer-string))))
  4413. ;; Test with indentation.
  4414. (should
  4415. (string= " #+begin_foo\n This is a paragraph\n #+end_foo\n"
  4416. (org-test-with-temp-text " This is a paragraph"
  4417. (org-mark-element)
  4418. (org-insert-structure-template "foo")
  4419. (buffer-string))))
  4420. (should
  4421. (string= " #+begin_foo\n Line 1\n Line2\n #+end_foo\n"
  4422. (org-test-with-temp-text " Line 1\n Line2"
  4423. (org-mark-element)
  4424. (org-insert-structure-template "foo")
  4425. (buffer-string))))
  4426. ;; Test point location.
  4427. (should
  4428. (string= "#+begin_foo\n"
  4429. (org-test-with-temp-text ""
  4430. (org-insert-structure-template "foo")
  4431. (buffer-substring (point-min) (point)))))
  4432. (should
  4433. (string= "#+begin_src "
  4434. (org-test-with-temp-text ""
  4435. (org-insert-structure-template "src")
  4436. (buffer-substring (point-min) (point))))))
  4437. (ert-deftest test-org/previous-block ()
  4438. "Test `org-previous-block' specifications."
  4439. ;; Regular test.
  4440. (should
  4441. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
  4442. (org-previous-block 1)
  4443. (looking-at "#\\+BEGIN_CENTER")))
  4444. ;; Ignore case.
  4445. (should
  4446. (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
  4447. (let ((case-fold-search nil))
  4448. (org-previous-block 1)
  4449. (looking-at "#\\+begin_center"))))
  4450. ;; Ignore current line.
  4451. (should
  4452. (org-test-with-temp-text
  4453. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
  4454. (org-previous-block 1)
  4455. (looking-at "#\\+BEGIN_QUOTE")))
  4456. ;; Throw an error when no block is found.
  4457. (should-error
  4458. (org-test-with-temp-text "Paragraph<point>"
  4459. (org-previous-block 1)))
  4460. ;; With an argument, skip many blocks at once.
  4461. (should
  4462. (org-test-with-temp-text
  4463. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4464. (org-previous-block 2)
  4465. (looking-at "#\\+BEGIN_CENTER")))
  4466. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4467. (should
  4468. (org-test-with-temp-text
  4469. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4470. (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4471. (looking-at "#\\+BEGIN_QUOTE")))
  4472. ;; Optional argument is also case-insensitive.
  4473. (should
  4474. (org-test-with-temp-text
  4475. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
  4476. (let ((case-fold-search nil))
  4477. (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4478. (looking-at "#\\+begin_quote")))))
  4479. ;;; Outline structure
  4480. (ert-deftest test-org/demote ()
  4481. "Test `org-demote' specifications."
  4482. ;; Add correct number of stars according to `org-odd-levels-only'.
  4483. (should
  4484. (= 2
  4485. (org-test-with-temp-text "* H"
  4486. (let ((org-odd-levels-only nil)) (org-demote))
  4487. (org-current-level))))
  4488. (should
  4489. (= 3
  4490. (org-test-with-temp-text "* H"
  4491. (let ((org-odd-levels-only t)) (org-demote))
  4492. (org-current-level))))
  4493. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4494. (should
  4495. (org-test-with-temp-text "* H :tag:"
  4496. (let ((org-tags-column 10)
  4497. (org-auto-align-tags t)
  4498. (org-odd-levels-only nil))
  4499. (org-demote))
  4500. (org-move-to-column 10)
  4501. (looking-at-p ":tag:$")))
  4502. (should-not
  4503. (org-test-with-temp-text "* H :tag:"
  4504. (let ((org-tags-column 10)
  4505. (org-auto-align-tags nil)
  4506. (org-odd-levels-only nil))
  4507. (org-demote))
  4508. (org-move-to-column 10)
  4509. (looking-at-p ":tag:$")))
  4510. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4511. ;; info and property drawers accordingly.
  4512. (should
  4513. (= 3
  4514. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4515. (let ((org-odd-levels-only nil)
  4516. (org-adapt-indentation t))
  4517. (org-demote))
  4518. (forward-line)
  4519. (org-get-indentation))))
  4520. (should
  4521. (= 3
  4522. (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4523. (let ((org-odd-levels-only nil)
  4524. (org-adapt-indentation t))
  4525. (org-demote))
  4526. (forward-line)
  4527. (org-get-indentation))))
  4528. (should-not
  4529. (= 3
  4530. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4531. (let ((org-odd-levels-only nil)
  4532. (org-adapt-indentation nil))
  4533. (org-demote))
  4534. (forward-line)
  4535. (org-get-indentation))))
  4536. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4537. ;; section accordingly. Ignore, however, footnote definitions and
  4538. ;; inlinetasks boundaries.
  4539. (should
  4540. (= 3
  4541. (org-test-with-temp-text "* H\n Paragraph"
  4542. (let ((org-odd-levels-only nil)
  4543. (org-adapt-indentation t))
  4544. (org-demote))
  4545. (forward-line)
  4546. (org-get-indentation))))
  4547. (should
  4548. (= 2
  4549. (org-test-with-temp-text "* H\n Paragraph"
  4550. (let ((org-odd-levels-only nil)
  4551. (org-adapt-indentation nil))
  4552. (org-demote))
  4553. (forward-line)
  4554. (org-get-indentation))))
  4555. (should
  4556. (zerop
  4557. (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
  4558. (let ((org-odd-levels-only nil)
  4559. (org-adapt-indentation t))
  4560. (org-demote))
  4561. (goto-char (point-max))
  4562. (org-get-indentation))))
  4563. (should
  4564. (= 3
  4565. (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
  4566. (let ((org-odd-levels-only nil)
  4567. (org-adapt-indentation t))
  4568. (org-demote))
  4569. (goto-char (point-max))
  4570. (org-get-indentation))))
  4571. (when (featurep 'org-inlinetask)
  4572. (should
  4573. (zerop
  4574. (let ((org-inlinetask-min-level 5)
  4575. (org-adapt-indentation t))
  4576. (org-test-with-temp-text "* H\n***** I\n***** END"
  4577. (org-demote)
  4578. (forward-line)
  4579. (org-get-indentation))))))
  4580. (when (featurep 'org-inlinetask)
  4581. (should
  4582. (= 3
  4583. (let ((org-inlinetask-min-level 5)
  4584. (org-adapt-indentation t))
  4585. (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
  4586. (org-demote)
  4587. (forward-line 2)
  4588. (org-get-indentation))))))
  4589. ;; When `org-adapt-indentation' is non-nil, log drawers are
  4590. ;; adjusted.
  4591. (should
  4592. (equal
  4593. "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4594. (org-test-with-temp-text "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4595. (let ((org-odd-levels-only nil)
  4596. (org-adapt-indentation t))
  4597. (org-demote))
  4598. (buffer-string))))
  4599. (should
  4600. (equal
  4601. "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4602. (org-test-with-temp-text "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4603. (let ((org-odd-levels-only nil)
  4604. (org-adapt-indentation 'headline-data))
  4605. (org-demote))
  4606. (buffer-string))))
  4607. (should
  4608. (equal
  4609. "** H\n :LOGBOOK:\n - a\n :END:"
  4610. (org-test-with-temp-text "* H\n:LOGBOOK:\n- a\n:END:"
  4611. (let ((org-odd-levels-only nil)
  4612. (org-adapt-indentation t))
  4613. (org-demote))
  4614. (buffer-string))))
  4615. ;; Ignore contents of source blocks or example blocks when
  4616. ;; indentation should be preserved (through
  4617. ;; `org-src-preserve-indentation' or "-i" flag).
  4618. (should-not
  4619. (zerop
  4620. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4621. (let ((org-adapt-indentation t)
  4622. (org-src-preserve-indentation nil))
  4623. (org-demote))
  4624. (forward-line 2)
  4625. (org-get-indentation))))
  4626. (should
  4627. (zerop
  4628. (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
  4629. (let ((org-adapt-indentation t)
  4630. (org-src-preserve-indentation t))
  4631. (org-demote))
  4632. (forward-line 2)
  4633. (org-get-indentation))))
  4634. (should
  4635. (zerop
  4636. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4637. (let ((org-adapt-indentation t)
  4638. (org-src-preserve-indentation t))
  4639. (org-demote))
  4640. (forward-line 2)
  4641. (org-get-indentation))))
  4642. (should
  4643. (zerop
  4644. (org-test-with-temp-text
  4645. "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
  4646. (let ((org-adapt-indentation t)
  4647. (org-src-preserve-indentation nil))
  4648. (org-demote))
  4649. (forward-line 2)
  4650. (org-get-indentation)))))
  4651. (ert-deftest test-org/promote ()
  4652. "Test `org-promote' specifications."
  4653. ;; Return an error if headline is to be promoted to level 0, unless
  4654. ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
  4655. ;; headline becomes a comment.
  4656. (should-error
  4657. (org-test-with-temp-text "* H"
  4658. (let ((org-allow-promoting-top-level-subtree nil)) (org-promote))))
  4659. (should
  4660. (equal "# H"
  4661. (org-test-with-temp-text "* H"
  4662. (let ((org-allow-promoting-top-level-subtree t)) (org-promote))
  4663. (buffer-string))))
  4664. ;; Remove correct number of stars according to
  4665. ;; `org-odd-levels-only'.
  4666. (should
  4667. (= 2
  4668. (org-test-with-temp-text "*** H"
  4669. (let ((org-odd-levels-only nil)) (org-promote))
  4670. (org-current-level))))
  4671. (should
  4672. (= 1
  4673. (org-test-with-temp-text "*** H"
  4674. (let ((org-odd-levels-only t)) (org-promote))
  4675. (org-current-level))))
  4676. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4677. (should
  4678. (org-test-with-temp-text "** H :tag:"
  4679. (let ((org-tags-column 10)
  4680. (org-auto-align-tags t)
  4681. (org-odd-levels-only nil))
  4682. (org-promote))
  4683. (org-move-to-column 10)
  4684. (looking-at-p ":tag:$")))
  4685. (should-not
  4686. (org-test-with-temp-text "** H :tag:"
  4687. (let ((org-tags-column 10)
  4688. (org-auto-align-tags nil)
  4689. (org-odd-levels-only nil))
  4690. (org-promote))
  4691. (org-move-to-column 10)
  4692. (looking-at-p ":tag:$")))
  4693. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4694. ;; info and property drawers.
  4695. (should
  4696. (= 2
  4697. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4698. (let ((org-odd-levels-only nil)
  4699. (org-adapt-indentation t))
  4700. (org-promote))
  4701. (forward-line)
  4702. (org-get-indentation))))
  4703. (should
  4704. (= 2
  4705. (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4706. (let ((org-odd-levels-only nil)
  4707. (org-adapt-indentation t))
  4708. (org-promote))
  4709. (forward-line)
  4710. (org-get-indentation))))
  4711. (should-not
  4712. (= 2
  4713. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4714. (let ((org-odd-levels-only nil)
  4715. (org-adapt-indentation nil))
  4716. (org-promote))
  4717. (forward-line)
  4718. (org-get-indentation))))
  4719. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4720. ;; section accordingly. Ignore, however, footnote definitions and
  4721. ;; inlinetasks boundaries.
  4722. (should
  4723. (= 2
  4724. (org-test-with-temp-text "** H\n Paragraph"
  4725. (let ((org-odd-levels-only nil)
  4726. (org-adapt-indentation t))
  4727. (org-promote))
  4728. (forward-line)
  4729. (org-get-indentation))))
  4730. (should-not
  4731. (= 2
  4732. (org-test-with-temp-text "** H\n Paragraph"
  4733. (let ((org-odd-levels-only nil)
  4734. (org-adapt-indentation nil))
  4735. (org-promote))
  4736. (forward-line)
  4737. (org-get-indentation))))
  4738. (should
  4739. (= 2
  4740. (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
  4741. (let ((org-odd-levels-only nil)
  4742. (org-adapt-indentation t))
  4743. (org-promote))
  4744. (forward-line)
  4745. (org-get-indentation))))
  4746. (when (featurep 'org-inlinetask)
  4747. (should
  4748. (zerop
  4749. (let ((org-inlinetask-min-level 5)
  4750. (org-adapt-indentation t))
  4751. (org-test-with-temp-text "** H\n***** I\n***** END"
  4752. (org-promote)
  4753. (forward-line)
  4754. (org-get-indentation))))))
  4755. (when (featurep 'org-inlinetask)
  4756. (should
  4757. (= 2
  4758. (let ((org-inlinetask-min-level 5)
  4759. (org-adapt-indentation t))
  4760. (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
  4761. (org-promote)
  4762. (forward-line 2)
  4763. (org-get-indentation))))))
  4764. ;; Give up shifting if it would break document's structure
  4765. ;; otherwise.
  4766. (should
  4767. (= 3
  4768. (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
  4769. (let ((org-odd-levels-only nil)
  4770. (org-adapt-indentation t))
  4771. (org-promote))
  4772. (forward-line)
  4773. (org-get-indentation))))
  4774. (should
  4775. (= 3
  4776. (org-test-with-temp-text "** H\n Paragraph\n * list."
  4777. (let ((org-odd-levels-only nil)
  4778. (org-adapt-indentation t))
  4779. (org-promote))
  4780. (forward-line)
  4781. (org-get-indentation))))
  4782. ;; When `org-adapt-indentation' is non-nil, log drawers are
  4783. ;; adjusted.
  4784. (should
  4785. (equal
  4786. "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4787. (org-test-with-temp-text "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4788. (let ((org-odd-levels-only nil)
  4789. (org-adapt-indentation t))
  4790. (org-promote))
  4791. (buffer-string))))
  4792. (should
  4793. (equal
  4794. "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4795. (org-test-with-temp-text "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4796. (let ((org-odd-levels-only nil)
  4797. (org-adapt-indentation 'headline-data))
  4798. (org-promote))
  4799. (buffer-string))))
  4800. (should
  4801. (equal
  4802. "* H\n:LOGBOOK:\n- a\n:END:"
  4803. (org-test-with-temp-text "** H\n:LOGBOOK:\n- a\n:END:"
  4804. (let ((org-odd-levels-only nil)
  4805. (org-adapt-indentation t))
  4806. (org-promote))
  4807. (buffer-string))))
  4808. (should
  4809. (equal
  4810. "# H\n:LOGBOOK:\n- a\n:END:"
  4811. (org-test-with-temp-text "* H\n:LOGBOOK:\n- a\n:END:"
  4812. (let ((org-odd-levels-only nil)
  4813. (org-allow-promoting-top-level-subtree t)
  4814. (org-adapt-indentation t))
  4815. (org-promote))
  4816. (buffer-string))))
  4817. ;; Ignore contents of source blocks or example blocks when
  4818. ;; indentation should be preserved (through
  4819. ;; `org-src-preserve-indentation' or "-i" flag).
  4820. (should-not
  4821. (zerop
  4822. (org-test-with-temp-text
  4823. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  4824. (let ((org-adapt-indentation t)
  4825. (org-src-preserve-indentation nil)
  4826. (org-odd-levels-only nil))
  4827. (org-promote))
  4828. (forward-line)
  4829. (org-get-indentation))))
  4830. (should
  4831. (zerop
  4832. (org-test-with-temp-text
  4833. "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
  4834. (let ((org-adapt-indentation t)
  4835. (org-src-preserve-indentation t)
  4836. (org-odd-levels-only nil))
  4837. (org-promote))
  4838. (forward-line)
  4839. (org-get-indentation))))
  4840. (should
  4841. (zerop
  4842. (org-test-with-temp-text
  4843. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  4844. (let ((org-adapt-indentation t)
  4845. (org-src-preserve-indentation t)
  4846. (org-odd-levels-only nil))
  4847. (org-promote))
  4848. (forward-line)
  4849. (org-get-indentation))))
  4850. (should
  4851. (zerop
  4852. (org-test-with-temp-text
  4853. "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
  4854. (let ((org-adapt-indentation t)
  4855. (org-src-preserve-indentation nil)
  4856. (org-odd-levels-only nil))
  4857. (org-promote))
  4858. (forward-line)
  4859. (org-get-indentation)))))
  4860. (ert-deftest test-org/org-get-valid-level ()
  4861. "Test function `org-get-valid-level' specifications."
  4862. (let ((org-odd-levels-only nil))
  4863. (should (equal 1 (org-get-valid-level 0 0)))
  4864. (should (equal 1 (org-get-valid-level 0 1)))
  4865. (should (equal 2 (org-get-valid-level 0 2)))
  4866. (should (equal 3 (org-get-valid-level 0 3)))
  4867. (should (equal 1 (org-get-valid-level 1 0)))
  4868. (should (equal 2 (org-get-valid-level 1 1)))
  4869. (should (equal 23 (org-get-valid-level 1 22)))
  4870. (should (equal 1 (org-get-valid-level 1 -1)))
  4871. (should (equal 1 (org-get-valid-level 2 -1))))
  4872. (let ((org-odd-levels-only t))
  4873. (should (equal 1 (org-get-valid-level 0 0)))
  4874. (should (equal 1 (org-get-valid-level 0 1)))
  4875. (should (equal 3 (org-get-valid-level 0 2)))
  4876. (should (equal 5 (org-get-valid-level 0 3)))
  4877. (should (equal 1 (org-get-valid-level 1 0)))
  4878. (should (equal 3 (org-get-valid-level 1 1)))
  4879. (should (equal 3 (org-get-valid-level 2 1)))
  4880. (should (equal 5 (org-get-valid-level 3 1)))
  4881. (should (equal 5 (org-get-valid-level 4 1)))
  4882. (should (equal 43 (org-get-valid-level 1 21)))
  4883. (should (equal 1 (org-get-valid-level 1 -1)))
  4884. (should (equal 1 (org-get-valid-level 2 -1)))
  4885. (should (equal 1 (org-get-valid-level 3 -1)))
  4886. (should (equal 3 (org-get-valid-level 4 -1)))
  4887. (should (equal 3 (org-get-valid-level 5 -1)))))
  4888. ;;; Planning
  4889. (ert-deftest test-org/at-planning-p ()
  4890. "Test `org-at-planning-p' specifications."
  4891. ;; Regular test.
  4892. (should
  4893. (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
  4894. (org-at-planning-p)))
  4895. (should-not
  4896. (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
  4897. (org-at-planning-p)))
  4898. ;; Correctly find planning attached to inlinetasks.
  4899. (when (featurep 'org-inlinetask)
  4900. (should
  4901. (org-test-with-temp-text
  4902. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
  4903. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4904. (should-not
  4905. (org-test-with-temp-text
  4906. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  4907. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4908. (should-not
  4909. (org-test-with-temp-text
  4910. "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  4911. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4912. (should-not
  4913. (org-test-with-temp-text
  4914. "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
  4915. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
  4916. (ert-deftest test-org/add-planning-info ()
  4917. "Test `org-add-planning-info'."
  4918. ;; Create deadline when `org-adapt-indentation' is non-nil.
  4919. (should
  4920. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4921. (org-test-with-temp-text "* H\nParagraph<point>"
  4922. (let ((org-adapt-indentation t))
  4923. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4924. (replace-regexp-in-string
  4925. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4926. nil nil 1))))
  4927. ;; Create deadline when `org-adapt-indentation' is nil.
  4928. (should
  4929. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  4930. (org-test-with-temp-text "* H\nParagraph<point>"
  4931. (let ((org-adapt-indentation nil))
  4932. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4933. (replace-regexp-in-string
  4934. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4935. nil nil 1))))
  4936. ;; Update deadline when `org-adapt-indentation' is non-nil.
  4937. (should
  4938. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4939. (org-test-with-temp-text "\
  4940. * H
  4941. DEADLINE: <2015-06-24 Wed>
  4942. Paragraph<point>"
  4943. (let ((org-adapt-indentation t))
  4944. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4945. (replace-regexp-in-string
  4946. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4947. nil nil 1))))
  4948. ;; Update deadline when `org-adapt-indentation' is nil.
  4949. (should
  4950. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  4951. (org-test-with-temp-text "\
  4952. * H
  4953. DEADLINE: <2015-06-24 Wed>
  4954. Paragraph<point>"
  4955. (let ((org-adapt-indentation nil))
  4956. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4957. (replace-regexp-in-string
  4958. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4959. nil nil 1))))
  4960. ;; Schedule when `org-adapt-indentation' is non-nil.
  4961. (should
  4962. (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
  4963. (org-test-with-temp-text "* H\nParagraph<point>"
  4964. (let ((org-adapt-indentation t))
  4965. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  4966. (replace-regexp-in-string
  4967. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4968. nil nil 1))))
  4969. ;; Schedule when `org-adapt-indentation' is nil.
  4970. (should
  4971. (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
  4972. (org-test-with-temp-text "* H\nParagraph<point>"
  4973. (let ((org-adapt-indentation nil))
  4974. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  4975. (replace-regexp-in-string
  4976. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4977. nil nil 1))))
  4978. ;; Add deadline when scheduled.
  4979. (should
  4980. (equal "\
  4981. * H
  4982. DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
  4983. Paragraph"
  4984. (org-test-with-temp-text "\
  4985. * H
  4986. SCHEDULED: <2015-06-24 Wed>
  4987. Paragraph<point>"
  4988. (let ((org-adapt-indentation t))
  4989. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4990. (replace-regexp-in-string
  4991. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4992. nil nil 1))))
  4993. ;; Remove middle entry.
  4994. (should
  4995. (equal "\
  4996. * H
  4997. CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
  4998. Paragraph"
  4999. (org-test-with-temp-text "\
  5000. * H
  5001. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  5002. Paragraph<point>"
  5003. (let ((org-adapt-indentation t))
  5004. (org-add-planning-info nil nil 'deadline))
  5005. (replace-regexp-in-string
  5006. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  5007. nil nil 1))))
  5008. ;; Remove last entry and then middle entry (order should not
  5009. ;; matter).
  5010. (should
  5011. (equal "\
  5012. * H
  5013. CLOSED: [2015-06-24]
  5014. Paragraph"
  5015. (org-test-with-temp-text "\
  5016. * H
  5017. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  5018. Paragraph<point>"
  5019. (let ((org-adapt-indentation t))
  5020. (org-add-planning-info nil nil 'scheduled 'deadline))
  5021. (replace-regexp-in-string
  5022. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  5023. nil nil 1))))
  5024. ;; Remove closed when `org-adapt-indentation' is non-nil.
  5025. (should
  5026. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5027. (org-test-with-temp-text "\
  5028. * H
  5029. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  5030. Paragraph<point>"
  5031. (let ((org-adapt-indentation t))
  5032. (org-add-planning-info nil nil 'closed))
  5033. (replace-regexp-in-string
  5034. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5035. nil nil 1))))
  5036. (should
  5037. (equal "* H\n Paragraph"
  5038. (org-test-with-temp-text "\
  5039. * H
  5040. CLOSED: [2015-06-25 Thu]
  5041. Paragraph<point>"
  5042. (let ((org-adapt-indentation t))
  5043. (org-add-planning-info nil nil 'closed))
  5044. (replace-regexp-in-string
  5045. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5046. nil nil 1))))
  5047. ;; Remove closed when `org-adapt-indentation' is nil.
  5048. (should
  5049. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  5050. (org-test-with-temp-text "\
  5051. * H
  5052. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  5053. Paragraph<point>"
  5054. (let ((org-adapt-indentation nil))
  5055. (org-add-planning-info nil nil 'closed))
  5056. (replace-regexp-in-string
  5057. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5058. nil nil 1))))
  5059. (should
  5060. (equal "* H\nParagraph"
  5061. (org-test-with-temp-text "\
  5062. * H
  5063. CLOSED: [2015-06-25 Thu]
  5064. Paragraph<point>"
  5065. (let ((org-adapt-indentation nil))
  5066. (org-add-planning-info nil nil 'closed))
  5067. (replace-regexp-in-string
  5068. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5069. nil nil 1))))
  5070. ;; Remove closed entry and delete empty line.
  5071. (should
  5072. (equal "\
  5073. * H
  5074. Paragraph"
  5075. (org-test-with-temp-text "\
  5076. * H
  5077. CLOSED: [2015-06-24 Wed]
  5078. Paragraph<point>"
  5079. (let ((org-adapt-indentation t))
  5080. (org-add-planning-info nil nil 'closed))
  5081. (replace-regexp-in-string
  5082. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5083. nil nil 1))))
  5084. ;; Remove one entry and update another.
  5085. (should
  5086. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5087. (org-test-with-temp-text "\
  5088. * H
  5089. SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
  5090. Paragraph<point>"
  5091. (let ((org-adapt-indentation t))
  5092. (org-add-planning-info 'deadline "<2015-06-25 Thu>" 'scheduled))
  5093. (replace-regexp-in-string
  5094. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5095. nil nil 1)))))
  5096. (ert-deftest test-org/deadline ()
  5097. "Test `org-deadline' specifications."
  5098. ;; Insert a new value or replace existing one.
  5099. (should
  5100. (equal "* H\nDEADLINE: <2012-03-29>"
  5101. (org-test-with-temp-text "* H"
  5102. (let ((org-adapt-indentation nil)
  5103. (org-last-inserted-timestamp nil))
  5104. (org-deadline nil "<2012-03-29 Tue>"))
  5105. (replace-regexp-in-string
  5106. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5107. nil nil 1))))
  5108. (should
  5109. (equal "* H\nDEADLINE: <2014-03-04>"
  5110. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5111. (let ((org-adapt-indentation nil)
  5112. (org-last-inserted-timestamp nil))
  5113. (org-deadline nil "<2014-03-04 Thu>"))
  5114. (replace-regexp-in-string
  5115. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5116. nil nil 1))))
  5117. ;; Accept delta time, e.g., "+2d".
  5118. (should
  5119. (equal "* H\nDEADLINE: <2015-03-04>"
  5120. (org-test-at-time "2014-03-04"
  5121. (org-test-with-temp-text "* H"
  5122. (let ((org-adapt-indentation nil)
  5123. (org-last-inserted-timestamp nil))
  5124. (org-deadline nil "+1y"))
  5125. (replace-regexp-in-string
  5126. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5127. ;; Preserve repeater.
  5128. (should
  5129. (equal "* H\nDEADLINE: <2012-03-29 +2y>"
  5130. (org-test-with-temp-text "* H"
  5131. (let ((org-adapt-indentation nil)
  5132. (org-last-inserted-timestamp nil))
  5133. (org-deadline nil "<2012-03-29 Tue +2y>"))
  5134. (replace-regexp-in-string
  5135. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5136. ;; Remove CLOSED keyword, if any.
  5137. (should
  5138. (equal "* H\nDEADLINE: <2012-03-29>"
  5139. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  5140. (let ((org-adapt-indentation nil)
  5141. (org-last-inserted-timestamp nil))
  5142. (org-deadline nil "<2012-03-29 Tue>"))
  5143. (replace-regexp-in-string
  5144. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5145. ;; With C-u argument, remove DEADLINE keyword.
  5146. (should
  5147. (equal "* H\n"
  5148. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5149. (let ((org-adapt-indentation nil)
  5150. (org-last-inserted-timestamp nil))
  5151. (org-deadline '(4)))
  5152. (buffer-string))))
  5153. (should
  5154. (equal "* H"
  5155. (org-test-with-temp-text "* H"
  5156. (let ((org-adapt-indentation nil)
  5157. (org-last-inserted-timestamp nil))
  5158. (org-deadline '(4)))
  5159. (buffer-string))))
  5160. ;; With C-u C-u argument, prompt for a delay cookie.
  5161. (should
  5162. (equal "* H\nDEADLINE: <2012-03-29 -705d>"
  5163. (cl-letf (((symbol-function 'org-read-date)
  5164. (lambda (&rest args)
  5165. (apply #'encode-time
  5166. (org-parse-time-string "2014-03-04")))))
  5167. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5168. (let ((org-adapt-indentation nil)
  5169. (org-last-inserted-timestamp nil))
  5170. (org-deadline '(16)))
  5171. (buffer-string)))))
  5172. (should-error
  5173. (cl-letf (((symbol-function 'org-read-date)
  5174. (lambda (&rest args)
  5175. (apply #'encode-time
  5176. (org-parse-time-string "2014-03-04")))))
  5177. (org-test-with-temp-text "* H"
  5178. (let ((org-adapt-indentation nil)
  5179. (org-last-inserted-timestamp nil))
  5180. (org-deadline '(16)))
  5181. (buffer-string))))
  5182. ;; When a region is active and
  5183. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5184. ;; same value in all headlines in region.
  5185. (should
  5186. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5187. (org-test-with-temp-text "* H1\n* H2"
  5188. (let ((org-adapt-indentation nil)
  5189. (org-last-inserted-timestamp nil)
  5190. (org-loop-over-headlines-in-active-region t))
  5191. (transient-mark-mode 1)
  5192. (push-mark (point) t t)
  5193. (goto-char (point-max))
  5194. (org-deadline nil "2012-03-29"))
  5195. (replace-regexp-in-string
  5196. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5197. (should-not
  5198. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5199. (org-test-with-temp-text "* H1\n* H2"
  5200. (let ((org-adapt-indentation nil)
  5201. (org-last-inserted-timestamp nil)
  5202. (org-loop-over-headlines-in-active-region nil))
  5203. (transient-mark-mode 1)
  5204. (push-mark (point) t t)
  5205. (goto-char (point-max))
  5206. (org-deadline nil "2012-03-29"))
  5207. (replace-regexp-in-string
  5208. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5209. (ert-deftest test-org/schedule ()
  5210. "Test `org-schedule' specifications."
  5211. ;; Insert a new value or replace existing one.
  5212. (should
  5213. (equal "* H\nSCHEDULED: <2012-03-29>"
  5214. (org-test-with-temp-text "* H"
  5215. (let ((org-adapt-indentation nil)
  5216. (org-last-inserted-timestamp nil))
  5217. (org-schedule nil "<2012-03-29 Tue>"))
  5218. (replace-regexp-in-string
  5219. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5220. nil nil 1))))
  5221. (should
  5222. (equal "* H\nSCHEDULED: <2014-03-04>"
  5223. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5224. (let ((org-adapt-indentation nil)
  5225. (org-last-inserted-timestamp nil))
  5226. (org-schedule nil "<2014-03-04 Thu>"))
  5227. (replace-regexp-in-string
  5228. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5229. nil nil 1))))
  5230. ;; Accept delta time, e.g., "+2d".
  5231. (should
  5232. (equal "* H\nSCHEDULED: <2015-03-04>"
  5233. (org-test-at-time "2014-03-04"
  5234. (org-test-with-temp-text "* H"
  5235. (let ((org-adapt-indentation nil)
  5236. (org-last-inserted-timestamp nil))
  5237. (org-schedule nil "+1y"))
  5238. (replace-regexp-in-string
  5239. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5240. ;; Preserve repeater.
  5241. (should
  5242. (equal "* H\nSCHEDULED: <2012-03-29 +2y>"
  5243. (org-test-with-temp-text "* H"
  5244. (let ((org-adapt-indentation nil)
  5245. (org-last-inserted-timestamp nil))
  5246. (org-schedule nil "<2012-03-29 Tue +2y>"))
  5247. (replace-regexp-in-string
  5248. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5249. ;; Remove CLOSED keyword, if any.
  5250. (should
  5251. (equal "* H\nSCHEDULED: <2012-03-29>"
  5252. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  5253. (let ((org-adapt-indentation nil)
  5254. (org-last-inserted-timestamp nil))
  5255. (org-schedule nil "<2012-03-29 Tue>"))
  5256. (replace-regexp-in-string
  5257. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5258. ;; With C-u argument, remove SCHEDULED keyword.
  5259. (should
  5260. (equal "* H\n"
  5261. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5262. (let ((org-adapt-indentation nil)
  5263. (org-last-inserted-timestamp nil))
  5264. (org-schedule '(4)))
  5265. (buffer-string))))
  5266. (should
  5267. (equal "* H"
  5268. (org-test-with-temp-text "* H"
  5269. (let ((org-adapt-indentation nil)
  5270. (org-last-inserted-timestamp nil))
  5271. (org-schedule '(4)))
  5272. (buffer-string))))
  5273. ;; With C-u C-u argument, prompt for a delay cookie.
  5274. (should
  5275. (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
  5276. (cl-letf (((symbol-function 'org-read-date)
  5277. (lambda (&rest args)
  5278. (apply #'encode-time
  5279. (org-parse-time-string "2014-03-04")))))
  5280. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5281. (let ((org-adapt-indentation nil)
  5282. (org-last-inserted-timestamp nil))
  5283. (org-schedule '(16)))
  5284. (buffer-string)))))
  5285. (should-error
  5286. (cl-letf (((symbol-function 'org-read-date)
  5287. (lambda (&rest args)
  5288. (apply #'encode-time
  5289. (org-parse-time-string "2014-03-04")))))
  5290. (org-test-with-temp-text "* H"
  5291. (let ((org-adapt-indentation nil)
  5292. (org-last-inserted-timestamp nil))
  5293. (org-schedule '(16)))
  5294. (buffer-string))))
  5295. ;; When a region is active and
  5296. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5297. ;; same value in all headlines in region.
  5298. (should
  5299. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5300. (org-test-with-temp-text "* H1\n* H2"
  5301. (let ((org-adapt-indentation nil)
  5302. (org-last-inserted-timestamp nil)
  5303. (org-loop-over-headlines-in-active-region t))
  5304. (transient-mark-mode 1)
  5305. (push-mark (point) t t)
  5306. (goto-char (point-max))
  5307. (org-schedule nil "2012-03-29"))
  5308. (replace-regexp-in-string
  5309. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5310. (should-not
  5311. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5312. (org-test-with-temp-text "* H1\n* H2"
  5313. (let ((org-adapt-indentation nil)
  5314. (org-last-inserted-timestamp nil)
  5315. (org-loop-over-headlines-in-active-region nil))
  5316. (transient-mark-mode 1)
  5317. (push-mark (point) t t)
  5318. (goto-char (point-max))
  5319. (org-schedule nil "2012-03-29"))
  5320. (replace-regexp-in-string
  5321. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5322. (should
  5323. ;; check if a repeater survives re-scheduling.
  5324. (string-match-p
  5325. "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
  5326. (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
  5327. (let ((org-adapt-indentation nil)
  5328. (org-last-inserted-timestamp nil))
  5329. (org-schedule nil "2017-02-01"))
  5330. (buffer-string)))))
  5331. ;;; Property API
  5332. (ert-deftest test-org/buffer-property-keys ()
  5333. "Test `org-buffer-property-keys' specifications."
  5334. ;; Retrieve properties across siblings.
  5335. (should
  5336. (equal '("A" "B")
  5337. (org-test-with-temp-text "
  5338. * H1
  5339. :PROPERTIES:
  5340. :A: 1
  5341. :END:
  5342. * H2
  5343. :PROPERTIES:
  5344. :B: 1
  5345. :END:"
  5346. (org-buffer-property-keys))))
  5347. ;; Retrieve properties across children.
  5348. (should
  5349. (equal '("A" "B")
  5350. (org-test-with-temp-text "
  5351. * H1
  5352. :PROPERTIES:
  5353. :A: 1
  5354. :END:
  5355. ** H2
  5356. :PROPERTIES:
  5357. :B: 1
  5358. :END:"
  5359. (org-buffer-property-keys))))
  5360. ;; Retrieve muliple properties in the same drawer.
  5361. (should
  5362. (equal '("A" "B")
  5363. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5364. (org-buffer-property-keys))))
  5365. ;; Ignore extension symbol in property name.
  5366. (should
  5367. (equal '("A")
  5368. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5369. (org-buffer-property-keys))))
  5370. ;; Add bare property if xxx_ALL property is there
  5371. (should
  5372. (equal '("A" "B" "B_ALL")
  5373. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B_ALL: foo bar\n:END:"
  5374. (org-buffer-property-keys))))
  5375. ;; Add bare property if xxx_ALL property is there - check dupes
  5376. (should
  5377. (equal '("A" "B" "B_ALL")
  5378. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:B_ALL: foo bar\n:END:"
  5379. (org-buffer-property-keys))))
  5380. ;; Retrieve properties from #+PROPERTY keyword lines
  5381. (should
  5382. (equal '("A" "C")
  5383. (org-test-with-temp-text "#+PROPERTY: C foo\n* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5384. (org-buffer-property-keys))))
  5385. ;; Retrieve properties from #+PROPERTY keyword lines - make sure an _ALL property also
  5386. ;; adds the bare property
  5387. (should
  5388. (equal '("A" "C" "C_ALL")
  5389. (org-test-with-temp-text "#+PROPERTY: C_ALL foo bar\n* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5390. (org-buffer-property-keys))))
  5391. ;; With non-nil COLUMNS, extract property names from columns.
  5392. (should
  5393. (equal '("A" "B")
  5394. (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
  5395. (org-buffer-property-keys nil nil t))))
  5396. (should
  5397. (equal '("A" "B" "COLUMNS")
  5398. (org-test-with-temp-text
  5399. "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
  5400. (org-buffer-property-keys nil nil t))))
  5401. ;; In COLUMNS, ignore title and summary-type.
  5402. (should
  5403. (equal '("A")
  5404. (org-test-with-temp-text "#+COLUMNS: %A(Foo)"
  5405. (org-buffer-property-keys nil nil t))))
  5406. (should
  5407. (equal '("A")
  5408. (org-test-with-temp-text "#+COLUMNS: %A{Foo}"
  5409. (org-buffer-property-keys nil nil t))))
  5410. (should
  5411. (equal '("A")
  5412. (org-test-with-temp-text "#+COLUMNS: %A(Foo){Bar}"
  5413. (org-buffer-property-keys nil nil t)))))
  5414. (ert-deftest test-org/property-values ()
  5415. "Test `org-property-values' specifications."
  5416. ;; Regular test.
  5417. (should
  5418. (equal '("2" "1")
  5419. (org-test-with-temp-text
  5420. "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
  5421. (org-property-values "A"))))
  5422. ;; Ignore empty values.
  5423. (should-not
  5424. (org-test-with-temp-text
  5425. "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
  5426. (org-property-values "A")))
  5427. ;; Take into consideration extended values.
  5428. (should
  5429. (equal '("1 2")
  5430. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5431. (org-property-values "A")))))
  5432. (ert-deftest test-org/set-property ()
  5433. "Test `org-set-property' specifications."
  5434. (should
  5435. (equal
  5436. ":PROPERTIES:\n:TEST: t\n:END:\n"
  5437. (org-test-with-temp-text ""
  5438. (let ((org-property-format "%s %s"))
  5439. (org-set-property "TEST" "t"))
  5440. (buffer-string))))
  5441. (should
  5442. (equal
  5443. "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5444. (org-test-with-temp-text "* H"
  5445. (let ((org-adapt-indentation nil)
  5446. (org-property-format "%s %s"))
  5447. (org-set-property "TEST" "t"))
  5448. (buffer-string)))))
  5449. (ert-deftest test-org/delete-property ()
  5450. "Test `org-delete-property' specifications."
  5451. (should
  5452. (equal
  5453. ""
  5454. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5455. (org-delete-property "TEST")
  5456. (buffer-string))))
  5457. (should
  5458. (equal
  5459. ":PROPERTIES:\n:TEST1: t\n:END:\n"
  5460. (org-test-with-temp-text ":PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5461. (org-delete-property "TEST2")
  5462. (buffer-string))))
  5463. (should
  5464. (equal
  5465. "* H\n"
  5466. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5467. (org-delete-property "TEST")
  5468. (buffer-string))))
  5469. (should
  5470. (equal
  5471. "* H\n:PROPERTIES:\n:TEST1: t\n:END:\n"
  5472. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5473. (org-delete-property "TEST2")
  5474. (buffer-string)))))
  5475. (ert-deftest test-org/delete-property-globally ()
  5476. "Test `org-delete-property-global' specifications."
  5477. (should
  5478. (equal
  5479. ""
  5480. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5481. (org-delete-property-globally "TEST")
  5482. (buffer-string))))
  5483. (should
  5484. (equal
  5485. "* H\n"
  5486. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n* H\n:PROPERTIES:\n:TEST: nil\n:END:"
  5487. (org-delete-property-globally "TEST")
  5488. (buffer-string)))))
  5489. (ert-deftest test-org/find-property ()
  5490. "Test `org-find-property' specifications."
  5491. ;; Regular test.
  5492. (should
  5493. (= 1
  5494. (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
  5495. (org-find-property "prop"))))
  5496. ;; Find properties in top-level property drawer.
  5497. (should
  5498. (= 1
  5499. (org-test-with-temp-text ":PROPERTIES:\n:PROP: value\n:END:"
  5500. (org-find-property "prop"))))
  5501. ;; Ignore false positives.
  5502. (should
  5503. (= 27
  5504. (org-test-with-temp-text
  5505. "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
  5506. (org-find-property "A"))))
  5507. ;; Return first entry found in buffer.
  5508. (should
  5509. (= 1
  5510. (org-test-with-temp-text
  5511. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5512. (org-find-property "A"))))
  5513. ;; Only search visible part of the buffer.
  5514. (should
  5515. (= 31
  5516. (org-test-with-temp-text
  5517. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5518. (org-narrow-to-subtree)
  5519. (org-find-property "A"))))
  5520. ;; With optional argument, only find entries with a specific value.
  5521. (should-not
  5522. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5523. (org-find-property "A" "2")))
  5524. (should
  5525. (= 31
  5526. (org-test-with-temp-text
  5527. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
  5528. (org-find-property "A" "2"))))
  5529. ;; Use "nil" for explicit nil values.
  5530. (should
  5531. (= 31
  5532. (org-test-with-temp-text
  5533. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
  5534. (org-find-property "A" "nil")))))
  5535. (ert-deftest test-org/entry-delete ()
  5536. "Test `org-entry-delete' specifications."
  5537. ;; Regular test.
  5538. (should
  5539. (string-match
  5540. " *:PROPERTIES:\n *:B: +2\n *:END:"
  5541. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5542. (org-entry-delete (point) "A")
  5543. (buffer-string))))
  5544. ;; Also remove accumulated properties.
  5545. (should-not
  5546. (string-match
  5547. ":A"
  5548. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
  5549. (org-entry-delete (point) "A")
  5550. (buffer-string))))
  5551. ;; When last property is removed, remove the property drawer.
  5552. (should-not
  5553. (string-match
  5554. ":PROPERTIES:"
  5555. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
  5556. (org-entry-delete (point) "A")
  5557. (buffer-string))))
  5558. ;; Return a non-nil value when some property was removed.
  5559. (should
  5560. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5561. (org-entry-delete (point) "A")))
  5562. (should-not
  5563. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5564. (org-entry-delete (point) "C")))
  5565. ;; Special properties cannot be located in a drawer. Allow to
  5566. ;; remove them anyway, in case of user error.
  5567. (should
  5568. (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
  5569. (org-entry-delete (point) "SCHEDULED"))))
  5570. (ert-deftest test-org/entry-get ()
  5571. "Test `org-entry-get' specifications."
  5572. ;; Regular test.
  5573. (should
  5574. (equal "1"
  5575. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:"
  5576. (org-entry-get (point) "A"))))
  5577. (should
  5578. (equal "1"
  5579. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5580. (org-entry-get (point) "A"))))
  5581. ;; Ignore case.
  5582. (should
  5583. (equal "1"
  5584. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5585. (org-entry-get (point) "a"))))
  5586. ;; Handle extended values, both before and after base value.
  5587. (should
  5588. (equal "1 2 3"
  5589. (org-test-with-temp-text
  5590. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5591. (org-entry-get (point) "A"))))
  5592. ;; Empty values are returned as the empty string.
  5593. (should
  5594. (equal ""
  5595. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
  5596. (org-entry-get (point) "A"))))
  5597. ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
  5598. ;; otherwise, return nil.
  5599. (should-not
  5600. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5601. (org-entry-get (point) "A")))
  5602. (should
  5603. (equal "nil"
  5604. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5605. (org-entry-get (point) "A" nil t))))
  5606. ;; Return nil when no property is found, independently on the
  5607. ;; LITERAL-NIL argument.
  5608. (should-not
  5609. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5610. (org-entry-get (point) "B")))
  5611. (should-not
  5612. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5613. (org-entry-get (point) "B" nil t)))
  5614. ;; Handle inheritance, when allowed. Include extended values and
  5615. ;; possibly global values.
  5616. (should
  5617. (equal
  5618. "1"
  5619. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:\n* H"
  5620. (org-entry-get (point-max) "A" t))))
  5621. (should
  5622. (equal
  5623. "1"
  5624. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5625. (org-entry-get (point-max) "A" t))))
  5626. (should
  5627. (equal
  5628. "1"
  5629. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5630. (let ((org-use-property-inheritance t))
  5631. (org-entry-get (point-max) "A" 'selective)))))
  5632. (should-not
  5633. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5634. (let ((org-use-property-inheritance nil))
  5635. (org-entry-get (point-max) "A" 'selective))))
  5636. (should
  5637. (equal
  5638. "1 2"
  5639. (org-test-with-temp-text
  5640. ":PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5641. (org-entry-get (point-max) "A" t))))
  5642. (should
  5643. (equal
  5644. "1 2"
  5645. (org-test-with-temp-text
  5646. "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5647. (org-entry-get (point-max) "A" t))))
  5648. (should
  5649. (equal
  5650. "1 2"
  5651. (org-test-with-temp-text
  5652. ":PROPERTIES:\n:A: 1\n:END:\n* H1\n* H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5653. (org-entry-get (point-max) "A" t))))
  5654. (should
  5655. (equal
  5656. "1 2"
  5657. (org-test-with-temp-text
  5658. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2.1\n* H2.2\n:PROPERTIES:\n:A+: 2\n:END:"
  5659. (org-entry-get (point-max) "A" t))))
  5660. (should
  5661. (equal "1"
  5662. (org-test-with-temp-text
  5663. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
  5664. (org-mode-restart)
  5665. (org-entry-get (point-max) "A" t))))
  5666. (should
  5667. (equal "0 1"
  5668. (org-test-with-temp-text
  5669. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
  5670. (org-mode-restart)
  5671. (org-entry-get (point-max) "A" t))))
  5672. ;; document level property-drawer has precedance over
  5673. ;; global-property by PROPERTY-keyword.
  5674. (should
  5675. (equal "0 2"
  5676. (org-test-with-temp-text
  5677. ":PROPERTIES:\n:A: 0\n:END:\n#+PROPERTY: A 1\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5678. (org-mode-restart)
  5679. (org-entry-get (point-max) "A" t)))))
  5680. (ert-deftest test-org/entry-properties ()
  5681. "Test `org-entry-properties' specifications."
  5682. ;; Get "ITEM" property.
  5683. (should
  5684. (equal "H"
  5685. (org-test-with-temp-text "* TODO H"
  5686. (cdr (assoc "ITEM" (org-entry-properties nil "ITEM"))))))
  5687. (should
  5688. (equal "H"
  5689. (org-test-with-temp-text "* TODO H"
  5690. (cdr (assoc "ITEM" (org-entry-properties))))))
  5691. ;; Get "TODO" property. TODO keywords are case sensitive.
  5692. (should
  5693. (equal "TODO"
  5694. (org-test-with-temp-text "* TODO H"
  5695. (cdr (assoc "TODO" (org-entry-properties nil "TODO"))))))
  5696. (should
  5697. (equal "TODO"
  5698. (org-test-with-temp-text "* TODO H"
  5699. (cdr (assoc "TODO" (org-entry-properties))))))
  5700. (should-not
  5701. (org-test-with-temp-text "* H"
  5702. (assoc "TODO" (org-entry-properties nil "TODO"))))
  5703. (should-not
  5704. (org-test-with-temp-text "* todo H"
  5705. (assoc "TODO" (org-entry-properties nil "TODO"))))
  5706. ;; Get "PRIORITY" property.
  5707. (should
  5708. (equal "A"
  5709. (org-test-with-temp-text "* [#A] H"
  5710. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  5711. (should
  5712. (equal "A"
  5713. (org-test-with-temp-text "* [#A] H"
  5714. (cdr (assoc "PRIORITY" (org-entry-properties))))))
  5715. (should
  5716. (equal (char-to-string org-priority-default)
  5717. (org-test-with-temp-text "* H"
  5718. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  5719. ;; Get "FILE" property.
  5720. (should
  5721. (org-test-with-temp-text-in-file "* H\nParagraph"
  5722. (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil "FILE")))
  5723. (buffer-file-name))))
  5724. (should
  5725. (org-test-with-temp-text-in-file "* H\nParagraph"
  5726. (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
  5727. (buffer-file-name))))
  5728. (should-not
  5729. (org-test-with-temp-text "* H\nParagraph"
  5730. (cdr (assoc "FILE" (org-entry-properties nil "FILE")))))
  5731. ;; Get "TAGS" property.
  5732. (should
  5733. (equal ":tag1:tag2:"
  5734. (org-test-with-temp-text "* H :tag1:tag2:"
  5735. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS"))))))
  5736. (should
  5737. (equal ":tag1:tag2:"
  5738. (org-test-with-temp-text "* H :tag1:tag2:"
  5739. (cdr (assoc "TAGS" (org-entry-properties))))))
  5740. (should-not
  5741. (org-test-with-temp-text "* H"
  5742. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS")))))
  5743. ;; Get "ALLTAGS" property.
  5744. (should
  5745. (equal ":tag1:tag2:"
  5746. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  5747. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS"))))))
  5748. (should
  5749. (equal ":tag1:tag2:"
  5750. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  5751. (cdr (assoc "ALLTAGS" (org-entry-properties))))))
  5752. (should-not
  5753. (org-test-with-temp-text "* H"
  5754. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS")))))
  5755. ;; Get "BLOCKED" property.
  5756. (should
  5757. (equal "t"
  5758. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  5759. (let ((org-enforce-todo-dependencies t)
  5760. (org-blocker-hook
  5761. '(org-block-todo-from-children-or-siblings-or-parent)))
  5762. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  5763. (should
  5764. (equal ""
  5765. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  5766. (let ((org-enforce-todo-dependencies t)
  5767. (org-blocker-hook
  5768. '(org-block-todo-from-children-or-siblings-or-parent)))
  5769. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  5770. ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
  5771. (should
  5772. (equal
  5773. "[2012-03-29 thu.]"
  5774. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  5775. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED"))))))
  5776. (should
  5777. (equal
  5778. "[2012-03-29 thu.]"
  5779. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  5780. (cdr (assoc "CLOSED" (org-entry-properties))))))
  5781. (should-not
  5782. (org-test-with-temp-text "* H"
  5783. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED")))))
  5784. (should
  5785. (equal
  5786. "<2014-03-04 tue.>"
  5787. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5788. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE"))))))
  5789. (should
  5790. (equal
  5791. "<2014-03-04 tue.>"
  5792. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5793. (cdr (assoc "DEADLINE" (org-entry-properties))))))
  5794. (should-not
  5795. (org-test-with-temp-text "* H"
  5796. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE")))))
  5797. (should
  5798. (equal
  5799. "<2014-03-04 tue.>"
  5800. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5801. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED"))))))
  5802. (should
  5803. (equal
  5804. "<2014-03-04 tue.>"
  5805. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5806. (cdr (assoc "SCHEDULED" (org-entry-properties))))))
  5807. (should-not
  5808. (org-test-with-temp-text "* H"
  5809. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED")))))
  5810. ;; Get "CATEGORY"
  5811. (should
  5812. (equal "cat"
  5813. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  5814. (cdr (assoc "CATEGORY" (org-entry-properties))))))
  5815. (should
  5816. (equal "cat"
  5817. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  5818. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5819. (should
  5820. (equal "cat"
  5821. (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
  5822. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5823. (should
  5824. (equal "cat2"
  5825. (org-test-with-temp-text
  5826. (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  5827. "\n"
  5828. "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
  5829. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5830. ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
  5831. (should
  5832. (equal "<2012-03-29 thu.>"
  5833. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
  5834. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  5835. (should
  5836. (equal "[2012-03-29 thu.]"
  5837. (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
  5838. (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
  5839. (should
  5840. (equal "<2012-03-29 thu.>"
  5841. (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
  5842. (cdr (assoc "TIMESTAMP" (org-entry-properties nil "TIMESTAMP"))))))
  5843. (should
  5844. (equal "[2014-03-04 tue.]"
  5845. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
  5846. (cdr (assoc "TIMESTAMP_IA"
  5847. (org-entry-properties nil "TIMESTAMP_IA"))))))
  5848. (should-not
  5849. (equal "<2012-03-29 thu.>"
  5850. (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
  5851. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  5852. ;; Get standard properties.
  5853. (should
  5854. (equal "1"
  5855. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5856. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5857. ;; Handle extended properties.
  5858. (should
  5859. (equal "1 2 3"
  5860. (org-test-with-temp-text
  5861. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5862. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5863. (should
  5864. (equal "1 2 3"
  5865. (org-test-with-temp-text
  5866. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
  5867. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5868. ;; Ignore forbidden (special) properties.
  5869. (should-not
  5870. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
  5871. (cdr (assoc "TODO" (org-entry-properties nil 'standard))))))
  5872. (ert-deftest test-org/entry-put ()
  5873. "Test `org-entry-put' specifications."
  5874. ;; Error when not a string or nil.
  5875. (should-error
  5876. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5877. (org-entry-put 1 "test" 2)))
  5878. ;; Error when property name is invalid.
  5879. (should-error
  5880. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5881. (org-entry-put 1 "no space" "value")))
  5882. (should-error
  5883. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5884. (org-entry-put 1 "" "value")))
  5885. ;; Set "TODO" property.
  5886. (should
  5887. (string-match (regexp-quote " TODO H")
  5888. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  5889. (org-entry-put (point) "TODO" "TODO")
  5890. (buffer-string))))
  5891. (should
  5892. (string-match (regexp-quote "* H")
  5893. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  5894. (org-entry-put (point) "TODO" nil)
  5895. (buffer-string))))
  5896. ;; Set "PRIORITY" property.
  5897. (should
  5898. (equal "* [#A] H"
  5899. (org-test-with-temp-text "* [#B] H"
  5900. (org-entry-put (point) "PRIORITY" "A")
  5901. (buffer-string))))
  5902. (should
  5903. (equal "* H"
  5904. (org-test-with-temp-text "* [#B] H"
  5905. (org-entry-put (point) "PRIORITY" nil)
  5906. (buffer-string))))
  5907. ;; Set "SCHEDULED" property.
  5908. (should
  5909. (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
  5910. (org-test-with-temp-text "* H"
  5911. (org-entry-put (point) "SCHEDULED" "2014-03-04")
  5912. (buffer-string))))
  5913. (should
  5914. (string= "* H\n"
  5915. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5916. (org-entry-put (point) "SCHEDULED" nil)
  5917. (buffer-string))))
  5918. (should
  5919. (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
  5920. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5921. (org-entry-put (point) "SCHEDULED" "earlier")
  5922. (buffer-string))))
  5923. (should
  5924. (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
  5925. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5926. (org-entry-put (point) "SCHEDULED" "later")
  5927. (buffer-string))))
  5928. ;; Set "DEADLINE" property.
  5929. (should
  5930. (string-match "^ *DEADLINE: <2014-03-04 .*?>"
  5931. (org-test-with-temp-text "* H"
  5932. (org-entry-put (point) "DEADLINE" "2014-03-04")
  5933. (buffer-string))))
  5934. (should
  5935. (string= "* H\n"
  5936. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5937. (org-entry-put (point) "DEADLINE" nil)
  5938. (buffer-string))))
  5939. (should
  5940. (string-match "^ *DEADLINE: <2014-03-03 .*?>"
  5941. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5942. (org-entry-put (point) "DEADLINE" "earlier")
  5943. (buffer-string))))
  5944. (should
  5945. (string-match "^ *DEADLINE: <2014-03-05 .*?>"
  5946. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5947. (org-entry-put (point) "DEADLINE" "later")
  5948. (buffer-string))))
  5949. ;; Set "CATEGORY" property
  5950. (should
  5951. (string-match "^ *:CATEGORY: cat"
  5952. (org-test-with-temp-text "* H"
  5953. (org-entry-put (point) "CATEGORY" "cat")
  5954. (buffer-string))))
  5955. ;; Regular properties, with or without pre-existing drawer.
  5956. (should
  5957. (string-match "^ *:A: +2$"
  5958. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5959. (org-entry-put (point) "A" "2")
  5960. (buffer-string))))
  5961. (should
  5962. (string-match "^ *:A: +1$"
  5963. (org-test-with-temp-text "* H"
  5964. (org-entry-put (point) "A" "1")
  5965. (buffer-string))))
  5966. ;; Special case: two consecutive headlines.
  5967. (should
  5968. (string-match "\\* A\n *:PROPERTIES:"
  5969. (org-test-with-temp-text "* A\n** B"
  5970. (org-entry-put (point) "A" "1")
  5971. (buffer-string)))))
  5972. (ert-deftest test-org/refresh-properties ()
  5973. "Test `org-refresh-properties' specifications."
  5974. (should
  5975. (equal "1"
  5976. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5977. (org-refresh-properties "A" 'org-test)
  5978. (get-text-property (point) 'org-test))))
  5979. (should-not
  5980. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5981. (org-refresh-properties "B" 'org-test)
  5982. (get-text-property (point) 'org-test)))
  5983. ;; Handle properties only defined with extension syntax, i.e.,
  5984. ;; "PROPERTY+".
  5985. (should
  5986. (equal "1"
  5987. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
  5988. (org-refresh-properties "A" 'org-test)
  5989. (get-text-property (point) 'org-test))))
  5990. ;; When property is inherited, add text property to the whole
  5991. ;; sub-tree.
  5992. (should
  5993. (equal "1"
  5994. (org-test-with-temp-text
  5995. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
  5996. (let ((org-use-property-inheritance t))
  5997. (org-refresh-properties "A" 'org-test))
  5998. (get-text-property (point) 'org-test))))
  5999. ;; When a document level property-drawer is used, those properties
  6000. ;; should work exactly like headline-properties as if at a
  6001. ;; headline-level 0.
  6002. (should
  6003. (equal "1"
  6004. (org-test-with-temp-text
  6005. ":PROPERTIES:\n:A: 1\n:END:\n"
  6006. (org-mode-restart)
  6007. (let ((org-use-property-inheritance t))
  6008. (org-refresh-properties "A" 'org-test))
  6009. (get-text-property (point) 'org-test))))
  6010. (should-not
  6011. (equal "1"
  6012. (org-test-with-temp-text
  6013. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  6014. (org-mode-restart)
  6015. (let ((org-use-property-inheritance nil))
  6016. (org-refresh-properties "A" 'org-test))
  6017. (get-text-property (point) 'org-test))))
  6018. (should
  6019. (equal "1"
  6020. (org-test-with-temp-text
  6021. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  6022. (org-mode-restart)
  6023. (let ((org-use-property-inheritance t))
  6024. (org-refresh-properties "A" 'org-test))
  6025. (get-text-property (point) 'org-test))))
  6026. (should
  6027. (equal "2"
  6028. (org-test-with-temp-text
  6029. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1\n:PROPERTIES:\n:A: 2\n:END:"
  6030. (org-mode-restart)
  6031. (let ((org-use-property-inheritance t))
  6032. (org-refresh-properties "A" 'org-test))
  6033. (get-text-property (point) 'org-test))))
  6034. ;; When property is inherited, use global value across the whole
  6035. ;; buffer. However local values have precedence, as well as the
  6036. ;; document level property-drawer.
  6037. (should-not
  6038. (equal "1"
  6039. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  6040. (org-mode-restart)
  6041. (let ((org-use-property-inheritance nil))
  6042. (org-refresh-properties "A" 'org-test))
  6043. (get-text-property (point) 'org-test))))
  6044. (should
  6045. (equal "1"
  6046. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  6047. (org-mode-restart)
  6048. (let ((org-use-property-inheritance t))
  6049. (org-refresh-properties "A" 'org-test))
  6050. (get-text-property (point) 'org-test))))
  6051. (should
  6052. (equal "2"
  6053. (org-test-with-temp-text
  6054. "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
  6055. (org-mode-restart)
  6056. (let ((org-use-property-inheritance t))
  6057. (org-refresh-properties "A" 'org-test))
  6058. (get-text-property (point) 'org-test))))
  6059. ;; When both keyword-property and document-level property-block is
  6060. ;; defined, the property-block has precedance.
  6061. (should
  6062. (equal "1"
  6063. (org-test-with-temp-text
  6064. ":PROPERTIES:\n:A: 1\n:END:\n#+PROPERTY: A 2\n<point>* H1"
  6065. (org-mode-restart)
  6066. (let ((org-use-property-inheritance t))
  6067. (org-refresh-properties "A" 'org-test))
  6068. (get-text-property (point) 'org-test)))))
  6069. (ert-deftest test-org/refresh-category-properties ()
  6070. "Test `org-refresh-category-properties' specifications"
  6071. (should
  6072. (equal "cat1"
  6073. (org-test-with-temp-text
  6074. ":PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6075. (org-refresh-category-properties)
  6076. (get-text-property (point) 'org-category))))
  6077. (should
  6078. (equal "cat1"
  6079. (org-test-with-temp-text
  6080. "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6081. (org-refresh-category-properties)
  6082. (get-text-property (point) 'org-category))))
  6083. ;; Even though property-inheritance is deactivated, category
  6084. ;; property should be inherited. As described in
  6085. ;; `org-use-property-inheritance'.
  6086. (should
  6087. (equal "cat1"
  6088. (org-test-with-temp-text
  6089. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  6090. (org-mode-restart)
  6091. (let ((org-use-property-inheritance nil))
  6092. (org-refresh-category-properties))
  6093. (get-text-property (point) 'org-category))))
  6094. (should
  6095. (equal "cat1"
  6096. (org-test-with-temp-text
  6097. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  6098. (org-mode-restart)
  6099. (let ((org-use-property-inheritance t))
  6100. (org-refresh-category-properties))
  6101. (get-text-property (point) 'org-category))))
  6102. (should
  6103. (equal "cat2"
  6104. (org-test-with-temp-text
  6105. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H\n:PROPERTIES:\n:CATEGORY: cat2\n:END:\n"
  6106. (org-mode-restart)
  6107. (let ((org-use-property-inheritance t))
  6108. (org-refresh-category-properties))
  6109. (get-text-property (point) 'org-category)))))
  6110. ;;; Refile
  6111. (ert-deftest test-org/refile-get-targets ()
  6112. "Test `org-refile-get-targets' specifications."
  6113. ;; :maxlevel includes all headings above specified value.
  6114. (should
  6115. (equal '("H1" "H2" "H3")
  6116. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6117. (let ((org-refile-use-outline-path nil)
  6118. (org-refile-targets `((nil :maxlevel . 3))))
  6119. (mapcar #'car (org-refile-get-targets))))))
  6120. (should
  6121. (equal '("H1" "H2")
  6122. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6123. (let ((org-refile-use-outline-path nil)
  6124. (org-refile-targets `((nil :maxlevel . 2))))
  6125. (mapcar #'car (org-refile-get-targets))))))
  6126. ;; :level limits targets to headlines with the specified level.
  6127. (should
  6128. (equal '("H2")
  6129. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6130. (let ((org-refile-use-outline-path nil)
  6131. (org-refile-targets `((nil :level . 2))))
  6132. (mapcar #'car (org-refile-get-targets))))))
  6133. ;; :tag limits targets to headlines with specified tag.
  6134. (should
  6135. (equal '("H1")
  6136. (org-test-with-temp-text "* H1 :foo:\n** H2\n*** H3 :bar:"
  6137. (let ((org-refile-use-outline-path nil)
  6138. (org-refile-targets `((nil :tag . "foo"))))
  6139. (mapcar #'car (org-refile-get-targets))))))
  6140. ;; :todo limits targets to headlines with specified TODO keyword.
  6141. (should
  6142. (equal '("H2")
  6143. (org-test-with-temp-text "* H1\n** TODO H2\n*** DONE H3"
  6144. (let ((org-refile-use-outline-path nil)
  6145. (org-refile-targets `((nil :todo . "TODO"))))
  6146. (mapcar #'car (org-refile-get-targets))))))
  6147. ;; :regexp filters targets matching provided regexp.
  6148. (should
  6149. (equal '("F2" "F3")
  6150. (org-test-with-temp-text "* H1\n** F2\n*** F3"
  6151. (let ((org-refile-use-outline-path nil)
  6152. (org-refile-targets `((nil :regexp . "F"))))
  6153. (mapcar #'car (org-refile-get-targets))))))
  6154. ;; A nil `org-refile-targets' includes only top level headlines in
  6155. ;; current buffer.
  6156. (should
  6157. (equal '("H1" "H2")
  6158. (org-test-with-temp-text "* H1\n** S1\n* H2"
  6159. (let ((org-refile-use-outline-path nil)
  6160. (org-refile-targets nil))
  6161. (mapcar #'car (org-refile-get-targets))))))
  6162. ;; Return value is the union of the targets according to all the
  6163. ;; defined rules. However, prevent duplicates.
  6164. (should
  6165. (equal '("F2" "F3" "H1")
  6166. (org-test-with-temp-text "* TODO H1\n** F2\n*** F3"
  6167. (let ((org-refile-use-outline-path nil)
  6168. (org-refile-targets `((nil :regexp . "F")
  6169. (nil :todo . "TODO"))))
  6170. (mapcar #'car (org-refile-get-targets))))))
  6171. (should
  6172. (equal '("F2" "F3" "H1")
  6173. (org-test-with-temp-text "* TODO H1\n** TODO F2\n*** F3"
  6174. (let ((org-refile-use-outline-path nil)
  6175. (org-refile-targets `((nil :regexp . "F")
  6176. (nil :todo . "TODO"))))
  6177. (mapcar #'car (org-refile-get-targets))))))
  6178. ;; When `org-refile-use-outline-path' is non-nil, provide targets as
  6179. ;; paths.
  6180. (should
  6181. (equal '("H1" "H1/H2" "H1/H2/H3")
  6182. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6183. (let ((org-refile-use-outline-path t)
  6184. (org-refile-targets `((nil :maxlevel . 3))))
  6185. (mapcar #'car (org-refile-get-targets))))))
  6186. ;; When providing targets as paths, escape forward slashes in
  6187. ;; headings with backslashes.
  6188. (should
  6189. (equal '("H1\\/foo")
  6190. (org-test-with-temp-text "* H1/foo"
  6191. (let ((org-refile-use-outline-path t)
  6192. (org-refile-targets `((nil :maxlevel . 1))))
  6193. (mapcar #'car (org-refile-get-targets))))))
  6194. ;; When `org-refile-use-outline-path' is `file', include file name
  6195. ;; without directory in targets.
  6196. (should
  6197. (org-test-with-temp-text-in-file "* H1"
  6198. (let* ((filename (buffer-file-name))
  6199. (org-refile-use-outline-path 'file)
  6200. (org-refile-targets `(((,filename) :level . 1))))
  6201. (member (file-name-nondirectory filename)
  6202. (mapcar #'car (org-refile-get-targets))))))
  6203. ;; When `org-refile-use-outline-path' is `full-file-path', include
  6204. ;; full file name.
  6205. (should
  6206. (org-test-with-temp-text-in-file "* H1"
  6207. (let* ((filename (file-truename (buffer-file-name)))
  6208. (org-refile-use-outline-path 'full-file-path)
  6209. (org-refile-targets `(((,filename) :level . 1))))
  6210. (member filename (mapcar #'car (org-refile-get-targets))))))
  6211. ;; When `org-refile-use-outline-path' is `buffer-name', include
  6212. ;; buffer name.
  6213. (should
  6214. (org-test-with-temp-text "* H1"
  6215. (let* ((org-refile-use-outline-path 'buffer-name)
  6216. (org-refile-targets `((nil :level . 1))))
  6217. (member (buffer-name) (mapcar #'car (org-refile-get-targets)))))))
  6218. ;;; Sparse trees
  6219. (ert-deftest test-org/match-sparse-tree ()
  6220. "Test `org-match-sparse-tree' specifications."
  6221. ;; Match tags.
  6222. (should-not
  6223. (org-test-with-temp-text "* H\n** H1 :tag:"
  6224. (org-match-sparse-tree nil "tag")
  6225. (search-forward "H1")
  6226. (org-invisible-p2)))
  6227. (should
  6228. (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
  6229. (org-match-sparse-tree nil "tag")
  6230. (search-forward "H2")
  6231. (org-invisible-p2)))
  6232. ;; "-" operator for tags.
  6233. (should-not
  6234. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6235. (org-match-sparse-tree nil "tag1-tag2")
  6236. (search-forward "H1")
  6237. (org-invisible-p2)))
  6238. (should
  6239. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6240. (org-match-sparse-tree nil "tag1-tag2")
  6241. (search-forward "H2")
  6242. (org-invisible-p2)))
  6243. ;; "&" operator for tags.
  6244. (should
  6245. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6246. (org-match-sparse-tree nil "tag1&tag2")
  6247. (search-forward "H1")
  6248. (org-invisible-p2)))
  6249. (should-not
  6250. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6251. (org-match-sparse-tree nil "tag1&tag2")
  6252. (search-forward "H2")
  6253. (org-invisible-p2)))
  6254. ;; "|" operator for tags.
  6255. (should-not
  6256. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6257. (org-match-sparse-tree nil "tag1|tag2")
  6258. (search-forward "H1")
  6259. (org-invisible-p2)))
  6260. (should-not
  6261. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6262. (org-match-sparse-tree nil "tag1|tag2")
  6263. (search-forward "H2")
  6264. (org-invisible-p2)))
  6265. ;; Regexp match on tags.
  6266. (should-not
  6267. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6268. (org-match-sparse-tree nil "{^tag.*}")
  6269. (search-forward "H1")
  6270. (org-invisible-p2)))
  6271. (should
  6272. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6273. (org-match-sparse-tree nil "{^tag.*}")
  6274. (search-forward "H2")
  6275. (org-invisible-p2)))
  6276. ;; Match group tags.
  6277. (should-not
  6278. (org-test-with-temp-text
  6279. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6280. (org-match-sparse-tree nil "work")
  6281. (search-forward "H1")
  6282. (org-invisible-p2)))
  6283. (should-not
  6284. (org-test-with-temp-text
  6285. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6286. (org-match-sparse-tree nil "work")
  6287. (search-forward "H2")
  6288. (org-invisible-p2)))
  6289. ;; Match group tags with hard brackets.
  6290. (should-not
  6291. (org-test-with-temp-text
  6292. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6293. (org-match-sparse-tree nil "work")
  6294. (search-forward "H1")
  6295. (org-invisible-p2)))
  6296. (should-not
  6297. (org-test-with-temp-text
  6298. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6299. (org-match-sparse-tree nil "work")
  6300. (search-forward "H2")
  6301. (org-invisible-p2)))
  6302. ;; Match tags in hierarchies
  6303. (should-not
  6304. (org-test-with-temp-text
  6305. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6306. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6307. #+TAGS: { Lev_3 : Lev_4 }\n
  6308. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6309. (org-match-sparse-tree nil "Lev_1")
  6310. (search-forward "H4")
  6311. (org-invisible-p2)))
  6312. (should-not
  6313. (org-test-with-temp-text
  6314. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6315. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6316. #+TAGS: { Lev_3 : Lev_4 }\n
  6317. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6318. (org-match-sparse-tree nil "Lev_1+Lev_3")
  6319. (search-forward "H4")
  6320. (org-invisible-p2)))
  6321. ;; Match regular expressions in tags
  6322. (should-not
  6323. (org-test-with-temp-text
  6324. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
  6325. (org-match-sparse-tree nil "Lev")
  6326. (search-forward "H1")
  6327. (org-invisible-p2)))
  6328. (should
  6329. (org-test-with-temp-text
  6330. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
  6331. (org-match-sparse-tree nil "Lev")
  6332. (search-forward "H1")
  6333. (org-invisible-p2)))
  6334. ;; Match properties.
  6335. (should
  6336. (org-test-with-temp-text
  6337. "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
  6338. (org-match-sparse-tree nil "A=\"1\"")
  6339. (search-forward "H2")
  6340. (org-invisible-p2)))
  6341. (should-not
  6342. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6343. (org-match-sparse-tree nil "A=\"1\"")
  6344. (search-forward "H2")
  6345. (org-invisible-p2)))
  6346. ;; Case is not significant when matching properties.
  6347. (should-not
  6348. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6349. (org-match-sparse-tree nil "a=\"1\"")
  6350. (search-forward "H2")
  6351. (org-invisible-p2)))
  6352. (should-not
  6353. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
  6354. (org-match-sparse-tree nil "A=\"1\"")
  6355. (search-forward "H2")
  6356. (org-invisible-p2)))
  6357. ;; Match special LEVEL property.
  6358. (should-not
  6359. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6360. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6361. (search-forward "H1")
  6362. (org-invisible-p2)))
  6363. (should
  6364. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6365. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6366. (search-forward "H2")
  6367. (org-invisible-p2)))
  6368. ;; Comparison operators when matching properties.
  6369. (should
  6370. (org-test-with-temp-text
  6371. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6372. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6373. (search-forward "H1")
  6374. (org-invisible-p2)))
  6375. (should-not
  6376. (org-test-with-temp-text
  6377. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6378. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6379. (search-forward "H2")
  6380. (org-invisible-p2)))
  6381. ;; Regexp match on properties values.
  6382. (should-not
  6383. (org-test-with-temp-text
  6384. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6385. (org-match-sparse-tree nil "A={f.*}")
  6386. (search-forward "H1")
  6387. (org-invisible-p2)))
  6388. (should
  6389. (org-test-with-temp-text
  6390. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6391. (org-match-sparse-tree nil "A={f.*}")
  6392. (search-forward "H2")
  6393. (org-invisible-p2)))
  6394. ;; With an optional argument, limit match to TODO entries.
  6395. (should-not
  6396. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6397. (org-match-sparse-tree t "tag")
  6398. (search-forward "H1")
  6399. (org-invisible-p2)))
  6400. (should
  6401. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6402. (org-match-sparse-tree t "tag")
  6403. (search-forward "H2")
  6404. (org-invisible-p2))))
  6405. (ert-deftest test-org/occur ()
  6406. "Test `org-occur' specifications."
  6407. ;; Count number of matches.
  6408. (should
  6409. (= 1
  6410. (org-test-with-temp-text "* H\nA\n* H2"
  6411. (org-occur "A"))))
  6412. (should
  6413. (= 2
  6414. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6415. (org-occur "A"))))
  6416. ;; Test CALLBACK optional argument.
  6417. (should
  6418. (= 0
  6419. (org-test-with-temp-text "* H\nA\n* H2"
  6420. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6421. (should
  6422. (= 1
  6423. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6424. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6425. ;; Case-fold searches according to `org-occur-case-fold-search'.
  6426. (should
  6427. (= 2
  6428. (org-test-with-temp-text "Aa"
  6429. (let ((org-occur-case-fold-search t)) (org-occur "A")))))
  6430. (should
  6431. (= 2
  6432. (org-test-with-temp-text "Aa"
  6433. (let ((org-occur-case-fold-search t)) (org-occur "a")))))
  6434. (should
  6435. (= 1
  6436. (org-test-with-temp-text "Aa"
  6437. (let ((org-occur-case-fold-search nil)) (org-occur "A")))))
  6438. (should
  6439. (= 1
  6440. (org-test-with-temp-text "Aa"
  6441. (let ((org-occur-case-fold-search nil)) (org-occur "a")))))
  6442. (should
  6443. (= 1
  6444. (org-test-with-temp-text "Aa"
  6445. (let ((org-occur-case-fold-search 'smart)) (org-occur "A")))))
  6446. (should
  6447. (= 2
  6448. (org-test-with-temp-text "Aa"
  6449. (let ((org-occur-case-fold-search 'smart)) (org-occur "a"))))))
  6450. ;;; Tags
  6451. (ert-deftest test-org/tag-string-to-alist ()
  6452. "Test `org-tag-string-to-alist' specifications."
  6453. ;; Tag without selection key.
  6454. (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
  6455. ;; Tag with selection key.
  6456. (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t))))
  6457. ;; Tag group.
  6458. (should
  6459. (equal
  6460. (org-tag-string-to-alist "[ group : t1 t2 ]")
  6461. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag))))
  6462. ;; Mutually exclusive tags.
  6463. (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
  6464. '((:startgroup) ("tag1") ("tag2") (:endgroup))))
  6465. (should
  6466. (equal
  6467. (org-tag-string-to-alist "{ group : tag1 tag2 }")
  6468. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))))
  6469. (ert-deftest test-org/tag-alist-to-string ()
  6470. "Test `org-tag-alist-to-string' specifications."
  6471. (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
  6472. (should (equal (org-tag-alist-to-string '(("tag1" . ?t))) "tag1(t)"))
  6473. (should
  6474. (equal
  6475. (org-tag-alist-to-string
  6476. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6477. "[ group : t1 t2 ]"))
  6478. (should
  6479. (equal (org-tag-alist-to-string
  6480. '((:startgroup) ("tag1") ("tag2") (:endgroup)))
  6481. "{ tag1 tag2 }"))
  6482. (should
  6483. (equal
  6484. (org-tag-alist-to-string
  6485. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))
  6486. "{ group : tag1 tag2 }")))
  6487. (ert-deftest test-org/tag-alist-to-groups ()
  6488. "Test `org-tag-alist-to-groups' specifications."
  6489. (should
  6490. (equal (org-tag-alist-to-groups
  6491. '((:startgroup) ("group") (:grouptags) ("t1") ("t2") (:endgroup)))
  6492. '(("group" "t1" "t2"))))
  6493. (should
  6494. (equal
  6495. (org-tag-alist-to-groups
  6496. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6497. '(("group" "t1" "t2"))))
  6498. (should-not
  6499. (org-tag-alist-to-groups
  6500. '((:startgroup) ("group") ("t1") ("t2") (:endgroup)))))
  6501. (ert-deftest test-org/tag-align ()
  6502. "Test tags alignment."
  6503. ;; Test aligning tags with different display width.
  6504. (should
  6505. ;; 12345678901234567890
  6506. (equal "* Test :abc:"
  6507. (org-test-with-temp-text "* Test :abc:"
  6508. (let ((org-tags-column -20)
  6509. (indent-tabs-mode nil))
  6510. (org-fix-tags-on-the-fly))
  6511. (buffer-string))))
  6512. (should
  6513. ;; 12345678901234567890
  6514. (equal "* Test :日本語:"
  6515. (org-test-with-temp-text "* Test :日本語:"
  6516. (let ((org-tags-column -20)
  6517. (indent-tabs-mode nil))
  6518. (org-fix-tags-on-the-fly))
  6519. (buffer-string))))
  6520. ;; Make sure aligning tags do not skip invisible text.
  6521. (should
  6522. (equal "* [[linkx]] :tag:"
  6523. (org-test-with-temp-text "* [[link<point>]] :tag:"
  6524. (let ((org-tags-column 0))
  6525. (org-fix-tags-on-the-fly)
  6526. (insert "x")
  6527. (buffer-string)))))
  6528. ;; Aligning tags preserve position.
  6529. (should
  6530. (= 6 (org-test-with-temp-text "* 345 <point> :tag:"
  6531. (let ((org-tags-column 78)
  6532. (indent-tabs-mode nil))
  6533. (org-fix-tags-on-the-fly))
  6534. (current-column))))
  6535. ;; Aligning all tags in visible buffer.
  6536. (should
  6537. ;; 12345678901234567890
  6538. (equal (concat "* Level 1 :abc:\n"
  6539. "** Level 2 :def:")
  6540. (org-test-with-temp-text (concat "* Level 1 :abc:\n"
  6541. "** Level 2 :def:")
  6542. (let ((org-tags-column -20)
  6543. (indent-tabs-mode nil))
  6544. ;; (org-align-tags :all) must work even when the point
  6545. ;; is at the end of the buffer.
  6546. (goto-char (point-max))
  6547. (org-align-tags :all))
  6548. (buffer-string)))))
  6549. (ert-deftest test-org/get-tags ()
  6550. "Test `org-get-tags' specifications."
  6551. ;; Standard test.
  6552. (should
  6553. (equal '("foo")
  6554. (org-test-with-temp-text "* Test :foo:" (org-get-tags))))
  6555. (should
  6556. (equal '("foo" "bar")
  6557. (org-test-with-temp-text "* Test :foo:bar:" (org-get-tags))))
  6558. ;; Return nil when there is no tag.
  6559. (should-not
  6560. (org-test-with-temp-text "* Test" (org-get-tags)))
  6561. ;; Tags are inherited from parent headlines.
  6562. (should
  6563. (equal '("tag")
  6564. (let ((org-use-tag-inheritance t))
  6565. (org-test-with-temp-text "* H0 :foo:\n* H1 :tag:\n<point>** H2"
  6566. (org-get-tags)))))
  6567. ;; Tags are inherited from `org-file-tags'.
  6568. (should
  6569. (equal '("tag")
  6570. (org-test-with-temp-text "* H1"
  6571. (let ((org-file-tags '("tag"))
  6572. (org-use-tag-inheritance t))
  6573. (org-get-tags)))))
  6574. ;; Only inherited tags have the `inherited' text property.
  6575. (should
  6576. (get-text-property 0 'inherited
  6577. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6578. (let ((org-use-tag-inheritance t))
  6579. (assoc-string "foo" (org-get-tags))))))
  6580. (should-not
  6581. (get-text-property 0 'inherited
  6582. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6583. (let ((org-use-tag-inheritance t))
  6584. (assoc-string "bar" (org-get-tags))))))
  6585. ;; Obey to `org-use-tag-inheritance'.
  6586. (should-not
  6587. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6588. (let ((org-use-tag-inheritance nil))
  6589. (assoc-string "foo" (org-get-tags)))))
  6590. (should-not
  6591. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6592. (let ((org-use-tag-inheritance nil)
  6593. (org-file-tags '("foo")))
  6594. (assoc-string "foo" (org-get-tags)))))
  6595. (should-not
  6596. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6597. (let ((org-use-tag-inheritance '("bar")))
  6598. (assoc-string "foo" (org-get-tags)))))
  6599. (should
  6600. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6601. (let ((org-use-tag-inheritance '("bar")))
  6602. (assoc-string "bar" (org-get-tags)))))
  6603. (should-not
  6604. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6605. (let ((org-use-tag-inheritance "b.*"))
  6606. (assoc-string "foo" (org-get-tags)))))
  6607. (should
  6608. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6609. (let ((org-use-tag-inheritance "b.*"))
  6610. (assoc-string "bar" (org-get-tags)))))
  6611. ;; When optional argument LOCAL is non-nil, ignore tag inheritance.
  6612. (should
  6613. (equal '("baz")
  6614. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6615. (let ((org-use-tag-inheritance t))
  6616. (org-get-tags nil t)))))
  6617. ;; When optional argument POS is non-nil, get tags there instead.
  6618. (should
  6619. (equal '("foo")
  6620. (org-test-with-temp-text "* H1 :foo:\n* <point>H2 :bar:"
  6621. (org-get-tags 1))))
  6622. ;; Make sure tags excluded from inheritance are returned if local
  6623. (should
  6624. (equal '("foo")
  6625. (org-test-with-temp-text "* Test :foo:"
  6626. (let ((org-use-tag-inheritance t)
  6627. (org-tags-exclude-from-inheritance '("foo")))
  6628. (org-get-tags)))))
  6629. ;; Test the collection of tags from #+filetags and parent tags.
  6630. (should
  6631. (equal '("a" "b" "c" "d")
  6632. (org-test-with-temp-text (concat "#+filetags: a\n"
  6633. "* Level 1 :b:\n"
  6634. "** Level 2 :c:\n"
  6635. "*** Level 3 :d:\n"
  6636. "<point>")
  6637. (let ((org-use-tag-inheritance t))
  6638. (org-mode-restart) ;So that `org-file-tags' get populated from #+filetags
  6639. (org-get-tags)))))
  6640. ;; Pathological case: tagged headline with an empty body.
  6641. (should (org-test-with-temp-text "* :tag:" (org-get-tags))))
  6642. (ert-deftest test-org/set-tags ()
  6643. "Test `org-set-tags' specifications."
  6644. ;; Throw an error on invalid data.
  6645. (should-error
  6646. (org-test-with-temp-text "* H"
  6647. (org-set-tags 'foo)))
  6648. ;; `nil', an empty, and a blank string remove all tags.
  6649. (should
  6650. (equal "* H"
  6651. (org-test-with-temp-text "* H :tag1:tag2:"
  6652. (org-set-tags nil)
  6653. (buffer-string))))
  6654. (should
  6655. (equal "* H"
  6656. (org-test-with-temp-text "* H :tag1:tag2:"
  6657. (org-set-tags "")
  6658. (buffer-string))))
  6659. (should
  6660. (equal "* H"
  6661. (org-test-with-temp-text "* H :tag1:tag2:"
  6662. (org-set-tags " ")
  6663. (buffer-string))))
  6664. ;; If there's nothing to remove, just bail out.
  6665. (should
  6666. (equal "* H"
  6667. (org-test-with-temp-text "* H"
  6668. (org-set-tags nil)
  6669. (buffer-string))))
  6670. (should
  6671. (equal "* "
  6672. (org-test-with-temp-text "* "
  6673. (org-set-tags nil)
  6674. (buffer-string))))
  6675. ;; If DATA is a tag string, set current tags to it, even if it means
  6676. ;; replacing old tags.
  6677. (should
  6678. (equal "* H :tag0:"
  6679. (org-test-with-temp-text "* H :tag1:tag2:"
  6680. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  6681. (buffer-string))))
  6682. (should
  6683. (equal "* H :tag0:"
  6684. (org-test-with-temp-text "* H"
  6685. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  6686. (buffer-string))))
  6687. ;; If DATA is a list, set tags to this list, even if it means
  6688. ;; replacing old tags.
  6689. (should
  6690. (equal "* H :tag0:"
  6691. (org-test-with-temp-text "* H :tag1:tag2:"
  6692. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6693. (buffer-string))))
  6694. (should
  6695. (equal "* H :tag0:"
  6696. (org-test-with-temp-text "* H"
  6697. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6698. (buffer-string))))
  6699. ;; When set, apply `org-tags-sort-function'.
  6700. (should
  6701. (equal "* H :a:b:"
  6702. (org-test-with-temp-text "* H"
  6703. (let ((org-tags-column 1)
  6704. (org-tags-sort-function #'string<))
  6705. (org-set-tags '("b" "a"))
  6706. (buffer-string)))))
  6707. ;; When new tags are identical to the previous ones, still align.
  6708. (should
  6709. (equal "* H :foo:"
  6710. (org-test-with-temp-text "* H :foo:"
  6711. (let ((org-tags-column 1))
  6712. (org-set-tags '("foo"))
  6713. (buffer-string)))))
  6714. ;; When tags have been changed, run `org-after-tags-change-hook'.
  6715. (should
  6716. (catch :return
  6717. (org-test-with-temp-text "* H :foo:"
  6718. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  6719. (org-set-tags '("bar"))
  6720. nil))))
  6721. (should-not
  6722. (catch :return
  6723. (org-test-with-temp-text "* H :foo:"
  6724. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  6725. (org-set-tags '("foo"))
  6726. nil))))
  6727. ;; Special case: handle empty headlines.
  6728. (should
  6729. (equal "* :tag0:"
  6730. (org-test-with-temp-text "* "
  6731. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6732. (buffer-string))))
  6733. ;; Modify buffer only when a tag change happens or alignment is
  6734. ;; done.
  6735. (should-not
  6736. (org-test-with-temp-text "* H :foo:"
  6737. (set-buffer-modified-p nil)
  6738. (let ((org-tags-column 1)) (org-set-tags '("foo")))
  6739. (buffer-modified-p)))
  6740. (should
  6741. (org-test-with-temp-text "* H :foo:"
  6742. (set-buffer-modified-p nil)
  6743. (let ((org-tags-column 10)) (org-set-tags '("foo")))
  6744. (buffer-modified-p)))
  6745. (should
  6746. (org-test-with-temp-text "* H :foo:"
  6747. (set-buffer-modified-p nil)
  6748. (let ((org-tags-column 10)) (org-set-tags '("bar")))
  6749. (buffer-modified-p)))
  6750. ;; Pathological case: when setting tags of a folded headline, do not
  6751. ;; let new tags being sucked into invisibility.
  6752. (should-not
  6753. (org-test-with-temp-text "* H1\nContent\n* H2\n\n Other Content"
  6754. ;; Show only headlines
  6755. (org-content)
  6756. ;; Set NEXT tag on current entry
  6757. (org-set-tags ":NEXT:")
  6758. ;; Move point to that NEXT tag
  6759. (search-forward "NEXT") (backward-word)
  6760. ;; And it should be visible (i.e. no overlays)
  6761. (overlays-at (point)))))
  6762. (ert-deftest test-org/set-tags-command ()
  6763. "Test `org-set-tags-command' specifications"
  6764. ;; Set tags at current headline.
  6765. (should
  6766. (equal "* H1 :foo:"
  6767. (org-test-with-temp-text "* H1"
  6768. (cl-letf (((symbol-function 'completing-read)
  6769. (lambda (&rest args) ":foo:")))
  6770. (let ((org-use-fast-tag-selection nil)
  6771. (org-tags-column 1))
  6772. (org-set-tags-command)))
  6773. (buffer-string))))
  6774. ;; Preserve position when called from the section below.
  6775. (should
  6776. (equal "* H1 :foo:\nContents"
  6777. (org-test-with-temp-text "* H1\n<point>Contents"
  6778. (cl-letf (((symbol-function 'completing-read)
  6779. (lambda (&rest args) ":foo:")))
  6780. (let ((org-use-fast-tag-selection nil)
  6781. (org-tags-column 1))
  6782. (org-set-tags-command)))
  6783. (buffer-string))))
  6784. (should-not
  6785. (equal "* H1 :foo:\nContents2"
  6786. (org-test-with-temp-text "* H1\n<point>Contents2"
  6787. (cl-letf (((symbol-function 'completing-read)
  6788. (lambda (&rest args) ":foo:")))
  6789. (let ((org-use-fast-tag-selection nil)
  6790. (org-tags-column 1))
  6791. (org-set-tags-command)))
  6792. (org-at-heading-p))))
  6793. ;; Strip all forbidden characters from user-entered tags.
  6794. (should
  6795. (equal "* H1 :foo:"
  6796. (org-test-with-temp-text "* H1"
  6797. (cl-letf (((symbol-function 'completing-read)
  6798. (lambda (&rest args) ": foo *:")))
  6799. (let ((org-use-fast-tag-selection nil)
  6800. (org-tags-column 1))
  6801. (org-set-tags-command)))
  6802. (buffer-string))))
  6803. ;; When a region is active and
  6804. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  6805. ;; same value in all headlines in region.
  6806. (should
  6807. (equal "* H1 :foo:\nContents\n* H2 :foo:"
  6808. (org-test-with-temp-text "* H1\nContents\n* H2"
  6809. (cl-letf (((symbol-function 'completing-read)
  6810. (lambda (&rest args) ":foo:")))
  6811. (let ((org-use-fast-tag-selection nil)
  6812. (org-loop-over-headlines-in-active-region t)
  6813. (org-tags-column 1))
  6814. (transient-mark-mode 1)
  6815. (push-mark (point) t t)
  6816. (goto-char (point-max))
  6817. (org-set-tags-command)))
  6818. (buffer-string))))
  6819. (should
  6820. (equal "* H1\nContents\n* H2 :foo:"
  6821. (org-test-with-temp-text "* H1\nContents\n* H2"
  6822. (cl-letf (((symbol-function 'completing-read)
  6823. (lambda (&rest args) ":foo:")))
  6824. (let ((org-use-fast-tag-selection nil)
  6825. (org-loop-over-headlines-in-active-region nil)
  6826. (org-tags-column 1))
  6827. (transient-mark-mode 1)
  6828. (push-mark (point) t t)
  6829. (goto-char (point-max))
  6830. (org-set-tags-command)))
  6831. (buffer-string))))
  6832. ;; With a C-u prefix argument, align all tags in the buffer.
  6833. (should
  6834. (equal "* H1 :foo:\n* H2 :bar:"
  6835. (org-test-with-temp-text "* H1 :foo:\n* H2 :bar:"
  6836. (let ((org-tags-column 1)) (org-set-tags-command '(4)))
  6837. (buffer-string))))
  6838. ;; Point does not move with empty headline.
  6839. (should
  6840. (equal ":foo:"
  6841. (org-test-with-temp-text "* <point>"
  6842. (cl-letf (((symbol-function 'completing-read)
  6843. (lambda (&rest args) ":foo:")))
  6844. (let ((org-use-fast-tag-selection nil)
  6845. (org-tags-column 1))
  6846. (org-set-tags-command)))
  6847. (buffer-substring (point) (line-end-position)))))
  6848. ;; Point does not move at start of line.
  6849. (should
  6850. (equal "* H1 :foo:"
  6851. (org-test-with-temp-text "* H1"
  6852. (cl-letf (((symbol-function 'completing-read)
  6853. (lambda (&rest args) ":foo:")))
  6854. (let ((org-use-fast-tag-selection nil)
  6855. (org-tags-column 1))
  6856. (org-set-tags-command)))
  6857. (buffer-substring (point) (line-end-position)))))
  6858. ;; Point does not move when within *'s.
  6859. (should
  6860. (equal "* H1 :foo:"
  6861. (org-test-with-temp-text "*<point>* H1"
  6862. (cl-letf (((symbol-function 'completing-read)
  6863. (lambda (&rest args) ":foo:")))
  6864. (let ((org-use-fast-tag-selection nil)
  6865. (org-tags-column 1))
  6866. (org-set-tags-command)))
  6867. (buffer-substring (point) (line-end-position)))))
  6868. ;; Point workaround does not get fooled when looking at a space.
  6869. (should
  6870. (equal " b :foo:"
  6871. (org-test-with-temp-text "* a<point> b"
  6872. (cl-letf (((symbol-function 'completing-read)
  6873. (lambda (&rest args) ":foo:")))
  6874. (let ((org-use-fast-tag-selection nil)
  6875. (org-tags-column 1))
  6876. (org-set-tags-command)))
  6877. (buffer-substring (point) (line-end-position)))))
  6878. ;; Handle tags both set locally and inherited.
  6879. (should
  6880. (equal "b :foo:"
  6881. (org-test-with-temp-text "* a :foo:\n** <point>b :foo:"
  6882. (cl-letf (((symbol-function 'completing-read)
  6883. (lambda (prompt coll &optional pred req initial &rest args)
  6884. initial)))
  6885. (let ((org-use-fast-tag-selection nil)
  6886. (org-tags-column 1))
  6887. (org-set-tags-command)))
  6888. (buffer-substring (point) (line-end-position))))))
  6889. (ert-deftest test-org/toggle-tag ()
  6890. "Test `org-toggle-tag' specifications."
  6891. ;; Insert missing tag.
  6892. (should
  6893. (equal "* H :tag:"
  6894. (org-test-with-temp-text "* H"
  6895. (let ((org-tags-column 1)) (org-toggle-tag "tag"))
  6896. (buffer-string))))
  6897. (should
  6898. (equal "* H :tag1:tag2:"
  6899. (org-test-with-temp-text "* H :tag1:"
  6900. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  6901. (buffer-string))))
  6902. ;; Remove existing tag.
  6903. (should
  6904. (equal "* H"
  6905. (org-test-with-temp-text "* H :tag:"
  6906. (org-toggle-tag "tag")
  6907. (buffer-string))))
  6908. (should
  6909. (equal "* H :tag1:"
  6910. (org-test-with-temp-text "* H :tag1:tag2:"
  6911. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  6912. (buffer-string))))
  6913. (should
  6914. (equal "* H :tag2:"
  6915. (org-test-with-temp-text "* H :tag1:tag2:"
  6916. (let ((org-tags-column 1)) (org-toggle-tag "tag1"))
  6917. (buffer-string))))
  6918. ;; With optional argument ONOFF set to `on', try to insert the tag,
  6919. ;; even if its already there.
  6920. (should
  6921. (equal "* H :tag:"
  6922. (org-test-with-temp-text "* H"
  6923. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  6924. (buffer-string))))
  6925. (should
  6926. (equal "* H :tag:"
  6927. (org-test-with-temp-text "* H :tag:"
  6928. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  6929. (buffer-string))))
  6930. ;; With optional argument ONOFF set to `off', try to remove the tag,
  6931. ;; even if its not there.
  6932. (should
  6933. (equal "* H"
  6934. (org-test-with-temp-text "* H :tag:"
  6935. (org-toggle-tag "tag" 'off)
  6936. (buffer-string))))
  6937. (should
  6938. (equal "* H :tag:"
  6939. (org-test-with-temp-text "* H :tag:"
  6940. (let ((org-tags-column 1)) (org-toggle-tag "foo" 'off))
  6941. (buffer-string))))
  6942. ;; Special case: Handle properly tag inheritance. In particular, do
  6943. ;; not set inherited tags.
  6944. (should
  6945. (equal "* H1 :tag:\n** H2 :tag2:tag:"
  6946. (org-test-with-temp-text "* H1 :tag:\n** <point>H2 :tag2:"
  6947. (let ((org-use-tag-inheritance t)
  6948. (org-tags-column 1))
  6949. (org-toggle-tag "tag"))
  6950. (buffer-string))))
  6951. (should
  6952. (equal "* H1 :tag1:tag2:\n** H2 :foo:"
  6953. (org-test-with-temp-text "* H1 :tag1:tag2:\n** <point>H2"
  6954. (let ((org-use-tag-inheritance t)
  6955. (org-tags-column 1))
  6956. (org-toggle-tag "foo"))
  6957. (buffer-string)))))
  6958. (ert-deftest test-org/tags-expand ()
  6959. "Test `org-tags-expand' specifications."
  6960. ;; Expand tag groups as a regexp enclosed within curly brackets.
  6961. (should
  6962. (equal "{\\<[ABC]\\>}"
  6963. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6964. (org-mode-restart)
  6965. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  6966. (should
  6967. (equal "{\\<\\(?:Aa\\|Bb\\|Cc\\)\\>}"
  6968. (org-test-with-temp-text "#+TAGS: [ Aa : Bb Cc ]"
  6969. (org-mode-restart)
  6970. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "Aa")))))
  6971. ;; Preserve operator before the regexp.
  6972. (should
  6973. (equal "+{\\<[ABC]\\>}"
  6974. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6975. (org-mode-restart)
  6976. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "+A")))))
  6977. (should
  6978. (equal "-{\\<[ABC]\\>}"
  6979. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6980. (org-mode-restart)
  6981. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "-A")))))
  6982. ;; Handle "|" syntax.
  6983. (should
  6984. (equal "{\\<[ABC]\\>}|D"
  6985. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6986. (org-mode-restart)
  6987. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|D")))))
  6988. ;; Handle nested groups.
  6989. (should
  6990. (equal "{\\<[A-D]\\>}"
  6991. (org-test-with-temp-text "#+TAGS: [ A : B C ]\n#+TAGS: [ B : D ]"
  6992. (org-mode-restart)
  6993. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  6994. ;; Expand multiple occurrences of the same group.
  6995. (should
  6996. (equal "{\\<[ABC]\\>}|{\\<[ABC]\\>}"
  6997. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6998. (org-mode-restart)
  6999. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|A")))))
  7000. ;; Preserve regexp matches.
  7001. (should
  7002. (equal "{A+}"
  7003. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7004. (org-mode-restart)
  7005. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "{A+}"))))))
  7006. ;;; TODO keywords
  7007. (ert-deftest test-org/auto-repeat-maybe ()
  7008. "Test `org-auto-repeat-maybe' specifications."
  7009. ;; Do not auto repeat when there is no valid time stamp with
  7010. ;; a repeater in the entry.
  7011. (should-not
  7012. (string-prefix-p
  7013. "* TODO H"
  7014. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7015. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
  7016. (org-todo "DONE")
  7017. (buffer-string)))))
  7018. (should-not
  7019. (string-prefix-p
  7020. "* TODO H"
  7021. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7022. (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
  7023. (org-todo "DONE")
  7024. (buffer-string)))))
  7025. ;; When switching to DONE state, switch back to first TODO keyword
  7026. ;; in sequence, or the same keyword if they have different types.
  7027. (should
  7028. (string-prefix-p
  7029. "* TODO H"
  7030. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7031. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7032. (org-todo "DONE")
  7033. (buffer-string)))))
  7034. (should
  7035. (string-prefix-p
  7036. "* KWD1 H"
  7037. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  7038. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  7039. (org-todo "DONE")
  7040. (buffer-string)))))
  7041. (should
  7042. (string-prefix-p
  7043. "* KWD2 H"
  7044. (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
  7045. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  7046. (org-todo "DONE")
  7047. (buffer-string)))))
  7048. ;; If there was no TODO keyword in the first place, do not insert
  7049. ;; any either.
  7050. (should
  7051. (string-prefix-p
  7052. "* H"
  7053. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7054. (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
  7055. (org-todo "DONE")
  7056. (buffer-string)))))
  7057. ;; Revert to REPEAT_TO_STATE, if set.
  7058. (should
  7059. (string-prefix-p
  7060. "* KWD2 H"
  7061. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  7062. (org-test-with-temp-text
  7063. "* KWD2 H
  7064. :PROPERTIES:
  7065. :REPEAT_TO_STATE: KWD2
  7066. :END:
  7067. <2012-03-29 Thu +2y>"
  7068. (org-todo "DONE")
  7069. (buffer-string)))))
  7070. ;; When switching to DONE state, update base date. If there are
  7071. ;; multiple repeated time stamps, update them all.
  7072. (should
  7073. (string-match-p
  7074. "<2014-03-29 .* \\+2y>"
  7075. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7076. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7077. (org-todo "DONE")
  7078. (buffer-string)))))
  7079. (should
  7080. (string-match-p
  7081. "<2015-03-04 .* \\+1y>"
  7082. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7083. (org-test-with-temp-text
  7084. "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
  7085. (org-todo "DONE")
  7086. (buffer-string)))))
  7087. ;; Throw an error if repeater unit is the hour and no time is
  7088. ;; provided in the time-stamp.
  7089. (should-error
  7090. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7091. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
  7092. (org-todo "DONE")
  7093. (buffer-string))))
  7094. ;; Handle every repeater type using hours step.
  7095. (should
  7096. (string-match-p
  7097. "2014-03-04 .* 02:00"
  7098. (org-test-at-time "<2014-03-04 02:35>"
  7099. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 +8h>"
  7100. (org-todo "DONE")
  7101. (buffer-string)))))
  7102. (should
  7103. (string-match-p
  7104. "2014-03-04 .* 10:00"
  7105. (org-test-at-time "<2014-03-04 02:35>"
  7106. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 ++8h>"
  7107. (org-todo "DONE")
  7108. (buffer-string)))))
  7109. (should
  7110. (string-match-p
  7111. "2014-03-04 .* 10:35"
  7112. (org-test-at-time "<2014-03-04 02:35>"
  7113. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 .+8h>"
  7114. (org-todo "DONE")
  7115. (buffer-string)))))
  7116. ;; Do not repeat inactive time stamps with a repeater.
  7117. (should-not
  7118. (string-match-p
  7119. "\\[2014-03-29 .* \\+2y\\]"
  7120. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7121. (org-test-with-temp-text
  7122. "* TODO H\n[2012-03-29 Thu. +2y]"
  7123. (org-todo "DONE")
  7124. (buffer-string)))))
  7125. ;; Do not repeat commented time stamps.
  7126. (should-not
  7127. (string-prefix-p
  7128. "<2015-03-04 .* \\+1y>"
  7129. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7130. (org-test-with-temp-text
  7131. "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
  7132. (org-todo "DONE")
  7133. (buffer-string)))))
  7134. (should-not
  7135. (string-prefix-p
  7136. "<2015-03-04 .* \\+1y>"
  7137. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7138. (org-test-with-temp-text
  7139. "* TODO H
  7140. <2012-03-29 Thu. +2y>
  7141. #+BEGIN_EXAMPLE
  7142. <2014-03-04 Tue +1y>
  7143. #+END_EXAMPLE"
  7144. (org-todo "DONE")
  7145. (buffer-string)))))
  7146. ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
  7147. ;; entry, record time of last repeat.
  7148. (should-not
  7149. (string-match-p
  7150. ":LAST_REPEAT:"
  7151. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  7152. (org-log-repeat nil))
  7153. (cl-letf (((symbol-function 'org-add-log-setup)
  7154. (lambda (&rest args) nil)))
  7155. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  7156. (org-todo "DONE")
  7157. (buffer-string))))))
  7158. (should
  7159. (string-match-p
  7160. ":LAST_REPEAT:"
  7161. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  7162. (org-log-repeat t))
  7163. (cl-letf (((symbol-function 'org-add-log-setup)
  7164. (lambda (&rest args) nil)))
  7165. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  7166. (org-todo "DONE")
  7167. (buffer-string))))))
  7168. (should
  7169. (string-match-p
  7170. ":LAST_REPEAT:"
  7171. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7172. (cl-letf (((symbol-function 'org-add-log-setup)
  7173. (lambda (&rest args) nil)))
  7174. (org-test-with-temp-text
  7175. "* TODO H\n<2012-03-29 Thu +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
  7176. (org-todo "DONE")
  7177. (buffer-string))))))
  7178. ;; When a SCHEDULED entry has no repeater, remove it upon repeating
  7179. ;; the entry as it is no longer relevant.
  7180. (should-not
  7181. (string-match-p
  7182. "^SCHEDULED:"
  7183. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7184. (org-test-with-temp-text
  7185. "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
  7186. (org-todo "DONE")
  7187. (buffer-string)))))
  7188. ;; Properly advance repeater even when a clock entry is specified
  7189. ;; and `org-log-repeat' is nil.
  7190. (should
  7191. (string-match-p
  7192. "SCHEDULED: <2014-03-29"
  7193. (let ((org-log-repeat nil)
  7194. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7195. (org-test-with-temp-text
  7196. "* TODO H
  7197. SCHEDULED: <2012-03-29 Thu +2y>
  7198. CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] => 6:40"
  7199. (org-todo "DONE")
  7200. (buffer-string))))))
  7201. ;;; Timestamps API
  7202. (ert-deftest test-org/at-timestamp-p ()
  7203. "Test `org-at-timestamp-p' specifications."
  7204. (should
  7205. (org-test-with-temp-text "<2012-03-29 Thu>"
  7206. (org-at-timestamp-p)))
  7207. (should-not
  7208. (org-test-with-temp-text "2012-03-29 Thu"
  7209. (org-at-timestamp-p)))
  7210. ;; Test return values.
  7211. (should
  7212. (eq 'bracket
  7213. (org-test-with-temp-text "<2012-03-29 Thu>"
  7214. (org-at-timestamp-p))))
  7215. (should
  7216. (eq 'year
  7217. (org-test-with-temp-text "<<point>2012-03-29 Thu>"
  7218. (org-at-timestamp-p))))
  7219. (should
  7220. (eq 'month
  7221. (org-test-with-temp-text "<2012-<point>03-29 Thu>"
  7222. (org-at-timestamp-p))))
  7223. (should
  7224. (eq 'day
  7225. (org-test-with-temp-text "<2012-03-<point>29 Thu>"
  7226. (org-at-timestamp-p))))
  7227. (should
  7228. (eq 'day
  7229. (org-test-with-temp-text "<2012-03-29 T<point>hu>"
  7230. (org-at-timestamp-p))))
  7231. (should
  7232. (wholenump
  7233. (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
  7234. (org-at-timestamp-p))))
  7235. (should
  7236. (eq 'bracket
  7237. (org-test-with-temp-text "<2012-03-29 Thu<point>>"
  7238. (org-at-timestamp-p))))
  7239. (should
  7240. (eq 'after
  7241. (org-test-with-temp-text "<2012-03-29 Thu><point>»"
  7242. (org-at-timestamp-p))))
  7243. ;; Test `inactive' optional argument.
  7244. (should
  7245. (org-test-with-temp-text "[2012-03-29 Thu]"
  7246. (org-at-timestamp-p 'inactive)))
  7247. (should-not
  7248. (org-test-with-temp-text "[2012-03-29 Thu]"
  7249. (org-at-timestamp-p)))
  7250. ;; When optional argument is `agenda', recognize time-stamps in
  7251. ;; planning info line, property drawers and clocks.
  7252. (should
  7253. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7254. (org-at-timestamp-p 'agenda)))
  7255. (should-not
  7256. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7257. (org-at-timestamp-p)))
  7258. (should
  7259. (org-test-with-temp-text
  7260. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7261. (org-at-timestamp-p 'agenda)))
  7262. (should-not
  7263. (org-test-with-temp-text
  7264. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7265. (org-at-timestamp-p)))
  7266. (should
  7267. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7268. (let ((org-agenda-include-inactive-timestamps t))
  7269. (org-at-timestamp-p 'agenda))))
  7270. (should-not
  7271. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7272. (let ((org-agenda-include-inactive-timestamps t))
  7273. (org-at-timestamp-p))))
  7274. (should-not
  7275. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7276. (let ((org-agenda-include-inactive-timestamps t))
  7277. (org-at-timestamp-p 'inactive))))
  7278. ;; When optional argument is `lax', match any part of the document
  7279. ;; with Org timestamp syntax.
  7280. (should
  7281. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7282. (org-at-timestamp-p 'lax)))
  7283. (should-not
  7284. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7285. (org-at-timestamp-p)))
  7286. (should
  7287. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7288. (org-at-timestamp-p 'lax)))
  7289. (should-not
  7290. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7291. (org-at-timestamp-p)))
  7292. (should
  7293. (org-test-with-temp-text
  7294. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7295. (org-at-timestamp-p 'lax)))
  7296. (should-not
  7297. (org-test-with-temp-text
  7298. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7299. (org-at-timestamp-p)))
  7300. ;; Optional argument `lax' also matches inactive timestamps.
  7301. (should
  7302. (org-test-with-temp-text "# [2012-03-29 Thu]<point>"
  7303. (org-at-timestamp-p 'lax))))
  7304. (ert-deftest test-org/time-stamp ()
  7305. "Test `org-time-stamp' specifications."
  7306. ;; Insert chosen time stamp at point.
  7307. (should
  7308. (string-match
  7309. "Te<2014-03-04 .*?>xt"
  7310. (org-test-with-temp-text "Te<point>xt"
  7311. (cl-letf (((symbol-function 'org-read-date)
  7312. (lambda (&rest args)
  7313. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7314. (org-time-stamp nil)
  7315. (buffer-string)))))
  7316. ;; With a prefix argument, also insert time.
  7317. (should
  7318. (string-match
  7319. "Te<2014-03-04 .*? 00:41>xt"
  7320. (org-test-with-temp-text "Te<point>xt"
  7321. (cl-letf (((symbol-function 'org-read-date)
  7322. (lambda (&rest args)
  7323. (apply #'encode-time
  7324. (org-parse-time-string "2014-03-04 00:41")))))
  7325. (org-time-stamp '(4))
  7326. (buffer-string)))))
  7327. ;; With two universal prefix arguments, insert an active timestamp
  7328. ;; with the current time without prompting the user.
  7329. (should
  7330. (string-match
  7331. "Te<2014-03-04 .*? 00:41>xt"
  7332. (org-test-with-temp-text "Te<point>xt"
  7333. (org-test-at-time "2014-03-04 00:41"
  7334. (org-time-stamp '(16))
  7335. (buffer-string)))))
  7336. ;; When optional argument is non-nil, insert an inactive timestamp.
  7337. (should
  7338. (string-match
  7339. "Te\\[2014-03-04 .*?\\]xt"
  7340. (org-test-with-temp-text "Te<point>xt"
  7341. (cl-letf (((symbol-function 'org-read-date)
  7342. (lambda (&rest args)
  7343. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7344. (org-time-stamp nil t)
  7345. (buffer-string)))))
  7346. ;; When called from a timestamp, replace existing one.
  7347. (should
  7348. (string-match
  7349. "<2014-03-04 .*?>"
  7350. (org-test-with-temp-text "<2012-03-29<point> thu.>"
  7351. (cl-letf (((symbol-function 'org-read-date)
  7352. (lambda (&rest args)
  7353. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7354. (org-time-stamp nil)
  7355. (buffer-string)))))
  7356. (should
  7357. (string-match
  7358. "<2014-03-04 .*?>--<2014-03-04 .*?>"
  7359. (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
  7360. (cl-letf (((symbol-function 'org-read-date)
  7361. (lambda (&rest args)
  7362. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7363. (org-time-stamp nil)
  7364. (buffer-string)))))
  7365. ;; When replacing a timestamp, preserve repeater, if any.
  7366. (should
  7367. (string-match
  7368. "<2014-03-04 .*? \\+2y>"
  7369. (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
  7370. (cl-letf (((symbol-function 'org-read-date)
  7371. (lambda (&rest args)
  7372. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7373. (org-time-stamp nil)
  7374. (buffer-string)))))
  7375. ;; When called twice in a raw, build a date range.
  7376. (should
  7377. (string-match
  7378. "<2012-03-29 .*?>--<2014-03-04 .*?>"
  7379. (org-test-with-temp-text "<2012-03-29 thu.><point>"
  7380. (cl-letf (((symbol-function 'org-read-date)
  7381. (lambda (&rest args)
  7382. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7383. (let ((last-command 'org-time-stamp)
  7384. (this-command 'org-time-stamp))
  7385. (org-time-stamp nil))
  7386. (buffer-string))))))
  7387. (ert-deftest test-org/timestamp-has-time-p ()
  7388. "Test `org-timestamp-has-time-p' specifications."
  7389. ;; With time.
  7390. (should
  7391. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7392. (org-timestamp-has-time-p (org-element-context))))
  7393. ;; Without time.
  7394. (should-not
  7395. (org-test-with-temp-text "<2012-03-29 Thu>"
  7396. (org-timestamp-has-time-p (org-element-context)))))
  7397. (ert-deftest test-org/get-repeat ()
  7398. "Test `org-get-repeat' specifications."
  7399. (should
  7400. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
  7401. (org-get-repeat)))
  7402. (should-not
  7403. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
  7404. (org-get-repeat)))
  7405. ;; Return proper repeat string.
  7406. (should
  7407. (equal "+2y"
  7408. (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
  7409. (org-get-repeat))))
  7410. ;; Prevent false positive (commented or verbatim time stamps)
  7411. (should-not
  7412. (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
  7413. (org-get-repeat)))
  7414. (should-not
  7415. (org-test-with-temp-text
  7416. "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
  7417. (org-get-repeat)))
  7418. ;; Return nil when called before first heading.
  7419. (should-not
  7420. (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
  7421. (org-get-repeat)))
  7422. ;; When called with an optional argument, extract repeater from that
  7423. ;; string instead.
  7424. (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
  7425. (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
  7426. (ert-deftest test-org/timestamp-format ()
  7427. "Test `org-timestamp-format' specifications."
  7428. ;; Regular test.
  7429. (should
  7430. (equal
  7431. "2012-03-29 16:40"
  7432. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7433. (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
  7434. ;; Range end.
  7435. (should
  7436. (equal
  7437. "2012-03-29"
  7438. (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
  7439. (org-timestamp-format (org-element-context) "%Y-%m-%d" t)))))
  7440. (ert-deftest test-org/timestamp-split-range ()
  7441. "Test `org-timestamp-split-range' specifications."
  7442. ;; Extract range start (active).
  7443. (should
  7444. (equal '(2012 3 29)
  7445. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7446. (let ((ts (org-timestamp-split-range (org-element-context))))
  7447. (mapcar (lambda (p) (org-element-property p ts))
  7448. '(:year-end :month-end :day-end))))))
  7449. ;; Extract range start (inactive)
  7450. (should
  7451. (equal '(2012 3 29)
  7452. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7453. (let ((ts (org-timestamp-split-range (org-element-context))))
  7454. (mapcar (lambda (p) (org-element-property p ts))
  7455. '(:year-end :month-end :day-end))))))
  7456. ;; Extract range end (active).
  7457. (should
  7458. (equal '(2012 3 30)
  7459. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7460. (let ((ts (org-timestamp-split-range
  7461. (org-element-context) t)))
  7462. (mapcar (lambda (p) (org-element-property p ts))
  7463. '(:year-end :month-end :day-end))))))
  7464. ;; Extract range end (inactive)
  7465. (should
  7466. (equal '(2012 3 30)
  7467. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7468. (let ((ts (org-timestamp-split-range
  7469. (org-element-context) t)))
  7470. (mapcar (lambda (p) (org-element-property p ts))
  7471. '(:year-end :month-end :day-end))))))
  7472. ;; Return the timestamp if not a range.
  7473. (should
  7474. (org-test-with-temp-text "[2012-03-29 Thu]"
  7475. (let* ((ts-orig (org-element-context))
  7476. (ts-copy (org-timestamp-split-range ts-orig)))
  7477. (eq ts-orig ts-copy))))
  7478. (should
  7479. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7480. (let* ((ts-orig (org-element-context))
  7481. (ts-copy (org-timestamp-split-range ts-orig)))
  7482. (eq ts-orig ts-copy)))))
  7483. (ert-deftest test-org/timestamp-translate ()
  7484. "Test `org-timestamp-translate' specifications."
  7485. ;; Translate whole date range.
  7486. (should
  7487. (equal "<29>--<30>"
  7488. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7489. (let ((org-display-custom-times t)
  7490. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7491. (org-timestamp-translate (org-element-context))))))
  7492. ;; Translate date range start.
  7493. (should
  7494. (equal "<29>"
  7495. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7496. (let ((org-display-custom-times t)
  7497. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7498. (org-timestamp-translate (org-element-context) 'start)))))
  7499. ;; Translate date range end.
  7500. (should
  7501. (equal "<30>"
  7502. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7503. (let ((org-display-custom-times t)
  7504. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7505. (org-timestamp-translate (org-element-context) 'end)))))
  7506. ;; Translate time range.
  7507. (should
  7508. (equal "<08>--<16>"
  7509. (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
  7510. (let ((org-display-custom-times t)
  7511. (org-time-stamp-custom-formats '("<%d>" . "<%H>")))
  7512. (org-timestamp-translate (org-element-context))))))
  7513. ;; Translate non-range timestamp.
  7514. (should
  7515. (equal "<29>"
  7516. (org-test-with-temp-text "<2012-03-29 Thu>"
  7517. (let ((org-display-custom-times t)
  7518. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7519. (org-timestamp-translate (org-element-context))))))
  7520. ;; Do not change `diary' timestamps.
  7521. (should
  7522. (equal "<%%(org-float t 4 2)>"
  7523. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7524. (let ((org-display-custom-times t)
  7525. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7526. (org-timestamp-translate (org-element-context)))))))
  7527. (ert-deftest test-org/timestamp-from-string ()
  7528. "Test `org-timestamp-from-string' specifications."
  7529. ;; Return nil if argument is not a valid Org timestamp.
  7530. (should-not (org-timestamp-from-string ""))
  7531. (should-not (org-timestamp-from-string nil))
  7532. (should-not (org-timestamp-from-string "<2012-03-29"))
  7533. ;; Otherwise, return a valid Org timestamp object.
  7534. (should
  7535. (string-match-p "<2012-03-29 .+>"
  7536. (org-element-interpret-data
  7537. (org-timestamp-from-string "<2012-03-29 Thu>"))))
  7538. (should
  7539. (string-match-p "[2014-03-04 .+]"
  7540. (org-element-interpret-data
  7541. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  7542. (ert-deftest test-org/timestamp-from-time ()
  7543. "Test `org-timestamp-from-time' specifications."
  7544. ;; Standard test.
  7545. (should
  7546. (string-match-p
  7547. "<2012-03-29 .+>"
  7548. (org-element-interpret-data
  7549. (org-timestamp-from-time
  7550. (apply #'encode-time
  7551. (org-parse-time-string "<2012-03-29 Thu 16:40>"))))))
  7552. ;; When optional argument WITH-TIME is non-nil, provide time
  7553. ;; information.
  7554. (should
  7555. (string-match-p
  7556. "<2012-03-29 .+ 16:40>"
  7557. (org-element-interpret-data
  7558. (org-timestamp-from-time
  7559. (apply #'encode-time
  7560. (org-parse-time-string "<2012-03-29 Thu 16:40>"))
  7561. t))))
  7562. ;; When optional argument INACTIVE is non-nil, return an inactive
  7563. ;; timestamp.
  7564. (should
  7565. (string-match-p
  7566. "[2012-03-29 .+]"
  7567. (org-element-interpret-data
  7568. (org-timestamp-from-time
  7569. (apply #'encode-time
  7570. (org-parse-time-string "<2012-03-29 Thu 16:40>"))
  7571. nil t)))))
  7572. (ert-deftest test-org/timestamp-to-time ()
  7573. "Test `org-timestamp-to-time' specifications."
  7574. (should
  7575. (equal "2014-03-04"
  7576. (format-time-string
  7577. "%Y-%m-%d"
  7578. (org-timestamp-to-time
  7579. (org-timestamp-from-string "<2014-03-04 Tue>")))))
  7580. (should
  7581. (equal "2014-03-04"
  7582. (format-time-string
  7583. "%Y-%m-%d"
  7584. (org-timestamp-to-time
  7585. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  7586. (should
  7587. (equal "2012-03-29 08:30"
  7588. (format-time-string
  7589. "%Y-%m-%d %H:%M"
  7590. (org-timestamp-to-time
  7591. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")))))
  7592. (should
  7593. (equal "2012-03-29"
  7594. (format-time-string
  7595. "%Y-%m-%d"
  7596. (org-timestamp-to-time
  7597. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")))))
  7598. (should
  7599. (equal "2012-03-29"
  7600. (format-time-string
  7601. "%Y-%m-%d"
  7602. (org-timestamp-to-time
  7603. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")))))
  7604. ;; When optional argument END is non-nil, use end of date range or
  7605. ;; time range.
  7606. (should
  7607. (equal "2012-03-29 16:40"
  7608. (format-time-string
  7609. "%Y-%m-%d %H:%M"
  7610. (org-timestamp-to-time
  7611. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")
  7612. t))))
  7613. (should
  7614. (equal "2014-03-04"
  7615. (format-time-string
  7616. "%Y-%m-%d"
  7617. (org-timestamp-to-time
  7618. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")
  7619. t))))
  7620. (should
  7621. (equal "2014-03-04"
  7622. (format-time-string
  7623. "%Y-%m-%d"
  7624. (org-timestamp-to-time
  7625. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")
  7626. t)))))
  7627. ;;; Visibility
  7628. (ert-deftest test-org/hide-drawer-toggle ()
  7629. "Test `org-hide-drawer-toggle' specifications."
  7630. ;; Error when not at a drawer.
  7631. (should-error
  7632. (org-test-with-temp-text ":fake-drawer:\ncontents"
  7633. (org-hide-drawer-toggle 'off)
  7634. (get-char-property (line-end-position) 'invisible)))
  7635. (should-error
  7636. (org-test-with-temp-text
  7637. "#+begin_example\n<point>:D:\nc\n:END:\n#+end_example"
  7638. (org-hide-drawer-toggle t)))
  7639. ;; Hide drawer.
  7640. (should
  7641. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7642. (org-hide-drawer-toggle)
  7643. (get-char-property (line-end-position) 'invisible)))
  7644. ;; Show drawer unconditionally when optional argument is `off'.
  7645. (should-not
  7646. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7647. (org-hide-drawer-toggle)
  7648. (org-hide-drawer-toggle 'off)
  7649. (get-char-property (line-end-position) 'invisible)))
  7650. ;; Hide drawer unconditionally when optional argument is non-nil.
  7651. (should
  7652. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7653. (org-hide-drawer-toggle t)
  7654. (get-char-property (line-end-position) 'invisible)))
  7655. ;; Do not hide drawer when called from final blank lines.
  7656. (should-not
  7657. (org-test-with-temp-text ":drawer:\ncontents\n:end:\n\n<point>"
  7658. (org-hide-drawer-toggle)
  7659. (goto-char (point-min))
  7660. (get-char-property (line-end-position) 'invisible)))
  7661. ;; Don't leave point in an invisible part of the buffer when hiding
  7662. ;; a drawer away.
  7663. (should-not
  7664. (org-test-with-temp-text ":drawer:\ncontents\n<point>:end:"
  7665. (org-hide-drawer-toggle)
  7666. (get-char-property (point) 'invisible))))
  7667. (ert-deftest test-org/hide-block-toggle ()
  7668. "Test `org-hide-block-toggle' specifications."
  7669. ;; Error when not at a block.
  7670. (should-error
  7671. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
  7672. (org-hide-block-toggle 'off)
  7673. (get-char-property (line-end-position) 'invisible)))
  7674. ;; Hide block.
  7675. (should
  7676. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  7677. (org-hide-block-toggle)
  7678. (get-char-property (line-end-position) 'invisible)))
  7679. (should
  7680. (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
  7681. (org-hide-block-toggle)
  7682. (get-char-property (line-end-position) 'invisible)))
  7683. ;; Show block unconditionally when optional argument is `off'.
  7684. (should-not
  7685. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7686. (org-hide-block-toggle)
  7687. (org-hide-block-toggle 'off)
  7688. (get-char-property (line-end-position) 'invisible)))
  7689. (should-not
  7690. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7691. (org-hide-block-toggle 'off)
  7692. (get-char-property (line-end-position) 'invisible)))
  7693. ;; Hide block unconditionally when optional argument is non-nil.
  7694. (should
  7695. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7696. (org-hide-block-toggle t)
  7697. (get-char-property (line-end-position) 'invisible)))
  7698. (should
  7699. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7700. (org-hide-block-toggle)
  7701. (org-hide-block-toggle t)
  7702. (get-char-property (line-end-position) 'invisible)))
  7703. ;; Do not hide block when called from final blank lines.
  7704. (should-not
  7705. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
  7706. (org-hide-block-toggle)
  7707. (goto-char (point-min))
  7708. (get-char-property (line-end-position) 'invisible)))
  7709. ;; Don't leave point in an invisible part of the buffer when hiding
  7710. ;; a block away.
  7711. (should-not
  7712. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
  7713. (org-hide-block-toggle)
  7714. (get-char-property (point) 'invisible))))
  7715. (ert-deftest test-org/hide-block-toggle-maybe ()
  7716. "Test `org-hide-block-toggle-maybe' specifications."
  7717. (should
  7718. (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
  7719. (org-hide-block-toggle-maybe)))
  7720. (should-not
  7721. (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
  7722. (ert-deftest test-org/show-set-visibility ()
  7723. "Test `org-show-set-visibility' specifications."
  7724. ;; Do not throw an error before first heading.
  7725. (should
  7726. (org-test-with-temp-text "Preamble\n* Headline"
  7727. (org-show-set-visibility 'tree)
  7728. t))
  7729. ;; Test all visibility spans, both on headline and in entry.
  7730. (let ((list-visible-lines
  7731. (lambda (state headerp)
  7732. (org-test-with-temp-text "* Grandmother (0)
  7733. ** Uncle (1)
  7734. *** Heir (2)
  7735. ** Father (3)
  7736. Ancestor text (4)
  7737. *** Sister (5)
  7738. Sibling text (6)
  7739. *** Self (7)
  7740. Match (8)
  7741. **** First born (9)
  7742. Child text (10)
  7743. **** The other child (11)
  7744. *** Brother (12)
  7745. ** Aunt (13)
  7746. "
  7747. (org-cycle t)
  7748. (search-forward (if headerp "Self" "Match"))
  7749. (org-show-set-visibility state)
  7750. (goto-char (point-min))
  7751. (let (result (line 0))
  7752. (while (not (eobp))
  7753. (unless (org-invisible-p2) (push line result))
  7754. (cl-incf line)
  7755. (forward-line))
  7756. (nreverse result))))))
  7757. (should (equal '(0 7) (funcall list-visible-lines 'minimal t)))
  7758. (should (equal '(0 7 8) (funcall list-visible-lines 'minimal nil)))
  7759. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local t)))
  7760. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local nil)))
  7761. (should (equal '(0 3 7) (funcall list-visible-lines 'ancestors t)))
  7762. (should (equal '(0 3 7 8) (funcall list-visible-lines 'ancestors nil)))
  7763. (should (equal '(0 3 5 7 12) (funcall list-visible-lines 'lineage t)))
  7764. (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines 'lineage nil)))
  7765. (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines 'tree t)))
  7766. (should (equal '(0 1 3 5 7 8 9 11 12 13)
  7767. (funcall list-visible-lines 'tree nil)))
  7768. (should (equal '(0 1 3 4 5 7 12 13)
  7769. (funcall list-visible-lines 'canonical t)))
  7770. (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
  7771. (funcall list-visible-lines 'canonical nil))))
  7772. ;; When point is hidden in a drawer or a block, make sure to make it
  7773. ;; visible.
  7774. (should-not
  7775. (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
  7776. (org-hide-block-toggle)
  7777. (search-forward "Text")
  7778. (org-show-set-visibility 'minimal)
  7779. (org-invisible-p2)))
  7780. (should-not
  7781. (org-test-with-temp-text ":DRAWER:\nText\n:END:"
  7782. (org-hide-drawer-toggle)
  7783. (search-forward "Text")
  7784. (org-show-set-visibility 'minimal)
  7785. (org-invisible-p2)))
  7786. (should-not
  7787. (org-test-with-temp-text
  7788. "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
  7789. (org-hide-drawer-toggle)
  7790. (forward-line -1)
  7791. (org-hide-block-toggle)
  7792. (search-forward "Text")
  7793. (org-show-set-visibility 'minimal)
  7794. (org-invisible-p2))))
  7795. (defun test-org/copy-visible ()
  7796. "Test `org-copy-visible' specifications."
  7797. (should
  7798. (equal "Foo"
  7799. (org-test-with-temp-text "Foo"
  7800. (let ((kill-ring nil))
  7801. (org-copy-visible (point-min) (point-max))
  7802. (current-kill 0 t)))))
  7803. ;; Skip invisible characters by text property.
  7804. (should
  7805. (equal "Foo"
  7806. (org-test-with-temp-text #("F<hidden>oo" 1 7 (invisible t))
  7807. (let ((kill-ring nil))
  7808. (org-copy-visible (point-min) (point-max))
  7809. (current-kill 0 t)))))
  7810. ;; Skip invisible characters by overlay.
  7811. (should
  7812. (equal "Foo"
  7813. (org-test-with-temp-text "F<hidden>oo"
  7814. (let ((o (make-overlay 2 10)))
  7815. (overlay-put o 'invisible t))
  7816. (let ((kill-ring nil))
  7817. (org-copy-visible (point-min) (point-max))
  7818. (current-kill 0 t)))))
  7819. ;; Handle invisible characters at the beginning and the end of the
  7820. ;; buffer.
  7821. (should
  7822. (equal "Foo"
  7823. (org-test-with-temp-text #("<hidden>Foo" 0 8 (invisible t))
  7824. (let ((kill-ring nil))
  7825. (org-copy-visible (point-min) (point-max))
  7826. (current-kill 0 t)))))
  7827. (should
  7828. (equal "Foo"
  7829. (org-test-with-temp-text #("Foo<hidden>" 3 11 (invisible t))
  7830. (let ((kill-ring nil))
  7831. (org-copy-visible (point-min) (point-max))
  7832. (current-kill 0 t)))))
  7833. ;; Handle multiple visible parts.
  7834. (should
  7835. (equal "abc"
  7836. (org-test-with-temp-text
  7837. #("aXbXc" 1 2 (invisible t) 3 4 (invisible t))
  7838. (let ((kill-ring nil))
  7839. (org-copy-visible (point-min) (point-max))
  7840. (current-kill 0 t))))))
  7841. (ert-deftest test-org/set-visibility-according-to-property ()
  7842. "Test `org-set-visibility-according-to-property' specifications."
  7843. ;; "folded" state.
  7844. (should
  7845. (org-test-with-temp-text
  7846. "
  7847. * a
  7848. :PROPERTIES:
  7849. :VISIBILITY: folded
  7850. :END:
  7851. ** <point>b"
  7852. (org-set-visibility-according-to-property)
  7853. (invisible-p (point))))
  7854. ;; "children" state.
  7855. (should
  7856. (org-test-with-temp-text
  7857. "
  7858. * a
  7859. :PROPERTIES:
  7860. :VISIBILITY: children
  7861. :END:
  7862. ** b
  7863. <point>Contents
  7864. ** c"
  7865. (org-set-visibility-according-to-property)
  7866. (invisible-p (point))))
  7867. (should
  7868. (org-test-with-temp-text
  7869. "
  7870. * a
  7871. :PROPERTIES:
  7872. :VISIBILITY: children
  7873. :END:
  7874. ** b
  7875. Contents
  7876. *** <point>c"
  7877. (org-set-visibility-according-to-property)
  7878. (invisible-p (point))))
  7879. ;; "content" state.
  7880. (should
  7881. (org-test-with-temp-text
  7882. "
  7883. * a
  7884. :PROPERTIES:
  7885. :VISIBILITY: content
  7886. :END:
  7887. ** b
  7888. <point>Contents
  7889. *** c"
  7890. (org-set-visibility-according-to-property)
  7891. (invisible-p (point))))
  7892. (should
  7893. (org-test-with-temp-text
  7894. "
  7895. * a
  7896. :PROPERTIES:
  7897. :VISIBILITY: content
  7898. :END:
  7899. ** b
  7900. Contents
  7901. *** <point>c"
  7902. (org-set-visibility-according-to-property)
  7903. (not (invisible-p (point)))))
  7904. ;; "showall" state.
  7905. (should
  7906. (org-test-with-temp-text
  7907. "
  7908. * a
  7909. :PROPERTIES:
  7910. :VISIBILITY: showall
  7911. :END:
  7912. ** b
  7913. <point>Contents
  7914. *** c"
  7915. (org-set-visibility-according-to-property)
  7916. (not (invisible-p (point)))))
  7917. (should
  7918. (org-test-with-temp-text
  7919. "
  7920. * a
  7921. :PROPERTIES:
  7922. :VISIBILITY: showall
  7923. :END:
  7924. ** b
  7925. Contents
  7926. *** <point>c"
  7927. (org-set-visibility-according-to-property)
  7928. (not (invisible-p (point)))))
  7929. ;; When VISIBILITY properties are nested, ignore inner ones.
  7930. (should
  7931. (org-test-with-temp-text
  7932. "
  7933. * A
  7934. :PROPERTIES:
  7935. :VISIBILITY: folded
  7936. :END:
  7937. ** <point>B
  7938. :PROPERTIES:
  7939. :VISIBILITY: folded
  7940. :END:"
  7941. (org-set-visibility-according-to-property)
  7942. (invisible-p (point)))))
  7943. (ert-deftest test-org/visibility-show-branches ()
  7944. "Test visibility of inline archived subtrees."
  7945. (org-test-with-temp-text
  7946. "* Foo<point>
  7947. ** Bar :ARCHIVE:
  7948. *** Baz
  7949. "
  7950. (org-kill-note-or-show-branches)
  7951. (should (org-invisible-p (- (point-max) 2)))))
  7952. ;;; Yank and Kill
  7953. (ert-deftest test-org/paste-subtree ()
  7954. "Test `org-paste-subtree' specifications."
  7955. ;; Return an error if text to yank is not a set of subtrees.
  7956. (should-error (org-paste-subtree nil "Text"))
  7957. ;; Adjust level according to current one.
  7958. (should
  7959. (equal "* H\n* Text\n"
  7960. (org-test-with-temp-text "* H\n<point>"
  7961. (org-paste-subtree nil "* Text")
  7962. (buffer-string))))
  7963. (should
  7964. (equal "* H1\n** H2\n** Text\n"
  7965. (org-test-with-temp-text "* H1\n** H2\n<point>"
  7966. (org-paste-subtree nil "* Text")
  7967. (buffer-string))))
  7968. ;; When not on a heading, move to next heading before yanking.
  7969. (should
  7970. (equal "* H1\nParagraph\n* Text\n* H2"
  7971. (org-test-with-temp-text "* H1\n<point>Paragraph\n* H2"
  7972. (org-paste-subtree nil "* Text")
  7973. (buffer-string))))
  7974. ;; If point is between two headings, use the deepest level.
  7975. (should
  7976. (equal "* H1\n\n* Text\n* H2"
  7977. (org-test-with-temp-text "* H1\n<point>\n* H2"
  7978. (org-paste-subtree nil "* Text")
  7979. (buffer-string))))
  7980. (should
  7981. (equal "** H1\n\n** Text\n* H2"
  7982. (org-test-with-temp-text "** H1\n<point>\n* H2"
  7983. (org-paste-subtree nil "* Text")
  7984. (buffer-string))))
  7985. (should
  7986. (equal "* H1\n\n** Text\n** H2"
  7987. (org-test-with-temp-text "* H1\n<point>\n** H2"
  7988. (org-paste-subtree nil "* Text")
  7989. (buffer-string))))
  7990. ;; When on an empty heading, after the stars, deduce the new level
  7991. ;; from the number of stars.
  7992. (should
  7993. (equal "*** Text\n"
  7994. (org-test-with-temp-text "*** <point>"
  7995. (org-paste-subtree nil "* Text")
  7996. (buffer-string))))
  7997. ;; Optional argument LEVEL forces a level for the subtree.
  7998. (should
  7999. (equal "* H\n*** Text\n"
  8000. (org-test-with-temp-text "* H<point>"
  8001. (org-paste-subtree 3 "* Text")
  8002. (buffer-string)))))
  8003. (ert-deftest test-org/cut-and-paste-subtree ()
  8004. "Test `org-cut-subtree' and `org-paste-subtree'."
  8005. (should
  8006. (equal
  8007. "* Two
  8008. two
  8009. * One
  8010. "
  8011. (org-test-with-temp-text
  8012. "* One
  8013. <point>* Two
  8014. two
  8015. "
  8016. (call-interactively #'org-cut-subtree)
  8017. (goto-char (point-min))
  8018. (call-interactively #'org-paste-subtree)
  8019. (buffer-string))))
  8020. (should
  8021. (equal
  8022. "* One
  8023. * Two
  8024. "
  8025. (org-test-with-temp-text
  8026. "* One
  8027. <point>* Two
  8028. "
  8029. (call-interactively #'org-cut-subtree)
  8030. (backward-char)
  8031. (call-interactively #'org-paste-subtree)
  8032. (buffer-string)))))
  8033. (provide 'test-org)
  8034. ;;; test-org.el ends here