test-org.el 196 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050
  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. ;;; Comments:
  16. ;; Template test file for Org tests
  17. ;;; Code:
  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. (progn (call-interactively '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. (progn (call-interactively '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# Comment"
  96. (progn (forward-line)
  97. (let ((org-adapt-indentation t))
  98. (call-interactively 'comment-dwim))
  99. (buffer-string)))))
  100. ;; Also recognize single # at column 0 as comments.
  101. (should
  102. (equal "# Comment"
  103. (org-test-with-temp-text "# Comment"
  104. (progn (forward-line)
  105. (call-interactively 'comment-dwim)
  106. (buffer-string)))))
  107. ;; Region selected and only comments and blank lines within it:
  108. ;; un-comment all commented lines.
  109. (should
  110. (equal "Comment 1\n\nComment 2"
  111. (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
  112. (progn
  113. (transient-mark-mode 1)
  114. (push-mark (point) t t)
  115. (goto-char (point-max))
  116. (call-interactively 'comment-dwim)
  117. (buffer-string)))))
  118. ;; Region selected without comments: comment all lines if
  119. ;; `comment-empty-lines' is non-nil, only non-blank lines otherwise.
  120. (should
  121. (equal "# Comment 1\n\n# Comment 2"
  122. (org-test-with-temp-text "Comment 1\n\nComment 2"
  123. (progn
  124. (transient-mark-mode 1)
  125. (push-mark (point) t t)
  126. (goto-char (point-max))
  127. (let ((comment-empty-lines nil))
  128. (call-interactively 'comment-dwim))
  129. (buffer-string)))))
  130. (should
  131. (equal "# Comment 1\n# \n# Comment 2"
  132. (org-test-with-temp-text "Comment 1\n\nComment 2"
  133. (progn
  134. (transient-mark-mode 1)
  135. (push-mark (point) t t)
  136. (goto-char (point-max))
  137. (let ((comment-empty-lines t))
  138. (call-interactively 'comment-dwim))
  139. (buffer-string)))))
  140. ;; In front of a keyword without region, insert a new comment.
  141. (should
  142. (equal "# \n#+KEYWORD: value"
  143. (org-test-with-temp-text "#+KEYWORD: value"
  144. (progn (call-interactively 'comment-dwim)
  145. (buffer-string)))))
  146. ;; In a source block, use appropriate syntax.
  147. (should
  148. (equal " ;; "
  149. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n\n#+END_SRC"
  150. (forward-line)
  151. (let ((org-edit-src-content-indentation 2))
  152. (call-interactively 'comment-dwim))
  153. (buffer-substring-no-properties (line-beginning-position) (point)))))
  154. (should
  155. (equal "#+BEGIN_SRC emacs-lisp\n ;; a\n ;; b\n#+END_SRC"
  156. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\na\nb\n#+END_SRC"
  157. (forward-line)
  158. (transient-mark-mode 1)
  159. (push-mark (point) t t)
  160. (forward-line 2)
  161. (let ((org-edit-src-content-indentation 2))
  162. (call-interactively 'comment-dwim))
  163. (buffer-string)))))
  164. ;;; Date and time analysis
  165. (ert-deftest test-org/org-read-date ()
  166. "Test `org-read-date' specifications."
  167. ;; Parse ISO date with abbreviated year and month.
  168. (should (equal "2012-03-29 16:40"
  169. (let ((org-time-was-given t))
  170. (org-read-date t nil "12-3-29 16:40"))))
  171. ;; Parse Europeans dates.
  172. (should (equal "2012-03-29 16:40"
  173. (let ((org-time-was-given t))
  174. (org-read-date t nil "29.03.2012 16:40"))))
  175. ;; Parse Europeans dates without year.
  176. (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
  177. (let ((org-time-was-given t))
  178. (org-read-date t nil "29.03. 16:40"))))
  179. ;; Relative date applied to current time if there is single
  180. ;; plus/minus, or to default date when there are two of them.
  181. (should
  182. (equal
  183. "2015-03-04"
  184. (cl-letf (((symbol-function 'current-time)
  185. (lambda ()
  186. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  187. (org-read-date
  188. t nil "+1y" nil
  189. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))
  190. (should
  191. (equal
  192. "2013-03-29"
  193. (cl-letf (((symbol-function 'current-time)
  194. (lambda ()
  195. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  196. (org-read-date
  197. t nil "++1y" nil
  198. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))
  199. ;; When `org-read-date-prefer-future' is non-nil, prefer future
  200. ;; dates (relatively to now) when incomplete. Otherwise, use
  201. ;; default date.
  202. (should
  203. (equal
  204. "2014-04-01"
  205. (cl-letf (((symbol-function 'current-time)
  206. (lambda ()
  207. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  208. (let ((org-read-date-prefer-future t))
  209. (org-read-date t nil "1")))))
  210. (should
  211. (equal
  212. "2013-03-04"
  213. (cl-letf (((symbol-function 'current-time)
  214. (lambda ()
  215. (apply #'encode-time (org-parse-time-string "2012-03-29")))))
  216. (let ((org-read-date-prefer-future t))
  217. (org-read-date t nil "3-4")))))
  218. (should
  219. (equal
  220. "2012-03-04"
  221. (cl-letf (((symbol-function 'current-time)
  222. (lambda ()
  223. (apply #'encode-time (org-parse-time-string "2012-03-29")))))
  224. (let ((org-read-date-prefer-future nil))
  225. (org-read-date t nil "3-4")))))
  226. ;; When set to `org-read-date-prefer-future' is set to `time', read
  227. ;; day is moved to tomorrow if specified hour is before current
  228. ;; time. However, it only happens in no other part of the date is
  229. ;; specified.
  230. (should
  231. (equal
  232. "2012-03-30"
  233. (cl-letf (((symbol-function 'current-time)
  234. (lambda ()
  235. (apply #'encode-time (org-parse-time-string "2012-03-29 16:40")))))
  236. (let ((org-read-date-prefer-future 'time))
  237. (org-read-date t nil "00:40" nil)))))
  238. (should-not
  239. (equal
  240. "2012-03-30"
  241. (cl-letf (((symbol-function 'current-time)
  242. (lambda ()
  243. (apply #'encode-time (org-parse-time-string "2012-03-29 16:40")))))
  244. (let ((org-read-date-prefer-future 'time))
  245. (org-read-date t nil "29 00:40" nil)))))
  246. ;; Caveat: `org-read-date-prefer-future' always refers to current
  247. ;; time, not default time, when they differ.
  248. (should
  249. (equal
  250. "2014-04-01"
  251. (cl-letf (((symbol-function 'current-time)
  252. (lambda ()
  253. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  254. (let ((org-read-date-prefer-future t))
  255. (org-read-date
  256. t nil "1" nil
  257. (apply #'encode-time (org-parse-time-string "2012-03-29")))))))
  258. (should
  259. (equal
  260. "2014-03-25"
  261. (cl-letf (((symbol-function 'current-time)
  262. (lambda ()
  263. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  264. (let ((org-read-date-prefer-future t))
  265. (org-read-date
  266. t nil "25" nil
  267. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))))
  268. (ert-deftest test-org/org-parse-time-string ()
  269. "Test `org-parse-time-string'."
  270. (should (equal (org-parse-time-string "2012-03-29 16:40")
  271. '(0 40 16 29 3 2012 nil nil nil)))
  272. (should (equal (org-parse-time-string "[2012-03-29 16:40]")
  273. '(0 40 16 29 3 2012 nil nil nil)))
  274. (should (equal (org-parse-time-string "<2012-03-29 16:40>")
  275. '(0 40 16 29 3 2012 nil nil nil)))
  276. (should (equal (org-parse-time-string "<2012-03-29>")
  277. '(0 0 0 29 3 2012 nil nil nil)))
  278. (should (equal (org-parse-time-string "<2012-03-29>" t)
  279. '(0 nil nil 29 3 2012 nil nil nil))))
  280. (ert-deftest test-org/closest-date ()
  281. "Test `org-closest-date' specifications."
  282. (require 'calendar)
  283. ;; Time stamps without a repeater are returned unchanged.
  284. (should
  285. (equal
  286. '(3 29 2012)
  287. (calendar-gregorian-from-absolute
  288. (org-closest-date "<2012-03-29>" "<2014-03-04>" nil))))
  289. ;; Time stamps with a null repeater are returned unchanged.
  290. (should
  291. (equal
  292. '(3 29 2012)
  293. (calendar-gregorian-from-absolute
  294. (org-closest-date "<2012-03-29 +0d>" "<2014-03-04>" nil))))
  295. ;; if PREFER is set to `past' always return a date before, or equal
  296. ;; to CURRENT.
  297. (should
  298. (equal
  299. '(3 1 2014)
  300. (calendar-gregorian-from-absolute
  301. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'past))))
  302. (should
  303. (equal
  304. '(3 4 2014)
  305. (calendar-gregorian-from-absolute
  306. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'past))))
  307. ;; if PREFER is set to `future' always return a date before, or equal
  308. ;; to CURRENT.
  309. (should
  310. (equal
  311. '(3 29 2014)
  312. (calendar-gregorian-from-absolute
  313. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'future))))
  314. (should
  315. (equal
  316. '(3 4 2014)
  317. (calendar-gregorian-from-absolute
  318. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'future))))
  319. ;; If PREFER is neither `past' nor `future', select closest date.
  320. (should
  321. (equal
  322. '(3 1 2014)
  323. (calendar-gregorian-from-absolute
  324. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" nil))))
  325. (should
  326. (equal
  327. '(5 4 2014)
  328. (calendar-gregorian-from-absolute
  329. (org-closest-date "<2012-03-04 +1m>" "<2014-04-28>" nil))))
  330. ;; Test "day" repeater.
  331. (should
  332. (equal '(3 8 2014)
  333. (calendar-gregorian-from-absolute
  334. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'past))))
  335. (should
  336. (equal '(3 10 2014)
  337. (calendar-gregorian-from-absolute
  338. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'future))))
  339. ;; Test "month" repeater.
  340. (should
  341. (equal '(1 5 2015)
  342. (calendar-gregorian-from-absolute
  343. (org-closest-date "<2014-03-05 +2m>" "<2015-02-04>" 'past))))
  344. (should
  345. (equal '(3 29 2014)
  346. (calendar-gregorian-from-absolute
  347. (org-closest-date "<2012-03-29 +2m>" "<2014-03-04>" 'future))))
  348. ;; Test "year" repeater.
  349. (should
  350. (equal '(3 5 2014)
  351. (calendar-gregorian-from-absolute
  352. (org-closest-date "<2014-03-05 +2y>" "<2015-02-04>" 'past))))
  353. (should
  354. (equal '(3 29 2014)
  355. (calendar-gregorian-from-absolute
  356. (org-closest-date "<2012-03-29 +2y>" "<2014-03-04>" 'future)))))
  357. (ert-deftest test-org/deadline-close-p ()
  358. "Test `org-deadline-close-p' specifications."
  359. ;; Pretend that the current time is 2016-06-03 Fri 01:43
  360. (cl-letf (((symbol-function 'current-time)
  361. (lambda ()
  362. (apply #'encode-time
  363. (org-parse-time-string "2016-06-03 Fri 01:43")))))
  364. ;; Timestamps are close if they are within `ndays' of lead time.
  365. (org-test-with-temp-text "* Heading"
  366. (should (org-deadline-close-p "2016-06-03 Fri" 0))
  367. (should (org-deadline-close-p "2016-06-02 Thu" 0))
  368. (should-not (org-deadline-close-p "2016-06-04 Sat" 0))
  369. (should (org-deadline-close-p "2016-06-04 Sat" 1))
  370. (should (org-deadline-close-p "2016-06-03 Fri 12:00" 0)))
  371. ;; Read `ndays' from timestamp if argument not given.
  372. (org-test-with-temp-text "* H"
  373. (should (org-deadline-close-p "2016-06-04 Sat -1d"))
  374. (should-not (org-deadline-close-p "2016-06-04 Sat -0d"))
  375. (should (org-deadline-close-p "2016-06-10 Fri -1w"))
  376. (should-not (org-deadline-close-p "2016-06-11 Sat -1w")))
  377. ;; Prefer `ndays' argument over lead time in timestamp.
  378. (org-test-with-temp-text "* H"
  379. (should (org-deadline-close-p "2016-06-04 Sat -0d" 1))
  380. (should-not (org-deadline-close-p "2016-06-04 Sat -0d" 0)))
  381. ;; Completed tasks are never close.
  382. (let ((org-todo-keywords '(("TODO" "|" "DONE"))))
  383. (org-test-with-temp-text "* TODO Heading"
  384. (should (org-deadline-close-p "2016-06-03")))
  385. (org-test-with-temp-text "* DONE Heading"
  386. (should-not (org-deadline-close-p "2016-06-03"))))))
  387. ;;; Drawers
  388. (ert-deftest test-org/insert-property-drawer ()
  389. "Test `org-insert-property-drawer' specifications."
  390. ;; Error before first headline.
  391. (should-error (org-test-with-temp-text "" (org-insert-property-drawer)))
  392. ;; Insert drawer right after headline if there is no planning line,
  393. ;; or after it otherwise.
  394. (should
  395. (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
  396. (org-test-with-temp-text "* H\nParagraph<point>"
  397. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  398. (buffer-string))))
  399. (should
  400. (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
  401. (org-test-with-temp-text
  402. "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
  403. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  404. (buffer-string))))
  405. ;; Indent inserted drawer.
  406. (should
  407. (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
  408. (org-test-with-temp-text "* H\nParagraph<point>"
  409. (let ((org-adapt-indentation t)) (org-insert-property-drawer))
  410. (buffer-string))))
  411. ;; Handle insertion at eob.
  412. (should
  413. (equal "* H\n:PROPERTIES:\n:END:\n"
  414. (org-test-with-temp-text "* H"
  415. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  416. (buffer-string))))
  417. ;; Skip inlinetasks before point.
  418. (when (featurep 'org-inlinetask)
  419. (should
  420. (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
  421. (org-test-with-temp-text
  422. "* H\n*************** I\n*************** END\nP<point>"
  423. (let ((org-adapt-indentation nil)
  424. (org-inlinetask-min-level 15))
  425. (org-insert-property-drawer))
  426. (buffer-string)))))
  427. ;; Correctly set drawer in an inlinetask.
  428. (when (featurep 'org-inlinetask)
  429. (should
  430. (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
  431. (org-test-with-temp-text
  432. "* H\n*************** I\nP<point>\n*************** END"
  433. (let ((org-adapt-indentation nil)
  434. (org-inlinetask-min-level 15))
  435. (org-insert-property-drawer))
  436. (buffer-string))))))
  437. ;;; Filling
  438. (ert-deftest test-org/fill-paragraph ()
  439. "Test `org-fill-paragraph' specifications."
  440. ;; At an Org table, align it.
  441. (should
  442. (equal "| a |\n"
  443. (org-test-with-temp-text "|a|"
  444. (org-fill-paragraph)
  445. (buffer-string))))
  446. (should
  447. (equal "#+name: table\n| a |\n"
  448. (org-test-with-temp-text "#+name: table\n| a |\n"
  449. (org-fill-paragraph)
  450. (buffer-string))))
  451. ;; At a paragraph, preserve line breaks.
  452. (org-test-with-temp-text "some \\\\\nlong\ntext"
  453. (let ((fill-column 20))
  454. (org-fill-paragraph)
  455. (should (equal (buffer-string) "some \\\\\nlong text"))))
  456. ;; Correctly fill a paragraph when point is at its very end.
  457. (should
  458. (equal "A B"
  459. (org-test-with-temp-text "A\nB"
  460. (let ((fill-column 20))
  461. (goto-char (point-max))
  462. (org-fill-paragraph)
  463. (buffer-string)))))
  464. ;; Correctly fill the last paragraph of a greater element.
  465. (should
  466. (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
  467. (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
  468. (let ((fill-column 8))
  469. (forward-line)
  470. (end-of-line)
  471. (org-fill-paragraph)
  472. (buffer-string)))))
  473. ;; Correctly fill an element in a narrowed buffer.
  474. (should
  475. (equal "01234\n6"
  476. (org-test-with-temp-text "01234 6789"
  477. (let ((fill-column 5))
  478. (narrow-to-region 1 8)
  479. (org-fill-paragraph)
  480. (buffer-string)))))
  481. ;; Handle `adaptive-fill-regexp' in paragraphs.
  482. (should
  483. (equal "> a b"
  484. (org-test-with-temp-text "> a\n> b"
  485. (let ((fill-column 5)
  486. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  487. (org-fill-paragraph)
  488. (buffer-string)))))
  489. ;; Special case: Fill first paragraph when point is at an item or
  490. ;; a plain-list or a footnote reference.
  491. (should
  492. (equal "- A B"
  493. (org-test-with-temp-text "- A\n B"
  494. (let ((fill-column 20))
  495. (org-fill-paragraph)
  496. (buffer-string)))))
  497. (should
  498. (equal "[fn:1] A B"
  499. (org-test-with-temp-text "[fn:1] A\nB"
  500. (let ((fill-column 20))
  501. (org-fill-paragraph)
  502. (buffer-string)))))
  503. (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
  504. (let ((fill-column 20))
  505. (org-fill-paragraph)
  506. (should (equal (buffer-string)
  507. "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
  508. ;; Fill contents of `comment-block' elements.
  509. (should
  510. (equal
  511. (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
  512. (let ((fill-column 20))
  513. (forward-line)
  514. (org-fill-paragraph)
  515. (buffer-string)))
  516. "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
  517. ;; Fill `comment' elements.
  518. (should
  519. (equal " # A B"
  520. (org-test-with-temp-text " # A\n # B"
  521. (let ((fill-column 20))
  522. (org-fill-paragraph)
  523. (buffer-string)))))
  524. ;; Do not mix consecutive comments when filling one of them.
  525. (should
  526. (equal "# A B\n\n# C"
  527. (org-test-with-temp-text "# A\n# B\n\n# C"
  528. (let ((fill-column 20))
  529. (org-fill-paragraph)
  530. (buffer-string)))))
  531. ;; Use commented empty lines as separators when filling comments.
  532. (should
  533. (equal "# A B\n#\n# C"
  534. (org-test-with-temp-text "# A\n# B\n#\n# C"
  535. (let ((fill-column 20))
  536. (org-fill-paragraph)
  537. (buffer-string)))))
  538. ;; Handle `adaptive-fill-regexp' in comments.
  539. (should
  540. (equal "# > a b"
  541. (org-test-with-temp-text "# > a\n# > b"
  542. (let ((fill-column 20)
  543. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  544. (org-fill-paragraph)
  545. (buffer-string)))))
  546. ;; Do nothing at affiliated keywords.
  547. (org-test-with-temp-text "#+NAME: para\nSome\ntext."
  548. (let ((fill-column 20))
  549. (org-fill-paragraph)
  550. (should (equal (buffer-string) "#+NAME: para\nSome\ntext."))))
  551. ;; Do not move point after table when filling a table.
  552. (should-not
  553. (org-test-with-temp-text "| a | b |\n| c | d |\n"
  554. (forward-char)
  555. (org-fill-paragraph)
  556. (eobp))))
  557. (ert-deftest test-org/auto-fill-function ()
  558. "Test auto-filling features."
  559. ;; Auto fill paragraph.
  560. (should
  561. (equal "12345\n7890"
  562. (org-test-with-temp-text "12345 7890"
  563. (let ((fill-column 5))
  564. (end-of-line)
  565. (org-auto-fill-function)
  566. (buffer-string)))))
  567. ;; Auto fill first paragraph in an item.
  568. (should
  569. (equal "- 12345\n 7890"
  570. (org-test-with-temp-text "- 12345 7890"
  571. (let ((fill-column 7))
  572. (end-of-line)
  573. (org-auto-fill-function)
  574. (buffer-string)))))
  575. ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
  576. (should
  577. (equal "> 12345\n 7890"
  578. (org-test-with-temp-text "> 12345 7890"
  579. (let ((fill-column 10)
  580. (adaptive-fill-regexp "[ \t]*>+[ \t]*")
  581. (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
  582. (end-of-line)
  583. (org-auto-fill-function)
  584. (buffer-string)))))
  585. (should
  586. (equal "> 12345\n> 12345\n> 7890"
  587. (org-test-with-temp-text "> 12345\n> 12345 7890"
  588. (let ((fill-column 10)
  589. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  590. (goto-char (point-max))
  591. (org-auto-fill-function)
  592. (buffer-string)))))
  593. (should-not
  594. (equal " 12345\n *12345\n *12345"
  595. (org-test-with-temp-text " 12345\n *12345 12345"
  596. (let ((fill-column 10)
  597. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  598. (goto-char (point-max))
  599. (org-auto-fill-function)
  600. (buffer-string)))))
  601. ;; Auto fill comments.
  602. (should
  603. (equal " # 12345\n # 7890"
  604. (org-test-with-temp-text " # 12345 7890"
  605. (let ((fill-column 10))
  606. (end-of-line)
  607. (org-auto-fill-function)
  608. (buffer-string)))))
  609. ;; A hash within a line isn't a comment.
  610. (should-not
  611. (equal "12345 # 7890\n# 1"
  612. (org-test-with-temp-text "12345 # 7890 1"
  613. (let ((fill-column 12))
  614. (end-of-line)
  615. (org-auto-fill-function)
  616. (buffer-string)))))
  617. ;; Correctly interpret empty prefix.
  618. (should-not
  619. (equal "# a\n# b\nRegular\n# paragraph"
  620. (org-test-with-temp-text "# a\n# b\nRegular paragraph"
  621. (let ((fill-column 12))
  622. (end-of-line 3)
  623. (org-auto-fill-function)
  624. (buffer-string)))))
  625. ;; Comment block: auto fill contents.
  626. (should
  627. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  628. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  629. (let ((fill-column 5))
  630. (forward-line)
  631. (end-of-line)
  632. (org-auto-fill-function)
  633. (buffer-string)))))
  634. (should
  635. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  636. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  637. (let ((fill-column 5))
  638. (forward-line)
  639. (end-of-line)
  640. (org-auto-fill-function)
  641. (buffer-string)))))
  642. ;; Do not fill if a new item could be created.
  643. (should-not
  644. (equal "12345\n- 90"
  645. (org-test-with-temp-text "12345 - 90"
  646. (let ((fill-column 5))
  647. (end-of-line)
  648. (org-auto-fill-function)
  649. (buffer-string)))))
  650. ;; Do not fill if a line break could be introduced.
  651. (should-not
  652. (equal "123\\\\\n7890"
  653. (org-test-with-temp-text "123\\\\ 7890"
  654. (let ((fill-column 6))
  655. (end-of-line)
  656. (org-auto-fill-function)
  657. (buffer-string)))))
  658. ;; Do not fill affiliated keywords.
  659. (should-not
  660. (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
  661. (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
  662. (let ((fill-column 20))
  663. (end-of-line)
  664. (org-auto-fill-function)
  665. (buffer-string))))))
  666. ;;; Indentation
  667. (ert-deftest test-org/indent-line ()
  668. "Test `org-indent-line' specifications."
  669. ;; Do not indent diary sexps, footnote definitions or headlines.
  670. (should
  671. (zerop
  672. (org-test-with-temp-text "%%(org-calendar-holiday)"
  673. (org-indent-line)
  674. (org-get-indentation))))
  675. (should
  676. (zerop
  677. (org-test-with-temp-text "[fn:1] fn"
  678. (let ((org-adapt-indentation t)) (org-indent-line))
  679. (org-get-indentation))))
  680. (should
  681. (zerop
  682. (org-test-with-temp-text "* H"
  683. (org-indent-line)
  684. (org-get-indentation))))
  685. ;; Do not indent before first headline.
  686. (should
  687. (zerop
  688. (org-test-with-temp-text ""
  689. (org-indent-line)
  690. (org-get-indentation))))
  691. ;; Indent according to headline level otherwise, unless
  692. ;; `org-adapt-indentation' is nil.
  693. (should
  694. (= 2
  695. (org-test-with-temp-text "* H\n<point>A"
  696. (let ((org-adapt-indentation t)) (org-indent-line))
  697. (org-get-indentation))))
  698. (should
  699. (= 2
  700. (org-test-with-temp-text "* H\n<point>\nA"
  701. (let ((org-adapt-indentation t)) (org-indent-line))
  702. (org-get-indentation))))
  703. (should
  704. (zerop
  705. (org-test-with-temp-text "* H\n<point>A"
  706. (let ((org-adapt-indentation nil)) (org-indent-line))
  707. (org-get-indentation))))
  708. ;; Indenting preserves point position.
  709. (should
  710. (org-test-with-temp-text "* H\nA<point>B"
  711. (let ((org-adapt-indentation t)) (org-indent-line))
  712. (looking-at "B")))
  713. ;; Do not change indentation at an item or a LaTeX environment.
  714. (should
  715. (= 1
  716. (org-test-with-temp-text "* H\n<point> - A"
  717. (let ((org-adapt-indentation t)) (org-indent-line))
  718. (org-get-indentation))))
  719. (should
  720. (= 1
  721. (org-test-with-temp-text
  722. "\\begin{equation}\n <point>1+1=2\n\\end{equation}"
  723. (org-indent-line)
  724. (org-get-indentation))))
  725. ;; On blank lines at the end of a list, indent like last element
  726. ;; within it if the line is still in the list. If the last element
  727. ;; is an item, indent like its contents. Otherwise, indent like the
  728. ;; whole list.
  729. (should
  730. (= 4
  731. (org-test-with-temp-text "* H\n- A\n - AA\n<point>"
  732. (let ((org-adapt-indentation t)) (org-indent-line))
  733. (org-get-indentation))))
  734. (should
  735. (= 4
  736. (org-test-with-temp-text "* H\n- A\n -\n\n<point>"
  737. (let ((org-adapt-indentation t)) (org-indent-line))
  738. (org-get-indentation))))
  739. (should
  740. (zerop
  741. (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n<point>"
  742. (let ((org-adapt-indentation t)) (org-indent-line))
  743. (org-get-indentation))))
  744. (should
  745. (= 4
  746. (org-test-with-temp-text "* H\n- A\n - \n<point>"
  747. (let ((org-adapt-indentation t)) (org-indent-line))
  748. (org-get-indentation))))
  749. (should
  750. (= 4
  751. (org-test-with-temp-text
  752. "* H\n - \n #+BEGIN_SRC emacs-lisp\n t\n #+END_SRC\n<point>"
  753. (let ((org-adapt-indentation t)) (org-indent-line))
  754. (org-get-indentation))))
  755. (should
  756. (= 2
  757. (org-test-with-temp-text "- A\n B\n\n<point>"
  758. (let ((org-adapt-indentation nil)) (org-indent-line))
  759. (org-get-indentation))))
  760. (should
  761. (= 2
  762. (org-test-with-temp-text
  763. "- A\n \begin{cases} 1 + 1\n \end{cases}\n\n<point>"
  764. (let ((org-adapt-indentation nil)) (org-indent-line))
  765. (org-get-indentation))))
  766. ;; Likewise, on a blank line at the end of a footnote definition,
  767. ;; indent at column 0 if line belongs to the definition. Otherwise,
  768. ;; indent like the definition itself.
  769. (should
  770. (zerop
  771. (org-test-with-temp-text "* H\n[fn:1] Definition\n<point>"
  772. (let ((org-adapt-indentation t)) (org-indent-line))
  773. (org-get-indentation))))
  774. (should
  775. (zerop
  776. (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n<point>"
  777. (let ((org-adapt-indentation t)) (org-indent-line))
  778. (org-get-indentation))))
  779. ;; After the end of the contents of a greater element, indent like
  780. ;; the beginning of the element.
  781. (should
  782. (= 1
  783. (org-test-with-temp-text
  784. " #+BEGIN_CENTER\n Contents\n<point>#+END_CENTER"
  785. (org-indent-line)
  786. (org-get-indentation))))
  787. ;; On blank lines after a paragraph, indent like its last non-empty
  788. ;; line.
  789. (should
  790. (= 1
  791. (org-test-with-temp-text " Paragraph\n\n<point>"
  792. (org-indent-line)
  793. (org-get-indentation))))
  794. ;; At the first line of an element, indent like previous element's
  795. ;; first line, ignoring footnotes definitions and inline tasks, or
  796. ;; according to parent.
  797. (should
  798. (= 2
  799. (org-test-with-temp-text "A\n\n B\n\nC<point>"
  800. (org-indent-line)
  801. (org-get-indentation))))
  802. (should
  803. (= 1
  804. (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC<point>"
  805. (org-indent-line)
  806. (org-get-indentation))))
  807. (should
  808. (= 1
  809. (org-test-with-temp-text
  810. " #+BEGIN_CENTER\n<point> Contents\n#+END_CENTER"
  811. (org-indent-line)
  812. (org-get-indentation))))
  813. ;; Within code part of a source block, use language major mode if
  814. ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
  815. ;; according to line above.
  816. (should
  817. (= 6
  818. (org-test-with-temp-text
  819. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  820. (let ((org-src-tab-acts-natively t)
  821. (org-edit-src-content-indentation 0))
  822. (org-indent-line))
  823. (org-get-indentation))))
  824. (should
  825. (= 1
  826. (org-test-with-temp-text
  827. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  828. (let ((org-src-tab-acts-natively nil)
  829. (org-edit-src-content-indentation 0))
  830. (org-indent-line))
  831. (org-get-indentation))))
  832. ;; Otherwise, indent like the first non-blank line above.
  833. (should
  834. (zerop
  835. (org-test-with-temp-text
  836. "#+BEGIN_CENTER\nline1\n\n<point> line2\n#+END_CENTER"
  837. (org-indent-line)
  838. (org-get-indentation))))
  839. ;; Align node properties according to `org-property-format'. Handle
  840. ;; nicely empty values.
  841. (should
  842. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  843. (org-test-with-temp-text
  844. "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
  845. (let ((org-property-format "%-10s %s")) (org-indent-line))
  846. (buffer-string))))
  847. (should
  848. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  849. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
  850. (let ((org-property-format "%-10s %s")) (org-indent-line))
  851. (buffer-string)))))
  852. (ert-deftest test-org/indent-region ()
  853. "Test `org-indent-region' specifications."
  854. ;; Indent paragraph.
  855. (should
  856. (equal "A\nB\nC"
  857. (org-test-with-temp-text " A\nB\n C"
  858. (org-indent-region (point-min) (point-max))
  859. (buffer-string))))
  860. ;; Indent greater elements along with their contents.
  861. (should
  862. (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
  863. (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
  864. (org-indent-region (point-min) (point-max))
  865. (buffer-string))))
  866. ;; Ignore contents of verse blocks. Only indent block delimiters.
  867. (should
  868. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  869. (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  870. (org-indent-region (point-min) (point-max))
  871. (buffer-string))))
  872. (should
  873. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  874. (org-test-with-temp-text " #+BEGIN_VERSE\n A\n B\n #+END_VERSE"
  875. (org-indent-region (point-min) (point-max))
  876. (buffer-string))))
  877. ;; Indent example blocks as a single block, unless indentation
  878. ;; should be preserved. In this case only indent the block markers.
  879. (should
  880. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  881. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  882. (org-indent-region (point-min) (point-max))
  883. (buffer-string))))
  884. (should
  885. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  886. (org-test-with-temp-text " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  887. (org-indent-region (point-min) (point-max))
  888. (buffer-string))))
  889. (should
  890. (equal "#+BEGIN_EXAMPLE -i\n A\n B\n#+END_EXAMPLE"
  891. (org-test-with-temp-text
  892. " #+BEGIN_EXAMPLE -i\n A\n B\n #+END_EXAMPLE"
  893. (org-indent-region (point-min) (point-max))
  894. (buffer-string))))
  895. (should
  896. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  897. (org-test-with-temp-text
  898. " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  899. (let ((org-src-preserve-indentation t))
  900. (org-indent-region (point-min) (point-max)))
  901. (buffer-string))))
  902. ;; Treat export blocks as a whole.
  903. (should
  904. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  905. (org-test-with-temp-text "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  906. (org-indent-region (point-min) (point-max))
  907. (buffer-string))))
  908. (should
  909. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  910. (org-test-with-temp-text
  911. " #+BEGIN_EXPORT latex\n A\n B\n #+END_EXPORT"
  912. (org-indent-region (point-min) (point-max))
  913. (buffer-string))))
  914. ;; Indent according to mode if `org-src-tab-acts-natively' is
  915. ;; non-nil. Otherwise, do not indent code at all.
  916. (should
  917. (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
  918. (org-test-with-temp-text
  919. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  920. (let ((org-src-tab-acts-natively t)
  921. (org-edit-src-content-indentation 0))
  922. (org-indent-region (point-min) (point-max)))
  923. (buffer-string))))
  924. (should
  925. (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  926. (org-test-with-temp-text
  927. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  928. (let ((org-src-tab-acts-natively nil)
  929. (org-edit-src-content-indentation 0))
  930. (org-indent-region (point-min) (point-max)))
  931. (buffer-string))))
  932. ;; Align node properties according to `org-property-format'. Handle
  933. ;; nicely empty values.
  934. (should
  935. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  936. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
  937. (let ((org-property-format "%-10s %s")
  938. (org-adapt-indentation nil))
  939. (org-indent-region (point) (point-max)))
  940. (buffer-string))))
  941. (should
  942. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  943. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
  944. (let ((org-property-format "%-10s %s")
  945. (org-adapt-indentation nil))
  946. (org-indent-region (point) (point-max)))
  947. (buffer-string))))
  948. ;; Indent plain lists.
  949. (should
  950. (equal "- A\n B\n - C\n\n D"
  951. (org-test-with-temp-text "- A\n B\n - C\n\n D"
  952. (org-indent-region (point-min) (point-max))
  953. (buffer-string))))
  954. (should
  955. (equal "- A\n\n- B"
  956. (org-test-with-temp-text " - A\n\n - B"
  957. (org-indent-region (point-min) (point-max))
  958. (buffer-string))))
  959. ;; Indent footnote definitions.
  960. (should
  961. (equal "[fn:1] Definition\n\nDefinition"
  962. (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
  963. (org-indent-region (point-min) (point-max))
  964. (buffer-string))))
  965. ;; Special case: Start indenting on a blank line.
  966. (should
  967. (equal "\nParagraph"
  968. (org-test-with-temp-text "\n Paragraph"
  969. (org-indent-region (point-min) (point-max))
  970. (buffer-string)))))
  971. ;;; Editing
  972. (ert-deftest test-org/delete-indentation ()
  973. "Test `org-delete-indentation' specifications."
  974. ;; Regular test.
  975. (should (equal "foo bar"
  976. (org-test-with-temp-text
  977. "foo \n bar<point>"
  978. (org-delete-indentation)
  979. (buffer-string))))
  980. ;; With optional argument.
  981. (should (equal "foo bar"
  982. (org-test-with-temp-text
  983. "foo<point> \n bar"
  984. (org-delete-indentation t)
  985. (buffer-string))))
  986. ;; At headline text should be appended to the headline text.
  987. (should
  988. (equal"* foo bar :tag:"
  989. (let (org-auto-align-tags)
  990. (org-test-with-temp-text
  991. "* foo :tag:\n bar<point>"
  992. (org-delete-indentation)
  993. (buffer-string)))))
  994. (should
  995. (equal "* foo bar :tag:"
  996. (let (org-auto-align-tags)
  997. (org-test-with-temp-text
  998. "* foo <point>:tag:\n bar"
  999. (org-delete-indentation t)
  1000. (buffer-string))))))
  1001. (ert-deftest test-org/return ()
  1002. "Test `org-return' specifications."
  1003. ;; Regular test.
  1004. (should
  1005. (equal "Para\ngraph"
  1006. (org-test-with-temp-text "Para<point>graph"
  1007. (org-return)
  1008. (buffer-string))))
  1009. ;; With optional argument, indent line.
  1010. (should
  1011. (equal " Para\n graph"
  1012. (org-test-with-temp-text " Para<point>graph"
  1013. (org-return t)
  1014. (buffer-string))))
  1015. ;; On a table, call `org-table-next-row'.
  1016. (should
  1017. (org-test-with-temp-text "| <point>a |\n| b |"
  1018. (org-return)
  1019. (looking-at-p "b")))
  1020. ;; Open link or timestamp under point when `org-return-follows-link'
  1021. ;; is non-nil.
  1022. (should
  1023. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1024. (let ((org-return-follows-link t)
  1025. (org-link-search-must-match-exact-headline nil))
  1026. (org-return))
  1027. (looking-at-p "<<target>>")))
  1028. (should-not
  1029. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1030. (let ((org-return-follows-link nil)) (org-return))
  1031. (looking-at-p "<<target>>")))
  1032. (should
  1033. (org-test-with-temp-text "* [[b][a<point>]]\n* b"
  1034. (let ((org-return-follows-link t)) (org-return))
  1035. (looking-at-p "* b")))
  1036. (should
  1037. (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
  1038. (let ((org-return-follows-link t)
  1039. (org-link-search-must-match-exact-headline nil))
  1040. (org-return))
  1041. (looking-at-p "<<target>>")))
  1042. (should-not
  1043. (org-test-with-temp-text "Link [[target]]<point> <<target>>"
  1044. (let ((org-return-follows-link t)
  1045. (org-link-search-must-match-exact-headline nil))
  1046. (org-return))
  1047. (looking-at-p "<<target>>")))
  1048. ;; When `org-return-follows-link' is non-nil, tolerate links and
  1049. ;; timestamps in comments, node properties, etc.
  1050. (should
  1051. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1052. (let ((org-return-follows-link t)
  1053. (org-link-search-must-match-exact-headline nil))
  1054. (org-return))
  1055. (looking-at-p "<<target>>")))
  1056. (should-not
  1057. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1058. (let ((org-return-follows-link nil)) (org-return))
  1059. (looking-at-p "<<target>>")))
  1060. (should-not
  1061. (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
  1062. (let ((org-return-follows-link t)
  1063. (org-link-search-must-match-exact-headline nil))
  1064. (org-return))
  1065. (looking-at-p "<<target>>")))
  1066. ;; However, do not open link when point is in a table.
  1067. (should
  1068. (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
  1069. (let ((org-return-follows-link t)) (org-return))
  1070. (looking-at-p "between")))
  1071. ;; Special case: in a list, when indenting, do not break structure.
  1072. (should
  1073. (equal "- A\n B"
  1074. (org-test-with-temp-text "- A <point>B"
  1075. (org-return t)
  1076. (buffer-string))))
  1077. (should
  1078. (equal "- A\n\n- B"
  1079. (org-test-with-temp-text "- A\n<point>- B"
  1080. (org-return t)
  1081. (buffer-string))))
  1082. ;; On tags part of a headline, add a newline below it instead of
  1083. ;; breaking it.
  1084. (should
  1085. (equal "* H :tag:\n"
  1086. (org-test-with-temp-text "* H :<point>tag:"
  1087. (org-return)
  1088. (buffer-string))))
  1089. ;; Before headline text, add a newline below it instead of breaking
  1090. ;; it.
  1091. (should
  1092. (equal "* TODO H :tag:\n"
  1093. (org-test-with-temp-text "* <point>TODO H :tag:"
  1094. (org-return)
  1095. (buffer-string))))
  1096. (should
  1097. (equal "* TODO [#B] H :tag:\n"
  1098. (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
  1099. (org-return)
  1100. (buffer-string))))
  1101. (should ;TODO are case-sensitive
  1102. (equal "* \nTodo"
  1103. (org-test-with-temp-text "* <point>Todo"
  1104. (org-return)
  1105. (buffer-string))))
  1106. ;; At headline text, break headline text but preserve tags.
  1107. (should
  1108. (equal "* TODO [#B] foo :tag:\nbar"
  1109. (let (org-auto-align-tags)
  1110. (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
  1111. (org-return)
  1112. (buffer-string)))))
  1113. ;; At bol of headline insert newline.
  1114. (should
  1115. (equal "\n* h"
  1116. (org-test-with-temp-text "<point>* h"
  1117. (org-return)
  1118. (buffer-string))))
  1119. ;; Refuse to leave invalid headline in buffer.
  1120. (should
  1121. (equal "* h\n"
  1122. (org-test-with-temp-text "*<point> h"
  1123. (org-return)
  1124. (buffer-string)))))
  1125. (ert-deftest test-org/meta-return ()
  1126. "Test M-RET (`org-meta-return') specifications."
  1127. ;; In a table field insert a row above.
  1128. (should
  1129. (org-test-with-temp-text "| a |"
  1130. (forward-char)
  1131. (org-meta-return)
  1132. (forward-line -1)
  1133. (looking-at "| |$")))
  1134. ;; In a paragraph change current line into a header.
  1135. (should
  1136. (org-test-with-temp-text "a"
  1137. (org-meta-return)
  1138. (beginning-of-line)
  1139. (looking-at "\* a$")))
  1140. ;; In an item insert an item, in this case above.
  1141. (should
  1142. (org-test-with-temp-text "- a"
  1143. (org-meta-return)
  1144. (beginning-of-line)
  1145. (looking-at "- $")))
  1146. ;; In a drawer and item insert an item, in this case above.
  1147. (should
  1148. (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
  1149. (forward-line)
  1150. (org-meta-return)
  1151. (beginning-of-line)
  1152. (looking-at "- $"))))
  1153. (ert-deftest test-org/insert-heading ()
  1154. "Test `org-insert-heading' specifications."
  1155. ;; In an empty buffer, insert a new headline.
  1156. (should
  1157. (equal "* "
  1158. (org-test-with-temp-text ""
  1159. (org-insert-heading)
  1160. (buffer-string))))
  1161. ;; At the beginning of a line, turn it into a headline
  1162. (should
  1163. (equal "* P"
  1164. (org-test-with-temp-text "<point>P"
  1165. (org-insert-heading)
  1166. (buffer-string))))
  1167. ;; In the middle of a line, split the line if allowed, otherwise,
  1168. ;; insert the headline at its end.
  1169. (should
  1170. (equal "Para\n* graph"
  1171. (org-test-with-temp-text "Para<point>graph"
  1172. (let ((org-M-RET-may-split-line '((default . t))))
  1173. (org-insert-heading))
  1174. (buffer-string))))
  1175. (should
  1176. (equal "Paragraph\n* "
  1177. (org-test-with-temp-text "Para<point>graph"
  1178. (let ((org-M-RET-may-split-line '((default . nil))))
  1179. (org-insert-heading))
  1180. (buffer-string))))
  1181. ;; At the beginning of a headline, create one above.
  1182. (should
  1183. (equal "* \n* H"
  1184. (org-test-with-temp-text "* H"
  1185. (org-insert-heading)
  1186. (buffer-string))))
  1187. ;; In the middle of a headline, split it if allowed.
  1188. (should
  1189. (equal "* H\n* 1"
  1190. (org-test-with-temp-text "* H<point>1"
  1191. (let ((org-M-RET-may-split-line '((headline . t))))
  1192. (org-insert-heading))
  1193. (buffer-string))))
  1194. (should
  1195. (equal "* H1\n* "
  1196. (org-test-with-temp-text "* H<point>1"
  1197. (let ((org-M-RET-may-split-line '((headline . nil))))
  1198. (org-insert-heading))
  1199. (buffer-string))))
  1200. ;; However, splitting cannot happen on TODO keywords, priorities or
  1201. ;; tags.
  1202. (should
  1203. (equal "* TODO H1\n* "
  1204. (org-test-with-temp-text "* TO<point>DO H1"
  1205. (let ((org-M-RET-may-split-line '((headline . t))))
  1206. (org-insert-heading))
  1207. (buffer-string))))
  1208. (should
  1209. (equal "* [#A] H1\n* "
  1210. (org-test-with-temp-text "* [#<point>A] H1"
  1211. (let ((org-M-RET-may-split-line '((headline . t))))
  1212. (org-insert-heading))
  1213. (buffer-string))))
  1214. (should
  1215. (equal "* H1 :tag:\n* "
  1216. (org-test-with-temp-text "* H1 :ta<point>g:"
  1217. (let ((org-M-RET-may-split-line '((headline . t))))
  1218. (org-insert-heading))
  1219. (buffer-string))))
  1220. ;; When on a list, insert an item instead, unless called with an
  1221. ;; universal argument or if list is invisible. In this case, create
  1222. ;; a new headline after contents.
  1223. (should
  1224. (equal "* H\n- item\n- "
  1225. (org-test-with-temp-text "* H\n- item<point>"
  1226. (let ((org-insert-heading-respect-content nil))
  1227. (org-insert-heading))
  1228. (buffer-string))))
  1229. (should
  1230. (equal "* H\n- item\n- item 2\n* "
  1231. (org-test-with-temp-text "* H\n- item<point>\n- item 2"
  1232. (let ((org-insert-heading-respect-content nil))
  1233. (org-insert-heading '(4)))
  1234. (buffer-string))))
  1235. (should
  1236. (equal "* H\n- item\n* "
  1237. (org-test-with-temp-text "* H\n- item"
  1238. (org-cycle)
  1239. (goto-char (point-max))
  1240. (let ((org-insert-heading-respect-content nil)) (org-insert-heading))
  1241. (buffer-string))))
  1242. ;; Preserve list visibility when inserting an item.
  1243. (should
  1244. (equal
  1245. '(outline outline)
  1246. (org-test-with-temp-text "- A\n - B\n- C\n - D"
  1247. (let ((org-cycle-include-plain-lists t))
  1248. (org-cycle)
  1249. (forward-line 2)
  1250. (org-cycle)
  1251. (let ((org-insert-heading-respect-content nil)) (org-insert-heading))
  1252. (list (get-char-property (line-beginning-position 0) 'invisible)
  1253. (get-char-property (line-end-position 2) 'invisible))))))
  1254. ;; When called with one universal argument, insert a new headline at
  1255. ;; the end of the current subtree, independently on the position of
  1256. ;; point.
  1257. (should
  1258. (equal
  1259. "* H1\n** H2\n* "
  1260. (org-test-with-temp-text "* H1\n** H2"
  1261. (let ((org-insert-heading-respect-content nil))
  1262. (org-insert-heading '(4)))
  1263. (buffer-string))))
  1264. (should
  1265. (equal
  1266. "* H1\n** H2\n* "
  1267. (org-test-with-temp-text "* H<point>1\n** H2"
  1268. (let ((org-insert-heading-respect-content nil))
  1269. (org-insert-heading '(4)))
  1270. (buffer-string))))
  1271. ;; When called with two universal arguments, insert a new headline
  1272. ;; at the end of the grandparent subtree.
  1273. (should
  1274. (equal "* H1\n** H3\n- item\n** H2\n** "
  1275. (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
  1276. (let ((org-insert-heading-respect-content nil))
  1277. (org-insert-heading '(16)))
  1278. (buffer-string))))
  1279. ;; When optional TOP-LEVEL argument is non-nil, always insert
  1280. ;; a level 1 heading.
  1281. (should
  1282. (equal "* H1\n** H2\n* "
  1283. (org-test-with-temp-text "* H1\n** H2<point>"
  1284. (org-insert-heading nil nil t)
  1285. (buffer-string))))
  1286. (should
  1287. (equal "* H1\n- item\n* "
  1288. (org-test-with-temp-text "* H1\n- item<point>"
  1289. (org-insert-heading nil nil t)
  1290. (buffer-string))))
  1291. ;; Corner case: correctly insert a headline after an empty one.
  1292. (should
  1293. (equal "* \n* "
  1294. (org-test-with-temp-text "* <point>"
  1295. (org-insert-heading)
  1296. (buffer-string)))))
  1297. (ert-deftest test-org/insert-todo-heading-respect-content ()
  1298. "Test `org-insert-todo-heading-respect-content' specifications."
  1299. ;; Create a TODO heading.
  1300. (should
  1301. (org-test-with-temp-text "* H1\n Body"
  1302. (org-insert-todo-heading-respect-content)
  1303. (nth 2 (org-heading-components))))
  1304. ;; Add headline at the end of the first subtree
  1305. (should
  1306. (org-test-with-temp-text "* H1\nH1Body\n** H2\nH2Body"
  1307. (search-forward "H1Body")
  1308. (org-insert-todo-heading-respect-content)
  1309. (and (eobp) (org-at-heading-p))))
  1310. ;; In a list, do not create a new item.
  1311. (should
  1312. (org-test-with-temp-text "* H\n- an item\n- another one"
  1313. (search-forward "an ")
  1314. (org-insert-todo-heading-respect-content)
  1315. (and (eobp) (org-at-heading-p)))))
  1316. (ert-deftest test-org/clone-with-time-shift ()
  1317. "Test `org-clone-subtree-with-time-shift'."
  1318. ;; Raise an error before first heading.
  1319. (should-error
  1320. (org-test-with-temp-text ""
  1321. (org-clone-subtree-with-time-shift 1)))
  1322. ;; Raise an error on invalid number of clones.
  1323. (should-error
  1324. (org-test-with-temp-text "* Clone me"
  1325. (org-clone-subtree-with-time-shift -1)))
  1326. ;; Clone non-repeating once.
  1327. (should
  1328. (equal "\
  1329. * H1\n<2015-06-21>
  1330. * H1\n<2015-06-23>
  1331. "
  1332. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1333. (org-clone-subtree-with-time-shift 1 "+2d")
  1334. (replace-regexp-in-string
  1335. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1336. nil nil 1))))
  1337. ;; Clone repeating once.
  1338. (should
  1339. (equal "\
  1340. * H1\n<2015-06-21>
  1341. * H1\n<2015-06-23>
  1342. * H1\n<2015-06-25 +1w>
  1343. "
  1344. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1345. (org-clone-subtree-with-time-shift 1 "+2d")
  1346. (replace-regexp-in-string
  1347. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1348. nil nil 1))))
  1349. ;; Clone non-repeating zero times.
  1350. (should
  1351. (equal "\
  1352. * H1\n<2015-06-21>
  1353. "
  1354. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1355. (org-clone-subtree-with-time-shift 0 "+2d")
  1356. (replace-regexp-in-string
  1357. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1358. nil nil 1))))
  1359. ;; Clone repeating "zero" times.
  1360. (should
  1361. (equal "\
  1362. * H1\n<2015-06-21>
  1363. * H1\n<2015-06-23 +1w>
  1364. "
  1365. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1366. (org-clone-subtree-with-time-shift 0 "+2d")
  1367. (replace-regexp-in-string
  1368. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1369. nil nil 1))))
  1370. ;; Clone with blank SHIFT argument.
  1371. (should
  1372. (string-prefix-p
  1373. "* H <2012-03-29"
  1374. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1375. (org-clone-subtree-with-time-shift 1 "")
  1376. (buffer-substring-no-properties (line-beginning-position 2)
  1377. (line-end-position 2)))))
  1378. ;; Find time stamps before point. If SHIFT is not specified, ask
  1379. ;; for a time shift.
  1380. (should
  1381. (string-prefix-p
  1382. "* H <2012-03-30"
  1383. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1384. (org-clone-subtree-with-time-shift 1 "+1d")
  1385. (buffer-substring-no-properties (line-beginning-position 2)
  1386. (line-end-position 2)))))
  1387. (should
  1388. (string-prefix-p
  1389. "* H <2014-03-05"
  1390. (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
  1391. (cl-letf (((symbol-function 'read-from-minibuffer)
  1392. (lambda (&rest args) "+1d")))
  1393. (org-clone-subtree-with-time-shift 1))
  1394. (buffer-substring-no-properties (line-beginning-position 2)
  1395. (line-end-position 2))))))
  1396. ;;; Fixed-Width Areas
  1397. (ert-deftest test-org/toggle-fixed-width ()
  1398. "Test `org-toggle-fixed-width' specifications."
  1399. ;; No region: Toggle on fixed-width marker in paragraphs.
  1400. (should
  1401. (equal ": A"
  1402. (org-test-with-temp-text "A"
  1403. (org-toggle-fixed-width)
  1404. (buffer-string))))
  1405. ;; No region: Toggle off fixed-width markers in fixed-width areas.
  1406. (should
  1407. (equal "A"
  1408. (org-test-with-temp-text ": A"
  1409. (org-toggle-fixed-width)
  1410. (buffer-string))))
  1411. ;; No region: Toggle on marker in blank lines after elements or just
  1412. ;; after a headline.
  1413. (should
  1414. (equal "* H\n: "
  1415. (org-test-with-temp-text "* H\n"
  1416. (forward-line)
  1417. (org-toggle-fixed-width)
  1418. (buffer-string))))
  1419. (should
  1420. (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
  1421. (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
  1422. (goto-char (point-max))
  1423. (org-toggle-fixed-width)
  1424. (buffer-string))))
  1425. ;; No region: Toggle on marker in front of one line elements (e.g.,
  1426. ;; headlines, clocks)
  1427. (should
  1428. (equal ": * Headline"
  1429. (org-test-with-temp-text "* Headline"
  1430. (org-toggle-fixed-width)
  1431. (buffer-string))))
  1432. (should
  1433. (equal ": #+KEYWORD: value"
  1434. (org-test-with-temp-text "#+KEYWORD: value"
  1435. (org-toggle-fixed-width)
  1436. (buffer-string))))
  1437. ;; No region: error in other situations.
  1438. (should-error
  1439. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
  1440. (forward-line)
  1441. (org-toggle-fixed-width)
  1442. (buffer-string)))
  1443. ;; No region: Indentation is preserved.
  1444. (should
  1445. (equal "- A\n : B"
  1446. (org-test-with-temp-text "- A\n B"
  1447. (forward-line)
  1448. (org-toggle-fixed-width)
  1449. (buffer-string))))
  1450. ;; Region: If it contains only fixed-width elements and blank lines,
  1451. ;; toggle off fixed-width markup.
  1452. (should
  1453. (equal "A\n\nB"
  1454. (org-test-with-temp-text ": A\n\n: B"
  1455. (transient-mark-mode 1)
  1456. (push-mark (point) t t)
  1457. (goto-char (point-max))
  1458. (org-toggle-fixed-width)
  1459. (buffer-string))))
  1460. ;; Region: If it contains anything else, toggle on fixed-width but
  1461. ;; not on fixed-width areas.
  1462. (should
  1463. (equal ": A\n: \n: B\n: \n: C"
  1464. (org-test-with-temp-text "A\n\n: B\n\nC"
  1465. (transient-mark-mode 1)
  1466. (push-mark (point) t t)
  1467. (goto-char (point-max))
  1468. (org-toggle-fixed-width)
  1469. (buffer-string))))
  1470. ;; Region: Ignore blank lines at its end, unless it contains only
  1471. ;; such lines.
  1472. (should
  1473. (equal ": A\n\n"
  1474. (org-test-with-temp-text "A\n\n"
  1475. (transient-mark-mode 1)
  1476. (push-mark (point) t t)
  1477. (goto-char (point-max))
  1478. (org-toggle-fixed-width)
  1479. (buffer-string))))
  1480. (should
  1481. (equal ": \n: \n"
  1482. (org-test-with-temp-text "\n\n"
  1483. (transient-mark-mode 1)
  1484. (push-mark (point) t t)
  1485. (goto-char (point-max))
  1486. (org-toggle-fixed-width)
  1487. (buffer-string)))))
  1488. ;;; Headline
  1489. (ert-deftest test-org/get-heading ()
  1490. "Test `org-get-heading' specifications."
  1491. ;; Return current heading, even if point is not on it.
  1492. (should
  1493. (equal "H"
  1494. (org-test-with-temp-text "* H"
  1495. (org-get-heading))))
  1496. (should
  1497. (equal "H"
  1498. (org-test-with-temp-text "* H\nText<point>"
  1499. (org-get-heading))))
  1500. ;; Without any optional argument, return TODO keywords and tags.
  1501. (should
  1502. (equal "TODO H"
  1503. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  1504. (org-get-heading))))
  1505. (should
  1506. (equal "H :tag:"
  1507. (org-test-with-temp-text "* H :tag:"
  1508. (org-get-heading))))
  1509. ;; With NO-TAGS argument, ignore tags.
  1510. (should
  1511. (equal "TODO H"
  1512. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  1513. (org-get-heading t))))
  1514. (should
  1515. (equal "H"
  1516. (org-test-with-temp-text "* H :tag:"
  1517. (org-get-heading t))))
  1518. ;; With NO-TODO, ignore TODO keyword.
  1519. (should
  1520. (equal "H"
  1521. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  1522. (org-get-heading nil t))))
  1523. (should
  1524. (equal "H :tag:"
  1525. (org-test-with-temp-text "* H :tag:"
  1526. (org-get-heading nil t))))
  1527. ;; TODO keywords are case-sensitive.
  1528. (should
  1529. (equal "Todo H"
  1530. (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
  1531. (org-get-heading nil t))))
  1532. ;; On an empty headline, return value is consistent.
  1533. (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
  1534. (should (equal "" (org-test-with-temp-text "* " (org-get-heading t))))
  1535. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t))))
  1536. (should (equal "" (org-test-with-temp-text "* " (org-get-heading t t)))))
  1537. (ert-deftest test-org/in-commented-heading-p ()
  1538. "Test `org-in-commented-heading-p' specifications."
  1539. ;; Commented headline.
  1540. (should
  1541. (org-test-with-temp-text "* COMMENT Headline\nBody"
  1542. (goto-char (point-max))
  1543. (org-in-commented-heading-p)))
  1544. ;; Commented ancestor.
  1545. (should
  1546. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  1547. (goto-char (point-max))
  1548. (org-in-commented-heading-p)))
  1549. ;; Comment keyword is case-sensitive.
  1550. (should-not
  1551. (org-test-with-temp-text "* Comment Headline\nBody"
  1552. (goto-char (point-max))
  1553. (org-in-commented-heading-p)))
  1554. ;; Keyword is standalone.
  1555. (should-not
  1556. (org-test-with-temp-text "* COMMENTHeadline\nBody"
  1557. (goto-char (point-max))
  1558. (org-in-commented-heading-p)))
  1559. ;; Optional argument.
  1560. (should-not
  1561. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  1562. (goto-char (point-max))
  1563. (org-in-commented-heading-p t))))
  1564. (ert-deftest test-org/entry-blocked-p ()
  1565. ;; Check other dependencies.
  1566. (should
  1567. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  1568. (let ((org-enforce-todo-dependencies t)
  1569. (org-blocker-hook
  1570. '(org-block-todo-from-children-or-siblings-or-parent)))
  1571. (org-entry-blocked-p))))
  1572. (should-not
  1573. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  1574. (let ((org-enforce-todo-dependencies t)
  1575. (org-blocker-hook
  1576. '(org-block-todo-from-children-or-siblings-or-parent)))
  1577. (org-entry-blocked-p))))
  1578. ;; Entry without a TODO keyword or with a DONE keyword cannot be
  1579. ;; blocked.
  1580. (should-not
  1581. (org-test-with-temp-text "* Blocked\n** TODO one"
  1582. (let ((org-enforce-todo-dependencies t)
  1583. (org-blocker-hook
  1584. '(org-block-todo-from-children-or-siblings-or-parent)))
  1585. (org-entry-blocked-p))))
  1586. (should-not
  1587. (org-test-with-temp-text "* DONE Blocked\n** TODO one"
  1588. (let ((org-enforce-todo-dependencies t)
  1589. (org-blocker-hook
  1590. '(org-block-todo-from-children-or-siblings-or-parent)))
  1591. (org-entry-blocked-p))))
  1592. ;; Follow :ORDERED: specifications.
  1593. (should
  1594. (org-test-with-temp-text
  1595. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
  1596. (let ((org-enforce-todo-dependencies t)
  1597. (org-blocker-hook
  1598. '(org-block-todo-from-children-or-siblings-or-parent)))
  1599. (org-entry-blocked-p))))
  1600. (should-not
  1601. (org-test-with-temp-text
  1602. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
  1603. (let ((org-enforce-todo-dependencies t)
  1604. (org-blocker-hook
  1605. '(org-block-todo-from-children-or-siblings-or-parent)))
  1606. (org-entry-blocked-p)))))
  1607. (ert-deftest test-org/get-outline-path ()
  1608. "Test `org-get-outline-path' specifications."
  1609. ;; Top-level headlines have no outline path.
  1610. (should-not
  1611. (org-test-with-temp-text "* H"
  1612. (org-get-outline-path)))
  1613. ;; Otherwise, outline path is the path leading to the headline.
  1614. (should
  1615. (equal '("H")
  1616. (org-test-with-temp-text "* H\n** S<point>"
  1617. (org-get-outline-path))))
  1618. ;; Find path even when point is not on a headline.
  1619. (should
  1620. (equal '("H")
  1621. (org-test-with-temp-text "* H\n** S\nText<point>"
  1622. (org-get-outline-path))))
  1623. ;; TODO keywords, tags and statistics cookies are ignored.
  1624. (should
  1625. (equal '("H")
  1626. (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
  1627. (org-get-outline-path))))
  1628. ;; Links are replaced with their description or their path.
  1629. (should
  1630. (equal '("Org")
  1631. (org-test-with-temp-text
  1632. "* [[http://orgmode.org][Org]]\n** S<point>"
  1633. (org-get-outline-path))))
  1634. (should
  1635. (equal '("http://orgmode.org")
  1636. (org-test-with-temp-text
  1637. "* [[http://orgmode.org]]\n** S<point>"
  1638. (org-get-outline-path))))
  1639. ;; When WITH-SELF is non-nil, include current heading.
  1640. (should
  1641. (equal '("H")
  1642. (org-test-with-temp-text "* H"
  1643. (org-get-outline-path t))))
  1644. (should
  1645. (equal '("H" "S")
  1646. (org-test-with-temp-text "* H\n** S\nText<point>"
  1647. (org-get-outline-path t))))
  1648. ;; Using cache is transparent to the user.
  1649. (should
  1650. (equal '("H")
  1651. (org-test-with-temp-text "* H\n** S<point>"
  1652. (setq org-outline-path-cache nil)
  1653. (org-get-outline-path nil t))))
  1654. ;; Do not corrupt cache when finding outline path in distant part of
  1655. ;; the buffer.
  1656. (should
  1657. (equal '("H2")
  1658. (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
  1659. (setq org-outline-path-cache nil)
  1660. (org-get-outline-path nil t)
  1661. (search-forward "S2")
  1662. (org-get-outline-path nil t))))
  1663. ;; Do not choke on empty headlines.
  1664. (should
  1665. (org-test-with-temp-text "* H\n** <point>"
  1666. (org-get-outline-path)))
  1667. (should
  1668. (org-test-with-temp-text "* \n** H<point>"
  1669. (org-get-outline-path))))
  1670. (ert-deftest test-org/format-outline-path ()
  1671. "Test `org-format-outline-path' specifications."
  1672. (should
  1673. (string= (org-format-outline-path (list "one" "two" "three"))
  1674. "one/two/three"))
  1675. ;; Empty path.
  1676. (should
  1677. (string= (org-format-outline-path '())
  1678. ""))
  1679. (should
  1680. (string= (org-format-outline-path '(nil))
  1681. ""))
  1682. ;; Empty path and prefix.
  1683. (should
  1684. (string= (org-format-outline-path '() nil ">>")
  1685. ">>"))
  1686. ;; Trailing whitespace in headings.
  1687. (should
  1688. (string= (org-format-outline-path (list "one\t" "tw o " "three "))
  1689. "one/tw o/three"))
  1690. ;; Non-default prefix and separators.
  1691. (should
  1692. (string= (org-format-outline-path (list "one" "two" "three") nil ">>" "|")
  1693. ">>|one|two|three"))
  1694. ;; Truncate.
  1695. (should
  1696. (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
  1697. "one/two/.."))
  1698. ;; Give a very narrow width.
  1699. (should
  1700. (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
  1701. "on"))
  1702. ;; Give a prefix that extends beyond the width.
  1703. (should
  1704. (string= (org-format-outline-path (list "one" "two" "three" "four") 10
  1705. ">>>>>>>>>>")
  1706. ">>>>>>>>..")))
  1707. (ert-deftest test-org/map-entries ()
  1708. "Test `org-map-entries' specifications."
  1709. ;; Full match.
  1710. (should
  1711. (equal '(1 11)
  1712. (org-test-with-temp-text "* Level 1\n** Level 2"
  1713. (org-map-entries #'point))))
  1714. ;; Level match.
  1715. (should
  1716. (equal '(1)
  1717. (org-test-with-temp-text "* Level 1\n** Level 2"
  1718. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL=1")))))
  1719. (should
  1720. (equal '(11)
  1721. (org-test-with-temp-text "* Level 1\n** Level 2"
  1722. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL>1")))))
  1723. ;; Tag match.
  1724. (should
  1725. (equal '(11)
  1726. (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
  1727. (org-map-entries #'point "yes"))))
  1728. (should
  1729. (equal '(14)
  1730. (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
  1731. (org-map-entries #'point "+yes-a"))))
  1732. (should
  1733. (equal '(11 23)
  1734. (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
  1735. (org-map-entries #'point "{yes?}"))))
  1736. ;; Priority match.
  1737. (should
  1738. (equal '(1)
  1739. (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
  1740. (org-map-entries #'point "PRIORITY=\"A\""))))
  1741. ;; Date match.
  1742. (should
  1743. (equal '(36)
  1744. (org-test-with-temp-text "
  1745. * H1
  1746. SCHEDULED: <2012-03-29 thu.>
  1747. * H2
  1748. SCHEDULED: <2014-03-04 tue.>"
  1749. (org-map-entries #'point "SCHEDULED=\"<2014-03-04 tue.>\""))))
  1750. (should
  1751. (equal '(2)
  1752. (org-test-with-temp-text "
  1753. * H1
  1754. SCHEDULED: <2012-03-29 thu.>
  1755. * H2
  1756. SCHEDULED: <2014-03-04 tue.>"
  1757. (org-map-entries #'point "SCHEDULED<\"<2013-01-01>\""))))
  1758. ;; Regular property match.
  1759. (should
  1760. (equal '(2)
  1761. (org-test-with-temp-text "
  1762. * H1
  1763. :PROPERTIES:
  1764. :TEST: 1
  1765. :END:
  1766. * H2
  1767. :PROPERTIES:
  1768. :TEST: 2
  1769. :END:"
  1770. (org-map-entries #'point "TEST=1"))))
  1771. ;; Multiple criteria.
  1772. (should
  1773. (equal '(23)
  1774. (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
  1775. (let (org-odd-levels-only
  1776. (org-use-tag-inheritance nil))
  1777. (org-map-entries #'point "yes+LEVEL=1")))))
  1778. ;; "or" criteria.
  1779. (should
  1780. (equal '(12 24)
  1781. (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
  1782. (let (org-odd-levels-only)
  1783. (org-map-entries #'point "LEVEL=2|no")))))
  1784. (should
  1785. (equal '(1 12)
  1786. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
  1787. (let (org-odd-levels-only)
  1788. (org-map-entries #'point "yes|no")))))
  1789. ;; "and" criteria.
  1790. (should
  1791. (equal '(22)
  1792. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
  1793. (let (org-odd-levels-only)
  1794. (org-map-entries #'point "yes&no"))))))
  1795. (ert-deftest test-org/edit-headline ()
  1796. "Test `org-edit-headline' specifications."
  1797. (should
  1798. (equal "* B"
  1799. (org-test-with-temp-text "* A"
  1800. (org-edit-headline "B")
  1801. (buffer-string))))
  1802. ;; Handle empty headings.
  1803. (should
  1804. (equal "* "
  1805. (org-test-with-temp-text "* A"
  1806. (org-edit-headline "")
  1807. (buffer-string))))
  1808. (should
  1809. (equal "* A"
  1810. (org-test-with-temp-text "* "
  1811. (org-edit-headline "A")
  1812. (buffer-string))))
  1813. ;; Handle TODO keywords and priority cookies.
  1814. (should
  1815. (equal "* TODO B"
  1816. (org-test-with-temp-text "* TODO A"
  1817. (org-edit-headline "B")
  1818. (buffer-string))))
  1819. (should
  1820. (equal "* [#A] B"
  1821. (org-test-with-temp-text "* [#A] A"
  1822. (org-edit-headline "B")
  1823. (buffer-string))))
  1824. (should
  1825. (equal "* TODO [#A] B"
  1826. (org-test-with-temp-text "* TODO [#A] A"
  1827. (org-edit-headline "B")
  1828. (buffer-string))))
  1829. ;; Handle tags.
  1830. (equal "* B :tag:"
  1831. (org-test-with-temp-text "* A :tag:"
  1832. (let ((org-tags-column 4)) (org-edit-headline "B"))
  1833. (buffer-string))))
  1834. ;;; Keywords
  1835. (ert-deftest test-org/set-regexps-and-options ()
  1836. "Test `org-set-regexps-and-options' specifications."
  1837. ;; TAGS keyword.
  1838. (should
  1839. (equal '(("A"))
  1840. (let ((org-tag-alist '(("A")))
  1841. (org-tag-persistent-alist nil))
  1842. (org-test-with-temp-text ""
  1843. (org-mode-restart)
  1844. org-current-tag-alist))))
  1845. (should
  1846. (equal '(("B"))
  1847. (let ((org-tag-alist '(("A")))
  1848. (org-tag-persistent-alist nil))
  1849. (org-test-with-temp-text "#+TAGS: B"
  1850. (org-mode-restart)
  1851. org-current-tag-alist))))
  1852. (should
  1853. (equal '(("C") ("B"))
  1854. (let ((org-tag-alist '(("A")))
  1855. (org-tag-persistent-alist '(("C"))))
  1856. (org-test-with-temp-text "#+TAGS: B"
  1857. (org-mode-restart)
  1858. org-current-tag-alist))))
  1859. (should
  1860. (equal '(("B"))
  1861. (let ((org-tag-alist '(("A")))
  1862. (org-tag-persistent-alist '(("C"))))
  1863. (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
  1864. (org-mode-restart)
  1865. org-current-tag-alist))))
  1866. (should
  1867. (equal '(("A" . ?a) ("B") ("C"))
  1868. (let ((org-tag-persistant-alist nil))
  1869. (org-test-with-temp-text "#+TAGS: A(a) B C"
  1870. (org-mode-restart)
  1871. org-current-tag-alist))))
  1872. (should
  1873. (equal '(("A") (:newline) ("B"))
  1874. (let ((org-tag-persistent-alist nil))
  1875. (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
  1876. (org-mode-restart)
  1877. org-current-tag-alist))))
  1878. (should
  1879. (equal '((:startgroup) ("A") ("B") (:endgroup) ("C"))
  1880. (let ((org-tag-persistent-alist nil))
  1881. (org-test-with-temp-text "#+TAGS: { A B } C"
  1882. (org-mode-restart)
  1883. org-current-tag-alist))))
  1884. (should
  1885. (equal '((:startgroup) ("A") (:grouptags) ("B") ("C") (:endgroup))
  1886. (let ((org-tag-persistent-alist nil))
  1887. (org-test-with-temp-text "#+TAGS: { A : B C }"
  1888. (org-mode-restart)
  1889. org-current-tag-alist))))
  1890. (should
  1891. (equal '(("A" "B" "C"))
  1892. (let ((org-tag-persistent-alist nil))
  1893. (org-test-with-temp-text "#+TAGS: { A : B C }"
  1894. (org-mode-restart)
  1895. org-tag-groups-alist))))
  1896. (should
  1897. (equal '((:startgrouptag) ("A") (:grouptags) ("B") ("C") (:endgrouptag))
  1898. (let ((org-tag-persistent-alist nil))
  1899. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  1900. (org-mode-restart)
  1901. org-current-tag-alist))))
  1902. (should
  1903. (equal '(("A" "B" "C"))
  1904. (let ((org-tag-persistent-alist nil))
  1905. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  1906. (org-mode-restart)
  1907. org-tag-groups-alist))))
  1908. ;; FILETAGS keyword.
  1909. (should
  1910. (equal '("A" "B" "C")
  1911. (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
  1912. (org-mode-restart)
  1913. org-file-tags)))
  1914. ;; PROPERTY keyword. Property names are case-insensitive.
  1915. (should
  1916. (equal "foo=1"
  1917. (org-test-with-temp-text "#+PROPERTY: var foo=1"
  1918. (org-mode-restart)
  1919. (cdr (assoc "var" org-file-properties)))))
  1920. (should
  1921. (equal
  1922. "foo=1 bar=2"
  1923. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
  1924. (org-mode-restart)
  1925. (cdr (assoc "var" org-file-properties)))))
  1926. (should
  1927. (equal
  1928. "foo=1 bar=2"
  1929. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
  1930. (org-mode-restart)
  1931. (cdr (assoc "var" org-file-properties)))))
  1932. ;; ARCHIVE keyword.
  1933. (should
  1934. (equal "%s_done::"
  1935. (org-test-with-temp-text "#+ARCHIVE: %s_done::"
  1936. (org-mode-restart)
  1937. org-archive-location)))
  1938. ;; CATEGORY keyword.
  1939. (should
  1940. (eq 'test
  1941. (org-test-with-temp-text "#+CATEGORY: test"
  1942. (org-mode-restart)
  1943. org-category)))
  1944. (should
  1945. (equal "test"
  1946. (org-test-with-temp-text "#+CATEGORY: test"
  1947. (org-mode-restart)
  1948. (cdr (assoc "CATEGORY" org-file-properties)))))
  1949. ;; COLUMNS keyword.
  1950. (should
  1951. (equal "%25ITEM %TAGS %PRIORITY %TODO"
  1952. (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
  1953. (org-mode-restart)
  1954. org-columns-default-format)))
  1955. ;; CONSTANTS keyword. Constants names are case sensitive.
  1956. (should
  1957. (equal '("299792458." "3.14")
  1958. (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
  1959. (org-mode-restart)
  1960. (mapcar
  1961. (lambda (n) (cdr (assoc n org-table-formula-constants-local)))
  1962. '("c" "pi")))))
  1963. (should
  1964. (equal "3.14"
  1965. (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
  1966. (org-mode-restart)
  1967. (cdr (assoc "pi" org-table-formula-constants-local)))))
  1968. (should
  1969. (equal "22/7"
  1970. (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
  1971. (org-mode-restart)
  1972. (cdr (assoc "PI" org-table-formula-constants-local)))))
  1973. ;; LINK keyword.
  1974. (should
  1975. (equal
  1976. '("url1" "url2")
  1977. (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
  1978. (org-mode-restart)
  1979. (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local)))
  1980. '("a" "b")))))
  1981. ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
  1982. (should
  1983. (equal
  1984. '(?X ?Z ?Y)
  1985. (org-test-with-temp-text "#+PRIORITIES: X Z Y"
  1986. (org-mode-restart)
  1987. (list org-highest-priority org-lowest-priority org-default-priority))))
  1988. (should
  1989. (equal
  1990. '(?A ?C ?B)
  1991. (org-test-with-temp-text "#+PRIORITIES: X Z"
  1992. (org-mode-restart)
  1993. (list org-highest-priority org-lowest-priority org-default-priority))))
  1994. ;; STARTUP keyword.
  1995. (should
  1996. (equal '(t t)
  1997. (org-test-with-temp-text "#+STARTUP: fold odd"
  1998. (org-mode-restart)
  1999. (list org-startup-folded org-odd-levels-only))))
  2000. ;; TODO keywords.
  2001. (should
  2002. (equal '(("A" "B") ("C"))
  2003. (org-test-with-temp-text "#+TODO: A B | C"
  2004. (org-mode-restart)
  2005. (list org-not-done-keywords org-done-keywords))))
  2006. (should
  2007. (equal '(("A" "C") ("B" "D"))
  2008. (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
  2009. (org-mode-restart)
  2010. (list org-not-done-keywords org-done-keywords))))
  2011. (should
  2012. (equal '(("A" "B") ("C"))
  2013. (org-test-with-temp-text "#+TYP_TODO: A B | C"
  2014. (org-mode-restart)
  2015. (list org-not-done-keywords org-done-keywords))))
  2016. (should
  2017. (equal '((:startgroup) ("A" . ?a) (:endgroup))
  2018. (org-test-with-temp-text "#+TODO: A(a)"
  2019. (org-mode-restart)
  2020. org-todo-key-alist)))
  2021. (should
  2022. (equal '(("D" note nil) ("C" time nil) ("B" note time))
  2023. (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
  2024. (org-mode-restart)
  2025. org-todo-log-states)))
  2026. ;; Enter SETUPFILE keyword.
  2027. (should
  2028. (equal "1"
  2029. (org-test-with-temp-text
  2030. (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
  2031. (org-mode-restart)
  2032. (cdr (assoc "a" org-file-properties))))))
  2033. ;;; Links
  2034. ;;;; Coderefs
  2035. (ert-deftest test-org/coderef ()
  2036. "Test coderef links specifications."
  2037. (should
  2038. (org-test-with-temp-text "
  2039. #+BEGIN_SRC emacs-lisp
  2040. \(+ 1 1) (ref:sc)
  2041. #+END_SRC
  2042. \[[(sc)<point>]]"
  2043. (org-open-at-point)
  2044. (looking-at "(ref:sc)")))
  2045. ;; Find coderef even with alternate label format.
  2046. (should
  2047. (org-test-with-temp-text "
  2048. #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
  2049. \(+ 1 1) {ref:sc}
  2050. #+END_SRC
  2051. \[[(sc)<point>]]"
  2052. (org-open-at-point)
  2053. (looking-at "{ref:sc}"))))
  2054. ;;;; Custom ID
  2055. (ert-deftest test-org/custom-id ()
  2056. "Test custom ID links specifications."
  2057. (should
  2058. (org-test-with-temp-text
  2059. "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2060. (org-open-at-point)
  2061. (looking-at-p "\\* H1")))
  2062. ;; Throw an error on false positives.
  2063. (should-error
  2064. (org-test-with-temp-text
  2065. "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2066. (org-open-at-point)
  2067. (looking-at-p "\\* H1"))))
  2068. ;;;; Fuzzy Links
  2069. ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
  2070. ;; a named element (#+name: text) and to headlines (* Text).
  2071. (ert-deftest test-org/fuzzy-links ()
  2072. "Test fuzzy links specifications."
  2073. ;; Fuzzy link goes in priority to a matching target.
  2074. (should
  2075. (org-test-with-temp-text
  2076. "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
  2077. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2078. (looking-at "<<Test>>")))
  2079. ;; Then fuzzy link points to an element with a given name.
  2080. (should
  2081. (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
  2082. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2083. (looking-at "#\\+NAME: Test")))
  2084. ;; A target still lead to a matching headline otherwise.
  2085. (should
  2086. (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
  2087. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2088. (looking-at "\\* Head2")))
  2089. ;; With a leading star in link, enforce heading match.
  2090. (should
  2091. (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
  2092. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2093. (looking-at "\\* Test")))
  2094. ;; With a leading star in link, enforce exact heading match, even
  2095. ;; with `org-link-search-must-match-exact-headline' set to nil.
  2096. (should-error
  2097. (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
  2098. (let ((org-link-search-must-match-exact-headline nil))
  2099. (org-open-at-point))))
  2100. ;; Handle non-nil `org-link-search-must-match-exact-headline'.
  2101. (should
  2102. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
  2103. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2104. (looking-at "\\* Test")))
  2105. (should
  2106. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
  2107. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2108. (looking-at "\\* Test")))
  2109. ;; Heading match should not care about spaces, cookies, TODO
  2110. ;; keywords, priorities, and tags. However, TODO keywords are
  2111. ;; case-sensitive.
  2112. (should
  2113. (let ((first-line
  2114. "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
  2115. (org-test-with-temp-text
  2116. (concat first-line "\nFoo Bar\n<point>[[*Test 1 2]]")
  2117. (let ((org-link-search-must-match-exact-headline nil)
  2118. (org-todo-regexp "TODO"))
  2119. (org-open-at-point))
  2120. (looking-at (regexp-quote first-line)))))
  2121. (should-error
  2122. (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
  2123. (let ((org-link-search-must-match-exact-headline nil)
  2124. (org-todo-regexp "TODO"))
  2125. (org-open-at-point))))
  2126. ;; Heading match should still be exact.
  2127. (should-error
  2128. (org-test-with-temp-text "
  2129. ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
  2130. Foo Bar
  2131. <point>[[*Test 1]]"
  2132. (let ((org-link-search-must-match-exact-headline nil)
  2133. (org-todo-regexp "TODO"))
  2134. (org-open-at-point))))
  2135. (should
  2136. (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
  2137. (let ((org-link-search-must-match-exact-headline nil)
  2138. (org-todo-regexp "TODO"))
  2139. (org-open-at-point))
  2140. (looking-at-p (regexp-quote "** Test 1 2"))))
  2141. ;; Heading match ignores COMMENT keyword.
  2142. (should
  2143. (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
  2144. (org-open-at-point)
  2145. (looking-at "\\* COMMENT Test")))
  2146. (should
  2147. (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
  2148. (org-open-at-point)
  2149. (looking-at "\\* TODO COMMENT Test")))
  2150. ;; Correctly un-hexify fuzzy links.
  2151. (should
  2152. (org-test-with-temp-text "* With space\n[[*With%20space][With space<point>]]"
  2153. (org-open-at-point)
  2154. (bobp)))
  2155. (should
  2156. (org-test-with-temp-text "* [1]\n[[*%5B1%5D<point>]]"
  2157. (org-open-at-point)
  2158. (bobp)))
  2159. ;; Match search strings containing newline characters, including
  2160. ;; blank lines.
  2161. (should
  2162. (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
  2163. (let ((file (buffer-file-name)))
  2164. (goto-char (point-max))
  2165. (insert (format "[[file:%s::line1 line2]]" file))
  2166. (beginning-of-line)
  2167. (let ((org-link-search-must-match-exact-headline nil))
  2168. (org-open-at-point 0))
  2169. (looking-at-p "line1"))))
  2170. (should
  2171. (org-test-with-temp-text-in-file "Paragraph\n\nline1\n\nline2\n\n"
  2172. (let ((file (buffer-file-name)))
  2173. (goto-char (point-max))
  2174. (insert (format "[[file:%s::line1 line2]]" file))
  2175. (beginning-of-line)
  2176. (let ((org-link-search-must-match-exact-headline nil))
  2177. (org-open-at-point 0))
  2178. (looking-at-p "line1")))))
  2179. ;;;; Link Escaping
  2180. (ert-deftest test-org/org-link-escape-ascii-character ()
  2181. "Escape an ascii character."
  2182. (should
  2183. (string=
  2184. "%5B"
  2185. (org-link-escape "["))))
  2186. (ert-deftest test-org/org-link-escape-ascii-ctrl-character ()
  2187. "Escape an ascii control character."
  2188. (should
  2189. (string=
  2190. "%09"
  2191. (org-link-escape "\t"))))
  2192. (ert-deftest test-org/org-link-escape-multibyte-character ()
  2193. "Escape an unicode multibyte character."
  2194. (should
  2195. (string=
  2196. "%E2%82%AC"
  2197. (org-link-escape "€"))))
  2198. (ert-deftest test-org/org-link-escape-custom-table ()
  2199. "Escape string with custom character table."
  2200. (should
  2201. (string=
  2202. "Foo%3A%42ar%0A"
  2203. (org-link-escape "Foo:Bar\n" '(?\: ?\B)))))
  2204. (ert-deftest test-org/org-link-escape-custom-table-merge ()
  2205. "Escape string with custom table merged with default table."
  2206. (should
  2207. (string=
  2208. "%5BF%6F%6F%3A%42ar%0A%5D"
  2209. (org-link-escape "[Foo:Bar\n]" '(?\: ?\B ?\o) t))))
  2210. (ert-deftest test-org/org-link-unescape-ascii-character ()
  2211. "Unescape an ascii character."
  2212. (should
  2213. (string=
  2214. "["
  2215. (org-link-unescape "%5B"))))
  2216. (ert-deftest test-org/org-link-unescape-ascii-ctrl-character ()
  2217. "Unescpae an ascii control character."
  2218. (should
  2219. (string=
  2220. "\n"
  2221. (org-link-unescape "%0A"))))
  2222. (ert-deftest test-org/org-link-unescape-multibyte-character ()
  2223. "Unescape unicode multibyte character."
  2224. (should
  2225. (string=
  2226. "€"
  2227. (org-link-unescape "%E2%82%AC"))))
  2228. (ert-deftest test-org/org-link-unescape-ascii-extended-char ()
  2229. "Unescape old style percent escaped character."
  2230. (should
  2231. (string=
  2232. "àâçèéêîôùû"
  2233. (decode-coding-string
  2234. (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1))))
  2235. (ert-deftest test-org/org-link-escape-url-with-escaped-char ()
  2236. "Escape and unescape a URL that includes an escaped char.
  2237. http://article.gmane.org/gmane.emacs.orgmode/21459/"
  2238. (should
  2239. (string=
  2240. "http://some.host.com/form?&id=blah%2Bblah25"
  2241. (org-link-unescape
  2242. (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
  2243. ;;;; Open at point
  2244. (ert-deftest test-org/open-at-point/keyword ()
  2245. "Does `org-open-at-point' open link in a keyword line?"
  2246. (should
  2247. (org-test-with-temp-text
  2248. "<<top>>\n#+KEYWORD: <point>[[top]]"
  2249. (org-open-at-point) t))
  2250. (should
  2251. (org-test-with-temp-text
  2252. "* H\n<<top>>\n#+KEYWORD: <point>[[top]]"
  2253. (org-open-at-point) t)))
  2254. (ert-deftest test-org/open-at-point/property ()
  2255. "Does `org-open-at-point' open link in property drawer?"
  2256. (should
  2257. (org-test-with-temp-text
  2258. "* Headline
  2259. :PROPERTIES:
  2260. :URL: <point>[[*Headline]]
  2261. :END:"
  2262. (org-open-at-point) t)))
  2263. (ert-deftest test-org/open-at-point/comment ()
  2264. "Does `org-open-at-point' open link in a commented line?"
  2265. (should
  2266. (org-test-with-temp-text
  2267. "<<top>>\n# <point>[[top]]"
  2268. (org-open-at-point) t))
  2269. (should
  2270. (org-test-with-temp-text
  2271. "* H\n<<top>>\n# <point>[[top]]"
  2272. (org-open-at-point) t)))
  2273. (ert-deftest test-org/open-at-point/inline-image ()
  2274. "Test `org-open-at-point' on nested links."
  2275. (should
  2276. (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
  2277. (org-open-at-point)
  2278. (bobp))))
  2279. (ert-deftest test-org/open-at-point/radio-target ()
  2280. "Test `org-open-at-point' on radio targets."
  2281. (should
  2282. (org-test-with-temp-text "<<<target>>> <point>target"
  2283. (org-update-radio-target-regexp)
  2284. (org-open-at-point)
  2285. (eq (org-element-type (org-element-context)) 'radio-target))))
  2286. (ert-deftest test-org/open-at-point/tag ()
  2287. "Test `org-open-at-point' on tags."
  2288. (should
  2289. (org-test-with-temp-text "* H :<point>tag:"
  2290. (catch :result
  2291. (cl-letf (((symbol-function 'org-tags-view)
  2292. (lambda (&rest args) (throw :result t))))
  2293. (org-open-at-point)
  2294. nil))))
  2295. (should-not
  2296. (org-test-with-temp-text-in-file "* H<point> :tag:"
  2297. (catch :result
  2298. (cl-letf (((symbol-function 'org-tags-view)
  2299. (lambda (&rest args) (throw :result t))))
  2300. (org-open-at-point)
  2301. nil)))))
  2302. ;;;; Stored links
  2303. (ert-deftest test-org/store-link ()
  2304. "Test `org-store-link' specifications."
  2305. ;; On a headline, link to that headline. Use heading as the
  2306. ;; description of the link.
  2307. (should
  2308. (let (org-store-link-props org-stored-links)
  2309. (org-test-with-temp-text-in-file "* H1"
  2310. (let ((file (buffer-file-name)))
  2311. (equal (format "[[file:%s::*H1][H1]]" file)
  2312. (org-store-link nil))))))
  2313. ;; On a headline, remove any link from description.
  2314. (should
  2315. (let (org-store-link-props org-stored-links)
  2316. (org-test-with-temp-text-in-file "* [[#l][d]]"
  2317. (let ((file (buffer-file-name)))
  2318. (equal (format "[[file:%s::*%s][d]]"
  2319. file
  2320. (org-link-escape "[[#l][d]]"))
  2321. (org-store-link nil))))))
  2322. (should
  2323. (let (org-store-link-props org-stored-links)
  2324. (org-test-with-temp-text-in-file "* [[l]]"
  2325. (let ((file (buffer-file-name)))
  2326. (equal (format "[[file:%s::*%s][l]]" file (org-link-escape "[[l]]"))
  2327. (org-store-link nil))))))
  2328. (should
  2329. (let (org-store-link-props org-stored-links)
  2330. (org-test-with-temp-text-in-file "* [[l1][d1]] [[l2][d2]]"
  2331. (let ((file (buffer-file-name)))
  2332. (equal (format "[[file:%s::*%s][d1 d2]]"
  2333. file
  2334. (org-link-escape "[[l1][d1]] [[l2][d2]]"))
  2335. (org-store-link nil))))))
  2336. ;; On a named element, link to that element.
  2337. (should
  2338. (let (org-store-link-props org-stored-links)
  2339. (org-test-with-temp-text-in-file "#+NAME: foo\nParagraph"
  2340. (let ((file (buffer-file-name)))
  2341. (equal (format "[[file:%s::foo][foo]]" file)
  2342. (org-store-link nil))))))
  2343. ;; Store link to Org buffer, with context.
  2344. (should
  2345. (let ((org-stored-links nil)
  2346. (org-id-link-to-org-use-id nil)
  2347. (org-context-in-file-links t))
  2348. (org-test-with-temp-text-in-file "* h1"
  2349. (let ((file (buffer-file-name)))
  2350. (equal (format "[[file:%s::*h1][h1]]" file)
  2351. (org-store-link nil))))))
  2352. ;; Store link to Org buffer, without context.
  2353. (should
  2354. (let ((org-stored-links nil)
  2355. (org-id-link-to-org-use-id nil)
  2356. (org-context-in-file-links nil))
  2357. (org-test-with-temp-text-in-file "* h1"
  2358. (let ((file (buffer-file-name)))
  2359. (equal (format "[[file:%s][file:%s]]" file file)
  2360. (org-store-link nil))))))
  2361. ;; C-u prefix reverses `org-context-in-file-links' in Org buffer.
  2362. (should
  2363. (let ((org-stored-links nil)
  2364. (org-id-link-to-org-use-id nil)
  2365. (org-context-in-file-links nil))
  2366. (org-test-with-temp-text-in-file "* h1"
  2367. (let ((file (buffer-file-name)))
  2368. (equal (format "[[file:%s::*h1][h1]]" file)
  2369. (org-store-link '(4)))))))
  2370. ;; A C-u C-u does *not* reverse `org-context-in-file-links' in Org
  2371. ;; buffer.
  2372. (should
  2373. (let ((org-stored-links nil)
  2374. (org-id-link-to-org-use-id nil)
  2375. (org-context-in-file-links nil))
  2376. (org-test-with-temp-text-in-file "* h1"
  2377. (let ((file (buffer-file-name)))
  2378. (equal (format "[[file:%s][file:%s]]" file file)
  2379. (org-store-link '(16)))))))
  2380. ;; Store file link to non-Org buffer, with context.
  2381. (should
  2382. (let ((org-stored-links nil)
  2383. (org-context-in-file-links t))
  2384. (org-test-with-temp-text-in-file "one\n<point>two"
  2385. (fundamental-mode)
  2386. (let ((file (buffer-file-name)))
  2387. (equal (format "[[file:%s::one]]" file)
  2388. (org-store-link nil))))))
  2389. ;; Store file link to non-Org buffer, without context.
  2390. (should
  2391. (let ((org-stored-links nil)
  2392. (org-context-in-file-links nil))
  2393. (org-test-with-temp-text-in-file "one\n<point>two"
  2394. (fundamental-mode)
  2395. (let ((file (buffer-file-name)))
  2396. (equal (format "[[file:%s][file:%s]]" file file)
  2397. (org-store-link nil))))))
  2398. ;; C-u prefix reverses `org-context-in-file-links' in non-Org
  2399. ;; buffer.
  2400. (should
  2401. (let ((org-stored-links nil)
  2402. (org-context-in-file-links nil))
  2403. (org-test-with-temp-text-in-file "one\n<point>two"
  2404. (fundamental-mode)
  2405. (let ((file (buffer-file-name)))
  2406. (equal (format "[[file:%s::one]]" file)
  2407. (org-store-link '(4)))))))
  2408. ;; A C-u C-u does *not* reverse `org-context-in-file-links' in
  2409. ;; non-Org buffer.
  2410. (should
  2411. (let ((org-stored-links nil)
  2412. (org-context-in-file-links nil))
  2413. (org-test-with-temp-text-in-file "one\n<point>two"
  2414. (fundamental-mode)
  2415. (let ((file (buffer-file-name)))
  2416. (equal (format "[[file:%s][file:%s]]" file file)
  2417. (org-store-link '(16))))))))
  2418. ;;; Node Properties
  2419. (ert-deftest test-org/accumulated-properties-in-drawers ()
  2420. "Ensure properties accumulate in subtree drawers."
  2421. (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
  2422. (org-babel-next-src-block)
  2423. (should (equal '(2 1) (org-babel-execute-src-block)))))
  2424. (ert-deftest test-org/custom-properties ()
  2425. "Test custom properties specifications."
  2426. ;; Standard test.
  2427. (should
  2428. (let ((org-custom-properties '("FOO")))
  2429. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2430. (org-toggle-custom-properties-visibility)
  2431. (org-invisible-p2))))
  2432. ;; Properties are case-insensitive.
  2433. (should
  2434. (let ((org-custom-properties '("FOO")))
  2435. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
  2436. (org-toggle-custom-properties-visibility)
  2437. (org-invisible-p2))))
  2438. (should
  2439. (let ((org-custom-properties '("foo")))
  2440. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2441. (org-toggle-custom-properties-visibility)
  2442. (org-invisible-p2))))
  2443. ;; Multiple custom properties in the same drawer.
  2444. (should
  2445. (let ((org-custom-properties '("FOO" "BAR")))
  2446. (org-test-with-temp-text
  2447. "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
  2448. (org-toggle-custom-properties-visibility)
  2449. (and (org-invisible-p2)
  2450. (not (progn (forward-line) (org-invisible-p2)))
  2451. (progn (forward-line) (org-invisible-p2))))))
  2452. ;; Hide custom properties with an empty value.
  2453. (should
  2454. (let ((org-custom-properties '("FOO")))
  2455. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
  2456. (org-toggle-custom-properties-visibility)
  2457. (org-invisible-p2))))
  2458. ;; Do not hide fake properties.
  2459. (should-not
  2460. (let ((org-custom-properties '("FOO")))
  2461. (org-test-with-temp-text ":FOO: val\n"
  2462. (org-toggle-custom-properties-visibility)
  2463. (org-invisible-p2))))
  2464. (should-not
  2465. (let ((org-custom-properties '("A")))
  2466. (org-test-with-temp-text
  2467. "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
  2468. (org-toggle-custom-properties-visibility)
  2469. (org-invisible-p2)))))
  2470. ;;; Mark Region
  2471. (ert-deftest test-org/mark-subtree ()
  2472. "Test `org-mark-subtree' specifications."
  2473. ;; Error when point is before first headline.
  2474. (should-error
  2475. (org-test-with-temp-text "Paragraph\n* Headline\nBody"
  2476. (progn (transient-mark-mode 1)
  2477. (org-mark-subtree))))
  2478. ;; Without argument, mark current subtree.
  2479. (should
  2480. (equal
  2481. '(12 32)
  2482. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  2483. (progn (transient-mark-mode 1)
  2484. (forward-line 2)
  2485. (org-mark-subtree)
  2486. (list (region-beginning) (region-end))))))
  2487. ;; With an argument, move ARG up.
  2488. (should
  2489. (equal
  2490. '(1 32)
  2491. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  2492. (progn (transient-mark-mode 1)
  2493. (forward-line 2)
  2494. (org-mark-subtree 1)
  2495. (list (region-beginning) (region-end))))))
  2496. ;; Do not get fooled by inlinetasks.
  2497. (when (featurep 'org-inlinetask)
  2498. (should
  2499. (= 1
  2500. (org-test-with-temp-text "* Headline\n*************** Task\nContents"
  2501. (progn (transient-mark-mode 1)
  2502. (forward-line 1)
  2503. (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
  2504. (region-beginning)))))))
  2505. ;;; Miscellaneous
  2506. (ert-deftest test-org/in-regexp ()
  2507. "Test `org-in-regexp' specifications."
  2508. ;; Standard tests.
  2509. (should
  2510. (org-test-with-temp-text "xx ab<point>c xx"
  2511. (org-in-regexp "abc")))
  2512. (should-not
  2513. (org-test-with-temp-text "xx abc <point>xx"
  2514. (org-in-regexp "abc")))
  2515. ;; Return non-nil even with multiple matching regexps in the same
  2516. ;; line.
  2517. (should
  2518. (org-test-with-temp-text "abc xx ab<point>c xx"
  2519. (org-in-regexp "abc")))
  2520. ;; With optional argument NLINES, check extra lines around point.
  2521. (should-not
  2522. (org-test-with-temp-text "A\nB<point>\nC"
  2523. (org-in-regexp "A\nB\nC")))
  2524. (should
  2525. (org-test-with-temp-text "A\nB<point>\nC"
  2526. (org-in-regexp "A\nB\nC" 1)))
  2527. (should-not
  2528. (org-test-with-temp-text "A\nB\nC<point>"
  2529. (org-in-regexp "A\nB\nC" 1)))
  2530. ;; When optional argument VISUALLY is non-nil, return nil if at
  2531. ;; regexp boundaries.
  2532. (should
  2533. (org-test-with-temp-text "xx abc<point> xx"
  2534. (org-in-regexp "abc")))
  2535. (should-not
  2536. (org-test-with-temp-text "xx abc<point> xx"
  2537. (org-in-regexp "abc" nil t))))
  2538. (ert-deftest test-org/sort-entries ()
  2539. "Test `org-sort-entries'."
  2540. ;; Sort alphabetically.
  2541. (should
  2542. (equal "\n* abc\n* def\n* xyz\n"
  2543. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  2544. (org-sort-entries nil ?a)
  2545. (buffer-string))))
  2546. (should
  2547. (equal "\n* xyz\n* def\n* abc\n"
  2548. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  2549. (org-sort-entries nil ?A)
  2550. (buffer-string))))
  2551. ;; Sort numerically.
  2552. (should
  2553. (equal "\n* 1\n* 2\n* 10\n"
  2554. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  2555. (org-sort-entries nil ?n)
  2556. (buffer-string))))
  2557. (should
  2558. (equal "\n* 10\n* 2\n* 1\n"
  2559. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  2560. (org-sort-entries nil ?N)
  2561. (buffer-string))))
  2562. ;; Sort by custom function.
  2563. (should
  2564. (equal "\n* b\n* aa\n* ccc\n"
  2565. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  2566. (org-sort-entries nil ?f
  2567. (lambda ()
  2568. (length (buffer-substring (point-at-bol)
  2569. (point-at-eol))))
  2570. #'<)
  2571. (buffer-string))))
  2572. (should
  2573. (equal "\n* ccc\n* aa\n* b\n"
  2574. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  2575. (org-sort-entries nil ?F
  2576. (lambda ()
  2577. (length (buffer-substring (point-at-bol)
  2578. (point-at-eol))))
  2579. #'<)
  2580. (buffer-string))))
  2581. ;; Sort by TODO keyword.
  2582. (should
  2583. (equal "\n* TODO h1\n* TODO h3\n* DONE h2\n"
  2584. (org-test-with-temp-text
  2585. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  2586. (org-sort-entries nil ?o)
  2587. (buffer-string))))
  2588. (should
  2589. (equal "\n* DONE h2\n* TODO h1\n* TODO h3\n"
  2590. (org-test-with-temp-text
  2591. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  2592. (org-sort-entries nil ?O)
  2593. (buffer-string))))
  2594. ;; Sort by priority.
  2595. (should
  2596. (equal "\n* [#A] h2\n* [#B] h3\n* [#C] h1\n"
  2597. (org-test-with-temp-text
  2598. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  2599. (org-sort-entries nil ?p)
  2600. (buffer-string))))
  2601. (should
  2602. (equal "\n* [#C] h1\n* [#B] h3\n* [#A] h2\n"
  2603. (org-test-with-temp-text
  2604. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  2605. (org-sort-entries nil ?P)
  2606. (buffer-string))))
  2607. ;; Sort by creation time.
  2608. (should
  2609. (equal "
  2610. * h3
  2611. [2017-05-08 Mon]
  2612. * h2
  2613. [2017-05-09 Tue]
  2614. * h1
  2615. [2018-05-09 Wed]
  2616. "
  2617. (org-test-with-temp-text
  2618. "
  2619. * h1
  2620. [2018-05-09 Wed]
  2621. * h2
  2622. [2017-05-09 Tue]
  2623. * h3
  2624. [2017-05-08 Mon]
  2625. "
  2626. (org-sort-entries nil ?c)
  2627. (buffer-string))))
  2628. ;; Sort by scheduled date.
  2629. (should
  2630. (equal "
  2631. * TODO h4
  2632. SCHEDULED: <2017-05-06 Sat>
  2633. * TODO h3
  2634. SCHEDULED: <2017-05-08 Mon>
  2635. * TODO h2
  2636. DEADLINE: <2017-05-09 Tue>
  2637. * TODO h1
  2638. DEADLINE: <2017-05-07 Sun>
  2639. "
  2640. (org-test-with-temp-text
  2641. "
  2642. * TODO h2
  2643. DEADLINE: <2017-05-09 Tue>
  2644. * TODO h1
  2645. DEADLINE: <2017-05-07 Sun>
  2646. * TODO h3
  2647. SCHEDULED: <2017-05-08 Mon>
  2648. * TODO h4
  2649. SCHEDULED: <2017-05-06 Sat>
  2650. "
  2651. (org-sort-entries nil ?s)
  2652. (buffer-string))))
  2653. ;; Sort by deadline date.
  2654. (should
  2655. (equal "
  2656. * TODO h1
  2657. DEADLINE: <2017-05-07 Sun>
  2658. * TODO h2
  2659. DEADLINE: <2017-05-09 Tue>
  2660. * TODO h3
  2661. SCHEDULED: <2017-05-08 Mon>
  2662. * TODO h4
  2663. SCHEDULED: <2017-05-06 Sat>
  2664. "
  2665. (org-test-with-temp-text
  2666. "
  2667. * TODO h2
  2668. DEADLINE: <2017-05-09 Tue>
  2669. * TODO h1
  2670. DEADLINE: <2017-05-07 Sun>
  2671. * TODO h3
  2672. SCHEDULED: <2017-05-08 Mon>
  2673. * TODO h4
  2674. SCHEDULED: <2017-05-06 Sat>
  2675. "
  2676. (org-sort-entries nil ?d)
  2677. (buffer-string))))
  2678. ;; Sort by any date/time
  2679. (should
  2680. (equal "
  2681. * TODO h4
  2682. SCHEDULED: <2017-05-06 Sat>
  2683. * TODO h1
  2684. DEADLINE: <2017-05-07 Sun>
  2685. * TODO h3
  2686. SCHEDULED: <2017-05-08 Mon>
  2687. * TODO h2
  2688. DEADLINE: <2017-05-09 Tue>
  2689. "
  2690. (org-test-with-temp-text
  2691. "
  2692. * TODO h2
  2693. DEADLINE: <2017-05-09 Tue>
  2694. * TODO h1
  2695. DEADLINE: <2017-05-07 Sun>
  2696. * TODO h3
  2697. SCHEDULED: <2017-05-08 Mon>
  2698. * TODO h4
  2699. SCHEDULED: <2017-05-06 Sat>
  2700. "
  2701. (org-sort-entries nil ?t)
  2702. (buffer-string))))
  2703. ;; Sort by clocking time.
  2704. (should
  2705. (equal "
  2706. * clocked h2
  2707. :LOGBOOK:
  2708. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  2709. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  2710. :END:
  2711. * clocked h1
  2712. :LOGBOOK:
  2713. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  2714. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  2715. :END:
  2716. "
  2717. (org-test-with-temp-text
  2718. "
  2719. * clocked h1
  2720. :LOGBOOK:
  2721. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  2722. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  2723. :END:
  2724. * clocked h2
  2725. :LOGBOOK:
  2726. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  2727. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  2728. :END:
  2729. "
  2730. (org-sort-entries nil ?k)
  2731. (buffer-string)))))
  2732. ;;; Navigation
  2733. (ert-deftest test-org/forward-heading-same-level ()
  2734. "Test `org-forward-heading-same-level' specifications."
  2735. ;; Test navigation at top level, forward and backward.
  2736. (should
  2737. (equal "* H2"
  2738. (org-test-with-temp-text "* H1\n* H2"
  2739. (org-forward-heading-same-level 1)
  2740. (buffer-substring-no-properties (point) (line-end-position)))))
  2741. (should
  2742. (equal "* H1"
  2743. (org-test-with-temp-text "* H1\n<point>* H2"
  2744. (org-forward-heading-same-level -1)
  2745. (buffer-substring-no-properties (point) (line-end-position)))))
  2746. ;; Test navigation in a sub-tree, forward and backward.
  2747. (should
  2748. (equal "* H2"
  2749. (org-test-with-temp-text "* H1\n** H11\n** H12\n* H2"
  2750. (org-forward-heading-same-level 1)
  2751. (buffer-substring-no-properties (point) (line-end-position)))))
  2752. (should
  2753. (equal "* H1"
  2754. (org-test-with-temp-text "* H1\n** H11\n** H12\n<point>* H2"
  2755. (org-forward-heading-same-level -1)
  2756. (buffer-substring-no-properties (point) (line-end-position)))))
  2757. ;; Stop at first or last sub-heading.
  2758. (should-not
  2759. (equal "* H2"
  2760. (org-test-with-temp-text "* H1\n** H11\n<point>** H12\n* H2"
  2761. (org-forward-heading-same-level 1)
  2762. (buffer-substring-no-properties (point) (line-end-position)))))
  2763. (should-not
  2764. (equal "* H2"
  2765. (org-test-with-temp-text "* H1\n<point>** H11\n** H12\n* H2"
  2766. (org-forward-heading-same-level -1)
  2767. (buffer-substring-no-properties (point) (line-end-position)))))
  2768. ;; Allow multiple moves.
  2769. (should
  2770. (equal "* H3"
  2771. (org-test-with-temp-text "* H1\n* H2\n* H3"
  2772. (org-forward-heading-same-level 2)
  2773. (buffer-substring-no-properties (point) (line-end-position)))))
  2774. (should
  2775. (equal "* H1"
  2776. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  2777. (org-forward-heading-same-level -2)
  2778. (buffer-substring-no-properties (point) (line-end-position)))))
  2779. ;; Ignore spurious moves when first (or last) sibling is reached.
  2780. (should
  2781. (equal "** H3"
  2782. (org-test-with-temp-text "* First\n<point>** H1\n** H2\n** H3\n* Last"
  2783. (org-forward-heading-same-level 100)
  2784. (buffer-substring-no-properties (point) (line-end-position)))))
  2785. (should
  2786. (equal "** H1"
  2787. (org-test-with-temp-text "* First\n** H1\n** H2\n<point>** H3\n* Last"
  2788. (org-forward-heading-same-level -100)
  2789. (buffer-substring-no-properties (point) (line-end-position))))))
  2790. (ert-deftest test-org/end-of-meta-data ()
  2791. "Test `org-end-of-meta-data' specifications."
  2792. ;; Skip planning line.
  2793. (should
  2794. (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
  2795. (org-end-of-meta-data)
  2796. (eobp)))
  2797. ;; Skip properties drawer.
  2798. (should
  2799. (org-test-with-temp-text
  2800. "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
  2801. (org-end-of-meta-data)
  2802. (eobp)))
  2803. ;; Skip both.
  2804. (should
  2805. (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
  2806. (org-end-of-meta-data)
  2807. (eobp)))
  2808. ;; Nothing to skip, go to first line.
  2809. (should
  2810. (org-test-with-temp-text "* Headline\nContents"
  2811. (org-end-of-meta-data)
  2812. (looking-at "Contents")))
  2813. ;; With option argument, skip empty lines, regular drawers and
  2814. ;; clocking lines.
  2815. (should
  2816. (org-test-with-temp-text "* Headline\n\nContents"
  2817. (org-end-of-meta-data t)
  2818. (looking-at "Contents")))
  2819. (should
  2820. (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
  2821. (org-end-of-meta-data t)
  2822. (looking-at "Contents")))
  2823. (should
  2824. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
  2825. (org-end-of-meta-data t)
  2826. (looking-at "Contents")))
  2827. ;; Special case: do not skip incomplete drawers.
  2828. (should
  2829. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
  2830. (org-end-of-meta-data t)
  2831. (looking-at ":LOGBOOK:")))
  2832. ;; Special case: Be careful about consecutive headlines.
  2833. (should-not
  2834. (org-test-with-temp-text "* H1\n*H2\nContents"
  2835. (org-end-of-meta-data t)
  2836. (looking-at "Contents"))))
  2837. (ert-deftest test-org/beginning-of-line ()
  2838. "Test `org-beginning-of-line' specifications."
  2839. ;; Move to beginning of line. If current line in invisible, move to
  2840. ;; beginning of visible line instead.
  2841. (should
  2842. (org-test-with-temp-text "Some text\nSome other text<point>"
  2843. (org-beginning-of-line)
  2844. (bolp)))
  2845. (should
  2846. (org-test-with-temp-text "* H1\n** H2<point>"
  2847. (org-overview)
  2848. (org-beginning-of-line)
  2849. (= (line-beginning-position) 1)))
  2850. ;; With `visual-line-mode' active, move to beginning of visual line.
  2851. (should-not
  2852. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  2853. (visual-line-mode)
  2854. (dotimes (i 1000) (insert "very "))
  2855. (org-beginning-of-line)
  2856. (bolp)))
  2857. ;; In a wide headline, with `visual-line-mode', prefer going to the
  2858. ;; beginning of a visual line than to the logical beginning of line,
  2859. ;; even if special movement is active.
  2860. (should-not
  2861. (org-test-with-temp-text "* A <point>long headline"
  2862. (visual-line-mode)
  2863. (dotimes (i 1000) (insert "very "))
  2864. (goto-char (point-max))
  2865. (org-beginning-of-line)
  2866. (bobp)))
  2867. (should-not
  2868. (org-test-with-temp-text "* A <point>long headline"
  2869. (visual-line-mode)
  2870. (dotimes (i 1000) (insert "very "))
  2871. (goto-char (point-max))
  2872. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line))
  2873. (bobp)))
  2874. ;; At an headline with special movement, first move at beginning of
  2875. ;; title, then at the beginning of line, rinse, repeat.
  2876. (should
  2877. (org-test-with-temp-text "* TODO Headline<point>"
  2878. (let ((org-special-ctrl-a/e t))
  2879. (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
  2880. (progn (org-beginning-of-line) (bolp))
  2881. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  2882. (should
  2883. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  2884. (let ((org-special-ctrl-a/e t))
  2885. (org-beginning-of-line)
  2886. (looking-at "Headline"))))
  2887. (should
  2888. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  2889. (let ((org-special-ctrl-a/e '(t . nil)))
  2890. (org-beginning-of-line)
  2891. (looking-at "Headline"))))
  2892. (should-not
  2893. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  2894. (let ((org-special-ctrl-a/e '(nil . nil)))
  2895. (org-beginning-of-line)
  2896. (looking-at "Headline"))))
  2897. ;; At an headline with reversed movement, first move to beginning of
  2898. ;; line, then to the beginning of title.
  2899. (should
  2900. (org-test-with-temp-text "* TODO Headline<point>"
  2901. (let ((org-special-ctrl-a/e 'reversed)
  2902. (this-command last-command))
  2903. (and (progn (org-beginning-of-line) (bolp))
  2904. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  2905. (should
  2906. (org-test-with-temp-text "* TODO Headline<point>"
  2907. (let ((org-special-ctrl-a/e '(reversed . nil))
  2908. (this-command last-command))
  2909. (and (progn (org-beginning-of-line) (bolp))
  2910. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  2911. (should-not
  2912. (org-test-with-temp-text "* TODO Headline<point>"
  2913. (let ((org-special-ctrl-a/e '(t . nil))
  2914. (this-command last-command))
  2915. (and (progn (org-beginning-of-line) (bolp))
  2916. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  2917. ;; At an item with special movement, first move after to beginning
  2918. ;; of title, then to the beginning of line, rinse, repeat.
  2919. (should
  2920. (org-test-with-temp-text "- [ ] Item<point>"
  2921. (let ((org-special-ctrl-a/e t))
  2922. (and (progn (org-beginning-of-line) (looking-at-p "Item"))
  2923. (progn (org-beginning-of-line) (bolp))
  2924. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  2925. ;; At an item with reversed movement, first move to beginning of
  2926. ;; line, then to the beginning of title.
  2927. (should
  2928. (org-test-with-temp-text "- [X] Item<point>"
  2929. (let ((org-special-ctrl-a/e 'reversed)
  2930. (this-command last-command))
  2931. (and (progn (org-beginning-of-line) (bolp))
  2932. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  2933. ;; Leave point before invisible characters at column 0.
  2934. (should
  2935. (org-test-with-temp-text "[[http://orgmode.org]]<point>"
  2936. (let ((org-special-ctrl-a/e nil))
  2937. (org-beginning-of-line)
  2938. (bolp))))
  2939. (should
  2940. (org-test-with-temp-text "[[http://orgmode.org]]<point>"
  2941. (let ((org-special-ctrl-a/e t))
  2942. (org-beginning-of-line)
  2943. (bolp))))
  2944. (should
  2945. (org-test-with-temp-text "[[http<point>://orgmode.org]]"
  2946. (visual-line-mode)
  2947. (org-beginning-of-line)
  2948. (bolp)))
  2949. ;; Special case: Do not error when the buffer contains only a single
  2950. ;; asterisk.
  2951. (should
  2952. (org-test-with-temp-text "*<point>"
  2953. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line) t)))
  2954. (should
  2955. (org-test-with-temp-text "*<point>"
  2956. (let ((org-special-ctrl-a/e nil)) (org-beginning-of-line) t))))
  2957. (ert-deftest test-org/end-of-line ()
  2958. "Test `org-end-of-line' specifications."
  2959. ;; Standard test.
  2960. (should
  2961. (org-test-with-temp-text "Some text\nSome other text"
  2962. (org-end-of-line)
  2963. (eolp)))
  2964. ;; With `visual-line-mode' active, move to end of visible line.
  2965. ;; However, never go past ellipsis.
  2966. (should-not
  2967. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  2968. (visual-line-mode)
  2969. (dotimes (i 1000) (insert "very "))
  2970. (goto-char (point-min))
  2971. (org-end-of-line)
  2972. (eolp)))
  2973. (should-not
  2974. (org-test-with-temp-text "* A short headline\nSome contents"
  2975. (visual-line-mode)
  2976. (org-overview)
  2977. (org-end-of-line)
  2978. (eobp)))
  2979. ;; In a wide headline, with `visual-line-mode', prefer going to end
  2980. ;; of visible line if tags, or end of line, are farther.
  2981. (should-not
  2982. (org-test-with-temp-text "* A <point>long headline"
  2983. (visual-line-mode)
  2984. (dotimes (i 1000) (insert "very "))
  2985. (goto-char (point-min))
  2986. (org-end-of-line)
  2987. (eolp)))
  2988. (should-not
  2989. (org-test-with-temp-text "* A <point>long headline :tag:"
  2990. (visual-line-mode)
  2991. (dotimes (i 1000) (insert "very "))
  2992. (goto-char (point-min))
  2993. (org-end-of-line)
  2994. (eolp)))
  2995. ;; At an headline without special movement, go to end of line.
  2996. ;; However, never go past ellipsis.
  2997. (should
  2998. (org-test-with-temp-text "* Headline2b :tag:\n"
  2999. (let ((org-special-ctrl-a/e nil))
  3000. (and (progn (org-end-of-line) (eolp))
  3001. (progn (org-end-of-line) (eolp))))))
  3002. (should
  3003. (org-test-with-temp-text "* Headline2b :tag:\n"
  3004. (let ((org-special-ctrl-a/e '(t . nil)))
  3005. (and (progn (org-end-of-line) (eolp))
  3006. (progn (org-end-of-line) (eolp))))))
  3007. (should
  3008. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3009. (org-overview)
  3010. (let ((org-special-ctrl-a/e nil))
  3011. (org-end-of-line)
  3012. (= 1 (line-beginning-position)))))
  3013. ;; At an headline with special movement, first move before tags,
  3014. ;; then at the end of line, rinse, repeat. However, never go past
  3015. ;; ellipsis.
  3016. (should
  3017. (org-test-with-temp-text "* Headline1 :tag:\n"
  3018. (let ((org-special-ctrl-a/e t))
  3019. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3020. (progn (org-end-of-line) (eolp))
  3021. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3022. (should
  3023. (org-test-with-temp-text "* Headline1 :tag:\n"
  3024. (let ((org-special-ctrl-a/e '(nil . t)))
  3025. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3026. (progn (org-end-of-line) (eolp))
  3027. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3028. (should-not
  3029. (org-test-with-temp-text "* Headline1 :tag:\n"
  3030. (let ((org-special-ctrl-a/e '(nil . nil)))
  3031. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3032. (progn (org-end-of-line) (eolp))
  3033. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3034. (should
  3035. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3036. (org-overview)
  3037. (let ((org-special-ctrl-a/e t))
  3038. (org-end-of-line)
  3039. (org-end-of-line)
  3040. (= 1 (line-beginning-position)))))
  3041. ;; At an headline, with reversed movement, first go to end of line,
  3042. ;; then before tags. However, never go past ellipsis.
  3043. (should
  3044. (org-test-with-temp-text "* Headline3 :tag:\n"
  3045. (let ((org-special-ctrl-a/e 'reversed)
  3046. (this-command last-command))
  3047. (and (progn (org-end-of-line) (eolp))
  3048. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3049. (should
  3050. (org-test-with-temp-text "* Headline3 :tag:\n"
  3051. (let ((org-special-ctrl-a/e '(nil . reversed))
  3052. (this-command last-command))
  3053. (and (progn (org-end-of-line) (eolp))
  3054. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3055. (should-not
  3056. (org-test-with-temp-text "* Headline3 :tag:\n"
  3057. (let ((org-special-ctrl-a/e '(nil . t))
  3058. (this-command last-command))
  3059. (and (progn (org-end-of-line) (eolp))
  3060. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3061. (should
  3062. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3063. (org-overview)
  3064. (let ((org-special-ctrl-a/e 'reversed))
  3065. (org-end-of-line)
  3066. (= 1 (line-beginning-position)))))
  3067. ;; At a block without hidden contents.
  3068. (should
  3069. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3070. (progn (org-end-of-line) (eolp))))
  3071. ;; At a block with hidden contents.
  3072. (should-not
  3073. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3074. (let ((org-special-ctrl-a/e t))
  3075. (org-hide-block-toggle)
  3076. (org-end-of-line)
  3077. (eobp))))
  3078. ;; Get past invisible characters at the end of line.
  3079. (should
  3080. (org-test-with-temp-text "[[http://orgmode.org]]"
  3081. (org-end-of-line)
  3082. (eolp))))
  3083. (ert-deftest test-org/open-line ()
  3084. "Test `org-open-line' specifications."
  3085. ;; Call `open-line' outside of tables.
  3086. (should
  3087. (equal "\nText"
  3088. (org-test-with-temp-text "Text"
  3089. (org-open-line 1)
  3090. (buffer-string))))
  3091. ;; At a table, create a row above.
  3092. (should
  3093. (equal "\n| |\n| a |"
  3094. (org-test-with-temp-text "\n<point>| a |"
  3095. (org-open-line 1)
  3096. (buffer-string))))
  3097. ;; At the very first character of the buffer, also call `open-line'.
  3098. (should
  3099. (equal "\n| a |"
  3100. (org-test-with-temp-text "| a |"
  3101. (org-open-line 1)
  3102. (buffer-string))))
  3103. ;; Narrowing does not count.
  3104. (should
  3105. (equal "Text\n| |\n| a |"
  3106. (org-test-with-temp-text "Text\n<point>| a |"
  3107. (narrow-to-region (point) (point-max))
  3108. (org-open-line 1)
  3109. (widen)
  3110. (buffer-string)))))
  3111. (ert-deftest test-org/forward-sentence ()
  3112. "Test `org-forward-sentence' specifications."
  3113. ;; At the end of a table cell, move to the end of the next one.
  3114. (should
  3115. (org-test-with-temp-text "| a<point> | b |"
  3116. (org-forward-sentence)
  3117. (looking-at " |$")))
  3118. ;; Elsewhere in a cell, move to its end.
  3119. (should
  3120. (org-test-with-temp-text "| a<point>c | b |"
  3121. (org-forward-sentence)
  3122. (looking-at " | b |$")))
  3123. ;; Otherwise, simply call `forward-sentence'.
  3124. (should
  3125. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3126. (org-forward-sentence)
  3127. (looking-at " Sentence 2.")))
  3128. (should
  3129. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3130. (org-forward-sentence)
  3131. (org-forward-sentence)
  3132. (eobp)))
  3133. ;; At the end of an element, jump to the next one, without stopping
  3134. ;; on blank lines in-between.
  3135. (should
  3136. (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
  3137. (org-forward-sentence)
  3138. (eobp))))
  3139. (ert-deftest test-org/backward-sentence ()
  3140. "Test `org-backward-sentence' specifications."
  3141. ;; At the beginning of a table cell, move to the beginning of the
  3142. ;; previous one.
  3143. (should
  3144. (org-test-with-temp-text "| a | <point>b |"
  3145. (org-backward-sentence)
  3146. (looking-at "a | b |$")))
  3147. ;; Elsewhere in a cell, move to its beginning.
  3148. (should
  3149. (org-test-with-temp-text "| a | b<point>c |"
  3150. (org-backward-sentence)
  3151. (looking-at "bc |$")))
  3152. ;; Otherwise, simply call `backward-sentence'.
  3153. (should
  3154. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3155. (org-backward-sentence)
  3156. (looking-at "Sentence 2.")))
  3157. (should
  3158. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3159. (org-backward-sentence)
  3160. (org-backward-sentence)
  3161. (bobp)))
  3162. ;; Make sure to hit the beginning of a sentence on the same line as
  3163. ;; an item.
  3164. (should
  3165. (org-test-with-temp-text "- Line 1\n line <point>2."
  3166. (org-backward-sentence)
  3167. (looking-at "Line 1"))))
  3168. (ert-deftest test-org/forward-paragraph ()
  3169. "Test `org-forward-paragraph' specifications."
  3170. ;; At end of buffer, do not return an error.
  3171. (should
  3172. (org-test-with-temp-text "Paragraph"
  3173. (goto-char (point-max))
  3174. (org-forward-paragraph)
  3175. t))
  3176. ;; Standard test.
  3177. (should
  3178. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  3179. (org-forward-paragraph)
  3180. (looking-at "P2")))
  3181. ;; Ignore depth.
  3182. (should
  3183. (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
  3184. (org-forward-paragraph)
  3185. (looking-at "P1")))
  3186. ;; Do not enter elements with invisible contents.
  3187. (should
  3188. (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
  3189. (org-hide-block-toggle)
  3190. (org-forward-paragraph)
  3191. (looking-at "P3")))
  3192. ;; On an affiliated keyword, jump to the beginning of the element.
  3193. (should
  3194. (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
  3195. (org-forward-paragraph)
  3196. (looking-at "Para")))
  3197. ;; On an item or a footnote definition, move to the second element
  3198. ;; inside, if any.
  3199. (should
  3200. (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
  3201. (org-forward-paragraph)
  3202. (looking-at " Paragraph")))
  3203. (should
  3204. (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
  3205. (org-forward-paragraph)
  3206. (looking-at "Paragraph")))
  3207. ;; On an item, or a footnote definition, when the first line is
  3208. ;; empty, move to the first item.
  3209. (should
  3210. (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
  3211. (org-forward-paragraph)
  3212. (looking-at " Paragraph")))
  3213. (should
  3214. (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
  3215. (org-forward-paragraph)
  3216. (looking-at "Paragraph")))
  3217. ;; On a table (resp. a property drawer) do not move through table
  3218. ;; rows (resp. node properties).
  3219. (should
  3220. (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
  3221. (org-forward-paragraph)
  3222. (looking-at "Paragraph")))
  3223. (should
  3224. (org-test-with-temp-text
  3225. "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
  3226. (org-forward-paragraph)
  3227. (looking-at "Paragraph")))
  3228. ;; On a verse or source block, stop after blank lines.
  3229. (should
  3230. (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
  3231. (org-forward-paragraph)
  3232. (looking-at "L2")))
  3233. (should
  3234. (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
  3235. (org-forward-paragraph)
  3236. (looking-at "L2"))))
  3237. (ert-deftest test-org/backward-paragraph ()
  3238. "Test `org-backward-paragraph' specifications."
  3239. ;; Do not error at beginning of buffer.
  3240. (should
  3241. (org-test-with-temp-text "Paragraph"
  3242. (org-backward-paragraph)
  3243. t))
  3244. ;; Regular test.
  3245. (should
  3246. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  3247. (goto-char (point-max))
  3248. (org-backward-paragraph)
  3249. (looking-at "P3")))
  3250. (should
  3251. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  3252. (goto-char (point-max))
  3253. (beginning-of-line)
  3254. (org-backward-paragraph)
  3255. (looking-at "P2")))
  3256. ;; Ignore depth.
  3257. (should
  3258. (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
  3259. (goto-char (point-max))
  3260. (beginning-of-line)
  3261. (org-backward-paragraph)
  3262. (looking-at "P2")))
  3263. ;; Ignore invisible elements.
  3264. (should
  3265. (org-test-with-temp-text "* H1\n P1\n* H2"
  3266. (org-cycle)
  3267. (goto-char (point-max))
  3268. (beginning-of-line)
  3269. (org-backward-paragraph)
  3270. (bobp)))
  3271. ;; On an affiliated keyword, jump to the first one.
  3272. (should
  3273. (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
  3274. (search-forward "c2")
  3275. (org-backward-paragraph)
  3276. (looking-at "#\\+name")))
  3277. ;; On the second element in an item or a footnote definition, jump
  3278. ;; to item or the definition.
  3279. (should
  3280. (org-test-with-temp-text "- line1\n\n line2"
  3281. (goto-char (point-max))
  3282. (beginning-of-line)
  3283. (org-backward-paragraph)
  3284. (looking-at "- line1")))
  3285. (should
  3286. (org-test-with-temp-text "[fn:1] line1\n\n line2"
  3287. (goto-char (point-max))
  3288. (beginning-of-line)
  3289. (org-backward-paragraph)
  3290. (looking-at "\\[fn:1\\] line1")))
  3291. ;; On a table (resp. a property drawer), ignore table rows
  3292. ;; (resp. node properties).
  3293. (should
  3294. (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
  3295. (goto-char (point-max))
  3296. (beginning-of-line)
  3297. (org-backward-paragraph)
  3298. (bobp)))
  3299. (should
  3300. (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
  3301. (org-backward-paragraph)
  3302. (looking-at ":PROPERTIES:")))
  3303. ;; On a source or verse block, stop before blank lines.
  3304. (should
  3305. (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
  3306. (search-forward "L3")
  3307. (beginning-of-line)
  3308. (org-backward-paragraph)
  3309. (looking-at "L2")))
  3310. (should
  3311. (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
  3312. (search-forward "L3")
  3313. (beginning-of-line)
  3314. (org-backward-paragraph)
  3315. (looking-at "L2"))))
  3316. (ert-deftest test-org/forward-element ()
  3317. "Test `org-forward-element' specifications."
  3318. ;; 1. At EOB: should error.
  3319. (org-test-with-temp-text "Some text\n"
  3320. (goto-char (point-max))
  3321. (should-error (org-forward-element)))
  3322. ;; 2. Standard move: expected to ignore blank lines.
  3323. (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
  3324. (org-forward-element)
  3325. (should (looking-at (regexp-quote "Second paragraph."))))
  3326. ;; 3. Headline tests.
  3327. (org-test-with-temp-text "
  3328. * Head 1
  3329. ** Head 1.1
  3330. *** Head 1.1.1
  3331. ** Head 1.2"
  3332. ;; 3.1. At an headline beginning: move to next headline at the
  3333. ;; same level.
  3334. (goto-line 3)
  3335. (org-forward-element)
  3336. (should (looking-at (regexp-quote "** Head 1.2")))
  3337. ;; 3.2. At an headline beginning: move to parent headline if no
  3338. ;; headline at the same level.
  3339. (goto-line 3)
  3340. (org-forward-element)
  3341. (should (looking-at (regexp-quote "** Head 1.2"))))
  3342. ;; 4. Greater element tests.
  3343. (org-test-with-temp-text
  3344. "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
  3345. ;; 4.1. At a greater element: expected to skip contents.
  3346. (org-forward-element)
  3347. (should (looking-at (regexp-quote "Outside.")))
  3348. ;; 4.2. At the end of greater element contents: expected to skip
  3349. ;; to the end of the greater element.
  3350. (goto-line 2)
  3351. (org-forward-element)
  3352. (should (looking-at (regexp-quote "Outside."))))
  3353. ;; 5. List tests.
  3354. (org-test-with-temp-text "
  3355. - item1
  3356. - sub1
  3357. - sub2
  3358. - sub3
  3359. Inner paragraph.
  3360. - item2
  3361. Outside."
  3362. ;; 5.1. At list top point: expected to move to the element after
  3363. ;; the list.
  3364. (goto-line 2)
  3365. (org-forward-element)
  3366. (should (looking-at (regexp-quote "Outside.")))
  3367. ;; 5.2. Special case: at the first line of a sub-list, but not at
  3368. ;; beginning of line, move to next item.
  3369. (goto-line 2)
  3370. (forward-char)
  3371. (org-forward-element)
  3372. (should (looking-at "- item2"))
  3373. (goto-line 4)
  3374. (forward-char)
  3375. (org-forward-element)
  3376. (should (looking-at " - sub2"))
  3377. ;; 5.3 At sub-list beginning: expected to move after the sub-list.
  3378. (goto-line 4)
  3379. (org-forward-element)
  3380. (should (looking-at (regexp-quote " Inner paragraph.")))
  3381. ;; 5.4. At sub-list end: expected to move outside the sub-list.
  3382. (goto-line 8)
  3383. (org-forward-element)
  3384. (should (looking-at (regexp-quote " Inner paragraph.")))
  3385. ;; 5.5. At an item: expected to move to next item, if any.
  3386. (goto-line 6)
  3387. (org-forward-element)
  3388. (should (looking-at " - sub3"))))
  3389. (ert-deftest test-org/backward-element ()
  3390. "Test `org-backward-element' specifications."
  3391. ;; 1. Should error at BOB.
  3392. (org-test-with-temp-text " \nParagraph."
  3393. (should-error (org-backward-element)))
  3394. ;; 2. Should move at BOB when called on the first element in buffer.
  3395. (should
  3396. (org-test-with-temp-text "\n#+TITLE: test"
  3397. (progn (forward-line)
  3398. (org-backward-element)
  3399. (bobp))))
  3400. ;; 3. Not at the beginning of an element: move at its beginning.
  3401. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  3402. (goto-line 3)
  3403. (end-of-line)
  3404. (org-backward-element)
  3405. (should (looking-at (regexp-quote "Paragraph2."))))
  3406. ;; 4. Headline tests.
  3407. (org-test-with-temp-text "
  3408. * Head 1
  3409. ** Head 1.1
  3410. *** Head 1.1.1
  3411. ** Head 1.2"
  3412. ;; 4.1. At an headline beginning: move to previous headline at the
  3413. ;; same level.
  3414. (goto-line 5)
  3415. (org-backward-element)
  3416. (should (looking-at (regexp-quote "** Head 1.1")))
  3417. ;; 4.2. At an headline beginning: move to parent headline if no
  3418. ;; headline at the same level.
  3419. (goto-line 3)
  3420. (org-backward-element)
  3421. (should (looking-at (regexp-quote "* Head 1")))
  3422. ;; 4.3. At the first top-level headline: should error.
  3423. (goto-line 2)
  3424. (should-error (org-backward-element)))
  3425. ;; 5. At beginning of first element inside a greater element:
  3426. ;; expected to move to greater element's beginning.
  3427. (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
  3428. (goto-line 3)
  3429. (org-backward-element)
  3430. (should (looking-at "#\\+BEGIN_CENTER")))
  3431. ;; 6. At the beginning of the first element in a section: should
  3432. ;; move back to headline, if any.
  3433. (should
  3434. (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
  3435. (progn (goto-char (point-max))
  3436. (beginning-of-line)
  3437. (org-backward-element)
  3438. (org-at-heading-p))))
  3439. ;; 7. List tests.
  3440. (org-test-with-temp-text "
  3441. - item1
  3442. - sub1
  3443. - sub2
  3444. - sub3
  3445. Inner paragraph.
  3446. - item2
  3447. Outside."
  3448. ;; 7.1. At beginning of sub-list: expected to move to the
  3449. ;; paragraph before it.
  3450. (goto-line 4)
  3451. (org-backward-element)
  3452. (should (looking-at "item1"))
  3453. ;; 7.2. At an item in a list: expected to move at previous item.
  3454. (goto-line 8)
  3455. (org-backward-element)
  3456. (should (looking-at " - sub2"))
  3457. (goto-line 12)
  3458. (org-backward-element)
  3459. (should (looking-at "- item1"))
  3460. ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
  3461. ;; beginning.
  3462. (goto-line 10)
  3463. (org-backward-element)
  3464. (should (looking-at " - sub1"))
  3465. (goto-line 15)
  3466. (org-backward-element)
  3467. (should (looking-at "- item1"))
  3468. ;; 7.4. At blank-lines before list end: expected to move to top
  3469. ;; item.
  3470. (goto-line 14)
  3471. (org-backward-element)
  3472. (should (looking-at "- item1"))))
  3473. (ert-deftest test-org/up-element ()
  3474. "Test `org-up-element' specifications."
  3475. ;; 1. At BOB or with no surrounding element: should error.
  3476. (org-test-with-temp-text "Paragraph."
  3477. (should-error (org-up-element)))
  3478. (org-test-with-temp-text "* Head1\n* Head2"
  3479. (goto-line 2)
  3480. (should-error (org-up-element)))
  3481. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  3482. (goto-line 3)
  3483. (should-error (org-up-element)))
  3484. ;; 2. At an headline: move to parent headline.
  3485. (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
  3486. (goto-line 3)
  3487. (org-up-element)
  3488. (should (looking-at "\\* Head1")))
  3489. ;; 3. Inside a greater element: move to greater element beginning.
  3490. (org-test-with-temp-text
  3491. "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
  3492. (goto-line 3)
  3493. (org-up-element)
  3494. (should (looking-at "#\\+BEGIN_CENTER")))
  3495. ;; 4. List tests.
  3496. (org-test-with-temp-text "* Top
  3497. - item1
  3498. - sub1
  3499. - sub2
  3500. Paragraph within sub2.
  3501. - item2"
  3502. ;; 4.1. Within an item: move to the item beginning.
  3503. (goto-line 8)
  3504. (org-up-element)
  3505. (should (looking-at " - sub2"))
  3506. ;; 4.2. At an item in a sub-list: move to parent item.
  3507. (goto-line 4)
  3508. (org-up-element)
  3509. (should (looking-at "- item1"))
  3510. ;; 4.3. At an item in top list: move to beginning of whole list.
  3511. (goto-line 10)
  3512. (org-up-element)
  3513. (should (looking-at "- item1"))
  3514. ;; 4.4. Special case. At very top point: should move to parent of
  3515. ;; list.
  3516. (goto-line 2)
  3517. (org-up-element)
  3518. (should (looking-at "\\* Top"))))
  3519. (ert-deftest test-org/down-element ()
  3520. "Test `org-down-element' specifications."
  3521. ;; Error when the element hasn't got a recursive type.
  3522. (org-test-with-temp-text "Paragraph."
  3523. (should-error (org-down-element)))
  3524. ;; Error when the element has no contents
  3525. (org-test-with-temp-text "* Headline"
  3526. (should-error (org-down-element)))
  3527. ;; When at a plain-list, move to first item.
  3528. (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
  3529. (goto-line 2)
  3530. (org-down-element)
  3531. (should (looking-at " - Item 1.1")))
  3532. (org-test-with-temp-text "#+NAME: list\n- Item 1"
  3533. (org-down-element)
  3534. (should (looking-at " Item 1")))
  3535. ;; When at a table, move to first row
  3536. (org-test-with-temp-text "#+NAME: table\n| a | b |"
  3537. (org-down-element)
  3538. (should (looking-at " a | b |")))
  3539. ;; Otherwise, move inside the greater element.
  3540. (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
  3541. (org-down-element)
  3542. (should (looking-at "Paragraph"))))
  3543. (ert-deftest test-org/drag-element-backward ()
  3544. "Test `org-drag-element-backward' specifications."
  3545. ;; Standard test.
  3546. (should
  3547. (equal
  3548. "#+key2: val2\n#+key1: val1\n#+key3: val3"
  3549. (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
  3550. (org-drag-element-backward)
  3551. (buffer-string))))
  3552. (should
  3553. (equal
  3554. "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
  3555. (org-test-with-temp-text
  3556. "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
  3557. (org-drag-element-backward)
  3558. (buffer-string))))
  3559. ;; Preserve blank lines.
  3560. (should
  3561. (equal "Paragraph 2\n\n\nPara1\n\nPara3"
  3562. (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
  3563. (org-drag-element-backward)
  3564. (buffer-string))))
  3565. ;; Preserve column.
  3566. (should
  3567. (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
  3568. (org-drag-element-backward)
  3569. (looking-at-p "2")))
  3570. ;; Error when trying to move first element of buffer.
  3571. (should-error
  3572. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  3573. (org-drag-element-backward))
  3574. :type 'user-error)
  3575. ;; Error when trying to swap nested elements.
  3576. (should-error
  3577. (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
  3578. (org-drag-element-backward))
  3579. :type 'user-error)
  3580. ;; Error when trying to swap an headline element and a non-headline
  3581. ;; element.
  3582. (should-error
  3583. (org-test-with-temp-text "Test.\n<point>* Head 1"
  3584. (org-drag-element-backward))
  3585. :type 'error)
  3586. ;; Error when called before first element.
  3587. (should-error
  3588. (org-test-with-temp-text "\n<point>"
  3589. (org-drag-element-backward))
  3590. :type 'user-error)
  3591. ;; Preserve visibility of elements and their contents.
  3592. (should
  3593. (equal '((63 . 82) (26 . 48))
  3594. (org-test-with-temp-text "
  3595. #+BEGIN_CENTER
  3596. Text.
  3597. #+END_CENTER
  3598. - item 1
  3599. #+BEGIN_QUOTE
  3600. Text.
  3601. #+END_QUOTE"
  3602. (while (search-forward "BEGIN_" nil t) (org-cycle))
  3603. (search-backward "- item 1")
  3604. (org-drag-element-backward)
  3605. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  3606. (overlays-in (point-min) (point-max))))))
  3607. ;; Pathological case: handle call with point in blank lines right
  3608. ;; after a headline.
  3609. (should
  3610. (equal "* H2\n* H1\nText\n\n"
  3611. (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
  3612. (org-drag-element-backward)
  3613. (buffer-string)))))
  3614. (ert-deftest test-org/drag-element-forward ()
  3615. "Test `org-drag-element-forward' specifications."
  3616. ;; 1. Error when trying to move first element of buffer.
  3617. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  3618. (goto-line 3)
  3619. (should-error (org-drag-element-forward)))
  3620. ;; 2. Error when trying to swap nested elements.
  3621. (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
  3622. (forward-line)
  3623. (should-error (org-drag-element-forward)))
  3624. ;; 3. Error when trying to swap a non-headline element and an
  3625. ;; headline.
  3626. (org-test-with-temp-text "Test.\n* Head 1"
  3627. (should-error (org-drag-element-forward)))
  3628. ;; 4. Error when called before first element.
  3629. (should-error
  3630. (org-test-with-temp-text "\n"
  3631. (forward-line)
  3632. (org-drag-element-backward))
  3633. :type 'user-error)
  3634. ;; 5. Otherwise, swap elements, preserving column and blank lines
  3635. ;; between elements.
  3636. (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
  3637. (search-forward "graph")
  3638. (org-drag-element-forward)
  3639. (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
  3640. (should (looking-at " 1")))
  3641. ;; 5. Preserve visibility of elements and their contents.
  3642. (org-test-with-temp-text "
  3643. #+BEGIN_CENTER
  3644. Text.
  3645. #+END_CENTER
  3646. - item 1
  3647. #+BEGIN_QUOTE
  3648. Text.
  3649. #+END_QUOTE"
  3650. (while (search-forward "BEGIN_" nil t) (org-cycle))
  3651. (search-backward "#+BEGIN_CENTER")
  3652. (org-drag-element-forward)
  3653. (should
  3654. (equal
  3655. '((63 . 82) (26 . 48))
  3656. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  3657. (overlays-in (point-min) (point-max)))))))
  3658. (ert-deftest test-org/next-block ()
  3659. "Test `org-next-block' specifications."
  3660. ;; Regular test.
  3661. (should
  3662. (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  3663. (org-next-block 1)
  3664. (looking-at "#\\+BEGIN_CENTER")))
  3665. ;; Ignore case.
  3666. (should
  3667. (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
  3668. (let ((case-fold-search nil))
  3669. (org-next-block 1)
  3670. (looking-at "#\\+begin_center"))))
  3671. ;; Ignore current line.
  3672. (should
  3673. (org-test-with-temp-text
  3674. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
  3675. (org-next-block 1)
  3676. (looking-at "#\\+BEGIN_CENTER")))
  3677. ;; Throw an error when no block is found.
  3678. (should-error
  3679. (org-test-with-temp-text "Paragraph"
  3680. (org-next-block 1)))
  3681. ;; With an argument, skip many blocks at once.
  3682. (should
  3683. (org-test-with-temp-text
  3684. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  3685. (org-next-block 2)
  3686. (looking-at "#\\+BEGIN_QUOTE")))
  3687. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  3688. (should
  3689. (org-test-with-temp-text
  3690. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  3691. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  3692. (looking-at "#\\+BEGIN_QUOTE")))
  3693. ;; Optional argument is also case-insensitive.
  3694. (should
  3695. (org-test-with-temp-text
  3696. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
  3697. (let ((case-fold-search nil))
  3698. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  3699. (looking-at "#\\+begin_quote")))))
  3700. (ert-deftest test-org/previous-block ()
  3701. "Test `org-previous-block' specifications."
  3702. ;; Regular test.
  3703. (should
  3704. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
  3705. (org-previous-block 1)
  3706. (looking-at "#\\+BEGIN_CENTER")))
  3707. ;; Ignore case.
  3708. (should
  3709. (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
  3710. (let ((case-fold-search nil))
  3711. (org-previous-block 1)
  3712. (looking-at "#\\+begin_center"))))
  3713. ;; Ignore current line.
  3714. (should
  3715. (org-test-with-temp-text
  3716. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
  3717. (org-previous-block 1)
  3718. (looking-at "#\\+BEGIN_QUOTE")))
  3719. ;; Throw an error when no block is found.
  3720. (should-error
  3721. (org-test-with-temp-text "Paragraph<point>"
  3722. (org-previous-block 1)))
  3723. ;; With an argument, skip many blocks at once.
  3724. (should
  3725. (org-test-with-temp-text
  3726. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  3727. (org-previous-block 2)
  3728. (looking-at "#\\+BEGIN_CENTER")))
  3729. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  3730. (should
  3731. (org-test-with-temp-text
  3732. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  3733. (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  3734. (looking-at "#\\+BEGIN_QUOTE")))
  3735. ;; Optional argument is also case-insensitive.
  3736. (should
  3737. (org-test-with-temp-text
  3738. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
  3739. (let ((case-fold-search nil))
  3740. (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  3741. (looking-at "#\\+begin_quote")))))
  3742. ;;; Outline structure
  3743. (ert-deftest test-org/demote ()
  3744. "Test `org-demote' specifications."
  3745. ;; Add correct number of stars according to `org-odd-levels-only'.
  3746. (should
  3747. (= 2
  3748. (org-test-with-temp-text "* H"
  3749. (let ((org-odd-levels-only nil)) (org-demote))
  3750. (org-current-level))))
  3751. (should
  3752. (= 3
  3753. (org-test-with-temp-text "* H"
  3754. (let ((org-odd-levels-only t)) (org-demote))
  3755. (org-current-level))))
  3756. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  3757. (should
  3758. (org-test-with-temp-text "* H :tag:"
  3759. (let ((org-tags-column 10)
  3760. (org-auto-align-tags t)
  3761. (org-odd-levels-only nil))
  3762. (org-demote))
  3763. (org-move-to-column 10)
  3764. (looking-at-p ":tag:$")))
  3765. (should-not
  3766. (org-test-with-temp-text "* H :tag:"
  3767. (let ((org-tags-column 10)
  3768. (org-auto-align-tags nil)
  3769. (org-odd-levels-only nil))
  3770. (org-demote))
  3771. (org-move-to-column 10)
  3772. (looking-at-p ":tag:$")))
  3773. ;; When `org-adapt-indentation' is non-nil, always indent planning
  3774. ;; info and property drawers accordingly.
  3775. (should
  3776. (= 3
  3777. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  3778. (let ((org-odd-levels-only nil)
  3779. (org-adapt-indentation t))
  3780. (org-demote))
  3781. (forward-line)
  3782. (org-get-indentation))))
  3783. (should
  3784. (= 3
  3785. (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  3786. (let ((org-odd-levels-only nil)
  3787. (org-adapt-indentation t))
  3788. (org-demote))
  3789. (forward-line)
  3790. (org-get-indentation))))
  3791. (should-not
  3792. (= 3
  3793. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  3794. (let ((org-odd-levels-only nil)
  3795. (org-adapt-indentation nil))
  3796. (org-demote))
  3797. (forward-line)
  3798. (org-get-indentation))))
  3799. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  3800. ;; section accordingly. Ignore, however, footnote definitions and
  3801. ;; inlinetasks boundaries.
  3802. (should
  3803. (= 3
  3804. (org-test-with-temp-text "* H\n Paragraph"
  3805. (let ((org-odd-levels-only nil)
  3806. (org-adapt-indentation t))
  3807. (org-demote))
  3808. (forward-line)
  3809. (org-get-indentation))))
  3810. (should
  3811. (= 2
  3812. (org-test-with-temp-text "* H\n Paragraph"
  3813. (let ((org-odd-levels-only nil)
  3814. (org-adapt-indentation nil))
  3815. (org-demote))
  3816. (forward-line)
  3817. (org-get-indentation))))
  3818. (should
  3819. (zerop
  3820. (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
  3821. (let ((org-odd-levels-only nil)
  3822. (org-adapt-indentation t))
  3823. (org-demote))
  3824. (goto-char (point-max))
  3825. (org-get-indentation))))
  3826. (should
  3827. (= 3
  3828. (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
  3829. (let ((org-odd-levels-only nil)
  3830. (org-adapt-indentation t))
  3831. (org-demote))
  3832. (goto-char (point-max))
  3833. (org-get-indentation))))
  3834. (when (featurep 'org-inlinetask)
  3835. (should
  3836. (zerop
  3837. (let ((org-inlinetask-min-level 5)
  3838. (org-adapt-indentation t))
  3839. (org-test-with-temp-text "* H\n***** I\n***** END"
  3840. (org-demote)
  3841. (forward-line)
  3842. (org-get-indentation))))))
  3843. (when (featurep 'org-inlinetask)
  3844. (should
  3845. (= 3
  3846. (let ((org-inlinetask-min-level 5)
  3847. (org-adapt-indentation t))
  3848. (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
  3849. (org-demote)
  3850. (forward-line 2)
  3851. (org-get-indentation))))))
  3852. ;; Ignore contents of source blocks or example blocks when
  3853. ;; indentation should be preserved (through
  3854. ;; `org-src-preserve-indentation' or "-i" flag).
  3855. (should-not
  3856. (zerop
  3857. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  3858. (let ((org-adapt-indentation t)
  3859. (org-src-preserve-indentation nil))
  3860. (org-demote))
  3861. (forward-line 2)
  3862. (org-get-indentation))))
  3863. (should
  3864. (zerop
  3865. (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
  3866. (let ((org-adapt-indentation t)
  3867. (org-src-preserve-indentation t))
  3868. (org-demote))
  3869. (forward-line 2)
  3870. (org-get-indentation))))
  3871. (should
  3872. (zerop
  3873. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  3874. (let ((org-adapt-indentation t)
  3875. (org-src-preserve-indentation t))
  3876. (org-demote))
  3877. (forward-line 2)
  3878. (org-get-indentation))))
  3879. (should
  3880. (zerop
  3881. (org-test-with-temp-text
  3882. "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
  3883. (let ((org-adapt-indentation t)
  3884. (org-src-preserve-indentation nil))
  3885. (org-demote))
  3886. (forward-line 2)
  3887. (org-get-indentation)))))
  3888. (ert-deftest test-org/promote ()
  3889. "Test `org-promote' specifications."
  3890. ;; Return an error if headline is to be promoted to level 0, unless
  3891. ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
  3892. ;; headline becomes a comment.
  3893. (should-error
  3894. (org-test-with-temp-text "* H"
  3895. (let ((org-allow-promoting-top-level-subtree nil)) (org-promote))))
  3896. (should
  3897. (equal "# H"
  3898. (org-test-with-temp-text "* H"
  3899. (let ((org-allow-promoting-top-level-subtree t)) (org-promote))
  3900. (buffer-string))))
  3901. ;; Remove correct number of stars according to
  3902. ;; `org-odd-levels-only'.
  3903. (should
  3904. (= 2
  3905. (org-test-with-temp-text "*** H"
  3906. (let ((org-odd-levels-only nil)) (org-promote))
  3907. (org-current-level))))
  3908. (should
  3909. (= 1
  3910. (org-test-with-temp-text "*** H"
  3911. (let ((org-odd-levels-only t)) (org-promote))
  3912. (org-current-level))))
  3913. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  3914. (should
  3915. (org-test-with-temp-text "** H :tag:"
  3916. (let ((org-tags-column 10)
  3917. (org-auto-align-tags t)
  3918. (org-odd-levels-only nil))
  3919. (org-promote))
  3920. (org-move-to-column 10)
  3921. (looking-at-p ":tag:$")))
  3922. (should-not
  3923. (org-test-with-temp-text "** H :tag:"
  3924. (let ((org-tags-column 10)
  3925. (org-auto-align-tags nil)
  3926. (org-odd-levels-only nil))
  3927. (org-promote))
  3928. (org-move-to-column 10)
  3929. (looking-at-p ":tag:$")))
  3930. ;; When `org-adapt-indentation' is non-nil, always indent planning
  3931. ;; info and property drawers.
  3932. (should
  3933. (= 2
  3934. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  3935. (let ((org-odd-levels-only nil)
  3936. (org-adapt-indentation t))
  3937. (org-promote))
  3938. (forward-line)
  3939. (org-get-indentation))))
  3940. (should
  3941. (= 2
  3942. (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  3943. (let ((org-odd-levels-only nil)
  3944. (org-adapt-indentation t))
  3945. (org-promote))
  3946. (forward-line)
  3947. (org-get-indentation))))
  3948. (should-not
  3949. (= 2
  3950. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  3951. (let ((org-odd-levels-only nil)
  3952. (org-adapt-indentation nil))
  3953. (org-promote))
  3954. (forward-line)
  3955. (org-get-indentation))))
  3956. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  3957. ;; section accordingly. Ignore, however, footnote definitions and
  3958. ;; inlinetasks boundaries.
  3959. (should
  3960. (= 2
  3961. (org-test-with-temp-text "** H\n Paragraph"
  3962. (let ((org-odd-levels-only nil)
  3963. (org-adapt-indentation t))
  3964. (org-promote))
  3965. (forward-line)
  3966. (org-get-indentation))))
  3967. (should-not
  3968. (= 2
  3969. (org-test-with-temp-text "** H\n Paragraph"
  3970. (let ((org-odd-levels-only nil)
  3971. (org-adapt-indentation nil))
  3972. (org-promote))
  3973. (forward-line)
  3974. (org-get-indentation))))
  3975. (should
  3976. (= 2
  3977. (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
  3978. (let ((org-odd-levels-only nil)
  3979. (org-adapt-indentation t))
  3980. (org-promote))
  3981. (forward-line)
  3982. (org-get-indentation))))
  3983. (when (featurep 'org-inlinetask)
  3984. (should
  3985. (zerop
  3986. (let ((org-inlinetask-min-level 5)
  3987. (org-adapt-indentation t))
  3988. (org-test-with-temp-text "** H\n***** I\n***** END"
  3989. (org-promote)
  3990. (forward-line)
  3991. (org-get-indentation))))))
  3992. (when (featurep 'org-inlinetask)
  3993. (should
  3994. (= 2
  3995. (let ((org-inlinetask-min-level 5)
  3996. (org-adapt-indentation t))
  3997. (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
  3998. (org-promote)
  3999. (forward-line 2)
  4000. (org-get-indentation))))))
  4001. ;; Give up shifting if it would break document's structure
  4002. ;; otherwise.
  4003. (should
  4004. (= 3
  4005. (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
  4006. (let ((org-odd-levels-only nil)
  4007. (org-adapt-indentation t))
  4008. (org-promote))
  4009. (forward-line)
  4010. (org-get-indentation))))
  4011. (should
  4012. (= 3
  4013. (org-test-with-temp-text "** H\n Paragraph\n * list."
  4014. (let ((org-odd-levels-only nil)
  4015. (org-adapt-indentation t))
  4016. (org-promote))
  4017. (forward-line)
  4018. (org-get-indentation))))
  4019. ;; Ignore contents of source blocks or example blocks when
  4020. ;; indentation should be preserved (through
  4021. ;; `org-src-preserve-indentation' or "-i" flag).
  4022. (should-not
  4023. (zerop
  4024. (org-test-with-temp-text
  4025. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  4026. (let ((org-adapt-indentation t)
  4027. (org-src-preserve-indentation nil)
  4028. (org-odd-levels-only nil))
  4029. (org-promote))
  4030. (forward-line)
  4031. (org-get-indentation))))
  4032. (should
  4033. (zerop
  4034. (org-test-with-temp-text
  4035. "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
  4036. (let ((org-adapt-indentation t)
  4037. (org-src-preserve-indentation t)
  4038. (org-odd-levels-only nil))
  4039. (org-promote))
  4040. (forward-line)
  4041. (org-get-indentation))))
  4042. (should
  4043. (zerop
  4044. (org-test-with-temp-text
  4045. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  4046. (let ((org-adapt-indentation t)
  4047. (org-src-preserve-indentation t)
  4048. (org-odd-levels-only nil))
  4049. (org-promote))
  4050. (forward-line)
  4051. (org-get-indentation))))
  4052. (should
  4053. (zerop
  4054. (org-test-with-temp-text
  4055. "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
  4056. (let ((org-adapt-indentation t)
  4057. (org-src-preserve-indentation nil)
  4058. (org-odd-levels-only nil))
  4059. (org-promote))
  4060. (forward-line)
  4061. (org-get-indentation)))))
  4062. ;;; Planning
  4063. (ert-deftest test-org/at-planning-p ()
  4064. "Test `org-at-planning-p' specifications."
  4065. ;; Regular test.
  4066. (should
  4067. (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
  4068. (org-at-planning-p)))
  4069. (should-not
  4070. (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
  4071. (org-at-planning-p)))
  4072. ;; Correctly find planning attached to inlinetasks.
  4073. (when (featurep 'org-inlinetask)
  4074. (should
  4075. (org-test-with-temp-text
  4076. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
  4077. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4078. (should-not
  4079. (org-test-with-temp-text
  4080. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  4081. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4082. (should-not
  4083. (org-test-with-temp-text
  4084. "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  4085. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4086. (should-not
  4087. (org-test-with-temp-text
  4088. "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
  4089. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
  4090. (ert-deftest test-org/add-planning-info ()
  4091. "Test `org-add-planning-info'."
  4092. ;; Create deadline when `org-adapt-indentation' is non-nil.
  4093. (should
  4094. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4095. (org-test-with-temp-text "* H\nParagraph<point>"
  4096. (let ((org-adapt-indentation t))
  4097. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4098. (replace-regexp-in-string
  4099. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4100. nil nil 1))))
  4101. ;; Create deadline when `org-adapt-indentation' is nil.
  4102. (should
  4103. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  4104. (org-test-with-temp-text "* H\nParagraph<point>"
  4105. (let ((org-adapt-indentation nil))
  4106. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4107. (replace-regexp-in-string
  4108. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4109. nil nil 1))))
  4110. ;; Update deadline when `org-adapt-indentation' is non-nil.
  4111. (should
  4112. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4113. (org-test-with-temp-text "\
  4114. * H
  4115. DEADLINE: <2015-06-24 Wed>
  4116. Paragraph<point>"
  4117. (let ((org-adapt-indentation t))
  4118. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4119. (replace-regexp-in-string
  4120. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4121. nil nil 1))))
  4122. ;; Update deadline when `org-adapt-indentation' is nil.
  4123. (should
  4124. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  4125. (org-test-with-temp-text "\
  4126. * H
  4127. DEADLINE: <2015-06-24 Wed>
  4128. Paragraph<point>"
  4129. (let ((org-adapt-indentation nil))
  4130. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4131. (replace-regexp-in-string
  4132. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4133. nil nil 1))))
  4134. ;; Schedule when `org-adapt-indentation' is non-nil.
  4135. (should
  4136. (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
  4137. (org-test-with-temp-text "* H\nParagraph<point>"
  4138. (let ((org-adapt-indentation t))
  4139. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  4140. (replace-regexp-in-string
  4141. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4142. nil nil 1))))
  4143. ;; Schedule when `org-adapt-indentation' is nil.
  4144. (should
  4145. (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
  4146. (org-test-with-temp-text "* H\nParagraph<point>"
  4147. (let ((org-adapt-indentation nil))
  4148. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  4149. (replace-regexp-in-string
  4150. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4151. nil nil 1))))
  4152. ;; Add deadline when scheduled.
  4153. (should
  4154. (equal "\
  4155. * H
  4156. DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
  4157. Paragraph"
  4158. (org-test-with-temp-text "\
  4159. * H
  4160. SCHEDULED: <2015-06-24 Wed>
  4161. Paragraph<point>"
  4162. (let ((org-adapt-indentation t))
  4163. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4164. (replace-regexp-in-string
  4165. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4166. nil nil 1))))
  4167. ;; Remove middle entry.
  4168. (should
  4169. (equal "\
  4170. * H
  4171. CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
  4172. Paragraph"
  4173. (org-test-with-temp-text "\
  4174. * H
  4175. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  4176. Paragraph<point>"
  4177. (let ((org-adapt-indentation t))
  4178. (org-add-planning-info nil nil 'deadline))
  4179. (replace-regexp-in-string
  4180. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  4181. nil nil 1))))
  4182. ;; Remove last entry and then middle entry (order should not
  4183. ;; matter).
  4184. (should
  4185. (equal "\
  4186. * H
  4187. CLOSED: [2015-06-24]
  4188. Paragraph"
  4189. (org-test-with-temp-text "\
  4190. * H
  4191. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  4192. Paragraph<point>"
  4193. (let ((org-adapt-indentation t))
  4194. (org-add-planning-info nil nil 'scheduled 'deadline))
  4195. (replace-regexp-in-string
  4196. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  4197. nil nil 1))))
  4198. ;; Remove closed when `org-adapt-indentation' is non-nil.
  4199. (should
  4200. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4201. (org-test-with-temp-text "\
  4202. * H
  4203. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  4204. Paragraph<point>"
  4205. (let ((org-adapt-indentation t))
  4206. (org-add-planning-info nil nil 'closed))
  4207. (replace-regexp-in-string
  4208. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4209. nil nil 1))))
  4210. (should
  4211. (equal "* H\n Paragraph"
  4212. (org-test-with-temp-text "\
  4213. * H
  4214. CLOSED: [2015-06-25 Thu]
  4215. Paragraph<point>"
  4216. (let ((org-adapt-indentation t))
  4217. (org-add-planning-info nil nil 'closed))
  4218. (replace-regexp-in-string
  4219. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4220. nil nil 1))))
  4221. ;; Remove closed when `org-adapt-indentation' is nil.
  4222. (should
  4223. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  4224. (org-test-with-temp-text "\
  4225. * H
  4226. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  4227. Paragraph<point>"
  4228. (let ((org-adapt-indentation nil))
  4229. (org-add-planning-info nil nil 'closed))
  4230. (replace-regexp-in-string
  4231. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4232. nil nil 1))))
  4233. (should
  4234. (equal "* H\nParagraph"
  4235. (org-test-with-temp-text "\
  4236. * H
  4237. CLOSED: [2015-06-25 Thu]
  4238. Paragraph<point>"
  4239. (let ((org-adapt-indentation nil))
  4240. (org-add-planning-info nil nil 'closed))
  4241. (replace-regexp-in-string
  4242. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4243. nil nil 1))))
  4244. ;; Remove closed entry and delete empty line.
  4245. (should
  4246. (equal "\
  4247. * H
  4248. Paragraph"
  4249. (org-test-with-temp-text "\
  4250. * H
  4251. CLOSED: [2015-06-24 Wed]
  4252. Paragraph<point>"
  4253. (let ((org-adapt-indentation t))
  4254. (org-add-planning-info nil nil 'closed))
  4255. (replace-regexp-in-string
  4256. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4257. nil nil 1))))
  4258. ;; Remove one entry and update another.
  4259. (should
  4260. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4261. (org-test-with-temp-text "\
  4262. * H
  4263. SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
  4264. Paragraph<point>"
  4265. (let ((org-adapt-indentation t))
  4266. (org-add-planning-info 'deadline "<2015-06-25 Thu>" 'scheduled))
  4267. (replace-regexp-in-string
  4268. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4269. nil nil 1)))))
  4270. (ert-deftest test-org/deadline ()
  4271. "Test `org-deadline' specifications."
  4272. ;; Insert a new value or replace existing one.
  4273. (should
  4274. (equal "* H\nDEADLINE: <2012-03-29>\n"
  4275. (org-test-with-temp-text "* H"
  4276. (let ((org-adapt-indentation nil)
  4277. (org-last-inserted-timestamp nil))
  4278. (org-deadline nil "<2012-03-29 Tue>"))
  4279. (replace-regexp-in-string
  4280. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4281. nil nil 1))))
  4282. (should
  4283. (equal "* H\nDEADLINE: <2014-03-04>"
  4284. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  4285. (let ((org-adapt-indentation nil)
  4286. (org-last-inserted-timestamp nil))
  4287. (org-deadline nil "<2014-03-04 Thu>"))
  4288. (replace-regexp-in-string
  4289. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4290. nil nil 1))))
  4291. ;; Accept delta time, e.g., "+2d".
  4292. (should
  4293. (equal "* H\nDEADLINE: <2015-03-04>\n"
  4294. (cl-letf (((symbol-function 'current-time)
  4295. (lambda (&rest args)
  4296. (apply #'encode-time
  4297. (org-parse-time-string "2014-03-04")))))
  4298. (org-test-with-temp-text "* H"
  4299. (let ((org-adapt-indentation nil)
  4300. (org-last-inserted-timestamp nil))
  4301. (org-deadline nil "+1y"))
  4302. (replace-regexp-in-string
  4303. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  4304. ;; Preserve repeater.
  4305. (should
  4306. (equal "* H\nDEADLINE: <2012-03-29 +2y>\n"
  4307. (org-test-with-temp-text "* H"
  4308. (let ((org-adapt-indentation nil)
  4309. (org-last-inserted-timestamp nil))
  4310. (org-deadline nil "<2012-03-29 Tue +2y>"))
  4311. (replace-regexp-in-string
  4312. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  4313. ;; Remove CLOSED keyword, if any.
  4314. (should
  4315. (equal "* H\nDEADLINE: <2012-03-29>"
  4316. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  4317. (let ((org-adapt-indentation nil)
  4318. (org-last-inserted-timestamp nil))
  4319. (org-deadline nil "<2012-03-29 Tue>"))
  4320. (replace-regexp-in-string
  4321. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  4322. ;; With C-u argument, remove DEADLINE keyword.
  4323. (should
  4324. (equal "* H\n"
  4325. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  4326. (let ((org-adapt-indentation nil)
  4327. (org-last-inserted-timestamp nil))
  4328. (org-deadline '(4)))
  4329. (buffer-string))))
  4330. (should
  4331. (equal "* H"
  4332. (org-test-with-temp-text "* H"
  4333. (let ((org-adapt-indentation nil)
  4334. (org-last-inserted-timestamp nil))
  4335. (org-deadline '(4)))
  4336. (buffer-string))))
  4337. ;; With C-u C-u argument, prompt for a delay cookie.
  4338. (should
  4339. (equal "* H\nDEADLINE: <2012-03-29 -705d>"
  4340. (cl-letf (((symbol-function 'org-read-date)
  4341. (lambda (&rest args)
  4342. (apply #'encode-time
  4343. (org-parse-time-string "2014-03-04")))))
  4344. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  4345. (let ((org-adapt-indentation nil)
  4346. (org-last-inserted-timestamp nil))
  4347. (org-deadline '(16)))
  4348. (buffer-string)))))
  4349. (should-error
  4350. (cl-letf (((symbol-function 'org-read-date)
  4351. (lambda (&rest args)
  4352. (apply #'encode-time
  4353. (org-parse-time-string "2014-03-04")))))
  4354. (org-test-with-temp-text "* H"
  4355. (let ((org-adapt-indentation nil)
  4356. (org-last-inserted-timestamp nil))
  4357. (org-deadline '(16)))
  4358. (buffer-string))))
  4359. ;; When a region is active and
  4360. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  4361. ;; same value in all headlines in region.
  4362. (should
  4363. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
  4364. (org-test-with-temp-text "* H1\n* H2"
  4365. (let ((org-adapt-indentation nil)
  4366. (org-last-inserted-timestamp nil)
  4367. (org-loop-over-headlines-in-active-region t))
  4368. (transient-mark-mode 1)
  4369. (push-mark (point) t t)
  4370. (goto-char (point-max))
  4371. (org-deadline nil "2012-03-29"))
  4372. (replace-regexp-in-string
  4373. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  4374. (should-not
  4375. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
  4376. (org-test-with-temp-text "* H1\n* H2"
  4377. (let ((org-adapt-indentation nil)
  4378. (org-last-inserted-timestamp nil)
  4379. (org-loop-over-headlines-in-active-region nil))
  4380. (transient-mark-mode 1)
  4381. (push-mark (point) t t)
  4382. (goto-char (point-max))
  4383. (org-deadline nil "2012-03-29"))
  4384. (replace-regexp-in-string
  4385. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  4386. (ert-deftest test-org/schedule ()
  4387. "Test `org-schedule' specifications."
  4388. ;; Insert a new value or replace existing one.
  4389. (should
  4390. (equal "* H\nSCHEDULED: <2012-03-29>\n"
  4391. (org-test-with-temp-text "* H"
  4392. (let ((org-adapt-indentation nil)
  4393. (org-last-inserted-timestamp nil))
  4394. (org-schedule nil "<2012-03-29 Tue>"))
  4395. (replace-regexp-in-string
  4396. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4397. nil nil 1))))
  4398. (should
  4399. (equal "* H\nSCHEDULED: <2014-03-04>"
  4400. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  4401. (let ((org-adapt-indentation nil)
  4402. (org-last-inserted-timestamp nil))
  4403. (org-schedule nil "<2014-03-04 Thu>"))
  4404. (replace-regexp-in-string
  4405. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4406. nil nil 1))))
  4407. ;; Accept delta time, e.g., "+2d".
  4408. (should
  4409. (equal "* H\nSCHEDULED: <2015-03-04>\n"
  4410. (cl-letf (((symbol-function 'current-time)
  4411. (lambda (&rest args)
  4412. (apply #'encode-time
  4413. (org-parse-time-string "2014-03-04")))))
  4414. (org-test-with-temp-text "* H"
  4415. (let ((org-adapt-indentation nil)
  4416. (org-last-inserted-timestamp nil))
  4417. (org-schedule nil "+1y"))
  4418. (replace-regexp-in-string
  4419. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  4420. ;; Preserve repeater.
  4421. (should
  4422. (equal "* H\nSCHEDULED: <2012-03-29 +2y>\n"
  4423. (org-test-with-temp-text "* H"
  4424. (let ((org-adapt-indentation nil)
  4425. (org-last-inserted-timestamp nil))
  4426. (org-schedule nil "<2012-03-29 Tue +2y>"))
  4427. (replace-regexp-in-string
  4428. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  4429. ;; Remove CLOSED keyword, if any.
  4430. (should
  4431. (equal "* H\nSCHEDULED: <2012-03-29>"
  4432. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  4433. (let ((org-adapt-indentation nil)
  4434. (org-last-inserted-timestamp nil))
  4435. (org-schedule nil "<2012-03-29 Tue>"))
  4436. (replace-regexp-in-string
  4437. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  4438. ;; With C-u argument, remove SCHEDULED keyword.
  4439. (should
  4440. (equal "* H\n"
  4441. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  4442. (let ((org-adapt-indentation nil)
  4443. (org-last-inserted-timestamp nil))
  4444. (org-schedule '(4)))
  4445. (buffer-string))))
  4446. (should
  4447. (equal "* H"
  4448. (org-test-with-temp-text "* H"
  4449. (let ((org-adapt-indentation nil)
  4450. (org-last-inserted-timestamp nil))
  4451. (org-schedule '(4)))
  4452. (buffer-string))))
  4453. ;; With C-u C-u argument, prompt for a delay cookie.
  4454. (should
  4455. (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
  4456. (cl-letf (((symbol-function 'org-read-date)
  4457. (lambda (&rest args)
  4458. (apply #'encode-time
  4459. (org-parse-time-string "2014-03-04")))))
  4460. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  4461. (let ((org-adapt-indentation nil)
  4462. (org-last-inserted-timestamp nil))
  4463. (org-schedule '(16)))
  4464. (buffer-string)))))
  4465. (should-error
  4466. (cl-letf (((symbol-function 'org-read-date)
  4467. (lambda (&rest args)
  4468. (apply #'encode-time
  4469. (org-parse-time-string "2014-03-04")))))
  4470. (org-test-with-temp-text "* H"
  4471. (let ((org-adapt-indentation nil)
  4472. (org-last-inserted-timestamp nil))
  4473. (org-schedule '(16)))
  4474. (buffer-string))))
  4475. ;; When a region is active and
  4476. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  4477. ;; same value in all headlines in region.
  4478. (should
  4479. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
  4480. (org-test-with-temp-text "* H1\n* H2"
  4481. (let ((org-adapt-indentation nil)
  4482. (org-last-inserted-timestamp nil)
  4483. (org-loop-over-headlines-in-active-region t))
  4484. (transient-mark-mode 1)
  4485. (push-mark (point) t t)
  4486. (goto-char (point-max))
  4487. (org-schedule nil "2012-03-29"))
  4488. (replace-regexp-in-string
  4489. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  4490. (should-not
  4491. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
  4492. (org-test-with-temp-text "* H1\n* H2"
  4493. (let ((org-adapt-indentation nil)
  4494. (org-last-inserted-timestamp nil)
  4495. (org-loop-over-headlines-in-active-region nil))
  4496. (transient-mark-mode 1)
  4497. (push-mark (point) t t)
  4498. (goto-char (point-max))
  4499. (org-schedule nil "2012-03-29"))
  4500. (replace-regexp-in-string
  4501. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  4502. (should
  4503. ;; check if a repeater survives re-scheduling.
  4504. (string-match-p
  4505. "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
  4506. (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
  4507. (let ((org-adapt-indentation nil)
  4508. (org-last-inserted-timestamp nil))
  4509. (org-schedule nil "2017-02-01"))
  4510. (buffer-string)))))
  4511. ;;; Property API
  4512. (ert-deftest test-org/buffer-property-keys ()
  4513. "Test `org-buffer-property-keys' specifications."
  4514. ;; Retrieve properties accross siblings.
  4515. (should
  4516. (equal '("A" "B")
  4517. (org-test-with-temp-text "
  4518. * H1
  4519. :PROPERTIES:
  4520. :A: 1
  4521. :END:
  4522. * H2
  4523. :PROPERTIES:
  4524. :B: 1
  4525. :END:"
  4526. (org-buffer-property-keys))))
  4527. ;; Retrieve properties accross children.
  4528. (should
  4529. (equal '("A" "B")
  4530. (org-test-with-temp-text "
  4531. * H1
  4532. :PROPERTIES:
  4533. :A: 1
  4534. :END:
  4535. ** H2
  4536. :PROPERTIES:
  4537. :B: 1
  4538. :END:"
  4539. (org-buffer-property-keys))))
  4540. ;; Retrieve muliple properties in the same drawer.
  4541. (should
  4542. (equal '("A" "B")
  4543. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  4544. (org-buffer-property-keys))))
  4545. ;; Ignore extension symbol in property name.
  4546. (should
  4547. (equal '("A")
  4548. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  4549. (org-buffer-property-keys))))
  4550. ;; With non-nil COLUMNS, extract property names from columns.
  4551. (should
  4552. (equal '("A" "B")
  4553. (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
  4554. (org-buffer-property-keys nil nil t))))
  4555. (should
  4556. (equal '("A" "B" "COLUMNS")
  4557. (org-test-with-temp-text
  4558. "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
  4559. (org-buffer-property-keys nil nil t))))
  4560. ;; With non-nil IGNORE-MALFORMED malformed property drawers are silently ignored.
  4561. (should
  4562. (equal '("A")
  4563. (org-test-with-temp-text
  4564. "* a\n:PROPERTIES:\n:A: 1\n:END:\n* b\n:PROPERTIES:\nsome junk here\n:END:\n"
  4565. (org-buffer-property-keys nil nil nil t)))))
  4566. (ert-deftest test-org/property-values ()
  4567. "Test `org-property-values' specifications."
  4568. ;; Regular test.
  4569. (should
  4570. (equal '("2" "1")
  4571. (org-test-with-temp-text
  4572. "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
  4573. (org-property-values "A"))))
  4574. ;; Ignore empty values.
  4575. (should-not
  4576. (org-test-with-temp-text
  4577. "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
  4578. (org-property-values "A")))
  4579. ;; Take into consideration extended values.
  4580. (should
  4581. (equal '("1 2")
  4582. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  4583. (org-property-values "A")))))
  4584. (ert-deftest test-org/find-property ()
  4585. "Test `org-find-property' specifications."
  4586. ;; Regular test.
  4587. (should
  4588. (= 1
  4589. (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
  4590. (org-find-property "prop"))))
  4591. ;; Ignore false positives.
  4592. (should
  4593. (= 27
  4594. (org-test-with-temp-text
  4595. "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
  4596. (org-find-property "A"))))
  4597. ;; Return first entry found in buffer.
  4598. (should
  4599. (= 1
  4600. (org-test-with-temp-text
  4601. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  4602. (org-find-property "A"))))
  4603. ;; Only search visible part of the buffer.
  4604. (should
  4605. (= 31
  4606. (org-test-with-temp-text
  4607. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  4608. (org-narrow-to-subtree)
  4609. (org-find-property "A"))))
  4610. ;; With optional argument, only find entries with a specific value.
  4611. (should-not
  4612. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  4613. (org-find-property "A" "2")))
  4614. (should
  4615. (= 31
  4616. (org-test-with-temp-text
  4617. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
  4618. (org-find-property "A" "2"))))
  4619. ;; Use "nil" for explicit nil values.
  4620. (should
  4621. (= 31
  4622. (org-test-with-temp-text
  4623. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
  4624. (org-find-property "A" "nil")))))
  4625. (ert-deftest test-org/entry-delete ()
  4626. "Test `org-entry-delete' specifications."
  4627. ;; Regular test.
  4628. (should
  4629. (string-match
  4630. " *:PROPERTIES:\n *:B: +2\n *:END:"
  4631. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  4632. (org-entry-delete (point) "A")
  4633. (buffer-string))))
  4634. ;; Also remove accumulated properties.
  4635. (should-not
  4636. (string-match
  4637. ":A"
  4638. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
  4639. (org-entry-delete (point) "A")
  4640. (buffer-string))))
  4641. ;; When last property is removed, remove the property drawer.
  4642. (should-not
  4643. (string-match
  4644. ":PROPERTIES:"
  4645. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
  4646. (org-entry-delete (point) "A")
  4647. (buffer-string))))
  4648. ;; Return a non-nil value when some property was removed.
  4649. (should
  4650. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  4651. (org-entry-delete (point) "A")))
  4652. (should-not
  4653. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  4654. (org-entry-delete (point) "C")))
  4655. ;; Special properties cannot be located in a drawer. Allow to
  4656. ;; remove them anyway, in case of user error.
  4657. (should
  4658. (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
  4659. (org-entry-delete (point) "SCHEDULED"))))
  4660. (ert-deftest test-org/entry-get ()
  4661. "Test `org-entry-get' specifications."
  4662. ;; Regular test.
  4663. (should
  4664. (equal "1"
  4665. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  4666. (org-entry-get (point) "A"))))
  4667. ;; Ignore case.
  4668. (should
  4669. (equal "1"
  4670. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  4671. (org-entry-get (point) "a"))))
  4672. ;; Handle extended values, both before and after base value.
  4673. (should
  4674. (equal "1 2 3"
  4675. (org-test-with-temp-text
  4676. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  4677. (org-entry-get (point) "A"))))
  4678. ;; Empty values are returned as the empty string.
  4679. (should
  4680. (equal ""
  4681. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
  4682. (org-entry-get (point) "A"))))
  4683. ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
  4684. ;; otherwise, return nil.
  4685. (should-not
  4686. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  4687. (org-entry-get (point) "A")))
  4688. (should
  4689. (equal "nil"
  4690. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  4691. (org-entry-get (point) "A" nil t))))
  4692. ;; Return nil when no property is found, independently on the
  4693. ;; LITERAL-NIL argument.
  4694. (should-not
  4695. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  4696. (org-entry-get (point) "B")))
  4697. (should-not
  4698. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  4699. (org-entry-get (point) "B" nil t)))
  4700. ;; Handle inheritance, when allowed. Include extended values and
  4701. ;; possibly global values.
  4702. (should
  4703. (equal
  4704. "1"
  4705. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
  4706. (org-entry-get (point) "A" t))))
  4707. (should
  4708. (equal
  4709. "1"
  4710. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
  4711. (let ((org-use-property-inheritance t))
  4712. (org-entry-get (point) "A" 'selective)))))
  4713. (should-not
  4714. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
  4715. (let ((org-use-property-inheritance nil))
  4716. (org-entry-get (point) "A" 'selective))))
  4717. (should
  4718. (equal
  4719. "1 2"
  4720. (org-test-with-temp-text
  4721. "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
  4722. (org-entry-get (point-max) "A" t))))
  4723. (should
  4724. (equal "1"
  4725. (org-test-with-temp-text
  4726. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
  4727. (org-mode-restart)
  4728. (org-entry-get (point-max) "A" t))))
  4729. (should
  4730. (equal "0 1"
  4731. (org-test-with-temp-text
  4732. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
  4733. (org-mode-restart)
  4734. (org-entry-get (point-max) "A" t)))))
  4735. (ert-deftest test-org/entry-properties ()
  4736. "Test `org-entry-properties' specifications."
  4737. ;; Get "ITEM" property.
  4738. (should
  4739. (equal "H"
  4740. (org-test-with-temp-text "* TODO H"
  4741. (cdr (assoc "ITEM" (org-entry-properties nil "ITEM"))))))
  4742. (should
  4743. (equal "H"
  4744. (org-test-with-temp-text "* TODO H"
  4745. (cdr (assoc "ITEM" (org-entry-properties))))))
  4746. ;; Get "TODO" property. TODO keywords are case sensitive.
  4747. (should
  4748. (equal "TODO"
  4749. (org-test-with-temp-text "* TODO H"
  4750. (cdr (assoc "TODO" (org-entry-properties nil "TODO"))))))
  4751. (should
  4752. (equal "TODO"
  4753. (org-test-with-temp-text "* TODO H"
  4754. (cdr (assoc "TODO" (org-entry-properties))))))
  4755. (should-not
  4756. (org-test-with-temp-text "* H"
  4757. (assoc "TODO" (org-entry-properties nil "TODO"))))
  4758. (should-not
  4759. (org-test-with-temp-text "* todo H"
  4760. (assoc "TODO" (org-entry-properties nil "TODO"))))
  4761. ;; Get "PRIORITY" property.
  4762. (should
  4763. (equal "A"
  4764. (org-test-with-temp-text "* [#A] H"
  4765. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  4766. (should
  4767. (equal "A"
  4768. (org-test-with-temp-text "* [#A] H"
  4769. (cdr (assoc "PRIORITY" (org-entry-properties))))))
  4770. (should
  4771. (equal (char-to-string org-default-priority)
  4772. (org-test-with-temp-text "* H"
  4773. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  4774. ;; Get "FILE" property.
  4775. (should
  4776. (org-test-with-temp-text-in-file "* H\nParagraph"
  4777. (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil "FILE")))
  4778. (buffer-file-name))))
  4779. (should
  4780. (org-test-with-temp-text-in-file "* H\nParagraph"
  4781. (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
  4782. (buffer-file-name))))
  4783. (should-not
  4784. (org-test-with-temp-text "* H\nParagraph"
  4785. (cdr (assoc "FILE" (org-entry-properties nil "FILE")))))
  4786. ;; Get "TAGS" property.
  4787. (should
  4788. (equal ":tag1:tag2:"
  4789. (org-test-with-temp-text "* H :tag1:tag2:"
  4790. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS"))))))
  4791. (should
  4792. (equal ":tag1:tag2:"
  4793. (org-test-with-temp-text "* H :tag1:tag2:"
  4794. (cdr (assoc "TAGS" (org-entry-properties))))))
  4795. (should-not
  4796. (org-test-with-temp-text "* H"
  4797. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS")))))
  4798. ;; Get "ALLTAGS" property.
  4799. (should
  4800. (equal ":tag1:tag2:"
  4801. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  4802. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS"))))))
  4803. (should
  4804. (equal ":tag1:tag2:"
  4805. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  4806. (cdr (assoc "ALLTAGS" (org-entry-properties))))))
  4807. (should-not
  4808. (org-test-with-temp-text "* H"
  4809. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS")))))
  4810. ;; Get "BLOCKED" property.
  4811. (should
  4812. (equal "t"
  4813. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  4814. (let ((org-enforce-todo-dependencies t)
  4815. (org-blocker-hook
  4816. '(org-block-todo-from-children-or-siblings-or-parent)))
  4817. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  4818. (should
  4819. (equal ""
  4820. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  4821. (let ((org-enforce-todo-dependencies t)
  4822. (org-blocker-hook
  4823. '(org-block-todo-from-children-or-siblings-or-parent)))
  4824. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  4825. ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
  4826. (should
  4827. (equal
  4828. "[2012-03-29 thu.]"
  4829. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  4830. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED"))))))
  4831. (should
  4832. (equal
  4833. "[2012-03-29 thu.]"
  4834. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  4835. (cdr (assoc "CLOSED" (org-entry-properties))))))
  4836. (should-not
  4837. (org-test-with-temp-text "* H"
  4838. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED")))))
  4839. (should
  4840. (equal
  4841. "<2014-03-04 tue.>"
  4842. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  4843. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE"))))))
  4844. (should
  4845. (equal
  4846. "<2014-03-04 tue.>"
  4847. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  4848. (cdr (assoc "DEADLINE" (org-entry-properties))))))
  4849. (should-not
  4850. (org-test-with-temp-text "* H"
  4851. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE")))))
  4852. (should
  4853. (equal
  4854. "<2014-03-04 tue.>"
  4855. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  4856. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED"))))))
  4857. (should
  4858. (equal
  4859. "<2014-03-04 tue.>"
  4860. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  4861. (cdr (assoc "SCHEDULED" (org-entry-properties))))))
  4862. (should-not
  4863. (org-test-with-temp-text "* H"
  4864. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED")))))
  4865. ;; Get "CATEGORY"
  4866. (should
  4867. (equal "cat"
  4868. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  4869. (cdr (assoc "CATEGORY" (org-entry-properties))))))
  4870. (should
  4871. (equal "cat"
  4872. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  4873. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  4874. (should
  4875. (equal "cat"
  4876. (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
  4877. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  4878. (should
  4879. (equal "cat2"
  4880. (org-test-with-temp-text
  4881. (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  4882. "\n"
  4883. "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
  4884. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  4885. ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
  4886. (should
  4887. (equal "<2012-03-29 thu.>"
  4888. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
  4889. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  4890. (should
  4891. (equal "[2012-03-29 thu.]"
  4892. (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
  4893. (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
  4894. (should
  4895. (equal "<2012-03-29 thu.>"
  4896. (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
  4897. (cdr (assoc "TIMESTAMP" (org-entry-properties nil "TIMESTAMP"))))))
  4898. (should
  4899. (equal "[2014-03-04 tue.]"
  4900. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
  4901. (cdr (assoc "TIMESTAMP_IA"
  4902. (org-entry-properties nil "TIMESTAMP_IA"))))))
  4903. (should-not
  4904. (equal "<2012-03-29 thu.>"
  4905. (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
  4906. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  4907. ;; Get standard properties.
  4908. (should
  4909. (equal "1"
  4910. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  4911. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  4912. ;; Handle extended properties.
  4913. (should
  4914. (equal "1 2 3"
  4915. (org-test-with-temp-text
  4916. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  4917. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  4918. (should
  4919. (equal "1 2 3"
  4920. (org-test-with-temp-text
  4921. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
  4922. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  4923. ;; Ignore forbidden (special) properties.
  4924. (should-not
  4925. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
  4926. (cdr (assoc "TODO" (org-entry-properties nil 'standard))))))
  4927. (ert-deftest test-org/entry-put ()
  4928. "Test `org-entry-put' specifications."
  4929. ;; Error when not a string or nil.
  4930. (should-error
  4931. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  4932. (org-entry-put 1 "test" 2)))
  4933. ;; Error when property name is invalid.
  4934. (should-error
  4935. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  4936. (org-entry-put 1 "no space" "value")))
  4937. (should-error
  4938. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  4939. (org-entry-put 1 "" "value")))
  4940. ;; Set "TODO" property.
  4941. (should
  4942. (string-match (regexp-quote " TODO H")
  4943. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  4944. (org-entry-put (point) "TODO" "TODO")
  4945. (buffer-string))))
  4946. (should
  4947. (string-match (regexp-quote "* H")
  4948. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  4949. (org-entry-put (point) "TODO" nil)
  4950. (buffer-string))))
  4951. ;; Set "PRIORITY" property.
  4952. (should
  4953. (equal "* [#A] H"
  4954. (org-test-with-temp-text "* [#B] H"
  4955. (org-entry-put (point) "PRIORITY" "A")
  4956. (buffer-string))))
  4957. (should
  4958. (equal "* H"
  4959. (org-test-with-temp-text "* [#B] H"
  4960. (org-entry-put (point) "PRIORITY" nil)
  4961. (buffer-string))))
  4962. ;; Set "SCHEDULED" property.
  4963. (should
  4964. (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
  4965. (org-test-with-temp-text "* H"
  4966. (org-entry-put (point) "SCHEDULED" "2014-03-04")
  4967. (buffer-string))))
  4968. (should
  4969. (string= "* H\n"
  4970. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  4971. (org-entry-put (point) "SCHEDULED" nil)
  4972. (buffer-string))))
  4973. (should
  4974. (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
  4975. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  4976. (org-entry-put (point) "SCHEDULED" "earlier")
  4977. (buffer-string))))
  4978. (should
  4979. (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
  4980. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  4981. (org-entry-put (point) "SCHEDULED" "later")
  4982. (buffer-string))))
  4983. ;; Set "DEADLINE" property.
  4984. (should
  4985. (string-match "^ *DEADLINE: <2014-03-04 .*?>"
  4986. (org-test-with-temp-text "* H"
  4987. (org-entry-put (point) "DEADLINE" "2014-03-04")
  4988. (buffer-string))))
  4989. (should
  4990. (string= "* H\n"
  4991. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  4992. (org-entry-put (point) "DEADLINE" nil)
  4993. (buffer-string))))
  4994. (should
  4995. (string-match "^ *DEADLINE: <2014-03-03 .*?>"
  4996. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  4997. (org-entry-put (point) "DEADLINE" "earlier")
  4998. (buffer-string))))
  4999. (should
  5000. (string-match "^ *DEADLINE: <2014-03-05 .*?>"
  5001. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5002. (org-entry-put (point) "DEADLINE" "later")
  5003. (buffer-string))))
  5004. ;; Set "CATEGORY" property
  5005. (should
  5006. (string-match "^ *:CATEGORY: cat"
  5007. (org-test-with-temp-text "* H"
  5008. (org-entry-put (point) "CATEGORY" "cat")
  5009. (buffer-string))))
  5010. ;; Regular properties, with or without pre-existing drawer.
  5011. (should
  5012. (string-match "^ *:A: +2$"
  5013. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5014. (org-entry-put (point) "A" "2")
  5015. (buffer-string))))
  5016. (should
  5017. (string-match "^ *:A: +1$"
  5018. (org-test-with-temp-text "* H"
  5019. (org-entry-put (point) "A" "1")
  5020. (buffer-string))))
  5021. ;; Special case: two consecutive headlines.
  5022. (should
  5023. (string-match "\\* A\n *:PROPERTIES:"
  5024. (org-test-with-temp-text "* A\n** B"
  5025. (org-entry-put (point) "A" "1")
  5026. (buffer-string)))))
  5027. (ert-deftest test-org/refresh-properties ()
  5028. "Test `org-refresh-properties' specifications."
  5029. (should
  5030. (equal "1"
  5031. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5032. (org-refresh-properties "A" 'org-test)
  5033. (get-text-property (point) 'org-test))))
  5034. (should-not
  5035. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5036. (org-refresh-properties "B" 'org-test)
  5037. (get-text-property (point) 'org-test)))
  5038. ;; Handle properties only defined with extension syntax, i.e.,
  5039. ;; "PROPERTY+".
  5040. (should
  5041. (equal "1"
  5042. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
  5043. (org-refresh-properties "A" 'org-test)
  5044. (get-text-property (point) 'org-test))))
  5045. ;; When property is inherited, add text property to the whole
  5046. ;; sub-tree.
  5047. (should
  5048. (equal "1"
  5049. (org-test-with-temp-text
  5050. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
  5051. (let ((org-use-property-inheritance t))
  5052. (org-refresh-properties "A" 'org-test))
  5053. (get-text-property (point) 'org-test))))
  5054. ;; When property is inherited, use global value across the whole
  5055. ;; buffer. However local values have precedence.
  5056. (should-not
  5057. (equal "1"
  5058. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  5059. (org-mode-restart)
  5060. (let ((org-use-property-inheritance nil))
  5061. (org-refresh-properties "A" 'org-test))
  5062. (get-text-property (point) 'org-test))))
  5063. (should
  5064. (equal "1"
  5065. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  5066. (org-mode-restart)
  5067. (let ((org-use-property-inheritance t))
  5068. (org-refresh-properties "A" 'org-test))
  5069. (get-text-property (point) 'org-test))))
  5070. (should
  5071. (equal "2"
  5072. (org-test-with-temp-text
  5073. "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
  5074. (org-mode-restart)
  5075. (let ((org-use-property-inheritance t))
  5076. (org-refresh-properties "A" 'org-test))
  5077. (get-text-property (point) 'org-test)))))
  5078. ;;; Radio Targets
  5079. (ert-deftest test-org/update-radio-target-regexp ()
  5080. "Test `org-update-radio-target-regexp' specifications."
  5081. ;; Properly update cache with no previous radio target regexp.
  5082. (should
  5083. (eq 'link
  5084. (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
  5085. (save-excursion (goto-char (point-max)) (org-element-context))
  5086. (insert "<<<")
  5087. (search-forward "o")
  5088. (insert ">>>")
  5089. (org-update-radio-target-regexp)
  5090. (goto-char (point-max))
  5091. (org-element-type (org-element-context)))))
  5092. ;; Properly update cache with previous radio target regexp.
  5093. (should
  5094. (eq 'link
  5095. (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
  5096. (save-excursion (goto-char (point-max)) (org-element-context))
  5097. (insert "<<<")
  5098. (search-forward "o")
  5099. (insert ">>>")
  5100. (org-update-radio-target-regexp)
  5101. (search-backward "r")
  5102. (delete-char 5)
  5103. (insert "new")
  5104. (org-update-radio-target-regexp)
  5105. (goto-char (point-max))
  5106. (delete-region (line-beginning-position) (point))
  5107. (insert "new")
  5108. (org-element-type (org-element-context))))))
  5109. ;;; Sparse trees
  5110. (ert-deftest test-org/match-sparse-tree ()
  5111. "Test `org-match-sparse-tree' specifications."
  5112. ;; Match tags.
  5113. (should-not
  5114. (org-test-with-temp-text "* H\n** H1 :tag:"
  5115. (org-match-sparse-tree nil "tag")
  5116. (search-forward "H1")
  5117. (org-invisible-p2)))
  5118. (should
  5119. (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
  5120. (org-match-sparse-tree nil "tag")
  5121. (search-forward "H2")
  5122. (org-invisible-p2)))
  5123. ;; "-" operator for tags.
  5124. (should-not
  5125. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  5126. (org-match-sparse-tree nil "tag1-tag2")
  5127. (search-forward "H1")
  5128. (org-invisible-p2)))
  5129. (should
  5130. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  5131. (org-match-sparse-tree nil "tag1-tag2")
  5132. (search-forward "H2")
  5133. (org-invisible-p2)))
  5134. ;; "&" operator for tags.
  5135. (should
  5136. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  5137. (org-match-sparse-tree nil "tag1&tag2")
  5138. (search-forward "H1")
  5139. (org-invisible-p2)))
  5140. (should-not
  5141. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  5142. (org-match-sparse-tree nil "tag1&tag2")
  5143. (search-forward "H2")
  5144. (org-invisible-p2)))
  5145. ;; "|" operator for tags.
  5146. (should-not
  5147. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  5148. (org-match-sparse-tree nil "tag1|tag2")
  5149. (search-forward "H1")
  5150. (org-invisible-p2)))
  5151. (should-not
  5152. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  5153. (org-match-sparse-tree nil "tag1|tag2")
  5154. (search-forward "H2")
  5155. (org-invisible-p2)))
  5156. ;; Regexp match on tags.
  5157. (should-not
  5158. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  5159. (org-match-sparse-tree nil "{^tag.*}")
  5160. (search-forward "H1")
  5161. (org-invisible-p2)))
  5162. (should
  5163. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  5164. (org-match-sparse-tree nil "{^tag.*}")
  5165. (search-forward "H2")
  5166. (org-invisible-p2)))
  5167. ;; Match group tags.
  5168. (should-not
  5169. (org-test-with-temp-text
  5170. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  5171. (org-match-sparse-tree nil "work")
  5172. (search-forward "H1")
  5173. (org-invisible-p2)))
  5174. (should-not
  5175. (org-test-with-temp-text
  5176. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  5177. (org-match-sparse-tree nil "work")
  5178. (search-forward "H2")
  5179. (org-invisible-p2)))
  5180. ;; Match group tags with hard brackets.
  5181. (should-not
  5182. (org-test-with-temp-text
  5183. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  5184. (org-match-sparse-tree nil "work")
  5185. (search-forward "H1")
  5186. (org-invisible-p2)))
  5187. (should-not
  5188. (org-test-with-temp-text
  5189. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  5190. (org-match-sparse-tree nil "work")
  5191. (search-forward "H2")
  5192. (org-invisible-p2)))
  5193. ;; Match tags in hierarchies
  5194. (should-not
  5195. (org-test-with-temp-text
  5196. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  5197. #+TAGS: [ Lev_2 : Lev_3 ]\n
  5198. #+TAGS: { Lev_3 : Lev_4 }\n
  5199. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  5200. (org-match-sparse-tree nil "Lev_1")
  5201. (search-forward "H4")
  5202. (org-invisible-p2)))
  5203. ;; Match regular expressions in tags
  5204. (should-not
  5205. (org-test-with-temp-text
  5206. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
  5207. (org-match-sparse-tree nil "Lev")
  5208. (search-forward "H1")
  5209. (org-invisible-p2)))
  5210. (should
  5211. (org-test-with-temp-text
  5212. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
  5213. (org-match-sparse-tree nil "Lev")
  5214. (search-forward "H1")
  5215. (org-invisible-p2)))
  5216. ;; Match properties.
  5217. (should
  5218. (org-test-with-temp-text
  5219. "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
  5220. (org-match-sparse-tree nil "A=\"1\"")
  5221. (search-forward "H2")
  5222. (org-invisible-p2)))
  5223. (should-not
  5224. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  5225. (org-match-sparse-tree nil "A=\"1\"")
  5226. (search-forward "H2")
  5227. (org-invisible-p2)))
  5228. ;; Case is not significant when matching properties.
  5229. (should-not
  5230. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  5231. (org-match-sparse-tree nil "a=\"1\"")
  5232. (search-forward "H2")
  5233. (org-invisible-p2)))
  5234. (should-not
  5235. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
  5236. (org-match-sparse-tree nil "A=\"1\"")
  5237. (search-forward "H2")
  5238. (org-invisible-p2)))
  5239. ;; Match special LEVEL property.
  5240. (should-not
  5241. (org-test-with-temp-text "* H\n** H1\n*** H2"
  5242. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  5243. (search-forward "H1")
  5244. (org-invisible-p2)))
  5245. (should
  5246. (org-test-with-temp-text "* H\n** H1\n*** H2"
  5247. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  5248. (search-forward "H2")
  5249. (org-invisible-p2)))
  5250. ;; Comparison operators when matching properties.
  5251. (should
  5252. (org-test-with-temp-text
  5253. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  5254. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  5255. (search-forward "H1")
  5256. (org-invisible-p2)))
  5257. (should-not
  5258. (org-test-with-temp-text
  5259. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  5260. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  5261. (search-forward "H2")
  5262. (org-invisible-p2)))
  5263. ;; Regexp match on properties values.
  5264. (should-not
  5265. (org-test-with-temp-text
  5266. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  5267. (org-match-sparse-tree nil "A={f.*}")
  5268. (search-forward "H1")
  5269. (org-invisible-p2)))
  5270. (should
  5271. (org-test-with-temp-text
  5272. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  5273. (org-match-sparse-tree nil "A={f.*}")
  5274. (search-forward "H2")
  5275. (org-invisible-p2)))
  5276. ;; With an optional argument, limit match to TODO entries.
  5277. (should-not
  5278. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  5279. (org-match-sparse-tree t "tag")
  5280. (search-forward "H1")
  5281. (org-invisible-p2)))
  5282. (should
  5283. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  5284. (org-match-sparse-tree t "tag")
  5285. (search-forward "H2")
  5286. (org-invisible-p2))))
  5287. (ert-deftest test-org/occur ()
  5288. "Test `org-occur' specifications."
  5289. ;; Count number of matches.
  5290. (should
  5291. (= 1
  5292. (org-test-with-temp-text "* H\nA\n* H2"
  5293. (org-occur "A"))))
  5294. (should
  5295. (= 2
  5296. (org-test-with-temp-text "* H\nA\n* H2\nA"
  5297. (org-occur "A"))))
  5298. ;; Test CALLBACK optional argument.
  5299. (should
  5300. (= 0
  5301. (org-test-with-temp-text "* H\nA\n* H2"
  5302. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  5303. (should
  5304. (= 1
  5305. (org-test-with-temp-text "* H\nA\n* H2\nA"
  5306. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  5307. ;; Case-fold searches according to `org-occur-case-fold-search'.
  5308. (should
  5309. (= 2
  5310. (org-test-with-temp-text "Aa"
  5311. (let ((org-occur-case-fold-search t)) (org-occur "A")))))
  5312. (should
  5313. (= 2
  5314. (org-test-with-temp-text "Aa"
  5315. (let ((org-occur-case-fold-search t)) (org-occur "a")))))
  5316. (should
  5317. (= 1
  5318. (org-test-with-temp-text "Aa"
  5319. (let ((org-occur-case-fold-search nil)) (org-occur "A")))))
  5320. (should
  5321. (= 1
  5322. (org-test-with-temp-text "Aa"
  5323. (let ((org-occur-case-fold-search nil)) (org-occur "a")))))
  5324. (should
  5325. (= 1
  5326. (org-test-with-temp-text "Aa"
  5327. (let ((org-occur-case-fold-search 'smart)) (org-occur "A")))))
  5328. (should
  5329. (= 2
  5330. (org-test-with-temp-text "Aa"
  5331. (let ((org-occur-case-fold-search 'smart)) (org-occur "a"))))))
  5332. ;;; Tags
  5333. (ert-deftest test-org/tag-string-to-alist ()
  5334. "Test `org-tag-string-to-alist' specifications."
  5335. ;; Tag without selection key.
  5336. (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
  5337. ;; Tag with selection key.
  5338. (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t))))
  5339. ;; Tag group.
  5340. (should
  5341. (equal
  5342. (org-tag-string-to-alist "[ group : t1 t2 ]")
  5343. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag))))
  5344. ;; Mutually exclusive tags.
  5345. (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
  5346. '((:startgroup) ("tag1") ("tag2") (:endgroup))))
  5347. (should
  5348. (equal
  5349. (org-tag-string-to-alist "{ group : tag1 tag2 }")
  5350. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))))
  5351. (ert-deftest test-org/tag-alist-to-string ()
  5352. "Test `org-tag-alist-to-string' specifications."
  5353. (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
  5354. (should (equal (org-tag-alist-to-string '(("tag1" . ?t))) "tag1(t)"))
  5355. (should
  5356. (equal
  5357. (org-tag-alist-to-string
  5358. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  5359. "[ group : t1 t2 ]"))
  5360. (should
  5361. (equal (org-tag-alist-to-string
  5362. '((:startgroup) ("tag1") ("tag2") (:endgroup)))
  5363. "{ tag1 tag2 }"))
  5364. (should
  5365. (equal
  5366. (org-tag-alist-to-string
  5367. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))
  5368. "{ group : tag1 tag2 }")))
  5369. (ert-deftest test-org/tag-alist-to-groups ()
  5370. "Test `org-tag-alist-to-groups' specifications."
  5371. (should
  5372. (equal (org-tag-alist-to-groups
  5373. '((:startgroup) ("group") (:grouptags) ("t1") ("t2") (:endgroup)))
  5374. '(("group" "t1" "t2"))))
  5375. (should
  5376. (equal
  5377. (org-tag-alist-to-groups
  5378. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  5379. '(("group" "t1" "t2"))))
  5380. (should-not
  5381. (org-tag-alist-to-groups
  5382. '((:startgroup) ("group") ("t1") ("t2") (:endgroup)))))
  5383. (ert-deftest test-org/tag-align ()
  5384. "Test tags alignment."
  5385. ;; Test aligning tags with different display width.
  5386. (should
  5387. ;; 12345678901234567890
  5388. (equal "* Test :abc:"
  5389. (org-test-with-temp-text "* Test :abc:"
  5390. (let ((org-tags-column -20)
  5391. (indent-tabs-mode nil))
  5392. (org-fix-tags-on-the-fly))
  5393. (buffer-string))))
  5394. (should
  5395. ;; 12345678901234567890
  5396. (equal "* Test :日本語:"
  5397. (org-test-with-temp-text "* Test :日本語:"
  5398. (let ((org-tags-column -20)
  5399. (indent-tabs-mode nil))
  5400. (org-fix-tags-on-the-fly))
  5401. (buffer-string))))
  5402. ;; Make sure aligning tags do not skip invisible text.
  5403. (should
  5404. (equal "* [[linkx]] :tag:"
  5405. (org-test-with-temp-text "* [[link<point>]] :tag:"
  5406. (let ((org-tags-column 0))
  5407. (org-fix-tags-on-the-fly)
  5408. (insert "x")
  5409. (buffer-string))))))
  5410. (ert-deftest test-org/tags-at ()
  5411. (should
  5412. (equal '("foo" "bar")
  5413. (org-test-with-temp-text
  5414. "* T<point>est :foo:bar:"
  5415. (org-get-tags-at)))))
  5416. ;;; Timestamps API
  5417. (ert-deftest test-org/time-stamp ()
  5418. "Test `org-time-stamp' specifications."
  5419. ;; Insert chosen time stamp at point.
  5420. (should
  5421. (string-match
  5422. "Te<2014-03-04 .*?>xt"
  5423. (org-test-with-temp-text "Te<point>xt"
  5424. (cl-letf (((symbol-function 'org-read-date)
  5425. (lambda (&rest args)
  5426. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  5427. (org-time-stamp nil)
  5428. (buffer-string)))))
  5429. ;; With a prefix argument, also insert time.
  5430. (should
  5431. (string-match
  5432. "Te<2014-03-04 .*? 00:41>xt"
  5433. (org-test-with-temp-text "Te<point>xt"
  5434. (cl-letf (((symbol-function 'org-read-date)
  5435. (lambda (&rest args)
  5436. (apply #'encode-time
  5437. (org-parse-time-string "2014-03-04 00:41")))))
  5438. (org-time-stamp '(4))
  5439. (buffer-string)))))
  5440. ;; With two universal prefix arguments, insert an active timestamp
  5441. ;; with the current time without prompting the user.
  5442. (should
  5443. (string-match
  5444. "Te<2014-03-04 .*? 00:41>xt"
  5445. (org-test-with-temp-text "Te<point>xt"
  5446. (cl-letf (((symbol-function 'current-time)
  5447. (lambda ()
  5448. (apply #'encode-time
  5449. (org-parse-time-string "2014-03-04 00:41")))))
  5450. (org-time-stamp '(16))
  5451. (buffer-string)))))
  5452. ;; When optional argument is non-nil, insert an inactive timestamp.
  5453. (should
  5454. (string-match
  5455. "Te\\[2014-03-04 .*?\\]xt"
  5456. (org-test-with-temp-text "Te<point>xt"
  5457. (cl-letf (((symbol-function 'org-read-date)
  5458. (lambda (&rest args)
  5459. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  5460. (org-time-stamp nil t)
  5461. (buffer-string)))))
  5462. ;; When called from a timestamp, replace existing one.
  5463. (should
  5464. (string-match
  5465. "<2014-03-04 .*?>"
  5466. (org-test-with-temp-text "<2012-03-29<point> thu.>"
  5467. (cl-letf (((symbol-function 'org-read-date)
  5468. (lambda (&rest args)
  5469. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  5470. (org-time-stamp nil)
  5471. (buffer-string)))))
  5472. (should
  5473. (string-match
  5474. "<2014-03-04 .*?>--<2014-03-04 .*?>"
  5475. (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
  5476. (cl-letf (((symbol-function 'org-read-date)
  5477. (lambda (&rest args)
  5478. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  5479. (org-time-stamp nil)
  5480. (buffer-string)))))
  5481. ;; When replacing a timestamp, preserve repeater, if any.
  5482. (should
  5483. (string-match
  5484. "<2014-03-04 .*? \\+2y>"
  5485. (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
  5486. (cl-letf (((symbol-function 'org-read-date)
  5487. (lambda (&rest args)
  5488. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  5489. (org-time-stamp nil)
  5490. (buffer-string)))))
  5491. ;; When called twice in a raw, build a date range.
  5492. (should
  5493. (string-match
  5494. "<2012-03-29 .*?>--<2014-03-04 .*?>"
  5495. (org-test-with-temp-text "<2012-03-29 thu.><point>"
  5496. (cl-letf (((symbol-function 'org-read-date)
  5497. (lambda (&rest args)
  5498. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  5499. (let ((last-command 'org-time-stamp)
  5500. (this-command 'org-time-stamp))
  5501. (org-time-stamp nil))
  5502. (buffer-string))))))
  5503. (ert-deftest test-org/timestamp-has-time-p ()
  5504. "Test `org-timestamp-has-time-p' specifications."
  5505. ;; With time.
  5506. (should
  5507. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  5508. (org-timestamp-has-time-p (org-element-context))))
  5509. ;; Without time.
  5510. (should-not
  5511. (org-test-with-temp-text "<2012-03-29 Thu>"
  5512. (org-timestamp-has-time-p (org-element-context)))))
  5513. (ert-deftest test-org/timestamp-format ()
  5514. "Test `org-timestamp-format' specifications."
  5515. ;; Regular test.
  5516. (should
  5517. (equal
  5518. "2012-03-29 16:40"
  5519. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  5520. (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
  5521. ;; Range end.
  5522. (should
  5523. (equal
  5524. "2012-03-29"
  5525. (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
  5526. (org-timestamp-format (org-element-context) "%Y-%m-%d" t)))))
  5527. (ert-deftest test-org/timestamp-split-range ()
  5528. "Test `org-timestamp-split-range' specifications."
  5529. ;; Extract range start (active).
  5530. (should
  5531. (equal '(2012 3 29)
  5532. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  5533. (let ((ts (org-timestamp-split-range (org-element-context))))
  5534. (mapcar (lambda (p) (org-element-property p ts))
  5535. '(:year-end :month-end :day-end))))))
  5536. ;; Extract range start (inactive)
  5537. (should
  5538. (equal '(2012 3 29)
  5539. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  5540. (let ((ts (org-timestamp-split-range (org-element-context))))
  5541. (mapcar (lambda (p) (org-element-property p ts))
  5542. '(:year-end :month-end :day-end))))))
  5543. ;; Extract range end (active).
  5544. (should
  5545. (equal '(2012 3 30)
  5546. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  5547. (let ((ts (org-timestamp-split-range
  5548. (org-element-context) t)))
  5549. (mapcar (lambda (p) (org-element-property p ts))
  5550. '(:year-end :month-end :day-end))))))
  5551. ;; Extract range end (inactive)
  5552. (should
  5553. (equal '(2012 3 30)
  5554. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  5555. (let ((ts (org-timestamp-split-range
  5556. (org-element-context) t)))
  5557. (mapcar (lambda (p) (org-element-property p ts))
  5558. '(:year-end :month-end :day-end))))))
  5559. ;; Return the timestamp if not a range.
  5560. (should
  5561. (org-test-with-temp-text "[2012-03-29 Thu]"
  5562. (let* ((ts-orig (org-element-context))
  5563. (ts-copy (org-timestamp-split-range ts-orig)))
  5564. (eq ts-orig ts-copy))))
  5565. (should
  5566. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  5567. (let* ((ts-orig (org-element-context))
  5568. (ts-copy (org-timestamp-split-range ts-orig)))
  5569. (eq ts-orig ts-copy)))))
  5570. (ert-deftest test-org/timestamp-translate ()
  5571. "Test `org-timestamp-translate' specifications."
  5572. ;; Translate whole date range.
  5573. (should
  5574. (equal "<29>--<30>"
  5575. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  5576. (let ((org-display-custom-times t)
  5577. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  5578. (org-timestamp-translate (org-element-context))))))
  5579. ;; Translate date range start.
  5580. (should
  5581. (equal "<29>"
  5582. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  5583. (let ((org-display-custom-times t)
  5584. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  5585. (org-timestamp-translate (org-element-context) 'start)))))
  5586. ;; Translate date range end.
  5587. (should
  5588. (equal "<30>"
  5589. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  5590. (let ((org-display-custom-times t)
  5591. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  5592. (org-timestamp-translate (org-element-context) 'end)))))
  5593. ;; Translate time range.
  5594. (should
  5595. (equal "<08>--<16>"
  5596. (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
  5597. (let ((org-display-custom-times t)
  5598. (org-time-stamp-custom-formats '("<%d>" . "<%H>")))
  5599. (org-timestamp-translate (org-element-context))))))
  5600. ;; Translate non-range timestamp.
  5601. (should
  5602. (equal "<29>"
  5603. (org-test-with-temp-text "<2012-03-29 Thu>"
  5604. (let ((org-display-custom-times t)
  5605. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  5606. (org-timestamp-translate (org-element-context))))))
  5607. ;; Do not change `diary' timestamps.
  5608. (should
  5609. (equal "<%%(org-float t 4 2)>"
  5610. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  5611. (let ((org-display-custom-times t)
  5612. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  5613. (org-timestamp-translate (org-element-context)))))))
  5614. ;;; Visibility
  5615. (ert-deftest test-org/flag-drawer ()
  5616. "Test `org-flag-drawer' specifications."
  5617. ;; Hide drawer.
  5618. (should
  5619. (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
  5620. (org-flag-drawer t)
  5621. (get-char-property (line-end-position) 'invisible)))
  5622. ;; Show drawer.
  5623. (should-not
  5624. (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
  5625. (org-flag-drawer t)
  5626. (org-flag-drawer nil)
  5627. (get-char-property (line-end-position) 'invisible)))
  5628. ;; Test optional argument.
  5629. (should
  5630. (org-test-with-temp-text "Text\n:D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
  5631. (let ((drawer (save-excursion (search-forward ":D2")
  5632. (org-element-at-point))))
  5633. (org-flag-drawer t drawer)
  5634. (get-char-property (progn (search-forward ":D2") (line-end-position))
  5635. 'invisible))))
  5636. (should-not
  5637. (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
  5638. (let ((drawer (save-excursion (search-forward ":D2")
  5639. (org-element-at-point))))
  5640. (org-flag-drawer t drawer)
  5641. (get-char-property (line-end-position) 'invisible))))
  5642. ;; Do not hide fake drawers.
  5643. (should-not
  5644. (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
  5645. (forward-line 1)
  5646. (org-flag-drawer t)
  5647. (get-char-property (line-end-position) 'invisible)))
  5648. ;; Do not hide incomplete drawers.
  5649. (should-not
  5650. (org-test-with-temp-text ":D:\nparagraph"
  5651. (forward-line 1)
  5652. (org-flag-drawer t)
  5653. (get-char-property (line-end-position) 'invisible)))
  5654. ;; Do not hide drawers when called from final blank lines.
  5655. (should-not
  5656. (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
  5657. (goto-char (point-max))
  5658. (org-flag-drawer t)
  5659. (goto-char (point-min))
  5660. (get-char-property (line-end-position) 'invisible)))
  5661. ;; Don't leave point in an invisible part of the buffer when hiding
  5662. ;; a drawer away.
  5663. (should-not
  5664. (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
  5665. (goto-char (point-max))
  5666. (org-flag-drawer t)
  5667. (get-char-property (point) 'invisible))))
  5668. (ert-deftest test-org/hide-block-toggle ()
  5669. "Test `org-hide-block-toggle' specifications."
  5670. ;; Error when not at a block.
  5671. (should-error
  5672. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
  5673. (org-hide-block-toggle 'off)
  5674. (get-char-property (line-end-position) 'invisible)))
  5675. ;; Hide block.
  5676. (should
  5677. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  5678. (org-hide-block-toggle)
  5679. (get-char-property (line-end-position) 'invisible)))
  5680. (should
  5681. (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
  5682. (org-hide-block-toggle)
  5683. (get-char-property (line-end-position) 'invisible)))
  5684. ;; Show block unconditionally when optional argument is `off'.
  5685. (should-not
  5686. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  5687. (org-hide-block-toggle)
  5688. (org-hide-block-toggle 'off)
  5689. (get-char-property (line-end-position) 'invisible)))
  5690. (should-not
  5691. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  5692. (org-hide-block-toggle 'off)
  5693. (get-char-property (line-end-position) 'invisible)))
  5694. ;; Hide block unconditionally when optional argument is non-nil.
  5695. (should
  5696. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  5697. (org-hide-block-toggle t)
  5698. (get-char-property (line-end-position) 'invisible)))
  5699. (should
  5700. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  5701. (org-hide-block-toggle)
  5702. (org-hide-block-toggle t)
  5703. (get-char-property (line-end-position) 'invisible)))
  5704. ;; Do not hide block when called from final blank lines.
  5705. (should-not
  5706. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
  5707. (org-hide-block-toggle)
  5708. (goto-char (point-min))
  5709. (get-char-property (line-end-position) 'invisible)))
  5710. ;; Don't leave point in an invisible part of the buffer when hiding
  5711. ;; a block away.
  5712. (should-not
  5713. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
  5714. (org-hide-block-toggle)
  5715. (get-char-property (point) 'invisible))))
  5716. (ert-deftest test-org/hide-block-toggle-maybe ()
  5717. "Test `org-hide-block-toggle-maybe' specifications."
  5718. (should
  5719. (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
  5720. (org-hide-block-toggle-maybe)))
  5721. (should-not
  5722. (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
  5723. (ert-deftest test-org/set-tags ()
  5724. "Test `org-set-tags' specifications."
  5725. ;; Tags set via fast-tag-selection should be visible afterwards
  5726. (should
  5727. (let ((org-tag-alist '(("NEXT" . ?n)))
  5728. (org-fast-tag-selection-single-key t))
  5729. (cl-letf (((symbol-function 'read-char-exclusive) (lambda () ?n))
  5730. ((symbol-function 'window-width) (lambda (&rest args) 100)))
  5731. (org-test-with-temp-text "<point>* Headline\nAnd its content\n* And another headline\n\nWith some content"
  5732. ;; Show only headlines
  5733. (org-content)
  5734. ;; Set NEXT tag on current entry
  5735. (org-set-tags nil nil)
  5736. ;; Move point to that NEXT tag
  5737. (search-forward "NEXT") (backward-word)
  5738. ;; And it should be visible (i.e. no overlays)
  5739. (not (overlays-at (point))))))))
  5740. (ert-deftest test-org/show-set-visibility ()
  5741. "Test `org-show-set-visibility' specifications."
  5742. ;; Do not throw an error before first heading.
  5743. (should
  5744. (org-test-with-temp-text "Preamble\n* Headline"
  5745. (org-show-set-visibility 'tree)
  5746. t))
  5747. ;; Test all visibility spans, both on headline and in entry.
  5748. (let ((list-visible-lines
  5749. (lambda (state headerp)
  5750. (org-test-with-temp-text "* Grandmother (0)
  5751. ** Uncle (1)
  5752. *** Heir (2)
  5753. ** Father (3)
  5754. Ancestor text (4)
  5755. *** Sister (5)
  5756. Sibling text (6)
  5757. *** Self (7)
  5758. Match (8)
  5759. **** First born (9)
  5760. Child text (10)
  5761. **** The other child (11)
  5762. *** Brother (12)
  5763. ** Aunt (13)
  5764. "
  5765. (org-cycle t)
  5766. (search-forward (if headerp "Self" "Match"))
  5767. (org-show-set-visibility state)
  5768. (goto-char (point-min))
  5769. (let (result (line 0))
  5770. (while (not (eobp))
  5771. (unless (org-invisible-p2) (push line result))
  5772. (incf line)
  5773. (forward-line))
  5774. (nreverse result))))))
  5775. (should (equal '(0 7) (funcall list-visible-lines 'minimal t)))
  5776. (should (equal '(0 7 8) (funcall list-visible-lines 'minimal nil)))
  5777. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local t)))
  5778. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local nil)))
  5779. (should (equal '(0 3 7) (funcall list-visible-lines 'ancestors t)))
  5780. (should (equal '(0 3 7 8) (funcall list-visible-lines 'ancestors nil)))
  5781. (should (equal '(0 3 5 7 12) (funcall list-visible-lines 'lineage t)))
  5782. (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines 'lineage nil)))
  5783. (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines 'tree t)))
  5784. (should (equal '(0 1 3 5 7 8 9 11 12 13)
  5785. (funcall list-visible-lines 'tree nil)))
  5786. (should (equal '(0 1 3 4 5 7 12 13)
  5787. (funcall list-visible-lines 'canonical t)))
  5788. (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
  5789. (funcall list-visible-lines 'canonical nil))))
  5790. ;; When point is hidden in a drawer or a block, make sure to make it
  5791. ;; visible.
  5792. (should-not
  5793. (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
  5794. (org-hide-block-toggle)
  5795. (search-forward "Text")
  5796. (org-show-set-visibility 'minimal)
  5797. (org-invisible-p2)))
  5798. (should-not
  5799. (org-test-with-temp-text ":DRAWER:\nText\n:END:"
  5800. (org-flag-drawer t)
  5801. (search-forward "Text")
  5802. (org-show-set-visibility 'minimal)
  5803. (org-invisible-p2)))
  5804. (should-not
  5805. (org-test-with-temp-text
  5806. "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
  5807. (org-flag-drawer t)
  5808. (forward-line -1)
  5809. (org-hide-block-toggle)
  5810. (search-forward "Text")
  5811. (org-show-set-visibility 'minimal)
  5812. (org-invisible-p2))))
  5813. (defun test-org/copy-visible ()
  5814. "Test `org-copy-visible' specifications."
  5815. (should
  5816. (equal "Foo"
  5817. (org-test-with-temp-text "Foo"
  5818. (let ((kill-ring nil))
  5819. (org-copy-visible (point-min) (point-max))
  5820. (current-kill 0 t)))))
  5821. ;; Skip invisible characters by text property.
  5822. (should
  5823. (equal "Foo"
  5824. (org-test-with-temp-text #("F<hidden>oo" 1 7 (invisible t))
  5825. (let ((kill-ring nil))
  5826. (org-copy-visible (point-min) (point-max))
  5827. (current-kill 0 t)))))
  5828. ;; Skip invisible characters by overlay.
  5829. (should
  5830. (equal "Foo"
  5831. (org-test-with-temp-text "F<hidden>oo"
  5832. (let ((o (make-overlay 2 10)))
  5833. (overlay-put o 'invisible t))
  5834. (let ((kill-ring nil))
  5835. (org-copy-visible (point-min) (point-max))
  5836. (current-kill 0 t)))))
  5837. ;; Handle invisible characters at the beginning and the end of the
  5838. ;; buffer.
  5839. (should
  5840. (equal "Foo"
  5841. (org-test-with-temp-text #("<hidden>Foo" 0 8 (invisible t))
  5842. (let ((kill-ring nil))
  5843. (org-copy-visible (point-min) (point-max))
  5844. (current-kill 0 t)))))
  5845. (should
  5846. (equal "Foo"
  5847. (org-test-with-temp-text #("Foo<hidden>" 3 11 (invisible t))
  5848. (let ((kill-ring nil))
  5849. (org-copy-visible (point-min) (point-max))
  5850. (current-kill 0 t)))))
  5851. ;; Handle multiple visible parts.
  5852. (should
  5853. (equal "abc"
  5854. (org-test-with-temp-text
  5855. #("aXbXc" 1 2 (invisible t) 3 4 (invisible t))
  5856. (let ((kill-ring nil))
  5857. (org-copy-visible (point-min) (point-max))
  5858. (current-kill 0 t))))))
  5859. (provide 'test-org)
  5860. ;;; test-org.el ends here