test-org.el 265 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168
  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. (should
  977. (= 2
  978. (org-test-with-temp-text "A\n\n B\n\nC<point>"
  979. (org-indent-line)
  980. (org-get-indentation))))
  981. (should
  982. (= 1
  983. (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC<point>"
  984. (org-indent-line)
  985. (org-get-indentation))))
  986. (should
  987. (= 1
  988. (org-test-with-temp-text
  989. " #+BEGIN_CENTER\n<point> Contents\n#+END_CENTER"
  990. (org-indent-line)
  991. (org-get-indentation))))
  992. ;; Within code part of a source block, use language major mode if
  993. ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
  994. ;; according to line above.
  995. (should
  996. (= 6
  997. (org-test-with-temp-text
  998. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  999. (let ((org-src-tab-acts-natively t)
  1000. (org-edit-src-content-indentation 0))
  1001. (org-indent-line))
  1002. (org-get-indentation))))
  1003. (should
  1004. (= 1
  1005. (org-test-with-temp-text
  1006. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  1007. (let ((org-src-tab-acts-natively nil)
  1008. (org-edit-src-content-indentation 0))
  1009. (org-indent-line))
  1010. (org-get-indentation))))
  1011. ;; Otherwise, indent like the first non-blank line above.
  1012. (should
  1013. (zerop
  1014. (org-test-with-temp-text
  1015. "#+BEGIN_CENTER\nline1\n\n<point> line2\n#+END_CENTER"
  1016. (org-indent-line)
  1017. (org-get-indentation))))
  1018. ;; Align node properties according to `org-property-format'. Handle
  1019. ;; nicely empty values.
  1020. (should
  1021. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1022. (org-test-with-temp-text
  1023. "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
  1024. (let ((org-property-format "%-10s %s")) (org-indent-line))
  1025. (buffer-string))))
  1026. (should
  1027. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1028. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
  1029. (let ((org-property-format "%-10s %s")) (org-indent-line))
  1030. (buffer-string)))))
  1031. (ert-deftest test-org/indent-region ()
  1032. "Test `org-indent-region' specifications."
  1033. ;; Indent paragraph.
  1034. (should
  1035. (equal "A\nB\nC"
  1036. (org-test-with-temp-text " A\nB\n C"
  1037. (org-indent-region (point-min) (point-max))
  1038. (buffer-string))))
  1039. ;; Indent greater elements along with their contents.
  1040. (should
  1041. (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
  1042. (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
  1043. (org-indent-region (point-min) (point-max))
  1044. (buffer-string))))
  1045. ;; Ignore contents of verse blocks. Only indent block delimiters.
  1046. (should
  1047. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1048. (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1049. (org-indent-region (point-min) (point-max))
  1050. (buffer-string))))
  1051. (should
  1052. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1053. (org-test-with-temp-text " #+BEGIN_VERSE\n A\n B\n #+END_VERSE"
  1054. (org-indent-region (point-min) (point-max))
  1055. (buffer-string))))
  1056. ;; Indent example blocks as a single block, unless indentation
  1057. ;; should be preserved. In this case only indent the block markers.
  1058. (should
  1059. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1060. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1061. (org-indent-region (point-min) (point-max))
  1062. (buffer-string))))
  1063. (should
  1064. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1065. (org-test-with-temp-text " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1066. (org-indent-region (point-min) (point-max))
  1067. (buffer-string))))
  1068. (should
  1069. (equal "#+BEGIN_EXAMPLE -i\n A\n B\n#+END_EXAMPLE"
  1070. (org-test-with-temp-text
  1071. " #+BEGIN_EXAMPLE -i\n A\n B\n #+END_EXAMPLE"
  1072. (org-indent-region (point-min) (point-max))
  1073. (buffer-string))))
  1074. (should
  1075. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1076. (org-test-with-temp-text
  1077. " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1078. (let ((org-src-preserve-indentation t))
  1079. (org-indent-region (point-min) (point-max)))
  1080. (buffer-string))))
  1081. ;; Treat export blocks as a whole.
  1082. (should
  1083. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1084. (org-test-with-temp-text "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1085. (org-indent-region (point-min) (point-max))
  1086. (buffer-string))))
  1087. (should
  1088. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1089. (org-test-with-temp-text
  1090. " #+BEGIN_EXPORT latex\n A\n B\n #+END_EXPORT"
  1091. (org-indent-region (point-min) (point-max))
  1092. (buffer-string))))
  1093. ;; Indent according to mode if `org-src-tab-acts-natively' is
  1094. ;; non-nil. Otherwise, do not indent code at all.
  1095. (should
  1096. (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
  1097. (org-test-with-temp-text
  1098. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1099. (let ((org-src-tab-acts-natively t)
  1100. (org-edit-src-content-indentation 0))
  1101. (org-indent-region (point-min) (point-max)))
  1102. (buffer-string))))
  1103. (should
  1104. (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1105. (org-test-with-temp-text
  1106. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1107. (let ((org-src-tab-acts-natively nil)
  1108. (org-edit-src-content-indentation 0))
  1109. (org-indent-region (point-min) (point-max)))
  1110. (buffer-string))))
  1111. ;; Align node properties according to `org-property-format'. Handle
  1112. ;; nicely empty values.
  1113. (should
  1114. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1115. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
  1116. (let ((org-property-format "%-10s %s")
  1117. (org-adapt-indentation nil))
  1118. (org-indent-region (point) (point-max)))
  1119. (buffer-string))))
  1120. (should
  1121. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1122. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
  1123. (let ((org-property-format "%-10s %s")
  1124. (org-adapt-indentation nil))
  1125. (org-indent-region (point) (point-max)))
  1126. (buffer-string))))
  1127. ;; Indent plain lists.
  1128. (should
  1129. (equal "- A\n B\n - C\n\n D"
  1130. (org-test-with-temp-text "- A\n B\n - C\n\n D"
  1131. (org-indent-region (point-min) (point-max))
  1132. (buffer-string))))
  1133. (should
  1134. (equal "- A\n\n- B"
  1135. (org-test-with-temp-text " - A\n\n - B"
  1136. (org-indent-region (point-min) (point-max))
  1137. (buffer-string))))
  1138. ;; Indent footnote definitions.
  1139. (should
  1140. (equal "[fn:1] Definition\n\nDefinition"
  1141. (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
  1142. (org-indent-region (point-min) (point-max))
  1143. (buffer-string))))
  1144. ;; Special case: Start indenting on a blank line.
  1145. (should
  1146. (equal "\nParagraph"
  1147. (org-test-with-temp-text "\n Paragraph"
  1148. (org-indent-region (point-min) (point-max))
  1149. (buffer-string)))))
  1150. ;;; Editing
  1151. (ert-deftest test-org/delete-indentation ()
  1152. "Test `org-delete-indentation' specifications."
  1153. ;; Regular test.
  1154. (should (equal "foo bar"
  1155. (org-test-with-temp-text
  1156. "foo \n bar<point>"
  1157. (org-delete-indentation)
  1158. (buffer-string))))
  1159. ;; With optional argument.
  1160. (should (equal "foo bar"
  1161. (org-test-with-temp-text
  1162. "foo<point> \n bar"
  1163. (org-delete-indentation t)
  1164. (buffer-string))))
  1165. ;; At headline text should be appended to the headline text.
  1166. (should
  1167. (equal"* foo bar :tag:"
  1168. (let (org-auto-align-tags)
  1169. (org-test-with-temp-text
  1170. "* foo :tag:\n bar<point>"
  1171. (org-delete-indentation)
  1172. (buffer-string)))))
  1173. (should
  1174. (equal "* foo bar :tag:"
  1175. (let (org-auto-align-tags)
  1176. (org-test-with-temp-text
  1177. "* foo <point>:tag:\n bar"
  1178. (org-delete-indentation t)
  1179. (buffer-string))))))
  1180. (ert-deftest test-org/return ()
  1181. "Test `org-return' specifications."
  1182. ;; Regular test.
  1183. (should
  1184. (equal "Para\ngraph"
  1185. (org-test-with-temp-text "Para<point>graph"
  1186. (org-return)
  1187. (buffer-string))))
  1188. ;; With optional argument, indent line.
  1189. (should
  1190. (equal " Para\n graph"
  1191. (org-test-with-temp-text " Para<point>graph"
  1192. (org-return t)
  1193. (buffer-string))))
  1194. ;; On a table, call `org-table-next-row'.
  1195. (should
  1196. (org-test-with-temp-text "| <point>a |\n| b |"
  1197. (org-return)
  1198. (looking-at-p "b")))
  1199. ;; Open link or timestamp under point when `org-return-follows-link'
  1200. ;; is non-nil.
  1201. (should
  1202. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1203. (let ((org-return-follows-link t)
  1204. (org-link-search-must-match-exact-headline nil))
  1205. (org-return))
  1206. (looking-at-p "<<target>>")))
  1207. (should-not
  1208. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1209. (let ((org-return-follows-link nil)) (org-return))
  1210. (looking-at-p "<<target>>")))
  1211. (should
  1212. (org-test-with-temp-text "* [[b][a<point>]]\n* b"
  1213. (let ((org-return-follows-link t)) (org-return))
  1214. (looking-at-p "* b")))
  1215. (should
  1216. (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
  1217. (let ((org-return-follows-link t)
  1218. (org-link-search-must-match-exact-headline nil))
  1219. (org-return))
  1220. (looking-at-p "<<target>>")))
  1221. (should-not
  1222. (org-test-with-temp-text "Link [[target]]<point> <<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. ;; When `org-return-follows-link' is non-nil, tolerate links and
  1228. ;; timestamps in comments, node properties, etc.
  1229. (should
  1230. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1231. (let ((org-return-follows-link t)
  1232. (org-link-search-must-match-exact-headline nil))
  1233. (org-return))
  1234. (looking-at-p "<<target>>")))
  1235. (should-not
  1236. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1237. (let ((org-return-follows-link nil)) (org-return))
  1238. (looking-at-p "<<target>>")))
  1239. (should-not
  1240. (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
  1241. (let ((org-return-follows-link t)
  1242. (org-link-search-must-match-exact-headline nil))
  1243. (org-return))
  1244. (looking-at-p "<<target>>")))
  1245. ;; Non-nil `org-return-follows-link' ignores read-only state of
  1246. ;; a buffer.
  1247. (should
  1248. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1249. (let ((org-return-follows-link t)
  1250. (org-link-search-must-match-exact-headline nil))
  1251. (setq buffer-read-only t)
  1252. (call-interactively #'org-return))
  1253. (looking-at-p "<<target>>")))
  1254. ;; `org-return-follows-link' handle multi-line lines.
  1255. (should
  1256. (org-test-with-temp-text
  1257. "[[target][This is a very\n long description<point>]]\n <<target>>"
  1258. (let ((org-return-follows-link t)
  1259. (org-link-search-must-match-exact-headline nil))
  1260. (org-return))
  1261. (looking-at-p "<<target>>")))
  1262. (should-not
  1263. (org-test-with-temp-text
  1264. "[[target][This is a very\n long description]]<point>\n <<target>>"
  1265. (let ((org-return-follows-link t)
  1266. (org-link-search-must-match-exact-headline nil))
  1267. (org-return))
  1268. (looking-at-p "<<target>>")))
  1269. ;; However, do not open link when point is in a table.
  1270. (should
  1271. (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
  1272. (let ((org-return-follows-link t)) (org-return))
  1273. (looking-at-p "between")))
  1274. ;; Special case: in a list, when indenting, do not break structure.
  1275. (should
  1276. (equal "- A\n B"
  1277. (org-test-with-temp-text "- A <point>B"
  1278. (org-return t)
  1279. (buffer-string))))
  1280. (should
  1281. (equal "- A\n\n- B"
  1282. (org-test-with-temp-text "- A\n<point>- B"
  1283. (org-return t)
  1284. (buffer-string))))
  1285. ;; On tags part of a headline, add a newline below it instead of
  1286. ;; breaking it.
  1287. (should
  1288. (equal "* H :tag:\n"
  1289. (org-test-with-temp-text "* H :<point>tag:"
  1290. (org-return)
  1291. (buffer-string))))
  1292. ;; Before headline text, add a newline below it instead of breaking
  1293. ;; it.
  1294. (should
  1295. (equal "* TODO H :tag:\n"
  1296. (org-test-with-temp-text "* <point>TODO H :tag:"
  1297. (org-return)
  1298. (buffer-string))))
  1299. (should
  1300. (equal "* TODO [#B] H :tag:\n"
  1301. (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
  1302. (org-return)
  1303. (buffer-string))))
  1304. (should ;TODO are case-sensitive
  1305. (equal "* \nTodo"
  1306. (org-test-with-temp-text "* <point>Todo"
  1307. (org-return)
  1308. (buffer-string))))
  1309. ;; At headline text, break headline text but preserve tags.
  1310. (should
  1311. (equal "* TODO [#B] foo :tag:\nbar"
  1312. (let (org-auto-align-tags)
  1313. (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
  1314. (org-return)
  1315. (buffer-string)))))
  1316. ;; At bol of headline insert newline.
  1317. (should
  1318. (equal "\n* h"
  1319. (org-test-with-temp-text "<point>* h"
  1320. (org-return)
  1321. (buffer-string))))
  1322. ;; Refuse to leave invalid headline in buffer.
  1323. (should
  1324. (equal "* h\n"
  1325. (org-test-with-temp-text "*<point> h"
  1326. (org-return)
  1327. (buffer-string))))
  1328. ;; Before first column or after last one in a table, split the
  1329. ;; table.
  1330. (should
  1331. (equal "| a |\n\n| b |"
  1332. (org-test-with-temp-text "| a |\n<point>| b |"
  1333. (org-return)
  1334. (buffer-string))))
  1335. (should
  1336. (equal "| a |\n\n| b |"
  1337. (org-test-with-temp-text "| a |<point>\n| b |"
  1338. (org-return)
  1339. (buffer-string))))
  1340. ;; Do not auto-fill on hitting <RET> inside a property drawer.
  1341. (should
  1342. (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:"
  1343. (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:"
  1344. (setq-local fill-column 10)
  1345. (auto-fill-mode 1)
  1346. (org-return)
  1347. (buffer-string)))))
  1348. (ert-deftest test-org/with-electric-indent ()
  1349. "Test RET and C-j specifications with `electric-indent-mode' on."
  1350. ;; Call commands interactively, since this is how `newline' knows it
  1351. ;; must run `post-self-insert-hook'.
  1352. ;;
  1353. ;; RET, like `newline', should indent.
  1354. (should
  1355. (equal " Para\n graph"
  1356. (org-test-with-temp-text " Para<point>graph"
  1357. (electric-indent-local-mode 1)
  1358. (call-interactively 'org-return)
  1359. (buffer-string))))
  1360. (should
  1361. (equal "- item1\n item2"
  1362. (org-test-with-temp-text "- item1<point>item2"
  1363. (electric-indent-local-mode 1)
  1364. (call-interactively 'org-return)
  1365. (buffer-string))))
  1366. (should
  1367. (equal "* heading\n body"
  1368. (org-test-with-temp-text "* heading<point>body"
  1369. (electric-indent-local-mode 1)
  1370. (call-interactively 'org-return)
  1371. (buffer-string))))
  1372. ;; C-j, like `electric-newline-and-maybe-indent', should not indent.
  1373. (should
  1374. (equal " Para\ngraph"
  1375. (org-test-with-temp-text " Para<point>graph"
  1376. (electric-indent-local-mode 1)
  1377. (call-interactively 'org-return-and-maybe-indent)
  1378. (buffer-string))))
  1379. (should
  1380. (equal "- item1\nitem2"
  1381. (org-test-with-temp-text "- item1<point>item2"
  1382. (electric-indent-local-mode 1)
  1383. (call-interactively 'org-return-and-maybe-indent)
  1384. (buffer-string))))
  1385. (should
  1386. (equal "* heading\nbody"
  1387. (org-test-with-temp-text "* heading<point>body"
  1388. (electric-indent-local-mode 1)
  1389. (call-interactively 'org-return-and-maybe-indent)
  1390. (buffer-string)))))
  1391. (ert-deftest test-org/without-electric-indent ()
  1392. "Test RET and C-j specifications with `electric-indent-mode' off."
  1393. ;; Call commands interactively, since this is how `newline' knows it
  1394. ;; must run `post-self-insert-hook'.
  1395. ;;
  1396. ;; RET, like `newline', should not indent.
  1397. (should
  1398. (equal " Para\ngraph"
  1399. (org-test-with-temp-text " Para<point>graph"
  1400. (electric-indent-local-mode 0)
  1401. (call-interactively 'org-return)
  1402. (buffer-string))))
  1403. (should
  1404. (equal "- item1\nitem2"
  1405. (org-test-with-temp-text "- item1<point>item2"
  1406. (electric-indent-local-mode 0)
  1407. (call-interactively 'org-return)
  1408. (buffer-string))))
  1409. (should
  1410. (equal "* heading\nbody"
  1411. (org-test-with-temp-text "* heading<point>body"
  1412. (electric-indent-local-mode 0)
  1413. (call-interactively 'org-return)
  1414. (buffer-string))))
  1415. ;; C-j, like `electric-newline-and-maybe-indent', should indent.
  1416. (should
  1417. (equal " Para\n graph"
  1418. (org-test-with-temp-text " Para<point>graph"
  1419. (electric-indent-local-mode 0)
  1420. (call-interactively 'org-return-and-maybe-indent)
  1421. (buffer-string))))
  1422. (should
  1423. (equal "- item1\n item2"
  1424. (org-test-with-temp-text "- item1<point>item2"
  1425. (electric-indent-local-mode 0)
  1426. (call-interactively 'org-return-and-maybe-indent)
  1427. (buffer-string))))
  1428. (should
  1429. (equal "* heading\n body"
  1430. (org-test-with-temp-text "* heading<point>body"
  1431. (electric-indent-local-mode 0)
  1432. (call-interactively 'org-return-and-maybe-indent)
  1433. (buffer-string)))))
  1434. (ert-deftest test-org/meta-return ()
  1435. "Test M-RET (`org-meta-return') specifications."
  1436. ;; In a table field insert a row above.
  1437. (should
  1438. (org-test-with-temp-text "| a |"
  1439. (forward-char)
  1440. (org-meta-return)
  1441. (forward-line -1)
  1442. (looking-at "| |$")))
  1443. ;; In a paragraph change current line into a header.
  1444. (should
  1445. (org-test-with-temp-text "a"
  1446. (org-meta-return)
  1447. (beginning-of-line)
  1448. (looking-at "\* a$")))
  1449. ;; In an item insert an item, in this case above.
  1450. (should
  1451. (org-test-with-temp-text "- a"
  1452. (org-meta-return)
  1453. (beginning-of-line)
  1454. (looking-at "- $")))
  1455. ;; In a drawer and item insert an item, in this case above.
  1456. (should
  1457. (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
  1458. (forward-line)
  1459. (org-meta-return)
  1460. (beginning-of-line)
  1461. (looking-at "- $"))))
  1462. (ert-deftest test-org/insert-heading ()
  1463. "Test `org-insert-heading' specifications."
  1464. ;; In an empty buffer, insert a new headline.
  1465. (should
  1466. (equal "* "
  1467. (org-test-with-temp-text ""
  1468. (org-insert-heading)
  1469. (buffer-string))))
  1470. ;; At the beginning of a line, turn it into a headline.
  1471. (should
  1472. (equal "* P"
  1473. (org-test-with-temp-text "<point>P"
  1474. (org-insert-heading)
  1475. (buffer-string))))
  1476. ;; In the middle of a line, split the line if allowed, otherwise,
  1477. ;; insert the headline at its end.
  1478. (should
  1479. (equal "Para\n* graph"
  1480. (org-test-with-temp-text "Para<point>graph"
  1481. (let ((org-M-RET-may-split-line '((default . t))))
  1482. (org-insert-heading))
  1483. (buffer-string))))
  1484. (should
  1485. (equal "Paragraph\n* "
  1486. (org-test-with-temp-text "Para<point>graph"
  1487. (let ((org-M-RET-may-split-line '((default . nil))))
  1488. (org-insert-heading))
  1489. (buffer-string))))
  1490. ;; At the beginning of a headline, create one above.
  1491. (should
  1492. (equal "* \n* H"
  1493. (org-test-with-temp-text "* H"
  1494. (org-insert-heading)
  1495. (buffer-string))))
  1496. ;; In the middle of a headline, split it if allowed.
  1497. (should
  1498. (equal "* H\n* 1"
  1499. (org-test-with-temp-text "* H<point>1"
  1500. (let ((org-M-RET-may-split-line '((headline . t))))
  1501. (org-insert-heading))
  1502. (buffer-string))))
  1503. (should
  1504. (equal "* H1\n* "
  1505. (org-test-with-temp-text "* H<point>1"
  1506. (let ((org-M-RET-may-split-line '((headline . nil))))
  1507. (org-insert-heading))
  1508. (buffer-string))))
  1509. ;; However, splitting cannot happen on TODO keywords, priorities or
  1510. ;; tags.
  1511. (should
  1512. (equal "* TODO H1\n* "
  1513. (org-test-with-temp-text "* TO<point>DO H1"
  1514. (let ((org-M-RET-may-split-line '((headline . t))))
  1515. (org-insert-heading))
  1516. (buffer-string))))
  1517. (should
  1518. (equal "* [#A] H1\n* "
  1519. (org-test-with-temp-text "* [#<point>A] H1"
  1520. (let ((org-M-RET-may-split-line '((headline . t))))
  1521. (org-insert-heading))
  1522. (buffer-string))))
  1523. (should
  1524. (equal "* H1 :tag:\n* "
  1525. (org-test-with-temp-text "* H1 :ta<point>g:"
  1526. (let ((org-M-RET-may-split-line '((headline . t))))
  1527. (org-insert-heading))
  1528. (buffer-string))))
  1529. ;; New headline level depends on the level of the headline above.
  1530. (should
  1531. (equal "** H\n** P"
  1532. (org-test-with-temp-text "** H\n<point>P"
  1533. (org-insert-heading)
  1534. (buffer-string))))
  1535. (should
  1536. (equal "** H\nPara\n** graph"
  1537. (org-test-with-temp-text "** H\nPara<point>graph"
  1538. (let ((org-M-RET-may-split-line '((default . t))))
  1539. (org-insert-heading))
  1540. (buffer-string))))
  1541. (should
  1542. (equal "** \n** H"
  1543. (org-test-with-temp-text "** H"
  1544. (org-insert-heading)
  1545. (buffer-string))))
  1546. ;; When called with one universal argument, insert a new headline at
  1547. ;; the end of the current subtree, independently on the position of
  1548. ;; point.
  1549. (should
  1550. (equal
  1551. "* H1\n** H2\n* "
  1552. (org-test-with-temp-text "* H1\n** H2"
  1553. (let ((org-insert-heading-respect-content nil))
  1554. (org-insert-heading '(4)))
  1555. (buffer-string))))
  1556. (should
  1557. (equal
  1558. "* H1\n** H2\n* "
  1559. (org-test-with-temp-text "* H<point>1\n** H2"
  1560. (let ((org-insert-heading-respect-content nil))
  1561. (org-insert-heading '(4)))
  1562. (buffer-string))))
  1563. ;; When called with two universal arguments, insert a new headline
  1564. ;; at the end of the grandparent subtree.
  1565. (should
  1566. (equal "* H1\n** H3\n- item\n** H2\n** "
  1567. (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
  1568. (let ((org-insert-heading-respect-content nil))
  1569. (org-insert-heading '(16)))
  1570. (buffer-string))))
  1571. ;; When optional TOP-LEVEL argument is non-nil, always insert
  1572. ;; a level 1 heading.
  1573. (should
  1574. (equal "* H1\n** H2\n* "
  1575. (org-test-with-temp-text "* H1\n** H2<point>"
  1576. (org-insert-heading nil nil t)
  1577. (buffer-string))))
  1578. (should
  1579. (equal "* H1\n- item\n* "
  1580. (org-test-with-temp-text "* H1\n- item<point>"
  1581. (org-insert-heading nil nil t)
  1582. (buffer-string))))
  1583. ;; Obey `org-blank-before-new-entry'.
  1584. (should
  1585. (equal "* H1\n\n* "
  1586. (org-test-with-temp-text "* H1<point>"
  1587. (let ((org-blank-before-new-entry '((heading . t))))
  1588. (org-insert-heading))
  1589. (buffer-string))))
  1590. (should
  1591. (equal "* H1\n* "
  1592. (org-test-with-temp-text "* H1<point>"
  1593. (let ((org-blank-before-new-entry '((heading . nil))))
  1594. (org-insert-heading))
  1595. (buffer-string))))
  1596. (should
  1597. (equal "* H1\n* H2\n* "
  1598. (org-test-with-temp-text "* H1\n* H2<point>"
  1599. (let ((org-blank-before-new-entry '((heading . auto))))
  1600. (org-insert-heading))
  1601. (buffer-string))))
  1602. (should
  1603. (equal "* H1\n\n* H2\n\n* "
  1604. (org-test-with-temp-text "* H1\n\n* H2<point>"
  1605. (let ((org-blank-before-new-entry '((heading . auto))))
  1606. (org-insert-heading))
  1607. (buffer-string))))
  1608. ;; Corner case: correctly insert a headline after an empty one.
  1609. (should
  1610. (equal "* \n* "
  1611. (org-test-with-temp-text "* <point>"
  1612. (org-insert-heading)
  1613. (buffer-string))))
  1614. (should
  1615. (org-test-with-temp-text "* <point>\n"
  1616. (org-insert-heading)
  1617. (looking-at-p "\n\\'")))
  1618. ;; Do not insert spurious headlines when inserting a new headline.
  1619. (should
  1620. (equal "* H1\n* H2\n* \n"
  1621. (org-test-with-temp-text "* H1\n* H2<point>\n"
  1622. (org-insert-heading)
  1623. (buffer-string))))
  1624. ;; Preserve visibility at beginning of line. In particular, when
  1625. ;; removing spurious blank lines, do not visually merge heading with
  1626. ;; the line visible above.
  1627. (should-not
  1628. (org-test-with-temp-text "* H1<point>\nContents\n\n* H2\n"
  1629. (org-overview)
  1630. (let ((org-blank-before-new-entry '((heading . nil))))
  1631. (org-insert-heading '(4)))
  1632. (invisible-p (line-end-position 0))))
  1633. ;; Properly handle empty lines when forcing a headline below current
  1634. ;; one.
  1635. (should
  1636. (equal "* H1\n\n* H\n\n* "
  1637. (org-test-with-temp-text "* H1\n\n* H<point>"
  1638. (let ((org-blank-before-new-entry '((heading . t))))
  1639. (org-insert-heading '(4))
  1640. (buffer-string))))))
  1641. (ert-deftest test-org/insert-todo-heading-respect-content ()
  1642. "Test `org-insert-todo-heading-respect-content' specifications."
  1643. ;; Create a TODO heading.
  1644. (should
  1645. (org-test-with-temp-text "* H1\n Body"
  1646. (org-insert-todo-heading-respect-content)
  1647. (nth 2 (org-heading-components))))
  1648. ;; Add headline at the end of the first subtree
  1649. (should
  1650. (equal
  1651. "* TODO "
  1652. (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
  1653. (org-insert-todo-heading-respect-content)
  1654. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1655. ;; In a list, do not create a new item.
  1656. (should
  1657. (equal
  1658. "* TODO "
  1659. (org-test-with-temp-text "* H\n- an item\n- another one"
  1660. (search-forward "an ")
  1661. (org-insert-todo-heading-respect-content)
  1662. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1663. ;; Use the same TODO keyword as current heading.
  1664. (should
  1665. (equal
  1666. "* TODO \n"
  1667. (org-test-with-temp-text "* TODO\n** WAITING\n"
  1668. (org-insert-todo-heading-respect-content)
  1669. (buffer-substring-no-properties (line-beginning-position) (point-max))))))
  1670. (ert-deftest test-org/clone-with-time-shift ()
  1671. "Test `org-clone-subtree-with-time-shift'."
  1672. ;; Raise an error before first heading.
  1673. (should-error
  1674. (org-test-with-temp-text ""
  1675. (org-clone-subtree-with-time-shift 1)))
  1676. ;; Raise an error on invalid number of clones.
  1677. (should-error
  1678. (org-test-with-temp-text "* Clone me"
  1679. (org-clone-subtree-with-time-shift -1)))
  1680. ;; Clone non-repeating once.
  1681. (should
  1682. (equal "\
  1683. * H1\n<2015-06-21>
  1684. * H1\n<2015-06-23>
  1685. "
  1686. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1687. (org-clone-subtree-with-time-shift 1 "+2d")
  1688. (replace-regexp-in-string
  1689. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1690. nil nil 1))))
  1691. ;; Clone repeating once.
  1692. (should
  1693. (equal "\
  1694. * H1\n<2015-06-21>
  1695. * H1\n<2015-06-23>
  1696. * H1\n<2015-06-25 +1w>
  1697. "
  1698. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  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 in backward.
  1704. (should
  1705. (equal "\
  1706. * H1\n<2015-06-21>
  1707. * H1\n<2015-06-19>
  1708. * H1\n<2015-06-17 +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 non-repeating zero times.
  1716. (should
  1717. (equal "\
  1718. * H1\n<2015-06-21>
  1719. "
  1720. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1721. (org-clone-subtree-with-time-shift 0 "+2d")
  1722. (replace-regexp-in-string
  1723. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1724. nil nil 1))))
  1725. ;; Clone repeating "zero" times.
  1726. (should
  1727. (equal "\
  1728. * H1\n<2015-06-21>
  1729. * H1\n<2015-06-23 +1w>
  1730. "
  1731. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1732. (org-clone-subtree-with-time-shift 0 "+2d")
  1733. (replace-regexp-in-string
  1734. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1735. nil nil 1))))
  1736. ;; Clone with blank SHIFT argument.
  1737. (should
  1738. (string-prefix-p
  1739. "* H <2012-03-29"
  1740. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1741. (org-clone-subtree-with-time-shift 1 "")
  1742. (buffer-substring-no-properties (line-beginning-position 2)
  1743. (line-end-position 2)))))
  1744. ;; Find time stamps before point. If SHIFT is not specified, ask
  1745. ;; for a time shift.
  1746. (should
  1747. (string-prefix-p
  1748. "* H <2012-03-30"
  1749. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1750. (org-clone-subtree-with-time-shift 1 "+1d")
  1751. (buffer-substring-no-properties (line-beginning-position 2)
  1752. (line-end-position 2)))))
  1753. (should
  1754. (string-prefix-p
  1755. "* H <2014-03-05"
  1756. (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
  1757. (cl-letf (((symbol-function 'read-from-minibuffer)
  1758. (lambda (&rest args) "+1d")))
  1759. (org-clone-subtree-with-time-shift 1))
  1760. (buffer-substring-no-properties (line-beginning-position 2)
  1761. (line-end-position 2))))))
  1762. ;;; Fixed-Width Areas
  1763. (ert-deftest test-org/toggle-fixed-width ()
  1764. "Test `org-toggle-fixed-width' specifications."
  1765. ;; No region: Toggle on fixed-width marker in paragraphs.
  1766. (should
  1767. (equal ": A"
  1768. (org-test-with-temp-text "A"
  1769. (org-toggle-fixed-width)
  1770. (buffer-string))))
  1771. ;; No region: Toggle off fixed-width markers in fixed-width areas.
  1772. (should
  1773. (equal "A"
  1774. (org-test-with-temp-text ": A"
  1775. (org-toggle-fixed-width)
  1776. (buffer-string))))
  1777. ;; No region: Toggle on marker in blank lines after elements or just
  1778. ;; after a headline.
  1779. (should
  1780. (equal "* H\n: "
  1781. (org-test-with-temp-text "* H\n"
  1782. (forward-line)
  1783. (org-toggle-fixed-width)
  1784. (buffer-string))))
  1785. (should
  1786. (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
  1787. (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
  1788. (goto-char (point-max))
  1789. (org-toggle-fixed-width)
  1790. (buffer-string))))
  1791. ;; No region: Toggle on marker in front of one line elements (e.g.,
  1792. ;; headlines, clocks)
  1793. (should
  1794. (equal ": * Headline"
  1795. (org-test-with-temp-text "* Headline"
  1796. (org-toggle-fixed-width)
  1797. (buffer-string))))
  1798. (should
  1799. (equal ": #+KEYWORD: value"
  1800. (org-test-with-temp-text "#+KEYWORD: value"
  1801. (org-toggle-fixed-width)
  1802. (buffer-string))))
  1803. ;; No region: error in other situations.
  1804. (should-error
  1805. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
  1806. (forward-line)
  1807. (org-toggle-fixed-width)
  1808. (buffer-string)))
  1809. ;; No region: Indentation is preserved.
  1810. (should
  1811. (equal "- A\n : B"
  1812. (org-test-with-temp-text "- A\n B"
  1813. (forward-line)
  1814. (org-toggle-fixed-width)
  1815. (buffer-string))))
  1816. ;; Region: If it contains only fixed-width elements and blank lines,
  1817. ;; toggle off fixed-width markup.
  1818. (should
  1819. (equal "A\n\nB"
  1820. (org-test-with-temp-text ": A\n\n: B"
  1821. (transient-mark-mode 1)
  1822. (push-mark (point) t t)
  1823. (goto-char (point-max))
  1824. (org-toggle-fixed-width)
  1825. (buffer-string))))
  1826. ;; Region: If it contains anything else, toggle on fixed-width but
  1827. ;; not on fixed-width areas.
  1828. (should
  1829. (equal ": A\n: \n: B\n: \n: C"
  1830. (org-test-with-temp-text "A\n\n: B\n\nC"
  1831. (transient-mark-mode 1)
  1832. (push-mark (point) t t)
  1833. (goto-char (point-max))
  1834. (org-toggle-fixed-width)
  1835. (buffer-string))))
  1836. ;; Region: Ignore blank lines at its end, unless it contains only
  1837. ;; such lines.
  1838. (should
  1839. (equal ": A\n\n"
  1840. (org-test-with-temp-text "A\n\n"
  1841. (transient-mark-mode 1)
  1842. (push-mark (point) t t)
  1843. (goto-char (point-max))
  1844. (org-toggle-fixed-width)
  1845. (buffer-string))))
  1846. (should
  1847. (equal ": \n: \n"
  1848. (org-test-with-temp-text "\n\n"
  1849. (transient-mark-mode 1)
  1850. (push-mark (point) t t)
  1851. (goto-char (point-max))
  1852. (org-toggle-fixed-width)
  1853. (buffer-string)))))
  1854. (ert-deftest test-org/kill-line ()
  1855. "Test `org-kill-line' specifications."
  1856. ;; At the beginning of a line, kill whole line.
  1857. (should
  1858. (equal ""
  1859. (org-test-with-temp-text "abc"
  1860. (org-kill-line)
  1861. (buffer-string))))
  1862. ;; In the middle of a line, kill line until its end.
  1863. (should
  1864. (equal "a"
  1865. (org-test-with-temp-text "a<point>bc"
  1866. (org-kill-line)
  1867. (buffer-string))))
  1868. ;; Do not kill newline character.
  1869. (should
  1870. (equal "\n123"
  1871. (org-test-with-temp-text "abc\n123"
  1872. (org-kill-line)
  1873. (buffer-string))))
  1874. (should
  1875. (equal "a\n123"
  1876. (org-test-with-temp-text "a<point>bc\n123"
  1877. (org-kill-line)
  1878. (buffer-string))))
  1879. ;; When `org-special-ctrl-k' is non-nil and point is at a headline,
  1880. ;; kill until tags.
  1881. (should
  1882. (equal "* A :tag:"
  1883. (org-test-with-temp-text "* A<point>B :tag:"
  1884. (let ((org-special-ctrl-k t)
  1885. (org-tags-column 0))
  1886. (org-kill-line))
  1887. (buffer-string))))
  1888. ;; If point is on tags, only kill part left until the end of line.
  1889. (should
  1890. (equal "* A :tag:"
  1891. (org-test-with-temp-text "* A :tag:<point>tag2:"
  1892. (let ((org-special-ctrl-k t)
  1893. (org-tags-column 0))
  1894. (org-kill-line))
  1895. (buffer-string))))
  1896. ;; However, if point is at the beginning of the line, kill whole
  1897. ;; headline.
  1898. (should
  1899. (equal ""
  1900. (org-test-with-temp-text "* AB :tag:"
  1901. (let ((org-special-ctrl-k t)
  1902. (org-tags-column 0))
  1903. (org-kill-line))
  1904. (buffer-string))))
  1905. ;; When `org-ctrl-k-protect-subtree' is non-nil, and point is in
  1906. ;; invisible text, ask before removing it. When set to `error',
  1907. ;; throw an error.
  1908. (should-error
  1909. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  1910. (org-overview)
  1911. (let ((org-special-ctrl-k nil)
  1912. (org-ctrl-k-protect-subtree t))
  1913. (cl-letf (((symbol-function 'y-or-n-p) 'ignore))
  1914. (org-kill-line)))))
  1915. (should-error
  1916. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  1917. (org-overview)
  1918. (let ((org-special-ctrl-k nil)
  1919. (org-ctrl-k-protect-subtree 'error))
  1920. (org-kill-line)))))
  1921. ;;; Headline
  1922. (ert-deftest test-org/get-heading ()
  1923. "Test `org-get-heading' specifications."
  1924. ;; Return current heading, even if point is not on it.
  1925. (should
  1926. (equal "H"
  1927. (org-test-with-temp-text "* H"
  1928. (org-get-heading))))
  1929. (should
  1930. (equal "H"
  1931. (org-test-with-temp-text "* H\nText<point>"
  1932. (org-get-heading))))
  1933. ;; Without any optional argument, return TODO keyword, priority
  1934. ;; cookie, COMMENT keyword and tags.
  1935. (should
  1936. (equal "TODO H"
  1937. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  1938. (org-get-heading))))
  1939. (should
  1940. (equal "[#A] H"
  1941. (org-test-with-temp-text "* [#A] H"
  1942. (org-get-heading))))
  1943. (should
  1944. (equal "COMMENT H"
  1945. (org-test-with-temp-text "* COMMENT H"
  1946. (org-get-heading))))
  1947. (should
  1948. (equal "H :tag:"
  1949. (org-test-with-temp-text "* H :tag:"
  1950. (org-get-heading))))
  1951. ;; With NO-TAGS argument, ignore tags.
  1952. (should
  1953. (equal "TODO H"
  1954. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  1955. (org-get-heading t))))
  1956. (should
  1957. (equal "H"
  1958. (org-test-with-temp-text "* H :tag:"
  1959. (org-get-heading t))))
  1960. ;; With NO-TODO, ignore TODO keyword.
  1961. (should
  1962. (equal "H"
  1963. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  1964. (org-get-heading nil t))))
  1965. (should
  1966. (equal "H :tag:"
  1967. (org-test-with-temp-text "* H :tag:"
  1968. (org-get-heading nil t))))
  1969. ;; TODO keywords are case-sensitive.
  1970. (should
  1971. (equal "Todo H"
  1972. (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
  1973. (org-get-heading nil t))))
  1974. ;; With NO-PRIORITY, ignore priority.
  1975. (should
  1976. (equal "H"
  1977. (org-test-with-temp-text "* [#A] H"
  1978. (org-get-heading nil nil t))))
  1979. (should
  1980. (equal "H"
  1981. (org-test-with-temp-text "* H"
  1982. (org-get-heading nil nil t))))
  1983. (should
  1984. (equal "TODO H"
  1985. (org-test-with-temp-text "* TODO [#A] H"
  1986. (org-get-heading nil nil t))))
  1987. ;; With NO-COMMENT, ignore COMMENT keyword.
  1988. (should
  1989. (equal "H"
  1990. (org-test-with-temp-text "* COMMENT H"
  1991. (org-get-heading nil nil nil t))))
  1992. (should
  1993. (equal "H"
  1994. (org-test-with-temp-text "* H"
  1995. (org-get-heading nil nil nil t))))
  1996. (should
  1997. (equal "TODO [#A] H"
  1998. (org-test-with-temp-text "* TODO [#A] COMMENT H"
  1999. (org-get-heading nil nil nil t))))
  2000. ;; On an empty headline, return value is consistent.
  2001. (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
  2002. (should (equal "" (org-test-with-temp-text "* " (org-get-heading t))))
  2003. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t))))
  2004. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t))))
  2005. (should
  2006. (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t)))))
  2007. (ert-deftest test-org/in-commented-heading-p ()
  2008. "Test `org-in-commented-heading-p' specifications."
  2009. ;; Commented headline.
  2010. (should
  2011. (org-test-with-temp-text "* COMMENT Headline\nBody"
  2012. (goto-char (point-max))
  2013. (org-in-commented-heading-p)))
  2014. ;; Commented ancestor.
  2015. (should
  2016. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  2017. (goto-char (point-max))
  2018. (org-in-commented-heading-p)))
  2019. ;; Comment keyword is case-sensitive.
  2020. (should-not
  2021. (org-test-with-temp-text "* Comment Headline\nBody"
  2022. (goto-char (point-max))
  2023. (org-in-commented-heading-p)))
  2024. ;; Keyword is standalone.
  2025. (should-not
  2026. (org-test-with-temp-text "* COMMENTHeadline\nBody"
  2027. (goto-char (point-max))
  2028. (org-in-commented-heading-p)))
  2029. ;; Optional argument.
  2030. (should-not
  2031. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  2032. (goto-char (point-max))
  2033. (org-in-commented-heading-p t))))
  2034. (ert-deftest test-org/in-archived-heading-p ()
  2035. "Test `org-in-archived-heading-p' specifications."
  2036. ;; Archived headline.
  2037. (should
  2038. (org-test-with-temp-text "* Headline :ARCHIVE:\nBody"
  2039. (goto-char (point-max))
  2040. (org-in-archived-heading-p)))
  2041. ;; Archived ancestor.
  2042. (should
  2043. (org-test-with-temp-text "* Headline :ARCHIVE:\n** Level 2\nBody"
  2044. (goto-char (point-max))
  2045. (org-in-archived-heading-p)))
  2046. ;; Optional argument.
  2047. (should-not
  2048. (org-test-with-temp-text "* Headline :ARCHIVE:\n** Level 2\nBody"
  2049. (goto-char (point-max))
  2050. (org-in-archived-heading-p t))))
  2051. (ert-deftest test-org/entry-blocked-p ()
  2052. ;; Check other dependencies.
  2053. (should
  2054. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  2055. (let ((org-enforce-todo-dependencies t)
  2056. (org-blocker-hook
  2057. '(org-block-todo-from-children-or-siblings-or-parent)))
  2058. (org-entry-blocked-p))))
  2059. (should-not
  2060. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  2061. (let ((org-enforce-todo-dependencies t)
  2062. (org-blocker-hook
  2063. '(org-block-todo-from-children-or-siblings-or-parent)))
  2064. (org-entry-blocked-p))))
  2065. ;; Entry without a TODO keyword or with a DONE keyword cannot be
  2066. ;; blocked.
  2067. (should-not
  2068. (org-test-with-temp-text "* Blocked\n** TODO one"
  2069. (let ((org-enforce-todo-dependencies t)
  2070. (org-blocker-hook
  2071. '(org-block-todo-from-children-or-siblings-or-parent)))
  2072. (org-entry-blocked-p))))
  2073. (should-not
  2074. (org-test-with-temp-text "* DONE Blocked\n** TODO one"
  2075. (let ((org-enforce-todo-dependencies t)
  2076. (org-blocker-hook
  2077. '(org-block-todo-from-children-or-siblings-or-parent)))
  2078. (org-entry-blocked-p))))
  2079. ;; Follow :ORDERED: specifications.
  2080. (should
  2081. (org-test-with-temp-text
  2082. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
  2083. (let ((org-enforce-todo-dependencies t)
  2084. (org-blocker-hook
  2085. '(org-block-todo-from-children-or-siblings-or-parent)))
  2086. (org-entry-blocked-p))))
  2087. (should-not
  2088. (org-test-with-temp-text
  2089. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
  2090. (let ((org-enforce-todo-dependencies t)
  2091. (org-blocker-hook
  2092. '(org-block-todo-from-children-or-siblings-or-parent)))
  2093. (org-entry-blocked-p)))))
  2094. (ert-deftest test-org/get-outline-path ()
  2095. "Test `org-get-outline-path' specifications."
  2096. ;; Top-level headlines have no outline path.
  2097. (should-not
  2098. (org-test-with-temp-text "* H"
  2099. (org-get-outline-path)))
  2100. ;; Otherwise, outline path is the path leading to the headline.
  2101. (should
  2102. (equal '("H")
  2103. (org-test-with-temp-text "* H\n** S<point>"
  2104. (org-get-outline-path))))
  2105. ;; Find path even when point is not on a headline.
  2106. (should
  2107. (equal '("H")
  2108. (org-test-with-temp-text "* H\n** S\nText<point>"
  2109. (org-get-outline-path))))
  2110. ;; TODO keywords, tags and statistics cookies are ignored.
  2111. (should
  2112. (equal '("H")
  2113. (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
  2114. (org-get-outline-path))))
  2115. ;; Links are replaced with their description or their path.
  2116. (should
  2117. (equal '("Org")
  2118. (org-test-with-temp-text
  2119. "* [[https://orgmode.org][Org]]\n** S<point>"
  2120. (org-get-outline-path))))
  2121. (should
  2122. (equal '("https://orgmode.org")
  2123. (org-test-with-temp-text
  2124. "* [[https://orgmode.org]]\n** S<point>"
  2125. (org-get-outline-path))))
  2126. ;; When WITH-SELF is non-nil, include current heading.
  2127. (should
  2128. (equal '("H")
  2129. (org-test-with-temp-text "* H"
  2130. (org-get-outline-path t))))
  2131. (should
  2132. (equal '("H" "S")
  2133. (org-test-with-temp-text "* H\n** S\nText<point>"
  2134. (org-get-outline-path t))))
  2135. ;; Using cache is transparent to the user.
  2136. (should
  2137. (equal '("H")
  2138. (org-test-with-temp-text "* H\n** S<point>"
  2139. (setq org-outline-path-cache nil)
  2140. (org-get-outline-path nil t))))
  2141. ;; Do not corrupt cache when finding outline path in distant part of
  2142. ;; the buffer.
  2143. (should
  2144. (equal '("H2")
  2145. (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
  2146. (setq org-outline-path-cache nil)
  2147. (org-get-outline-path nil t)
  2148. (search-forward "S2")
  2149. (org-get-outline-path nil t))))
  2150. ;; Do not choke on empty headlines.
  2151. (should
  2152. (org-test-with-temp-text "* H\n** <point>"
  2153. (org-get-outline-path)))
  2154. (should
  2155. (org-test-with-temp-text "* \n** H<point>"
  2156. (org-get-outline-path))))
  2157. (ert-deftest test-org/format-outline-path ()
  2158. "Test `org-format-outline-path' specifications."
  2159. (should
  2160. (string= (org-format-outline-path (list "one" "two" "three"))
  2161. "one/two/three"))
  2162. ;; Empty path.
  2163. (should
  2164. (string= (org-format-outline-path '())
  2165. ""))
  2166. (should
  2167. (string= (org-format-outline-path '(nil))
  2168. ""))
  2169. ;; Empty path and prefix.
  2170. (should
  2171. (string= (org-format-outline-path '() nil ">>")
  2172. ">>"))
  2173. ;; Trailing whitespace in headings.
  2174. (should
  2175. (string= (org-format-outline-path (list "one\t" "tw o " "three "))
  2176. "one/tw o/three"))
  2177. ;; Non-default prefix and separators.
  2178. (should
  2179. (string= (org-format-outline-path (list "one" "two" "three") nil ">>" "|")
  2180. ">>|one|two|three"))
  2181. ;; Truncate.
  2182. (should
  2183. (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
  2184. "one/two/.."))
  2185. ;; Give a very narrow width.
  2186. (should
  2187. (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
  2188. "on"))
  2189. ;; Give a prefix that extends beyond the width.
  2190. (should
  2191. (string= (org-format-outline-path (list "one" "two" "three" "four") 10
  2192. ">>>>>>>>>>")
  2193. ">>>>>>>>..")))
  2194. (ert-deftest test-org/map-entries ()
  2195. "Test `org-map-entries' specifications."
  2196. ;; Full match.
  2197. (should
  2198. (equal '(1 11)
  2199. (org-test-with-temp-text "* Level 1\n** Level 2"
  2200. (org-map-entries #'point))))
  2201. ;; Level match.
  2202. (should
  2203. (equal '(1)
  2204. (org-test-with-temp-text "* Level 1\n** Level 2"
  2205. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL=1")))))
  2206. (should
  2207. (equal '(11)
  2208. (org-test-with-temp-text "* Level 1\n** Level 2"
  2209. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL>1")))))
  2210. ;; Tag match.
  2211. (should
  2212. (equal '(11)
  2213. (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
  2214. (org-map-entries #'point "yes"))))
  2215. (should
  2216. (equal '(14)
  2217. (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
  2218. (org-map-entries #'point "+yes-a"))))
  2219. (should
  2220. (equal '(11 23)
  2221. (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
  2222. (org-map-entries #'point "{yes?}"))))
  2223. ;; Priority match.
  2224. (should
  2225. (equal '(1)
  2226. (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
  2227. (org-map-entries #'point "PRIORITY=\"A\""))))
  2228. ;; Date match.
  2229. (should
  2230. (equal '(36)
  2231. (org-test-with-temp-text "
  2232. * H1
  2233. SCHEDULED: <2012-03-29 thu.>
  2234. * H2
  2235. SCHEDULED: <2014-03-04 tue.>"
  2236. (org-map-entries #'point "SCHEDULED=\"<2014-03-04 tue.>\""))))
  2237. (should
  2238. (equal '(2)
  2239. (org-test-with-temp-text "
  2240. * H1
  2241. SCHEDULED: <2012-03-29 thu.>
  2242. * H2
  2243. SCHEDULED: <2014-03-04 tue.>"
  2244. (org-map-entries #'point "SCHEDULED<\"<2013-01-01>\""))))
  2245. ;; Regular property match.
  2246. (should
  2247. (equal '(2)
  2248. (org-test-with-temp-text "
  2249. * H1
  2250. :PROPERTIES:
  2251. :TEST: 1
  2252. :END:
  2253. * H2
  2254. :PROPERTIES:
  2255. :TEST: 2
  2256. :END:"
  2257. (org-map-entries #'point "TEST=1"))))
  2258. ;; Multiple criteria.
  2259. (should
  2260. (equal '(23)
  2261. (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
  2262. (let (org-odd-levels-only
  2263. (org-use-tag-inheritance nil))
  2264. (org-map-entries #'point "yes+LEVEL=1")))))
  2265. ;; "or" criteria.
  2266. (should
  2267. (equal '(12 24)
  2268. (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
  2269. (let (org-odd-levels-only)
  2270. (org-map-entries #'point "LEVEL=2|no")))))
  2271. (should
  2272. (equal '(1 12)
  2273. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
  2274. (let (org-odd-levels-only)
  2275. (org-map-entries #'point "yes|no")))))
  2276. ;; "and" criteria.
  2277. (should
  2278. (equal '(22)
  2279. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
  2280. (let (org-odd-levels-only)
  2281. (org-map-entries #'point "yes&no"))))))
  2282. (ert-deftest test-org/edit-headline ()
  2283. "Test `org-edit-headline' specifications."
  2284. (should
  2285. (equal "* B"
  2286. (org-test-with-temp-text "* A"
  2287. (org-edit-headline "B")
  2288. (buffer-string))))
  2289. ;; Handle empty headings.
  2290. (should
  2291. (equal "* "
  2292. (org-test-with-temp-text "* A"
  2293. (org-edit-headline "")
  2294. (buffer-string))))
  2295. (should
  2296. (equal "* A"
  2297. (org-test-with-temp-text "* "
  2298. (org-edit-headline "A")
  2299. (buffer-string))))
  2300. ;; Handle TODO keywords and priority cookies.
  2301. (should
  2302. (equal "* TODO B"
  2303. (org-test-with-temp-text "* TODO A"
  2304. (org-edit-headline "B")
  2305. (buffer-string))))
  2306. (should
  2307. (equal "* [#A] B"
  2308. (org-test-with-temp-text "* [#A] A"
  2309. (org-edit-headline "B")
  2310. (buffer-string))))
  2311. (should
  2312. (equal "* TODO [#A] B"
  2313. (org-test-with-temp-text "* TODO [#A] A"
  2314. (org-edit-headline "B")
  2315. (buffer-string))))
  2316. ;; Handle tags.
  2317. (equal "* B :tag:"
  2318. (org-test-with-temp-text "* A :tag:"
  2319. (let ((org-tags-column 4)) (org-edit-headline "B"))
  2320. (buffer-string))))
  2321. ;;; Keywords
  2322. (ert-deftest test-org/set-regexps-and-options ()
  2323. "Test `org-set-regexps-and-options' specifications."
  2324. ;; TAGS keyword.
  2325. (should
  2326. (equal '(("A"))
  2327. (let ((org-tag-alist '(("A")))
  2328. (org-tag-persistent-alist nil))
  2329. (org-test-with-temp-text ""
  2330. (org-mode-restart)
  2331. org-current-tag-alist))))
  2332. (should
  2333. (equal '(("B"))
  2334. (let ((org-tag-alist '(("A")))
  2335. (org-tag-persistent-alist nil))
  2336. (org-test-with-temp-text "#+TAGS: B"
  2337. (org-mode-restart)
  2338. org-current-tag-alist))))
  2339. (should
  2340. (equal '(("C") ("B"))
  2341. (let ((org-tag-alist '(("A")))
  2342. (org-tag-persistent-alist '(("C"))))
  2343. (org-test-with-temp-text "#+TAGS: B"
  2344. (org-mode-restart)
  2345. org-current-tag-alist))))
  2346. (should
  2347. (equal '(("B"))
  2348. (let ((org-tag-alist '(("A")))
  2349. (org-tag-persistent-alist '(("C"))))
  2350. (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
  2351. (org-mode-restart)
  2352. org-current-tag-alist))))
  2353. (should
  2354. (equal '(("A" . ?a) ("B") ("C"))
  2355. (let ((org-tag-persistant-alist nil))
  2356. (org-test-with-temp-text "#+TAGS: A(a) B C"
  2357. (org-mode-restart)
  2358. org-current-tag-alist))))
  2359. (should
  2360. (equal '(("A") (:newline) ("B"))
  2361. (let ((org-tag-persistent-alist nil))
  2362. (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
  2363. (org-mode-restart)
  2364. org-current-tag-alist))))
  2365. (should
  2366. (equal '((:startgroup) ("A") ("B") (:endgroup) ("C"))
  2367. (let ((org-tag-persistent-alist nil))
  2368. (org-test-with-temp-text "#+TAGS: { A B } C"
  2369. (org-mode-restart)
  2370. org-current-tag-alist))))
  2371. (should
  2372. (equal '((:startgroup) ("A") (:grouptags) ("B") ("C") (:endgroup))
  2373. (let ((org-tag-persistent-alist nil))
  2374. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2375. (org-mode-restart)
  2376. org-current-tag-alist))))
  2377. (should
  2378. (equal '(("A" "B" "C"))
  2379. (let ((org-tag-persistent-alist nil))
  2380. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2381. (org-mode-restart)
  2382. org-tag-groups-alist))))
  2383. (should
  2384. (equal '((:startgrouptag) ("A") (:grouptags) ("B") ("C") (:endgrouptag))
  2385. (let ((org-tag-persistent-alist nil))
  2386. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2387. (org-mode-restart)
  2388. org-current-tag-alist))))
  2389. (should
  2390. (equal '(("A" "B" "C"))
  2391. (let ((org-tag-persistent-alist nil))
  2392. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2393. (org-mode-restart)
  2394. org-tag-groups-alist))))
  2395. (should-not
  2396. (let ((org-tag-alist '(("A"))))
  2397. (org-test-with-temp-text "#+TAGS:"
  2398. (org-mode-restart)
  2399. org-current-tag-alist)))
  2400. ;; FILETAGS keyword.
  2401. (should
  2402. (equal '("A" "B" "C")
  2403. (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
  2404. (org-mode-restart)
  2405. org-file-tags)))
  2406. ;; PROPERTY keyword. Property names are case-insensitive.
  2407. (should
  2408. (equal "foo=1"
  2409. (org-test-with-temp-text "#+PROPERTY: var foo=1"
  2410. (org-mode-restart)
  2411. (cdr (assoc "var" org-keyword-properties)))))
  2412. (should
  2413. (equal
  2414. "foo=1 bar=2"
  2415. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
  2416. (org-mode-restart)
  2417. (cdr (assoc "var" org-keyword-properties)))))
  2418. (should
  2419. (equal
  2420. "foo=1 bar=2"
  2421. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
  2422. (org-mode-restart)
  2423. (cdr (assoc "var" org-keyword-properties)))))
  2424. ;; ARCHIVE keyword.
  2425. (should
  2426. (equal "%s_done::"
  2427. (org-test-with-temp-text "#+ARCHIVE: %s_done::"
  2428. (org-mode-restart)
  2429. org-archive-location)))
  2430. ;; CATEGORY keyword.
  2431. (should
  2432. (eq 'test
  2433. (org-test-with-temp-text "#+CATEGORY: test"
  2434. (org-mode-restart)
  2435. org-category)))
  2436. (should
  2437. (equal "test"
  2438. (org-test-with-temp-text "#+CATEGORY: test"
  2439. (org-mode-restart)
  2440. (cdr (assoc "CATEGORY" org-keyword-properties)))))
  2441. ;; COLUMNS keyword.
  2442. (should
  2443. (equal "%25ITEM %TAGS %PRIORITY %TODO"
  2444. (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
  2445. (org-mode-restart)
  2446. org-columns-default-format)))
  2447. ;; CONSTANTS keyword. Constants names are case sensitive.
  2448. (should
  2449. (equal '("299792458." "3.14")
  2450. (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
  2451. (org-mode-restart)
  2452. (mapcar
  2453. (lambda (n) (cdr (assoc n org-table-formula-constants-local)))
  2454. '("c" "pi")))))
  2455. (should
  2456. (equal "3.14"
  2457. (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
  2458. (org-mode-restart)
  2459. (cdr (assoc "pi" org-table-formula-constants-local)))))
  2460. (should
  2461. (equal "22/7"
  2462. (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
  2463. (org-mode-restart)
  2464. (cdr (assoc "PI" org-table-formula-constants-local)))))
  2465. ;; LINK keyword.
  2466. (should
  2467. (equal
  2468. '("url1" "url2")
  2469. (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
  2470. (org-mode-restart)
  2471. (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local)))
  2472. '("a" "b")))))
  2473. ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
  2474. (should
  2475. (equal
  2476. '(?X ?Z ?Y)
  2477. (org-test-with-temp-text "#+PRIORITIES: X Z Y"
  2478. (org-mode-restart)
  2479. (list org-priority-highest org-priority-lowest org-priority-default))))
  2480. (should
  2481. (equal
  2482. '(?A ?C ?B)
  2483. (org-test-with-temp-text "#+PRIORITIES: X Z"
  2484. (org-mode-restart)
  2485. (list org-priority-highest org-priority-lowest org-priority-default))))
  2486. ;; STARTUP keyword.
  2487. (should
  2488. (equal '(t t)
  2489. (org-test-with-temp-text "#+STARTUP: fold odd"
  2490. (org-mode-restart)
  2491. (list org-startup-folded org-odd-levels-only))))
  2492. ;; TODO keywords.
  2493. (should
  2494. (equal '(("A" "B") ("C"))
  2495. (org-test-with-temp-text "#+TODO: A B | C"
  2496. (org-mode-restart)
  2497. (list org-not-done-keywords org-done-keywords))))
  2498. (should
  2499. (equal '(("A" "C") ("B" "D"))
  2500. (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
  2501. (org-mode-restart)
  2502. (list org-not-done-keywords org-done-keywords))))
  2503. (should
  2504. (equal '(("A" "B") ("C"))
  2505. (org-test-with-temp-text "#+TYP_TODO: A B | C"
  2506. (org-mode-restart)
  2507. (list org-not-done-keywords org-done-keywords))))
  2508. (should
  2509. (equal '((:startgroup) ("A" . ?a) (:endgroup))
  2510. (org-test-with-temp-text "#+TODO: A(a)"
  2511. (org-mode-restart)
  2512. org-todo-key-alist)))
  2513. (should
  2514. (equal '(("D" note nil) ("C" time nil) ("B" note time))
  2515. (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
  2516. (org-mode-restart)
  2517. org-todo-log-states)))
  2518. ;; Enter SETUPFILE keyword.
  2519. (should
  2520. (equal "1"
  2521. (org-test-with-temp-text
  2522. (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
  2523. (org-mode-restart)
  2524. (cdr (assoc "a" org-keyword-properties))))))
  2525. ;;; Links
  2526. ;;;; Coderefs
  2527. (ert-deftest test-org/coderef ()
  2528. "Test coderef links specifications."
  2529. (should
  2530. (org-test-with-temp-text "
  2531. #+BEGIN_SRC emacs-lisp
  2532. \(+ 1 1) (ref:sc)
  2533. #+END_SRC
  2534. \[[(sc)<point>]]"
  2535. (org-open-at-point)
  2536. (looking-at "(ref:sc)")))
  2537. ;; Find coderef even with alternate label format.
  2538. (should
  2539. (org-test-with-temp-text "
  2540. #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
  2541. \(+ 1 1) {ref:sc}
  2542. #+END_SRC
  2543. \[[(sc)<point>]]"
  2544. (org-open-at-point)
  2545. (looking-at "{ref:sc}"))))
  2546. ;;;; Custom ID
  2547. (ert-deftest test-org/custom-id ()
  2548. "Test custom ID links specifications."
  2549. (should
  2550. (org-test-with-temp-text
  2551. "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2552. (org-open-at-point)
  2553. (looking-at-p "\\* H1")))
  2554. ;; Handle escape characters.
  2555. (should
  2556. (org-test-with-temp-text
  2557. "* H1\n:PROPERTIES:\n:CUSTOM_ID: [%]\n:END:\n* H2\n[[#\\[%\\]<point>]]"
  2558. (org-open-at-point)
  2559. (looking-at-p "\\* H1")))
  2560. ;; Throw an error on false positives.
  2561. (should-error
  2562. (org-test-with-temp-text
  2563. "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2564. (org-open-at-point)
  2565. (looking-at-p "\\* H1"))))
  2566. ;;;; Fuzzy Links
  2567. ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
  2568. ;; a named element (#+name: text) and to headlines (* Text).
  2569. (ert-deftest test-org/fuzzy-links ()
  2570. "Test fuzzy links specifications."
  2571. ;; Fuzzy link goes in priority to a matching target.
  2572. (should
  2573. (org-test-with-temp-text
  2574. "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
  2575. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2576. (looking-at "<<Test>>")))
  2577. ;; Then fuzzy link points to an element with a given name.
  2578. (should
  2579. (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
  2580. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2581. (looking-at "#\\+NAME: Test")))
  2582. ;; A target still lead to a matching headline otherwise.
  2583. (should
  2584. (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
  2585. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2586. (looking-at "\\* Head2")))
  2587. ;; With a leading star in link, enforce heading match.
  2588. (should
  2589. (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
  2590. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2591. (looking-at "\\* Test")))
  2592. ;; With a leading star in link, enforce exact heading match, even
  2593. ;; with `org-link-search-must-match-exact-headline' set to nil.
  2594. (should-error
  2595. (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
  2596. (let ((org-link-search-must-match-exact-headline nil))
  2597. (org-open-at-point))))
  2598. ;; Handle non-nil `org-link-search-must-match-exact-headline'.
  2599. (should
  2600. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
  2601. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2602. (looking-at "\\* Test")))
  2603. (should
  2604. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
  2605. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2606. (looking-at "\\* Test")))
  2607. ;; Heading match should not care about spaces, cookies, TODO
  2608. ;; keywords, priorities, and tags. However, TODO keywords are
  2609. ;; case-sensitive.
  2610. (should
  2611. (let ((first-line
  2612. "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
  2613. (org-test-with-temp-text
  2614. (concat first-line "\nFoo Bar\n<point>[[*Test 1 2]]")
  2615. (let ((org-link-search-must-match-exact-headline nil)
  2616. (org-todo-regexp "TODO"))
  2617. (org-open-at-point))
  2618. (looking-at (regexp-quote first-line)))))
  2619. (should-error
  2620. (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
  2621. (let ((org-link-search-must-match-exact-headline nil)
  2622. (org-todo-regexp "TODO"))
  2623. (org-open-at-point))))
  2624. ;; Heading match should still be exact.
  2625. (should-error
  2626. (org-test-with-temp-text "
  2627. ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
  2628. Foo Bar
  2629. <point>[[*Test 1]]"
  2630. (let ((org-link-search-must-match-exact-headline nil)
  2631. (org-todo-regexp "TODO"))
  2632. (org-open-at-point))))
  2633. (should
  2634. (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
  2635. (let ((org-link-search-must-match-exact-headline nil)
  2636. (org-todo-regexp "TODO"))
  2637. (org-open-at-point))
  2638. (looking-at-p (regexp-quote "** Test 1 2"))))
  2639. ;; Heading match ignores COMMENT keyword.
  2640. (should
  2641. (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
  2642. (org-open-at-point)
  2643. (looking-at "\\* COMMENT Test")))
  2644. (should
  2645. (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
  2646. (org-open-at-point)
  2647. (looking-at "\\* TODO COMMENT Test")))
  2648. ;; Correctly un-escape fuzzy links.
  2649. (should
  2650. (org-test-with-temp-text "* [foo]\n[[*\\[foo\\]][With escaped characters]]"
  2651. (org-open-at-point)
  2652. (bobp)))
  2653. ;; Match search strings containing newline characters, including
  2654. ;; blank lines.
  2655. (should
  2656. (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
  2657. (let ((file (buffer-file-name)))
  2658. (goto-char (point-max))
  2659. (insert (format "[[file:%s::line1 line2]]" file))
  2660. (beginning-of-line)
  2661. (let ((org-link-search-must-match-exact-headline nil))
  2662. (org-open-at-point 0))
  2663. (looking-at-p "line1"))))
  2664. (should
  2665. (org-test-with-temp-text-in-file "Paragraph\n\nline1\n\nline2\n\n"
  2666. (let ((file (buffer-file-name)))
  2667. (goto-char (point-max))
  2668. (insert (format "[[file:%s::line1 line2]]" file))
  2669. (beginning-of-line)
  2670. (let ((org-link-search-must-match-exact-headline nil))
  2671. (org-open-at-point 0))
  2672. (looking-at-p "line1")))))
  2673. ;;;; Open at point
  2674. (ert-deftest test-org/open-at-point/keyword ()
  2675. "Does `org-open-at-point' open link in a keyword line?"
  2676. (should
  2677. (org-test-with-temp-text
  2678. "<<top>>\n#+KEYWORD: <point>[[top]]"
  2679. (org-open-at-point) t))
  2680. (should
  2681. (org-test-with-temp-text
  2682. "* H\n<<top>>\n#+KEYWORD: <point>[[top]]"
  2683. (org-open-at-point) t)))
  2684. (ert-deftest test-org/open-at-point/property ()
  2685. "Does `org-open-at-point' open link in property drawer?"
  2686. (should
  2687. (org-test-with-temp-text
  2688. "* Headline
  2689. :PROPERTIES:
  2690. :URL: <point>[[*Headline]]
  2691. :END:"
  2692. (org-open-at-point) t)))
  2693. (ert-deftest test-org/open-at-point/comment ()
  2694. "Does `org-open-at-point' open link in a commented line?"
  2695. (should
  2696. (org-test-with-temp-text
  2697. "<<top>>\n# <point>[[top]]"
  2698. (org-open-at-point) t))
  2699. (should
  2700. (org-test-with-temp-text
  2701. "* H\n<<top>>\n# <point>[[top]]"
  2702. (org-open-at-point) t)))
  2703. (ert-deftest test-org/open-at-point/inline-image ()
  2704. "Test `org-open-at-point' on nested links."
  2705. (should
  2706. (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
  2707. (org-open-at-point)
  2708. (bobp))))
  2709. (ert-deftest test-org/open-at-point/radio-target ()
  2710. "Test `org-open-at-point' on radio targets."
  2711. (should
  2712. (org-test-with-temp-text "<<<target>>> <point>target"
  2713. (org-update-radio-target-regexp)
  2714. (org-open-at-point)
  2715. (eq (org-element-type (org-element-context)) 'radio-target))))
  2716. (ert-deftest test-org/open-at-point/tag ()
  2717. "Test `org-open-at-point' on tags."
  2718. (should
  2719. (org-test-with-temp-text "* H :<point>tag:"
  2720. (catch :result
  2721. (cl-letf (((symbol-function 'org-tags-view)
  2722. (lambda (&rest args) (throw :result t))))
  2723. (org-open-at-point)
  2724. nil))))
  2725. (should-not
  2726. (org-test-with-temp-text-in-file "* H<point> :tag:"
  2727. (catch :result
  2728. (cl-letf (((symbol-function 'org-tags-view)
  2729. (lambda (&rest args) (throw :result t))))
  2730. ;; When point isn't on a tag it's going to try other things,
  2731. ;; possibly trying to open attachments which will return an
  2732. ;; error if there isn't an attachment. Suppress that error.
  2733. (ignore-errors
  2734. (org-open-at-point))
  2735. nil)))))
  2736. ;;; Node Properties
  2737. (ert-deftest test-org/accumulated-properties-in-drawers ()
  2738. "Ensure properties accumulate in subtree drawers."
  2739. (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
  2740. (org-babel-next-src-block)
  2741. (should (equal '(2 1) (org-babel-execute-src-block)))))
  2742. (ert-deftest test-org/custom-properties ()
  2743. "Test custom properties specifications."
  2744. ;; Standard test.
  2745. (should
  2746. (let ((org-custom-properties '("FOO")))
  2747. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2748. (org-toggle-custom-properties-visibility)
  2749. (org-invisible-p2))))
  2750. ;; Properties are case-insensitive.
  2751. (should
  2752. (let ((org-custom-properties '("FOO")))
  2753. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
  2754. (org-toggle-custom-properties-visibility)
  2755. (org-invisible-p2))))
  2756. (should
  2757. (let ((org-custom-properties '("foo")))
  2758. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2759. (org-toggle-custom-properties-visibility)
  2760. (org-invisible-p2))))
  2761. ;; Multiple custom properties in the same drawer.
  2762. (should
  2763. (let ((org-custom-properties '("FOO" "BAR")))
  2764. (org-test-with-temp-text
  2765. "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
  2766. (org-toggle-custom-properties-visibility)
  2767. (and (org-invisible-p2)
  2768. (not (progn (forward-line) (org-invisible-p2)))
  2769. (progn (forward-line) (org-invisible-p2))))))
  2770. ;; Hide custom properties with an empty value.
  2771. (should
  2772. (let ((org-custom-properties '("FOO")))
  2773. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
  2774. (org-toggle-custom-properties-visibility)
  2775. (org-invisible-p2))))
  2776. ;; Do not hide fake properties.
  2777. (should-not
  2778. (let ((org-custom-properties '("FOO")))
  2779. (org-test-with-temp-text ":FOO: val\n"
  2780. (org-toggle-custom-properties-visibility)
  2781. (org-invisible-p2))))
  2782. (should-not
  2783. (let ((org-custom-properties '("A")))
  2784. (org-test-with-temp-text
  2785. "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
  2786. (org-toggle-custom-properties-visibility)
  2787. (org-invisible-p2)))))
  2788. ;;; Mark Region
  2789. (ert-deftest test-org/mark-element ()
  2790. "Test `org-mark-element' specifications."
  2791. ;; Mark beginning and end of element.
  2792. (should
  2793. (equal '(t t)
  2794. (org-test-with-temp-text "Para<point>graph"
  2795. (org-mark-element)
  2796. (list (bobp) (= (mark) (point-max))))))
  2797. (should
  2798. (equal '(t t)
  2799. (org-test-with-temp-text "P1\n\nPara<point>graph\n\nP2"
  2800. (org-mark-element)
  2801. (list (looking-at "Paragraph")
  2802. (org-with-point-at (mark) (looking-at "P2"))))))
  2803. ;; Do not set mark past (point-max).
  2804. (should
  2805. (org-test-with-temp-text "Para<point>graph"
  2806. (narrow-to-region 2 6)
  2807. (org-mark-element)
  2808. (= 6 (mark)))))
  2809. (ert-deftest test-org/mark-subtree ()
  2810. "Test `org-mark-subtree' specifications."
  2811. ;; Error when point is before first headline.
  2812. (should-error
  2813. (org-test-with-temp-text "Paragraph\n* Headline\nBody"
  2814. (progn (transient-mark-mode 1)
  2815. (org-mark-subtree))))
  2816. ;; Without argument, mark current subtree.
  2817. (should
  2818. (equal
  2819. '(12 32)
  2820. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  2821. (progn (transient-mark-mode 1)
  2822. (forward-line 2)
  2823. (org-mark-subtree)
  2824. (list (region-beginning) (region-end))))))
  2825. ;; With an argument, move ARG up.
  2826. (should
  2827. (equal
  2828. '(1 32)
  2829. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  2830. (progn (transient-mark-mode 1)
  2831. (forward-line 2)
  2832. (org-mark-subtree 1)
  2833. (list (region-beginning) (region-end))))))
  2834. ;; Do not get fooled by inlinetasks.
  2835. (when (featurep 'org-inlinetask)
  2836. (should
  2837. (= 1
  2838. (org-test-with-temp-text "* Headline\n*************** Task\nContents"
  2839. (progn (transient-mark-mode 1)
  2840. (forward-line 1)
  2841. (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
  2842. (region-beginning)))))))
  2843. ;;; Miscellaneous
  2844. (ert-deftest test-org/sort-entries ()
  2845. "Test `org-sort-entries'."
  2846. ;; Sort alphabetically.
  2847. (should
  2848. (equal "\n* abc\n* def\n* xyz\n"
  2849. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  2850. (org-sort-entries nil ?a)
  2851. (buffer-string))))
  2852. (should
  2853. (equal "\n* xyz\n* def\n* abc\n"
  2854. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  2855. (org-sort-entries nil ?A)
  2856. (buffer-string))))
  2857. (should
  2858. (equal "\n* \n* klm\n* xyz\n"
  2859. (org-test-with-temp-text "\n* xyz\n* \n* klm\n"
  2860. (org-sort-entries nil ?a)
  2861. (buffer-string))))
  2862. ;; Sort numerically.
  2863. (should
  2864. (equal "\n* 1\n* 2\n* 10\n"
  2865. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  2866. (org-sort-entries nil ?n)
  2867. (buffer-string))))
  2868. (should
  2869. (equal "\n* 10\n* 2\n* 1\n"
  2870. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  2871. (org-sort-entries nil ?N)
  2872. (buffer-string))))
  2873. (should
  2874. (equal "\n* \n* 1\n* 2\n"
  2875. (org-test-with-temp-text "\n* 1\n* \n* 2\n"
  2876. (org-sort-entries nil ?n)
  2877. (buffer-string))))
  2878. ;; Sort by custom function.
  2879. (should
  2880. (equal "\n* b\n* aa\n* ccc\n"
  2881. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  2882. (org-sort-entries nil ?f
  2883. (lambda ()
  2884. (length (buffer-substring (point-at-bol)
  2885. (point-at-eol))))
  2886. #'<)
  2887. (buffer-string))))
  2888. (should
  2889. (equal "\n* ccc\n* aa\n* b\n"
  2890. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  2891. (org-sort-entries nil ?F
  2892. (lambda ()
  2893. (length (buffer-substring (point-at-bol)
  2894. (point-at-eol))))
  2895. #'<)
  2896. (buffer-string))))
  2897. ;; Sort by TODO keyword.
  2898. (should
  2899. (equal "\n* TODO h1\n* TODO h3\n* DONE h2\n"
  2900. (org-test-with-temp-text
  2901. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  2902. (org-sort-entries nil ?o)
  2903. (buffer-string))))
  2904. (should
  2905. (equal "\n* DONE h2\n* TODO h1\n* TODO h3\n"
  2906. (org-test-with-temp-text
  2907. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  2908. (org-sort-entries nil ?O)
  2909. (buffer-string))))
  2910. ;; Sort by priority.
  2911. (should
  2912. (equal "\n* [#A] h2\n* [#B] h3\n* [#C] h1\n"
  2913. (org-test-with-temp-text
  2914. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  2915. (org-sort-entries nil ?p)
  2916. (buffer-string))))
  2917. (should
  2918. (equal "\n* [#C] h1\n* [#B] h3\n* [#A] h2\n"
  2919. (org-test-with-temp-text
  2920. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  2921. (org-sort-entries nil ?P)
  2922. (buffer-string))))
  2923. ;; Sort by creation time.
  2924. (should
  2925. (equal "
  2926. * h3
  2927. [2017-05-08 Mon]
  2928. * h2
  2929. [2017-05-09 Tue]
  2930. * h1
  2931. [2018-05-09 Wed]
  2932. "
  2933. (org-test-with-temp-text
  2934. "
  2935. * h1
  2936. [2018-05-09 Wed]
  2937. * h2
  2938. [2017-05-09 Tue]
  2939. * h3
  2940. [2017-05-08 Mon]
  2941. "
  2942. (org-sort-entries nil ?c)
  2943. (buffer-string))))
  2944. ;; Sort by scheduled date.
  2945. (should
  2946. (equal "
  2947. * TODO h4
  2948. SCHEDULED: <2017-05-06 Sat>
  2949. * TODO h3
  2950. SCHEDULED: <2017-05-08 Mon>
  2951. * TODO h2
  2952. DEADLINE: <2017-05-09 Tue>
  2953. * TODO h1
  2954. DEADLINE: <2017-05-07 Sun>
  2955. "
  2956. (org-test-with-temp-text
  2957. "
  2958. * TODO h2
  2959. DEADLINE: <2017-05-09 Tue>
  2960. * TODO h1
  2961. DEADLINE: <2017-05-07 Sun>
  2962. * TODO h3
  2963. SCHEDULED: <2017-05-08 Mon>
  2964. * TODO h4
  2965. SCHEDULED: <2017-05-06 Sat>
  2966. "
  2967. (org-sort-entries nil ?s)
  2968. (buffer-string))))
  2969. ;; Sort by deadline date.
  2970. (should
  2971. (equal "
  2972. * TODO h1
  2973. DEADLINE: <2017-05-07 Sun>
  2974. * TODO h2
  2975. DEADLINE: <2017-05-09 Tue>
  2976. * TODO h3
  2977. SCHEDULED: <2017-05-08 Mon>
  2978. * TODO h4
  2979. SCHEDULED: <2017-05-06 Sat>
  2980. "
  2981. (org-test-with-temp-text
  2982. "
  2983. * TODO h2
  2984. DEADLINE: <2017-05-09 Tue>
  2985. * TODO h1
  2986. DEADLINE: <2017-05-07 Sun>
  2987. * TODO h3
  2988. SCHEDULED: <2017-05-08 Mon>
  2989. * TODO h4
  2990. SCHEDULED: <2017-05-06 Sat>
  2991. "
  2992. (org-sort-entries nil ?d)
  2993. (buffer-string))))
  2994. ;; Sort by any date/time
  2995. (should
  2996. (equal "
  2997. * TODO h4
  2998. SCHEDULED: <2017-05-06 Sat>
  2999. * TODO h1
  3000. DEADLINE: <2017-05-07 Sun>
  3001. * TODO h3
  3002. SCHEDULED: <2017-05-08 Mon>
  3003. * TODO h2
  3004. DEADLINE: <2017-05-09 Tue>
  3005. "
  3006. (org-test-with-temp-text
  3007. "
  3008. * TODO h2
  3009. DEADLINE: <2017-05-09 Tue>
  3010. * TODO h1
  3011. DEADLINE: <2017-05-07 Sun>
  3012. * TODO h3
  3013. SCHEDULED: <2017-05-08 Mon>
  3014. * TODO h4
  3015. SCHEDULED: <2017-05-06 Sat>
  3016. "
  3017. (org-sort-entries nil ?t)
  3018. (buffer-string))))
  3019. ;; Sort by clocking time.
  3020. (should
  3021. (equal "
  3022. * clocked h2
  3023. :LOGBOOK:
  3024. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3025. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  3026. :END:
  3027. * clocked h1
  3028. :LOGBOOK:
  3029. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3030. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  3031. :END:
  3032. "
  3033. (org-test-with-temp-text
  3034. "
  3035. * clocked h1
  3036. :LOGBOOK:
  3037. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3038. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  3039. :END:
  3040. * clocked h2
  3041. :LOGBOOK:
  3042. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3043. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  3044. :END:
  3045. "
  3046. (org-sort-entries nil ?k)
  3047. (buffer-string))))
  3048. ;; Preserve file local variables when sorting.
  3049. (should
  3050. (equal "\n* A\n* B\n# Local Variables:\n# foo: t\n# End:\n"
  3051. (org-test-with-temp-text
  3052. "\n* B\n* A\n# Local Variables:\n# foo: t\n# End:"
  3053. (org-sort-entries nil ?a)
  3054. (buffer-string)))))
  3055. (ert-deftest test-org/string-collate-greaterp ()
  3056. "Test `org-string-collate-greaterp' specifications."
  3057. (should (org-string-collate-greaterp "def" "abc"))
  3058. (should-not (org-string-collate-greaterp "abc" "def")))
  3059. (ert-deftest test-org/file-contents ()
  3060. "Test `org-file-contents' specifications."
  3061. ;; Open files.
  3062. (should
  3063. (string= "#+BIND: variable value
  3064. #+DESCRIPTION: l2
  3065. #+LANGUAGE: en
  3066. #+SELECT_TAGS: b
  3067. #+TITLE: b
  3068. #+PROPERTY: a 1
  3069. " (org-file-contents (expand-file-name "setupfile3.org"
  3070. (concat org-test-dir "examples/")))))
  3071. ;; Throw error when trying to access an invalid file.
  3072. (should-error (org-file-contents "this-file-must-not-exist"))
  3073. ;; Try to access an invalid file, but do not throw an error.
  3074. (should
  3075. (progn (org-file-contents "this-file-must-not-exist" :noerror) t))
  3076. ;; Open URL.
  3077. (should
  3078. (string= "foo"
  3079. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3080. (unwind-protect
  3081. ;; Simulate successful retrieval of a URL.
  3082. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3083. (lambda (&rest_)
  3084. (with-current-buffer buffer
  3085. (insert "HTTP/1.1 200 OK\n\nfoo"))
  3086. buffer)))
  3087. (org-file-contents "http://some-valid-url"))
  3088. (kill-buffer buffer)))))
  3089. ;; Throw error when trying to access an invalid URL.
  3090. (should-error
  3091. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3092. (unwind-protect
  3093. ;; Simulate unsuccessful retrieval of a URL.
  3094. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3095. (lambda (&rest_)
  3096. (with-current-buffer buffer
  3097. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3098. buffer)))
  3099. (org-file-contents "http://this-url-must-not-exist"))
  3100. (kill-buffer buffer))))
  3101. ;; Try to access an invalid URL, but do not throw an error.
  3102. (should-error
  3103. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3104. (unwind-protect
  3105. ;; Simulate unsuccessful retrieval of a URL.
  3106. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3107. (lambda (&rest_)
  3108. (with-current-buffer buffer
  3109. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3110. buffer)))
  3111. (org-file-contents "http://this-url-must-not-exist"))
  3112. (kill-buffer buffer))))
  3113. (should
  3114. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3115. (unwind-protect
  3116. ;; Simulate unsuccessful retrieval of a URL.
  3117. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3118. (lambda (&rest_)
  3119. (with-current-buffer buffer
  3120. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3121. buffer)))
  3122. (org-file-contents "http://this-url-must-not-exist" :noerror))
  3123. (kill-buffer buffer))
  3124. t)))
  3125. ;;; Navigation
  3126. (ert-deftest test-org/next-visible-heading ()
  3127. "Test `org-next-visible-heading' specifications."
  3128. ;; Move to the beginning of the next headline, taking into
  3129. ;; consideration ARG.
  3130. (should
  3131. (org-test-with-temp-text "* H1\n* H2"
  3132. (org-next-visible-heading 1)
  3133. (looking-at "\\* H2")))
  3134. (should
  3135. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3136. (org-next-visible-heading 2)
  3137. (looking-at "\\* H3")))
  3138. ;; Ignore invisible headlines.
  3139. (should
  3140. (org-test-with-temp-text "* H1\n** H2\n* H3"
  3141. (org-cycle)
  3142. (org-next-visible-heading 1)
  3143. (looking-at "\\* H3")))
  3144. ;; Move point between headlines, not on blank lines between.
  3145. (should
  3146. (org-test-with-temp-text "* H1\n** H2\n\n\n\n* H3"
  3147. (let ((org-cycle-separator-lines 1))
  3148. (org-cycle)
  3149. (org-next-visible-heading 1))
  3150. (looking-at "\\* H3")))
  3151. ;; Move at end of buffer when there is no more headline.
  3152. (should
  3153. (org-test-with-temp-text "* H1"
  3154. (org-next-visible-heading 1)
  3155. (eobp)))
  3156. (should
  3157. (org-test-with-temp-text "* H1\n* H2"
  3158. (org-next-visible-heading 2)
  3159. (eobp)))
  3160. ;; With a negative argument, move backwards.
  3161. (should
  3162. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3163. (org-next-visible-heading -1)
  3164. (looking-at "\\* H2")))
  3165. (should
  3166. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3167. (org-next-visible-heading -2)
  3168. (looking-at "\\* H1"))))
  3169. (ert-deftest test-org/previous-visible-heading ()
  3170. "Test `org-previous-visible-heading' specifications."
  3171. ;; Move to the beginning of the next headline, taking into
  3172. ;; consideration ARG.
  3173. (should
  3174. (org-test-with-temp-text "* H1\n<point>* H2"
  3175. (org-previous-visible-heading 1)
  3176. (looking-at "\\* H1")))
  3177. (should
  3178. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3179. (org-previous-visible-heading 2)
  3180. (looking-at "\\* H1")))
  3181. ;; Ignore invisible headlines.
  3182. (should
  3183. (org-test-with-temp-text "* H1\n** H2\n<point>* H3"
  3184. (org-overview)
  3185. (org-previous-visible-heading 1)
  3186. (looking-at "\\* H1")))
  3187. ;; Move point between headlines, not on blank lines between.
  3188. (should
  3189. (org-test-with-temp-text "* H1\n\n\n\n** H2\n<point>* H3"
  3190. (let ((org-cycle-separator-lines 1))
  3191. (org-overview)
  3192. (org-previous-visible-heading 1))
  3193. (looking-at "\\* H1")))
  3194. ;; Move at end of buffer when there is no more headline.
  3195. (should
  3196. (org-test-with-temp-text "* H1"
  3197. (org-previous-visible-heading 1)
  3198. (bobp)))
  3199. (should
  3200. (org-test-with-temp-text "* H1\n* <point>H2"
  3201. (org-previous-visible-heading 2)
  3202. (bobp)))
  3203. ;; Invisible parts may not start at a headline, i.e., when revealing
  3204. ;; parts of the buffer. Handle this.
  3205. (should
  3206. (org-test-with-temp-text "* Main\n** H1\nFoo\n** H2\nBar\n** H3\nBaz"
  3207. (org-overview)
  3208. (search-forward "H1")
  3209. (org-show-context 'minimal)
  3210. (org-cycle)
  3211. (search-forward "H3")
  3212. (org-show-context 'minimal)
  3213. ;; At this point, buffer displays, with point at "|",
  3214. ;;
  3215. ;; * Main
  3216. ;; ** H1
  3217. ;; Foo
  3218. ;; ** H3|
  3219. (org-previous-visible-heading 1)
  3220. (looking-at "\\*+ H1"))))
  3221. (ert-deftest test-org/forward-heading-same-level ()
  3222. "Test `org-forward-heading-same-level' specifications."
  3223. ;; Test navigation at top level, forward and backward.
  3224. (should
  3225. (equal "* H2"
  3226. (org-test-with-temp-text "* H1\n* H2"
  3227. (org-forward-heading-same-level 1)
  3228. (buffer-substring-no-properties (point) (line-end-position)))))
  3229. (should
  3230. (equal "* H1"
  3231. (org-test-with-temp-text "* H1\n<point>* H2"
  3232. (org-forward-heading-same-level -1)
  3233. (buffer-substring-no-properties (point) (line-end-position)))))
  3234. ;; Test navigation in a sub-tree, forward and backward.
  3235. (should
  3236. (equal "* H2"
  3237. (org-test-with-temp-text "* H1\n** H11\n** H12\n* H2"
  3238. (org-forward-heading-same-level 1)
  3239. (buffer-substring-no-properties (point) (line-end-position)))))
  3240. (should
  3241. (equal "* H1"
  3242. (org-test-with-temp-text "* H1\n** H11\n** H12\n<point>* H2"
  3243. (org-forward-heading-same-level -1)
  3244. (buffer-substring-no-properties (point) (line-end-position)))))
  3245. ;; Stop at first or last sub-heading.
  3246. (should-not
  3247. (equal "* H2"
  3248. (org-test-with-temp-text "* H1\n** H11\n<point>** H12\n* H2"
  3249. (org-forward-heading-same-level 1)
  3250. (buffer-substring-no-properties (point) (line-end-position)))))
  3251. (should-not
  3252. (equal "* H2"
  3253. (org-test-with-temp-text "* H1\n<point>** H11\n** H12\n* H2"
  3254. (org-forward-heading-same-level -1)
  3255. (buffer-substring-no-properties (point) (line-end-position)))))
  3256. ;; Allow multiple moves.
  3257. (should
  3258. (equal "* H3"
  3259. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3260. (org-forward-heading-same-level 2)
  3261. (buffer-substring-no-properties (point) (line-end-position)))))
  3262. (should
  3263. (equal "* H1"
  3264. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3265. (org-forward-heading-same-level -2)
  3266. (buffer-substring-no-properties (point) (line-end-position)))))
  3267. ;; Ignore spurious moves when first (or last) sibling is reached.
  3268. (should
  3269. (equal "** H3"
  3270. (org-test-with-temp-text "* First\n<point>** H1\n** H2\n** H3\n* Last"
  3271. (org-forward-heading-same-level 100)
  3272. (buffer-substring-no-properties (point) (line-end-position)))))
  3273. (should
  3274. (equal "** H1"
  3275. (org-test-with-temp-text "* First\n** H1\n** H2\n<point>** H3\n* Last"
  3276. (org-forward-heading-same-level -100)
  3277. (buffer-substring-no-properties (point) (line-end-position))))))
  3278. (ert-deftest test-org/end-of-meta-data ()
  3279. "Test `org-end-of-meta-data' specifications."
  3280. ;; Skip planning line.
  3281. (should
  3282. (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
  3283. (org-end-of-meta-data)
  3284. (eobp)))
  3285. ;; Skip properties drawer.
  3286. (should
  3287. (org-test-with-temp-text
  3288. "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
  3289. (org-end-of-meta-data)
  3290. (eobp)))
  3291. ;; Skip both.
  3292. (should
  3293. (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
  3294. (org-end-of-meta-data)
  3295. (eobp)))
  3296. ;; Nothing to skip, go to first line.
  3297. (should
  3298. (org-test-with-temp-text "* Headline\nContents"
  3299. (org-end-of-meta-data)
  3300. (looking-at "Contents")))
  3301. ;; With option argument, skip empty lines, regular drawers and
  3302. ;; clocking lines.
  3303. (should
  3304. (org-test-with-temp-text "* Headline\n\nContents"
  3305. (org-end-of-meta-data t)
  3306. (looking-at "Contents")))
  3307. (should
  3308. (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
  3309. (org-end-of-meta-data t)
  3310. (looking-at "Contents")))
  3311. (should
  3312. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
  3313. (org-end-of-meta-data t)
  3314. (looking-at "Contents")))
  3315. ;; Special case: do not skip incomplete drawers.
  3316. (should
  3317. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
  3318. (org-end-of-meta-data t)
  3319. (looking-at ":LOGBOOK:")))
  3320. ;; Special case: Be careful about consecutive headlines.
  3321. (should-not
  3322. (org-test-with-temp-text "* H1\n*H2\nContents"
  3323. (org-end-of-meta-data t)
  3324. (looking-at "Contents"))))
  3325. (ert-deftest test-org/shiftright-heading ()
  3326. "Test `org-shiftright' on headings."
  3327. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  3328. (should
  3329. (equal "* TODO a1\n** a2\n* DONE b1\n"
  3330. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3331. (org-shiftright)
  3332. (buffer-string))))
  3333. (should
  3334. (equal "* TODO a1\n** TODO a2\n* b1\n"
  3335. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3336. (let ((org-loop-over-headlines-in-active-region t))
  3337. (transient-mark-mode 1)
  3338. (push-mark (point) t t)
  3339. (search-forward "* DONE b1")
  3340. (org-shiftright))
  3341. (buffer-string))))
  3342. (should
  3343. (equal "* TODO a1\n** a2\n* b1\n"
  3344. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3345. (let ((org-loop-over-headlines-in-active-region 'start-level))
  3346. (transient-mark-mode 1)
  3347. (push-mark (point) t t)
  3348. (search-forward "* DONE b1")
  3349. (org-shiftright))
  3350. (buffer-string))))))
  3351. (ert-deftest test-org/beginning-of-line ()
  3352. "Test `org-beginning-of-line' specifications."
  3353. ;; Move to beginning of line. If current line in invisible, move to
  3354. ;; beginning of visible line instead.
  3355. (should
  3356. (org-test-with-temp-text "Some text\nSome other text<point>"
  3357. (org-beginning-of-line)
  3358. (bolp)))
  3359. (should
  3360. (org-test-with-temp-text "* H1\n** H2<point>"
  3361. (org-overview)
  3362. (org-beginning-of-line)
  3363. (= (line-beginning-position) 1)))
  3364. ;; With `visual-line-mode' active, move to beginning of visual line.
  3365. (should-not
  3366. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3367. (visual-line-mode)
  3368. (dotimes (i 1000) (insert "very "))
  3369. (org-beginning-of-line)
  3370. (bolp)))
  3371. ;; In a wide headline, with `visual-line-mode', prefer going to the
  3372. ;; beginning of a visual line than to the logical beginning of line,
  3373. ;; even if special movement is active.
  3374. (should-not
  3375. (org-test-with-temp-text "* A <point>long headline"
  3376. (visual-line-mode)
  3377. (dotimes (i 1000) (insert "very "))
  3378. (goto-char (point-max))
  3379. (org-beginning-of-line)
  3380. (bobp)))
  3381. (should-not
  3382. (org-test-with-temp-text "* A <point>long headline"
  3383. (visual-line-mode)
  3384. (dotimes (i 1000) (insert "very "))
  3385. (goto-char (point-max))
  3386. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line))
  3387. (bobp)))
  3388. ;; At an headline with special movement, first move at beginning of
  3389. ;; title, then at the beginning of line, rinse, repeat.
  3390. (should
  3391. (org-test-with-temp-text "* TODO Headline<point>"
  3392. (let ((org-special-ctrl-a/e t))
  3393. (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
  3394. (progn (org-beginning-of-line) (bolp))
  3395. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3396. (should
  3397. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3398. (let ((org-special-ctrl-a/e t))
  3399. (org-beginning-of-line)
  3400. (looking-at "Headline"))))
  3401. (should
  3402. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3403. (let ((org-special-ctrl-a/e '(t . nil)))
  3404. (org-beginning-of-line)
  3405. (looking-at "Headline"))))
  3406. (should-not
  3407. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3408. (let ((org-special-ctrl-a/e '(nil . nil)))
  3409. (org-beginning-of-line)
  3410. (looking-at "Headline"))))
  3411. ;; At an headline with reversed movement, first move to beginning of
  3412. ;; line, then to the beginning of title.
  3413. (should
  3414. (org-test-with-temp-text "* TODO Headline<point>"
  3415. (let ((org-special-ctrl-a/e 'reversed)
  3416. (this-command last-command))
  3417. (and (progn (org-beginning-of-line) (bolp))
  3418. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3419. (should
  3420. (org-test-with-temp-text "* TODO Headline<point>"
  3421. (let ((org-special-ctrl-a/e '(reversed . nil))
  3422. (this-command last-command))
  3423. (and (progn (org-beginning-of-line) (bolp))
  3424. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3425. (should-not
  3426. (org-test-with-temp-text "* TODO Headline<point>"
  3427. (let ((org-special-ctrl-a/e '(t . nil))
  3428. (this-command last-command))
  3429. (and (progn (org-beginning-of-line) (bolp))
  3430. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3431. ;; At an item with special movement, first move after to beginning
  3432. ;; of title, then to the beginning of line, rinse, repeat.
  3433. (should
  3434. (org-test-with-temp-text "- [ ] Item<point>"
  3435. (let ((org-special-ctrl-a/e t))
  3436. (and (progn (org-beginning-of-line) (looking-at-p "Item"))
  3437. (progn (org-beginning-of-line) (bolp))
  3438. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3439. ;; At an item with reversed movement, first move to beginning of
  3440. ;; line, then to the beginning of title.
  3441. (should
  3442. (org-test-with-temp-text "- [X] Item<point>"
  3443. (let ((org-special-ctrl-a/e 'reversed)
  3444. (this-command last-command))
  3445. (and (progn (org-beginning-of-line) (bolp))
  3446. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3447. ;; Leave point before invisible characters at column 0.
  3448. (should
  3449. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3450. (let ((org-special-ctrl-a/e nil))
  3451. (org-beginning-of-line)
  3452. (bolp))))
  3453. (should
  3454. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3455. (let ((org-special-ctrl-a/e t))
  3456. (org-beginning-of-line)
  3457. (bolp))))
  3458. (should
  3459. (org-test-with-temp-text "[[http<point>://orgmode.org]]"
  3460. (visual-line-mode)
  3461. (org-beginning-of-line)
  3462. (bolp)))
  3463. ;; Special case: Do not error when the buffer contains only a single
  3464. ;; asterisk.
  3465. (should
  3466. (org-test-with-temp-text "*<point>"
  3467. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line) t)))
  3468. (should
  3469. (org-test-with-temp-text "*<point>"
  3470. (let ((org-special-ctrl-a/e nil)) (org-beginning-of-line) t))))
  3471. (ert-deftest test-org/end-of-line ()
  3472. "Test `org-end-of-line' specifications."
  3473. ;; Standard test.
  3474. (should
  3475. (org-test-with-temp-text "Some text\nSome other text"
  3476. (org-end-of-line)
  3477. (eolp)))
  3478. ;; With `visual-line-mode' active, move to end of visible line.
  3479. ;; However, never go past ellipsis.
  3480. (should-not
  3481. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3482. (visual-line-mode)
  3483. (dotimes (i 1000) (insert "very "))
  3484. (goto-char (point-min))
  3485. (org-end-of-line)
  3486. (eolp)))
  3487. (should-not
  3488. (org-test-with-temp-text "* A short headline\nSome contents"
  3489. (visual-line-mode)
  3490. (org-overview)
  3491. (org-end-of-line)
  3492. (eobp)))
  3493. ;; In a wide headline, with `visual-line-mode', prefer going to end
  3494. ;; of visible line if tags, or end of line, are farther.
  3495. (should-not
  3496. (org-test-with-temp-text "* A <point>long headline"
  3497. (visual-line-mode)
  3498. (dotimes (i 1000) (insert "very "))
  3499. (goto-char (point-min))
  3500. (org-end-of-line)
  3501. (eolp)))
  3502. (should-not
  3503. (org-test-with-temp-text "* A <point>long headline :tag:"
  3504. (visual-line-mode)
  3505. (dotimes (i 1000) (insert "very "))
  3506. (goto-char (point-min))
  3507. (org-end-of-line)
  3508. (eolp)))
  3509. ;; At an headline without special movement, go to end of line.
  3510. ;; However, never go past ellipsis.
  3511. (should
  3512. (org-test-with-temp-text "* Headline2b :tag:\n"
  3513. (let ((org-special-ctrl-a/e nil))
  3514. (and (progn (org-end-of-line) (eolp))
  3515. (progn (org-end-of-line) (eolp))))))
  3516. (should
  3517. (org-test-with-temp-text "* Headline2b :tag:\n"
  3518. (let ((org-special-ctrl-a/e '(t . nil)))
  3519. (and (progn (org-end-of-line) (eolp))
  3520. (progn (org-end-of-line) (eolp))))))
  3521. (should
  3522. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3523. (org-overview)
  3524. (let ((org-special-ctrl-a/e nil))
  3525. (org-end-of-line)
  3526. (= 1 (line-beginning-position)))))
  3527. ;; At an headline with special movement, first move before tags,
  3528. ;; then at the end of line, rinse, repeat. However, never go past
  3529. ;; ellipsis.
  3530. (should
  3531. (org-test-with-temp-text "* Headline1 :tag:\n"
  3532. (let ((org-special-ctrl-a/e t))
  3533. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3534. (progn (org-end-of-line) (eolp))
  3535. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3536. (should
  3537. (org-test-with-temp-text "* Headline1 :tag:\n"
  3538. (let ((org-special-ctrl-a/e '(nil . t)))
  3539. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3540. (progn (org-end-of-line) (eolp))
  3541. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3542. (should-not
  3543. (org-test-with-temp-text "* Headline1 :tag:\n"
  3544. (let ((org-special-ctrl-a/e '(nil . nil)))
  3545. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3546. (progn (org-end-of-line) (eolp))
  3547. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3548. (should
  3549. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3550. (org-overview)
  3551. (let ((org-special-ctrl-a/e t))
  3552. (org-end-of-line)
  3553. (org-end-of-line)
  3554. (= 1 (line-beginning-position)))))
  3555. ;; At an headline, with reversed movement, first go to end of line,
  3556. ;; then before tags. However, never go past ellipsis.
  3557. (should
  3558. (org-test-with-temp-text "* Headline3 :tag:\n"
  3559. (let ((org-special-ctrl-a/e 'reversed)
  3560. (this-command last-command))
  3561. (and (progn (org-end-of-line) (eolp))
  3562. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3563. (should
  3564. (org-test-with-temp-text "* Headline3 :tag:\n"
  3565. (let ((org-special-ctrl-a/e '(nil . reversed))
  3566. (this-command last-command))
  3567. (and (progn (org-end-of-line) (eolp))
  3568. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3569. (should-not
  3570. (org-test-with-temp-text "* Headline3 :tag:\n"
  3571. (let ((org-special-ctrl-a/e '(nil . t))
  3572. (this-command last-command))
  3573. (and (progn (org-end-of-line) (eolp))
  3574. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3575. (should
  3576. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3577. (org-overview)
  3578. (let ((org-special-ctrl-a/e 'reversed))
  3579. (org-end-of-line)
  3580. (= 1 (line-beginning-position)))))
  3581. ;; At a block without hidden contents.
  3582. (should
  3583. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3584. (progn (org-end-of-line) (eolp))))
  3585. ;; At a block with hidden contents.
  3586. (should-not
  3587. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3588. (let ((org-special-ctrl-a/e t))
  3589. (org-hide-block-toggle)
  3590. (org-end-of-line)
  3591. (eobp))))
  3592. ;; Get past invisible characters at the end of line.
  3593. (should
  3594. (org-test-with-temp-text "[[https://orgmode.org]]"
  3595. (org-end-of-line)
  3596. (eolp))))
  3597. (ert-deftest test-org/open-line ()
  3598. "Test `org-open-line' specifications."
  3599. ;; Call `open-line' outside of tables.
  3600. (should
  3601. (equal "\nText"
  3602. (org-test-with-temp-text "Text"
  3603. (org-open-line 1)
  3604. (buffer-string))))
  3605. ;; At a table, create a row above.
  3606. (should
  3607. (equal "\n| |\n| a |"
  3608. (org-test-with-temp-text "\n<point>| a |"
  3609. (org-open-line 1)
  3610. (buffer-string))))
  3611. ;; At the very first character of the buffer, also call `open-line'.
  3612. (should
  3613. (equal "\n| a |"
  3614. (org-test-with-temp-text "| a |"
  3615. (org-open-line 1)
  3616. (buffer-string))))
  3617. ;; Narrowing does not count.
  3618. (should
  3619. (equal "Text\n| |\n| a |"
  3620. (org-test-with-temp-text "Text\n<point>| a |"
  3621. (narrow-to-region (point) (point-max))
  3622. (org-open-line 1)
  3623. (widen)
  3624. (buffer-string)))))
  3625. (ert-deftest test-org/forward-sentence ()
  3626. "Test `org-forward-sentence' specifications."
  3627. ;; At the end of a table cell, move to the end of the next one.
  3628. (should
  3629. (org-test-with-temp-text "| a<point> | b |"
  3630. (org-forward-sentence)
  3631. (looking-at " |$")))
  3632. ;; Elsewhere in a cell, move to its end.
  3633. (should
  3634. (org-test-with-temp-text "| a<point>c | b |"
  3635. (org-forward-sentence)
  3636. (looking-at " | b |$")))
  3637. ;; Otherwise, simply call `forward-sentence'.
  3638. (should
  3639. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3640. (org-forward-sentence)
  3641. (looking-at " Sentence 2.")))
  3642. (should
  3643. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3644. (org-forward-sentence)
  3645. (org-forward-sentence)
  3646. (eobp)))
  3647. ;; At the end of an element, jump to the next one, without stopping
  3648. ;; on blank lines in-between.
  3649. (should
  3650. (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
  3651. (org-forward-sentence)
  3652. (eobp)))
  3653. ;; Headlines are considered to be sentences by themselves, even if
  3654. ;; they do not end with a full stop.
  3655. (should
  3656. (equal
  3657. "* Headline"
  3658. (org-test-with-temp-text "* <point>Headline\nSentence."
  3659. (org-forward-sentence)
  3660. (buffer-substring-no-properties (line-beginning-position) (point)))))
  3661. (should
  3662. (org-test-with-temp-text "* Headline<point>\nSentence."
  3663. (org-forward-sentence)
  3664. (eobp)))
  3665. (should
  3666. (org-test-with-temp-text "Sentence.<point>\n\n* Headline\n\nSentence 2."
  3667. (org-forward-sentence)
  3668. (and (org-at-heading-p) (eolp)))))
  3669. (ert-deftest test-org/backward-sentence ()
  3670. "Test `org-backward-sentence' specifications."
  3671. ;; At the beginning of a table cell, move to the beginning of the
  3672. ;; previous one.
  3673. (should
  3674. (org-test-with-temp-text "| a | <point>b |"
  3675. (org-backward-sentence)
  3676. (looking-at "a | b |$")))
  3677. ;; Elsewhere in a cell, move to its beginning.
  3678. (should
  3679. (org-test-with-temp-text "| a | b<point>c |"
  3680. (org-backward-sentence)
  3681. (looking-at "bc |$")))
  3682. ;; Otherwise, simply call `backward-sentence'.
  3683. (should
  3684. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3685. (org-backward-sentence)
  3686. (looking-at "Sentence 2.")))
  3687. (should
  3688. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3689. (org-backward-sentence)
  3690. (org-backward-sentence)
  3691. (bobp)))
  3692. ;; Make sure to hit the beginning of a sentence on the same line as
  3693. ;; an item.
  3694. (should
  3695. (org-test-with-temp-text "- Line 1\n line <point>2."
  3696. (org-backward-sentence)
  3697. (looking-at "Line 1"))))
  3698. (ert-deftest test-org/forward-paragraph ()
  3699. "Test `org-forward-paragraph' specifications."
  3700. ;; At end of buffer, do not return an error.
  3701. (should
  3702. (org-test-with-temp-text "Paragraph"
  3703. (goto-char (point-max))
  3704. (org-forward-paragraph)
  3705. t))
  3706. ;; Standard test.
  3707. (should
  3708. (= 2
  3709. (org-test-with-temp-text "P1\n\nP2"
  3710. (org-forward-paragraph)
  3711. (org-current-line))))
  3712. (should
  3713. (= 2
  3714. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  3715. (org-forward-paragraph)
  3716. (org-current-line))))
  3717. ;; Enter greater elements.
  3718. (should
  3719. (= 2
  3720. (org-test-with-temp-text "#+begin_center\nP1\n#+end_center\nP2"
  3721. (org-forward-paragraph)
  3722. (org-current-line))))
  3723. ;; Do not enter elements with invisible contents.
  3724. (should
  3725. (= 4
  3726. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  3727. (org-cycle)
  3728. (org-forward-paragraph)
  3729. (org-current-line))))
  3730. (should
  3731. (= 6
  3732. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\nP3"
  3733. (org-hide-block-toggle)
  3734. (org-forward-paragraph)
  3735. (org-current-line))))
  3736. ;; On an item or a footnote definition, move past the first element
  3737. ;; inside, if any.
  3738. (should
  3739. (= 2
  3740. (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
  3741. (org-forward-paragraph)
  3742. (org-current-line))))
  3743. (should
  3744. (= 2
  3745. (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
  3746. (org-forward-paragraph)
  3747. (org-current-line))))
  3748. ;; On a table (resp. a property drawer) do not move through table
  3749. ;; rows (resp. node properties).
  3750. (should
  3751. (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
  3752. (org-forward-paragraph)
  3753. (looking-at "Paragraph")))
  3754. (should
  3755. (org-test-with-temp-text
  3756. "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
  3757. (org-forward-paragraph)
  3758. (looking-at "Paragraph")))
  3759. ;; Skip consecutive keywords, clocks and diary S-exps.
  3760. (should
  3761. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n"
  3762. (org-forward-paragraph)
  3763. (eobp)))
  3764. (should
  3765. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n"
  3766. (org-forward-paragraph)
  3767. (eobp)))
  3768. (should
  3769. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n"
  3770. (org-forward-paragraph)
  3771. (eobp)))
  3772. (should-not
  3773. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n"
  3774. (org-forward-paragraph)
  3775. (eobp)))
  3776. (should-not
  3777. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n"
  3778. (org-forward-paragraph)
  3779. (eobp)))
  3780. ;; In a plain list with one item every line, skip the whole list,
  3781. ;; even with point in the middle of the list.
  3782. (should
  3783. (org-test-with-temp-text "- A\n - B\n- C\n"
  3784. (org-forward-paragraph)
  3785. (eobp)))
  3786. (should
  3787. (org-test-with-temp-text "- A\n - <point>B\n- C\n"
  3788. (org-forward-paragraph)
  3789. (eobp)))
  3790. ;; On a comment, verse or source block, stop at "contents"
  3791. ;; boundaries and blank lines.
  3792. (should
  3793. (= 2
  3794. (org-test-with-temp-text "#+begin_src emacs-lisp\nL1\n\nL2\n#+end_src"
  3795. (org-forward-paragraph)
  3796. (org-current-line))))
  3797. (should
  3798. (= 3
  3799. (org-test-with-temp-text "#+begin_verse\n<point>L1\n\nL2\n#+end_verse"
  3800. (org-forward-paragraph)
  3801. (org-current-line))))
  3802. (should
  3803. (= 5
  3804. (org-test-with-temp-text "#+begin_comment\nL1\n\n<point>L2\n#+end_comment"
  3805. (org-forward-paragraph)
  3806. (org-current-line))))
  3807. ;; Being on an affiliated keyword shouldn't make any difference.
  3808. (should
  3809. (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
  3810. (org-forward-paragraph)
  3811. (eobp))))
  3812. (ert-deftest test-org/backward-paragraph ()
  3813. "Test `org-backward-paragraph' specifications."
  3814. ;; Do not error at beginning of buffer.
  3815. (should
  3816. (org-test-with-temp-text "Paragraph"
  3817. (org-backward-paragraph)
  3818. t))
  3819. ;; At blank lines at the very beginning of a buffer, move to
  3820. ;; point-min.
  3821. (should
  3822. (org-test-with-temp-text "\n\n<point>\n\nParagraph"
  3823. (org-backward-paragraph)
  3824. (bobp)))
  3825. ;; Regular test.
  3826. (should
  3827. (= 2
  3828. (org-test-with-temp-text "P1\n\nP2<point>"
  3829. (org-backward-paragraph)
  3830. (org-current-line))))
  3831. (should
  3832. (= 4
  3833. (org-test-with-temp-text "P1\n\nP2\n\nP3<point>"
  3834. (org-backward-paragraph)
  3835. (org-current-line))))
  3836. ;; Try to move on the line above current element.
  3837. (should
  3838. (= 2
  3839. (org-test-with-temp-text "\n\n<point>Paragraph"
  3840. (org-backward-paragraph)
  3841. (org-current-line))))
  3842. ;; Do not leave point in an invisible area.
  3843. (should
  3844. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  3845. (org-cycle)
  3846. (goto-char (point-max))
  3847. (beginning-of-line)
  3848. (org-backward-paragraph)
  3849. (bobp)))
  3850. (should
  3851. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\n"
  3852. (org-hide-block-toggle)
  3853. (goto-char (point-max))
  3854. (org-backward-paragraph)
  3855. (bobp)))
  3856. ;; On the first element in an item or a footnote definition, jump
  3857. ;; before the footnote or the item.
  3858. (should
  3859. (org-test-with-temp-text "- line1<point>"
  3860. (org-backward-paragraph)
  3861. (bobp)))
  3862. (should
  3863. (org-test-with-temp-text "[fn:1] line1n<point>"
  3864. (org-backward-paragraph)
  3865. (bobp)))
  3866. ;; On the second element in an item or a footnote definition, jump
  3867. ;; to item or the definition.
  3868. (should
  3869. (= 2
  3870. (org-test-with-temp-text "- line1\n\n<point> line2"
  3871. (org-backward-paragraph)
  3872. (org-current-line))))
  3873. (should
  3874. (= 2
  3875. (org-test-with-temp-text "[fn:1] line1\n\n<point> line2"
  3876. (org-backward-paragraph)
  3877. (org-current-line))))
  3878. ;; On a table (resp. a property drawer), ignore table rows
  3879. ;; (resp. node properties).
  3880. (should
  3881. (org-test-with-temp-text "| a | b |\n| c | d |\n<point>P1"
  3882. (org-backward-paragraph)
  3883. (bobp)))
  3884. (should
  3885. (= 2
  3886. (org-test-with-temp-text
  3887. "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
  3888. (org-backward-paragraph)
  3889. (org-current-line))))
  3890. ;; In a plain list with one item every line, skip the whole list,
  3891. ;; even with point in the middle of the list.
  3892. (should
  3893. (org-test-with-temp-text "- A\n - B\n- C\n<point>"
  3894. (org-backward-paragraph)
  3895. (bobp)))
  3896. (should
  3897. (org-test-with-temp-text "- A\n - B\n- <point>C\n"
  3898. (org-backward-paragraph)
  3899. (bobp)))
  3900. ;; Skip consecutive keywords, clocks and diary S-exps.
  3901. (should
  3902. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n<point>"
  3903. (org-backward-paragraph)
  3904. (bobp)))
  3905. (should
  3906. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n<point>"
  3907. (org-backward-paragraph)
  3908. (bobp)))
  3909. (should
  3910. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n<point>"
  3911. (org-backward-paragraph)
  3912. (bobp)))
  3913. (should-not
  3914. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n<point>"
  3915. (org-backward-paragraph)
  3916. (bobp)))
  3917. (should-not
  3918. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n<point>"
  3919. (org-backward-paragraph)
  3920. (bobp)))
  3921. ;; On a comment, example, source and verse blocks, stop at blank
  3922. ;; lines.
  3923. (should
  3924. (= 1
  3925. (org-test-with-temp-text
  3926. "#+begin_comment\n<point>L1\n\nL2\n\nL3\n#+end_comment"
  3927. (org-backward-paragraph)
  3928. (org-current-line))))
  3929. (should
  3930. (= 2
  3931. (org-test-with-temp-text
  3932. "#+begin_verse\nL1\n\n<point>L2\n\nL3\n#+end_verse"
  3933. (org-backward-paragraph)
  3934. (org-current-line))))
  3935. (should
  3936. (= 3
  3937. (org-test-with-temp-text
  3938. "#+begin_src emacs-lisp\nL1\n\nL2\n\n<point>L3\n#+end_src"
  3939. (org-backward-paragraph)
  3940. (org-current-line))))
  3941. ;; When called from the opening line itself, however, move to
  3942. ;; beginning of block.
  3943. (should
  3944. (org-test-with-temp-text "#+begin_<point>example\nL1\n#+end_example"
  3945. (org-backward-paragraph)
  3946. (bobp)))
  3947. ;; On an empty heading, move above it.
  3948. (should
  3949. (org-test-with-temp-text "\n* <point>"
  3950. (org-backward-paragraph)
  3951. (bobp)))
  3952. (should
  3953. (org-test-with-temp-text "\n* \n<point>"
  3954. (org-backward-paragraph)
  3955. (bobp))))
  3956. (ert-deftest test-org/forward-element ()
  3957. "Test `org-forward-element' specifications."
  3958. ;; 1. At EOB: should error.
  3959. (org-test-with-temp-text "Some text\n"
  3960. (goto-char (point-max))
  3961. (should-error (org-forward-element)))
  3962. ;; 2. Standard move: expected to ignore blank lines.
  3963. (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
  3964. (org-forward-element)
  3965. (should (looking-at (regexp-quote "Second paragraph."))))
  3966. ;; 3. Headline tests.
  3967. (org-test-with-temp-text "
  3968. * Head 1
  3969. ** Head 1.1
  3970. *** Head 1.1.1
  3971. ** Head 1.2"
  3972. ;; 3.1. At an headline beginning: move to next headline at the
  3973. ;; same level.
  3974. (goto-line 3)
  3975. (org-forward-element)
  3976. (should (looking-at (regexp-quote "** Head 1.2")))
  3977. ;; 3.2. At an headline beginning: move to parent headline if no
  3978. ;; headline at the same level.
  3979. (goto-line 3)
  3980. (org-forward-element)
  3981. (should (looking-at (regexp-quote "** Head 1.2"))))
  3982. ;; 4. Greater element tests.
  3983. (org-test-with-temp-text
  3984. "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
  3985. ;; 4.1. At a greater element: expected to skip contents.
  3986. (org-forward-element)
  3987. (should (looking-at (regexp-quote "Outside.")))
  3988. ;; 4.2. At the end of greater element contents: expected to skip
  3989. ;; to the end of the greater element.
  3990. (goto-line 2)
  3991. (org-forward-element)
  3992. (should (looking-at (regexp-quote "Outside."))))
  3993. ;; 5. List tests.
  3994. (org-test-with-temp-text "
  3995. - item1
  3996. - sub1
  3997. - sub2
  3998. - sub3
  3999. Inner paragraph.
  4000. - item2
  4001. Outside."
  4002. ;; 5.1. At list top point: expected to move to the element after
  4003. ;; the list.
  4004. (goto-line 2)
  4005. (org-forward-element)
  4006. (should (looking-at (regexp-quote "Outside.")))
  4007. ;; 5.2. Special case: at the first line of a sub-list, but not at
  4008. ;; beginning of line, move to next item.
  4009. (goto-line 2)
  4010. (forward-char)
  4011. (org-forward-element)
  4012. (should (looking-at "- item2"))
  4013. (goto-line 4)
  4014. (forward-char)
  4015. (org-forward-element)
  4016. (should (looking-at " - sub2"))
  4017. ;; 5.3 At sub-list beginning: expected to move after the sub-list.
  4018. (goto-line 4)
  4019. (org-forward-element)
  4020. (should (looking-at (regexp-quote " Inner paragraph.")))
  4021. ;; 5.4. At sub-list end: expected to move outside the sub-list.
  4022. (goto-line 8)
  4023. (org-forward-element)
  4024. (should (looking-at (regexp-quote " Inner paragraph.")))
  4025. ;; 5.5. At an item: expected to move to next item, if any.
  4026. (goto-line 6)
  4027. (org-forward-element)
  4028. (should (looking-at " - sub3"))))
  4029. (ert-deftest test-org/backward-element ()
  4030. "Test `org-backward-element' specifications."
  4031. ;; 1. Should error at BOB.
  4032. (org-test-with-temp-text " \nParagraph."
  4033. (should-error (org-backward-element)))
  4034. ;; 2. Should move at BOB when called on the first element in buffer.
  4035. (should
  4036. (org-test-with-temp-text "\n#+TITLE: test"
  4037. (progn (forward-line)
  4038. (org-backward-element)
  4039. (bobp))))
  4040. ;; 3. Not at the beginning of an element: move at its beginning.
  4041. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  4042. (goto-line 3)
  4043. (end-of-line)
  4044. (org-backward-element)
  4045. (should (looking-at (regexp-quote "Paragraph2."))))
  4046. ;; 4. Headline tests.
  4047. (org-test-with-temp-text "
  4048. * Head 1
  4049. ** Head 1.1
  4050. *** Head 1.1.1
  4051. ** Head 1.2"
  4052. ;; 4.1. At an headline beginning: move to previous headline at the
  4053. ;; same level.
  4054. (goto-line 5)
  4055. (org-backward-element)
  4056. (should (looking-at (regexp-quote "** Head 1.1")))
  4057. ;; 4.2. At an headline beginning: move to parent headline if no
  4058. ;; headline at the same level.
  4059. (goto-line 3)
  4060. (org-backward-element)
  4061. (should (looking-at (regexp-quote "* Head 1")))
  4062. ;; 4.3. At the first top-level headline: should error.
  4063. (goto-line 2)
  4064. (should-error (org-backward-element)))
  4065. ;; 5. At beginning of first element inside a greater element:
  4066. ;; expected to move to greater element's beginning.
  4067. (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
  4068. (goto-line 3)
  4069. (org-backward-element)
  4070. (should (looking-at "#\\+BEGIN_CENTER")))
  4071. ;; 6. At the beginning of the first element in a section: should
  4072. ;; move back to headline, if any.
  4073. (should
  4074. (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
  4075. (progn (goto-char (point-max))
  4076. (beginning-of-line)
  4077. (org-backward-element)
  4078. (org-at-heading-p))))
  4079. ;; 7. List tests.
  4080. (org-test-with-temp-text "
  4081. - item1
  4082. - sub1
  4083. - sub2
  4084. - sub3
  4085. Inner paragraph.
  4086. - item2
  4087. Outside."
  4088. ;; 7.1. At beginning of sub-list: expected to move to the
  4089. ;; paragraph before it.
  4090. (goto-line 4)
  4091. (org-backward-element)
  4092. (should (looking-at "item1"))
  4093. ;; 7.2. At an item in a list: expected to move at previous item.
  4094. (goto-line 8)
  4095. (org-backward-element)
  4096. (should (looking-at " - sub2"))
  4097. (goto-line 12)
  4098. (org-backward-element)
  4099. (should (looking-at "- item1"))
  4100. ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
  4101. ;; beginning.
  4102. (goto-line 10)
  4103. (org-backward-element)
  4104. (should (looking-at " - sub1"))
  4105. (goto-line 15)
  4106. (org-backward-element)
  4107. (should (looking-at "- item1"))
  4108. ;; 7.4. At blank-lines before list end: expected to move to top
  4109. ;; item.
  4110. (goto-line 14)
  4111. (org-backward-element)
  4112. (should (looking-at "- item1"))))
  4113. (ert-deftest test-org/up-element ()
  4114. "Test `org-up-element' specifications."
  4115. ;; 1. At BOB or with no surrounding element: should error.
  4116. (org-test-with-temp-text "Paragraph."
  4117. (should-error (org-up-element)))
  4118. (org-test-with-temp-text "* Head1\n* Head2"
  4119. (goto-line 2)
  4120. (should-error (org-up-element)))
  4121. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  4122. (goto-line 3)
  4123. (should-error (org-up-element)))
  4124. ;; 2. At an headline: move to parent headline.
  4125. (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
  4126. (goto-line 3)
  4127. (org-up-element)
  4128. (should (looking-at "\\* Head1")))
  4129. ;; 3. Inside a greater element: move to greater element beginning.
  4130. (org-test-with-temp-text
  4131. "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
  4132. (goto-line 3)
  4133. (org-up-element)
  4134. (should (looking-at "#\\+BEGIN_CENTER")))
  4135. ;; 4. List tests.
  4136. (org-test-with-temp-text "* Top
  4137. - item1
  4138. - sub1
  4139. - sub2
  4140. Paragraph within sub2.
  4141. - item2"
  4142. ;; 4.1. Within an item: move to the item beginning.
  4143. (goto-line 8)
  4144. (org-up-element)
  4145. (should (looking-at " - sub2"))
  4146. ;; 4.2. At an item in a sub-list: move to parent item.
  4147. (goto-line 4)
  4148. (org-up-element)
  4149. (should (looking-at "- item1"))
  4150. ;; 4.3. At an item in top list: move to beginning of whole list.
  4151. (goto-line 10)
  4152. (org-up-element)
  4153. (should (looking-at "- item1"))
  4154. ;; 4.4. Special case. At very top point: should move to parent of
  4155. ;; list.
  4156. (goto-line 2)
  4157. (org-up-element)
  4158. (should (looking-at "\\* Top"))))
  4159. (ert-deftest test-org/down-element ()
  4160. "Test `org-down-element' specifications."
  4161. ;; Error when the element hasn't got a recursive type.
  4162. (org-test-with-temp-text "Paragraph."
  4163. (should-error (org-down-element)))
  4164. ;; Error when the element has no contents
  4165. (org-test-with-temp-text "* Headline"
  4166. (should-error (org-down-element)))
  4167. ;; When at a plain-list, move to first item.
  4168. (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
  4169. (goto-line 2)
  4170. (org-down-element)
  4171. (should (looking-at " - Item 1.1")))
  4172. (org-test-with-temp-text "#+NAME: list\n- Item 1"
  4173. (org-down-element)
  4174. (should (looking-at " Item 1")))
  4175. ;; When at a table, move to first row
  4176. (org-test-with-temp-text "#+NAME: table\n| a | b |"
  4177. (org-down-element)
  4178. (should (looking-at " a | b |")))
  4179. ;; Otherwise, move inside the greater element.
  4180. (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
  4181. (org-down-element)
  4182. (should (looking-at "Paragraph"))))
  4183. (ert-deftest test-org/drag-element-backward ()
  4184. "Test `org-drag-element-backward' specifications."
  4185. ;; Standard test.
  4186. (should
  4187. (equal
  4188. "#+key2: val2\n#+key1: val1\n#+key3: val3"
  4189. (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
  4190. (org-drag-element-backward)
  4191. (buffer-string))))
  4192. (should
  4193. (equal
  4194. "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
  4195. (org-test-with-temp-text
  4196. "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
  4197. (org-drag-element-backward)
  4198. (buffer-string))))
  4199. ;; Preserve blank lines.
  4200. (should
  4201. (equal "Paragraph 2\n\n\nPara1\n\nPara3"
  4202. (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
  4203. (org-drag-element-backward)
  4204. (buffer-string))))
  4205. ;; Preserve column.
  4206. (should
  4207. (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
  4208. (org-drag-element-backward)
  4209. (looking-at-p "2")))
  4210. ;; Error when trying to move first element of buffer.
  4211. (should-error
  4212. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4213. (org-drag-element-backward))
  4214. :type 'user-error)
  4215. ;; Error when trying to swap nested elements.
  4216. (should-error
  4217. (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
  4218. (org-drag-element-backward))
  4219. :type 'user-error)
  4220. ;; Error when trying to swap an headline element and a non-headline
  4221. ;; element.
  4222. (should-error
  4223. (org-test-with-temp-text "Test.\n<point>* Head 1"
  4224. (org-drag-element-backward))
  4225. :type 'error)
  4226. ;; Error when called before first element.
  4227. (should-error
  4228. (org-test-with-temp-text "\n<point>"
  4229. (org-drag-element-backward))
  4230. :type 'user-error)
  4231. ;; Preserve visibility of elements and their contents.
  4232. (should
  4233. (equal '((63 . 82) (26 . 48))
  4234. (org-test-with-temp-text "
  4235. #+BEGIN_CENTER
  4236. Text.
  4237. #+END_CENTER
  4238. - item 1
  4239. #+BEGIN_QUOTE
  4240. Text.
  4241. #+END_QUOTE"
  4242. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4243. (search-backward "- item 1")
  4244. (org-drag-element-backward)
  4245. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4246. (overlays-in (point-min) (point-max))))))
  4247. ;; Pathological case: handle call with point in blank lines right
  4248. ;; after a headline.
  4249. (should
  4250. (equal "* H2\n\n* H1\nText\n"
  4251. (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
  4252. (org-drag-element-backward)
  4253. (buffer-string)))))
  4254. (ert-deftest test-org/drag-element-forward ()
  4255. "Test `org-drag-element-forward' specifications."
  4256. ;; 1. Error when trying to move first element of buffer.
  4257. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4258. (goto-line 3)
  4259. (should-error (org-drag-element-forward)))
  4260. ;; 2. Error when trying to swap nested elements.
  4261. (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
  4262. (forward-line)
  4263. (should-error (org-drag-element-forward)))
  4264. ;; 3. Error when trying to swap a non-headline element and an
  4265. ;; headline.
  4266. (org-test-with-temp-text "Test.\n* Head 1"
  4267. (should-error (org-drag-element-forward)))
  4268. ;; 4. Error when called before first element.
  4269. (should-error
  4270. (org-test-with-temp-text "\n"
  4271. (forward-line)
  4272. (org-drag-element-backward))
  4273. :type 'user-error)
  4274. ;; 5. Otherwise, swap elements, preserving column and blank lines
  4275. ;; between elements.
  4276. (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
  4277. (search-forward "graph")
  4278. (org-drag-element-forward)
  4279. (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
  4280. (should (looking-at " 1")))
  4281. ;; 5. Preserve visibility of elements and their contents.
  4282. (org-test-with-temp-text "
  4283. #+BEGIN_CENTER
  4284. Text.
  4285. #+END_CENTER
  4286. - item 1
  4287. #+BEGIN_QUOTE
  4288. Text.
  4289. #+END_QUOTE"
  4290. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4291. (search-backward "#+BEGIN_CENTER")
  4292. (org-drag-element-forward)
  4293. (should
  4294. (equal
  4295. '((63 . 82) (26 . 48))
  4296. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4297. (overlays-in (point-min) (point-max)))))))
  4298. (ert-deftest test-org/next-block ()
  4299. "Test `org-next-block' specifications."
  4300. ;; Regular test.
  4301. (should
  4302. (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  4303. (org-next-block 1)
  4304. (looking-at "#\\+BEGIN_CENTER")))
  4305. ;; Ignore case.
  4306. (should
  4307. (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
  4308. (let ((case-fold-search nil))
  4309. (org-next-block 1)
  4310. (looking-at "#\\+begin_center"))))
  4311. ;; Ignore current line.
  4312. (should
  4313. (org-test-with-temp-text
  4314. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
  4315. (org-next-block 1)
  4316. (looking-at "#\\+BEGIN_CENTER")))
  4317. ;; Throw an error when no block is found.
  4318. (should-error
  4319. (org-test-with-temp-text "Paragraph"
  4320. (org-next-block 1)))
  4321. ;; With an argument, skip many blocks at once.
  4322. (should
  4323. (org-test-with-temp-text
  4324. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4325. (org-next-block 2)
  4326. (looking-at "#\\+BEGIN_QUOTE")))
  4327. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4328. (should
  4329. (org-test-with-temp-text
  4330. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4331. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4332. (looking-at "#\\+BEGIN_QUOTE")))
  4333. ;; Optional argument is also case-insensitive.
  4334. (should
  4335. (org-test-with-temp-text
  4336. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
  4337. (let ((case-fold-search nil))
  4338. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4339. (looking-at "#\\+begin_quote")))))
  4340. (ert-deftest test-org/insert-structure-template ()
  4341. "Test `org-insert-structure-template'."
  4342. ;; Test in empty buffer.
  4343. (should
  4344. (string= "#+begin_foo\n#+end_foo\n"
  4345. (org-test-with-temp-text ""
  4346. (org-insert-structure-template "foo")
  4347. (buffer-string))))
  4348. ;; Test with multiple lines in buffer.
  4349. (should
  4350. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4351. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4352. (transient-mark-mode 1)
  4353. (org-mark-element)
  4354. (org-insert-structure-template "foo")
  4355. (buffer-string))))
  4356. ;; Mark only the current line.
  4357. (should
  4358. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4359. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4360. (transient-mark-mode 1)
  4361. (set-mark (point-min))
  4362. (end-of-line)
  4363. (org-insert-structure-template "foo")
  4364. (buffer-string))))
  4365. ;; Middle of paragraph.
  4366. (should
  4367. (string= "p1\n#+begin_foo\np2\n#+end_foo\np3"
  4368. (org-test-with-temp-text "p1\n<point>p2\np3"
  4369. (set-mark (line-beginning-position))
  4370. (end-of-line)
  4371. (activate-mark)
  4372. (org-insert-structure-template "foo")
  4373. (buffer-string))))
  4374. ;; Test with text in buffer, no region, no final newline.
  4375. (should
  4376. (string= "#+begin_foo\nI'm a paragraph.\n#+end_foo\n"
  4377. (org-test-with-temp-text "I'm a paragraph."
  4378. (org-mark-element)
  4379. (org-insert-structure-template "foo")
  4380. (buffer-string))))
  4381. ;; Test with text in buffer and region set.
  4382. (should
  4383. (string= "#+begin_foo\nI'm a paragraph\n\nI'm a second paragrah\n#+end_foo\n"
  4384. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragrah"
  4385. (set-mark (point))
  4386. (goto-char (point-max))
  4387. (org-insert-structure-template "foo")
  4388. (buffer-string))))
  4389. ;; Test with example escaping.
  4390. (should
  4391. (string= "#+begin_example\n,* Heading\n#+end_example\n"
  4392. (org-test-with-temp-text "* Heading"
  4393. (org-mark-element)
  4394. (org-insert-structure-template "example")
  4395. (buffer-string))))
  4396. ;; Test with indentation.
  4397. (should
  4398. (string= " #+begin_foo\n This is a paragraph\n #+end_foo\n"
  4399. (org-test-with-temp-text " This is a paragraph"
  4400. (org-mark-element)
  4401. (org-insert-structure-template "foo")
  4402. (buffer-string))))
  4403. (should
  4404. (string= " #+begin_foo\n Line 1\n Line2\n #+end_foo\n"
  4405. (org-test-with-temp-text " Line 1\n Line2"
  4406. (org-mark-element)
  4407. (org-insert-structure-template "foo")
  4408. (buffer-string))))
  4409. ;; Test point location.
  4410. (should
  4411. (string= "#+begin_foo\n"
  4412. (org-test-with-temp-text ""
  4413. (org-insert-structure-template "foo")
  4414. (buffer-substring (point-min) (point)))))
  4415. (should
  4416. (string= "#+begin_src "
  4417. (org-test-with-temp-text ""
  4418. (org-insert-structure-template "src")
  4419. (buffer-substring (point-min) (point))))))
  4420. (ert-deftest test-org/previous-block ()
  4421. "Test `org-previous-block' specifications."
  4422. ;; Regular test.
  4423. (should
  4424. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
  4425. (org-previous-block 1)
  4426. (looking-at "#\\+BEGIN_CENTER")))
  4427. ;; Ignore case.
  4428. (should
  4429. (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
  4430. (let ((case-fold-search nil))
  4431. (org-previous-block 1)
  4432. (looking-at "#\\+begin_center"))))
  4433. ;; Ignore current line.
  4434. (should
  4435. (org-test-with-temp-text
  4436. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
  4437. (org-previous-block 1)
  4438. (looking-at "#\\+BEGIN_QUOTE")))
  4439. ;; Throw an error when no block is found.
  4440. (should-error
  4441. (org-test-with-temp-text "Paragraph<point>"
  4442. (org-previous-block 1)))
  4443. ;; With an argument, skip many blocks at once.
  4444. (should
  4445. (org-test-with-temp-text
  4446. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4447. (org-previous-block 2)
  4448. (looking-at "#\\+BEGIN_CENTER")))
  4449. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4450. (should
  4451. (org-test-with-temp-text
  4452. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4453. (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4454. (looking-at "#\\+BEGIN_QUOTE")))
  4455. ;; Optional argument is also case-insensitive.
  4456. (should
  4457. (org-test-with-temp-text
  4458. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
  4459. (let ((case-fold-search nil))
  4460. (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4461. (looking-at "#\\+begin_quote")))))
  4462. ;;; Outline structure
  4463. (ert-deftest test-org/demote ()
  4464. "Test `org-demote' specifications."
  4465. ;; Add correct number of stars according to `org-odd-levels-only'.
  4466. (should
  4467. (= 2
  4468. (org-test-with-temp-text "* H"
  4469. (let ((org-odd-levels-only nil)) (org-demote))
  4470. (org-current-level))))
  4471. (should
  4472. (= 3
  4473. (org-test-with-temp-text "* H"
  4474. (let ((org-odd-levels-only t)) (org-demote))
  4475. (org-current-level))))
  4476. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4477. (should
  4478. (org-test-with-temp-text "* H :tag:"
  4479. (let ((org-tags-column 10)
  4480. (org-auto-align-tags t)
  4481. (org-odd-levels-only nil))
  4482. (org-demote))
  4483. (org-move-to-column 10)
  4484. (looking-at-p ":tag:$")))
  4485. (should-not
  4486. (org-test-with-temp-text "* H :tag:"
  4487. (let ((org-tags-column 10)
  4488. (org-auto-align-tags nil)
  4489. (org-odd-levels-only nil))
  4490. (org-demote))
  4491. (org-move-to-column 10)
  4492. (looking-at-p ":tag:$")))
  4493. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4494. ;; info and property drawers accordingly.
  4495. (should
  4496. (= 3
  4497. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4498. (let ((org-odd-levels-only nil)
  4499. (org-adapt-indentation t))
  4500. (org-demote))
  4501. (forward-line)
  4502. (org-get-indentation))))
  4503. (should
  4504. (= 3
  4505. (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4506. (let ((org-odd-levels-only nil)
  4507. (org-adapt-indentation t))
  4508. (org-demote))
  4509. (forward-line)
  4510. (org-get-indentation))))
  4511. (should-not
  4512. (= 3
  4513. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4514. (let ((org-odd-levels-only nil)
  4515. (org-adapt-indentation nil))
  4516. (org-demote))
  4517. (forward-line)
  4518. (org-get-indentation))))
  4519. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4520. ;; section accordingly. Ignore, however, footnote definitions and
  4521. ;; inlinetasks boundaries.
  4522. (should
  4523. (= 3
  4524. (org-test-with-temp-text "* H\n Paragraph"
  4525. (let ((org-odd-levels-only nil)
  4526. (org-adapt-indentation t))
  4527. (org-demote))
  4528. (forward-line)
  4529. (org-get-indentation))))
  4530. (should
  4531. (= 2
  4532. (org-test-with-temp-text "* H\n Paragraph"
  4533. (let ((org-odd-levels-only nil)
  4534. (org-adapt-indentation nil))
  4535. (org-demote))
  4536. (forward-line)
  4537. (org-get-indentation))))
  4538. (should
  4539. (zerop
  4540. (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
  4541. (let ((org-odd-levels-only nil)
  4542. (org-adapt-indentation t))
  4543. (org-demote))
  4544. (goto-char (point-max))
  4545. (org-get-indentation))))
  4546. (should
  4547. (= 3
  4548. (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
  4549. (let ((org-odd-levels-only nil)
  4550. (org-adapt-indentation t))
  4551. (org-demote))
  4552. (goto-char (point-max))
  4553. (org-get-indentation))))
  4554. (when (featurep 'org-inlinetask)
  4555. (should
  4556. (zerop
  4557. (let ((org-inlinetask-min-level 5)
  4558. (org-adapt-indentation t))
  4559. (org-test-with-temp-text "* H\n***** I\n***** END"
  4560. (org-demote)
  4561. (forward-line)
  4562. (org-get-indentation))))))
  4563. (when (featurep 'org-inlinetask)
  4564. (should
  4565. (= 3
  4566. (let ((org-inlinetask-min-level 5)
  4567. (org-adapt-indentation t))
  4568. (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
  4569. (org-demote)
  4570. (forward-line 2)
  4571. (org-get-indentation))))))
  4572. ;; Ignore contents of source blocks or example blocks when
  4573. ;; indentation should be preserved (through
  4574. ;; `org-src-preserve-indentation' or "-i" flag).
  4575. (should-not
  4576. (zerop
  4577. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4578. (let ((org-adapt-indentation t)
  4579. (org-src-preserve-indentation nil))
  4580. (org-demote))
  4581. (forward-line 2)
  4582. (org-get-indentation))))
  4583. (should
  4584. (zerop
  4585. (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
  4586. (let ((org-adapt-indentation t)
  4587. (org-src-preserve-indentation t))
  4588. (org-demote))
  4589. (forward-line 2)
  4590. (org-get-indentation))))
  4591. (should
  4592. (zerop
  4593. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4594. (let ((org-adapt-indentation t)
  4595. (org-src-preserve-indentation t))
  4596. (org-demote))
  4597. (forward-line 2)
  4598. (org-get-indentation))))
  4599. (should
  4600. (zerop
  4601. (org-test-with-temp-text
  4602. "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
  4603. (let ((org-adapt-indentation t)
  4604. (org-src-preserve-indentation nil))
  4605. (org-demote))
  4606. (forward-line 2)
  4607. (org-get-indentation)))))
  4608. (ert-deftest test-org/promote ()
  4609. "Test `org-promote' specifications."
  4610. ;; Return an error if headline is to be promoted to level 0, unless
  4611. ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
  4612. ;; headline becomes a comment.
  4613. (should-error
  4614. (org-test-with-temp-text "* H"
  4615. (let ((org-allow-promoting-top-level-subtree nil)) (org-promote))))
  4616. (should
  4617. (equal "# H"
  4618. (org-test-with-temp-text "* H"
  4619. (let ((org-allow-promoting-top-level-subtree t)) (org-promote))
  4620. (buffer-string))))
  4621. ;; Remove correct number of stars according to
  4622. ;; `org-odd-levels-only'.
  4623. (should
  4624. (= 2
  4625. (org-test-with-temp-text "*** H"
  4626. (let ((org-odd-levels-only nil)) (org-promote))
  4627. (org-current-level))))
  4628. (should
  4629. (= 1
  4630. (org-test-with-temp-text "*** H"
  4631. (let ((org-odd-levels-only t)) (org-promote))
  4632. (org-current-level))))
  4633. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4634. (should
  4635. (org-test-with-temp-text "** H :tag:"
  4636. (let ((org-tags-column 10)
  4637. (org-auto-align-tags t)
  4638. (org-odd-levels-only nil))
  4639. (org-promote))
  4640. (org-move-to-column 10)
  4641. (looking-at-p ":tag:$")))
  4642. (should-not
  4643. (org-test-with-temp-text "** H :tag:"
  4644. (let ((org-tags-column 10)
  4645. (org-auto-align-tags nil)
  4646. (org-odd-levels-only nil))
  4647. (org-promote))
  4648. (org-move-to-column 10)
  4649. (looking-at-p ":tag:$")))
  4650. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4651. ;; info and property drawers.
  4652. (should
  4653. (= 2
  4654. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4655. (let ((org-odd-levels-only nil)
  4656. (org-adapt-indentation t))
  4657. (org-promote))
  4658. (forward-line)
  4659. (org-get-indentation))))
  4660. (should
  4661. (= 2
  4662. (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4663. (let ((org-odd-levels-only nil)
  4664. (org-adapt-indentation t))
  4665. (org-promote))
  4666. (forward-line)
  4667. (org-get-indentation))))
  4668. (should-not
  4669. (= 2
  4670. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4671. (let ((org-odd-levels-only nil)
  4672. (org-adapt-indentation nil))
  4673. (org-promote))
  4674. (forward-line)
  4675. (org-get-indentation))))
  4676. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4677. ;; section accordingly. Ignore, however, footnote definitions and
  4678. ;; inlinetasks boundaries.
  4679. (should
  4680. (= 2
  4681. (org-test-with-temp-text "** H\n Paragraph"
  4682. (let ((org-odd-levels-only nil)
  4683. (org-adapt-indentation t))
  4684. (org-promote))
  4685. (forward-line)
  4686. (org-get-indentation))))
  4687. (should-not
  4688. (= 2
  4689. (org-test-with-temp-text "** H\n Paragraph"
  4690. (let ((org-odd-levels-only nil)
  4691. (org-adapt-indentation nil))
  4692. (org-promote))
  4693. (forward-line)
  4694. (org-get-indentation))))
  4695. (should
  4696. (= 2
  4697. (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
  4698. (let ((org-odd-levels-only nil)
  4699. (org-adapt-indentation t))
  4700. (org-promote))
  4701. (forward-line)
  4702. (org-get-indentation))))
  4703. (when (featurep 'org-inlinetask)
  4704. (should
  4705. (zerop
  4706. (let ((org-inlinetask-min-level 5)
  4707. (org-adapt-indentation t))
  4708. (org-test-with-temp-text "** H\n***** I\n***** END"
  4709. (org-promote)
  4710. (forward-line)
  4711. (org-get-indentation))))))
  4712. (when (featurep 'org-inlinetask)
  4713. (should
  4714. (= 2
  4715. (let ((org-inlinetask-min-level 5)
  4716. (org-adapt-indentation t))
  4717. (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
  4718. (org-promote)
  4719. (forward-line 2)
  4720. (org-get-indentation))))))
  4721. ;; Give up shifting if it would break document's structure
  4722. ;; otherwise.
  4723. (should
  4724. (= 3
  4725. (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
  4726. (let ((org-odd-levels-only nil)
  4727. (org-adapt-indentation t))
  4728. (org-promote))
  4729. (forward-line)
  4730. (org-get-indentation))))
  4731. (should
  4732. (= 3
  4733. (org-test-with-temp-text "** H\n Paragraph\n * list."
  4734. (let ((org-odd-levels-only nil)
  4735. (org-adapt-indentation t))
  4736. (org-promote))
  4737. (forward-line)
  4738. (org-get-indentation))))
  4739. ;; Ignore contents of source blocks or example blocks when
  4740. ;; indentation should be preserved (through
  4741. ;; `org-src-preserve-indentation' or "-i" flag).
  4742. (should-not
  4743. (zerop
  4744. (org-test-with-temp-text
  4745. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  4746. (let ((org-adapt-indentation t)
  4747. (org-src-preserve-indentation nil)
  4748. (org-odd-levels-only nil))
  4749. (org-promote))
  4750. (forward-line)
  4751. (org-get-indentation))))
  4752. (should
  4753. (zerop
  4754. (org-test-with-temp-text
  4755. "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
  4756. (let ((org-adapt-indentation t)
  4757. (org-src-preserve-indentation t)
  4758. (org-odd-levels-only nil))
  4759. (org-promote))
  4760. (forward-line)
  4761. (org-get-indentation))))
  4762. (should
  4763. (zerop
  4764. (org-test-with-temp-text
  4765. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  4766. (let ((org-adapt-indentation t)
  4767. (org-src-preserve-indentation t)
  4768. (org-odd-levels-only nil))
  4769. (org-promote))
  4770. (forward-line)
  4771. (org-get-indentation))))
  4772. (should
  4773. (zerop
  4774. (org-test-with-temp-text
  4775. "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
  4776. (let ((org-adapt-indentation t)
  4777. (org-src-preserve-indentation nil)
  4778. (org-odd-levels-only nil))
  4779. (org-promote))
  4780. (forward-line)
  4781. (org-get-indentation)))))
  4782. (ert-deftest test-org/org-get-valid-level ()
  4783. "Test function `org-get-valid-level' specifications."
  4784. (let ((org-odd-levels-only nil))
  4785. (should (equal 1 (org-get-valid-level 0 0)))
  4786. (should (equal 1 (org-get-valid-level 0 1)))
  4787. (should (equal 2 (org-get-valid-level 0 2)))
  4788. (should (equal 3 (org-get-valid-level 0 3)))
  4789. (should (equal 1 (org-get-valid-level 1 0)))
  4790. (should (equal 2 (org-get-valid-level 1 1)))
  4791. (should (equal 23 (org-get-valid-level 1 22)))
  4792. (should (equal 1 (org-get-valid-level 1 -1)))
  4793. (should (equal 1 (org-get-valid-level 2 -1))))
  4794. (let ((org-odd-levels-only t))
  4795. (should (equal 1 (org-get-valid-level 0 0)))
  4796. (should (equal 1 (org-get-valid-level 0 1)))
  4797. (should (equal 3 (org-get-valid-level 0 2)))
  4798. (should (equal 5 (org-get-valid-level 0 3)))
  4799. (should (equal 1 (org-get-valid-level 1 0)))
  4800. (should (equal 3 (org-get-valid-level 1 1)))
  4801. (should (equal 3 (org-get-valid-level 2 1)))
  4802. (should (equal 5 (org-get-valid-level 3 1)))
  4803. (should (equal 5 (org-get-valid-level 4 1)))
  4804. (should (equal 43 (org-get-valid-level 1 21)))
  4805. (should (equal 1 (org-get-valid-level 1 -1)))
  4806. (should (equal 1 (org-get-valid-level 2 -1)))
  4807. (should (equal 1 (org-get-valid-level 3 -1)))
  4808. (should (equal 3 (org-get-valid-level 4 -1)))
  4809. (should (equal 3 (org-get-valid-level 5 -1)))))
  4810. ;;; Planning
  4811. (ert-deftest test-org/at-planning-p ()
  4812. "Test `org-at-planning-p' specifications."
  4813. ;; Regular test.
  4814. (should
  4815. (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
  4816. (org-at-planning-p)))
  4817. (should-not
  4818. (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
  4819. (org-at-planning-p)))
  4820. ;; Correctly find planning attached to inlinetasks.
  4821. (when (featurep 'org-inlinetask)
  4822. (should
  4823. (org-test-with-temp-text
  4824. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
  4825. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4826. (should-not
  4827. (org-test-with-temp-text
  4828. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  4829. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4830. (should-not
  4831. (org-test-with-temp-text
  4832. "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  4833. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4834. (should-not
  4835. (org-test-with-temp-text
  4836. "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
  4837. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
  4838. (ert-deftest test-org/add-planning-info ()
  4839. "Test `org-add-planning-info'."
  4840. ;; Create deadline when `org-adapt-indentation' is non-nil.
  4841. (should
  4842. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4843. (org-test-with-temp-text "* H\nParagraph<point>"
  4844. (let ((org-adapt-indentation t))
  4845. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4846. (replace-regexp-in-string
  4847. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4848. nil nil 1))))
  4849. ;; Create deadline when `org-adapt-indentation' is nil.
  4850. (should
  4851. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  4852. (org-test-with-temp-text "* H\nParagraph<point>"
  4853. (let ((org-adapt-indentation nil))
  4854. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4855. (replace-regexp-in-string
  4856. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4857. nil nil 1))))
  4858. ;; Update deadline when `org-adapt-indentation' is non-nil.
  4859. (should
  4860. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4861. (org-test-with-temp-text "\
  4862. * H
  4863. DEADLINE: <2015-06-24 Wed>
  4864. Paragraph<point>"
  4865. (let ((org-adapt-indentation t))
  4866. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4867. (replace-regexp-in-string
  4868. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4869. nil nil 1))))
  4870. ;; Update deadline when `org-adapt-indentation' is nil.
  4871. (should
  4872. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  4873. (org-test-with-temp-text "\
  4874. * H
  4875. DEADLINE: <2015-06-24 Wed>
  4876. Paragraph<point>"
  4877. (let ((org-adapt-indentation nil))
  4878. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4879. (replace-regexp-in-string
  4880. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4881. nil nil 1))))
  4882. ;; Schedule when `org-adapt-indentation' is non-nil.
  4883. (should
  4884. (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
  4885. (org-test-with-temp-text "* H\nParagraph<point>"
  4886. (let ((org-adapt-indentation t))
  4887. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  4888. (replace-regexp-in-string
  4889. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4890. nil nil 1))))
  4891. ;; Schedule when `org-adapt-indentation' is nil.
  4892. (should
  4893. (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
  4894. (org-test-with-temp-text "* H\nParagraph<point>"
  4895. (let ((org-adapt-indentation nil))
  4896. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  4897. (replace-regexp-in-string
  4898. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4899. nil nil 1))))
  4900. ;; Add deadline when scheduled.
  4901. (should
  4902. (equal "\
  4903. * H
  4904. DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
  4905. Paragraph"
  4906. (org-test-with-temp-text "\
  4907. * H
  4908. SCHEDULED: <2015-06-24 Wed>
  4909. Paragraph<point>"
  4910. (let ((org-adapt-indentation t))
  4911. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4912. (replace-regexp-in-string
  4913. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4914. nil nil 1))))
  4915. ;; Remove middle entry.
  4916. (should
  4917. (equal "\
  4918. * H
  4919. CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
  4920. Paragraph"
  4921. (org-test-with-temp-text "\
  4922. * H
  4923. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  4924. Paragraph<point>"
  4925. (let ((org-adapt-indentation t))
  4926. (org-add-planning-info nil nil 'deadline))
  4927. (replace-regexp-in-string
  4928. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  4929. nil nil 1))))
  4930. ;; Remove last entry and then middle entry (order should not
  4931. ;; matter).
  4932. (should
  4933. (equal "\
  4934. * H
  4935. CLOSED: [2015-06-24]
  4936. Paragraph"
  4937. (org-test-with-temp-text "\
  4938. * H
  4939. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  4940. Paragraph<point>"
  4941. (let ((org-adapt-indentation t))
  4942. (org-add-planning-info nil nil 'scheduled 'deadline))
  4943. (replace-regexp-in-string
  4944. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  4945. nil nil 1))))
  4946. ;; Remove closed when `org-adapt-indentation' is non-nil.
  4947. (should
  4948. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4949. (org-test-with-temp-text "\
  4950. * H
  4951. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  4952. Paragraph<point>"
  4953. (let ((org-adapt-indentation t))
  4954. (org-add-planning-info nil nil 'closed))
  4955. (replace-regexp-in-string
  4956. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4957. nil nil 1))))
  4958. (should
  4959. (equal "* H\n Paragraph"
  4960. (org-test-with-temp-text "\
  4961. * H
  4962. CLOSED: [2015-06-25 Thu]
  4963. Paragraph<point>"
  4964. (let ((org-adapt-indentation t))
  4965. (org-add-planning-info nil nil 'closed))
  4966. (replace-regexp-in-string
  4967. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4968. nil nil 1))))
  4969. ;; Remove closed when `org-adapt-indentation' is nil.
  4970. (should
  4971. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  4972. (org-test-with-temp-text "\
  4973. * H
  4974. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  4975. Paragraph<point>"
  4976. (let ((org-adapt-indentation nil))
  4977. (org-add-planning-info nil nil 'closed))
  4978. (replace-regexp-in-string
  4979. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4980. nil nil 1))))
  4981. (should
  4982. (equal "* H\nParagraph"
  4983. (org-test-with-temp-text "\
  4984. * H
  4985. CLOSED: [2015-06-25 Thu]
  4986. Paragraph<point>"
  4987. (let ((org-adapt-indentation nil))
  4988. (org-add-planning-info nil nil 'closed))
  4989. (replace-regexp-in-string
  4990. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4991. nil nil 1))))
  4992. ;; Remove closed entry and delete empty line.
  4993. (should
  4994. (equal "\
  4995. * H
  4996. Paragraph"
  4997. (org-test-with-temp-text "\
  4998. * H
  4999. CLOSED: [2015-06-24 Wed]
  5000. Paragraph<point>"
  5001. (let ((org-adapt-indentation t))
  5002. (org-add-planning-info nil nil 'closed))
  5003. (replace-regexp-in-string
  5004. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5005. nil nil 1))))
  5006. ;; Remove one entry and update another.
  5007. (should
  5008. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5009. (org-test-with-temp-text "\
  5010. * H
  5011. SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
  5012. Paragraph<point>"
  5013. (let ((org-adapt-indentation t))
  5014. (org-add-planning-info 'deadline "<2015-06-25 Thu>" 'scheduled))
  5015. (replace-regexp-in-string
  5016. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5017. nil nil 1)))))
  5018. (ert-deftest test-org/deadline ()
  5019. "Test `org-deadline' specifications."
  5020. ;; Insert a new value or replace existing one.
  5021. (should
  5022. (equal "* H\nDEADLINE: <2012-03-29>"
  5023. (org-test-with-temp-text "* H"
  5024. (let ((org-adapt-indentation nil)
  5025. (org-last-inserted-timestamp nil))
  5026. (org-deadline nil "<2012-03-29 Tue>"))
  5027. (replace-regexp-in-string
  5028. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5029. nil nil 1))))
  5030. (should
  5031. (equal "* H\nDEADLINE: <2014-03-04>"
  5032. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5033. (let ((org-adapt-indentation nil)
  5034. (org-last-inserted-timestamp nil))
  5035. (org-deadline nil "<2014-03-04 Thu>"))
  5036. (replace-regexp-in-string
  5037. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5038. nil nil 1))))
  5039. ;; Accept delta time, e.g., "+2d".
  5040. (should
  5041. (equal "* H\nDEADLINE: <2015-03-04>"
  5042. (org-test-at-time "2014-03-04"
  5043. (org-test-with-temp-text "* H"
  5044. (let ((org-adapt-indentation nil)
  5045. (org-last-inserted-timestamp nil))
  5046. (org-deadline nil "+1y"))
  5047. (replace-regexp-in-string
  5048. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5049. ;; Preserve repeater.
  5050. (should
  5051. (equal "* H\nDEADLINE: <2012-03-29 +2y>"
  5052. (org-test-with-temp-text "* H"
  5053. (let ((org-adapt-indentation nil)
  5054. (org-last-inserted-timestamp nil))
  5055. (org-deadline nil "<2012-03-29 Tue +2y>"))
  5056. (replace-regexp-in-string
  5057. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5058. ;; Remove CLOSED keyword, if any.
  5059. (should
  5060. (equal "* H\nDEADLINE: <2012-03-29>"
  5061. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  5062. (let ((org-adapt-indentation nil)
  5063. (org-last-inserted-timestamp nil))
  5064. (org-deadline nil "<2012-03-29 Tue>"))
  5065. (replace-regexp-in-string
  5066. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5067. ;; With C-u argument, remove DEADLINE keyword.
  5068. (should
  5069. (equal "* H\n"
  5070. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5071. (let ((org-adapt-indentation nil)
  5072. (org-last-inserted-timestamp nil))
  5073. (org-deadline '(4)))
  5074. (buffer-string))))
  5075. (should
  5076. (equal "* H"
  5077. (org-test-with-temp-text "* H"
  5078. (let ((org-adapt-indentation nil)
  5079. (org-last-inserted-timestamp nil))
  5080. (org-deadline '(4)))
  5081. (buffer-string))))
  5082. ;; With C-u C-u argument, prompt for a delay cookie.
  5083. (should
  5084. (equal "* H\nDEADLINE: <2012-03-29 -705d>"
  5085. (cl-letf (((symbol-function 'org-read-date)
  5086. (lambda (&rest args)
  5087. (apply #'encode-time
  5088. (org-parse-time-string "2014-03-04")))))
  5089. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5090. (let ((org-adapt-indentation nil)
  5091. (org-last-inserted-timestamp nil))
  5092. (org-deadline '(16)))
  5093. (buffer-string)))))
  5094. (should-error
  5095. (cl-letf (((symbol-function 'org-read-date)
  5096. (lambda (&rest args)
  5097. (apply #'encode-time
  5098. (org-parse-time-string "2014-03-04")))))
  5099. (org-test-with-temp-text "* H"
  5100. (let ((org-adapt-indentation nil)
  5101. (org-last-inserted-timestamp nil))
  5102. (org-deadline '(16)))
  5103. (buffer-string))))
  5104. ;; When a region is active and
  5105. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5106. ;; same value in all headlines in region.
  5107. (should
  5108. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5109. (org-test-with-temp-text "* H1\n* H2"
  5110. (let ((org-adapt-indentation nil)
  5111. (org-last-inserted-timestamp nil)
  5112. (org-loop-over-headlines-in-active-region t))
  5113. (transient-mark-mode 1)
  5114. (push-mark (point) t t)
  5115. (goto-char (point-max))
  5116. (org-deadline nil "2012-03-29"))
  5117. (replace-regexp-in-string
  5118. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5119. (should-not
  5120. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5121. (org-test-with-temp-text "* H1\n* H2"
  5122. (let ((org-adapt-indentation nil)
  5123. (org-last-inserted-timestamp nil)
  5124. (org-loop-over-headlines-in-active-region nil))
  5125. (transient-mark-mode 1)
  5126. (push-mark (point) t t)
  5127. (goto-char (point-max))
  5128. (org-deadline nil "2012-03-29"))
  5129. (replace-regexp-in-string
  5130. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5131. (ert-deftest test-org/schedule ()
  5132. "Test `org-schedule' specifications."
  5133. ;; Insert a new value or replace existing one.
  5134. (should
  5135. (equal "* H\nSCHEDULED: <2012-03-29>"
  5136. (org-test-with-temp-text "* H"
  5137. (let ((org-adapt-indentation nil)
  5138. (org-last-inserted-timestamp nil))
  5139. (org-schedule nil "<2012-03-29 Tue>"))
  5140. (replace-regexp-in-string
  5141. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5142. nil nil 1))))
  5143. (should
  5144. (equal "* H\nSCHEDULED: <2014-03-04>"
  5145. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5146. (let ((org-adapt-indentation nil)
  5147. (org-last-inserted-timestamp nil))
  5148. (org-schedule nil "<2014-03-04 Thu>"))
  5149. (replace-regexp-in-string
  5150. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5151. nil nil 1))))
  5152. ;; Accept delta time, e.g., "+2d".
  5153. (should
  5154. (equal "* H\nSCHEDULED: <2015-03-04>"
  5155. (org-test-at-time "2014-03-04"
  5156. (org-test-with-temp-text "* H"
  5157. (let ((org-adapt-indentation nil)
  5158. (org-last-inserted-timestamp nil))
  5159. (org-schedule nil "+1y"))
  5160. (replace-regexp-in-string
  5161. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5162. ;; Preserve repeater.
  5163. (should
  5164. (equal "* H\nSCHEDULED: <2012-03-29 +2y>"
  5165. (org-test-with-temp-text "* H"
  5166. (let ((org-adapt-indentation nil)
  5167. (org-last-inserted-timestamp nil))
  5168. (org-schedule nil "<2012-03-29 Tue +2y>"))
  5169. (replace-regexp-in-string
  5170. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5171. ;; Remove CLOSED keyword, if any.
  5172. (should
  5173. (equal "* H\nSCHEDULED: <2012-03-29>"
  5174. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  5175. (let ((org-adapt-indentation nil)
  5176. (org-last-inserted-timestamp nil))
  5177. (org-schedule nil "<2012-03-29 Tue>"))
  5178. (replace-regexp-in-string
  5179. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5180. ;; With C-u argument, remove SCHEDULED keyword.
  5181. (should
  5182. (equal "* H\n"
  5183. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5184. (let ((org-adapt-indentation nil)
  5185. (org-last-inserted-timestamp nil))
  5186. (org-schedule '(4)))
  5187. (buffer-string))))
  5188. (should
  5189. (equal "* H"
  5190. (org-test-with-temp-text "* H"
  5191. (let ((org-adapt-indentation nil)
  5192. (org-last-inserted-timestamp nil))
  5193. (org-schedule '(4)))
  5194. (buffer-string))))
  5195. ;; With C-u C-u argument, prompt for a delay cookie.
  5196. (should
  5197. (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
  5198. (cl-letf (((symbol-function 'org-read-date)
  5199. (lambda (&rest args)
  5200. (apply #'encode-time
  5201. (org-parse-time-string "2014-03-04")))))
  5202. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5203. (let ((org-adapt-indentation nil)
  5204. (org-last-inserted-timestamp nil))
  5205. (org-schedule '(16)))
  5206. (buffer-string)))))
  5207. (should-error
  5208. (cl-letf (((symbol-function 'org-read-date)
  5209. (lambda (&rest args)
  5210. (apply #'encode-time
  5211. (org-parse-time-string "2014-03-04")))))
  5212. (org-test-with-temp-text "* H"
  5213. (let ((org-adapt-indentation nil)
  5214. (org-last-inserted-timestamp nil))
  5215. (org-schedule '(16)))
  5216. (buffer-string))))
  5217. ;; When a region is active and
  5218. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5219. ;; same value in all headlines in region.
  5220. (should
  5221. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5222. (org-test-with-temp-text "* H1\n* H2"
  5223. (let ((org-adapt-indentation nil)
  5224. (org-last-inserted-timestamp nil)
  5225. (org-loop-over-headlines-in-active-region t))
  5226. (transient-mark-mode 1)
  5227. (push-mark (point) t t)
  5228. (goto-char (point-max))
  5229. (org-schedule nil "2012-03-29"))
  5230. (replace-regexp-in-string
  5231. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5232. (should-not
  5233. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5234. (org-test-with-temp-text "* H1\n* H2"
  5235. (let ((org-adapt-indentation nil)
  5236. (org-last-inserted-timestamp nil)
  5237. (org-loop-over-headlines-in-active-region nil))
  5238. (transient-mark-mode 1)
  5239. (push-mark (point) t t)
  5240. (goto-char (point-max))
  5241. (org-schedule nil "2012-03-29"))
  5242. (replace-regexp-in-string
  5243. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5244. (should
  5245. ;; check if a repeater survives re-scheduling.
  5246. (string-match-p
  5247. "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
  5248. (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
  5249. (let ((org-adapt-indentation nil)
  5250. (org-last-inserted-timestamp nil))
  5251. (org-schedule nil "2017-02-01"))
  5252. (buffer-string)))))
  5253. ;;; Property API
  5254. (ert-deftest test-org/buffer-property-keys ()
  5255. "Test `org-buffer-property-keys' specifications."
  5256. ;; Retrieve properties across siblings.
  5257. (should
  5258. (equal '("A" "B")
  5259. (org-test-with-temp-text "
  5260. * H1
  5261. :PROPERTIES:
  5262. :A: 1
  5263. :END:
  5264. * H2
  5265. :PROPERTIES:
  5266. :B: 1
  5267. :END:"
  5268. (org-buffer-property-keys))))
  5269. ;; Retrieve properties across children.
  5270. (should
  5271. (equal '("A" "B")
  5272. (org-test-with-temp-text "
  5273. * H1
  5274. :PROPERTIES:
  5275. :A: 1
  5276. :END:
  5277. ** H2
  5278. :PROPERTIES:
  5279. :B: 1
  5280. :END:"
  5281. (org-buffer-property-keys))))
  5282. ;; Retrieve muliple properties in the same drawer.
  5283. (should
  5284. (equal '("A" "B")
  5285. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5286. (org-buffer-property-keys))))
  5287. ;; Ignore extension symbol in property name.
  5288. (should
  5289. (equal '("A")
  5290. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5291. (org-buffer-property-keys))))
  5292. ;; Add bare property if xxx_ALL property is there
  5293. (should
  5294. (equal '("A" "B" "B_ALL")
  5295. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B_ALL: foo bar\n:END:"
  5296. (org-buffer-property-keys))))
  5297. ;; Add bare property if xxx_ALL property is there - check dupes
  5298. (should
  5299. (equal '("A" "B" "B_ALL")
  5300. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:B_ALL: foo bar\n:END:"
  5301. (org-buffer-property-keys))))
  5302. ;; Retrieve properties from #+PROPERTY keyword lines
  5303. (should
  5304. (equal '("A" "C")
  5305. (org-test-with-temp-text "#+PROPERTY: C foo\n* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5306. (org-buffer-property-keys))))
  5307. ;; Retrieve properties from #+PROPERTY keyword lines - make sure an _ALL property also
  5308. ;; adds the bare property
  5309. (should
  5310. (equal '("A" "C" "C_ALL")
  5311. (org-test-with-temp-text "#+PROPERTY: C_ALL foo bar\n* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5312. (org-buffer-property-keys))))
  5313. ;; With non-nil COLUMNS, extract property names from columns.
  5314. (should
  5315. (equal '("A" "B")
  5316. (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
  5317. (org-buffer-property-keys nil nil t))))
  5318. (should
  5319. (equal '("A" "B" "COLUMNS")
  5320. (org-test-with-temp-text
  5321. "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
  5322. (org-buffer-property-keys nil nil t))))
  5323. ;; In COLUMNS, ignore title and summary-type.
  5324. (should
  5325. (equal '("A")
  5326. (org-test-with-temp-text "#+COLUMNS: %A(Foo)"
  5327. (org-buffer-property-keys nil nil t))))
  5328. (should
  5329. (equal '("A")
  5330. (org-test-with-temp-text "#+COLUMNS: %A{Foo}"
  5331. (org-buffer-property-keys nil nil t))))
  5332. (should
  5333. (equal '("A")
  5334. (org-test-with-temp-text "#+COLUMNS: %A(Foo){Bar}"
  5335. (org-buffer-property-keys nil nil t)))))
  5336. (ert-deftest test-org/property-values ()
  5337. "Test `org-property-values' specifications."
  5338. ;; Regular test.
  5339. (should
  5340. (equal '("2" "1")
  5341. (org-test-with-temp-text
  5342. "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
  5343. (org-property-values "A"))))
  5344. ;; Ignore empty values.
  5345. (should-not
  5346. (org-test-with-temp-text
  5347. "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
  5348. (org-property-values "A")))
  5349. ;; Take into consideration extended values.
  5350. (should
  5351. (equal '("1 2")
  5352. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5353. (org-property-values "A")))))
  5354. (ert-deftest test-org/set-property ()
  5355. "Test `org-set-property' specifications."
  5356. (should
  5357. (equal
  5358. ":PROPERTIES:\n:TEST: t\n:END:\n"
  5359. (org-test-with-temp-text ""
  5360. (let ((org-property-format "%s %s"))
  5361. (org-set-property "TEST" "t"))
  5362. (buffer-string))))
  5363. (should
  5364. (equal
  5365. "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5366. (org-test-with-temp-text "* H"
  5367. (let ((org-adapt-indentation nil)
  5368. (org-property-format "%s %s"))
  5369. (org-set-property "TEST" "t"))
  5370. (buffer-string)))))
  5371. (ert-deftest test-org/delete-property ()
  5372. "Test `org-delete-property' specifications."
  5373. (should
  5374. (equal
  5375. ""
  5376. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5377. (org-delete-property "TEST")
  5378. (buffer-string))))
  5379. (should
  5380. (equal
  5381. ":PROPERTIES:\n:TEST1: t\n:END:\n"
  5382. (org-test-with-temp-text ":PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5383. (org-delete-property "TEST2")
  5384. (buffer-string))))
  5385. (should
  5386. (equal
  5387. "* H\n"
  5388. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5389. (org-delete-property "TEST")
  5390. (buffer-string))))
  5391. (should
  5392. (equal
  5393. "* H\n:PROPERTIES:\n:TEST1: t\n:END:\n"
  5394. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5395. (org-delete-property "TEST2")
  5396. (buffer-string)))))
  5397. (ert-deftest test-org/delete-property-globally ()
  5398. "Test `org-delete-property-global' specifications."
  5399. (should
  5400. (equal
  5401. ""
  5402. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5403. (org-delete-property-globally "TEST")
  5404. (buffer-string))))
  5405. (should
  5406. (equal
  5407. "* H\n"
  5408. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n* H\n:PROPERTIES:\n:TEST: nil\n:END:"
  5409. (org-delete-property-globally "TEST")
  5410. (buffer-string)))))
  5411. (ert-deftest test-org/find-property ()
  5412. "Test `org-find-property' specifications."
  5413. ;; Regular test.
  5414. (should
  5415. (= 1
  5416. (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
  5417. (org-find-property "prop"))))
  5418. ;; Find properties in top-level property drawer.
  5419. (should
  5420. (= 1
  5421. (org-test-with-temp-text ":PROPERTIES:\n:PROP: value\n:END:"
  5422. (org-find-property "prop"))))
  5423. ;; Ignore false positives.
  5424. (should
  5425. (= 27
  5426. (org-test-with-temp-text
  5427. "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
  5428. (org-find-property "A"))))
  5429. ;; Return first entry found in buffer.
  5430. (should
  5431. (= 1
  5432. (org-test-with-temp-text
  5433. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5434. (org-find-property "A"))))
  5435. ;; Only search visible part of the buffer.
  5436. (should
  5437. (= 31
  5438. (org-test-with-temp-text
  5439. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5440. (org-narrow-to-subtree)
  5441. (org-find-property "A"))))
  5442. ;; With optional argument, only find entries with a specific value.
  5443. (should-not
  5444. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5445. (org-find-property "A" "2")))
  5446. (should
  5447. (= 31
  5448. (org-test-with-temp-text
  5449. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
  5450. (org-find-property "A" "2"))))
  5451. ;; Use "nil" for explicit nil values.
  5452. (should
  5453. (= 31
  5454. (org-test-with-temp-text
  5455. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
  5456. (org-find-property "A" "nil")))))
  5457. (ert-deftest test-org/entry-delete ()
  5458. "Test `org-entry-delete' specifications."
  5459. ;; Regular test.
  5460. (should
  5461. (string-match
  5462. " *:PROPERTIES:\n *:B: +2\n *:END:"
  5463. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5464. (org-entry-delete (point) "A")
  5465. (buffer-string))))
  5466. ;; Also remove accumulated properties.
  5467. (should-not
  5468. (string-match
  5469. ":A"
  5470. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
  5471. (org-entry-delete (point) "A")
  5472. (buffer-string))))
  5473. ;; When last property is removed, remove the property drawer.
  5474. (should-not
  5475. (string-match
  5476. ":PROPERTIES:"
  5477. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
  5478. (org-entry-delete (point) "A")
  5479. (buffer-string))))
  5480. ;; Return a non-nil value when some property was removed.
  5481. (should
  5482. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5483. (org-entry-delete (point) "A")))
  5484. (should-not
  5485. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5486. (org-entry-delete (point) "C")))
  5487. ;; Special properties cannot be located in a drawer. Allow to
  5488. ;; remove them anyway, in case of user error.
  5489. (should
  5490. (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
  5491. (org-entry-delete (point) "SCHEDULED"))))
  5492. (ert-deftest test-org/entry-get ()
  5493. "Test `org-entry-get' specifications."
  5494. ;; Regular test.
  5495. (should
  5496. (equal "1"
  5497. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:"
  5498. (org-entry-get (point) "A"))))
  5499. (should
  5500. (equal "1"
  5501. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5502. (org-entry-get (point) "A"))))
  5503. ;; Ignore case.
  5504. (should
  5505. (equal "1"
  5506. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5507. (org-entry-get (point) "a"))))
  5508. ;; Handle extended values, both before and after base value.
  5509. (should
  5510. (equal "1 2 3"
  5511. (org-test-with-temp-text
  5512. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5513. (org-entry-get (point) "A"))))
  5514. ;; Empty values are returned as the empty string.
  5515. (should
  5516. (equal ""
  5517. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
  5518. (org-entry-get (point) "A"))))
  5519. ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
  5520. ;; otherwise, return nil.
  5521. (should-not
  5522. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5523. (org-entry-get (point) "A")))
  5524. (should
  5525. (equal "nil"
  5526. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5527. (org-entry-get (point) "A" nil t))))
  5528. ;; Return nil when no property is found, independently on the
  5529. ;; LITERAL-NIL argument.
  5530. (should-not
  5531. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5532. (org-entry-get (point) "B")))
  5533. (should-not
  5534. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5535. (org-entry-get (point) "B" nil t)))
  5536. ;; Handle inheritance, when allowed. Include extended values and
  5537. ;; possibly global values.
  5538. (should
  5539. (equal
  5540. "1"
  5541. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:\n* H"
  5542. (org-entry-get (point-max) "A" t))))
  5543. (should
  5544. (equal
  5545. "1"
  5546. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5547. (org-entry-get (point-max) "A" t))))
  5548. (should
  5549. (equal
  5550. "1"
  5551. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5552. (let ((org-use-property-inheritance t))
  5553. (org-entry-get (point-max) "A" 'selective)))))
  5554. (should-not
  5555. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5556. (let ((org-use-property-inheritance nil))
  5557. (org-entry-get (point-max) "A" 'selective))))
  5558. (should
  5559. (equal
  5560. "1 2"
  5561. (org-test-with-temp-text
  5562. ":PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5563. (org-entry-get (point-max) "A" t))))
  5564. (should
  5565. (equal
  5566. "1 2"
  5567. (org-test-with-temp-text
  5568. "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5569. (org-entry-get (point-max) "A" t))))
  5570. (should
  5571. (equal
  5572. "1 2"
  5573. (org-test-with-temp-text
  5574. ":PROPERTIES:\n:A: 1\n:END:\n* H1\n* H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5575. (org-entry-get (point-max) "A" t))))
  5576. (should
  5577. (equal
  5578. "1 2"
  5579. (org-test-with-temp-text
  5580. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2.1\n* H2.2\n:PROPERTIES:\n:A+: 2\n:END:"
  5581. (org-entry-get (point-max) "A" t))))
  5582. (should
  5583. (equal "1"
  5584. (org-test-with-temp-text
  5585. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
  5586. (org-mode-restart)
  5587. (org-entry-get (point-max) "A" t))))
  5588. (should
  5589. (equal "0 1"
  5590. (org-test-with-temp-text
  5591. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
  5592. (org-mode-restart)
  5593. (org-entry-get (point-max) "A" t))))
  5594. ;; document level property-drawer has precedance over
  5595. ;; global-property by PROPERTY-keyword.
  5596. (should
  5597. (equal "0 2"
  5598. (org-test-with-temp-text
  5599. ":PROPERTIES:\n:A: 0\n:END:\n#+PROPERTY: A 1\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5600. (org-mode-restart)
  5601. (org-entry-get (point-max) "A" t)))))
  5602. (ert-deftest test-org/entry-properties ()
  5603. "Test `org-entry-properties' specifications."
  5604. ;; Get "ITEM" property.
  5605. (should
  5606. (equal "H"
  5607. (org-test-with-temp-text "* TODO H"
  5608. (cdr (assoc "ITEM" (org-entry-properties nil "ITEM"))))))
  5609. (should
  5610. (equal "H"
  5611. (org-test-with-temp-text "* TODO H"
  5612. (cdr (assoc "ITEM" (org-entry-properties))))))
  5613. ;; Get "TODO" property. TODO keywords are case sensitive.
  5614. (should
  5615. (equal "TODO"
  5616. (org-test-with-temp-text "* TODO H"
  5617. (cdr (assoc "TODO" (org-entry-properties nil "TODO"))))))
  5618. (should
  5619. (equal "TODO"
  5620. (org-test-with-temp-text "* TODO H"
  5621. (cdr (assoc "TODO" (org-entry-properties))))))
  5622. (should-not
  5623. (org-test-with-temp-text "* H"
  5624. (assoc "TODO" (org-entry-properties nil "TODO"))))
  5625. (should-not
  5626. (org-test-with-temp-text "* todo H"
  5627. (assoc "TODO" (org-entry-properties nil "TODO"))))
  5628. ;; Get "PRIORITY" property.
  5629. (should
  5630. (equal "A"
  5631. (org-test-with-temp-text "* [#A] H"
  5632. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  5633. (should
  5634. (equal "A"
  5635. (org-test-with-temp-text "* [#A] H"
  5636. (cdr (assoc "PRIORITY" (org-entry-properties))))))
  5637. (should
  5638. (equal (char-to-string org-priority-default)
  5639. (org-test-with-temp-text "* H"
  5640. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  5641. ;; Get "FILE" property.
  5642. (should
  5643. (org-test-with-temp-text-in-file "* H\nParagraph"
  5644. (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil "FILE")))
  5645. (buffer-file-name))))
  5646. (should
  5647. (org-test-with-temp-text-in-file "* H\nParagraph"
  5648. (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
  5649. (buffer-file-name))))
  5650. (should-not
  5651. (org-test-with-temp-text "* H\nParagraph"
  5652. (cdr (assoc "FILE" (org-entry-properties nil "FILE")))))
  5653. ;; Get "TAGS" property.
  5654. (should
  5655. (equal ":tag1:tag2:"
  5656. (org-test-with-temp-text "* H :tag1:tag2:"
  5657. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS"))))))
  5658. (should
  5659. (equal ":tag1:tag2:"
  5660. (org-test-with-temp-text "* H :tag1:tag2:"
  5661. (cdr (assoc "TAGS" (org-entry-properties))))))
  5662. (should-not
  5663. (org-test-with-temp-text "* H"
  5664. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS")))))
  5665. ;; Get "ALLTAGS" property.
  5666. (should
  5667. (equal ":tag1:tag2:"
  5668. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  5669. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS"))))))
  5670. (should
  5671. (equal ":tag1:tag2:"
  5672. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  5673. (cdr (assoc "ALLTAGS" (org-entry-properties))))))
  5674. (should-not
  5675. (org-test-with-temp-text "* H"
  5676. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS")))))
  5677. ;; Get "BLOCKED" property.
  5678. (should
  5679. (equal "t"
  5680. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  5681. (let ((org-enforce-todo-dependencies t)
  5682. (org-blocker-hook
  5683. '(org-block-todo-from-children-or-siblings-or-parent)))
  5684. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  5685. (should
  5686. (equal ""
  5687. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  5688. (let ((org-enforce-todo-dependencies t)
  5689. (org-blocker-hook
  5690. '(org-block-todo-from-children-or-siblings-or-parent)))
  5691. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  5692. ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
  5693. (should
  5694. (equal
  5695. "[2012-03-29 thu.]"
  5696. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  5697. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED"))))))
  5698. (should
  5699. (equal
  5700. "[2012-03-29 thu.]"
  5701. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  5702. (cdr (assoc "CLOSED" (org-entry-properties))))))
  5703. (should-not
  5704. (org-test-with-temp-text "* H"
  5705. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED")))))
  5706. (should
  5707. (equal
  5708. "<2014-03-04 tue.>"
  5709. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5710. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE"))))))
  5711. (should
  5712. (equal
  5713. "<2014-03-04 tue.>"
  5714. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5715. (cdr (assoc "DEADLINE" (org-entry-properties))))))
  5716. (should-not
  5717. (org-test-with-temp-text "* H"
  5718. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE")))))
  5719. (should
  5720. (equal
  5721. "<2014-03-04 tue.>"
  5722. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5723. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED"))))))
  5724. (should
  5725. (equal
  5726. "<2014-03-04 tue.>"
  5727. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5728. (cdr (assoc "SCHEDULED" (org-entry-properties))))))
  5729. (should-not
  5730. (org-test-with-temp-text "* H"
  5731. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED")))))
  5732. ;; Get "CATEGORY"
  5733. (should
  5734. (equal "cat"
  5735. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  5736. (cdr (assoc "CATEGORY" (org-entry-properties))))))
  5737. (should
  5738. (equal "cat"
  5739. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  5740. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5741. (should
  5742. (equal "cat"
  5743. (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
  5744. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5745. (should
  5746. (equal "cat2"
  5747. (org-test-with-temp-text
  5748. (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  5749. "\n"
  5750. "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
  5751. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5752. ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
  5753. (should
  5754. (equal "<2012-03-29 thu.>"
  5755. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
  5756. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  5757. (should
  5758. (equal "[2012-03-29 thu.]"
  5759. (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
  5760. (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
  5761. (should
  5762. (equal "<2012-03-29 thu.>"
  5763. (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
  5764. (cdr (assoc "TIMESTAMP" (org-entry-properties nil "TIMESTAMP"))))))
  5765. (should
  5766. (equal "[2014-03-04 tue.]"
  5767. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
  5768. (cdr (assoc "TIMESTAMP_IA"
  5769. (org-entry-properties nil "TIMESTAMP_IA"))))))
  5770. (should-not
  5771. (equal "<2012-03-29 thu.>"
  5772. (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
  5773. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  5774. ;; Get standard properties.
  5775. (should
  5776. (equal "1"
  5777. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5778. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5779. ;; Handle extended properties.
  5780. (should
  5781. (equal "1 2 3"
  5782. (org-test-with-temp-text
  5783. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5784. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5785. (should
  5786. (equal "1 2 3"
  5787. (org-test-with-temp-text
  5788. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
  5789. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5790. ;; Ignore forbidden (special) properties.
  5791. (should-not
  5792. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
  5793. (cdr (assoc "TODO" (org-entry-properties nil 'standard))))))
  5794. (ert-deftest test-org/entry-put ()
  5795. "Test `org-entry-put' specifications."
  5796. ;; Error when not a string or nil.
  5797. (should-error
  5798. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5799. (org-entry-put 1 "test" 2)))
  5800. ;; Error when property name is invalid.
  5801. (should-error
  5802. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5803. (org-entry-put 1 "no space" "value")))
  5804. (should-error
  5805. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5806. (org-entry-put 1 "" "value")))
  5807. ;; Set "TODO" property.
  5808. (should
  5809. (string-match (regexp-quote " TODO H")
  5810. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  5811. (org-entry-put (point) "TODO" "TODO")
  5812. (buffer-string))))
  5813. (should
  5814. (string-match (regexp-quote "* H")
  5815. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  5816. (org-entry-put (point) "TODO" nil)
  5817. (buffer-string))))
  5818. ;; Set "PRIORITY" property.
  5819. (should
  5820. (equal "* [#A] H"
  5821. (org-test-with-temp-text "* [#B] H"
  5822. (org-entry-put (point) "PRIORITY" "A")
  5823. (buffer-string))))
  5824. (should
  5825. (equal "* H"
  5826. (org-test-with-temp-text "* [#B] H"
  5827. (org-entry-put (point) "PRIORITY" nil)
  5828. (buffer-string))))
  5829. ;; Set "SCHEDULED" property.
  5830. (should
  5831. (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
  5832. (org-test-with-temp-text "* H"
  5833. (org-entry-put (point) "SCHEDULED" "2014-03-04")
  5834. (buffer-string))))
  5835. (should
  5836. (string= "* H\n"
  5837. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5838. (org-entry-put (point) "SCHEDULED" nil)
  5839. (buffer-string))))
  5840. (should
  5841. (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
  5842. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5843. (org-entry-put (point) "SCHEDULED" "earlier")
  5844. (buffer-string))))
  5845. (should
  5846. (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
  5847. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5848. (org-entry-put (point) "SCHEDULED" "later")
  5849. (buffer-string))))
  5850. ;; Set "DEADLINE" property.
  5851. (should
  5852. (string-match "^ *DEADLINE: <2014-03-04 .*?>"
  5853. (org-test-with-temp-text "* H"
  5854. (org-entry-put (point) "DEADLINE" "2014-03-04")
  5855. (buffer-string))))
  5856. (should
  5857. (string= "* H\n"
  5858. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5859. (org-entry-put (point) "DEADLINE" nil)
  5860. (buffer-string))))
  5861. (should
  5862. (string-match "^ *DEADLINE: <2014-03-03 .*?>"
  5863. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5864. (org-entry-put (point) "DEADLINE" "earlier")
  5865. (buffer-string))))
  5866. (should
  5867. (string-match "^ *DEADLINE: <2014-03-05 .*?>"
  5868. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5869. (org-entry-put (point) "DEADLINE" "later")
  5870. (buffer-string))))
  5871. ;; Set "CATEGORY" property
  5872. (should
  5873. (string-match "^ *:CATEGORY: cat"
  5874. (org-test-with-temp-text "* H"
  5875. (org-entry-put (point) "CATEGORY" "cat")
  5876. (buffer-string))))
  5877. ;; Regular properties, with or without pre-existing drawer.
  5878. (should
  5879. (string-match "^ *:A: +2$"
  5880. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5881. (org-entry-put (point) "A" "2")
  5882. (buffer-string))))
  5883. (should
  5884. (string-match "^ *:A: +1$"
  5885. (org-test-with-temp-text "* H"
  5886. (org-entry-put (point) "A" "1")
  5887. (buffer-string))))
  5888. ;; Special case: two consecutive headlines.
  5889. (should
  5890. (string-match "\\* A\n *:PROPERTIES:"
  5891. (org-test-with-temp-text "* A\n** B"
  5892. (org-entry-put (point) "A" "1")
  5893. (buffer-string)))))
  5894. (ert-deftest test-org/refresh-properties ()
  5895. "Test `org-refresh-properties' specifications."
  5896. (should
  5897. (equal "1"
  5898. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5899. (org-refresh-properties "A" 'org-test)
  5900. (get-text-property (point) 'org-test))))
  5901. (should-not
  5902. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5903. (org-refresh-properties "B" 'org-test)
  5904. (get-text-property (point) 'org-test)))
  5905. ;; Handle properties only defined with extension syntax, i.e.,
  5906. ;; "PROPERTY+".
  5907. (should
  5908. (equal "1"
  5909. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
  5910. (org-refresh-properties "A" 'org-test)
  5911. (get-text-property (point) 'org-test))))
  5912. ;; When property is inherited, add text property to the whole
  5913. ;; sub-tree.
  5914. (should
  5915. (equal "1"
  5916. (org-test-with-temp-text
  5917. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
  5918. (let ((org-use-property-inheritance t))
  5919. (org-refresh-properties "A" 'org-test))
  5920. (get-text-property (point) 'org-test))))
  5921. ;; When a document level property-drawer is used, those properties
  5922. ;; should work exactly like headline-properties as if at a
  5923. ;; headline-level 0.
  5924. (should
  5925. (equal "1"
  5926. (org-test-with-temp-text
  5927. ":PROPERTIES:\n:A: 1\n:END:\n"
  5928. (org-mode-restart)
  5929. (let ((org-use-property-inheritance t))
  5930. (org-refresh-properties "A" 'org-test))
  5931. (get-text-property (point) 'org-test))))
  5932. (should-not
  5933. (equal "1"
  5934. (org-test-with-temp-text
  5935. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  5936. (org-mode-restart)
  5937. (let ((org-use-property-inheritance nil))
  5938. (org-refresh-properties "A" 'org-test))
  5939. (get-text-property (point) 'org-test))))
  5940. (should
  5941. (equal "1"
  5942. (org-test-with-temp-text
  5943. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  5944. (org-mode-restart)
  5945. (let ((org-use-property-inheritance t))
  5946. (org-refresh-properties "A" 'org-test))
  5947. (get-text-property (point) 'org-test))))
  5948. (should
  5949. (equal "2"
  5950. (org-test-with-temp-text
  5951. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1\n:PROPERTIES:\n:A: 2\n:END:"
  5952. (org-mode-restart)
  5953. (let ((org-use-property-inheritance t))
  5954. (org-refresh-properties "A" 'org-test))
  5955. (get-text-property (point) 'org-test))))
  5956. ;; When property is inherited, use global value across the whole
  5957. ;; buffer. However local values have precedence, as well as the
  5958. ;; document level property-drawer.
  5959. (should-not
  5960. (equal "1"
  5961. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  5962. (org-mode-restart)
  5963. (let ((org-use-property-inheritance nil))
  5964. (org-refresh-properties "A" 'org-test))
  5965. (get-text-property (point) 'org-test))))
  5966. (should
  5967. (equal "1"
  5968. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  5969. (org-mode-restart)
  5970. (let ((org-use-property-inheritance t))
  5971. (org-refresh-properties "A" 'org-test))
  5972. (get-text-property (point) 'org-test))))
  5973. (should
  5974. (equal "2"
  5975. (org-test-with-temp-text
  5976. "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
  5977. (org-mode-restart)
  5978. (let ((org-use-property-inheritance t))
  5979. (org-refresh-properties "A" 'org-test))
  5980. (get-text-property (point) 'org-test))))
  5981. ;; When both keyword-property and document-level property-block is
  5982. ;; defined, the property-block has precedance.
  5983. (should
  5984. (equal "1"
  5985. (org-test-with-temp-text
  5986. ":PROPERTIES:\n:A: 1\n:END:\n#+PROPERTY: A 2\n<point>* H1"
  5987. (org-mode-restart)
  5988. (let ((org-use-property-inheritance t))
  5989. (org-refresh-properties "A" 'org-test))
  5990. (get-text-property (point) 'org-test)))))
  5991. (ert-deftest test-org/refresh-category-properties ()
  5992. "Test `org-refresh-category-properties' specifications"
  5993. (should
  5994. (equal "cat1"
  5995. (org-test-with-temp-text
  5996. ":PROPERTIES:\n:CATEGORY: cat1\n:END:"
  5997. (org-refresh-category-properties)
  5998. (get-text-property (point) 'org-category))))
  5999. (should
  6000. (equal "cat1"
  6001. (org-test-with-temp-text
  6002. "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6003. (org-refresh-category-properties)
  6004. (get-text-property (point) 'org-category))))
  6005. ;; Even though property-inheritance is deactivated, category
  6006. ;; property should be inherited. As described in
  6007. ;; `org-use-property-inheritance'.
  6008. (should
  6009. (equal "cat1"
  6010. (org-test-with-temp-text
  6011. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  6012. (org-mode-restart)
  6013. (let ((org-use-property-inheritance nil))
  6014. (org-refresh-category-properties))
  6015. (get-text-property (point) 'org-category))))
  6016. (should
  6017. (equal "cat1"
  6018. (org-test-with-temp-text
  6019. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  6020. (org-mode-restart)
  6021. (let ((org-use-property-inheritance t))
  6022. (org-refresh-category-properties))
  6023. (get-text-property (point) 'org-category))))
  6024. (should
  6025. (equal "cat2"
  6026. (org-test-with-temp-text
  6027. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H\n:PROPERTIES:\n:CATEGORY: cat2\n:END:\n"
  6028. (org-mode-restart)
  6029. (let ((org-use-property-inheritance t))
  6030. (org-refresh-category-properties))
  6031. (get-text-property (point) 'org-category)))))
  6032. ;;; Refile
  6033. (ert-deftest test-org/refile-get-targets ()
  6034. "Test `org-refile-get-targets' specifications."
  6035. ;; :maxlevel includes all headings above specified value.
  6036. (should
  6037. (equal '("H1" "H2" "H3")
  6038. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6039. (let ((org-refile-use-outline-path nil)
  6040. (org-refile-targets `((nil :maxlevel . 3))))
  6041. (mapcar #'car (org-refile-get-targets))))))
  6042. (should
  6043. (equal '("H1" "H2")
  6044. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6045. (let ((org-refile-use-outline-path nil)
  6046. (org-refile-targets `((nil :maxlevel . 2))))
  6047. (mapcar #'car (org-refile-get-targets))))))
  6048. ;; :level limits targets to headlines with the specified level.
  6049. (should
  6050. (equal '("H2")
  6051. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6052. (let ((org-refile-use-outline-path nil)
  6053. (org-refile-targets `((nil :level . 2))))
  6054. (mapcar #'car (org-refile-get-targets))))))
  6055. ;; :tag limits targets to headlines with specified tag.
  6056. (should
  6057. (equal '("H1")
  6058. (org-test-with-temp-text "* H1 :foo:\n** H2\n*** H3 :bar:"
  6059. (let ((org-refile-use-outline-path nil)
  6060. (org-refile-targets `((nil :tag . "foo"))))
  6061. (mapcar #'car (org-refile-get-targets))))))
  6062. ;; :todo limits targets to headlines with specified TODO keyword.
  6063. (should
  6064. (equal '("H2")
  6065. (org-test-with-temp-text "* H1\n** TODO H2\n*** DONE H3"
  6066. (let ((org-refile-use-outline-path nil)
  6067. (org-refile-targets `((nil :todo . "TODO"))))
  6068. (mapcar #'car (org-refile-get-targets))))))
  6069. ;; :regexp filters targets matching provided regexp.
  6070. (should
  6071. (equal '("F2" "F3")
  6072. (org-test-with-temp-text "* H1\n** F2\n*** F3"
  6073. (let ((org-refile-use-outline-path nil)
  6074. (org-refile-targets `((nil :regexp . "F"))))
  6075. (mapcar #'car (org-refile-get-targets))))))
  6076. ;; A nil `org-refile-targets' includes only top level headlines in
  6077. ;; current buffer.
  6078. (should
  6079. (equal '("H1" "H2")
  6080. (org-test-with-temp-text "* H1\n** S1\n* H2"
  6081. (let ((org-refile-use-outline-path nil)
  6082. (org-refile-targets nil))
  6083. (mapcar #'car (org-refile-get-targets))))))
  6084. ;; Return value is the union of the targets according to all the
  6085. ;; defined rules. However, prevent duplicates.
  6086. (should
  6087. (equal '("F2" "F3" "H1")
  6088. (org-test-with-temp-text "* TODO H1\n** F2\n*** F3"
  6089. (let ((org-refile-use-outline-path nil)
  6090. (org-refile-targets `((nil :regexp . "F")
  6091. (nil :todo . "TODO"))))
  6092. (mapcar #'car (org-refile-get-targets))))))
  6093. (should
  6094. (equal '("F2" "F3" "H1")
  6095. (org-test-with-temp-text "* TODO H1\n** TODO F2\n*** F3"
  6096. (let ((org-refile-use-outline-path nil)
  6097. (org-refile-targets `((nil :regexp . "F")
  6098. (nil :todo . "TODO"))))
  6099. (mapcar #'car (org-refile-get-targets))))))
  6100. ;; When `org-refile-use-outline-path' is non-nil, provide targets as
  6101. ;; paths.
  6102. (should
  6103. (equal '("H1" "H1/H2" "H1/H2/H3")
  6104. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6105. (let ((org-refile-use-outline-path t)
  6106. (org-refile-targets `((nil :maxlevel . 3))))
  6107. (mapcar #'car (org-refile-get-targets))))))
  6108. ;; When providing targets as paths, escape forward slashes in
  6109. ;; headings with backslashes.
  6110. (should
  6111. (equal '("H1\\/foo")
  6112. (org-test-with-temp-text "* H1/foo"
  6113. (let ((org-refile-use-outline-path t)
  6114. (org-refile-targets `((nil :maxlevel . 1))))
  6115. (mapcar #'car (org-refile-get-targets))))))
  6116. ;; When `org-refile-use-outline-path' is `file', include file name
  6117. ;; without directory in targets.
  6118. (should
  6119. (org-test-with-temp-text-in-file "* H1"
  6120. (let* ((filename (buffer-file-name))
  6121. (org-refile-use-outline-path 'file)
  6122. (org-refile-targets `(((,filename) :level . 1))))
  6123. (member (file-name-nondirectory filename)
  6124. (mapcar #'car (org-refile-get-targets))))))
  6125. ;; When `org-refile-use-outline-path' is `full-file-path', include
  6126. ;; full file name.
  6127. (should
  6128. (org-test-with-temp-text-in-file "* H1"
  6129. (let* ((filename (file-truename (buffer-file-name)))
  6130. (org-refile-use-outline-path 'full-file-path)
  6131. (org-refile-targets `(((,filename) :level . 1))))
  6132. (member filename (mapcar #'car (org-refile-get-targets))))))
  6133. ;; When `org-refile-use-outline-path' is `buffer-name', include
  6134. ;; buffer name.
  6135. (should
  6136. (org-test-with-temp-text "* H1"
  6137. (let* ((org-refile-use-outline-path 'buffer-name)
  6138. (org-refile-targets `((nil :level . 1))))
  6139. (member (buffer-name) (mapcar #'car (org-refile-get-targets)))))))
  6140. ;;; Sparse trees
  6141. (ert-deftest test-org/match-sparse-tree ()
  6142. "Test `org-match-sparse-tree' specifications."
  6143. ;; Match tags.
  6144. (should-not
  6145. (org-test-with-temp-text "* H\n** H1 :tag:"
  6146. (org-match-sparse-tree nil "tag")
  6147. (search-forward "H1")
  6148. (org-invisible-p2)))
  6149. (should
  6150. (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
  6151. (org-match-sparse-tree nil "tag")
  6152. (search-forward "H2")
  6153. (org-invisible-p2)))
  6154. ;; "-" operator for tags.
  6155. (should-not
  6156. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6157. (org-match-sparse-tree nil "tag1-tag2")
  6158. (search-forward "H1")
  6159. (org-invisible-p2)))
  6160. (should
  6161. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6162. (org-match-sparse-tree nil "tag1-tag2")
  6163. (search-forward "H2")
  6164. (org-invisible-p2)))
  6165. ;; "&" operator for tags.
  6166. (should
  6167. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6168. (org-match-sparse-tree nil "tag1&tag2")
  6169. (search-forward "H1")
  6170. (org-invisible-p2)))
  6171. (should-not
  6172. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6173. (org-match-sparse-tree nil "tag1&tag2")
  6174. (search-forward "H2")
  6175. (org-invisible-p2)))
  6176. ;; "|" operator for tags.
  6177. (should-not
  6178. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6179. (org-match-sparse-tree nil "tag1|tag2")
  6180. (search-forward "H1")
  6181. (org-invisible-p2)))
  6182. (should-not
  6183. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6184. (org-match-sparse-tree nil "tag1|tag2")
  6185. (search-forward "H2")
  6186. (org-invisible-p2)))
  6187. ;; Regexp match on tags.
  6188. (should-not
  6189. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6190. (org-match-sparse-tree nil "{^tag.*}")
  6191. (search-forward "H1")
  6192. (org-invisible-p2)))
  6193. (should
  6194. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6195. (org-match-sparse-tree nil "{^tag.*}")
  6196. (search-forward "H2")
  6197. (org-invisible-p2)))
  6198. ;; Match group tags.
  6199. (should-not
  6200. (org-test-with-temp-text
  6201. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6202. (org-match-sparse-tree nil "work")
  6203. (search-forward "H1")
  6204. (org-invisible-p2)))
  6205. (should-not
  6206. (org-test-with-temp-text
  6207. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6208. (org-match-sparse-tree nil "work")
  6209. (search-forward "H2")
  6210. (org-invisible-p2)))
  6211. ;; Match group tags with hard brackets.
  6212. (should-not
  6213. (org-test-with-temp-text
  6214. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6215. (org-match-sparse-tree nil "work")
  6216. (search-forward "H1")
  6217. (org-invisible-p2)))
  6218. (should-not
  6219. (org-test-with-temp-text
  6220. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6221. (org-match-sparse-tree nil "work")
  6222. (search-forward "H2")
  6223. (org-invisible-p2)))
  6224. ;; Match tags in hierarchies
  6225. (should-not
  6226. (org-test-with-temp-text
  6227. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6228. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6229. #+TAGS: { Lev_3 : Lev_4 }\n
  6230. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6231. (org-match-sparse-tree nil "Lev_1")
  6232. (search-forward "H4")
  6233. (org-invisible-p2)))
  6234. (should-not
  6235. (org-test-with-temp-text
  6236. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6237. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6238. #+TAGS: { Lev_3 : Lev_4 }\n
  6239. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6240. (org-match-sparse-tree nil "Lev_1+Lev_3")
  6241. (search-forward "H4")
  6242. (org-invisible-p2)))
  6243. ;; Match regular expressions in tags
  6244. (should-not
  6245. (org-test-with-temp-text
  6246. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
  6247. (org-match-sparse-tree nil "Lev")
  6248. (search-forward "H1")
  6249. (org-invisible-p2)))
  6250. (should
  6251. (org-test-with-temp-text
  6252. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
  6253. (org-match-sparse-tree nil "Lev")
  6254. (search-forward "H1")
  6255. (org-invisible-p2)))
  6256. ;; Match properties.
  6257. (should
  6258. (org-test-with-temp-text
  6259. "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
  6260. (org-match-sparse-tree nil "A=\"1\"")
  6261. (search-forward "H2")
  6262. (org-invisible-p2)))
  6263. (should-not
  6264. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6265. (org-match-sparse-tree nil "A=\"1\"")
  6266. (search-forward "H2")
  6267. (org-invisible-p2)))
  6268. ;; Case is not significant when matching properties.
  6269. (should-not
  6270. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6271. (org-match-sparse-tree nil "a=\"1\"")
  6272. (search-forward "H2")
  6273. (org-invisible-p2)))
  6274. (should-not
  6275. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
  6276. (org-match-sparse-tree nil "A=\"1\"")
  6277. (search-forward "H2")
  6278. (org-invisible-p2)))
  6279. ;; Match special LEVEL property.
  6280. (should-not
  6281. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6282. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6283. (search-forward "H1")
  6284. (org-invisible-p2)))
  6285. (should
  6286. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6287. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6288. (search-forward "H2")
  6289. (org-invisible-p2)))
  6290. ;; Comparison operators when matching properties.
  6291. (should
  6292. (org-test-with-temp-text
  6293. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6294. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6295. (search-forward "H1")
  6296. (org-invisible-p2)))
  6297. (should-not
  6298. (org-test-with-temp-text
  6299. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6300. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6301. (search-forward "H2")
  6302. (org-invisible-p2)))
  6303. ;; Regexp match on properties values.
  6304. (should-not
  6305. (org-test-with-temp-text
  6306. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6307. (org-match-sparse-tree nil "A={f.*}")
  6308. (search-forward "H1")
  6309. (org-invisible-p2)))
  6310. (should
  6311. (org-test-with-temp-text
  6312. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6313. (org-match-sparse-tree nil "A={f.*}")
  6314. (search-forward "H2")
  6315. (org-invisible-p2)))
  6316. ;; With an optional argument, limit match to TODO entries.
  6317. (should-not
  6318. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6319. (org-match-sparse-tree t "tag")
  6320. (search-forward "H1")
  6321. (org-invisible-p2)))
  6322. (should
  6323. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6324. (org-match-sparse-tree t "tag")
  6325. (search-forward "H2")
  6326. (org-invisible-p2))))
  6327. (ert-deftest test-org/occur ()
  6328. "Test `org-occur' specifications."
  6329. ;; Count number of matches.
  6330. (should
  6331. (= 1
  6332. (org-test-with-temp-text "* H\nA\n* H2"
  6333. (org-occur "A"))))
  6334. (should
  6335. (= 2
  6336. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6337. (org-occur "A"))))
  6338. ;; Test CALLBACK optional argument.
  6339. (should
  6340. (= 0
  6341. (org-test-with-temp-text "* H\nA\n* H2"
  6342. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6343. (should
  6344. (= 1
  6345. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6346. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6347. ;; Case-fold searches according to `org-occur-case-fold-search'.
  6348. (should
  6349. (= 2
  6350. (org-test-with-temp-text "Aa"
  6351. (let ((org-occur-case-fold-search t)) (org-occur "A")))))
  6352. (should
  6353. (= 2
  6354. (org-test-with-temp-text "Aa"
  6355. (let ((org-occur-case-fold-search t)) (org-occur "a")))))
  6356. (should
  6357. (= 1
  6358. (org-test-with-temp-text "Aa"
  6359. (let ((org-occur-case-fold-search nil)) (org-occur "A")))))
  6360. (should
  6361. (= 1
  6362. (org-test-with-temp-text "Aa"
  6363. (let ((org-occur-case-fold-search nil)) (org-occur "a")))))
  6364. (should
  6365. (= 1
  6366. (org-test-with-temp-text "Aa"
  6367. (let ((org-occur-case-fold-search 'smart)) (org-occur "A")))))
  6368. (should
  6369. (= 2
  6370. (org-test-with-temp-text "Aa"
  6371. (let ((org-occur-case-fold-search 'smart)) (org-occur "a"))))))
  6372. ;;; Tags
  6373. (ert-deftest test-org/tag-string-to-alist ()
  6374. "Test `org-tag-string-to-alist' specifications."
  6375. ;; Tag without selection key.
  6376. (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
  6377. ;; Tag with selection key.
  6378. (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t))))
  6379. ;; Tag group.
  6380. (should
  6381. (equal
  6382. (org-tag-string-to-alist "[ group : t1 t2 ]")
  6383. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag))))
  6384. ;; Mutually exclusive tags.
  6385. (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
  6386. '((:startgroup) ("tag1") ("tag2") (:endgroup))))
  6387. (should
  6388. (equal
  6389. (org-tag-string-to-alist "{ group : tag1 tag2 }")
  6390. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))))
  6391. (ert-deftest test-org/tag-alist-to-string ()
  6392. "Test `org-tag-alist-to-string' specifications."
  6393. (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
  6394. (should (equal (org-tag-alist-to-string '(("tag1" . ?t))) "tag1(t)"))
  6395. (should
  6396. (equal
  6397. (org-tag-alist-to-string
  6398. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6399. "[ group : t1 t2 ]"))
  6400. (should
  6401. (equal (org-tag-alist-to-string
  6402. '((:startgroup) ("tag1") ("tag2") (:endgroup)))
  6403. "{ tag1 tag2 }"))
  6404. (should
  6405. (equal
  6406. (org-tag-alist-to-string
  6407. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))
  6408. "{ group : tag1 tag2 }")))
  6409. (ert-deftest test-org/tag-alist-to-groups ()
  6410. "Test `org-tag-alist-to-groups' specifications."
  6411. (should
  6412. (equal (org-tag-alist-to-groups
  6413. '((:startgroup) ("group") (:grouptags) ("t1") ("t2") (:endgroup)))
  6414. '(("group" "t1" "t2"))))
  6415. (should
  6416. (equal
  6417. (org-tag-alist-to-groups
  6418. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6419. '(("group" "t1" "t2"))))
  6420. (should-not
  6421. (org-tag-alist-to-groups
  6422. '((:startgroup) ("group") ("t1") ("t2") (:endgroup)))))
  6423. (ert-deftest test-org/tag-align ()
  6424. "Test tags alignment."
  6425. ;; Test aligning tags with different display width.
  6426. (should
  6427. ;; 12345678901234567890
  6428. (equal "* Test :abc:"
  6429. (org-test-with-temp-text "* Test :abc:"
  6430. (let ((org-tags-column -20)
  6431. (indent-tabs-mode nil))
  6432. (org-fix-tags-on-the-fly))
  6433. (buffer-string))))
  6434. (should
  6435. ;; 12345678901234567890
  6436. (equal "* Test :日本語:"
  6437. (org-test-with-temp-text "* Test :日本語:"
  6438. (let ((org-tags-column -20)
  6439. (indent-tabs-mode nil))
  6440. (org-fix-tags-on-the-fly))
  6441. (buffer-string))))
  6442. ;; Make sure aligning tags do not skip invisible text.
  6443. (should
  6444. (equal "* [[linkx]] :tag:"
  6445. (org-test-with-temp-text "* [[link<point>]] :tag:"
  6446. (let ((org-tags-column 0))
  6447. (org-fix-tags-on-the-fly)
  6448. (insert "x")
  6449. (buffer-string)))))
  6450. ;; Aligning tags preserve position.
  6451. (should
  6452. (= 6 (org-test-with-temp-text "* 345 <point> :tag:"
  6453. (let ((org-tags-column 78)
  6454. (indent-tabs-mode nil))
  6455. (org-fix-tags-on-the-fly))
  6456. (current-column))))
  6457. ;; Aligning all tags in visible buffer.
  6458. (should
  6459. ;; 12345678901234567890
  6460. (equal (concat "* Level 1 :abc:\n"
  6461. "** Level 2 :def:")
  6462. (org-test-with-temp-text (concat "* Level 1 :abc:\n"
  6463. "** Level 2 :def:")
  6464. (let ((org-tags-column -20)
  6465. (indent-tabs-mode nil))
  6466. ;; (org-align-tags :all) must work even when the point
  6467. ;; is at the end of the buffer.
  6468. (goto-char (point-max))
  6469. (org-align-tags :all))
  6470. (buffer-string)))))
  6471. (ert-deftest test-org/get-tags ()
  6472. "Test `org-get-tags' specifications."
  6473. ;; Standard test.
  6474. (should
  6475. (equal '("foo")
  6476. (org-test-with-temp-text "* Test :foo:" (org-get-tags))))
  6477. (should
  6478. (equal '("foo" "bar")
  6479. (org-test-with-temp-text "* Test :foo:bar:" (org-get-tags))))
  6480. ;; Return nil when there is no tag.
  6481. (should-not
  6482. (org-test-with-temp-text "* Test" (org-get-tags)))
  6483. ;; Tags are inherited from parent headlines.
  6484. (should
  6485. (equal '("tag")
  6486. (let ((org-use-tag-inheritance t))
  6487. (org-test-with-temp-text "* H0 :foo:\n* H1 :tag:\n<point>** H2"
  6488. (org-get-tags)))))
  6489. ;; Tags are inherited from `org-file-tags'.
  6490. (should
  6491. (equal '("tag")
  6492. (org-test-with-temp-text "* H1"
  6493. (let ((org-file-tags '("tag"))
  6494. (org-use-tag-inheritance t))
  6495. (org-get-tags)))))
  6496. ;; Only inherited tags have the `inherited' text property.
  6497. (should
  6498. (get-text-property 0 'inherited
  6499. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6500. (let ((org-use-tag-inheritance t))
  6501. (assoc-string "foo" (org-get-tags))))))
  6502. (should-not
  6503. (get-text-property 0 'inherited
  6504. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6505. (let ((org-use-tag-inheritance t))
  6506. (assoc-string "bar" (org-get-tags))))))
  6507. ;; Obey to `org-use-tag-inheritance'.
  6508. (should-not
  6509. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6510. (let ((org-use-tag-inheritance nil))
  6511. (assoc-string "foo" (org-get-tags)))))
  6512. (should-not
  6513. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6514. (let ((org-use-tag-inheritance nil)
  6515. (org-file-tags '("foo")))
  6516. (assoc-string "foo" (org-get-tags)))))
  6517. (should-not
  6518. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6519. (let ((org-use-tag-inheritance '("bar")))
  6520. (assoc-string "foo" (org-get-tags)))))
  6521. (should
  6522. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6523. (let ((org-use-tag-inheritance '("bar")))
  6524. (assoc-string "bar" (org-get-tags)))))
  6525. (should-not
  6526. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6527. (let ((org-use-tag-inheritance "b.*"))
  6528. (assoc-string "foo" (org-get-tags)))))
  6529. (should
  6530. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6531. (let ((org-use-tag-inheritance "b.*"))
  6532. (assoc-string "bar" (org-get-tags)))))
  6533. ;; When optional argument LOCAL is non-nil, ignore tag inheritance.
  6534. (should
  6535. (equal '("baz")
  6536. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6537. (let ((org-use-tag-inheritance t))
  6538. (org-get-tags nil t)))))
  6539. ;; When optional argument POS is non-nil, get tags there instead.
  6540. (should
  6541. (equal '("foo")
  6542. (org-test-with-temp-text "* H1 :foo:\n* <point>H2 :bar:"
  6543. (org-get-tags 1))))
  6544. ;; Make sure tags excluded from inheritance are returned if local
  6545. (should
  6546. (equal '("foo")
  6547. (org-test-with-temp-text "* Test :foo:"
  6548. (let ((org-use-tag-inheritance t)
  6549. (org-tags-exclude-from-inheritance '("foo")))
  6550. (org-get-tags)))))
  6551. ;; Test the collection of tags from #+filetags and parent tags.
  6552. (should
  6553. (equal '("a" "b" "c" "d")
  6554. (org-test-with-temp-text (concat "#+filetags: a\n"
  6555. "* Level 1 :b:\n"
  6556. "** Level 2 :c:\n"
  6557. "*** Level 3 :d:\n"
  6558. "<point>")
  6559. (let ((org-use-tag-inheritance t))
  6560. (org-mode-restart) ;So that `org-file-tags' get populated from #+filetags
  6561. (org-get-tags)))))
  6562. ;; Pathological case: tagged headline with an empty body.
  6563. (should (org-test-with-temp-text "* :tag:" (org-get-tags))))
  6564. (ert-deftest test-org/set-tags ()
  6565. "Test `org-set-tags' specifications."
  6566. ;; Throw an error on invalid data.
  6567. (should-error
  6568. (org-test-with-temp-text "* H"
  6569. (org-set-tags 'foo)))
  6570. ;; `nil', an empty, and a blank string remove all tags.
  6571. (should
  6572. (equal "* H"
  6573. (org-test-with-temp-text "* H :tag1:tag2:"
  6574. (org-set-tags nil)
  6575. (buffer-string))))
  6576. (should
  6577. (equal "* H"
  6578. (org-test-with-temp-text "* H :tag1:tag2:"
  6579. (org-set-tags "")
  6580. (buffer-string))))
  6581. (should
  6582. (equal "* H"
  6583. (org-test-with-temp-text "* H :tag1:tag2:"
  6584. (org-set-tags " ")
  6585. (buffer-string))))
  6586. ;; If there's nothing to remove, just bail out.
  6587. (should
  6588. (equal "* H"
  6589. (org-test-with-temp-text "* H"
  6590. (org-set-tags nil)
  6591. (buffer-string))))
  6592. (should
  6593. (equal "* "
  6594. (org-test-with-temp-text "* "
  6595. (org-set-tags nil)
  6596. (buffer-string))))
  6597. ;; If DATA is a tag string, set current tags to it, even if it means
  6598. ;; replacing old tags.
  6599. (should
  6600. (equal "* H :tag0:"
  6601. (org-test-with-temp-text "* H :tag1:tag2:"
  6602. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  6603. (buffer-string))))
  6604. (should
  6605. (equal "* H :tag0:"
  6606. (org-test-with-temp-text "* H"
  6607. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  6608. (buffer-string))))
  6609. ;; If DATA is a list, set tags to this list, even if it means
  6610. ;; replacing old tags.
  6611. (should
  6612. (equal "* H :tag0:"
  6613. (org-test-with-temp-text "* H :tag1:tag2:"
  6614. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6615. (buffer-string))))
  6616. (should
  6617. (equal "* H :tag0:"
  6618. (org-test-with-temp-text "* H"
  6619. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6620. (buffer-string))))
  6621. ;; When set, apply `org-tags-sort-function'.
  6622. (should
  6623. (equal "* H :a:b:"
  6624. (org-test-with-temp-text "* H"
  6625. (let ((org-tags-column 1)
  6626. (org-tags-sort-function #'string<))
  6627. (org-set-tags '("b" "a"))
  6628. (buffer-string)))))
  6629. ;; When new tags are identical to the previous ones, still align.
  6630. (should
  6631. (equal "* H :foo:"
  6632. (org-test-with-temp-text "* H :foo:"
  6633. (let ((org-tags-column 1))
  6634. (org-set-tags '("foo"))
  6635. (buffer-string)))))
  6636. ;; When tags have been changed, run `org-after-tags-change-hook'.
  6637. (should
  6638. (catch :return
  6639. (org-test-with-temp-text "* H :foo:"
  6640. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  6641. (org-set-tags '("bar"))
  6642. nil))))
  6643. (should-not
  6644. (catch :return
  6645. (org-test-with-temp-text "* H :foo:"
  6646. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  6647. (org-set-tags '("foo"))
  6648. nil))))
  6649. ;; Special case: handle empty headlines.
  6650. (should
  6651. (equal "* :tag0:"
  6652. (org-test-with-temp-text "* "
  6653. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6654. (buffer-string))))
  6655. ;; Modify buffer only when a tag change happens or alignment is
  6656. ;; done.
  6657. (should-not
  6658. (org-test-with-temp-text "* H :foo:"
  6659. (set-buffer-modified-p nil)
  6660. (let ((org-tags-column 1)) (org-set-tags '("foo")))
  6661. (buffer-modified-p)))
  6662. (should
  6663. (org-test-with-temp-text "* H :foo:"
  6664. (set-buffer-modified-p nil)
  6665. (let ((org-tags-column 10)) (org-set-tags '("foo")))
  6666. (buffer-modified-p)))
  6667. (should
  6668. (org-test-with-temp-text "* H :foo:"
  6669. (set-buffer-modified-p nil)
  6670. (let ((org-tags-column 10)) (org-set-tags '("bar")))
  6671. (buffer-modified-p)))
  6672. ;; Pathological case: when setting tags of a folded headline, do not
  6673. ;; let new tags being sucked into invisibility.
  6674. (should-not
  6675. (org-test-with-temp-text "* H1\nContent\n* H2\n\n Other Content"
  6676. ;; Show only headlines
  6677. (org-content)
  6678. ;; Set NEXT tag on current entry
  6679. (org-set-tags ":NEXT:")
  6680. ;; Move point to that NEXT tag
  6681. (search-forward "NEXT") (backward-word)
  6682. ;; And it should be visible (i.e. no overlays)
  6683. (overlays-at (point)))))
  6684. (ert-deftest test-org/set-tags-command ()
  6685. "Test `org-set-tags-command' specifications"
  6686. ;; Set tags at current headline.
  6687. (should
  6688. (equal "* H1 :foo:"
  6689. (org-test-with-temp-text "* H1"
  6690. (cl-letf (((symbol-function 'completing-read)
  6691. (lambda (&rest args) ":foo:")))
  6692. (let ((org-use-fast-tag-selection nil)
  6693. (org-tags-column 1))
  6694. (org-set-tags-command)))
  6695. (buffer-string))))
  6696. ;; Preserve position when called from the section below.
  6697. (should
  6698. (equal "* H1 :foo:\nContents"
  6699. (org-test-with-temp-text "* H1\n<point>Contents"
  6700. (cl-letf (((symbol-function 'completing-read)
  6701. (lambda (&rest args) ":foo:")))
  6702. (let ((org-use-fast-tag-selection nil)
  6703. (org-tags-column 1))
  6704. (org-set-tags-command)))
  6705. (buffer-string))))
  6706. (should-not
  6707. (equal "* H1 :foo:\nContents2"
  6708. (org-test-with-temp-text "* H1\n<point>Contents2"
  6709. (cl-letf (((symbol-function 'completing-read)
  6710. (lambda (&rest args) ":foo:")))
  6711. (let ((org-use-fast-tag-selection nil)
  6712. (org-tags-column 1))
  6713. (org-set-tags-command)))
  6714. (org-at-heading-p))))
  6715. ;; Strip all forbidden characters from user-entered tags.
  6716. (should
  6717. (equal "* H1 :foo:"
  6718. (org-test-with-temp-text "* H1"
  6719. (cl-letf (((symbol-function 'completing-read)
  6720. (lambda (&rest args) ": foo *:")))
  6721. (let ((org-use-fast-tag-selection nil)
  6722. (org-tags-column 1))
  6723. (org-set-tags-command)))
  6724. (buffer-string))))
  6725. ;; When a region is active and
  6726. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  6727. ;; same value in all headlines in region.
  6728. (should
  6729. (equal "* H1 :foo:\nContents\n* H2 :foo:"
  6730. (org-test-with-temp-text "* H1\nContents\n* H2"
  6731. (cl-letf (((symbol-function 'completing-read)
  6732. (lambda (&rest args) ":foo:")))
  6733. (let ((org-use-fast-tag-selection nil)
  6734. (org-loop-over-headlines-in-active-region t)
  6735. (org-tags-column 1))
  6736. (transient-mark-mode 1)
  6737. (push-mark (point) t t)
  6738. (goto-char (point-max))
  6739. (org-set-tags-command)))
  6740. (buffer-string))))
  6741. (should
  6742. (equal "* H1\nContents\n* H2 :foo:"
  6743. (org-test-with-temp-text "* H1\nContents\n* H2"
  6744. (cl-letf (((symbol-function 'completing-read)
  6745. (lambda (&rest args) ":foo:")))
  6746. (let ((org-use-fast-tag-selection nil)
  6747. (org-loop-over-headlines-in-active-region nil)
  6748. (org-tags-column 1))
  6749. (transient-mark-mode 1)
  6750. (push-mark (point) t t)
  6751. (goto-char (point-max))
  6752. (org-set-tags-command)))
  6753. (buffer-string))))
  6754. ;; With a C-u prefix argument, align all tags in the buffer.
  6755. (should
  6756. (equal "* H1 :foo:\n* H2 :bar:"
  6757. (org-test-with-temp-text "* H1 :foo:\n* H2 :bar:"
  6758. (let ((org-tags-column 1)) (org-set-tags-command '(4)))
  6759. (buffer-string))))
  6760. ;; Point does not move with empty headline.
  6761. (should
  6762. (equal ":foo:"
  6763. (org-test-with-temp-text "* <point>"
  6764. (cl-letf (((symbol-function 'completing-read)
  6765. (lambda (&rest args) ":foo:")))
  6766. (let ((org-use-fast-tag-selection nil)
  6767. (org-tags-column 1))
  6768. (org-set-tags-command)))
  6769. (buffer-substring (point) (line-end-position)))))
  6770. ;; Point does not move at start of line.
  6771. (should
  6772. (equal "* H1 :foo:"
  6773. (org-test-with-temp-text "* H1"
  6774. (cl-letf (((symbol-function 'completing-read)
  6775. (lambda (&rest args) ":foo:")))
  6776. (let ((org-use-fast-tag-selection nil)
  6777. (org-tags-column 1))
  6778. (org-set-tags-command)))
  6779. (buffer-substring (point) (line-end-position)))))
  6780. ;; Point does not move when within *'s.
  6781. (should
  6782. (equal "* H1 :foo:"
  6783. (org-test-with-temp-text "*<point>* H1"
  6784. (cl-letf (((symbol-function 'completing-read)
  6785. (lambda (&rest args) ":foo:")))
  6786. (let ((org-use-fast-tag-selection nil)
  6787. (org-tags-column 1))
  6788. (org-set-tags-command)))
  6789. (buffer-substring (point) (line-end-position)))))
  6790. ;; Point workaround does not get fooled when looking at a space.
  6791. (should
  6792. (equal " b :foo:"
  6793. (org-test-with-temp-text "* a<point> b"
  6794. (cl-letf (((symbol-function 'completing-read)
  6795. (lambda (&rest args) ":foo:")))
  6796. (let ((org-use-fast-tag-selection nil)
  6797. (org-tags-column 1))
  6798. (org-set-tags-command)))
  6799. (buffer-substring (point) (line-end-position)))))
  6800. ;; Handle tags both set locally and inherited.
  6801. (should
  6802. (equal "b :foo:"
  6803. (org-test-with-temp-text "* a :foo:\n** <point>b :foo:"
  6804. (cl-letf (((symbol-function 'completing-read)
  6805. (lambda (prompt coll &optional pred req initial &rest args)
  6806. initial)))
  6807. (let ((org-use-fast-tag-selection nil)
  6808. (org-tags-column 1))
  6809. (org-set-tags-command)))
  6810. (buffer-substring (point) (line-end-position))))))
  6811. (ert-deftest test-org/toggle-tag ()
  6812. "Test `org-toggle-tag' specifications."
  6813. ;; Insert missing tag.
  6814. (should
  6815. (equal "* H :tag:"
  6816. (org-test-with-temp-text "* H"
  6817. (let ((org-tags-column 1)) (org-toggle-tag "tag"))
  6818. (buffer-string))))
  6819. (should
  6820. (equal "* H :tag1:tag2:"
  6821. (org-test-with-temp-text "* H :tag1:"
  6822. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  6823. (buffer-string))))
  6824. ;; Remove existing tag.
  6825. (should
  6826. (equal "* H"
  6827. (org-test-with-temp-text "* H :tag:"
  6828. (org-toggle-tag "tag")
  6829. (buffer-string))))
  6830. (should
  6831. (equal "* H :tag1:"
  6832. (org-test-with-temp-text "* H :tag1:tag2:"
  6833. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  6834. (buffer-string))))
  6835. (should
  6836. (equal "* H :tag2:"
  6837. (org-test-with-temp-text "* H :tag1:tag2:"
  6838. (let ((org-tags-column 1)) (org-toggle-tag "tag1"))
  6839. (buffer-string))))
  6840. ;; With optional argument ONOFF set to `on', try to insert the tag,
  6841. ;; even if its already there.
  6842. (should
  6843. (equal "* H :tag:"
  6844. (org-test-with-temp-text "* H"
  6845. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  6846. (buffer-string))))
  6847. (should
  6848. (equal "* H :tag:"
  6849. (org-test-with-temp-text "* H :tag:"
  6850. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  6851. (buffer-string))))
  6852. ;; With optional argument ONOFF set to `off', try to remove the tag,
  6853. ;; even if its not there.
  6854. (should
  6855. (equal "* H"
  6856. (org-test-with-temp-text "* H :tag:"
  6857. (org-toggle-tag "tag" 'off)
  6858. (buffer-string))))
  6859. (should
  6860. (equal "* H :tag:"
  6861. (org-test-with-temp-text "* H :tag:"
  6862. (let ((org-tags-column 1)) (org-toggle-tag "foo" 'off))
  6863. (buffer-string))))
  6864. ;; Special case: Handle properly tag inheritance. In particular, do
  6865. ;; not set inherited tags.
  6866. (should
  6867. (equal "* H1 :tag:\n** H2 :tag2:tag:"
  6868. (org-test-with-temp-text "* H1 :tag:\n** <point>H2 :tag2:"
  6869. (let ((org-use-tag-inheritance t)
  6870. (org-tags-column 1))
  6871. (org-toggle-tag "tag"))
  6872. (buffer-string))))
  6873. (should
  6874. (equal "* H1 :tag1:tag2:\n** H2 :foo:"
  6875. (org-test-with-temp-text "* H1 :tag1:tag2:\n** <point>H2"
  6876. (let ((org-use-tag-inheritance t)
  6877. (org-tags-column 1))
  6878. (org-toggle-tag "foo"))
  6879. (buffer-string)))))
  6880. (ert-deftest test-org/tags-expand ()
  6881. "Test `org-tags-expand' specifications."
  6882. ;; Expand tag groups as a regexp enclosed within curly brackets.
  6883. (should
  6884. (equal "{\\<[ABC]\\>}"
  6885. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6886. (org-mode-restart)
  6887. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  6888. (should
  6889. (equal "{\\<\\(?:Aa\\|Bb\\|Cc\\)\\>}"
  6890. (org-test-with-temp-text "#+TAGS: [ Aa : Bb Cc ]"
  6891. (org-mode-restart)
  6892. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "Aa")))))
  6893. ;; Preserve operator before the regexp.
  6894. (should
  6895. (equal "+{\\<[ABC]\\>}"
  6896. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6897. (org-mode-restart)
  6898. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "+A")))))
  6899. (should
  6900. (equal "-{\\<[ABC]\\>}"
  6901. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6902. (org-mode-restart)
  6903. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "-A")))))
  6904. ;; Handle "|" syntax.
  6905. (should
  6906. (equal "{\\<[ABC]\\>}|D"
  6907. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6908. (org-mode-restart)
  6909. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|D")))))
  6910. ;; Handle nested groups.
  6911. (should
  6912. (equal "{\\<[A-D]\\>}"
  6913. (org-test-with-temp-text "#+TAGS: [ A : B C ]\n#+TAGS: [ B : D ]"
  6914. (org-mode-restart)
  6915. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  6916. ;; Expand multiple occurrences of the same group.
  6917. (should
  6918. (equal "{\\<[ABC]\\>}|{\\<[ABC]\\>}"
  6919. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6920. (org-mode-restart)
  6921. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|A")))))
  6922. ;; Preserve regexp matches.
  6923. (should
  6924. (equal "{A+}"
  6925. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6926. (org-mode-restart)
  6927. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "{A+}"))))))
  6928. ;;; TODO keywords
  6929. (ert-deftest test-org/auto-repeat-maybe ()
  6930. "Test `org-auto-repeat-maybe' specifications."
  6931. ;; Do not auto repeat when there is no valid time stamp with
  6932. ;; a repeater in the entry.
  6933. (should-not
  6934. (string-prefix-p
  6935. "* TODO H"
  6936. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6937. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
  6938. (org-todo "DONE")
  6939. (buffer-string)))))
  6940. (should-not
  6941. (string-prefix-p
  6942. "* TODO H"
  6943. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6944. (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
  6945. (org-todo "DONE")
  6946. (buffer-string)))))
  6947. ;; When switching to DONE state, switch back to first TODO keyword
  6948. ;; in sequence, or the same keyword if they have different types.
  6949. (should
  6950. (string-prefix-p
  6951. "* TODO H"
  6952. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6953. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  6954. (org-todo "DONE")
  6955. (buffer-string)))))
  6956. (should
  6957. (string-prefix-p
  6958. "* KWD1 H"
  6959. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  6960. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  6961. (org-todo "DONE")
  6962. (buffer-string)))))
  6963. (should
  6964. (string-prefix-p
  6965. "* KWD2 H"
  6966. (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
  6967. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  6968. (org-todo "DONE")
  6969. (buffer-string)))))
  6970. ;; If there was no TODO keyword in the first place, do not insert
  6971. ;; any either.
  6972. (should
  6973. (string-prefix-p
  6974. "* H"
  6975. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6976. (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
  6977. (org-todo "DONE")
  6978. (buffer-string)))))
  6979. ;; Revert to REPEAT_TO_STATE, if set.
  6980. (should
  6981. (string-prefix-p
  6982. "* KWD2 H"
  6983. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  6984. (org-test-with-temp-text
  6985. "* KWD2 H
  6986. :PROPERTIES:
  6987. :REPEAT_TO_STATE: KWD2
  6988. :END:
  6989. <2012-03-29 Thu +2y>"
  6990. (org-todo "DONE")
  6991. (buffer-string)))))
  6992. ;; When switching to DONE state, update base date. If there are
  6993. ;; multiple repeated time stamps, update them all.
  6994. (should
  6995. (string-match-p
  6996. "<2014-03-29 .* \\+2y>"
  6997. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6998. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  6999. (org-todo "DONE")
  7000. (buffer-string)))))
  7001. (should
  7002. (string-match-p
  7003. "<2015-03-04 .* \\+1y>"
  7004. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7005. (org-test-with-temp-text
  7006. "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
  7007. (org-todo "DONE")
  7008. (buffer-string)))))
  7009. ;; Throw an error if repeater unit is the hour and no time is
  7010. ;; provided in the time-stamp.
  7011. (should-error
  7012. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7013. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
  7014. (org-todo "DONE")
  7015. (buffer-string))))
  7016. ;; Handle every repeater type using hours step.
  7017. (should
  7018. (string-match-p
  7019. "2014-03-04 .* 02:00"
  7020. (org-test-at-time "<2014-03-04 02:35>"
  7021. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 +8h>"
  7022. (org-todo "DONE")
  7023. (buffer-string)))))
  7024. (should
  7025. (string-match-p
  7026. "2014-03-04 .* 10:00"
  7027. (org-test-at-time "<2014-03-04 02:35>"
  7028. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 ++8h>"
  7029. (org-todo "DONE")
  7030. (buffer-string)))))
  7031. (should
  7032. (string-match-p
  7033. "2014-03-04 .* 10:35"
  7034. (org-test-at-time "<2014-03-04 02:35>"
  7035. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 .+8h>"
  7036. (org-todo "DONE")
  7037. (buffer-string)))))
  7038. ;; Do not repeat inactive time stamps with a repeater.
  7039. (should-not
  7040. (string-match-p
  7041. "\\[2014-03-29 .* \\+2y\\]"
  7042. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7043. (org-test-with-temp-text
  7044. "* TODO H\n[2012-03-29 Thu. +2y]"
  7045. (org-todo "DONE")
  7046. (buffer-string)))))
  7047. ;; Do not repeat commented time stamps.
  7048. (should-not
  7049. (string-prefix-p
  7050. "<2015-03-04 .* \\+1y>"
  7051. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7052. (org-test-with-temp-text
  7053. "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
  7054. (org-todo "DONE")
  7055. (buffer-string)))))
  7056. (should-not
  7057. (string-prefix-p
  7058. "<2015-03-04 .* \\+1y>"
  7059. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7060. (org-test-with-temp-text
  7061. "* TODO H
  7062. <2012-03-29 Thu. +2y>
  7063. #+BEGIN_EXAMPLE
  7064. <2014-03-04 Tue +1y>
  7065. #+END_EXAMPLE"
  7066. (org-todo "DONE")
  7067. (buffer-string)))))
  7068. ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
  7069. ;; entry, record time of last repeat.
  7070. (should-not
  7071. (string-match-p
  7072. ":LAST_REPEAT:"
  7073. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  7074. (org-log-repeat nil))
  7075. (cl-letf (((symbol-function 'org-add-log-setup)
  7076. (lambda (&rest args) nil)))
  7077. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  7078. (org-todo "DONE")
  7079. (buffer-string))))))
  7080. (should
  7081. (string-match-p
  7082. ":LAST_REPEAT:"
  7083. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  7084. (org-log-repeat t))
  7085. (cl-letf (((symbol-function 'org-add-log-setup)
  7086. (lambda (&rest args) nil)))
  7087. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  7088. (org-todo "DONE")
  7089. (buffer-string))))))
  7090. (should
  7091. (string-match-p
  7092. ":LAST_REPEAT:"
  7093. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7094. (cl-letf (((symbol-function 'org-add-log-setup)
  7095. (lambda (&rest args) nil)))
  7096. (org-test-with-temp-text
  7097. "* TODO H\n<2012-03-29 Thu +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
  7098. (org-todo "DONE")
  7099. (buffer-string))))))
  7100. ;; When a SCHEDULED entry has no repeater, remove it upon repeating
  7101. ;; the entry as it is no longer relevant.
  7102. (should-not
  7103. (string-match-p
  7104. "^SCHEDULED:"
  7105. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7106. (org-test-with-temp-text
  7107. "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
  7108. (org-todo "DONE")
  7109. (buffer-string)))))
  7110. ;; Properly advance repeater even when a clock entry is specified
  7111. ;; and `org-log-repeat' is nil.
  7112. (should
  7113. (string-match-p
  7114. "SCHEDULED: <2014-03-29"
  7115. (let ((org-log-repeat nil)
  7116. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7117. (org-test-with-temp-text
  7118. "* TODO H
  7119. SCHEDULED: <2012-03-29 Thu +2y>
  7120. CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] => 6:40"
  7121. (org-todo "DONE")
  7122. (buffer-string))))))
  7123. ;;; Timestamps API
  7124. (ert-deftest test-org/at-timestamp-p ()
  7125. "Test `org-at-timestamp-p' specifications."
  7126. (should
  7127. (org-test-with-temp-text "<2012-03-29 Thu>"
  7128. (org-at-timestamp-p)))
  7129. (should-not
  7130. (org-test-with-temp-text "2012-03-29 Thu"
  7131. (org-at-timestamp-p)))
  7132. ;; Test return values.
  7133. (should
  7134. (eq 'bracket
  7135. (org-test-with-temp-text "<2012-03-29 Thu>"
  7136. (org-at-timestamp-p))))
  7137. (should
  7138. (eq 'year
  7139. (org-test-with-temp-text "<<point>2012-03-29 Thu>"
  7140. (org-at-timestamp-p))))
  7141. (should
  7142. (eq 'month
  7143. (org-test-with-temp-text "<2012-<point>03-29 Thu>"
  7144. (org-at-timestamp-p))))
  7145. (should
  7146. (eq 'day
  7147. (org-test-with-temp-text "<2012-03-<point>29 Thu>"
  7148. (org-at-timestamp-p))))
  7149. (should
  7150. (eq 'day
  7151. (org-test-with-temp-text "<2012-03-29 T<point>hu>"
  7152. (org-at-timestamp-p))))
  7153. (should
  7154. (wholenump
  7155. (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
  7156. (org-at-timestamp-p))))
  7157. (should
  7158. (eq 'bracket
  7159. (org-test-with-temp-text "<2012-03-29 Thu<point>>"
  7160. (org-at-timestamp-p))))
  7161. (should
  7162. (eq 'after
  7163. (org-test-with-temp-text "<2012-03-29 Thu><point>»"
  7164. (org-at-timestamp-p))))
  7165. ;; Test `inactive' optional argument.
  7166. (should
  7167. (org-test-with-temp-text "[2012-03-29 Thu]"
  7168. (org-at-timestamp-p 'inactive)))
  7169. (should-not
  7170. (org-test-with-temp-text "[2012-03-29 Thu]"
  7171. (org-at-timestamp-p)))
  7172. ;; When optional argument is `agenda', recognize time-stamps in
  7173. ;; planning info line, property drawers and clocks.
  7174. (should
  7175. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7176. (org-at-timestamp-p 'agenda)))
  7177. (should-not
  7178. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7179. (org-at-timestamp-p)))
  7180. (should
  7181. (org-test-with-temp-text
  7182. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7183. (org-at-timestamp-p 'agenda)))
  7184. (should-not
  7185. (org-test-with-temp-text
  7186. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7187. (org-at-timestamp-p)))
  7188. (should
  7189. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7190. (let ((org-agenda-include-inactive-timestamps t))
  7191. (org-at-timestamp-p 'agenda))))
  7192. (should-not
  7193. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7194. (let ((org-agenda-include-inactive-timestamps t))
  7195. (org-at-timestamp-p))))
  7196. (should-not
  7197. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7198. (let ((org-agenda-include-inactive-timestamps t))
  7199. (org-at-timestamp-p 'inactive))))
  7200. ;; When optional argument is `lax', match any part of the document
  7201. ;; with Org timestamp syntax.
  7202. (should
  7203. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7204. (org-at-timestamp-p 'lax)))
  7205. (should-not
  7206. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7207. (org-at-timestamp-p)))
  7208. (should
  7209. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7210. (org-at-timestamp-p 'lax)))
  7211. (should-not
  7212. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7213. (org-at-timestamp-p)))
  7214. (should
  7215. (org-test-with-temp-text
  7216. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7217. (org-at-timestamp-p 'lax)))
  7218. (should-not
  7219. (org-test-with-temp-text
  7220. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7221. (org-at-timestamp-p)))
  7222. ;; Optional argument `lax' also matches inactive timestamps.
  7223. (should
  7224. (org-test-with-temp-text "# [2012-03-29 Thu]<point>"
  7225. (org-at-timestamp-p 'lax))))
  7226. (ert-deftest test-org/time-stamp ()
  7227. "Test `org-time-stamp' specifications."
  7228. ;; Insert chosen time stamp at point.
  7229. (should
  7230. (string-match
  7231. "Te<2014-03-04 .*?>xt"
  7232. (org-test-with-temp-text "Te<point>xt"
  7233. (cl-letf (((symbol-function 'org-read-date)
  7234. (lambda (&rest args)
  7235. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7236. (org-time-stamp nil)
  7237. (buffer-string)))))
  7238. ;; With a prefix argument, also insert time.
  7239. (should
  7240. (string-match
  7241. "Te<2014-03-04 .*? 00:41>xt"
  7242. (org-test-with-temp-text "Te<point>xt"
  7243. (cl-letf (((symbol-function 'org-read-date)
  7244. (lambda (&rest args)
  7245. (apply #'encode-time
  7246. (org-parse-time-string "2014-03-04 00:41")))))
  7247. (org-time-stamp '(4))
  7248. (buffer-string)))))
  7249. ;; With two universal prefix arguments, insert an active timestamp
  7250. ;; with the current time without prompting the user.
  7251. (should
  7252. (string-match
  7253. "Te<2014-03-04 .*? 00:41>xt"
  7254. (org-test-with-temp-text "Te<point>xt"
  7255. (org-test-at-time "2014-03-04 00:41"
  7256. (org-time-stamp '(16))
  7257. (buffer-string)))))
  7258. ;; When optional argument is non-nil, insert an inactive timestamp.
  7259. (should
  7260. (string-match
  7261. "Te\\[2014-03-04 .*?\\]xt"
  7262. (org-test-with-temp-text "Te<point>xt"
  7263. (cl-letf (((symbol-function 'org-read-date)
  7264. (lambda (&rest args)
  7265. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7266. (org-time-stamp nil t)
  7267. (buffer-string)))))
  7268. ;; When called from a timestamp, replace existing one.
  7269. (should
  7270. (string-match
  7271. "<2014-03-04 .*?>"
  7272. (org-test-with-temp-text "<2012-03-29<point> thu.>"
  7273. (cl-letf (((symbol-function 'org-read-date)
  7274. (lambda (&rest args)
  7275. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7276. (org-time-stamp nil)
  7277. (buffer-string)))))
  7278. (should
  7279. (string-match
  7280. "<2014-03-04 .*?>--<2014-03-04 .*?>"
  7281. (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
  7282. (cl-letf (((symbol-function 'org-read-date)
  7283. (lambda (&rest args)
  7284. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7285. (org-time-stamp nil)
  7286. (buffer-string)))))
  7287. ;; When replacing a timestamp, preserve repeater, if any.
  7288. (should
  7289. (string-match
  7290. "<2014-03-04 .*? \\+2y>"
  7291. (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
  7292. (cl-letf (((symbol-function 'org-read-date)
  7293. (lambda (&rest args)
  7294. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7295. (org-time-stamp nil)
  7296. (buffer-string)))))
  7297. ;; When called twice in a raw, build a date range.
  7298. (should
  7299. (string-match
  7300. "<2012-03-29 .*?>--<2014-03-04 .*?>"
  7301. (org-test-with-temp-text "<2012-03-29 thu.><point>"
  7302. (cl-letf (((symbol-function 'org-read-date)
  7303. (lambda (&rest args)
  7304. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7305. (let ((last-command 'org-time-stamp)
  7306. (this-command 'org-time-stamp))
  7307. (org-time-stamp nil))
  7308. (buffer-string))))))
  7309. (ert-deftest test-org/timestamp-has-time-p ()
  7310. "Test `org-timestamp-has-time-p' specifications."
  7311. ;; With time.
  7312. (should
  7313. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7314. (org-timestamp-has-time-p (org-element-context))))
  7315. ;; Without time.
  7316. (should-not
  7317. (org-test-with-temp-text "<2012-03-29 Thu>"
  7318. (org-timestamp-has-time-p (org-element-context)))))
  7319. (ert-deftest test-org/get-repeat ()
  7320. "Test `org-get-repeat' specifications."
  7321. (should
  7322. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
  7323. (org-get-repeat)))
  7324. (should-not
  7325. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
  7326. (org-get-repeat)))
  7327. ;; Return proper repeat string.
  7328. (should
  7329. (equal "+2y"
  7330. (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
  7331. (org-get-repeat))))
  7332. ;; Prevent false positive (commented or verbatim time stamps)
  7333. (should-not
  7334. (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
  7335. (org-get-repeat)))
  7336. (should-not
  7337. (org-test-with-temp-text
  7338. "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
  7339. (org-get-repeat)))
  7340. ;; Return nil when called before first heading.
  7341. (should-not
  7342. (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
  7343. (org-get-repeat)))
  7344. ;; When called with an optional argument, extract repeater from that
  7345. ;; string instead.
  7346. (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
  7347. (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
  7348. (ert-deftest test-org/timestamp-format ()
  7349. "Test `org-timestamp-format' specifications."
  7350. ;; Regular test.
  7351. (should
  7352. (equal
  7353. "2012-03-29 16:40"
  7354. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7355. (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
  7356. ;; Range end.
  7357. (should
  7358. (equal
  7359. "2012-03-29"
  7360. (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
  7361. (org-timestamp-format (org-element-context) "%Y-%m-%d" t)))))
  7362. (ert-deftest test-org/timestamp-split-range ()
  7363. "Test `org-timestamp-split-range' specifications."
  7364. ;; Extract range start (active).
  7365. (should
  7366. (equal '(2012 3 29)
  7367. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7368. (let ((ts (org-timestamp-split-range (org-element-context))))
  7369. (mapcar (lambda (p) (org-element-property p ts))
  7370. '(:year-end :month-end :day-end))))))
  7371. ;; Extract range start (inactive)
  7372. (should
  7373. (equal '(2012 3 29)
  7374. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7375. (let ((ts (org-timestamp-split-range (org-element-context))))
  7376. (mapcar (lambda (p) (org-element-property p ts))
  7377. '(:year-end :month-end :day-end))))))
  7378. ;; Extract range end (active).
  7379. (should
  7380. (equal '(2012 3 30)
  7381. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7382. (let ((ts (org-timestamp-split-range
  7383. (org-element-context) t)))
  7384. (mapcar (lambda (p) (org-element-property p ts))
  7385. '(:year-end :month-end :day-end))))))
  7386. ;; Extract range end (inactive)
  7387. (should
  7388. (equal '(2012 3 30)
  7389. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7390. (let ((ts (org-timestamp-split-range
  7391. (org-element-context) t)))
  7392. (mapcar (lambda (p) (org-element-property p ts))
  7393. '(:year-end :month-end :day-end))))))
  7394. ;; Return the timestamp if not a range.
  7395. (should
  7396. (org-test-with-temp-text "[2012-03-29 Thu]"
  7397. (let* ((ts-orig (org-element-context))
  7398. (ts-copy (org-timestamp-split-range ts-orig)))
  7399. (eq ts-orig ts-copy))))
  7400. (should
  7401. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7402. (let* ((ts-orig (org-element-context))
  7403. (ts-copy (org-timestamp-split-range ts-orig)))
  7404. (eq ts-orig ts-copy)))))
  7405. (ert-deftest test-org/timestamp-translate ()
  7406. "Test `org-timestamp-translate' specifications."
  7407. ;; Translate whole date range.
  7408. (should
  7409. (equal "<29>--<30>"
  7410. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7411. (let ((org-display-custom-times t)
  7412. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7413. (org-timestamp-translate (org-element-context))))))
  7414. ;; Translate date range start.
  7415. (should
  7416. (equal "<29>"
  7417. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7418. (let ((org-display-custom-times t)
  7419. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7420. (org-timestamp-translate (org-element-context) 'start)))))
  7421. ;; Translate date range end.
  7422. (should
  7423. (equal "<30>"
  7424. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7425. (let ((org-display-custom-times t)
  7426. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7427. (org-timestamp-translate (org-element-context) 'end)))))
  7428. ;; Translate time range.
  7429. (should
  7430. (equal "<08>--<16>"
  7431. (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
  7432. (let ((org-display-custom-times t)
  7433. (org-time-stamp-custom-formats '("<%d>" . "<%H>")))
  7434. (org-timestamp-translate (org-element-context))))))
  7435. ;; Translate non-range timestamp.
  7436. (should
  7437. (equal "<29>"
  7438. (org-test-with-temp-text "<2012-03-29 Thu>"
  7439. (let ((org-display-custom-times t)
  7440. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7441. (org-timestamp-translate (org-element-context))))))
  7442. ;; Do not change `diary' timestamps.
  7443. (should
  7444. (equal "<%%(org-float t 4 2)>"
  7445. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7446. (let ((org-display-custom-times t)
  7447. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7448. (org-timestamp-translate (org-element-context)))))))
  7449. (ert-deftest test-org/timestamp-from-string ()
  7450. "Test `org-timestamp-from-string' specifications."
  7451. ;; Return nil if argument is not a valid Org timestamp.
  7452. (should-not (org-timestamp-from-string ""))
  7453. (should-not (org-timestamp-from-string nil))
  7454. (should-not (org-timestamp-from-string "<2012-03-29"))
  7455. ;; Otherwise, return a valid Org timestamp object.
  7456. (should
  7457. (string-match-p "<2012-03-29 .+>"
  7458. (org-element-interpret-data
  7459. (org-timestamp-from-string "<2012-03-29 Thu>"))))
  7460. (should
  7461. (string-match-p "[2014-03-04 .+]"
  7462. (org-element-interpret-data
  7463. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  7464. (ert-deftest test-org/timestamp-from-time ()
  7465. "Test `org-timestamp-from-time' specifications."
  7466. ;; Standard test.
  7467. (should
  7468. (string-match-p
  7469. "<2012-03-29 .+>"
  7470. (org-element-interpret-data
  7471. (org-timestamp-from-time
  7472. (apply #'encode-time
  7473. (org-parse-time-string "<2012-03-29 Thu 16:40>"))))))
  7474. ;; When optional argument WITH-TIME is non-nil, provide time
  7475. ;; information.
  7476. (should
  7477. (string-match-p
  7478. "<2012-03-29 .+ 16:40>"
  7479. (org-element-interpret-data
  7480. (org-timestamp-from-time
  7481. (apply #'encode-time
  7482. (org-parse-time-string "<2012-03-29 Thu 16:40>"))
  7483. t))))
  7484. ;; When optional argument INACTIVE is non-nil, return an inactive
  7485. ;; timestamp.
  7486. (should
  7487. (string-match-p
  7488. "[2012-03-29 .+]"
  7489. (org-element-interpret-data
  7490. (org-timestamp-from-time
  7491. (apply #'encode-time
  7492. (org-parse-time-string "<2012-03-29 Thu 16:40>"))
  7493. nil t)))))
  7494. (ert-deftest test-org/timestamp-to-time ()
  7495. "Test `org-timestamp-to-time' specifications."
  7496. (should
  7497. (equal "2014-03-04"
  7498. (format-time-string
  7499. "%Y-%m-%d"
  7500. (org-timestamp-to-time
  7501. (org-timestamp-from-string "<2014-03-04 Tue>")))))
  7502. (should
  7503. (equal "2014-03-04"
  7504. (format-time-string
  7505. "%Y-%m-%d"
  7506. (org-timestamp-to-time
  7507. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  7508. (should
  7509. (equal "2012-03-29 08:30"
  7510. (format-time-string
  7511. "%Y-%m-%d %H:%M"
  7512. (org-timestamp-to-time
  7513. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")))))
  7514. (should
  7515. (equal "2012-03-29"
  7516. (format-time-string
  7517. "%Y-%m-%d"
  7518. (org-timestamp-to-time
  7519. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")))))
  7520. (should
  7521. (equal "2012-03-29"
  7522. (format-time-string
  7523. "%Y-%m-%d"
  7524. (org-timestamp-to-time
  7525. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")))))
  7526. ;; When optional argument END is non-nil, use end of date range or
  7527. ;; time range.
  7528. (should
  7529. (equal "2012-03-29 16:40"
  7530. (format-time-string
  7531. "%Y-%m-%d %H:%M"
  7532. (org-timestamp-to-time
  7533. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")
  7534. t))))
  7535. (should
  7536. (equal "2014-03-04"
  7537. (format-time-string
  7538. "%Y-%m-%d"
  7539. (org-timestamp-to-time
  7540. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")
  7541. t))))
  7542. (should
  7543. (equal "2014-03-04"
  7544. (format-time-string
  7545. "%Y-%m-%d"
  7546. (org-timestamp-to-time
  7547. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")
  7548. t)))))
  7549. ;;; Visibility
  7550. (ert-deftest test-org/hide-drawer-toggle ()
  7551. "Test `org-hide-drawer-toggle' specifications."
  7552. ;; Error when not at a drawer.
  7553. (should-error
  7554. (org-test-with-temp-text ":fake-drawer:\ncontents"
  7555. (org-hide-drawer-toggle 'off)
  7556. (get-char-property (line-end-position) 'invisible)))
  7557. (should-error
  7558. (org-test-with-temp-text
  7559. "#+begin_example\n<point>:D:\nc\n:END:\n#+end_example"
  7560. (org-hide-drawer-toggle t)))
  7561. ;; Hide drawer.
  7562. (should
  7563. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7564. (org-hide-drawer-toggle)
  7565. (get-char-property (line-end-position) 'invisible)))
  7566. ;; Show drawer unconditionally when optional argument is `off'.
  7567. (should-not
  7568. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7569. (org-hide-drawer-toggle)
  7570. (org-hide-drawer-toggle 'off)
  7571. (get-char-property (line-end-position) 'invisible)))
  7572. ;; Hide drawer unconditionally when optional argument is non-nil.
  7573. (should
  7574. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7575. (org-hide-drawer-toggle t)
  7576. (get-char-property (line-end-position) 'invisible)))
  7577. ;; Do not hide drawer when called from final blank lines.
  7578. (should-not
  7579. (org-test-with-temp-text ":drawer:\ncontents\n:end:\n\n<point>"
  7580. (org-hide-drawer-toggle)
  7581. (goto-char (point-min))
  7582. (get-char-property (line-end-position) 'invisible)))
  7583. ;; Don't leave point in an invisible part of the buffer when hiding
  7584. ;; a drawer away.
  7585. (should-not
  7586. (org-test-with-temp-text ":drawer:\ncontents\n<point>:end:"
  7587. (org-hide-drawer-toggle)
  7588. (get-char-property (point) 'invisible))))
  7589. (ert-deftest test-org/hide-block-toggle ()
  7590. "Test `org-hide-block-toggle' specifications."
  7591. ;; Error when not at a block.
  7592. (should-error
  7593. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
  7594. (org-hide-block-toggle 'off)
  7595. (get-char-property (line-end-position) 'invisible)))
  7596. ;; Hide block.
  7597. (should
  7598. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  7599. (org-hide-block-toggle)
  7600. (get-char-property (line-end-position) 'invisible)))
  7601. (should
  7602. (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
  7603. (org-hide-block-toggle)
  7604. (get-char-property (line-end-position) 'invisible)))
  7605. ;; Show block unconditionally when optional argument is `off'.
  7606. (should-not
  7607. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7608. (org-hide-block-toggle)
  7609. (org-hide-block-toggle 'off)
  7610. (get-char-property (line-end-position) 'invisible)))
  7611. (should-not
  7612. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7613. (org-hide-block-toggle 'off)
  7614. (get-char-property (line-end-position) 'invisible)))
  7615. ;; Hide block unconditionally when optional argument is non-nil.
  7616. (should
  7617. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7618. (org-hide-block-toggle t)
  7619. (get-char-property (line-end-position) 'invisible)))
  7620. (should
  7621. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7622. (org-hide-block-toggle)
  7623. (org-hide-block-toggle t)
  7624. (get-char-property (line-end-position) 'invisible)))
  7625. ;; Do not hide block when called from final blank lines.
  7626. (should-not
  7627. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
  7628. (org-hide-block-toggle)
  7629. (goto-char (point-min))
  7630. (get-char-property (line-end-position) 'invisible)))
  7631. ;; Don't leave point in an invisible part of the buffer when hiding
  7632. ;; a block away.
  7633. (should-not
  7634. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
  7635. (org-hide-block-toggle)
  7636. (get-char-property (point) 'invisible))))
  7637. (ert-deftest test-org/hide-block-toggle-maybe ()
  7638. "Test `org-hide-block-toggle-maybe' specifications."
  7639. (should
  7640. (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
  7641. (org-hide-block-toggle-maybe)))
  7642. (should-not
  7643. (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
  7644. (ert-deftest test-org/show-set-visibility ()
  7645. "Test `org-show-set-visibility' specifications."
  7646. ;; Do not throw an error before first heading.
  7647. (should
  7648. (org-test-with-temp-text "Preamble\n* Headline"
  7649. (org-show-set-visibility 'tree)
  7650. t))
  7651. ;; Test all visibility spans, both on headline and in entry.
  7652. (let ((list-visible-lines
  7653. (lambda (state headerp)
  7654. (org-test-with-temp-text "* Grandmother (0)
  7655. ** Uncle (1)
  7656. *** Heir (2)
  7657. ** Father (3)
  7658. Ancestor text (4)
  7659. *** Sister (5)
  7660. Sibling text (6)
  7661. *** Self (7)
  7662. Match (8)
  7663. **** First born (9)
  7664. Child text (10)
  7665. **** The other child (11)
  7666. *** Brother (12)
  7667. ** Aunt (13)
  7668. "
  7669. (org-cycle t)
  7670. (search-forward (if headerp "Self" "Match"))
  7671. (org-show-set-visibility state)
  7672. (goto-char (point-min))
  7673. (let (result (line 0))
  7674. (while (not (eobp))
  7675. (unless (org-invisible-p2) (push line result))
  7676. (cl-incf line)
  7677. (forward-line))
  7678. (nreverse result))))))
  7679. (should (equal '(0 7) (funcall list-visible-lines 'minimal t)))
  7680. (should (equal '(0 7 8) (funcall list-visible-lines 'minimal nil)))
  7681. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local t)))
  7682. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local nil)))
  7683. (should (equal '(0 3 7) (funcall list-visible-lines 'ancestors t)))
  7684. (should (equal '(0 3 7 8) (funcall list-visible-lines 'ancestors nil)))
  7685. (should (equal '(0 3 5 7 12) (funcall list-visible-lines 'lineage t)))
  7686. (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines 'lineage nil)))
  7687. (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines 'tree t)))
  7688. (should (equal '(0 1 3 5 7 8 9 11 12 13)
  7689. (funcall list-visible-lines 'tree nil)))
  7690. (should (equal '(0 1 3 4 5 7 12 13)
  7691. (funcall list-visible-lines 'canonical t)))
  7692. (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
  7693. (funcall list-visible-lines 'canonical nil))))
  7694. ;; When point is hidden in a drawer or a block, make sure to make it
  7695. ;; visible.
  7696. (should-not
  7697. (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
  7698. (org-hide-block-toggle)
  7699. (search-forward "Text")
  7700. (org-show-set-visibility 'minimal)
  7701. (org-invisible-p2)))
  7702. (should-not
  7703. (org-test-with-temp-text ":DRAWER:\nText\n:END:"
  7704. (org-hide-drawer-toggle)
  7705. (search-forward "Text")
  7706. (org-show-set-visibility 'minimal)
  7707. (org-invisible-p2)))
  7708. (should-not
  7709. (org-test-with-temp-text
  7710. "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
  7711. (org-hide-drawer-toggle)
  7712. (forward-line -1)
  7713. (org-hide-block-toggle)
  7714. (search-forward "Text")
  7715. (org-show-set-visibility 'minimal)
  7716. (org-invisible-p2))))
  7717. (defun test-org/copy-visible ()
  7718. "Test `org-copy-visible' specifications."
  7719. (should
  7720. (equal "Foo"
  7721. (org-test-with-temp-text "Foo"
  7722. (let ((kill-ring nil))
  7723. (org-copy-visible (point-min) (point-max))
  7724. (current-kill 0 t)))))
  7725. ;; Skip invisible characters by text property.
  7726. (should
  7727. (equal "Foo"
  7728. (org-test-with-temp-text #("F<hidden>oo" 1 7 (invisible t))
  7729. (let ((kill-ring nil))
  7730. (org-copy-visible (point-min) (point-max))
  7731. (current-kill 0 t)))))
  7732. ;; Skip invisible characters by overlay.
  7733. (should
  7734. (equal "Foo"
  7735. (org-test-with-temp-text "F<hidden>oo"
  7736. (let ((o (make-overlay 2 10)))
  7737. (overlay-put o 'invisible t))
  7738. (let ((kill-ring nil))
  7739. (org-copy-visible (point-min) (point-max))
  7740. (current-kill 0 t)))))
  7741. ;; Handle invisible characters at the beginning and the end of the
  7742. ;; buffer.
  7743. (should
  7744. (equal "Foo"
  7745. (org-test-with-temp-text #("<hidden>Foo" 0 8 (invisible t))
  7746. (let ((kill-ring nil))
  7747. (org-copy-visible (point-min) (point-max))
  7748. (current-kill 0 t)))))
  7749. (should
  7750. (equal "Foo"
  7751. (org-test-with-temp-text #("Foo<hidden>" 3 11 (invisible t))
  7752. (let ((kill-ring nil))
  7753. (org-copy-visible (point-min) (point-max))
  7754. (current-kill 0 t)))))
  7755. ;; Handle multiple visible parts.
  7756. (should
  7757. (equal "abc"
  7758. (org-test-with-temp-text
  7759. #("aXbXc" 1 2 (invisible t) 3 4 (invisible t))
  7760. (let ((kill-ring nil))
  7761. (org-copy-visible (point-min) (point-max))
  7762. (current-kill 0 t))))))
  7763. (ert-deftest test-org/set-visibility-according-to-property ()
  7764. "Test `org-set-visibility-according-to-property' specifications."
  7765. ;; "folded" state.
  7766. (should
  7767. (org-test-with-temp-text
  7768. "
  7769. * a
  7770. :PROPERTIES:
  7771. :VISIBILITY: folded
  7772. :END:
  7773. ** <point>b"
  7774. (org-set-visibility-according-to-property)
  7775. (invisible-p (point))))
  7776. ;; "children" state.
  7777. (should
  7778. (org-test-with-temp-text
  7779. "
  7780. * a
  7781. :PROPERTIES:
  7782. :VISIBILITY: children
  7783. :END:
  7784. ** b
  7785. <point>Contents
  7786. ** c"
  7787. (org-set-visibility-according-to-property)
  7788. (invisible-p (point))))
  7789. (should
  7790. (org-test-with-temp-text
  7791. "
  7792. * a
  7793. :PROPERTIES:
  7794. :VISIBILITY: children
  7795. :END:
  7796. ** b
  7797. Contents
  7798. *** <point>c"
  7799. (org-set-visibility-according-to-property)
  7800. (invisible-p (point))))
  7801. ;; "content" state.
  7802. (should
  7803. (org-test-with-temp-text
  7804. "
  7805. * a
  7806. :PROPERTIES:
  7807. :VISIBILITY: content
  7808. :END:
  7809. ** b
  7810. <point>Contents
  7811. *** c"
  7812. (org-set-visibility-according-to-property)
  7813. (invisible-p (point))))
  7814. (should
  7815. (org-test-with-temp-text
  7816. "
  7817. * a
  7818. :PROPERTIES:
  7819. :VISIBILITY: content
  7820. :END:
  7821. ** b
  7822. Contents
  7823. *** <point>c"
  7824. (org-set-visibility-according-to-property)
  7825. (not (invisible-p (point)))))
  7826. ;; "showall" state.
  7827. (should
  7828. (org-test-with-temp-text
  7829. "
  7830. * a
  7831. :PROPERTIES:
  7832. :VISIBILITY: showall
  7833. :END:
  7834. ** b
  7835. <point>Contents
  7836. *** c"
  7837. (org-set-visibility-according-to-property)
  7838. (not (invisible-p (point)))))
  7839. (should
  7840. (org-test-with-temp-text
  7841. "
  7842. * a
  7843. :PROPERTIES:
  7844. :VISIBILITY: showall
  7845. :END:
  7846. ** b
  7847. Contents
  7848. *** <point>c"
  7849. (org-set-visibility-according-to-property)
  7850. (not (invisible-p (point)))))
  7851. ;; When VISIBILITY properties are nested, ignore inner ones.
  7852. (should
  7853. (org-test-with-temp-text
  7854. "
  7855. * A
  7856. :PROPERTIES:
  7857. :VISIBILITY: folded
  7858. :END:
  7859. ** <point>B
  7860. :PROPERTIES:
  7861. :VISIBILITY: folded
  7862. :END:"
  7863. (org-set-visibility-according-to-property)
  7864. (invisible-p (point)))))
  7865. (ert-deftest test-org/visibility-show-branches ()
  7866. "Test visibility of inline archived subtrees."
  7867. (org-test-with-temp-text
  7868. "* Foo<point>
  7869. ** Bar :ARCHIVE:
  7870. *** Baz
  7871. "
  7872. (org-kill-note-or-show-branches)
  7873. (should (org-invisible-p (- (point-max) 2)))))
  7874. ;;; Yank and Kill
  7875. (ert-deftest test-org/paste-subtree ()
  7876. "Test `org-paste-subtree' specifications."
  7877. ;; Return an error if text to yank is not a set of subtrees.
  7878. (should-error (org-paste-subtree nil "Text"))
  7879. ;; Adjust level according to current one.
  7880. (should
  7881. (equal "* H\n* Text\n"
  7882. (org-test-with-temp-text "* H\n<point>"
  7883. (org-paste-subtree nil "* Text")
  7884. (buffer-string))))
  7885. (should
  7886. (equal "* H1\n** H2\n** Text\n"
  7887. (org-test-with-temp-text "* H1\n** H2\n<point>"
  7888. (org-paste-subtree nil "* Text")
  7889. (buffer-string))))
  7890. ;; When not on a heading, move to next heading before yanking.
  7891. (should
  7892. (equal "* H1\nParagraph\n* Text\n* H2"
  7893. (org-test-with-temp-text "* H1\n<point>Paragraph\n* H2"
  7894. (org-paste-subtree nil "* Text")
  7895. (buffer-string))))
  7896. ;; If point is between two headings, use the deepest level.
  7897. (should
  7898. (equal "* H1\n\n* Text\n* H2"
  7899. (org-test-with-temp-text "* H1\n<point>\n* H2"
  7900. (org-paste-subtree nil "* Text")
  7901. (buffer-string))))
  7902. (should
  7903. (equal "** H1\n\n** Text\n* H2"
  7904. (org-test-with-temp-text "** H1\n<point>\n* H2"
  7905. (org-paste-subtree nil "* Text")
  7906. (buffer-string))))
  7907. (should
  7908. (equal "* H1\n\n** Text\n** H2"
  7909. (org-test-with-temp-text "* H1\n<point>\n** H2"
  7910. (org-paste-subtree nil "* Text")
  7911. (buffer-string))))
  7912. ;; When on an empty heading, after the stars, deduce the new level
  7913. ;; from the number of stars.
  7914. (should
  7915. (equal "*** Text\n"
  7916. (org-test-with-temp-text "*** <point>"
  7917. (org-paste-subtree nil "* Text")
  7918. (buffer-string))))
  7919. ;; Optional argument LEVEL forces a level for the subtree.
  7920. (should
  7921. (equal "* H\n*** Text\n"
  7922. (org-test-with-temp-text "* H<point>"
  7923. (org-paste-subtree 3 "* Text")
  7924. (buffer-string)))))
  7925. (ert-deftest test-org/cut-and-paste-subtree ()
  7926. "Test `org-cut-subtree' and `org-paste-subtree'."
  7927. (should
  7928. (equal
  7929. "* Two
  7930. two
  7931. * One
  7932. "
  7933. (org-test-with-temp-text
  7934. "* One
  7935. <point>* Two
  7936. two
  7937. "
  7938. (call-interactively #'org-cut-subtree)
  7939. (goto-char (point-min))
  7940. (call-interactively #'org-paste-subtree)
  7941. (buffer-string))))
  7942. (should
  7943. (equal
  7944. "* One
  7945. * Two
  7946. "
  7947. (org-test-with-temp-text
  7948. "* One
  7949. <point>* Two
  7950. "
  7951. (call-interactively #'org-cut-subtree)
  7952. (backward-char)
  7953. (call-interactively #'org-paste-subtree)
  7954. (buffer-string)))))
  7955. (provide 'test-org)
  7956. ;;; test-org.el ends here