test-org.el 274 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455
  1. ;;; test-org.el --- tests for org.el
  2. ;; Copyright (c) David Maus
  3. ;; Authors: David Maus
  4. ;; This file is not part of GNU Emacs.
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. ;; Template test file for Org tests
  16. ;;; Code:
  17. (eval-and-compile (require 'cl-lib))
  18. ;;; Comments
  19. (ert-deftest test-org/toggle-comment ()
  20. "Test `org-toggle-comment' specifications."
  21. ;; Simple headline.
  22. (should
  23. (equal "* Test"
  24. (org-test-with-temp-text "* COMMENT Test"
  25. (org-toggle-comment)
  26. (buffer-string))))
  27. (should
  28. (equal "* COMMENT Test"
  29. (org-test-with-temp-text "* Test"
  30. (org-toggle-comment)
  31. (buffer-string))))
  32. ;; Headline with a regular keyword.
  33. (should
  34. (equal "* TODO Test"
  35. (org-test-with-temp-text "* TODO COMMENT Test"
  36. (org-toggle-comment)
  37. (buffer-string))))
  38. (should
  39. (equal "* TODO COMMENT Test"
  40. (org-test-with-temp-text "* TODO Test"
  41. (org-toggle-comment)
  42. (buffer-string))))
  43. ;; Empty headline.
  44. (should
  45. (equal "* "
  46. (org-test-with-temp-text "* COMMENT"
  47. (org-toggle-comment)
  48. (buffer-string))))
  49. (should
  50. (equal "* COMMENT"
  51. (org-test-with-temp-text "* "
  52. (org-toggle-comment)
  53. (buffer-string))))
  54. ;; Headline with a single keyword.
  55. (should
  56. (equal "* TODO "
  57. (org-test-with-temp-text "* TODO COMMENT"
  58. (org-toggle-comment)
  59. (buffer-string))))
  60. (should
  61. (equal "* TODO COMMENT"
  62. (org-test-with-temp-text "* TODO"
  63. (org-toggle-comment)
  64. (buffer-string))))
  65. ;; Headline with a keyword, a priority cookie and contents.
  66. (should
  67. (equal "* TODO [#A] Headline"
  68. (org-test-with-temp-text "* TODO [#A] COMMENT Headline"
  69. (org-toggle-comment)
  70. (buffer-string))))
  71. (should
  72. (equal "* TODO [#A] COMMENT Headline"
  73. (org-test-with-temp-text "* TODO [#A] Headline"
  74. (org-toggle-comment)
  75. (buffer-string)))))
  76. (ert-deftest test-org/comment-dwim ()
  77. "Test `comment-dwim' behaviour in an Org buffer."
  78. ;; No region selected, no comment on current line and line not
  79. ;; empty: insert comment on line above.
  80. (should
  81. (equal "# \nComment"
  82. (org-test-with-temp-text "Comment"
  83. (call-interactively #'org-comment-dwim)
  84. (buffer-string))))
  85. ;; No region selected, no comment on current line and line empty:
  86. ;; insert comment on this line.
  87. (should
  88. (equal "# \nParagraph"
  89. (org-test-with-temp-text "\nParagraph"
  90. (call-interactively #'org-comment-dwim)
  91. (buffer-string))))
  92. ;; No region selected, and a comment on this line: indent it.
  93. (should
  94. (equal "* Headline\n # Comment"
  95. (org-test-with-temp-text "* Headline\n# <point>Comment"
  96. (let ((org-adapt-indentation t))
  97. (call-interactively #'org-comment-dwim))
  98. (buffer-string))))
  99. ;; Also recognize single # at column 0 as comments.
  100. (should
  101. (equal "# Comment"
  102. (org-test-with-temp-text "# Comment"
  103. (call-interactively #'org-comment-dwim)
  104. (buffer-string))))
  105. ;; Region selected and only comments and blank lines within it:
  106. ;; un-comment all commented lines.
  107. (should
  108. (equal "Comment 1\n\nComment 2"
  109. (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
  110. (transient-mark-mode 1)
  111. (push-mark (point) t t)
  112. (goto-char (point-max))
  113. (call-interactively #'org-comment-dwim)
  114. (buffer-string))))
  115. ;; Region selected without comments: comment all lines if
  116. ;; `comment-empty-lines' is non-nil, only non-blank lines otherwise.
  117. (should
  118. (equal "# Comment 1\n\n# Comment 2"
  119. (org-test-with-temp-text "Comment 1\n\nComment 2"
  120. (transient-mark-mode 1)
  121. (push-mark (point) t t)
  122. (goto-char (point-max))
  123. (let ((comment-empty-lines nil))
  124. (call-interactively #'org-comment-dwim))
  125. (buffer-string))))
  126. (should
  127. (equal "# Comment 1\n# \n# Comment 2"
  128. (org-test-with-temp-text "Comment 1\n\nComment 2"
  129. (transient-mark-mode 1)
  130. (push-mark (point) t t)
  131. (goto-char (point-max))
  132. (let ((comment-empty-lines t))
  133. (call-interactively #'org-comment-dwim))
  134. (buffer-string))))
  135. ;; In front of a keyword without region, insert a new comment.
  136. (should
  137. (equal "# \n#+KEYWORD: value"
  138. (org-test-with-temp-text "#+KEYWORD: value"
  139. (call-interactively #'org-comment-dwim)
  140. (buffer-string))))
  141. ;; Comment a heading
  142. (should
  143. (equal "* COMMENT Test"
  144. (org-test-with-temp-text "* Test"
  145. (call-interactively #'org-comment-dwim)
  146. (buffer-string))))
  147. ;; In a source block, use appropriate syntax.
  148. (should
  149. (equal " ;; "
  150. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n<point>\n#+END_SRC"
  151. (let ((org-edit-src-content-indentation 2))
  152. (call-interactively #'org-comment-dwim))
  153. (buffer-substring-no-properties (line-beginning-position)
  154. (point)))))
  155. (should
  156. (equal "#+BEGIN_SRC emacs-lisp\n ;; a\n ;; b\n#+END_SRC"
  157. (org-test-with-temp-text
  158. "#+BEGIN_SRC emacs-lisp\n<point>a\nb\n#+END_SRC"
  159. (transient-mark-mode 1)
  160. (push-mark (point) t t)
  161. (forward-line 2)
  162. (let ((org-edit-src-content-indentation 2))
  163. (call-interactively #'org-comment-dwim))
  164. (buffer-string)))))
  165. ;;; Date and time analysis
  166. (ert-deftest test-org/org-read-date ()
  167. "Test `org-read-date' specifications."
  168. ;; Parse ISO date with abbreviated year and month.
  169. (should (equal "2012-03-29 16:40"
  170. (let ((org-time-was-given t))
  171. (org-read-date t nil "12-3-29 16:40"))))
  172. ;; Parse Europeans dates.
  173. (should (equal "2012-03-29 16:40"
  174. (let ((org-time-was-given t))
  175. (org-read-date t nil "29.03.2012 16:40"))))
  176. ;; Parse Europeans dates without year.
  177. (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
  178. (let ((org-time-was-given t))
  179. (org-read-date t nil "29.03. 16:40"))))
  180. ;; Relative date applied to current time if there is single
  181. ;; plus/minus, or to default date when there are two of them.
  182. (should
  183. (equal
  184. "2015-03-04"
  185. (org-test-at-time "2014-03-04"
  186. (org-read-date
  187. t nil "+1y" nil
  188. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))
  189. (should
  190. (equal
  191. "2013-03-29"
  192. (org-test-at-time "2014-03-04"
  193. (org-read-date
  194. t nil "++1y" nil
  195. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))
  196. ;; When `org-read-date-prefer-future' is non-nil, prefer future
  197. ;; dates (relatively to now) when incomplete. Otherwise, use
  198. ;; default date.
  199. (should
  200. (equal
  201. "2014-04-01"
  202. (org-test-at-time "2014-03-04"
  203. (let ((org-read-date-prefer-future t))
  204. (org-read-date t nil "1")))))
  205. (should
  206. (equal
  207. "2013-03-04"
  208. (org-test-at-time "2012-03-29"
  209. (let ((org-read-date-prefer-future t))
  210. (org-read-date t nil "3-4")))))
  211. (should
  212. (equal
  213. "2012-03-04"
  214. (org-test-at-time "2012-03-29"
  215. (let ((org-read-date-prefer-future nil))
  216. (org-read-date t nil "3-4")))))
  217. ;; When set to `org-read-date-prefer-future' is set to `time', read
  218. ;; day is moved to tomorrow if specified hour is before current
  219. ;; time. However, it only happens in no other part of the date is
  220. ;; specified.
  221. (should
  222. (equal
  223. "2012-03-30"
  224. (org-test-at-time "2012-03-29 16:40"
  225. (let ((org-read-date-prefer-future 'time))
  226. (org-read-date t nil "00:40" nil)))))
  227. (should-not
  228. (equal
  229. "2012-03-30"
  230. (org-test-at-time "2012-03-29 16:40"
  231. (let ((org-read-date-prefer-future 'time))
  232. (org-read-date t nil "29 00:40" nil)))))
  233. ;; Caveat: `org-read-date-prefer-future' always refers to current
  234. ;; time, not default time, when they differ.
  235. (should
  236. (equal
  237. "2014-04-01"
  238. (org-test-at-time "2014-03-04"
  239. (let ((org-read-date-prefer-future t))
  240. (org-read-date
  241. t nil "1" nil
  242. (apply #'encode-time (org-parse-time-string "2012-03-29")))))))
  243. (should
  244. (equal
  245. "2014-03-25"
  246. (org-test-at-time "2014-03-04"
  247. (let ((org-read-date-prefer-future t))
  248. (org-read-date
  249. t nil "25" nil
  250. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))))
  251. (ert-deftest test-org/org-parse-time-string ()
  252. "Test `org-parse-time-string'."
  253. (should (equal (org-parse-time-string "2012-03-29 16:40")
  254. '(0 40 16 29 3 2012 nil nil nil)))
  255. (should (equal (org-parse-time-string "[2012-03-29 16:40]")
  256. '(0 40 16 29 3 2012 nil nil nil)))
  257. (should (equal (org-parse-time-string "<2012-03-29 16:40>")
  258. '(0 40 16 29 3 2012 nil nil nil)))
  259. (should (equal (org-parse-time-string "<2012-03-29>")
  260. '(0 0 0 29 3 2012 nil nil nil)))
  261. (should (equal (org-parse-time-string "<2012-03-29>" t)
  262. '(0 nil nil 29 3 2012 nil nil nil))))
  263. (ert-deftest test-org/closest-date ()
  264. "Test `org-closest-date' specifications."
  265. (require 'calendar)
  266. ;; Time stamps without a repeater are returned unchanged.
  267. (should
  268. (equal
  269. '(3 29 2012)
  270. (calendar-gregorian-from-absolute
  271. (org-closest-date "<2012-03-29>" "<2014-03-04>" nil))))
  272. ;; Time stamps with a null repeater are returned unchanged.
  273. (should
  274. (equal
  275. '(3 29 2012)
  276. (calendar-gregorian-from-absolute
  277. (org-closest-date "<2012-03-29 +0d>" "<2014-03-04>" nil))))
  278. ;; if PREFER is set to `past' always return a date before, or equal
  279. ;; to CURRENT.
  280. (should
  281. (equal
  282. '(3 1 2014)
  283. (calendar-gregorian-from-absolute
  284. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'past))))
  285. (should
  286. (equal
  287. '(3 4 2014)
  288. (calendar-gregorian-from-absolute
  289. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'past))))
  290. ;; if PREFER is set to `future' always return a date before, or equal
  291. ;; to CURRENT.
  292. (should
  293. (equal
  294. '(3 29 2014)
  295. (calendar-gregorian-from-absolute
  296. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'future))))
  297. (should
  298. (equal
  299. '(3 4 2014)
  300. (calendar-gregorian-from-absolute
  301. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'future))))
  302. ;; If PREFER is neither `past' nor `future', select closest date.
  303. (should
  304. (equal
  305. '(3 1 2014)
  306. (calendar-gregorian-from-absolute
  307. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" nil))))
  308. (should
  309. (equal
  310. '(5 4 2014)
  311. (calendar-gregorian-from-absolute
  312. (org-closest-date "<2012-03-04 +1m>" "<2014-04-28>" nil))))
  313. ;; Test "day" repeater.
  314. (should
  315. (equal '(3 8 2014)
  316. (calendar-gregorian-from-absolute
  317. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'past))))
  318. (should
  319. (equal '(3 10 2014)
  320. (calendar-gregorian-from-absolute
  321. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'future))))
  322. ;; Test "month" repeater.
  323. (should
  324. (equal '(1 5 2015)
  325. (calendar-gregorian-from-absolute
  326. (org-closest-date "<2014-03-05 +2m>" "<2015-02-04>" 'past))))
  327. (should
  328. (equal '(3 29 2014)
  329. (calendar-gregorian-from-absolute
  330. (org-closest-date "<2012-03-29 +2m>" "<2014-03-04>" 'future))))
  331. ;; Test "year" repeater.
  332. (should
  333. (equal '(3 5 2014)
  334. (calendar-gregorian-from-absolute
  335. (org-closest-date "<2014-03-05 +2y>" "<2015-02-04>" 'past))))
  336. (should
  337. (equal '(3 29 2014)
  338. (calendar-gregorian-from-absolute
  339. (org-closest-date "<2012-03-29 +2y>" "<2014-03-04>" 'future)))))
  340. (ert-deftest test-org/deadline-close-p ()
  341. "Test `org-deadline-close-p' specifications."
  342. (org-test-at-time "2016-06-03 Fri 01:43"
  343. ;; Timestamps are close if they are within `ndays' of lead time.
  344. (org-test-with-temp-text "* Heading"
  345. (should (org-deadline-close-p "2016-06-03 Fri" 0))
  346. (should (org-deadline-close-p "2016-06-02 Thu" 0))
  347. (should-not (org-deadline-close-p "2016-06-04 Sat" 0))
  348. (should (org-deadline-close-p "2016-06-04 Sat" 1))
  349. (should (org-deadline-close-p "2016-06-03 Fri 12:00" 0)))
  350. ;; Read `ndays' from timestamp if argument not given.
  351. (org-test-with-temp-text "* H"
  352. (should (org-deadline-close-p "2016-06-04 Sat -1d"))
  353. (should-not (org-deadline-close-p "2016-06-04 Sat -0d"))
  354. (should (org-deadline-close-p "2016-06-10 Fri -1w"))
  355. (should-not (org-deadline-close-p "2016-06-11 Sat -1w")))
  356. ;; Prefer `ndays' argument over lead time in timestamp.
  357. (org-test-with-temp-text "* H"
  358. (should (org-deadline-close-p "2016-06-04 Sat -0d" 1))
  359. (should-not (org-deadline-close-p "2016-06-04 Sat -0d" 0)))
  360. ;; Completed tasks are never close.
  361. (let ((org-todo-keywords '(("TODO" "|" "DONE"))))
  362. (org-test-with-temp-text "* TODO Heading"
  363. (should (org-deadline-close-p "2016-06-03")))
  364. (org-test-with-temp-text "* DONE Heading"
  365. (should-not (org-deadline-close-p "2016-06-03"))))))
  366. ;;; Drawers
  367. (ert-deftest test-org/at-property-p ()
  368. "Test `org-at-property-p' specifications."
  369. (should
  370. (equal 't
  371. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:PROP: t\n:END:\n"
  372. (org-at-property-p))))
  373. (should
  374. (equal 't
  375. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n:END:\n"
  376. (org-at-property-p)))))
  377. (ert-deftest test-org/at-property-drawer-p ()
  378. "Test `org-at-property-drawer-p' specifications."
  379. (should
  380. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:PROP: t\n:END:\n"
  381. (org-at-property-drawer-p)))
  382. (should
  383. (org-test-with-temp-text ":PROPERTIES:\n:PROP: t\n:END:\n"
  384. (org-at-property-drawer-p)))
  385. ;; The function only returns t if point is at the first line of
  386. ;; a property block.
  387. (should-not
  388. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n:END:\n"
  389. (org-at-property-drawer-p)))
  390. ;; The function ignores incomplete drawers.
  391. (should-not
  392. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n"
  393. (org-at-property-drawer-p)))
  394. ;; tab separating the value.
  395. (should
  396. (org-test-with-temp-text ":PROPERTIES:\n:PROP: t\n:END:\n"
  397. (org-at-property-drawer-p))))
  398. (ert-deftest test-org/get-property-block ()
  399. "Test `org-get-property-block' specifications."
  400. (should
  401. (equal '(14 . 14)
  402. (org-test-with-temp-text ":PROPERTIES:\n:END:\n* H\n"
  403. (org-get-property-block))))
  404. (should
  405. (equal '(14 . 14)
  406. (org-test-with-temp-text ":PROPERTIES:\n:END:\n"
  407. (org-get-property-block))))
  408. ;; Comments above a document property block is ok.
  409. (should
  410. (equal '(18 . 18)
  411. (org-test-with-temp-text "# C\n:PROPERTIES:\n:END:\n"
  412. (org-get-property-block))))
  413. ;; Keywords above a document property block is ok.
  414. (should
  415. (equal '(22 . 22)
  416. (org-test-with-temp-text "# C\n# C\n:PROPERTIES:\n:END:\n"
  417. (org-get-property-block))))
  418. ;; Comments and keywords are allowed before a document property block.
  419. (should
  420. (equal '(18 . 27)
  421. (org-test-with-temp-text "# C\n:PROPERTIES:\n:KEY: V:\n:END:\n"
  422. (org-get-property-block))))
  423. ;; A document property block will not be valid if there are lines
  424. ;; with whitespace above it
  425. (should-not
  426. (org-test-with-temp-text "\n:PROPERTIES:\n:END:\n"
  427. (org-get-property-block)))
  428. (should
  429. (equal '(18 . 18)
  430. (org-test-with-temp-text "* H\n:PROPERTIES:\n:END:\n<point>"
  431. (org-get-property-block))))
  432. (should
  433. (equal "* H\n:PROPERTIES:\n:END:\n"
  434. (org-test-with-temp-text "* H"
  435. (let ((org-adapt-indentation nil))
  436. (org-get-property-block nil 'force))
  437. (buffer-string))))
  438. (should
  439. (equal ":PROPERTIES:\n:END:\n"
  440. (org-test-with-temp-text ""
  441. (org-get-property-block nil 'force)
  442. (buffer-string))))
  443. (should
  444. (equal "* H1\n :PROPERTIES:\n :END:\n* H2"
  445. (org-test-with-temp-text "* H1\n* H2"
  446. (let ((org-adapt-indentation t))
  447. (org-get-property-block nil 'force))
  448. (buffer-string)))))
  449. (ert-deftest test-org/insert-property-drawer ()
  450. "Test `org-insert-property-drawer' specifications."
  451. ;; Insert drawer in empty buffer
  452. (should
  453. (equal ":PROPERTIES:\n:END:\n"
  454. (org-test-with-temp-text ""
  455. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  456. (buffer-string))))
  457. ;; Insert drawer in document header with existing comment and
  458. ;; keyword.
  459. (should
  460. (equal "# C\n:PROPERTIES:\n:END:\n#+TITLE: T"
  461. (org-test-with-temp-text "# C\n#+TITLE: T"
  462. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  463. (buffer-string))))
  464. ;; Insert drawer in document header with existing keyword.
  465. (should
  466. (equal ":PROPERTIES:\n:END:\n#+TITLE: T"
  467. (org-test-with-temp-text "#+TITLE: T"
  468. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  469. (buffer-string))))
  470. (should
  471. (equal ":PROPERTIES:\n:END:"
  472. (org-test-with-temp-text ":PROPERTIES:\n:END:"
  473. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  474. (buffer-string))))
  475. ;; Insert drawer in document header with one existing heading in buffer.
  476. (should
  477. (equal ":PROPERTIES:\n:END:\n\n* T\n"
  478. (org-test-with-temp-text "\n* T\n"
  479. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  480. (buffer-string))))
  481. ;; Insert drawer right after headline if there is no planning line,
  482. ;; or after it otherwise.
  483. (should
  484. (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
  485. (org-test-with-temp-text "* H\nParagraph<point>"
  486. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  487. (buffer-string))))
  488. (should
  489. (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
  490. (org-test-with-temp-text
  491. "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
  492. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  493. (buffer-string))))
  494. ;; Indent inserted drawer.
  495. (should
  496. (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
  497. (org-test-with-temp-text "* H\nParagraph<point>"
  498. (let ((org-adapt-indentation t)) (org-insert-property-drawer))
  499. (buffer-string))))
  500. ;; Handle insertion at eob.
  501. (should
  502. (equal "* H\n:PROPERTIES:\n:END:\n"
  503. (org-test-with-temp-text "* H"
  504. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  505. (buffer-string))))
  506. ;; Skip inlinetasks before point.
  507. (when (featurep 'org-inlinetask)
  508. (should
  509. (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
  510. (org-test-with-temp-text
  511. "* H\n*************** I\n*************** END\nP<point>"
  512. (let ((org-adapt-indentation nil)
  513. (org-inlinetask-min-level 15))
  514. (org-insert-property-drawer))
  515. (buffer-string)))))
  516. ;; Correctly set drawer in an inlinetask.
  517. (when (featurep 'org-inlinetask)
  518. (should
  519. (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
  520. (org-test-with-temp-text
  521. "* H\n*************** I\nP<point>\n*************** END"
  522. (let ((org-adapt-indentation nil)
  523. (org-inlinetask-min-level 15))
  524. (org-insert-property-drawer))
  525. (buffer-string))))))
  526. ;;; Filling
  527. (ert-deftest test-org/fill-element ()
  528. "Test `org-fill-element' specifications."
  529. ;; At an Org table, align it.
  530. (should
  531. (equal "| a |\n"
  532. (org-test-with-temp-text "|a|"
  533. (org-fill-element)
  534. (buffer-string))))
  535. (should
  536. (equal "#+name: table\n| a |\n"
  537. (org-test-with-temp-text "#+name: table\n| a |\n"
  538. (org-fill-element)
  539. (buffer-string))))
  540. ;; At a paragraph, preserve line breaks.
  541. (org-test-with-temp-text "some \\\\\nlong\ntext"
  542. (let ((fill-column 20))
  543. (org-fill-element)
  544. (should (equal (buffer-string) "some \\\\\nlong text"))))
  545. ;; Correctly fill a paragraph when point is at its very end.
  546. (should
  547. (equal "A B"
  548. (org-test-with-temp-text "A\nB"
  549. (let ((fill-column 20))
  550. (goto-char (point-max))
  551. (org-fill-element)
  552. (buffer-string)))))
  553. ;; Correctly fill the last paragraph of a greater element.
  554. (should
  555. (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
  556. (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
  557. (let ((fill-column 8))
  558. (forward-line)
  559. (end-of-line)
  560. (org-fill-element)
  561. (buffer-string)))))
  562. ;; Correctly fill an element in a narrowed buffer.
  563. (should
  564. (equal "01234\n6"
  565. (org-test-with-temp-text "01234 6789"
  566. (let ((fill-column 5))
  567. (narrow-to-region 1 8)
  568. (org-fill-element)
  569. (buffer-string)))))
  570. ;; Handle `adaptive-fill-regexp' in paragraphs.
  571. (should
  572. (equal "> a b"
  573. (org-test-with-temp-text "> a\n> b"
  574. (let ((fill-column 5)
  575. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  576. (org-fill-element)
  577. (buffer-string)))))
  578. ;; Special case: Fill first paragraph when point is at an item or
  579. ;; a plain-list or a footnote reference.
  580. (should
  581. (equal "- A B"
  582. (org-test-with-temp-text "- A\n B"
  583. (let ((fill-column 20))
  584. (org-fill-element)
  585. (buffer-string)))))
  586. (should
  587. (equal "[fn:1] A B"
  588. (org-test-with-temp-text "[fn:1] A\nB"
  589. (let ((fill-column 20))
  590. (org-fill-element)
  591. (buffer-string)))))
  592. (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
  593. (let ((fill-column 20))
  594. (org-fill-element)
  595. (should (equal (buffer-string)
  596. "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
  597. ;; Fill contents of `comment-block' elements.
  598. (should
  599. (equal
  600. (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
  601. (let ((fill-column 20))
  602. (forward-line)
  603. (org-fill-element)
  604. (buffer-string)))
  605. "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
  606. ;; Fill `comment' elements.
  607. (should
  608. (equal " # A B"
  609. (org-test-with-temp-text " # A\n # B"
  610. (let ((fill-column 20))
  611. (org-fill-element)
  612. (buffer-string)))))
  613. ;; Do not mix consecutive comments when filling one of them.
  614. (should
  615. (equal "# A B\n\n# C"
  616. (org-test-with-temp-text "# A\n# B\n\n# C"
  617. (let ((fill-column 20))
  618. (org-fill-element)
  619. (buffer-string)))))
  620. ;; Use commented empty lines as separators when filling comments.
  621. (should
  622. (equal "# A B\n#\n# C"
  623. (org-test-with-temp-text "# A\n# B\n#\n# C"
  624. (let ((fill-column 20))
  625. (org-fill-element)
  626. (buffer-string)))))
  627. ;; Handle `adaptive-fill-regexp' in comments.
  628. (should
  629. (equal "# > a b"
  630. (org-test-with-temp-text "# > a\n# > b"
  631. (let ((fill-column 20)
  632. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  633. (org-fill-element)
  634. (buffer-string)))))
  635. ;; Do nothing at affiliated keywords.
  636. (should
  637. (equal "#+NAME: para\nSome\ntext."
  638. (org-test-with-temp-text "#+NAME: para\nSome\ntext."
  639. (let ((fill-column 20))
  640. (org-fill-element)
  641. (buffer-string)))))
  642. ;; Do not move point after table when filling a table.
  643. (should-not
  644. (org-test-with-temp-text "| a | b |\n| c | d |\n"
  645. (forward-char)
  646. (org-fill-element)
  647. (eobp)))
  648. ;; Do not fill "n" macro, with or without arguments, followed by
  649. ;; a dot or a closing parenthesis since it could be confused with
  650. ;; a numbered bullet.
  651. (should-not
  652. (equal "123456789\n{{{n}}}."
  653. (org-test-with-temp-text "123456789 {{{n}}}."
  654. (let ((fill-column 10))
  655. (org-fill-element)
  656. (buffer-string)))))
  657. (should-not
  658. (equal "123456789\n{{{n}}}\)"
  659. (org-test-with-temp-text "123456789 {{{n}}}\)"
  660. (let ((fill-column 10))
  661. (org-fill-element)
  662. (buffer-string)))))
  663. (should-not
  664. (equal "123456789\n{{{n()}}}."
  665. (org-test-with-temp-text "123456789 {{{n()}}}."
  666. (let ((fill-column 10))
  667. (org-fill-element)
  668. (buffer-string)))))
  669. (should-not
  670. (equal "123456789\n{{{n(counter)}}}."
  671. (org-test-with-temp-text "123456789 {{{n(counter)}}}."
  672. (let ((fill-column 10))
  673. (org-fill-element)
  674. (buffer-string))))))
  675. (ert-deftest test-org/fill-paragraph ()
  676. "Test `org-fill-paragraph' specifications."
  677. ;; Regular test.
  678. (should
  679. (equal "012345678\n9"
  680. (org-test-with-temp-text "012345678 9"
  681. (let ((fill-column 10))
  682. (org-fill-paragraph)
  683. (buffer-string)))))
  684. ;; Fill paragraph even at end of buffer.
  685. (should
  686. (equal "012345678\n9\n"
  687. (org-test-with-temp-text "012345678 9\n<point>"
  688. (let ((fill-column 10))
  689. (org-fill-paragraph)
  690. (buffer-string)))))
  691. ;; Between two paragraphs, fill the next one.
  692. (should
  693. (equal "012345678 9\n\n012345678\n9"
  694. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  695. (let ((fill-column 10))
  696. (org-fill-paragraph)
  697. (buffer-string)))))
  698. (should
  699. (equal "012345678\n9\n\n012345678 9"
  700. (org-test-with-temp-text "012345678 9<point>\n\n012345678 9"
  701. (let ((fill-column 10))
  702. (org-fill-paragraph)
  703. (buffer-string)))))
  704. ;; Fill paragraph in a comment block.
  705. (should
  706. (equal "#+begin_comment\n012345678\n9\n#+end_comment"
  707. (org-test-with-temp-text
  708. "#+begin_comment\n<point>012345678 9\n#+end_comment"
  709. (let ((fill-column 10))
  710. (org-fill-paragraph)
  711. (buffer-string)))))
  712. ;; When a region is selected, fill every paragraph in the region.
  713. (should
  714. (equal "012345678\n9\n\n012345678\n9"
  715. (org-test-with-temp-text "012345678 9\n\n012345678 9"
  716. (let ((fill-column 10))
  717. (transient-mark-mode 1)
  718. (push-mark (point-min) t t)
  719. (goto-char (point-max))
  720. (call-interactively #'org-fill-paragraph)
  721. (buffer-string)))))
  722. (should
  723. (equal "012345678\n9\n\n012345678 9"
  724. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  725. (let ((fill-column 10))
  726. (transient-mark-mode 1)
  727. (push-mark (point) t t)
  728. (goto-char (point-min))
  729. (call-interactively #'org-fill-paragraph)
  730. (buffer-string)))))
  731. (should
  732. (equal "012345678 9\n\n012345678\n9"
  733. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  734. (let ((fill-column 10))
  735. (transient-mark-mode 1)
  736. (push-mark (point) t t)
  737. (goto-char (point-max))
  738. (call-interactively #'org-fill-paragraph)
  739. (buffer-string))))))
  740. (ert-deftest test-org/auto-fill-function ()
  741. "Test auto-filling features."
  742. ;; Auto fill paragraph.
  743. (should
  744. (equal "12345\n7890"
  745. (org-test-with-temp-text "12345 7890"
  746. (let ((fill-column 5))
  747. (end-of-line)
  748. (org-auto-fill-function)
  749. (buffer-string)))))
  750. ;; Auto fill first paragraph in an item.
  751. (should
  752. (equal "- 12345\n 7890"
  753. (org-test-with-temp-text "- 12345 7890"
  754. (let ((fill-column 7))
  755. (end-of-line)
  756. (org-auto-fill-function)
  757. (buffer-string)))))
  758. ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
  759. (should
  760. (equal "> 12345\n 7890"
  761. (org-test-with-temp-text "> 12345 7890"
  762. (let ((fill-column 10)
  763. (adaptive-fill-regexp "[ \t]*>+[ \t]*")
  764. (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
  765. (end-of-line)
  766. (org-auto-fill-function)
  767. (buffer-string)))))
  768. (should
  769. (equal "> 12345\n> 12345\n> 7890"
  770. (org-test-with-temp-text "> 12345\n> 12345 7890"
  771. (let ((fill-column 10)
  772. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  773. (goto-char (point-max))
  774. (org-auto-fill-function)
  775. (buffer-string)))))
  776. (should-not
  777. (equal " 12345\n *12345\n *12345"
  778. (org-test-with-temp-text " 12345\n *12345 12345"
  779. (let ((fill-column 10)
  780. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  781. (goto-char (point-max))
  782. (org-auto-fill-function)
  783. (buffer-string)))))
  784. ;; Auto fill comments.
  785. (should
  786. (equal " # 12345\n # 7890"
  787. (org-test-with-temp-text " # 12345 7890"
  788. (let ((fill-column 10))
  789. (end-of-line)
  790. (org-auto-fill-function)
  791. (buffer-string)))))
  792. ;; A hash within a line isn't a comment.
  793. (should-not
  794. (equal "12345 # 7890\n# 1"
  795. (org-test-with-temp-text "12345 # 7890 1"
  796. (let ((fill-column 12))
  797. (end-of-line)
  798. (org-auto-fill-function)
  799. (buffer-string)))))
  800. ;; Correctly interpret empty prefix.
  801. (should-not
  802. (equal "# a\n# b\nRegular\n# paragraph"
  803. (org-test-with-temp-text "# a\n# b\nRegular paragraph"
  804. (let ((fill-column 12))
  805. (end-of-line 3)
  806. (org-auto-fill-function)
  807. (buffer-string)))))
  808. ;; Comment block: auto fill contents.
  809. (should
  810. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  811. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  812. (let ((fill-column 5))
  813. (forward-line)
  814. (end-of-line)
  815. (org-auto-fill-function)
  816. (buffer-string)))))
  817. (should
  818. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  819. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  820. (let ((fill-column 5))
  821. (forward-line)
  822. (end-of-line)
  823. (org-auto-fill-function)
  824. (buffer-string)))))
  825. ;; Do not fill if a new item could be created.
  826. (should-not
  827. (equal "12345\n- 90"
  828. (org-test-with-temp-text "12345 - 90"
  829. (let ((fill-column 5))
  830. (end-of-line)
  831. (org-auto-fill-function)
  832. (buffer-string)))))
  833. ;; Do not fill if a line break could be introduced.
  834. (should-not
  835. (equal "123\\\\\n7890"
  836. (org-test-with-temp-text "123\\\\ 7890"
  837. (let ((fill-column 6))
  838. (end-of-line)
  839. (org-auto-fill-function)
  840. (buffer-string)))))
  841. ;; Do not fill affiliated keywords.
  842. (should-not
  843. (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
  844. (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
  845. (let ((fill-column 20))
  846. (end-of-line)
  847. (org-auto-fill-function)
  848. (buffer-string))))))
  849. ;;; Indentation
  850. (ert-deftest test-org/indent-line ()
  851. "Test `org-indent-line' specifications."
  852. ;; Do not indent diary sexps, footnote definitions or headlines.
  853. (should
  854. (zerop
  855. (org-test-with-temp-text "%%(org-calendar-holiday)"
  856. (org-indent-line)
  857. (org-get-indentation))))
  858. (should
  859. (zerop
  860. (org-test-with-temp-text "[fn:1] fn"
  861. (let ((org-adapt-indentation t)) (org-indent-line))
  862. (org-get-indentation))))
  863. (should
  864. (zerop
  865. (org-test-with-temp-text "* H"
  866. (org-indent-line)
  867. (org-get-indentation))))
  868. ;; Do not indent before first headline.
  869. (should
  870. (zerop
  871. (org-test-with-temp-text ""
  872. (org-indent-line)
  873. (org-get-indentation))))
  874. ;; Indent according to headline level otherwise, unless
  875. ;; `org-adapt-indentation' is nil.
  876. (should
  877. (= 2
  878. (org-test-with-temp-text "* H\n<point>A"
  879. (let ((org-adapt-indentation t)) (org-indent-line))
  880. (org-get-indentation))))
  881. (should
  882. (= 2
  883. (org-test-with-temp-text "* H\n<point>\nA"
  884. (let ((org-adapt-indentation t)) (org-indent-line))
  885. (org-get-indentation))))
  886. (should
  887. (zerop
  888. (org-test-with-temp-text "* H\n<point>A"
  889. (let ((org-adapt-indentation nil)) (org-indent-line))
  890. (org-get-indentation))))
  891. ;; Indenting preserves point position.
  892. (should
  893. (org-test-with-temp-text "* H\nA<point>B"
  894. (let ((org-adapt-indentation t)) (org-indent-line))
  895. (looking-at "B")))
  896. ;; Do not change indentation at an item or a LaTeX environment.
  897. (should
  898. (= 1
  899. (org-test-with-temp-text "* H\n<point> - A"
  900. (let ((org-adapt-indentation t)) (org-indent-line))
  901. (org-get-indentation))))
  902. (should
  903. (= 1
  904. (org-test-with-temp-text
  905. "\\begin{equation}\n <point>1+1=2\n\\end{equation}"
  906. (org-indent-line)
  907. (org-get-indentation))))
  908. ;; On blank lines at the end of a list, indent like last element
  909. ;; within it if the line is still in the list. If the last element
  910. ;; is an item, indent like its contents. Otherwise, indent like the
  911. ;; whole list.
  912. (should
  913. (= 4
  914. (org-test-with-temp-text "* H\n- A\n - AA\n<point>"
  915. (let ((org-adapt-indentation t)) (org-indent-line))
  916. (org-get-indentation))))
  917. (should
  918. (= 4
  919. (org-test-with-temp-text "* H\n- A\n -\n\n<point>"
  920. (let ((org-adapt-indentation t)) (org-indent-line))
  921. (org-get-indentation))))
  922. (should
  923. (zerop
  924. (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n<point>"
  925. (let ((org-adapt-indentation t)) (org-indent-line))
  926. (org-get-indentation))))
  927. (should
  928. (= 4
  929. (org-test-with-temp-text "* H\n- A\n - \n<point>"
  930. (let ((org-adapt-indentation t)) (org-indent-line))
  931. (org-get-indentation))))
  932. (should
  933. (= 4
  934. (org-test-with-temp-text
  935. "* H\n - \n #+BEGIN_SRC emacs-lisp\n t\n #+END_SRC\n<point>"
  936. (let ((org-adapt-indentation t)) (org-indent-line))
  937. (org-get-indentation))))
  938. (should
  939. (= 2
  940. (org-test-with-temp-text "- A\n B\n\n<point>"
  941. (let ((org-adapt-indentation nil)) (org-indent-line))
  942. (org-get-indentation))))
  943. (should
  944. (= 2
  945. (org-test-with-temp-text
  946. "- A\n \begin{cases} 1 + 1\n \end{cases}\n\n<point>"
  947. (let ((org-adapt-indentation nil)) (org-indent-line))
  948. (org-get-indentation))))
  949. ;; Likewise, on a blank line at the end of a footnote definition,
  950. ;; indent at column 0 if line belongs to the definition. Otherwise,
  951. ;; indent like the definition itself.
  952. (should
  953. (zerop
  954. (org-test-with-temp-text "* H\n[fn:1] Definition\n<point>"
  955. (let ((org-adapt-indentation t)) (org-indent-line))
  956. (org-get-indentation))))
  957. (should
  958. (zerop
  959. (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n<point>"
  960. (let ((org-adapt-indentation t)) (org-indent-line))
  961. (org-get-indentation))))
  962. ;; After the end of the contents of a greater element, indent like
  963. ;; the beginning of the element.
  964. (should
  965. (= 1
  966. (org-test-with-temp-text
  967. " #+BEGIN_CENTER\n Contents\n<point>#+END_CENTER"
  968. (org-indent-line)
  969. (org-get-indentation))))
  970. ;; On blank lines after a paragraph, indent like its last non-empty
  971. ;; line.
  972. (should
  973. (= 1
  974. (org-test-with-temp-text " Paragraph\n\n<point>"
  975. (org-indent-line)
  976. (org-get-indentation))))
  977. ;; At the first line of an element, indent like previous element's
  978. ;; first line, ignoring footnotes definitions and inline tasks, or
  979. ;; according to parent.
  980. (let ((org-adapt-indentation t))
  981. (should
  982. (= 2
  983. (org-test-with-temp-text "A\n\n B\n\nC<point>"
  984. (org-indent-line)
  985. (org-get-indentation))))
  986. (should
  987. (= 1
  988. (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC<point>"
  989. (org-indent-line)
  990. (org-get-indentation))))
  991. (should
  992. (= 1
  993. (org-test-with-temp-text
  994. " #+BEGIN_CENTER\n<point> Contents\n#+END_CENTER"
  995. (org-indent-line)
  996. (org-get-indentation)))))
  997. ;; Within code part of a source block, use language major mode if
  998. ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
  999. ;; according to line above.
  1000. (should
  1001. (= 6
  1002. (org-test-with-temp-text
  1003. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  1004. (let ((org-src-tab-acts-natively t)
  1005. (org-edit-src-content-indentation 0))
  1006. (org-indent-line))
  1007. (org-get-indentation))))
  1008. (should
  1009. (= 1
  1010. (org-test-with-temp-text
  1011. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  1012. (let ((org-src-tab-acts-natively nil)
  1013. (org-edit-src-content-indentation 0))
  1014. (org-indent-line))
  1015. (org-get-indentation))))
  1016. ;; Otherwise, indent like the first non-blank line above.
  1017. (should
  1018. (zerop
  1019. (org-test-with-temp-text
  1020. "#+BEGIN_CENTER\nline1\n\n<point> line2\n#+END_CENTER"
  1021. (org-indent-line)
  1022. (org-get-indentation))))
  1023. ;; Align node properties according to `org-property-format'. Handle
  1024. ;; nicely empty values.
  1025. (should
  1026. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1027. (org-test-with-temp-text
  1028. "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
  1029. (let ((org-property-format "%-10s %s")) (org-indent-line))
  1030. (buffer-string))))
  1031. (should
  1032. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1033. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
  1034. (let ((org-property-format "%-10s %s")) (org-indent-line))
  1035. (buffer-string)))))
  1036. (ert-deftest test-org/indent-region ()
  1037. "Test `org-indent-region' specifications."
  1038. ;; Indent paragraph.
  1039. (let ((org-adapt-indentation t))
  1040. (should
  1041. (equal "A\nB\nC"
  1042. (org-test-with-temp-text " A\nB\n C"
  1043. (org-indent-region (point-min) (point-max))
  1044. (buffer-string)))))
  1045. ;; Indent greater elements along with their contents.
  1046. (should
  1047. (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
  1048. (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
  1049. (org-indent-region (point-min) (point-max))
  1050. (buffer-string))))
  1051. ;; Ignore contents of verse blocks. Only indent block delimiters.
  1052. (should
  1053. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1054. (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1055. (org-indent-region (point-min) (point-max))
  1056. (buffer-string))))
  1057. (let ((org-adapt-indentation t))
  1058. (should
  1059. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1060. (org-test-with-temp-text " #+BEGIN_VERSE\n A\n B\n #+END_VERSE"
  1061. (org-indent-region (point-min) (point-max))
  1062. (buffer-string)))))
  1063. ;; Indent example blocks as a single block, unless indentation
  1064. ;; should be preserved. In this case only indent the block markers.
  1065. (should
  1066. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1067. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1068. (org-indent-region (point-min) (point-max))
  1069. (buffer-string))))
  1070. (let ((org-adapt-indentation t))
  1071. (should
  1072. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1073. (org-test-with-temp-text " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1074. (org-indent-region (point-min) (point-max))
  1075. (buffer-string))))
  1076. (should
  1077. (equal "#+BEGIN_EXAMPLE -i\n A\n B\n#+END_EXAMPLE"
  1078. (org-test-with-temp-text
  1079. " #+BEGIN_EXAMPLE -i\n A\n B\n #+END_EXAMPLE"
  1080. (org-indent-region (point-min) (point-max))
  1081. (buffer-string))))
  1082. (should
  1083. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1084. (org-test-with-temp-text
  1085. " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1086. (let ((org-src-preserve-indentation t))
  1087. (org-indent-region (point-min) (point-max)))
  1088. (buffer-string)))))
  1089. ;; Treat export blocks as a whole.
  1090. (should
  1091. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1092. (org-test-with-temp-text "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1093. (org-indent-region (point-min) (point-max))
  1094. (buffer-string))))
  1095. (let ((org-adapt-indentation t))
  1096. (should
  1097. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1098. (org-test-with-temp-text
  1099. " #+BEGIN_EXPORT latex\n A\n B\n #+END_EXPORT"
  1100. (org-indent-region (point-min) (point-max))
  1101. (buffer-string)))))
  1102. ;; Indent according to mode if `org-src-tab-acts-natively' is
  1103. ;; non-nil. Otherwise, do not indent code at all.
  1104. (should
  1105. (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
  1106. (org-test-with-temp-text
  1107. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1108. (let ((org-src-tab-acts-natively t)
  1109. (org-edit-src-content-indentation 0))
  1110. (org-indent-region (point-min) (point-max)))
  1111. (buffer-string))))
  1112. (should
  1113. (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1114. (org-test-with-temp-text
  1115. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1116. (let ((org-src-tab-acts-natively nil)
  1117. (org-edit-src-content-indentation 0))
  1118. (org-indent-region (point-min) (point-max)))
  1119. (buffer-string))))
  1120. ;; Align node properties according to `org-property-format'. Handle
  1121. ;; nicely empty values.
  1122. (should
  1123. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1124. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
  1125. (let ((org-property-format "%-10s %s")
  1126. (org-adapt-indentation nil))
  1127. (org-indent-region (point) (point-max)))
  1128. (buffer-string))))
  1129. (should
  1130. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1131. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
  1132. (let ((org-property-format "%-10s %s")
  1133. (org-adapt-indentation nil))
  1134. (org-indent-region (point) (point-max)))
  1135. (buffer-string))))
  1136. ;; Indent property drawers according to `org-adapt-indentation'.
  1137. (let ((org-adapt-indentation 'headline-data))
  1138. (should
  1139. (equal "* H\n :PROPERTIES:\n :key:\n :END:"
  1140. (org-test-with-temp-text "* H\n:PROPERTIES:\n:key:\n:END:"
  1141. (org-indent-region (point-min) (point-max))
  1142. (buffer-string)))))
  1143. ;; Indent plain lists.
  1144. (let ((org-adapt-indentation t))
  1145. (should
  1146. (equal "- A\n B\n - C\n\n D"
  1147. (org-test-with-temp-text "- A\n B\n - C\n\n D"
  1148. (org-indent-region (point-min) (point-max))
  1149. (buffer-string))))
  1150. (should
  1151. (equal "- A\n\n- B"
  1152. (org-test-with-temp-text " - A\n\n - B"
  1153. (org-indent-region (point-min) (point-max))
  1154. (buffer-string)))))
  1155. ;; Indent footnote definitions.
  1156. (should
  1157. (equal "[fn:1] Definition\n\nDefinition"
  1158. (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
  1159. (org-indent-region (point-min) (point-max))
  1160. (buffer-string))))
  1161. ;; Special case: Start indenting on a blank line.
  1162. (should
  1163. (equal "\nParagraph"
  1164. (org-test-with-temp-text "\n Paragraph"
  1165. (org-indent-region (point-min) (point-max))
  1166. (buffer-string)))))
  1167. ;;; Editing
  1168. (ert-deftest test-org/delete-indentation ()
  1169. "Test `org-delete-indentation' specifications."
  1170. ;; Regular test.
  1171. (should (equal "foo bar"
  1172. (org-test-with-temp-text
  1173. "foo \n bar<point>"
  1174. (org-delete-indentation)
  1175. (buffer-string))))
  1176. ;; With optional argument.
  1177. (should (equal "foo bar"
  1178. (org-test-with-temp-text
  1179. "foo<point> \n bar"
  1180. (org-delete-indentation t)
  1181. (buffer-string))))
  1182. ;; At headline text should be appended to the headline text.
  1183. (should
  1184. (equal"* foo bar :tag:"
  1185. (let (org-auto-align-tags)
  1186. (org-test-with-temp-text
  1187. "* foo :tag:\n bar<point>"
  1188. (org-delete-indentation)
  1189. (buffer-string)))))
  1190. (should
  1191. (equal "* foo bar :tag:"
  1192. (let (org-auto-align-tags)
  1193. (org-test-with-temp-text
  1194. "* foo <point>:tag:\n bar"
  1195. (org-delete-indentation t)
  1196. (buffer-string))))))
  1197. (ert-deftest test-org/return ()
  1198. "Test `org-return' specifications."
  1199. ;; Regular test.
  1200. (should
  1201. (equal "Para\ngraph"
  1202. (org-test-with-temp-text "Para<point>graph"
  1203. (org-return)
  1204. (buffer-string))))
  1205. ;; With optional argument, indent line.
  1206. (should
  1207. (equal " Para\n graph"
  1208. (org-test-with-temp-text " Para<point>graph"
  1209. (org-return t)
  1210. (buffer-string))))
  1211. ;; On a table, call `org-table-next-row'.
  1212. (should
  1213. (org-test-with-temp-text "| <point>a |\n| b |"
  1214. (org-return)
  1215. (looking-at-p "b")))
  1216. ;; Open link or timestamp under point when `org-return-follows-link'
  1217. ;; is non-nil.
  1218. (should
  1219. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1220. (let ((org-return-follows-link t)
  1221. (org-link-search-must-match-exact-headline nil))
  1222. (org-return))
  1223. (looking-at-p "<<target>>")))
  1224. (should-not
  1225. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1226. (let ((org-return-follows-link nil)) (org-return))
  1227. (looking-at-p "<<target>>")))
  1228. (should
  1229. (org-test-with-temp-text "* [[b][a<point>]]\n* b"
  1230. (let ((org-return-follows-link t)) (org-return))
  1231. (looking-at-p "* b")))
  1232. (should
  1233. (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
  1234. (let ((org-return-follows-link t)
  1235. (org-link-search-must-match-exact-headline nil))
  1236. (org-return))
  1237. (looking-at-p "<<target>>")))
  1238. (should-not
  1239. (org-test-with-temp-text "Link [[target]]<point> <<target>>"
  1240. (let ((org-return-follows-link t)
  1241. (org-link-search-must-match-exact-headline nil))
  1242. (org-return))
  1243. (looking-at-p "<<target>>")))
  1244. ;; When `org-return-follows-link' is non-nil, tolerate links and
  1245. ;; timestamps in comments, node properties, etc.
  1246. (should
  1247. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1248. (let ((org-return-follows-link t)
  1249. (org-link-search-must-match-exact-headline nil))
  1250. (org-return))
  1251. (looking-at-p "<<target>>")))
  1252. (should-not
  1253. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1254. (let ((org-return-follows-link nil)) (org-return))
  1255. (looking-at-p "<<target>>")))
  1256. (should-not
  1257. (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
  1258. (let ((org-return-follows-link t)
  1259. (org-link-search-must-match-exact-headline nil))
  1260. (org-return))
  1261. (looking-at-p "<<target>>")))
  1262. ;; Non-nil `org-return-follows-link' ignores read-only state of
  1263. ;; a buffer.
  1264. (should
  1265. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1266. (let ((org-return-follows-link t)
  1267. (org-link-search-must-match-exact-headline nil))
  1268. (setq buffer-read-only t)
  1269. (call-interactively #'org-return))
  1270. (looking-at-p "<<target>>")))
  1271. ;; `org-return-follows-link' handle multi-line lines.
  1272. (should
  1273. (org-test-with-temp-text
  1274. "[[target][This is a very\n long description<point>]]\n <<target>>"
  1275. (let ((org-return-follows-link t)
  1276. (org-link-search-must-match-exact-headline nil))
  1277. (org-return))
  1278. (looking-at-p "<<target>>")))
  1279. (should-not
  1280. (org-test-with-temp-text
  1281. "[[target][This is a very\n long description]]<point>\n <<target>>"
  1282. (let ((org-return-follows-link t)
  1283. (org-link-search-must-match-exact-headline nil))
  1284. (org-return))
  1285. (looking-at-p "<<target>>")))
  1286. ;; However, do not open link when point is in a table.
  1287. (should
  1288. (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
  1289. (let ((org-return-follows-link t)) (org-return))
  1290. (looking-at-p "between")))
  1291. ;; Special case: in a list, when indenting, do not break structure.
  1292. (should
  1293. (equal "- A\n B"
  1294. (org-test-with-temp-text "- A <point>B"
  1295. (org-return t)
  1296. (buffer-string))))
  1297. (should
  1298. (equal "- A\n\n- B"
  1299. (org-test-with-temp-text "- A\n<point>- B"
  1300. (org-return t)
  1301. (buffer-string))))
  1302. ;; On tags part of a headline, add a newline below it instead of
  1303. ;; breaking it.
  1304. (should
  1305. (equal "* H :tag:\n"
  1306. (org-test-with-temp-text "* H :<point>tag:"
  1307. (org-return)
  1308. (buffer-string))))
  1309. ;; Before headline text, add a newline below it instead of breaking
  1310. ;; it.
  1311. (should
  1312. (equal "* TODO H :tag:\n"
  1313. (org-test-with-temp-text "* <point>TODO H :tag:"
  1314. (org-return)
  1315. (buffer-string))))
  1316. (should
  1317. (equal "* TODO [#B] H :tag:\n"
  1318. (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
  1319. (org-return)
  1320. (buffer-string))))
  1321. (should ;TODO are case-sensitive
  1322. (equal "* \nTodo"
  1323. (org-test-with-temp-text "* <point>Todo"
  1324. (org-return)
  1325. (buffer-string))))
  1326. ;; At headline text, break headline text but preserve tags.
  1327. (should
  1328. (equal "* TODO [#B] foo :tag:\nbar"
  1329. (let (org-auto-align-tags)
  1330. (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
  1331. (org-return)
  1332. (buffer-string)))))
  1333. ;; At bol of headline insert newline.
  1334. (should
  1335. (equal "\n* h"
  1336. (org-test-with-temp-text "<point>* h"
  1337. (org-return)
  1338. (buffer-string))))
  1339. ;; Refuse to leave invalid headline in buffer.
  1340. (should
  1341. (equal "* h\n"
  1342. (org-test-with-temp-text "*<point> h"
  1343. (org-return)
  1344. (buffer-string))))
  1345. ;; Before first column or after last one in a table, split the
  1346. ;; table.
  1347. (should
  1348. (equal "| a |\n\n| b |"
  1349. (org-test-with-temp-text "| a |\n<point>| b |"
  1350. (org-return)
  1351. (buffer-string))))
  1352. (should
  1353. (equal "| a |\n\n| b |"
  1354. (org-test-with-temp-text "| a |<point>\n| b |"
  1355. (org-return)
  1356. (buffer-string))))
  1357. ;; Do not auto-fill on hitting <RET> inside a property drawer.
  1358. (should
  1359. (equal "* Heading\n:PROPERTIES:\n:SOME_PROP: This is a very long property value that goes beyond the fill-column. But this is inside a property drawer, so the auto-filling should be disabled.\n\n:END:"
  1360. (org-test-with-temp-text "* Heading\n:PROPERTIES:\n:SOME_PROP: This is a very long property value that goes beyond the fill-column. But this is inside a property drawer, so the auto-filling should be disabled.<point>\n:END:"
  1361. (setq-local fill-column 10)
  1362. (auto-fill-mode 1)
  1363. (org-return)
  1364. (buffer-string)))))
  1365. (ert-deftest test-org/with-electric-indent ()
  1366. "Test RET and C-j specifications with `electric-indent-mode' on."
  1367. ;; Call commands interactively, since this is how `newline' knows it
  1368. ;; must run `post-self-insert-hook'.
  1369. ;;
  1370. ;; RET, like `newline', should indent.
  1371. (should
  1372. (equal " Para\n graph"
  1373. (org-test-with-temp-text " Para<point>graph"
  1374. (electric-indent-local-mode 1)
  1375. (call-interactively 'org-return)
  1376. (buffer-string))))
  1377. (should
  1378. (equal "- item1\n item2"
  1379. (org-test-with-temp-text "- item1<point>item2"
  1380. (electric-indent-local-mode 1)
  1381. (call-interactively 'org-return)
  1382. (buffer-string))))
  1383. ;; TODO: test more values of `org-adapt-indentation'.
  1384. (let ((org-adapt-indentation t))
  1385. (should
  1386. (equal "* heading\n body"
  1387. (org-test-with-temp-text "* heading<point>body"
  1388. (electric-indent-local-mode 1)
  1389. (call-interactively 'org-return)
  1390. (buffer-string)))))
  1391. ;; C-j, like `electric-newline-and-maybe-indent', should not indent.
  1392. (should
  1393. (equal " Para\ngraph"
  1394. (org-test-with-temp-text " Para<point>graph"
  1395. (electric-indent-local-mode 1)
  1396. (call-interactively 'org-return-and-maybe-indent)
  1397. (buffer-string))))
  1398. (should
  1399. (equal "- item1\nitem2"
  1400. (org-test-with-temp-text "- item1<point>item2"
  1401. (electric-indent-local-mode 1)
  1402. (call-interactively 'org-return-and-maybe-indent)
  1403. (buffer-string))))
  1404. ;; TODO: test more values of `org-adapt-indentation'.
  1405. (let ((org-adapt-indentation t))
  1406. (should
  1407. (equal "* heading\nbody"
  1408. (org-test-with-temp-text "* heading<point>body"
  1409. (electric-indent-local-mode 1)
  1410. (call-interactively 'org-return-and-maybe-indent)
  1411. (buffer-string))))))
  1412. (ert-deftest test-org/without-electric-indent ()
  1413. "Test RET and C-j specifications with `electric-indent-mode' off."
  1414. ;; Call commands interactively, since this is how `newline' knows it
  1415. ;; must run `post-self-insert-hook'.
  1416. ;;
  1417. ;; RET, like `newline', should not indent.
  1418. (should
  1419. (equal " Para\ngraph"
  1420. (org-test-with-temp-text " Para<point>graph"
  1421. (electric-indent-local-mode 0)
  1422. (call-interactively 'org-return)
  1423. (buffer-string))))
  1424. (should
  1425. (equal "- item1\nitem2"
  1426. (org-test-with-temp-text "- item1<point>item2"
  1427. (electric-indent-local-mode 0)
  1428. (call-interactively 'org-return)
  1429. (buffer-string))))
  1430. (should
  1431. (equal "* heading\nbody"
  1432. (org-test-with-temp-text "* heading<point>body"
  1433. (electric-indent-local-mode 0)
  1434. (call-interactively 'org-return)
  1435. (buffer-string))))
  1436. ;; C-j, like `electric-newline-and-maybe-indent', should indent.
  1437. (should
  1438. (equal " Para\n graph"
  1439. (org-test-with-temp-text " Para<point>graph"
  1440. (electric-indent-local-mode 0)
  1441. (call-interactively 'org-return-and-maybe-indent)
  1442. (buffer-string))))
  1443. (should
  1444. (equal "- item1\n item2"
  1445. (org-test-with-temp-text "- item1<point>item2"
  1446. (electric-indent-local-mode 0)
  1447. (call-interactively 'org-return-and-maybe-indent)
  1448. (buffer-string))))
  1449. ;; TODO: test more values of `org-adapt-indentation'.
  1450. (let ((org-adapt-indentation t))
  1451. (should
  1452. (equal "* heading\n body"
  1453. (org-test-with-temp-text "* heading<point>body"
  1454. (electric-indent-local-mode 0)
  1455. (call-interactively 'org-return-and-maybe-indent)
  1456. (buffer-string))))))
  1457. (ert-deftest test-org/meta-return ()
  1458. "Test M-RET (`org-meta-return') specifications."
  1459. ;; In a table field insert a row above.
  1460. (should
  1461. (org-test-with-temp-text "| a |"
  1462. (forward-char)
  1463. (org-meta-return)
  1464. (forward-line -1)
  1465. (looking-at "| |$")))
  1466. ;; In a paragraph change current line into a header.
  1467. (should
  1468. (org-test-with-temp-text "a"
  1469. (org-meta-return)
  1470. (beginning-of-line)
  1471. (looking-at "\* a$")))
  1472. ;; In an item insert an item, in this case above.
  1473. (should
  1474. (org-test-with-temp-text "- a"
  1475. (org-meta-return)
  1476. (beginning-of-line)
  1477. (looking-at "- $")))
  1478. ;; In a drawer and item insert an item, in this case above.
  1479. (should
  1480. (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
  1481. (forward-line)
  1482. (org-meta-return)
  1483. (beginning-of-line)
  1484. (looking-at "- $"))))
  1485. (ert-deftest test-org/insert-heading ()
  1486. "Test `org-insert-heading' specifications."
  1487. ;; In an empty buffer, insert a new headline.
  1488. (should
  1489. (equal "* "
  1490. (org-test-with-temp-text ""
  1491. (org-insert-heading)
  1492. (buffer-string))))
  1493. ;; At the beginning of a line, turn it into a headline.
  1494. (should
  1495. (equal "* P"
  1496. (org-test-with-temp-text "<point>P"
  1497. (org-insert-heading)
  1498. (buffer-string))))
  1499. ;; In the middle of a line, split the line if allowed, otherwise,
  1500. ;; insert the headline at its end.
  1501. (should
  1502. (equal "Para\n* graph"
  1503. (org-test-with-temp-text "Para<point>graph"
  1504. (let ((org-M-RET-may-split-line '((default . t))))
  1505. (org-insert-heading))
  1506. (buffer-string))))
  1507. (should
  1508. (equal "Paragraph\n* "
  1509. (org-test-with-temp-text "Para<point>graph"
  1510. (let ((org-M-RET-may-split-line '((default . nil))))
  1511. (org-insert-heading))
  1512. (buffer-string))))
  1513. ;; At the beginning of a headline, create one above.
  1514. (should
  1515. (equal "* \n* H"
  1516. (org-test-with-temp-text "* H"
  1517. (org-insert-heading)
  1518. (buffer-string))))
  1519. ;; In the middle of a headline, split it if allowed.
  1520. (should
  1521. (equal "* H\n* 1"
  1522. (org-test-with-temp-text "* H<point>1"
  1523. (let ((org-M-RET-may-split-line '((headline . t))))
  1524. (org-insert-heading))
  1525. (buffer-string))))
  1526. (should
  1527. (equal "* H1\n* "
  1528. (org-test-with-temp-text "* H<point>1"
  1529. (let ((org-M-RET-may-split-line '((headline . nil))))
  1530. (org-insert-heading))
  1531. (buffer-string))))
  1532. ;; However, splitting cannot happen on TODO keywords, priorities or
  1533. ;; tags.
  1534. (should
  1535. (equal "* TODO H1\n* "
  1536. (org-test-with-temp-text "* TO<point>DO H1"
  1537. (let ((org-M-RET-may-split-line '((headline . t))))
  1538. (org-insert-heading))
  1539. (buffer-string))))
  1540. (should
  1541. (equal "* [#A] H1\n* "
  1542. (org-test-with-temp-text "* [#<point>A] H1"
  1543. (let ((org-M-RET-may-split-line '((headline . t))))
  1544. (org-insert-heading))
  1545. (buffer-string))))
  1546. (should
  1547. (equal "* H1 :tag:\n* "
  1548. (org-test-with-temp-text "* H1 :ta<point>g:"
  1549. (let ((org-M-RET-may-split-line '((headline . t))))
  1550. (org-insert-heading))
  1551. (buffer-string))))
  1552. ;; New headline level depends on the level of the headline above.
  1553. (should
  1554. (equal "** H\n** P"
  1555. (org-test-with-temp-text "** H\n<point>P"
  1556. (org-insert-heading)
  1557. (buffer-string))))
  1558. (should
  1559. (equal "** H\nPara\n** graph"
  1560. (org-test-with-temp-text "** H\nPara<point>graph"
  1561. (let ((org-M-RET-may-split-line '((default . t))))
  1562. (org-insert-heading))
  1563. (buffer-string))))
  1564. (should
  1565. (equal "** \n** H"
  1566. (org-test-with-temp-text "** H"
  1567. (org-insert-heading)
  1568. (buffer-string))))
  1569. ;; When called with one universal argument, insert a new headline at
  1570. ;; the end of the current subtree, independently on the position of
  1571. ;; point.
  1572. (should
  1573. (equal
  1574. "* "
  1575. (org-test-with-temp-text ""
  1576. (let ((org-insert-heading-respect-content nil))
  1577. (org-insert-heading '(4)))
  1578. (buffer-string))))
  1579. (should
  1580. (equal
  1581. "entry
  1582. * "
  1583. (org-test-with-temp-text "entry"
  1584. (let ((org-insert-heading-respect-content nil))
  1585. (org-insert-heading '(4)))
  1586. (buffer-string))))
  1587. (should
  1588. (equal
  1589. "* H1\n** H2\n* "
  1590. (org-test-with-temp-text "* H1\n** H2"
  1591. (let ((org-insert-heading-respect-content nil))
  1592. (org-insert-heading '(4)))
  1593. (buffer-string))))
  1594. (should
  1595. (equal
  1596. "* H1\n** H2\n* "
  1597. (org-test-with-temp-text "* H<point>1\n** H2"
  1598. (let ((org-insert-heading-respect-content nil))
  1599. (org-insert-heading '(4)))
  1600. (buffer-string))))
  1601. ;; When called with two universal arguments, insert a new headline
  1602. ;; at the end of the grandparent subtree.
  1603. (should
  1604. (equal "* H1\n** H3\n- item\n** H2\n** "
  1605. (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
  1606. (let ((org-insert-heading-respect-content nil))
  1607. (org-insert-heading '(16)))
  1608. (buffer-string))))
  1609. ;; When optional TOP-LEVEL argument is non-nil, always insert
  1610. ;; a level 1 heading.
  1611. (should
  1612. (equal "* H1\n** H2\n* "
  1613. (org-test-with-temp-text "* H1\n** H2<point>"
  1614. (org-insert-heading nil nil t)
  1615. (buffer-string))))
  1616. (should
  1617. (equal "* H1\n- item\n* "
  1618. (org-test-with-temp-text "* H1\n- item<point>"
  1619. (org-insert-heading nil nil t)
  1620. (buffer-string))))
  1621. ;; Obey `org-blank-before-new-entry'.
  1622. (should
  1623. (equal "* H1\n\n* "
  1624. (org-test-with-temp-text "* H1<point>"
  1625. (let ((org-blank-before-new-entry '((heading . t))))
  1626. (org-insert-heading))
  1627. (buffer-string))))
  1628. (should
  1629. (equal "* H1\n* "
  1630. (org-test-with-temp-text "* H1<point>"
  1631. (let ((org-blank-before-new-entry '((heading . nil))))
  1632. (org-insert-heading))
  1633. (buffer-string))))
  1634. (should
  1635. (equal "* H1\n* H2\n* "
  1636. (org-test-with-temp-text "* H1\n* H2<point>"
  1637. (let ((org-blank-before-new-entry '((heading . auto))))
  1638. (org-insert-heading))
  1639. (buffer-string))))
  1640. (should
  1641. (equal "* H1\n\n* H2\n\n* "
  1642. (org-test-with-temp-text "* H1\n\n* H2<point>"
  1643. (let ((org-blank-before-new-entry '((heading . auto))))
  1644. (org-insert-heading))
  1645. (buffer-string))))
  1646. ;; Corner case: correctly insert a headline after an empty one.
  1647. (should
  1648. (equal "* \n* "
  1649. (org-test-with-temp-text "* <point>"
  1650. (org-insert-heading)
  1651. (buffer-string))))
  1652. (should
  1653. (org-test-with-temp-text "* <point>\n"
  1654. (org-insert-heading)
  1655. (looking-at-p "\n\\'")))
  1656. ;; Do not insert spurious headlines when inserting a new headline.
  1657. (should
  1658. (equal "* H1\n* H2\n* \n"
  1659. (org-test-with-temp-text "* H1\n* H2<point>\n"
  1660. (org-insert-heading)
  1661. (buffer-string))))
  1662. ;; Preserve visibility at beginning of line. In particular, when
  1663. ;; removing spurious blank lines, do not visually merge heading with
  1664. ;; the line visible above.
  1665. (should-not
  1666. (org-test-with-temp-text "* H1<point>\nContents\n\n* H2\n"
  1667. (org-overview)
  1668. (let ((org-blank-before-new-entry '((heading . nil))))
  1669. (org-insert-heading '(4)))
  1670. (invisible-p (line-end-position 0))))
  1671. ;; Properly handle empty lines when forcing a headline below current
  1672. ;; one.
  1673. (should
  1674. (equal "* H1\n\n* H\n\n* "
  1675. (org-test-with-temp-text "* H1\n\n* H<point>"
  1676. (let ((org-blank-before-new-entry '((heading . t))))
  1677. (org-insert-heading '(4))
  1678. (buffer-string))))))
  1679. (ert-deftest test-org/insert-todo-heading-respect-content ()
  1680. "Test `org-insert-todo-heading-respect-content' specifications."
  1681. ;; Create a TODO heading.
  1682. (should
  1683. (org-test-with-temp-text "* H1\n Body"
  1684. (org-insert-todo-heading-respect-content)
  1685. (nth 2 (org-heading-components))))
  1686. ;; Add headline at the end of the first subtree
  1687. (should
  1688. (equal
  1689. "* TODO "
  1690. (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
  1691. (org-insert-todo-heading-respect-content)
  1692. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1693. ;; In a list, do not create a new item.
  1694. (should
  1695. (equal
  1696. "* TODO "
  1697. (org-test-with-temp-text "* H\n- an item\n- another one"
  1698. (search-forward "an ")
  1699. (org-insert-todo-heading-respect-content)
  1700. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1701. ;; Use the same TODO keyword as current heading.
  1702. (should
  1703. (equal
  1704. "* TODO \n"
  1705. (org-test-with-temp-text "* TODO\n** WAITING\n"
  1706. (org-insert-todo-heading-respect-content)
  1707. (buffer-substring-no-properties (line-beginning-position) (point-max))))))
  1708. (ert-deftest test-org/clone-with-time-shift ()
  1709. "Test `org-clone-subtree-with-time-shift'."
  1710. ;; Raise an error before first heading.
  1711. (should-error
  1712. (org-test-with-temp-text ""
  1713. (org-clone-subtree-with-time-shift 1)))
  1714. ;; Raise an error on invalid number of clones.
  1715. (should-error
  1716. (org-test-with-temp-text "* Clone me"
  1717. (org-clone-subtree-with-time-shift -1)))
  1718. ;; Clone non-repeating once.
  1719. (should
  1720. (equal "\
  1721. * H1\n<2015-06-21>
  1722. * H1\n<2015-06-23>
  1723. "
  1724. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1725. (org-clone-subtree-with-time-shift 1 "+2d")
  1726. (replace-regexp-in-string
  1727. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1728. nil nil 1))))
  1729. ;; Clone repeating once.
  1730. (should
  1731. (equal "\
  1732. * H1\n<2015-06-21>
  1733. * H1\n<2015-06-23>
  1734. * H1\n<2015-06-25 +1w>
  1735. "
  1736. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1737. (org-clone-subtree-with-time-shift 1 "+2d")
  1738. (replace-regexp-in-string
  1739. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1740. nil nil 1))))
  1741. ;; Clone repeating once in backward.
  1742. (should
  1743. (equal "\
  1744. * H1\n<2015-06-21>
  1745. * H1\n<2015-06-19>
  1746. * H1\n<2015-06-17 +1w>
  1747. "
  1748. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1749. (org-clone-subtree-with-time-shift 1 "-2d")
  1750. (replace-regexp-in-string
  1751. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1752. nil nil 1))))
  1753. ;; Clone non-repeating zero times.
  1754. (should
  1755. (equal "\
  1756. * H1\n<2015-06-21>
  1757. "
  1758. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1759. (org-clone-subtree-with-time-shift 0 "+2d")
  1760. (replace-regexp-in-string
  1761. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1762. nil nil 1))))
  1763. ;; Clone repeating "zero" times.
  1764. (should
  1765. (equal "\
  1766. * H1\n<2015-06-21>
  1767. * H1\n<2015-06-23 +1w>
  1768. "
  1769. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1770. (org-clone-subtree-with-time-shift 0 "+2d")
  1771. (replace-regexp-in-string
  1772. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1773. nil nil 1))))
  1774. ;; Clone with blank SHIFT argument.
  1775. (should
  1776. (string-prefix-p
  1777. "* H <2012-03-29"
  1778. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1779. (org-clone-subtree-with-time-shift 1 "")
  1780. (buffer-substring-no-properties (line-beginning-position 2)
  1781. (line-end-position 2)))))
  1782. ;; Find time stamps before point. If SHIFT is not specified, ask
  1783. ;; for a time shift.
  1784. (should
  1785. (string-prefix-p
  1786. "* H <2012-03-30"
  1787. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1788. (org-clone-subtree-with-time-shift 1 "+1d")
  1789. (buffer-substring-no-properties (line-beginning-position 2)
  1790. (line-end-position 2)))))
  1791. (should
  1792. (string-prefix-p
  1793. "* H <2014-03-05"
  1794. (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
  1795. (cl-letf (((symbol-function 'read-from-minibuffer)
  1796. (lambda (&rest args) "+1d")))
  1797. (org-clone-subtree-with-time-shift 1))
  1798. (buffer-substring-no-properties (line-beginning-position 2)
  1799. (line-end-position 2)))))
  1800. ;; Hour shift.
  1801. (should
  1802. (equal "\
  1803. * H1\n<2015-06-21 20:00>
  1804. * H1\n<2015-06-21 23:00>
  1805. * H1\n<2015-06-22 02:00>
  1806. "
  1807. (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>"
  1808. (org-clone-subtree-with-time-shift 2 "+3h")
  1809. (replace-regexp-in-string
  1810. "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" ""
  1811. (buffer-substring-no-properties (point-min) (point-max))
  1812. nil nil 1))))
  1813. (should
  1814. (equal "\
  1815. * H1\n<2015-06-21 20:00>
  1816. * H1\n<2015-06-21 18:00>
  1817. "
  1818. (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>"
  1819. (org-clone-subtree-with-time-shift 1 "-2h")
  1820. (replace-regexp-in-string
  1821. "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" ""
  1822. (buffer-substring-no-properties (point-min) (point-max))
  1823. nil nil 1)))))
  1824. ;;; Fixed-Width Areas
  1825. (ert-deftest test-org/toggle-fixed-width ()
  1826. "Test `org-toggle-fixed-width' specifications."
  1827. ;; No region: Toggle on fixed-width marker in paragraphs.
  1828. (should
  1829. (equal ": A"
  1830. (org-test-with-temp-text "A"
  1831. (org-toggle-fixed-width)
  1832. (buffer-string))))
  1833. ;; No region: Toggle off fixed-width markers in fixed-width areas.
  1834. (should
  1835. (equal "A"
  1836. (org-test-with-temp-text ": A"
  1837. (org-toggle-fixed-width)
  1838. (buffer-string))))
  1839. ;; No region: Toggle on marker in blank lines after elements or just
  1840. ;; after a headline.
  1841. (should
  1842. (equal "* H\n: "
  1843. (org-test-with-temp-text "* H\n"
  1844. (forward-line)
  1845. (org-toggle-fixed-width)
  1846. (buffer-string))))
  1847. (should
  1848. (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
  1849. (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
  1850. (goto-char (point-max))
  1851. (org-toggle-fixed-width)
  1852. (buffer-string))))
  1853. ;; No region: Toggle on marker in front of one line elements (e.g.,
  1854. ;; headlines, clocks)
  1855. (should
  1856. (equal ": * Headline"
  1857. (org-test-with-temp-text "* Headline"
  1858. (org-toggle-fixed-width)
  1859. (buffer-string))))
  1860. (should
  1861. (equal ": #+KEYWORD: value"
  1862. (org-test-with-temp-text "#+KEYWORD: value"
  1863. (org-toggle-fixed-width)
  1864. (buffer-string))))
  1865. ;; No region: error in other situations.
  1866. (should-error
  1867. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
  1868. (forward-line)
  1869. (org-toggle-fixed-width)
  1870. (buffer-string)))
  1871. ;; No region: Indentation is preserved.
  1872. (should
  1873. (equal "- A\n : B"
  1874. (org-test-with-temp-text "- A\n B"
  1875. (forward-line)
  1876. (org-toggle-fixed-width)
  1877. (buffer-string))))
  1878. ;; Region: If it contains only fixed-width elements and blank lines,
  1879. ;; toggle off fixed-width markup.
  1880. (should
  1881. (equal "A\n\nB"
  1882. (org-test-with-temp-text ": A\n\n: B"
  1883. (transient-mark-mode 1)
  1884. (push-mark (point) t t)
  1885. (goto-char (point-max))
  1886. (org-toggle-fixed-width)
  1887. (buffer-string))))
  1888. ;; Region: If it contains anything else, toggle on fixed-width but
  1889. ;; not on fixed-width areas.
  1890. (should
  1891. (equal ": A\n: \n: B\n: \n: C"
  1892. (org-test-with-temp-text "A\n\n: B\n\nC"
  1893. (transient-mark-mode 1)
  1894. (push-mark (point) t t)
  1895. (goto-char (point-max))
  1896. (org-toggle-fixed-width)
  1897. (buffer-string))))
  1898. ;; Region: Ignore blank lines at its end, unless it contains only
  1899. ;; such lines.
  1900. (should
  1901. (equal ": A\n\n"
  1902. (org-test-with-temp-text "A\n\n"
  1903. (transient-mark-mode 1)
  1904. (push-mark (point) t t)
  1905. (goto-char (point-max))
  1906. (org-toggle-fixed-width)
  1907. (buffer-string))))
  1908. (should
  1909. (equal ": \n: \n"
  1910. (org-test-with-temp-text "\n\n"
  1911. (transient-mark-mode 1)
  1912. (push-mark (point) t t)
  1913. (goto-char (point-max))
  1914. (org-toggle-fixed-width)
  1915. (buffer-string)))))
  1916. (ert-deftest test-org/kill-line ()
  1917. "Test `org-kill-line' specifications."
  1918. ;; At the beginning of a line, kill whole line.
  1919. (should
  1920. (equal ""
  1921. (org-test-with-temp-text "abc"
  1922. (org-kill-line)
  1923. (buffer-string))))
  1924. ;; In the middle of a line, kill line until its end.
  1925. (should
  1926. (equal "a"
  1927. (org-test-with-temp-text "a<point>bc"
  1928. (org-kill-line)
  1929. (buffer-string))))
  1930. ;; Do not kill newline character.
  1931. (should
  1932. (equal "\n123"
  1933. (org-test-with-temp-text "abc\n123"
  1934. (org-kill-line)
  1935. (buffer-string))))
  1936. (should
  1937. (equal "a\n123"
  1938. (org-test-with-temp-text "a<point>bc\n123"
  1939. (org-kill-line)
  1940. (buffer-string))))
  1941. ;; When `org-special-ctrl-k' is non-nil and point is at a headline,
  1942. ;; kill until tags.
  1943. (should
  1944. (equal "* A :tag:"
  1945. (org-test-with-temp-text "* A<point>B :tag:"
  1946. (let ((org-special-ctrl-k t)
  1947. (org-tags-column 0))
  1948. (org-kill-line))
  1949. (buffer-string))))
  1950. ;; If point is on tags, only kill part left until the end of line.
  1951. (should
  1952. (equal "* A :tag:"
  1953. (org-test-with-temp-text "* A :tag:<point>tag2:"
  1954. (let ((org-special-ctrl-k t)
  1955. (org-tags-column 0))
  1956. (org-kill-line))
  1957. (buffer-string))))
  1958. ;; However, if point is at the beginning of the line, kill whole
  1959. ;; headline.
  1960. (should
  1961. (equal ""
  1962. (org-test-with-temp-text "* AB :tag:"
  1963. (let ((org-special-ctrl-k t)
  1964. (org-tags-column 0))
  1965. (org-kill-line))
  1966. (buffer-string))))
  1967. ;; When `org-ctrl-k-protect-subtree' is non-nil, and point is in
  1968. ;; invisible text, ask before removing it. When set to `error',
  1969. ;; throw an error.
  1970. (should-error
  1971. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  1972. (org-overview)
  1973. (let ((org-special-ctrl-k nil)
  1974. (org-ctrl-k-protect-subtree t))
  1975. (cl-letf (((symbol-function 'y-or-n-p) 'ignore))
  1976. (org-kill-line)))))
  1977. (should-error
  1978. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  1979. (org-overview)
  1980. (let ((org-special-ctrl-k nil)
  1981. (org-ctrl-k-protect-subtree 'error))
  1982. (org-kill-line)))))
  1983. ;;; Headline
  1984. (ert-deftest test-org/get-heading ()
  1985. "Test `org-get-heading' specifications."
  1986. ;; Return current heading, even if point is not on it.
  1987. (should
  1988. (equal "H"
  1989. (org-test-with-temp-text "* H"
  1990. (org-get-heading))))
  1991. (should
  1992. (equal "H"
  1993. (org-test-with-temp-text "* H\nText<point>"
  1994. (org-get-heading))))
  1995. ;; Without any optional argument, return TODO keyword, priority
  1996. ;; cookie, COMMENT keyword and tags.
  1997. (should
  1998. (equal "TODO H"
  1999. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2000. (org-get-heading))))
  2001. (should
  2002. (equal "[#A] H"
  2003. (org-test-with-temp-text "* [#A] H"
  2004. (org-get-heading))))
  2005. (should
  2006. (equal "COMMENT H"
  2007. (org-test-with-temp-text "* COMMENT H"
  2008. (org-get-heading))))
  2009. (should
  2010. (equal "H :tag:"
  2011. (org-test-with-temp-text "* H :tag:"
  2012. (org-get-heading))))
  2013. ;; With NO-TAGS argument, ignore tags.
  2014. (should
  2015. (equal "TODO H"
  2016. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2017. (org-get-heading t))))
  2018. (should
  2019. (equal "H"
  2020. (org-test-with-temp-text "* H :tag:"
  2021. (org-get-heading t))))
  2022. ;; With NO-TODO, ignore TODO keyword.
  2023. (should
  2024. (equal "H"
  2025. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2026. (org-get-heading nil t))))
  2027. (should
  2028. (equal "H :tag:"
  2029. (org-test-with-temp-text "* H :tag:"
  2030. (org-get-heading nil t))))
  2031. ;; TODO keywords are case-sensitive.
  2032. (should
  2033. (equal "Todo H"
  2034. (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
  2035. (org-get-heading nil t))))
  2036. ;; With NO-PRIORITY, ignore priority.
  2037. (should
  2038. (equal "H"
  2039. (org-test-with-temp-text "* [#A] H"
  2040. (org-get-heading nil nil t))))
  2041. (should
  2042. (equal "H"
  2043. (org-test-with-temp-text "* H"
  2044. (org-get-heading nil nil t))))
  2045. (should
  2046. (equal "TODO H"
  2047. (org-test-with-temp-text "* TODO [#A] H"
  2048. (org-get-heading nil nil t))))
  2049. ;; With NO-COMMENT, ignore COMMENT keyword.
  2050. (should
  2051. (equal "H"
  2052. (org-test-with-temp-text "* COMMENT H"
  2053. (org-get-heading nil nil nil t))))
  2054. (should
  2055. (equal "H"
  2056. (org-test-with-temp-text "* H"
  2057. (org-get-heading nil nil nil t))))
  2058. (should
  2059. (equal "TODO [#A] H"
  2060. (org-test-with-temp-text "* TODO [#A] COMMENT H"
  2061. (org-get-heading nil nil nil t))))
  2062. ;; On an empty headline, return value is consistent.
  2063. (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
  2064. (should (equal "" (org-test-with-temp-text "* " (org-get-heading t))))
  2065. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t))))
  2066. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t))))
  2067. (should
  2068. (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t)))))
  2069. (ert-deftest test-org/in-commented-heading-p ()
  2070. "Test `org-in-commented-heading-p' specifications."
  2071. ;; Commented headline.
  2072. (should
  2073. (org-test-with-temp-text "* COMMENT Headline\nBody"
  2074. (goto-char (point-max))
  2075. (org-in-commented-heading-p)))
  2076. ;; Commented ancestor.
  2077. (should
  2078. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  2079. (goto-char (point-max))
  2080. (org-in-commented-heading-p)))
  2081. ;; Comment keyword is case-sensitive.
  2082. (should-not
  2083. (org-test-with-temp-text "* Comment Headline\nBody"
  2084. (goto-char (point-max))
  2085. (org-in-commented-heading-p)))
  2086. ;; Keyword is standalone.
  2087. (should-not
  2088. (org-test-with-temp-text "* COMMENTHeadline\nBody"
  2089. (goto-char (point-max))
  2090. (org-in-commented-heading-p)))
  2091. ;; Optional argument.
  2092. (should-not
  2093. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  2094. (goto-char (point-max))
  2095. (org-in-commented-heading-p t))))
  2096. (ert-deftest test-org/in-archived-heading-p ()
  2097. "Test `org-in-archived-heading-p' specifications."
  2098. ;; Archived headline.
  2099. (should
  2100. (org-test-with-temp-text "* Headline :ARCHIVE:\nBody"
  2101. (goto-char (point-max))
  2102. (org-in-archived-heading-p)))
  2103. ;; Archived ancestor.
  2104. (should
  2105. (org-test-with-temp-text "* Headline :ARCHIVE:\n** Level 2\nBody"
  2106. (goto-char (point-max))
  2107. (org-in-archived-heading-p)))
  2108. ;; Optional argument.
  2109. (should-not
  2110. (org-test-with-temp-text "* Headline :ARCHIVE:\n** Level 2\nBody"
  2111. (goto-char (point-max))
  2112. (org-in-archived-heading-p t)))
  2113. ;; Archive tag containing ARCHIVE as substring
  2114. (should-not
  2115. (org-test-with-temp-text "* Headline :NOARCHIVE:\n** Level 2\nBody"
  2116. (goto-char (point-max))
  2117. (org-in-archived-heading-p))))
  2118. (ert-deftest test-org/entry-blocked-p ()
  2119. ;; Check other dependencies.
  2120. (should
  2121. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  2122. (let ((org-enforce-todo-dependencies t)
  2123. (org-blocker-hook
  2124. '(org-block-todo-from-children-or-siblings-or-parent)))
  2125. (org-entry-blocked-p))))
  2126. (should-not
  2127. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  2128. (let ((org-enforce-todo-dependencies t)
  2129. (org-blocker-hook
  2130. '(org-block-todo-from-children-or-siblings-or-parent)))
  2131. (org-entry-blocked-p))))
  2132. ;; Entry without a TODO keyword or with a DONE keyword cannot be
  2133. ;; blocked.
  2134. (should-not
  2135. (org-test-with-temp-text "* Blocked\n** TODO one"
  2136. (let ((org-enforce-todo-dependencies t)
  2137. (org-blocker-hook
  2138. '(org-block-todo-from-children-or-siblings-or-parent)))
  2139. (org-entry-blocked-p))))
  2140. (should-not
  2141. (org-test-with-temp-text "* DONE Blocked\n** TODO one"
  2142. (let ((org-enforce-todo-dependencies t)
  2143. (org-blocker-hook
  2144. '(org-block-todo-from-children-or-siblings-or-parent)))
  2145. (org-entry-blocked-p))))
  2146. ;; Follow :ORDERED: specifications.
  2147. (should
  2148. (org-test-with-temp-text
  2149. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
  2150. (let ((org-enforce-todo-dependencies t)
  2151. (org-blocker-hook
  2152. '(org-block-todo-from-children-or-siblings-or-parent)))
  2153. (org-entry-blocked-p))))
  2154. (should-not
  2155. (org-test-with-temp-text
  2156. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
  2157. (let ((org-enforce-todo-dependencies t)
  2158. (org-blocker-hook
  2159. '(org-block-todo-from-children-or-siblings-or-parent)))
  2160. (org-entry-blocked-p)))))
  2161. (ert-deftest test-org/get-outline-path ()
  2162. "Test `org-get-outline-path' specifications."
  2163. ;; Top-level headlines have no outline path.
  2164. (should-not
  2165. (org-test-with-temp-text "* H"
  2166. (org-get-outline-path)))
  2167. ;; Otherwise, outline path is the path leading to the headline.
  2168. (should
  2169. (equal '("H")
  2170. (org-test-with-temp-text "* H\n** S<point>"
  2171. (org-get-outline-path))))
  2172. ;; Find path even when point is not on a headline.
  2173. (should
  2174. (equal '("H")
  2175. (org-test-with-temp-text "* H\n** S\nText<point>"
  2176. (org-get-outline-path))))
  2177. ;; TODO keywords, tags and statistics cookies are ignored.
  2178. (should
  2179. (equal '("H")
  2180. (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
  2181. (org-get-outline-path))))
  2182. ;; Links are replaced with their description or their path.
  2183. (should
  2184. (equal '("Org")
  2185. (org-test-with-temp-text
  2186. "* [[https://orgmode.org][Org]]\n** S<point>"
  2187. (org-get-outline-path))))
  2188. (should
  2189. (equal '("https://orgmode.org")
  2190. (org-test-with-temp-text
  2191. "* [[https://orgmode.org]]\n** S<point>"
  2192. (org-get-outline-path))))
  2193. ;; When WITH-SELF is non-nil, include current heading.
  2194. (should
  2195. (equal '("H")
  2196. (org-test-with-temp-text "* H"
  2197. (org-get-outline-path t))))
  2198. (should
  2199. (equal '("H" "S")
  2200. (org-test-with-temp-text "* H\n** S\nText<point>"
  2201. (org-get-outline-path t))))
  2202. ;; Using cache is transparent to the user.
  2203. (should
  2204. (equal '("H")
  2205. (org-test-with-temp-text "* H\n** S<point>"
  2206. (setq org-outline-path-cache nil)
  2207. (org-get-outline-path nil t))))
  2208. ;; Do not corrupt cache when finding outline path in distant part of
  2209. ;; the buffer.
  2210. (should
  2211. (equal '("H2")
  2212. (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
  2213. (setq org-outline-path-cache nil)
  2214. (org-get-outline-path nil t)
  2215. (search-forward "S2")
  2216. (org-get-outline-path nil t))))
  2217. ;; Do not choke on empty headlines.
  2218. (should
  2219. (org-test-with-temp-text "* H\n** <point>"
  2220. (org-get-outline-path)))
  2221. (should
  2222. (org-test-with-temp-text "* \n** H<point>"
  2223. (org-get-outline-path))))
  2224. (ert-deftest test-org/format-outline-path ()
  2225. "Test `org-format-outline-path' specifications."
  2226. (should
  2227. (string= (org-format-outline-path (list "one" "two" "three"))
  2228. "one/two/three"))
  2229. ;; Empty path.
  2230. (should
  2231. (string= (org-format-outline-path '())
  2232. ""))
  2233. (should
  2234. (string= (org-format-outline-path '(nil))
  2235. ""))
  2236. ;; Empty path and prefix.
  2237. (should
  2238. (string= (org-format-outline-path '() nil ">>")
  2239. ">>"))
  2240. ;; Trailing whitespace in headings.
  2241. (should
  2242. (string= (org-format-outline-path (list "one\t" "tw o " "three "))
  2243. "one/tw o/three"))
  2244. ;; Non-default prefix and separators.
  2245. (should
  2246. (string= (org-format-outline-path (list "one" "two" "three") nil ">>" "|")
  2247. ">>|one|two|three"))
  2248. ;; Truncate.
  2249. (should
  2250. (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
  2251. "one/two/.."))
  2252. ;; Give a very narrow width.
  2253. (should
  2254. (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
  2255. "on"))
  2256. ;; Give a prefix that extends beyond the width.
  2257. (should
  2258. (string= (org-format-outline-path (list "one" "two" "three" "four") 10
  2259. ">>>>>>>>>>")
  2260. ">>>>>>>>..")))
  2261. (ert-deftest test-org/map-entries ()
  2262. "Test `org-map-entries' specifications."
  2263. ;; Full match.
  2264. (should
  2265. (equal '(1 11)
  2266. (org-test-with-temp-text "* Level 1\n** Level 2"
  2267. (org-map-entries #'point))))
  2268. ;; Level match.
  2269. (should
  2270. (equal '(1)
  2271. (org-test-with-temp-text "* Level 1\n** Level 2"
  2272. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL=1")))))
  2273. (should
  2274. (equal '(11)
  2275. (org-test-with-temp-text "* Level 1\n** Level 2"
  2276. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL>1")))))
  2277. ;; Tag match.
  2278. (should
  2279. (equal '(11)
  2280. (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
  2281. (org-map-entries #'point "yes"))))
  2282. (should
  2283. (equal '(14)
  2284. (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
  2285. (org-map-entries #'point "+yes-a"))))
  2286. (should
  2287. (equal '(11 23)
  2288. (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
  2289. (org-map-entries #'point "{yes?}"))))
  2290. ;; Priority match.
  2291. (should
  2292. (equal '(1)
  2293. (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
  2294. (org-map-entries #'point "PRIORITY=\"A\""))))
  2295. ;; Date match.
  2296. (should
  2297. (equal '(36)
  2298. (org-test-with-temp-text "
  2299. * H1
  2300. SCHEDULED: <2012-03-29 thu.>
  2301. * H2
  2302. SCHEDULED: <2014-03-04 tue.>"
  2303. (org-map-entries #'point "SCHEDULED=\"<2014-03-04 tue.>\""))))
  2304. (should
  2305. (equal '(2)
  2306. (org-test-with-temp-text "
  2307. * H1
  2308. SCHEDULED: <2012-03-29 thu.>
  2309. * H2
  2310. SCHEDULED: <2014-03-04 tue.>"
  2311. (org-map-entries #'point "SCHEDULED<\"<2013-01-01>\""))))
  2312. ;; Regular property match.
  2313. (should
  2314. (equal '(2)
  2315. (org-test-with-temp-text "
  2316. * H1
  2317. :PROPERTIES:
  2318. :TEST: 1
  2319. :END:
  2320. * H2
  2321. :PROPERTIES:
  2322. :TEST: 2
  2323. :END:"
  2324. (org-map-entries #'point "TEST=1"))))
  2325. ;; Multiple criteria.
  2326. (should
  2327. (equal '(23)
  2328. (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
  2329. (let (org-odd-levels-only
  2330. (org-use-tag-inheritance nil))
  2331. (org-map-entries #'point "yes+LEVEL=1")))))
  2332. ;; "or" criteria.
  2333. (should
  2334. (equal '(12 24)
  2335. (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
  2336. (let (org-odd-levels-only)
  2337. (org-map-entries #'point "LEVEL=2|no")))))
  2338. (should
  2339. (equal '(1 12)
  2340. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
  2341. (let (org-odd-levels-only)
  2342. (org-map-entries #'point "yes|no")))))
  2343. ;; "and" criteria.
  2344. (should
  2345. (equal '(22)
  2346. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
  2347. (let (org-odd-levels-only)
  2348. (org-map-entries #'point "yes&no"))))))
  2349. (ert-deftest test-org/edit-headline ()
  2350. "Test `org-edit-headline' specifications."
  2351. (should
  2352. (equal "* B"
  2353. (org-test-with-temp-text "* A"
  2354. (org-edit-headline "B")
  2355. (buffer-string))))
  2356. ;; Handle empty headings.
  2357. (should
  2358. (equal "* "
  2359. (org-test-with-temp-text "* A"
  2360. (org-edit-headline "")
  2361. (buffer-string))))
  2362. (should
  2363. (equal "* A"
  2364. (org-test-with-temp-text "* "
  2365. (org-edit-headline "A")
  2366. (buffer-string))))
  2367. ;; Handle TODO keywords and priority cookies.
  2368. (should
  2369. (equal "* TODO B"
  2370. (org-test-with-temp-text "* TODO A"
  2371. (org-edit-headline "B")
  2372. (buffer-string))))
  2373. (should
  2374. (equal "* [#A] B"
  2375. (org-test-with-temp-text "* [#A] A"
  2376. (org-edit-headline "B")
  2377. (buffer-string))))
  2378. (should
  2379. (equal "* TODO [#A] B"
  2380. (org-test-with-temp-text "* TODO [#A] A"
  2381. (org-edit-headline "B")
  2382. (buffer-string))))
  2383. ;; Handle tags.
  2384. (equal "* B :tag:"
  2385. (org-test-with-temp-text "* A :tag:"
  2386. (let ((org-tags-column 4)) (org-edit-headline "B"))
  2387. (buffer-string))))
  2388. ;;; Keywords
  2389. (ert-deftest test-org/set-regexps-and-options ()
  2390. "Test `org-set-regexps-and-options' specifications."
  2391. ;; TAGS keyword.
  2392. (should
  2393. (equal '(("A"))
  2394. (let ((org-tag-alist '(("A")))
  2395. (org-tag-persistent-alist nil))
  2396. (org-test-with-temp-text ""
  2397. (org-mode-restart)
  2398. org-current-tag-alist))))
  2399. (should
  2400. (equal '(("B"))
  2401. (let ((org-tag-alist '(("A")))
  2402. (org-tag-persistent-alist nil))
  2403. (org-test-with-temp-text "#+TAGS: B"
  2404. (org-mode-restart)
  2405. org-current-tag-alist))))
  2406. (should
  2407. (equal '(("C") ("B"))
  2408. (let ((org-tag-alist '(("A")))
  2409. (org-tag-persistent-alist '(("C"))))
  2410. (org-test-with-temp-text "#+TAGS: B"
  2411. (org-mode-restart)
  2412. org-current-tag-alist))))
  2413. (should
  2414. (equal '(("B"))
  2415. (let ((org-tag-alist '(("A")))
  2416. (org-tag-persistent-alist '(("C"))))
  2417. (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
  2418. (org-mode-restart)
  2419. org-current-tag-alist))))
  2420. (should
  2421. (equal '(("A" . ?a) ("B") ("C"))
  2422. (let ((org-tag-persistant-alist nil))
  2423. (org-test-with-temp-text "#+TAGS: A(a) B C"
  2424. (org-mode-restart)
  2425. org-current-tag-alist))))
  2426. (should
  2427. (equal '(("A") (:newline) ("B"))
  2428. (let ((org-tag-persistent-alist nil))
  2429. (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
  2430. (org-mode-restart)
  2431. org-current-tag-alist))))
  2432. (should
  2433. (equal '((:startgroup) ("A") ("B") (:endgroup) ("C"))
  2434. (let ((org-tag-persistent-alist nil))
  2435. (org-test-with-temp-text "#+TAGS: { A B } C"
  2436. (org-mode-restart)
  2437. org-current-tag-alist))))
  2438. (should
  2439. (equal '((:startgroup) ("A") (:grouptags) ("B") ("C") (:endgroup))
  2440. (let ((org-tag-persistent-alist nil))
  2441. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2442. (org-mode-restart)
  2443. org-current-tag-alist))))
  2444. (should
  2445. (equal '(("A" "B" "C"))
  2446. (let ((org-tag-persistent-alist nil))
  2447. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2448. (org-mode-restart)
  2449. org-tag-groups-alist))))
  2450. (should
  2451. (equal '((:startgrouptag) ("A") (:grouptags) ("B") ("C") (:endgrouptag))
  2452. (let ((org-tag-persistent-alist nil))
  2453. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2454. (org-mode-restart)
  2455. org-current-tag-alist))))
  2456. (should
  2457. (equal '(("A" "B" "C"))
  2458. (let ((org-tag-persistent-alist nil))
  2459. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2460. (org-mode-restart)
  2461. org-tag-groups-alist))))
  2462. (should-not
  2463. (let ((org-tag-alist '(("A"))))
  2464. (org-test-with-temp-text "#+TAGS:"
  2465. (org-mode-restart)
  2466. org-current-tag-alist)))
  2467. ;; FILETAGS keyword.
  2468. (should
  2469. (equal '("A" "B" "C")
  2470. (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
  2471. (org-mode-restart)
  2472. org-file-tags)))
  2473. ;; PROPERTY keyword. Property names are case-insensitive.
  2474. (should
  2475. (equal "foo=1"
  2476. (org-test-with-temp-text "#+PROPERTY: var foo=1"
  2477. (org-mode-restart)
  2478. (cdr (assoc "var" org-keyword-properties)))))
  2479. (should
  2480. (equal
  2481. "foo=1 bar=2"
  2482. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
  2483. (org-mode-restart)
  2484. (cdr (assoc "var" org-keyword-properties)))))
  2485. (should
  2486. (equal
  2487. "foo=1 bar=2"
  2488. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
  2489. (org-mode-restart)
  2490. (cdr (assoc "var" org-keyword-properties)))))
  2491. ;; ARCHIVE keyword.
  2492. (should
  2493. (equal "%s_done::"
  2494. (org-test-with-temp-text "#+ARCHIVE: %s_done::"
  2495. (org-mode-restart)
  2496. org-archive-location)))
  2497. ;; CATEGORY keyword.
  2498. (should
  2499. (eq 'test
  2500. (org-test-with-temp-text "#+CATEGORY: test"
  2501. (org-mode-restart)
  2502. org-category)))
  2503. (should
  2504. (equal "test"
  2505. (org-test-with-temp-text "#+CATEGORY: test"
  2506. (org-mode-restart)
  2507. (cdr (assoc "CATEGORY" org-keyword-properties)))))
  2508. ;; COLUMNS keyword.
  2509. (should
  2510. (equal "%25ITEM %TAGS %PRIORITY %TODO"
  2511. (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
  2512. (org-mode-restart)
  2513. org-columns-default-format)))
  2514. ;; CONSTANTS keyword. Constants names are case sensitive.
  2515. (should
  2516. (equal '("299792458." "3.14")
  2517. (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
  2518. (org-mode-restart)
  2519. (mapcar
  2520. (lambda (n) (cdr (assoc n org-table-formula-constants-local)))
  2521. '("c" "pi")))))
  2522. (should
  2523. (equal "3.14"
  2524. (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
  2525. (org-mode-restart)
  2526. (cdr (assoc "pi" org-table-formula-constants-local)))))
  2527. (should
  2528. (equal "22/7"
  2529. (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
  2530. (org-mode-restart)
  2531. (cdr (assoc "PI" org-table-formula-constants-local)))))
  2532. ;; LINK keyword.
  2533. (should
  2534. (equal
  2535. '("url1" "url2")
  2536. (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
  2537. (org-mode-restart)
  2538. (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local)))
  2539. '("a" "b")))))
  2540. ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
  2541. (should
  2542. (equal
  2543. '(?X ?Z ?Y)
  2544. (org-test-with-temp-text "#+PRIORITIES: X Z Y"
  2545. (org-mode-restart)
  2546. (list org-priority-highest org-priority-lowest org-priority-default))))
  2547. (should
  2548. (equal
  2549. '(?A ?C ?B)
  2550. (org-test-with-temp-text "#+PRIORITIES: X Z"
  2551. (org-mode-restart)
  2552. (list org-priority-highest org-priority-lowest org-priority-default))))
  2553. ;; STARTUP keyword.
  2554. (should
  2555. (equal '(t t)
  2556. (org-test-with-temp-text "#+STARTUP: fold odd"
  2557. (org-mode-restart)
  2558. (list org-startup-folded org-odd-levels-only))))
  2559. ;; TODO keywords.
  2560. (should
  2561. (equal '(("A" "B") ("C"))
  2562. (org-test-with-temp-text "#+TODO: A B | C"
  2563. (org-mode-restart)
  2564. (list org-not-done-keywords org-done-keywords))))
  2565. (should
  2566. (equal '(("A" "C") ("B" "D"))
  2567. (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
  2568. (org-mode-restart)
  2569. (list org-not-done-keywords org-done-keywords))))
  2570. (should
  2571. (equal '(("A" "B") ("C"))
  2572. (org-test-with-temp-text "#+TYP_TODO: A B | C"
  2573. (org-mode-restart)
  2574. (list org-not-done-keywords org-done-keywords))))
  2575. (should
  2576. (equal '((:startgroup) ("A" . ?a) (:endgroup))
  2577. (org-test-with-temp-text "#+TODO: A(a)"
  2578. (org-mode-restart)
  2579. org-todo-key-alist)))
  2580. (should
  2581. (equal '(("D" note nil) ("C" time nil) ("B" note time))
  2582. (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
  2583. (org-mode-restart)
  2584. org-todo-log-states)))
  2585. ;; Enter SETUPFILE keyword.
  2586. (should
  2587. (equal "1"
  2588. (org-test-with-temp-text
  2589. (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
  2590. (org-mode-restart)
  2591. (cdr (assoc "a" org-keyword-properties))))))
  2592. (ert-deftest test-org/collect-keywords ()
  2593. "Test `org-collect-keywords'."
  2594. (should-not
  2595. (org-test-with-temp-text "#+begin_example\n#+foo: bar\n#+end_example"
  2596. (org-collect-keywords '("FOO")))))
  2597. ;;; Links
  2598. ;;;; Coderefs
  2599. (ert-deftest test-org/coderef ()
  2600. "Test coderef links specifications."
  2601. (should
  2602. (org-test-with-temp-text "
  2603. #+BEGIN_SRC emacs-lisp
  2604. \(+ 1 1) (ref:sc)
  2605. #+END_SRC
  2606. \[[(sc)<point>]]"
  2607. (org-open-at-point)
  2608. (looking-at "(ref:sc)")))
  2609. ;; Find coderef even with alternate label format.
  2610. (should
  2611. (org-test-with-temp-text "
  2612. #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
  2613. \(+ 1 1) {ref:sc}
  2614. #+END_SRC
  2615. \[[(sc)<point>]]"
  2616. (org-open-at-point)
  2617. (looking-at "{ref:sc}"))))
  2618. ;;;; Custom ID
  2619. (ert-deftest test-org/custom-id ()
  2620. "Test custom ID links specifications."
  2621. (should
  2622. (org-test-with-temp-text
  2623. "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2624. (org-open-at-point)
  2625. (looking-at-p "\\* H1")))
  2626. ;; Handle escape characters.
  2627. (should
  2628. (org-test-with-temp-text
  2629. "* H1\n:PROPERTIES:\n:CUSTOM_ID: [%]\n:END:\n* H2\n[[#\\[%\\]<point>]]"
  2630. (org-open-at-point)
  2631. (looking-at-p "\\* H1")))
  2632. ;; Throw an error on false positives.
  2633. (should-error
  2634. (org-test-with-temp-text
  2635. "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2636. (org-open-at-point)
  2637. (looking-at-p "\\* H1"))))
  2638. ;;;; Fuzzy Links
  2639. ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
  2640. ;; a named element (#+name: text) and to headlines (* Text).
  2641. (ert-deftest test-org/fuzzy-links ()
  2642. "Test fuzzy links specifications."
  2643. ;; Fuzzy link goes in priority to a matching target.
  2644. (should
  2645. (org-test-with-temp-text
  2646. "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
  2647. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2648. (looking-at "<<Test>>")))
  2649. ;; Then fuzzy link points to an element with a given name.
  2650. (should
  2651. (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
  2652. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2653. (looking-at "#\\+NAME: Test")))
  2654. ;; A target still lead to a matching headline otherwise.
  2655. (should
  2656. (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
  2657. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2658. (looking-at "\\* Head2")))
  2659. ;; With a leading star in link, enforce heading match.
  2660. (should
  2661. (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
  2662. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2663. (looking-at "\\* Test")))
  2664. ;; With a leading star in link, enforce exact heading match, even
  2665. ;; with `org-link-search-must-match-exact-headline' set to nil.
  2666. (should-error
  2667. (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
  2668. (let ((org-link-search-must-match-exact-headline nil))
  2669. (org-open-at-point))))
  2670. ;; Handle non-nil `org-link-search-must-match-exact-headline'.
  2671. (should
  2672. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
  2673. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2674. (looking-at "\\* Test")))
  2675. (should
  2676. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
  2677. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2678. (looking-at "\\* Test")))
  2679. ;; Heading match should not care about spaces, cookies, TODO
  2680. ;; keywords, priorities, and tags. However, TODO keywords are
  2681. ;; case-sensitive.
  2682. (should
  2683. (let ((first-line
  2684. "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
  2685. (org-test-with-temp-text
  2686. (concat first-line "\nFoo Bar\n<point>[[*Test 1 2]]")
  2687. (let ((org-link-search-must-match-exact-headline nil)
  2688. (org-todo-regexp "TODO"))
  2689. (org-open-at-point))
  2690. (looking-at (regexp-quote first-line)))))
  2691. (should-error
  2692. (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
  2693. (let ((org-link-search-must-match-exact-headline nil)
  2694. (org-todo-regexp "TODO"))
  2695. (org-open-at-point))))
  2696. ;; Heading match should still be exact.
  2697. (should-error
  2698. (org-test-with-temp-text "
  2699. ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
  2700. Foo Bar
  2701. <point>[[*Test 1]]"
  2702. (let ((org-link-search-must-match-exact-headline nil)
  2703. (org-todo-regexp "TODO"))
  2704. (org-open-at-point))))
  2705. (should
  2706. (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
  2707. (let ((org-link-search-must-match-exact-headline nil)
  2708. (org-todo-regexp "TODO"))
  2709. (org-open-at-point))
  2710. (looking-at-p (regexp-quote "** Test 1 2"))))
  2711. ;; Heading match ignores COMMENT keyword.
  2712. (should
  2713. (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
  2714. (org-open-at-point)
  2715. (looking-at "\\* COMMENT Test")))
  2716. (should
  2717. (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
  2718. (org-open-at-point)
  2719. (looking-at "\\* TODO COMMENT Test")))
  2720. ;; Correctly un-escape fuzzy links.
  2721. (should
  2722. (org-test-with-temp-text "* [foo]\n[[*\\[foo\\]][With escaped characters]]"
  2723. (org-open-at-point)
  2724. (bobp)))
  2725. ;; Match search strings containing newline characters, including
  2726. ;; blank lines.
  2727. (should
  2728. (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
  2729. (let ((file (buffer-file-name)))
  2730. (goto-char (point-max))
  2731. (insert (format "[[file:%s::line1 line2]]" file))
  2732. (beginning-of-line)
  2733. (let ((org-link-search-must-match-exact-headline nil))
  2734. (org-open-at-point 0))
  2735. (looking-at-p "line1"))))
  2736. (should
  2737. (org-test-with-temp-text-in-file "Paragraph\n\nline1\n\nline2\n\n"
  2738. (let ((file (buffer-file-name)))
  2739. (goto-char (point-max))
  2740. (insert (format "[[file:%s::line1 line2]]" file))
  2741. (beginning-of-line)
  2742. (let ((org-link-search-must-match-exact-headline nil))
  2743. (org-open-at-point 0))
  2744. (looking-at-p "line1")))))
  2745. ;;;; Open at point
  2746. (ert-deftest test-org/open-at-point/keyword ()
  2747. "Does `org-open-at-point' open link in a keyword line?"
  2748. (should
  2749. (org-test-with-temp-text
  2750. "<<top>>\n#+KEYWORD: <point>[[top]]"
  2751. (org-open-at-point) t))
  2752. (should
  2753. (org-test-with-temp-text
  2754. "* H\n<<top>>\n#+KEYWORD: <point>[[top]]"
  2755. (org-open-at-point) t)))
  2756. (ert-deftest test-org/open-at-point/property ()
  2757. "Does `org-open-at-point' open link in property drawer?"
  2758. (should
  2759. (org-test-with-temp-text
  2760. "* Headline
  2761. :PROPERTIES:
  2762. :URL: <point>[[*Headline]]
  2763. :END:"
  2764. (org-open-at-point) t)))
  2765. (ert-deftest test-org/open-at-point/comment ()
  2766. "Does `org-open-at-point' open link in a commented line?"
  2767. (should
  2768. (org-test-with-temp-text
  2769. "<<top>>\n# <point>[[top]]"
  2770. (org-open-at-point) t))
  2771. (should
  2772. (org-test-with-temp-text
  2773. "* H\n<<top>>\n# <point>[[top]]"
  2774. (org-open-at-point) t)))
  2775. (ert-deftest test-org/open-at-point/inline-image ()
  2776. "Test `org-open-at-point' on nested links."
  2777. (should
  2778. (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
  2779. (org-open-at-point)
  2780. (bobp))))
  2781. (ert-deftest test-org/open-at-point/radio-target ()
  2782. "Test `org-open-at-point' on radio targets."
  2783. (should
  2784. (org-test-with-temp-text "<<<target>>> <point>target"
  2785. (org-update-radio-target-regexp)
  2786. (org-open-at-point)
  2787. (eq (org-element-type (org-element-context)) 'radio-target))))
  2788. (ert-deftest test-org/open-at-point/tag ()
  2789. "Test `org-open-at-point' on tags."
  2790. (should
  2791. (org-test-with-temp-text "* H :<point>tag:"
  2792. (catch :result
  2793. (cl-letf (((symbol-function 'org-tags-view)
  2794. (lambda (&rest args) (throw :result t))))
  2795. (org-open-at-point)
  2796. nil))))
  2797. (should-not
  2798. (org-test-with-temp-text-in-file "* H<point> :tag:"
  2799. (catch :result
  2800. (cl-letf (((symbol-function 'org-tags-view)
  2801. (lambda (&rest args) (throw :result t))))
  2802. ;; When point isn't on a tag it's going to try other things,
  2803. ;; possibly trying to open attachments which will return an
  2804. ;; error if there isn't an attachment. Suppress that error.
  2805. (ignore-errors
  2806. (org-open-at-point))
  2807. nil)))))
  2808. ;;; Node Properties
  2809. (ert-deftest test-org/accumulated-properties-in-drawers ()
  2810. "Ensure properties accumulate in subtree drawers."
  2811. (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
  2812. (org-babel-next-src-block)
  2813. (should (equal '(2 1) (org-babel-execute-src-block)))))
  2814. (ert-deftest test-org/custom-properties ()
  2815. "Test custom properties specifications."
  2816. ;; Standard test.
  2817. (should
  2818. (let ((org-custom-properties '("FOO")))
  2819. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2820. (org-toggle-custom-properties-visibility)
  2821. (org-invisible-p2))))
  2822. ;; Properties are case-insensitive.
  2823. (should
  2824. (let ((org-custom-properties '("FOO")))
  2825. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
  2826. (org-toggle-custom-properties-visibility)
  2827. (org-invisible-p2))))
  2828. (should
  2829. (let ((org-custom-properties '("foo")))
  2830. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2831. (org-toggle-custom-properties-visibility)
  2832. (org-invisible-p2))))
  2833. ;; Multiple custom properties in the same drawer.
  2834. (should
  2835. (let ((org-custom-properties '("FOO" "BAR")))
  2836. (org-test-with-temp-text
  2837. "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
  2838. (org-toggle-custom-properties-visibility)
  2839. (and (org-invisible-p2)
  2840. (not (progn (forward-line) (org-invisible-p2)))
  2841. (progn (forward-line) (org-invisible-p2))))))
  2842. ;; Hide custom properties with an empty value.
  2843. (should
  2844. (let ((org-custom-properties '("FOO")))
  2845. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
  2846. (org-toggle-custom-properties-visibility)
  2847. (org-invisible-p2))))
  2848. ;; Do not hide fake properties.
  2849. (should-not
  2850. (let ((org-custom-properties '("FOO")))
  2851. (org-test-with-temp-text ":FOO: val\n"
  2852. (org-toggle-custom-properties-visibility)
  2853. (org-invisible-p2))))
  2854. (should-not
  2855. (let ((org-custom-properties '("A")))
  2856. (org-test-with-temp-text
  2857. "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
  2858. (org-toggle-custom-properties-visibility)
  2859. (org-invisible-p2)))))
  2860. ;;; Mark Region
  2861. (ert-deftest test-org/mark-element ()
  2862. "Test `org-mark-element' specifications."
  2863. ;; Mark beginning and end of element.
  2864. (should
  2865. (equal '(t t)
  2866. (org-test-with-temp-text "Para<point>graph"
  2867. (org-mark-element)
  2868. (list (bobp) (= (mark) (point-max))))))
  2869. (should
  2870. (equal '(t t)
  2871. (org-test-with-temp-text "P1\n\nPara<point>graph\n\nP2"
  2872. (org-mark-element)
  2873. (list (looking-at "Paragraph")
  2874. (org-with-point-at (mark) (looking-at "P2"))))))
  2875. ;; Do not set mark past (point-max).
  2876. (should
  2877. (org-test-with-temp-text "Para<point>graph"
  2878. (narrow-to-region 2 6)
  2879. (org-mark-element)
  2880. (= 6 (mark)))))
  2881. (ert-deftest test-org/mark-subtree ()
  2882. "Test `org-mark-subtree' specifications."
  2883. ;; Error when point is before first headline.
  2884. (should-error
  2885. (org-test-with-temp-text "Paragraph\n* Headline\nBody"
  2886. (progn (transient-mark-mode 1)
  2887. (org-mark-subtree))))
  2888. ;; Without argument, mark current subtree.
  2889. (should
  2890. (equal
  2891. '(12 32)
  2892. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  2893. (progn (transient-mark-mode 1)
  2894. (forward-line 2)
  2895. (org-mark-subtree)
  2896. (list (region-beginning) (region-end))))))
  2897. ;; With an argument, move ARG up.
  2898. (should
  2899. (equal
  2900. '(1 32)
  2901. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  2902. (progn (transient-mark-mode 1)
  2903. (forward-line 2)
  2904. (org-mark-subtree 1)
  2905. (list (region-beginning) (region-end))))))
  2906. ;; Do not get fooled by inlinetasks.
  2907. (when (featurep 'org-inlinetask)
  2908. (should
  2909. (= 1
  2910. (org-test-with-temp-text "* Headline\n*************** Task\nContents"
  2911. (progn (transient-mark-mode 1)
  2912. (forward-line 1)
  2913. (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
  2914. (region-beginning)))))))
  2915. ;;; Miscellaneous
  2916. (ert-deftest test-org/sort-entries ()
  2917. "Test `org-sort-entries'."
  2918. ;; Sort alphabetically.
  2919. (should
  2920. (equal "\n* abc\n* def\n* xyz\n"
  2921. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  2922. (org-sort-entries nil ?a)
  2923. (buffer-string))))
  2924. (should
  2925. (equal "\n* xyz\n* def\n* abc\n"
  2926. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  2927. (org-sort-entries nil ?A)
  2928. (buffer-string))))
  2929. (should
  2930. (equal "\n* \n* klm\n* xyz\n"
  2931. (org-test-with-temp-text "\n* xyz\n* \n* klm\n"
  2932. (org-sort-entries nil ?a)
  2933. (buffer-string))))
  2934. ;; Sort numerically.
  2935. (should
  2936. (equal "\n* 1\n* 2\n* 10\n"
  2937. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  2938. (org-sort-entries nil ?n)
  2939. (buffer-string))))
  2940. (should
  2941. (equal "\n* 10\n* 2\n* 1\n"
  2942. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  2943. (org-sort-entries nil ?N)
  2944. (buffer-string))))
  2945. (should
  2946. (equal "\n* \n* 1\n* 2\n"
  2947. (org-test-with-temp-text "\n* 1\n* \n* 2\n"
  2948. (org-sort-entries nil ?n)
  2949. (buffer-string))))
  2950. ;; Sort by custom function.
  2951. (should
  2952. (equal "\n* b\n* aa\n* ccc\n"
  2953. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  2954. (org-sort-entries nil ?f
  2955. (lambda ()
  2956. (length (buffer-substring (point-at-bol)
  2957. (point-at-eol))))
  2958. #'<)
  2959. (buffer-string))))
  2960. (should
  2961. (equal "\n* ccc\n* aa\n* b\n"
  2962. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  2963. (org-sort-entries nil ?F
  2964. (lambda ()
  2965. (length (buffer-substring (point-at-bol)
  2966. (point-at-eol))))
  2967. #'<)
  2968. (buffer-string))))
  2969. ;; Sort by TODO keyword.
  2970. (should
  2971. (equal "\n* TODO h1\n* TODO h3\n* DONE h2\n"
  2972. (org-test-with-temp-text
  2973. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  2974. (org-sort-entries nil ?o)
  2975. (buffer-string))))
  2976. (should
  2977. (equal "\n* DONE h2\n* TODO h1\n* TODO h3\n"
  2978. (org-test-with-temp-text
  2979. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  2980. (org-sort-entries nil ?O)
  2981. (buffer-string))))
  2982. ;; Sort by priority.
  2983. (should
  2984. (equal "\n* [#A] h2\n* [#B] h3\n* [#C] h1\n"
  2985. (org-test-with-temp-text
  2986. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  2987. (org-sort-entries nil ?p)
  2988. (buffer-string))))
  2989. (should
  2990. (equal "\n* [#C] h1\n* [#B] h3\n* [#A] h2\n"
  2991. (org-test-with-temp-text
  2992. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  2993. (org-sort-entries nil ?P)
  2994. (buffer-string))))
  2995. ;; Sort by creation time.
  2996. (should
  2997. (equal "
  2998. * h3
  2999. [2017-05-08 Mon]
  3000. * h2
  3001. [2017-05-09 Tue]
  3002. * h1
  3003. [2018-05-09 Wed]
  3004. "
  3005. (org-test-with-temp-text
  3006. "
  3007. * h1
  3008. [2018-05-09 Wed]
  3009. * h2
  3010. [2017-05-09 Tue]
  3011. * h3
  3012. [2017-05-08 Mon]
  3013. "
  3014. (org-sort-entries nil ?c)
  3015. (buffer-string))))
  3016. ;; Sort by scheduled date.
  3017. (should
  3018. (equal "
  3019. * TODO h4
  3020. SCHEDULED: <2017-05-06 Sat>
  3021. * TODO h3
  3022. SCHEDULED: <2017-05-08 Mon>
  3023. * TODO h2
  3024. DEADLINE: <2017-05-09 Tue>
  3025. * TODO h1
  3026. DEADLINE: <2017-05-07 Sun>
  3027. "
  3028. (org-test-with-temp-text
  3029. "
  3030. * TODO h2
  3031. DEADLINE: <2017-05-09 Tue>
  3032. * TODO h1
  3033. DEADLINE: <2017-05-07 Sun>
  3034. * TODO h3
  3035. SCHEDULED: <2017-05-08 Mon>
  3036. * TODO h4
  3037. SCHEDULED: <2017-05-06 Sat>
  3038. "
  3039. (org-sort-entries nil ?s)
  3040. (buffer-string))))
  3041. ;; Sort by deadline date.
  3042. (should
  3043. (equal "
  3044. * TODO h1
  3045. DEADLINE: <2017-05-07 Sun>
  3046. * TODO h2
  3047. DEADLINE: <2017-05-09 Tue>
  3048. * TODO h3
  3049. SCHEDULED: <2017-05-08 Mon>
  3050. * TODO h4
  3051. SCHEDULED: <2017-05-06 Sat>
  3052. "
  3053. (org-test-with-temp-text
  3054. "
  3055. * TODO h2
  3056. DEADLINE: <2017-05-09 Tue>
  3057. * TODO h1
  3058. DEADLINE: <2017-05-07 Sun>
  3059. * TODO h3
  3060. SCHEDULED: <2017-05-08 Mon>
  3061. * TODO h4
  3062. SCHEDULED: <2017-05-06 Sat>
  3063. "
  3064. (org-sort-entries nil ?d)
  3065. (buffer-string))))
  3066. ;; Sort by any date/time
  3067. (should
  3068. (equal "
  3069. * TODO h4
  3070. SCHEDULED: <2017-05-06 Sat>
  3071. * TODO h1
  3072. DEADLINE: <2017-05-07 Sun>
  3073. * TODO h3
  3074. SCHEDULED: <2017-05-08 Mon>
  3075. * TODO h2
  3076. DEADLINE: <2017-05-09 Tue>
  3077. "
  3078. (org-test-with-temp-text
  3079. "
  3080. * TODO h2
  3081. DEADLINE: <2017-05-09 Tue>
  3082. * TODO h1
  3083. DEADLINE: <2017-05-07 Sun>
  3084. * TODO h3
  3085. SCHEDULED: <2017-05-08 Mon>
  3086. * TODO h4
  3087. SCHEDULED: <2017-05-06 Sat>
  3088. "
  3089. (org-sort-entries nil ?t)
  3090. (buffer-string))))
  3091. ;; Sort by clocking time.
  3092. (should
  3093. (equal "
  3094. * clocked h2
  3095. :LOGBOOK:
  3096. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3097. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  3098. :END:
  3099. * clocked h1
  3100. :LOGBOOK:
  3101. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3102. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  3103. :END:
  3104. "
  3105. (org-test-with-temp-text
  3106. "
  3107. * clocked h1
  3108. :LOGBOOK:
  3109. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3110. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  3111. :END:
  3112. * clocked h2
  3113. :LOGBOOK:
  3114. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3115. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  3116. :END:
  3117. "
  3118. (org-sort-entries nil ?k)
  3119. (buffer-string))))
  3120. ;; Preserve file local variables when sorting.
  3121. (should
  3122. (equal "\n* A\n* B\n# Local Variables:\n# foo: t\n# End:\n"
  3123. (org-test-with-temp-text
  3124. "\n* B\n* A\n# Local Variables:\n# foo: t\n# End:"
  3125. (org-sort-entries nil ?a)
  3126. (buffer-string)))))
  3127. (ert-deftest test-org/string-collate-greaterp ()
  3128. "Test `org-string-collate-greaterp' specifications."
  3129. (should (org-string-collate-greaterp "def" "abc"))
  3130. (should-not (org-string-collate-greaterp "abc" "def")))
  3131. (ert-deftest test-org/file-contents ()
  3132. "Test `org-file-contents' specifications."
  3133. ;; Open files.
  3134. (should
  3135. (string= "#+BIND: variable value
  3136. #+DESCRIPTION: l2
  3137. #+LANGUAGE: en
  3138. #+SELECT_TAGS: b
  3139. #+TITLE: b
  3140. #+PROPERTY: a 1
  3141. " (org-file-contents (expand-file-name "setupfile3.org"
  3142. (concat org-test-dir "examples/")))))
  3143. ;; Throw error when trying to access an invalid file.
  3144. (should-error (org-file-contents "this-file-must-not-exist"))
  3145. ;; Try to access an invalid file, but do not throw an error.
  3146. (should
  3147. (progn (org-file-contents "this-file-must-not-exist" :noerror) t))
  3148. ;; Open URL.
  3149. (should
  3150. (string= "foo"
  3151. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3152. (unwind-protect
  3153. ;; Simulate successful retrieval of a URL.
  3154. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3155. (lambda (&rest_)
  3156. (with-current-buffer buffer
  3157. (insert "HTTP/1.1 200 OK\n\nfoo"))
  3158. buffer)))
  3159. (org-file-contents "http://some-valid-url"))
  3160. (kill-buffer buffer)))))
  3161. ;; Throw error when trying to access an invalid URL.
  3162. (should-error
  3163. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3164. (unwind-protect
  3165. ;; Simulate unsuccessful retrieval of a URL.
  3166. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3167. (lambda (&rest_)
  3168. (with-current-buffer buffer
  3169. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3170. buffer)))
  3171. (org-file-contents "http://this-url-must-not-exist"))
  3172. (kill-buffer buffer))))
  3173. ;; Try to access an invalid URL, but do not throw an error.
  3174. (should-error
  3175. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3176. (unwind-protect
  3177. ;; Simulate unsuccessful retrieval of a URL.
  3178. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3179. (lambda (&rest_)
  3180. (with-current-buffer buffer
  3181. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3182. buffer)))
  3183. (org-file-contents "http://this-url-must-not-exist"))
  3184. (kill-buffer buffer))))
  3185. (should
  3186. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3187. (unwind-protect
  3188. ;; Simulate unsuccessful retrieval of a URL.
  3189. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3190. (lambda (&rest_)
  3191. (with-current-buffer buffer
  3192. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3193. buffer)))
  3194. (org-file-contents "http://this-url-must-not-exist" :noerror))
  3195. (kill-buffer buffer))
  3196. t)))
  3197. ;;; Navigation
  3198. (ert-deftest test-org/next-visible-heading ()
  3199. "Test `org-next-visible-heading' specifications."
  3200. ;; Move to the beginning of the next headline, taking into
  3201. ;; consideration ARG.
  3202. (should
  3203. (org-test-with-temp-text "* H1\n* H2"
  3204. (org-next-visible-heading 1)
  3205. (looking-at "\\* H2")))
  3206. (should
  3207. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3208. (org-next-visible-heading 2)
  3209. (looking-at "\\* H3")))
  3210. ;; Ignore invisible headlines.
  3211. (should
  3212. (org-test-with-temp-text "* H1\n** H2\n* H3"
  3213. (org-cycle)
  3214. (org-next-visible-heading 1)
  3215. (looking-at "\\* H3")))
  3216. ;; Move point between headlines, not on blank lines between.
  3217. (should
  3218. (org-test-with-temp-text "* H1\n** H2\n\n\n\n* H3"
  3219. (let ((org-cycle-separator-lines 1))
  3220. (org-cycle)
  3221. (org-next-visible-heading 1))
  3222. (looking-at "\\* H3")))
  3223. ;; Move at end of buffer when there is no more headline.
  3224. (should
  3225. (org-test-with-temp-text "* H1"
  3226. (org-next-visible-heading 1)
  3227. (eobp)))
  3228. (should
  3229. (org-test-with-temp-text "* H1\n* H2"
  3230. (org-next-visible-heading 2)
  3231. (eobp)))
  3232. ;; With a negative argument, move backwards.
  3233. (should
  3234. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3235. (org-next-visible-heading -1)
  3236. (looking-at "\\* H2")))
  3237. (should
  3238. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3239. (org-next-visible-heading -2)
  3240. (looking-at "\\* H1"))))
  3241. (ert-deftest test-org/previous-visible-heading ()
  3242. "Test `org-previous-visible-heading' specifications."
  3243. ;; Move to the beginning of the next headline, taking into
  3244. ;; consideration ARG.
  3245. (should
  3246. (org-test-with-temp-text "* H1\n<point>* H2"
  3247. (org-previous-visible-heading 1)
  3248. (looking-at "\\* H1")))
  3249. (should
  3250. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3251. (org-previous-visible-heading 2)
  3252. (looking-at "\\* H1")))
  3253. ;; Ignore invisible headlines.
  3254. (should
  3255. (org-test-with-temp-text "* H1\n** H2\n<point>* H3"
  3256. (org-overview)
  3257. (org-previous-visible-heading 1)
  3258. (looking-at "\\* H1")))
  3259. ;; Move point between headlines, not on blank lines between.
  3260. (should
  3261. (org-test-with-temp-text "* H1\n\n\n\n** H2\n<point>* H3"
  3262. (let ((org-cycle-separator-lines 1))
  3263. (org-overview)
  3264. (org-previous-visible-heading 1))
  3265. (looking-at "\\* H1")))
  3266. ;; Move at end of buffer when there is no more headline.
  3267. (should
  3268. (org-test-with-temp-text "* H1"
  3269. (org-previous-visible-heading 1)
  3270. (bobp)))
  3271. (should
  3272. (org-test-with-temp-text "* H1\n* <point>H2"
  3273. (org-previous-visible-heading 2)
  3274. (bobp)))
  3275. ;; Invisible parts may not start at a headline, i.e., when revealing
  3276. ;; parts of the buffer. Handle this.
  3277. (should
  3278. (org-test-with-temp-text "* Main\n** H1\nFoo\n** H2\nBar\n** H3\nBaz"
  3279. (org-overview)
  3280. (search-forward "H1")
  3281. (org-show-context 'minimal)
  3282. (org-cycle)
  3283. (search-forward "H3")
  3284. (org-show-context 'minimal)
  3285. ;; At this point, buffer displays, with point at "|",
  3286. ;;
  3287. ;; * Main
  3288. ;; ** H1
  3289. ;; Foo
  3290. ;; ** H3|
  3291. (org-previous-visible-heading 1)
  3292. (looking-at "\\*+ H1"))))
  3293. (ert-deftest test-org/forward-heading-same-level ()
  3294. "Test `org-forward-heading-same-level' specifications."
  3295. ;; Test navigation at top level, forward and backward.
  3296. (should
  3297. (equal "* H2"
  3298. (org-test-with-temp-text "* H1\n* H2"
  3299. (org-forward-heading-same-level 1)
  3300. (buffer-substring-no-properties (point) (line-end-position)))))
  3301. (should
  3302. (equal "* H1"
  3303. (org-test-with-temp-text "* H1\n<point>* H2"
  3304. (org-forward-heading-same-level -1)
  3305. (buffer-substring-no-properties (point) (line-end-position)))))
  3306. ;; Test navigation in a sub-tree, forward and backward.
  3307. (should
  3308. (equal "* H2"
  3309. (org-test-with-temp-text "* H1\n** H11\n** H12\n* H2"
  3310. (org-forward-heading-same-level 1)
  3311. (buffer-substring-no-properties (point) (line-end-position)))))
  3312. (should
  3313. (equal "* H1"
  3314. (org-test-with-temp-text "* H1\n** H11\n** H12\n<point>* H2"
  3315. (org-forward-heading-same-level -1)
  3316. (buffer-substring-no-properties (point) (line-end-position)))))
  3317. ;; Stop at first or last sub-heading.
  3318. (should-not
  3319. (equal "* H2"
  3320. (org-test-with-temp-text "* H1\n** H11\n<point>** H12\n* H2"
  3321. (org-forward-heading-same-level 1)
  3322. (buffer-substring-no-properties (point) (line-end-position)))))
  3323. (should-not
  3324. (equal "* H2"
  3325. (org-test-with-temp-text "* H1\n<point>** H11\n** H12\n* H2"
  3326. (org-forward-heading-same-level -1)
  3327. (buffer-substring-no-properties (point) (line-end-position)))))
  3328. ;; Allow multiple moves.
  3329. (should
  3330. (equal "* H3"
  3331. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3332. (org-forward-heading-same-level 2)
  3333. (buffer-substring-no-properties (point) (line-end-position)))))
  3334. (should
  3335. (equal "* H1"
  3336. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3337. (org-forward-heading-same-level -2)
  3338. (buffer-substring-no-properties (point) (line-end-position)))))
  3339. ;; Ignore spurious moves when first (or last) sibling is reached.
  3340. (should
  3341. (equal "** H3"
  3342. (org-test-with-temp-text "* First\n<point>** H1\n** H2\n** H3\n* Last"
  3343. (org-forward-heading-same-level 100)
  3344. (buffer-substring-no-properties (point) (line-end-position)))))
  3345. (should
  3346. (equal "** H1"
  3347. (org-test-with-temp-text "* First\n** H1\n** H2\n<point>** H3\n* Last"
  3348. (org-forward-heading-same-level -100)
  3349. (buffer-substring-no-properties (point) (line-end-position))))))
  3350. (ert-deftest test-org/end-of-meta-data ()
  3351. "Test `org-end-of-meta-data' specifications."
  3352. ;; Skip planning line.
  3353. (should
  3354. (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
  3355. (org-end-of-meta-data)
  3356. (eobp)))
  3357. ;; Skip properties drawer.
  3358. (should
  3359. (org-test-with-temp-text
  3360. "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
  3361. (org-end-of-meta-data)
  3362. (eobp)))
  3363. ;; Skip both.
  3364. (should
  3365. (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
  3366. (org-end-of-meta-data)
  3367. (eobp)))
  3368. ;; Nothing to skip, go to first line.
  3369. (should
  3370. (org-test-with-temp-text "* Headline\nContents"
  3371. (org-end-of-meta-data)
  3372. (looking-at "Contents")))
  3373. ;; With option argument, skip empty lines, regular drawers and
  3374. ;; clocking lines.
  3375. (should
  3376. (org-test-with-temp-text "* Headline\n\nContents"
  3377. (org-end-of-meta-data t)
  3378. (looking-at "Contents")))
  3379. (should
  3380. (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
  3381. (org-end-of-meta-data t)
  3382. (looking-at "Contents")))
  3383. (should
  3384. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
  3385. (org-end-of-meta-data t)
  3386. (looking-at "Contents")))
  3387. ;; Special case: do not skip incomplete drawers.
  3388. (should
  3389. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
  3390. (org-end-of-meta-data t)
  3391. (looking-at ":LOGBOOK:")))
  3392. ;; Special case: Be careful about consecutive headlines.
  3393. (should-not
  3394. (org-test-with-temp-text "* H1\n*H2\nContents"
  3395. (org-end-of-meta-data t)
  3396. (looking-at "Contents"))))
  3397. (ert-deftest test-org/shiftright-heading ()
  3398. "Test `org-shiftright' on headings."
  3399. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  3400. (should
  3401. (equal "* TODO a1\n** a2\n* DONE b1\n"
  3402. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3403. (org-shiftright)
  3404. (buffer-string))))
  3405. (should
  3406. (equal "* TODO a1\n** TODO a2\n* b1\n"
  3407. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3408. (let ((org-loop-over-headlines-in-active-region t))
  3409. (transient-mark-mode 1)
  3410. (push-mark (point) t t)
  3411. (search-forward "* DONE b1")
  3412. (org-shiftright))
  3413. (buffer-string))))
  3414. (should
  3415. (equal "* TODO a1\n** a2\n* b1\n"
  3416. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3417. (let ((org-loop-over-headlines-in-active-region 'start-level))
  3418. (transient-mark-mode 1)
  3419. (push-mark (point) t t)
  3420. (search-forward "* DONE b1")
  3421. (org-shiftright))
  3422. (buffer-string))))))
  3423. (ert-deftest test-org/beginning-of-line ()
  3424. "Test `org-beginning-of-line' specifications."
  3425. ;; Move to beginning of line. If current line in invisible, move to
  3426. ;; beginning of visible line instead.
  3427. (should
  3428. (org-test-with-temp-text "Some text\nSome other text<point>"
  3429. (org-beginning-of-line)
  3430. (bolp)))
  3431. (should
  3432. (org-test-with-temp-text "* H1\n** H2<point>"
  3433. (org-overview)
  3434. (org-beginning-of-line)
  3435. (= (line-beginning-position) 1)))
  3436. ;; With `visual-line-mode' active, move to beginning of visual line.
  3437. (should-not
  3438. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3439. (visual-line-mode)
  3440. (dotimes (i 1000) (insert "very "))
  3441. (org-beginning-of-line)
  3442. (bolp)))
  3443. ;; In a wide headline, with `visual-line-mode', prefer going to the
  3444. ;; beginning of a visual line than to the logical beginning of line,
  3445. ;; even if special movement is active.
  3446. (should-not
  3447. (org-test-with-temp-text "* A <point>long headline"
  3448. (visual-line-mode)
  3449. (dotimes (i 1000) (insert "very "))
  3450. (goto-char (point-max))
  3451. (org-beginning-of-line)
  3452. (bobp)))
  3453. (should-not
  3454. (org-test-with-temp-text "* A <point>long headline"
  3455. (visual-line-mode)
  3456. (dotimes (i 1000) (insert "very "))
  3457. (goto-char (point-max))
  3458. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line))
  3459. (bobp)))
  3460. ;; At an headline with special movement, first move at beginning of
  3461. ;; title, then at the beginning of line, rinse, repeat.
  3462. (should
  3463. (org-test-with-temp-text "* TODO Headline<point>"
  3464. (let ((org-special-ctrl-a/e t))
  3465. (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
  3466. (progn (org-beginning-of-line) (bolp))
  3467. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3468. (should
  3469. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3470. (let ((org-special-ctrl-a/e t))
  3471. (org-beginning-of-line)
  3472. (looking-at "Headline"))))
  3473. (should
  3474. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3475. (let ((org-special-ctrl-a/e '(t . nil)))
  3476. (org-beginning-of-line)
  3477. (looking-at "Headline"))))
  3478. (should-not
  3479. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3480. (let ((org-special-ctrl-a/e '(nil . nil)))
  3481. (org-beginning-of-line)
  3482. (looking-at "Headline"))))
  3483. ;; At an headline with reversed movement, first move to beginning of
  3484. ;; line, then to the beginning of title.
  3485. (should
  3486. (org-test-with-temp-text "* TODO Headline<point>"
  3487. (let ((org-special-ctrl-a/e 'reversed)
  3488. (this-command last-command))
  3489. (and (progn (org-beginning-of-line) (bolp))
  3490. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3491. (should
  3492. (org-test-with-temp-text "* TODO Headline<point>"
  3493. (let ((org-special-ctrl-a/e '(reversed . nil))
  3494. (this-command last-command))
  3495. (and (progn (org-beginning-of-line) (bolp))
  3496. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3497. (should-not
  3498. (org-test-with-temp-text "* TODO Headline<point>"
  3499. (let ((org-special-ctrl-a/e '(t . nil))
  3500. (this-command last-command))
  3501. (and (progn (org-beginning-of-line) (bolp))
  3502. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3503. ;; At an item with special movement, first move after to beginning
  3504. ;; of title, then to the beginning of line, rinse, repeat.
  3505. (should
  3506. (org-test-with-temp-text "- [ ] Item<point>"
  3507. (let ((org-special-ctrl-a/e t))
  3508. (and (progn (org-beginning-of-line) (looking-at-p "Item"))
  3509. (progn (org-beginning-of-line) (bolp))
  3510. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3511. ;; At an item with reversed movement, first move to beginning of
  3512. ;; line, then to the beginning of title.
  3513. (should
  3514. (org-test-with-temp-text "- [X] Item<point>"
  3515. (let ((org-special-ctrl-a/e 'reversed)
  3516. (this-command last-command))
  3517. (and (progn (org-beginning-of-line) (bolp))
  3518. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3519. ;; Leave point before invisible characters at column 0.
  3520. (should
  3521. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3522. (let ((org-special-ctrl-a/e nil))
  3523. (org-beginning-of-line)
  3524. (bolp))))
  3525. (should
  3526. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3527. (let ((org-special-ctrl-a/e t))
  3528. (org-beginning-of-line)
  3529. (bolp))))
  3530. (should
  3531. (org-test-with-temp-text "[[http<point>://orgmode.org]]"
  3532. (visual-line-mode)
  3533. (org-beginning-of-line)
  3534. (bolp)))
  3535. ;; Special case: Do not error when the buffer contains only a single
  3536. ;; asterisk.
  3537. (should
  3538. (org-test-with-temp-text "*<point>"
  3539. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line) t)))
  3540. (should
  3541. (org-test-with-temp-text "*<point>"
  3542. (let ((org-special-ctrl-a/e nil)) (org-beginning-of-line) t))))
  3543. (ert-deftest test-org/end-of-line ()
  3544. "Test `org-end-of-line' specifications."
  3545. ;; Standard test.
  3546. (should
  3547. (org-test-with-temp-text "Some text\nSome other text"
  3548. (org-end-of-line)
  3549. (eolp)))
  3550. ;; With `visual-line-mode' active, move to end of visible line.
  3551. ;; However, never go past ellipsis.
  3552. (should-not
  3553. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3554. (visual-line-mode)
  3555. (dotimes (i 1000) (insert "very "))
  3556. (goto-char (point-min))
  3557. (org-end-of-line)
  3558. (eolp)))
  3559. (should-not
  3560. (org-test-with-temp-text "* A short headline\nSome contents"
  3561. (visual-line-mode)
  3562. (org-overview)
  3563. (org-end-of-line)
  3564. (eobp)))
  3565. ;; In a wide headline, with `visual-line-mode', prefer going to end
  3566. ;; of visible line if tags, or end of line, are farther.
  3567. (should-not
  3568. (org-test-with-temp-text "* A <point>long headline"
  3569. (visual-line-mode)
  3570. (dotimes (i 1000) (insert "very "))
  3571. (goto-char (point-min))
  3572. (org-end-of-line)
  3573. (eolp)))
  3574. (should-not
  3575. (org-test-with-temp-text "* A <point>long headline :tag:"
  3576. (visual-line-mode)
  3577. (dotimes (i 1000) (insert "very "))
  3578. (goto-char (point-min))
  3579. (org-end-of-line)
  3580. (eolp)))
  3581. ;; At an headline without special movement, go to end of line.
  3582. ;; However, never go past ellipsis.
  3583. (should
  3584. (org-test-with-temp-text "* Headline2b :tag:\n"
  3585. (let ((org-special-ctrl-a/e nil))
  3586. (and (progn (org-end-of-line) (eolp))
  3587. (progn (org-end-of-line) (eolp))))))
  3588. (should
  3589. (org-test-with-temp-text "* Headline2b :tag:\n"
  3590. (let ((org-special-ctrl-a/e '(t . nil)))
  3591. (and (progn (org-end-of-line) (eolp))
  3592. (progn (org-end-of-line) (eolp))))))
  3593. (should
  3594. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3595. (org-overview)
  3596. (let ((org-special-ctrl-a/e nil))
  3597. (org-end-of-line)
  3598. (= 1 (line-beginning-position)))))
  3599. ;; At an headline with special movement, first move before tags,
  3600. ;; then at the end of line, rinse, repeat. However, never go past
  3601. ;; ellipsis.
  3602. (should
  3603. (org-test-with-temp-text "* Headline1 :tag:\n"
  3604. (let ((org-special-ctrl-a/e t))
  3605. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3606. (progn (org-end-of-line) (eolp))
  3607. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3608. (should
  3609. (org-test-with-temp-text "* Headline1 :tag:\n"
  3610. (let ((org-special-ctrl-a/e '(nil . t)))
  3611. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3612. (progn (org-end-of-line) (eolp))
  3613. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3614. (should-not
  3615. (org-test-with-temp-text "* Headline1 :tag:\n"
  3616. (let ((org-special-ctrl-a/e '(nil . nil)))
  3617. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3618. (progn (org-end-of-line) (eolp))
  3619. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3620. (should
  3621. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3622. (org-overview)
  3623. (let ((org-special-ctrl-a/e t))
  3624. (org-end-of-line)
  3625. (org-end-of-line)
  3626. (= 1 (line-beginning-position)))))
  3627. ;; At an headline, with reversed movement, first go to end of line,
  3628. ;; then before tags. However, never go past ellipsis.
  3629. (should
  3630. (org-test-with-temp-text "* Headline3 :tag:\n"
  3631. (let ((org-special-ctrl-a/e 'reversed)
  3632. (this-command last-command))
  3633. (and (progn (org-end-of-line) (eolp))
  3634. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3635. (should
  3636. (org-test-with-temp-text "* Headline3 :tag:\n"
  3637. (let ((org-special-ctrl-a/e '(nil . reversed))
  3638. (this-command last-command))
  3639. (and (progn (org-end-of-line) (eolp))
  3640. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3641. (should-not
  3642. (org-test-with-temp-text "* Headline3 :tag:\n"
  3643. (let ((org-special-ctrl-a/e '(nil . t))
  3644. (this-command last-command))
  3645. (and (progn (org-end-of-line) (eolp))
  3646. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3647. (should
  3648. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3649. (org-overview)
  3650. (let ((org-special-ctrl-a/e 'reversed))
  3651. (org-end-of-line)
  3652. (= 1 (line-beginning-position)))))
  3653. ;; At a block without hidden contents.
  3654. (should
  3655. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3656. (progn (org-end-of-line) (eolp))))
  3657. ;; At a block with hidden contents.
  3658. (should-not
  3659. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3660. (let ((org-special-ctrl-a/e t))
  3661. (org-hide-block-toggle)
  3662. (org-end-of-line)
  3663. (eobp))))
  3664. ;; Get past invisible characters at the end of line.
  3665. (should
  3666. (org-test-with-temp-text "[[https://orgmode.org]]"
  3667. (org-end-of-line)
  3668. (eolp))))
  3669. (ert-deftest test-org/open-line ()
  3670. "Test `org-open-line' specifications."
  3671. ;; Call `open-line' outside of tables.
  3672. (should
  3673. (equal "\nText"
  3674. (org-test-with-temp-text "Text"
  3675. (org-open-line 1)
  3676. (buffer-string))))
  3677. ;; At a table, create a row above.
  3678. (should
  3679. (equal "\n| |\n| a |"
  3680. (org-test-with-temp-text "\n<point>| a |"
  3681. (org-open-line 1)
  3682. (buffer-string))))
  3683. ;; At the very first character of the buffer, also call `open-line'.
  3684. (should
  3685. (equal "\n| a |"
  3686. (org-test-with-temp-text "| a |"
  3687. (org-open-line 1)
  3688. (buffer-string))))
  3689. ;; Narrowing does not count.
  3690. (should
  3691. (equal "Text\n| |\n| a |"
  3692. (org-test-with-temp-text "Text\n<point>| a |"
  3693. (narrow-to-region (point) (point-max))
  3694. (org-open-line 1)
  3695. (widen)
  3696. (buffer-string)))))
  3697. (ert-deftest test-org/forward-sentence ()
  3698. "Test `org-forward-sentence' specifications."
  3699. ;; At the end of a table cell, move to the end of the next one.
  3700. (should
  3701. (org-test-with-temp-text "| a<point> | b |"
  3702. (org-forward-sentence)
  3703. (looking-at " |$")))
  3704. ;; Elsewhere in a cell, move to its end.
  3705. (should
  3706. (org-test-with-temp-text "| a<point>c | b |"
  3707. (org-forward-sentence)
  3708. (looking-at " | b |$")))
  3709. ;; Otherwise, simply call `forward-sentence'.
  3710. (should
  3711. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3712. (org-forward-sentence)
  3713. (looking-at " Sentence 2.")))
  3714. (should
  3715. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3716. (org-forward-sentence)
  3717. (org-forward-sentence)
  3718. (eobp)))
  3719. ;; At the end of an element, jump to the next one, without stopping
  3720. ;; on blank lines in-between.
  3721. (should
  3722. (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
  3723. (org-forward-sentence)
  3724. (eobp)))
  3725. ;; Headlines are considered to be sentences by themselves, even if
  3726. ;; they do not end with a full stop.
  3727. (should
  3728. (equal
  3729. "* Headline"
  3730. (org-test-with-temp-text "* <point>Headline\nSentence."
  3731. (org-forward-sentence)
  3732. (buffer-substring-no-properties (line-beginning-position) (point)))))
  3733. (should
  3734. (org-test-with-temp-text "* Headline<point>\nSentence."
  3735. (org-forward-sentence)
  3736. (eobp)))
  3737. (should
  3738. (org-test-with-temp-text "Sentence.<point>\n\n* Headline\n\nSentence 2."
  3739. (org-forward-sentence)
  3740. (and (org-at-heading-p) (eolp)))))
  3741. (ert-deftest test-org/backward-sentence ()
  3742. "Test `org-backward-sentence' specifications."
  3743. ;; At the beginning of a table cell, move to the beginning of the
  3744. ;; previous one.
  3745. (should
  3746. (org-test-with-temp-text "| a | <point>b |"
  3747. (org-backward-sentence)
  3748. (looking-at "a | b |$")))
  3749. ;; Elsewhere in a cell, move to its beginning.
  3750. (should
  3751. (org-test-with-temp-text "| a | b<point>c |"
  3752. (org-backward-sentence)
  3753. (looking-at "bc |$")))
  3754. ;; Otherwise, simply call `backward-sentence'.
  3755. (should
  3756. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3757. (org-backward-sentence)
  3758. (looking-at "Sentence 2.")))
  3759. (should
  3760. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3761. (org-backward-sentence)
  3762. (org-backward-sentence)
  3763. (bobp)))
  3764. ;; Make sure to hit the beginning of a sentence on the same line as
  3765. ;; an item.
  3766. (should
  3767. (org-test-with-temp-text "- Line 1\n line <point>2."
  3768. (org-backward-sentence)
  3769. (looking-at "Line 1"))))
  3770. (ert-deftest test-org/forward-paragraph ()
  3771. "Test `org-forward-paragraph' specifications."
  3772. ;; At end of buffer, do not return an error.
  3773. (should
  3774. (org-test-with-temp-text "Paragraph"
  3775. (goto-char (point-max))
  3776. (org-forward-paragraph)
  3777. t))
  3778. ;; Standard test.
  3779. (should
  3780. (= 2
  3781. (org-test-with-temp-text "P1\n\nP2"
  3782. (org-forward-paragraph)
  3783. (org-current-line))))
  3784. (should
  3785. (= 2
  3786. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  3787. (org-forward-paragraph)
  3788. (org-current-line))))
  3789. ;; Enter greater elements.
  3790. (should
  3791. (= 2
  3792. (org-test-with-temp-text "#+begin_center\nP1\n#+end_center\nP2"
  3793. (org-forward-paragraph)
  3794. (org-current-line))))
  3795. ;; Do not enter elements with invisible contents.
  3796. (should
  3797. (= 4
  3798. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  3799. (org-cycle)
  3800. (org-forward-paragraph)
  3801. (org-current-line))))
  3802. (should
  3803. (= 6
  3804. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\nP3"
  3805. (org-hide-block-toggle)
  3806. (org-forward-paragraph)
  3807. (org-current-line))))
  3808. ;; On an item or a footnote definition, move past the first element
  3809. ;; inside, if any.
  3810. (should
  3811. (= 2
  3812. (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
  3813. (org-forward-paragraph)
  3814. (org-current-line))))
  3815. (should
  3816. (= 2
  3817. (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
  3818. (org-forward-paragraph)
  3819. (org-current-line))))
  3820. ;; On a table (resp. a property drawer) do not move through table
  3821. ;; rows (resp. node properties).
  3822. (should
  3823. (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
  3824. (org-forward-paragraph)
  3825. (looking-at "Paragraph")))
  3826. (should
  3827. (org-test-with-temp-text
  3828. "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
  3829. (org-forward-paragraph)
  3830. (looking-at "Paragraph")))
  3831. ;; Skip consecutive keywords, clocks and diary S-exps.
  3832. (should
  3833. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n"
  3834. (org-forward-paragraph)
  3835. (eobp)))
  3836. (should
  3837. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n"
  3838. (org-forward-paragraph)
  3839. (eobp)))
  3840. (should
  3841. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n"
  3842. (org-forward-paragraph)
  3843. (eobp)))
  3844. (should-not
  3845. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n"
  3846. (org-forward-paragraph)
  3847. (eobp)))
  3848. (should-not
  3849. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n"
  3850. (org-forward-paragraph)
  3851. (eobp)))
  3852. ;; In a plain list with one item every line, skip the whole list,
  3853. ;; even with point in the middle of the list.
  3854. (should
  3855. (org-test-with-temp-text "- A\n - B\n- C\n"
  3856. (org-forward-paragraph)
  3857. (eobp)))
  3858. (should
  3859. (org-test-with-temp-text "- A\n - <point>B\n- C\n"
  3860. (org-forward-paragraph)
  3861. (eobp)))
  3862. ;; On a comment, verse or source block, stop at "contents"
  3863. ;; boundaries and blank lines.
  3864. (should
  3865. (= 2
  3866. (org-test-with-temp-text "#+begin_src emacs-lisp\nL1\n\nL2\n#+end_src"
  3867. (org-forward-paragraph)
  3868. (org-current-line))))
  3869. (should
  3870. (= 3
  3871. (org-test-with-temp-text "#+begin_verse\n<point>L1\n\nL2\n#+end_verse"
  3872. (org-forward-paragraph)
  3873. (org-current-line))))
  3874. (should
  3875. (= 5
  3876. (org-test-with-temp-text "#+begin_comment\nL1\n\n<point>L2\n#+end_comment"
  3877. (org-forward-paragraph)
  3878. (org-current-line))))
  3879. ;; Being on an affiliated keyword shouldn't make any difference.
  3880. (should
  3881. (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
  3882. (org-forward-paragraph)
  3883. (eobp))))
  3884. (ert-deftest test-org/backward-paragraph ()
  3885. "Test `org-backward-paragraph' specifications."
  3886. ;; Do not error at beginning of buffer.
  3887. (should
  3888. (org-test-with-temp-text "Paragraph"
  3889. (org-backward-paragraph)
  3890. t))
  3891. ;; At blank lines at the very beginning of a buffer, move to
  3892. ;; point-min.
  3893. (should
  3894. (org-test-with-temp-text "\n\n<point>\n\nParagraph"
  3895. (org-backward-paragraph)
  3896. (bobp)))
  3897. ;; Regular test.
  3898. (should
  3899. (= 2
  3900. (org-test-with-temp-text "P1\n\nP2<point>"
  3901. (org-backward-paragraph)
  3902. (org-current-line))))
  3903. (should
  3904. (= 4
  3905. (org-test-with-temp-text "P1\n\nP2\n\nP3<point>"
  3906. (org-backward-paragraph)
  3907. (org-current-line))))
  3908. ;; Try to move on the line above current element.
  3909. (should
  3910. (= 2
  3911. (org-test-with-temp-text "\n\n<point>Paragraph"
  3912. (org-backward-paragraph)
  3913. (org-current-line))))
  3914. ;; Do not leave point in an invisible area.
  3915. (should
  3916. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  3917. (org-cycle)
  3918. (goto-char (point-max))
  3919. (beginning-of-line)
  3920. (org-backward-paragraph)
  3921. (bobp)))
  3922. (should
  3923. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\n"
  3924. (org-hide-block-toggle)
  3925. (goto-char (point-max))
  3926. (org-backward-paragraph)
  3927. (bobp)))
  3928. ;; On the first element in an item or a footnote definition, jump
  3929. ;; before the footnote or the item.
  3930. (should
  3931. (org-test-with-temp-text "- line1<point>"
  3932. (org-backward-paragraph)
  3933. (bobp)))
  3934. (should
  3935. (org-test-with-temp-text "[fn:1] line1n<point>"
  3936. (org-backward-paragraph)
  3937. (bobp)))
  3938. ;; On the second element in an item or a footnote definition, jump
  3939. ;; to item or the definition.
  3940. (should
  3941. (= 2
  3942. (org-test-with-temp-text "- line1\n\n<point> line2"
  3943. (org-backward-paragraph)
  3944. (org-current-line))))
  3945. (should
  3946. (= 2
  3947. (org-test-with-temp-text "[fn:1] line1\n\n<point> line2"
  3948. (org-backward-paragraph)
  3949. (org-current-line))))
  3950. ;; On a table (resp. a property drawer), ignore table rows
  3951. ;; (resp. node properties).
  3952. (should
  3953. (org-test-with-temp-text "| a | b |\n| c | d |\n<point>P1"
  3954. (org-backward-paragraph)
  3955. (bobp)))
  3956. (should
  3957. (= 2
  3958. (org-test-with-temp-text
  3959. "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
  3960. (org-backward-paragraph)
  3961. (org-current-line))))
  3962. ;; In a plain list with one item every line, skip the whole list,
  3963. ;; even with point in the middle of the list.
  3964. (should
  3965. (org-test-with-temp-text "- A\n - B\n- C\n<point>"
  3966. (org-backward-paragraph)
  3967. (bobp)))
  3968. (should
  3969. (org-test-with-temp-text "- A\n - B\n- <point>C\n"
  3970. (org-backward-paragraph)
  3971. (bobp)))
  3972. ;; Skip consecutive keywords, clocks and diary S-exps.
  3973. (should
  3974. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n<point>"
  3975. (org-backward-paragraph)
  3976. (bobp)))
  3977. (should
  3978. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n<point>"
  3979. (org-backward-paragraph)
  3980. (bobp)))
  3981. (should
  3982. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n<point>"
  3983. (org-backward-paragraph)
  3984. (bobp)))
  3985. (should-not
  3986. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n<point>"
  3987. (org-backward-paragraph)
  3988. (bobp)))
  3989. (should-not
  3990. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n<point>"
  3991. (org-backward-paragraph)
  3992. (bobp)))
  3993. ;; On a comment, example, source and verse blocks, stop at blank
  3994. ;; lines.
  3995. (should
  3996. (= 1
  3997. (org-test-with-temp-text
  3998. "#+begin_comment\n<point>L1\n\nL2\n\nL3\n#+end_comment"
  3999. (org-backward-paragraph)
  4000. (org-current-line))))
  4001. (should
  4002. (= 2
  4003. (org-test-with-temp-text
  4004. "#+begin_verse\nL1\n\n<point>L2\n\nL3\n#+end_verse"
  4005. (org-backward-paragraph)
  4006. (org-current-line))))
  4007. (should
  4008. (= 3
  4009. (org-test-with-temp-text
  4010. "#+begin_src emacs-lisp\nL1\n\nL2\n\n<point>L3\n#+end_src"
  4011. (org-backward-paragraph)
  4012. (org-current-line))))
  4013. ;; When called from the opening line itself, however, move to
  4014. ;; beginning of block.
  4015. (should
  4016. (org-test-with-temp-text "#+begin_<point>example\nL1\n#+end_example"
  4017. (org-backward-paragraph)
  4018. (bobp)))
  4019. ;; On an empty heading, move above it.
  4020. (should
  4021. (org-test-with-temp-text "\n* <point>"
  4022. (org-backward-paragraph)
  4023. (bobp)))
  4024. (should
  4025. (org-test-with-temp-text "\n* \n<point>"
  4026. (org-backward-paragraph)
  4027. (bobp))))
  4028. (ert-deftest test-org/forward-element ()
  4029. "Test `org-forward-element' specifications."
  4030. ;; 1. At EOB: should error.
  4031. (org-test-with-temp-text "Some text\n"
  4032. (goto-char (point-max))
  4033. (should-error (org-forward-element)))
  4034. ;; 2. Standard move: expected to ignore blank lines.
  4035. (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
  4036. (org-forward-element)
  4037. (should (looking-at (regexp-quote "Second paragraph."))))
  4038. ;; 3. Headline tests.
  4039. (org-test-with-temp-text "
  4040. * Head 1
  4041. ** Head 1.1
  4042. *** Head 1.1.1
  4043. ** Head 1.2"
  4044. ;; 3.1. At an headline beginning: move to next headline at the
  4045. ;; same level.
  4046. (goto-line 3)
  4047. (org-forward-element)
  4048. (should (looking-at (regexp-quote "** Head 1.2")))
  4049. ;; 3.2. At an headline beginning: move to parent headline if no
  4050. ;; headline at the same level.
  4051. (goto-line 3)
  4052. (org-forward-element)
  4053. (should (looking-at (regexp-quote "** Head 1.2"))))
  4054. ;; 4. Greater element tests.
  4055. (org-test-with-temp-text
  4056. "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
  4057. ;; 4.1. At a greater element: expected to skip contents.
  4058. (org-forward-element)
  4059. (should (looking-at (regexp-quote "Outside.")))
  4060. ;; 4.2. At the end of greater element contents: expected to skip
  4061. ;; to the end of the greater element.
  4062. (goto-line 2)
  4063. (org-forward-element)
  4064. (should (looking-at (regexp-quote "Outside."))))
  4065. ;; 5. List tests.
  4066. (org-test-with-temp-text "
  4067. - item1
  4068. - sub1
  4069. - sub2
  4070. - sub3
  4071. Inner paragraph.
  4072. - item2
  4073. Outside."
  4074. ;; 5.1. At list top point: expected to move to the element after
  4075. ;; the list.
  4076. (goto-line 2)
  4077. (org-forward-element)
  4078. (should (looking-at (regexp-quote "Outside.")))
  4079. ;; 5.2. Special case: at the first line of a sub-list, but not at
  4080. ;; beginning of line, move to next item.
  4081. (goto-line 2)
  4082. (forward-char)
  4083. (org-forward-element)
  4084. (should (looking-at "- item2"))
  4085. (goto-line 4)
  4086. (forward-char)
  4087. (org-forward-element)
  4088. (should (looking-at " - sub2"))
  4089. ;; 5.3 At sub-list beginning: expected to move after the sub-list.
  4090. (goto-line 4)
  4091. (org-forward-element)
  4092. (should (looking-at (regexp-quote " Inner paragraph.")))
  4093. ;; 5.4. At sub-list end: expected to move outside the sub-list.
  4094. (goto-line 8)
  4095. (org-forward-element)
  4096. (should (looking-at (regexp-quote " Inner paragraph.")))
  4097. ;; 5.5. At an item: expected to move to next item, if any.
  4098. (goto-line 6)
  4099. (org-forward-element)
  4100. (should (looking-at " - sub3"))))
  4101. (ert-deftest test-org/backward-element ()
  4102. "Test `org-backward-element' specifications."
  4103. ;; 1. Should error at BOB.
  4104. (org-test-with-temp-text " \nParagraph."
  4105. (should-error (org-backward-element)))
  4106. ;; 2. Should move at BOB when called on the first element in buffer.
  4107. (should
  4108. (org-test-with-temp-text "\n#+TITLE: test"
  4109. (progn (forward-line)
  4110. (org-backward-element)
  4111. (bobp))))
  4112. ;; 3. Not at the beginning of an element: move at its beginning.
  4113. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  4114. (goto-line 3)
  4115. (end-of-line)
  4116. (org-backward-element)
  4117. (should (looking-at (regexp-quote "Paragraph2."))))
  4118. ;; 4. Headline tests.
  4119. (org-test-with-temp-text "
  4120. * Head 1
  4121. ** Head 1.1
  4122. *** Head 1.1.1
  4123. ** Head 1.2"
  4124. ;; 4.1. At an headline beginning: move to previous headline at the
  4125. ;; same level.
  4126. (goto-line 5)
  4127. (org-backward-element)
  4128. (should (looking-at (regexp-quote "** Head 1.1")))
  4129. ;; 4.2. At an headline beginning: move to parent headline if no
  4130. ;; headline at the same level.
  4131. (goto-line 3)
  4132. (org-backward-element)
  4133. (should (looking-at (regexp-quote "* Head 1")))
  4134. ;; 4.3. At the first top-level headline: should error.
  4135. (goto-line 2)
  4136. (should-error (org-backward-element)))
  4137. ;; 5. At beginning of first element inside a greater element:
  4138. ;; expected to move to greater element's beginning.
  4139. (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
  4140. (goto-line 3)
  4141. (org-backward-element)
  4142. (should (looking-at "#\\+BEGIN_CENTER")))
  4143. ;; 6. At the beginning of the first element in a section: should
  4144. ;; move back to headline, if any.
  4145. (should
  4146. (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
  4147. (progn (goto-char (point-max))
  4148. (beginning-of-line)
  4149. (org-backward-element)
  4150. (org-at-heading-p))))
  4151. ;; 7. List tests.
  4152. (org-test-with-temp-text "
  4153. - item1
  4154. - sub1
  4155. - sub2
  4156. - sub3
  4157. Inner paragraph.
  4158. - item2
  4159. Outside."
  4160. ;; 7.1. At beginning of sub-list: expected to move to the
  4161. ;; paragraph before it.
  4162. (goto-line 4)
  4163. (org-backward-element)
  4164. (should (looking-at "item1"))
  4165. ;; 7.2. At an item in a list: expected to move at previous item.
  4166. (goto-line 8)
  4167. (org-backward-element)
  4168. (should (looking-at " - sub2"))
  4169. (goto-line 12)
  4170. (org-backward-element)
  4171. (should (looking-at "- item1"))
  4172. ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
  4173. ;; beginning.
  4174. (goto-line 10)
  4175. (org-backward-element)
  4176. (should (looking-at " - sub1"))
  4177. (goto-line 15)
  4178. (org-backward-element)
  4179. (should (looking-at "- item1"))
  4180. ;; 7.4. At blank-lines before list end: expected to move to top
  4181. ;; item.
  4182. (goto-line 14)
  4183. (org-backward-element)
  4184. (should (looking-at "- item1"))))
  4185. (ert-deftest test-org/up-element ()
  4186. "Test `org-up-element' specifications."
  4187. ;; 1. At BOB or with no surrounding element: should error.
  4188. (org-test-with-temp-text "Paragraph."
  4189. (should-error (org-up-element)))
  4190. (org-test-with-temp-text "* Head1\n* Head2"
  4191. (goto-line 2)
  4192. (should-error (org-up-element)))
  4193. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  4194. (goto-line 3)
  4195. (should-error (org-up-element)))
  4196. ;; 2. At an headline: move to parent headline.
  4197. (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
  4198. (goto-line 3)
  4199. (org-up-element)
  4200. (should (looking-at "\\* Head1")))
  4201. ;; 3. Inside a greater element: move to greater element beginning.
  4202. (org-test-with-temp-text
  4203. "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
  4204. (goto-line 3)
  4205. (org-up-element)
  4206. (should (looking-at "#\\+BEGIN_CENTER")))
  4207. ;; 4. List tests.
  4208. (org-test-with-temp-text "* Top
  4209. - item1
  4210. - sub1
  4211. - sub2
  4212. Paragraph within sub2.
  4213. - item2"
  4214. ;; 4.1. Within an item: move to the item beginning.
  4215. (goto-line 8)
  4216. (org-up-element)
  4217. (should (looking-at " - sub2"))
  4218. ;; 4.2. At an item in a sub-list: move to parent item.
  4219. (goto-line 4)
  4220. (org-up-element)
  4221. (should (looking-at "- item1"))
  4222. ;; 4.3. At an item in top list: move to beginning of whole list.
  4223. (goto-line 10)
  4224. (org-up-element)
  4225. (should (looking-at "- item1"))
  4226. ;; 4.4. Special case. At very top point: should move to parent of
  4227. ;; list.
  4228. (goto-line 2)
  4229. (org-up-element)
  4230. (should (looking-at "\\* Top"))))
  4231. (ert-deftest test-org/down-element ()
  4232. "Test `org-down-element' specifications."
  4233. ;; Error when the element hasn't got a recursive type.
  4234. (org-test-with-temp-text "Paragraph."
  4235. (should-error (org-down-element)))
  4236. ;; Error when the element has no contents
  4237. (org-test-with-temp-text "* Headline"
  4238. (should-error (org-down-element)))
  4239. ;; When at a plain-list, move to first item.
  4240. (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
  4241. (goto-line 2)
  4242. (org-down-element)
  4243. (should (looking-at " - Item 1.1")))
  4244. (org-test-with-temp-text "#+NAME: list\n- Item 1"
  4245. (org-down-element)
  4246. (should (looking-at " Item 1")))
  4247. ;; When at a table, move to first row
  4248. (org-test-with-temp-text "#+NAME: table\n| a | b |"
  4249. (org-down-element)
  4250. (should (looking-at " a | b |")))
  4251. ;; Otherwise, move inside the greater element.
  4252. (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
  4253. (org-down-element)
  4254. (should (looking-at "Paragraph"))))
  4255. (ert-deftest test-org/drag-element-backward ()
  4256. "Test `org-drag-element-backward' specifications."
  4257. ;; Standard test.
  4258. (should
  4259. (equal
  4260. "#+key2: val2\n#+key1: val1\n#+key3: val3"
  4261. (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
  4262. (org-drag-element-backward)
  4263. (buffer-string))))
  4264. (should
  4265. (equal
  4266. "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
  4267. (org-test-with-temp-text
  4268. "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
  4269. (org-drag-element-backward)
  4270. (buffer-string))))
  4271. ;; Preserve blank lines.
  4272. (should
  4273. (equal "Paragraph 2\n\n\nPara1\n\nPara3"
  4274. (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
  4275. (org-drag-element-backward)
  4276. (buffer-string))))
  4277. ;; Preserve column.
  4278. (should
  4279. (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
  4280. (org-drag-element-backward)
  4281. (looking-at-p "2")))
  4282. ;; Error when trying to move first element of buffer.
  4283. (should-error
  4284. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4285. (org-drag-element-backward))
  4286. :type 'user-error)
  4287. ;; Error when trying to swap nested elements.
  4288. (should-error
  4289. (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
  4290. (org-drag-element-backward))
  4291. :type 'user-error)
  4292. ;; Error when trying to swap an headline element and a non-headline
  4293. ;; element.
  4294. (should-error
  4295. (org-test-with-temp-text "Test.\n<point>* Head 1"
  4296. (org-drag-element-backward))
  4297. :type 'error)
  4298. ;; Error when called before first element.
  4299. (should-error
  4300. (org-test-with-temp-text "\n<point>"
  4301. (org-drag-element-backward))
  4302. :type 'user-error)
  4303. ;; Preserve visibility of elements and their contents.
  4304. (should
  4305. (equal '((63 . 82) (26 . 48))
  4306. (org-test-with-temp-text "
  4307. #+BEGIN_CENTER
  4308. Text.
  4309. #+END_CENTER
  4310. - item 1
  4311. #+BEGIN_QUOTE
  4312. Text.
  4313. #+END_QUOTE"
  4314. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4315. (search-backward "- item 1")
  4316. (org-drag-element-backward)
  4317. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4318. (overlays-in (point-min) (point-max))))))
  4319. ;; Pathological case: handle call with point in blank lines right
  4320. ;; after a headline.
  4321. (should
  4322. (equal "* H2\n\n* H1\nText\n"
  4323. (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
  4324. (org-drag-element-backward)
  4325. (buffer-string)))))
  4326. (ert-deftest test-org/drag-element-forward ()
  4327. "Test `org-drag-element-forward' specifications."
  4328. ;; 1. Error when trying to move first element of buffer.
  4329. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4330. (goto-line 3)
  4331. (should-error (org-drag-element-forward)))
  4332. ;; 2. Error when trying to swap nested elements.
  4333. (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
  4334. (forward-line)
  4335. (should-error (org-drag-element-forward)))
  4336. ;; 3. Error when trying to swap a non-headline element and an
  4337. ;; headline.
  4338. (org-test-with-temp-text "Test.\n* Head 1"
  4339. (should-error (org-drag-element-forward)))
  4340. ;; 4. Error when called before first element.
  4341. (should-error
  4342. (org-test-with-temp-text "\n"
  4343. (forward-line)
  4344. (org-drag-element-backward))
  4345. :type 'user-error)
  4346. ;; 5. Otherwise, swap elements, preserving column and blank lines
  4347. ;; between elements.
  4348. (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
  4349. (search-forward "graph")
  4350. (org-drag-element-forward)
  4351. (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
  4352. (should (looking-at " 1")))
  4353. ;; 5. Preserve visibility of elements and their contents.
  4354. (org-test-with-temp-text "
  4355. #+BEGIN_CENTER
  4356. Text.
  4357. #+END_CENTER
  4358. - item 1
  4359. #+BEGIN_QUOTE
  4360. Text.
  4361. #+END_QUOTE"
  4362. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4363. (search-backward "#+BEGIN_CENTER")
  4364. (org-drag-element-forward)
  4365. (should
  4366. (equal
  4367. '((63 . 82) (26 . 48))
  4368. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4369. (overlays-in (point-min) (point-max)))))))
  4370. (ert-deftest test-org/next-block ()
  4371. "Test `org-next-block' specifications."
  4372. ;; Regular test.
  4373. (should
  4374. (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  4375. (org-next-block 1)
  4376. (looking-at "#\\+BEGIN_CENTER")))
  4377. ;; Ignore case.
  4378. (should
  4379. (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
  4380. (let ((case-fold-search nil))
  4381. (org-next-block 1)
  4382. (looking-at "#\\+begin_center"))))
  4383. ;; Ignore current line.
  4384. (should
  4385. (org-test-with-temp-text
  4386. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
  4387. (org-next-block 1)
  4388. (looking-at "#\\+BEGIN_CENTER")))
  4389. ;; Throw an error when no block is found.
  4390. (should-error
  4391. (org-test-with-temp-text "Paragraph"
  4392. (org-next-block 1)))
  4393. ;; With an argument, skip many blocks at once.
  4394. (should
  4395. (org-test-with-temp-text
  4396. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4397. (org-next-block 2)
  4398. (looking-at "#\\+BEGIN_QUOTE")))
  4399. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4400. (should
  4401. (org-test-with-temp-text
  4402. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4403. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4404. (looking-at "#\\+BEGIN_QUOTE")))
  4405. ;; Optional argument is also case-insensitive.
  4406. (should
  4407. (org-test-with-temp-text
  4408. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
  4409. (let ((case-fold-search nil))
  4410. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4411. (looking-at "#\\+begin_quote")))))
  4412. (ert-deftest test-org/insert-structure-template ()
  4413. "Test `org-insert-structure-template'."
  4414. ;; Test in empty buffer.
  4415. (should
  4416. (string= "#+begin_foo\n#+end_foo\n"
  4417. (org-test-with-temp-text ""
  4418. (org-insert-structure-template "foo")
  4419. (buffer-string))))
  4420. ;; Test with multiple lines in buffer.
  4421. (should
  4422. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4423. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4424. (transient-mark-mode 1)
  4425. (org-mark-element)
  4426. (org-insert-structure-template "foo")
  4427. (buffer-string))))
  4428. ;; Mark only the current line.
  4429. (should
  4430. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4431. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4432. (transient-mark-mode 1)
  4433. (set-mark (point-min))
  4434. (end-of-line)
  4435. (org-insert-structure-template "foo")
  4436. (buffer-string))))
  4437. ;; Middle of paragraph.
  4438. (should
  4439. (string= "p1\n#+begin_foo\np2\n#+end_foo\np3"
  4440. (org-test-with-temp-text "p1\n<point>p2\np3"
  4441. (set-mark (line-beginning-position))
  4442. (end-of-line)
  4443. (activate-mark)
  4444. (org-insert-structure-template "foo")
  4445. (buffer-string))))
  4446. ;; Test with text in buffer, no region, no final newline.
  4447. (should
  4448. (string= "#+begin_foo\nI'm a paragraph.\n#+end_foo\n"
  4449. (org-test-with-temp-text "I'm a paragraph."
  4450. (org-mark-element)
  4451. (org-insert-structure-template "foo")
  4452. (buffer-string))))
  4453. ;; Test with text in buffer and region set.
  4454. (should
  4455. (string= "#+begin_foo\nI'm a paragraph\n\nI'm a second paragrah\n#+end_foo\n"
  4456. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragrah"
  4457. (set-mark (point))
  4458. (goto-char (point-max))
  4459. (org-insert-structure-template "foo")
  4460. (buffer-string))))
  4461. ;; Test with example escaping.
  4462. (should
  4463. (string= "#+begin_example\n,* Heading\n#+end_example\n"
  4464. (org-test-with-temp-text "* Heading"
  4465. (org-mark-element)
  4466. (org-insert-structure-template "example")
  4467. (buffer-string))))
  4468. ;; Test with indentation.
  4469. (should
  4470. (string= " #+begin_foo\n This is a paragraph\n #+end_foo\n"
  4471. (org-test-with-temp-text " This is a paragraph"
  4472. (org-mark-element)
  4473. (org-insert-structure-template "foo")
  4474. (buffer-string))))
  4475. (should
  4476. (string= " #+begin_foo\n Line 1\n Line2\n #+end_foo\n"
  4477. (org-test-with-temp-text " Line 1\n Line2"
  4478. (org-mark-element)
  4479. (org-insert-structure-template "foo")
  4480. (buffer-string))))
  4481. ;; Test point location.
  4482. (should
  4483. (string= "#+begin_foo\n"
  4484. (org-test-with-temp-text ""
  4485. (org-insert-structure-template "foo")
  4486. (buffer-substring (point-min) (point)))))
  4487. (should
  4488. (string= "#+begin_src "
  4489. (org-test-with-temp-text ""
  4490. (org-insert-structure-template "src")
  4491. (buffer-substring (point-min) (point))))))
  4492. (ert-deftest test-org/previous-block ()
  4493. "Test `org-previous-block' specifications."
  4494. ;; Regular test.
  4495. (should
  4496. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
  4497. (org-previous-block 1)
  4498. (looking-at "#\\+BEGIN_CENTER")))
  4499. ;; Ignore case.
  4500. (should
  4501. (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
  4502. (let ((case-fold-search nil))
  4503. (org-previous-block 1)
  4504. (looking-at "#\\+begin_center"))))
  4505. ;; Ignore current line.
  4506. (should
  4507. (org-test-with-temp-text
  4508. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
  4509. (org-previous-block 1)
  4510. (looking-at "#\\+BEGIN_QUOTE")))
  4511. ;; Throw an error when no block is found.
  4512. (should-error
  4513. (org-test-with-temp-text "Paragraph<point>"
  4514. (org-previous-block 1)))
  4515. ;; With an argument, skip many blocks at once.
  4516. (should
  4517. (org-test-with-temp-text
  4518. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4519. (org-previous-block 2)
  4520. (looking-at "#\\+BEGIN_CENTER")))
  4521. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4522. (should
  4523. (org-test-with-temp-text
  4524. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4525. (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4526. (looking-at "#\\+BEGIN_QUOTE")))
  4527. ;; Optional argument is also case-insensitive.
  4528. (should
  4529. (org-test-with-temp-text
  4530. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
  4531. (let ((case-fold-search nil))
  4532. (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4533. (looking-at "#\\+begin_quote")))))
  4534. ;;; Outline structure
  4535. (ert-deftest test-org/demote ()
  4536. "Test `org-demote' specifications."
  4537. ;; Add correct number of stars according to `org-odd-levels-only'.
  4538. (should
  4539. (= 2
  4540. (org-test-with-temp-text "* H"
  4541. (let ((org-odd-levels-only nil)) (org-demote))
  4542. (org-current-level))))
  4543. (should
  4544. (= 3
  4545. (org-test-with-temp-text "* H"
  4546. (let ((org-odd-levels-only t)) (org-demote))
  4547. (org-current-level))))
  4548. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4549. (should
  4550. (org-test-with-temp-text "* H :tag:"
  4551. (let ((org-tags-column 10)
  4552. (org-auto-align-tags t)
  4553. (org-odd-levels-only nil))
  4554. (org-demote))
  4555. (org-move-to-column 10)
  4556. (looking-at-p ":tag:$")))
  4557. (should-not
  4558. (org-test-with-temp-text "* H :tag:"
  4559. (let ((org-tags-column 10)
  4560. (org-auto-align-tags nil)
  4561. (org-odd-levels-only nil))
  4562. (org-demote))
  4563. (org-move-to-column 10)
  4564. (looking-at-p ":tag:$")))
  4565. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4566. ;; info and property drawers accordingly.
  4567. (should
  4568. (= 3
  4569. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4570. (let ((org-odd-levels-only nil)
  4571. (org-adapt-indentation t))
  4572. (org-demote))
  4573. (forward-line)
  4574. (org-get-indentation))))
  4575. (should
  4576. (= 3
  4577. (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4578. (let ((org-odd-levels-only nil)
  4579. (org-adapt-indentation t))
  4580. (org-demote))
  4581. (forward-line)
  4582. (org-get-indentation))))
  4583. (should-not
  4584. (= 3
  4585. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4586. (let ((org-odd-levels-only nil)
  4587. (org-adapt-indentation nil))
  4588. (org-demote))
  4589. (forward-line)
  4590. (org-get-indentation))))
  4591. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4592. ;; section accordingly. Ignore, however, footnote definitions and
  4593. ;; inlinetasks boundaries.
  4594. (should
  4595. (= 3
  4596. (org-test-with-temp-text "* H\n Paragraph"
  4597. (let ((org-odd-levels-only nil)
  4598. (org-adapt-indentation t))
  4599. (org-demote))
  4600. (forward-line)
  4601. (org-get-indentation))))
  4602. (should
  4603. (= 2
  4604. (org-test-with-temp-text "* H\n Paragraph"
  4605. (let ((org-odd-levels-only nil)
  4606. (org-adapt-indentation nil))
  4607. (org-demote))
  4608. (forward-line)
  4609. (org-get-indentation))))
  4610. (should
  4611. (zerop
  4612. (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
  4613. (let ((org-odd-levels-only nil)
  4614. (org-adapt-indentation t))
  4615. (org-demote))
  4616. (goto-char (point-max))
  4617. (org-get-indentation))))
  4618. (should
  4619. (= 3
  4620. (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
  4621. (let ((org-odd-levels-only nil)
  4622. (org-adapt-indentation t))
  4623. (org-demote))
  4624. (goto-char (point-max))
  4625. (org-get-indentation))))
  4626. (when (featurep 'org-inlinetask)
  4627. (should
  4628. (zerop
  4629. (let ((org-inlinetask-min-level 5)
  4630. (org-adapt-indentation t))
  4631. (org-test-with-temp-text "* H\n***** I\n***** END"
  4632. (org-demote)
  4633. (forward-line)
  4634. (org-get-indentation))))))
  4635. (when (featurep 'org-inlinetask)
  4636. (should
  4637. (= 3
  4638. (let ((org-inlinetask-min-level 5)
  4639. (org-adapt-indentation t))
  4640. (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
  4641. (org-demote)
  4642. (forward-line 2)
  4643. (org-get-indentation))))))
  4644. ;; When `org-adapt-indentation' is non-nil, log drawers are
  4645. ;; adjusted.
  4646. (should
  4647. (equal
  4648. "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4649. (org-test-with-temp-text "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4650. (let ((org-odd-levels-only nil)
  4651. (org-adapt-indentation t))
  4652. (org-demote))
  4653. (buffer-string))))
  4654. (should
  4655. (equal
  4656. "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4657. (org-test-with-temp-text "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4658. (let ((org-odd-levels-only nil)
  4659. (org-adapt-indentation 'headline-data))
  4660. (org-demote))
  4661. (buffer-string))))
  4662. (should
  4663. (equal
  4664. "** H\n :LOGBOOK:\n - a\n :END:"
  4665. (org-test-with-temp-text "* H\n:LOGBOOK:\n- a\n:END:"
  4666. (let ((org-odd-levels-only nil)
  4667. (org-adapt-indentation t))
  4668. (org-demote))
  4669. (buffer-string))))
  4670. ;; Ignore contents of source blocks or example blocks when
  4671. ;; indentation should be preserved (through
  4672. ;; `org-src-preserve-indentation' or "-i" flag).
  4673. (should-not
  4674. (zerop
  4675. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4676. (let ((org-adapt-indentation t)
  4677. (org-src-preserve-indentation nil))
  4678. (org-demote))
  4679. (forward-line 2)
  4680. (org-get-indentation))))
  4681. (should
  4682. (zerop
  4683. (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
  4684. (let ((org-adapt-indentation t)
  4685. (org-src-preserve-indentation t))
  4686. (org-demote))
  4687. (forward-line 2)
  4688. (org-get-indentation))))
  4689. (should
  4690. (zerop
  4691. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4692. (let ((org-adapt-indentation t)
  4693. (org-src-preserve-indentation t))
  4694. (org-demote))
  4695. (forward-line 2)
  4696. (org-get-indentation))))
  4697. (should
  4698. (zerop
  4699. (org-test-with-temp-text
  4700. "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
  4701. (let ((org-adapt-indentation t)
  4702. (org-src-preserve-indentation nil))
  4703. (org-demote))
  4704. (forward-line 2)
  4705. (org-get-indentation)))))
  4706. (ert-deftest test-org/promote ()
  4707. "Test `org-promote' specifications."
  4708. ;; Return an error if headline is to be promoted to level 0, unless
  4709. ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
  4710. ;; headline becomes a comment.
  4711. (should-error
  4712. (org-test-with-temp-text "* H"
  4713. (let ((org-allow-promoting-top-level-subtree nil)) (org-promote))))
  4714. (should
  4715. (equal "# H"
  4716. (org-test-with-temp-text "* H"
  4717. (let ((org-allow-promoting-top-level-subtree t)) (org-promote))
  4718. (buffer-string))))
  4719. ;; Remove correct number of stars according to
  4720. ;; `org-odd-levels-only'.
  4721. (should
  4722. (= 2
  4723. (org-test-with-temp-text "*** H"
  4724. (let ((org-odd-levels-only nil)) (org-promote))
  4725. (org-current-level))))
  4726. (should
  4727. (= 1
  4728. (org-test-with-temp-text "*** H"
  4729. (let ((org-odd-levels-only t)) (org-promote))
  4730. (org-current-level))))
  4731. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4732. (should
  4733. (org-test-with-temp-text "** H :tag:"
  4734. (let ((org-tags-column 10)
  4735. (org-auto-align-tags t)
  4736. (org-odd-levels-only nil))
  4737. (org-promote))
  4738. (org-move-to-column 10)
  4739. (looking-at-p ":tag:$")))
  4740. (should-not
  4741. (org-test-with-temp-text "** H :tag:"
  4742. (let ((org-tags-column 10)
  4743. (org-auto-align-tags nil)
  4744. (org-odd-levels-only nil))
  4745. (org-promote))
  4746. (org-move-to-column 10)
  4747. (looking-at-p ":tag:$")))
  4748. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4749. ;; info and property drawers.
  4750. (should
  4751. (= 2
  4752. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4753. (let ((org-odd-levels-only nil)
  4754. (org-adapt-indentation t))
  4755. (org-promote))
  4756. (forward-line)
  4757. (org-get-indentation))))
  4758. (should
  4759. (= 2
  4760. (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4761. (let ((org-odd-levels-only nil)
  4762. (org-adapt-indentation t))
  4763. (org-promote))
  4764. (forward-line)
  4765. (org-get-indentation))))
  4766. (should-not
  4767. (= 2
  4768. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4769. (let ((org-odd-levels-only nil)
  4770. (org-adapt-indentation nil))
  4771. (org-promote))
  4772. (forward-line)
  4773. (org-get-indentation))))
  4774. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4775. ;; section accordingly. Ignore, however, footnote definitions and
  4776. ;; inlinetasks boundaries.
  4777. (should
  4778. (= 2
  4779. (org-test-with-temp-text "** H\n Paragraph"
  4780. (let ((org-odd-levels-only nil)
  4781. (org-adapt-indentation t))
  4782. (org-promote))
  4783. (forward-line)
  4784. (org-get-indentation))))
  4785. (should-not
  4786. (= 2
  4787. (org-test-with-temp-text "** H\n Paragraph"
  4788. (let ((org-odd-levels-only nil)
  4789. (org-adapt-indentation nil))
  4790. (org-promote))
  4791. (forward-line)
  4792. (org-get-indentation))))
  4793. (should
  4794. (= 2
  4795. (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
  4796. (let ((org-odd-levels-only nil)
  4797. (org-adapt-indentation t))
  4798. (org-promote))
  4799. (forward-line)
  4800. (org-get-indentation))))
  4801. (when (featurep 'org-inlinetask)
  4802. (should
  4803. (zerop
  4804. (let ((org-inlinetask-min-level 5)
  4805. (org-adapt-indentation t))
  4806. (org-test-with-temp-text "** H\n***** I\n***** END"
  4807. (org-promote)
  4808. (forward-line)
  4809. (org-get-indentation))))))
  4810. (when (featurep 'org-inlinetask)
  4811. (should
  4812. (= 2
  4813. (let ((org-inlinetask-min-level 5)
  4814. (org-adapt-indentation t))
  4815. (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
  4816. (org-promote)
  4817. (forward-line 2)
  4818. (org-get-indentation))))))
  4819. ;; Give up shifting if it would break document's structure
  4820. ;; otherwise.
  4821. (should
  4822. (= 3
  4823. (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
  4824. (let ((org-odd-levels-only nil)
  4825. (org-adapt-indentation t))
  4826. (org-promote))
  4827. (forward-line)
  4828. (org-get-indentation))))
  4829. (should
  4830. (= 3
  4831. (org-test-with-temp-text "** H\n Paragraph\n * list."
  4832. (let ((org-odd-levels-only nil)
  4833. (org-adapt-indentation t))
  4834. (org-promote))
  4835. (forward-line)
  4836. (org-get-indentation))))
  4837. ;; When `org-adapt-indentation' is non-nil, log drawers are
  4838. ;; adjusted.
  4839. (should
  4840. (equal
  4841. "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4842. (org-test-with-temp-text "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4843. (let ((org-odd-levels-only nil)
  4844. (org-adapt-indentation t))
  4845. (org-promote))
  4846. (buffer-string))))
  4847. (should
  4848. (equal
  4849. "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4850. (org-test-with-temp-text "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4851. (let ((org-odd-levels-only nil)
  4852. (org-adapt-indentation 'headline-data))
  4853. (org-promote))
  4854. (buffer-string))))
  4855. (should
  4856. (equal
  4857. "* H\n:LOGBOOK:\n- a\n:END:"
  4858. (org-test-with-temp-text "** H\n:LOGBOOK:\n- a\n:END:"
  4859. (let ((org-odd-levels-only nil)
  4860. (org-adapt-indentation t))
  4861. (org-promote))
  4862. (buffer-string))))
  4863. (should
  4864. (equal
  4865. "# H\n:LOGBOOK:\n- a\n:END:"
  4866. (org-test-with-temp-text "* H\n:LOGBOOK:\n- a\n:END:"
  4867. (let ((org-odd-levels-only nil)
  4868. (org-allow-promoting-top-level-subtree t)
  4869. (org-adapt-indentation t))
  4870. (org-promote))
  4871. (buffer-string))))
  4872. ;; Ignore contents of source blocks or example blocks when
  4873. ;; indentation should be preserved (through
  4874. ;; `org-src-preserve-indentation' or "-i" flag).
  4875. (should-not
  4876. (zerop
  4877. (org-test-with-temp-text
  4878. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  4879. (let ((org-adapt-indentation t)
  4880. (org-src-preserve-indentation nil)
  4881. (org-odd-levels-only nil))
  4882. (org-promote))
  4883. (forward-line)
  4884. (org-get-indentation))))
  4885. (should
  4886. (zerop
  4887. (org-test-with-temp-text
  4888. "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
  4889. (let ((org-adapt-indentation t)
  4890. (org-src-preserve-indentation t)
  4891. (org-odd-levels-only nil))
  4892. (org-promote))
  4893. (forward-line)
  4894. (org-get-indentation))))
  4895. (should
  4896. (zerop
  4897. (org-test-with-temp-text
  4898. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  4899. (let ((org-adapt-indentation t)
  4900. (org-src-preserve-indentation t)
  4901. (org-odd-levels-only nil))
  4902. (org-promote))
  4903. (forward-line)
  4904. (org-get-indentation))))
  4905. (should
  4906. (zerop
  4907. (org-test-with-temp-text
  4908. "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
  4909. (let ((org-adapt-indentation t)
  4910. (org-src-preserve-indentation nil)
  4911. (org-odd-levels-only nil))
  4912. (org-promote))
  4913. (forward-line)
  4914. (org-get-indentation)))))
  4915. (ert-deftest test-org/org-get-valid-level ()
  4916. "Test function `org-get-valid-level' specifications."
  4917. (let ((org-odd-levels-only nil))
  4918. (should (equal 1 (org-get-valid-level 0 0)))
  4919. (should (equal 1 (org-get-valid-level 0 1)))
  4920. (should (equal 2 (org-get-valid-level 0 2)))
  4921. (should (equal 3 (org-get-valid-level 0 3)))
  4922. (should (equal 1 (org-get-valid-level 1 0)))
  4923. (should (equal 2 (org-get-valid-level 1 1)))
  4924. (should (equal 23 (org-get-valid-level 1 22)))
  4925. (should (equal 1 (org-get-valid-level 1 -1)))
  4926. (should (equal 1 (org-get-valid-level 2 -1))))
  4927. (let ((org-odd-levels-only t))
  4928. (should (equal 1 (org-get-valid-level 0 0)))
  4929. (should (equal 1 (org-get-valid-level 0 1)))
  4930. (should (equal 3 (org-get-valid-level 0 2)))
  4931. (should (equal 5 (org-get-valid-level 0 3)))
  4932. (should (equal 1 (org-get-valid-level 1 0)))
  4933. (should (equal 3 (org-get-valid-level 1 1)))
  4934. (should (equal 3 (org-get-valid-level 2 1)))
  4935. (should (equal 5 (org-get-valid-level 3 1)))
  4936. (should (equal 5 (org-get-valid-level 4 1)))
  4937. (should (equal 43 (org-get-valid-level 1 21)))
  4938. (should (equal 1 (org-get-valid-level 1 -1)))
  4939. (should (equal 1 (org-get-valid-level 2 -1)))
  4940. (should (equal 1 (org-get-valid-level 3 -1)))
  4941. (should (equal 3 (org-get-valid-level 4 -1)))
  4942. (should (equal 3 (org-get-valid-level 5 -1)))))
  4943. ;;; Planning
  4944. (ert-deftest test-org/at-planning-p ()
  4945. "Test `org-at-planning-p' specifications."
  4946. ;; Regular test.
  4947. (should
  4948. (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
  4949. (org-at-planning-p)))
  4950. (should-not
  4951. (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
  4952. (org-at-planning-p)))
  4953. ;; Correctly find planning attached to inlinetasks.
  4954. (when (featurep 'org-inlinetask)
  4955. (should
  4956. (org-test-with-temp-text
  4957. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
  4958. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4959. (should-not
  4960. (org-test-with-temp-text
  4961. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  4962. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4963. (should-not
  4964. (org-test-with-temp-text
  4965. "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  4966. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4967. (should-not
  4968. (org-test-with-temp-text
  4969. "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
  4970. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
  4971. (ert-deftest test-org/add-planning-info ()
  4972. "Test `org-add-planning-info'."
  4973. ;; Create deadline when `org-adapt-indentation' is non-nil.
  4974. (should
  4975. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4976. (org-test-with-temp-text "* H\nParagraph<point>"
  4977. (let ((org-adapt-indentation t))
  4978. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4979. (replace-regexp-in-string
  4980. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4981. nil nil 1))))
  4982. ;; Create deadline when `org-adapt-indentation' is nil.
  4983. (should
  4984. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  4985. (org-test-with-temp-text "* H\nParagraph<point>"
  4986. (let ((org-adapt-indentation nil))
  4987. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4988. (replace-regexp-in-string
  4989. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4990. nil nil 1))))
  4991. ;; Update deadline when `org-adapt-indentation' is non-nil.
  4992. (should
  4993. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4994. (org-test-with-temp-text "\
  4995. * H
  4996. DEADLINE: <2015-06-24 Wed>
  4997. Paragraph<point>"
  4998. (let ((org-adapt-indentation t))
  4999. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5000. (replace-regexp-in-string
  5001. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5002. nil nil 1))))
  5003. ;; Update deadline when `org-adapt-indentation' is nil.
  5004. (should
  5005. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  5006. (org-test-with-temp-text "\
  5007. * H
  5008. DEADLINE: <2015-06-24 Wed>
  5009. Paragraph<point>"
  5010. (let ((org-adapt-indentation nil))
  5011. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5012. (replace-regexp-in-string
  5013. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5014. nil nil 1))))
  5015. ;; Schedule when `org-adapt-indentation' is non-nil.
  5016. (should
  5017. (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
  5018. (org-test-with-temp-text "* H\nParagraph<point>"
  5019. (let ((org-adapt-indentation t))
  5020. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  5021. (replace-regexp-in-string
  5022. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5023. nil nil 1))))
  5024. ;; Schedule when `org-adapt-indentation' is nil.
  5025. (should
  5026. (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
  5027. (org-test-with-temp-text "* H\nParagraph<point>"
  5028. (let ((org-adapt-indentation nil))
  5029. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  5030. (replace-regexp-in-string
  5031. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5032. nil nil 1))))
  5033. ;; Add deadline when scheduled.
  5034. (should
  5035. (equal "\
  5036. * H
  5037. DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
  5038. Paragraph"
  5039. (org-test-with-temp-text "\
  5040. * H
  5041. SCHEDULED: <2015-06-24 Wed>
  5042. Paragraph<point>"
  5043. (let ((org-adapt-indentation t))
  5044. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5045. (replace-regexp-in-string
  5046. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5047. nil nil 1))))
  5048. ;; Remove middle entry.
  5049. (should
  5050. (equal "\
  5051. * H
  5052. CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
  5053. Paragraph"
  5054. (org-test-with-temp-text "\
  5055. * H
  5056. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  5057. Paragraph<point>"
  5058. (let ((org-adapt-indentation t))
  5059. (org-add-planning-info nil nil 'deadline))
  5060. (replace-regexp-in-string
  5061. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  5062. nil nil 1))))
  5063. ;; Remove last entry and then middle entry (order should not
  5064. ;; matter).
  5065. (should
  5066. (equal "\
  5067. * H
  5068. CLOSED: [2015-06-24]
  5069. Paragraph"
  5070. (org-test-with-temp-text "\
  5071. * H
  5072. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  5073. Paragraph<point>"
  5074. (let ((org-adapt-indentation t))
  5075. (org-add-planning-info nil nil 'scheduled 'deadline))
  5076. (replace-regexp-in-string
  5077. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  5078. nil nil 1))))
  5079. ;; Remove closed when `org-adapt-indentation' is non-nil.
  5080. (should
  5081. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5082. (org-test-with-temp-text "\
  5083. * H
  5084. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  5085. Paragraph<point>"
  5086. (let ((org-adapt-indentation t))
  5087. (org-add-planning-info nil nil 'closed))
  5088. (replace-regexp-in-string
  5089. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5090. nil nil 1))))
  5091. (should
  5092. (equal "* H\n Paragraph"
  5093. (org-test-with-temp-text "\
  5094. * H
  5095. CLOSED: [2015-06-25 Thu]
  5096. Paragraph<point>"
  5097. (let ((org-adapt-indentation t))
  5098. (org-add-planning-info nil nil 'closed))
  5099. (replace-regexp-in-string
  5100. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5101. nil nil 1))))
  5102. ;; Remove closed when `org-adapt-indentation' is nil.
  5103. (should
  5104. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  5105. (org-test-with-temp-text "\
  5106. * H
  5107. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  5108. Paragraph<point>"
  5109. (let ((org-adapt-indentation nil))
  5110. (org-add-planning-info nil nil 'closed))
  5111. (replace-regexp-in-string
  5112. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5113. nil nil 1))))
  5114. (should
  5115. (equal "* H\nParagraph"
  5116. (org-test-with-temp-text "\
  5117. * H
  5118. CLOSED: [2015-06-25 Thu]
  5119. Paragraph<point>"
  5120. (let ((org-adapt-indentation nil))
  5121. (org-add-planning-info nil nil 'closed))
  5122. (replace-regexp-in-string
  5123. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5124. nil nil 1))))
  5125. ;; Remove closed entry and delete empty line.
  5126. (should
  5127. (equal "\
  5128. * H
  5129. Paragraph"
  5130. (org-test-with-temp-text "\
  5131. * H
  5132. CLOSED: [2015-06-24 Wed]
  5133. Paragraph<point>"
  5134. (let ((org-adapt-indentation t))
  5135. (org-add-planning-info nil nil 'closed))
  5136. (replace-regexp-in-string
  5137. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5138. nil nil 1))))
  5139. ;; Remove one entry and update another.
  5140. (should
  5141. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5142. (org-test-with-temp-text "\
  5143. * H
  5144. SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
  5145. Paragraph<point>"
  5146. (let ((org-adapt-indentation t))
  5147. (org-add-planning-info 'deadline "<2015-06-25 Thu>" 'scheduled))
  5148. (replace-regexp-in-string
  5149. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5150. nil nil 1)))))
  5151. (ert-deftest test-org/deadline ()
  5152. "Test `org-deadline' specifications."
  5153. ;; Insert a new value or replace existing one.
  5154. (should
  5155. (equal "* H\nDEADLINE: <2012-03-29>"
  5156. (org-test-with-temp-text "* H"
  5157. (let ((org-adapt-indentation nil)
  5158. (org-last-inserted-timestamp nil))
  5159. (org-deadline nil "<2012-03-29 Tue>"))
  5160. (replace-regexp-in-string
  5161. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5162. nil nil 1))))
  5163. (should
  5164. (equal "* H\nDEADLINE: <2014-03-04>"
  5165. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5166. (let ((org-adapt-indentation nil)
  5167. (org-last-inserted-timestamp nil))
  5168. (org-deadline nil "<2014-03-04 Thu>"))
  5169. (replace-regexp-in-string
  5170. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5171. nil nil 1))))
  5172. ;; Accept delta time, e.g., "+2d".
  5173. (should
  5174. (equal "* H\nDEADLINE: <2015-03-04>"
  5175. (org-test-at-time "2014-03-04"
  5176. (org-test-with-temp-text "* H"
  5177. (let ((org-adapt-indentation nil)
  5178. (org-last-inserted-timestamp nil))
  5179. (org-deadline nil "+1y"))
  5180. (replace-regexp-in-string
  5181. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5182. ;; Preserve repeater.
  5183. (should
  5184. (equal "* H\nDEADLINE: <2012-03-29 +2y>"
  5185. (org-test-with-temp-text "* H"
  5186. (let ((org-adapt-indentation nil)
  5187. (org-last-inserted-timestamp nil))
  5188. (org-deadline nil "<2012-03-29 Tue +2y>"))
  5189. (replace-regexp-in-string
  5190. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5191. ;; Remove CLOSED keyword, if any.
  5192. (should
  5193. (equal "* H\nDEADLINE: <2012-03-29>"
  5194. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  5195. (let ((org-adapt-indentation nil)
  5196. (org-last-inserted-timestamp nil))
  5197. (org-deadline nil "<2012-03-29 Tue>"))
  5198. (replace-regexp-in-string
  5199. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5200. ;; With C-u argument, remove DEADLINE keyword.
  5201. (should
  5202. (equal "* H\n"
  5203. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5204. (let ((org-adapt-indentation nil)
  5205. (org-last-inserted-timestamp nil))
  5206. (org-deadline '(4)))
  5207. (buffer-string))))
  5208. (should
  5209. (equal "* H"
  5210. (org-test-with-temp-text "* H"
  5211. (let ((org-adapt-indentation nil)
  5212. (org-last-inserted-timestamp nil))
  5213. (org-deadline '(4)))
  5214. (buffer-string))))
  5215. ;; With C-u C-u argument, prompt for a delay cookie.
  5216. (should
  5217. (equal "* H\nDEADLINE: <2012-03-29 -705d>"
  5218. (cl-letf (((symbol-function 'org-read-date)
  5219. (lambda (&rest args)
  5220. (apply #'encode-time
  5221. (org-parse-time-string "2014-03-04")))))
  5222. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5223. (let ((org-adapt-indentation nil)
  5224. (org-last-inserted-timestamp nil))
  5225. (org-deadline '(16)))
  5226. (buffer-string)))))
  5227. (should-error
  5228. (cl-letf (((symbol-function 'org-read-date)
  5229. (lambda (&rest args)
  5230. (apply #'encode-time
  5231. (org-parse-time-string "2014-03-04")))))
  5232. (org-test-with-temp-text "* H"
  5233. (let ((org-adapt-indentation nil)
  5234. (org-last-inserted-timestamp nil))
  5235. (org-deadline '(16)))
  5236. (buffer-string))))
  5237. ;; When a region is active and
  5238. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5239. ;; same value in all headlines in region.
  5240. (should
  5241. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5242. (org-test-with-temp-text "* H1\n* H2"
  5243. (let ((org-adapt-indentation nil)
  5244. (org-last-inserted-timestamp nil)
  5245. (org-loop-over-headlines-in-active-region t))
  5246. (transient-mark-mode 1)
  5247. (push-mark (point) t t)
  5248. (goto-char (point-max))
  5249. (org-deadline nil "2012-03-29"))
  5250. (replace-regexp-in-string
  5251. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5252. (should-not
  5253. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5254. (org-test-with-temp-text "* H1\n* H2"
  5255. (let ((org-adapt-indentation nil)
  5256. (org-last-inserted-timestamp nil)
  5257. (org-loop-over-headlines-in-active-region nil))
  5258. (transient-mark-mode 1)
  5259. (push-mark (point) t t)
  5260. (goto-char (point-max))
  5261. (org-deadline nil "2012-03-29"))
  5262. (replace-regexp-in-string
  5263. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5264. (ert-deftest test-org/schedule ()
  5265. "Test `org-schedule' specifications."
  5266. ;; Insert a new value or replace existing one.
  5267. (should
  5268. (equal "* H\nSCHEDULED: <2012-03-29>"
  5269. (org-test-with-temp-text "* H"
  5270. (let ((org-adapt-indentation nil)
  5271. (org-last-inserted-timestamp nil))
  5272. (org-schedule nil "<2012-03-29 Tue>"))
  5273. (replace-regexp-in-string
  5274. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5275. nil nil 1))))
  5276. (should
  5277. (equal "* H\nSCHEDULED: <2014-03-04>"
  5278. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5279. (let ((org-adapt-indentation nil)
  5280. (org-last-inserted-timestamp nil))
  5281. (org-schedule nil "<2014-03-04 Thu>"))
  5282. (replace-regexp-in-string
  5283. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5284. nil nil 1))))
  5285. ;; Accept delta time, e.g., "+2d".
  5286. (should
  5287. (equal "* H\nSCHEDULED: <2015-03-04>"
  5288. (org-test-at-time "2014-03-04"
  5289. (org-test-with-temp-text "* H"
  5290. (let ((org-adapt-indentation nil)
  5291. (org-last-inserted-timestamp nil))
  5292. (org-schedule nil "+1y"))
  5293. (replace-regexp-in-string
  5294. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5295. ;; Preserve repeater.
  5296. (should
  5297. (equal "* H\nSCHEDULED: <2012-03-29 +2y>"
  5298. (org-test-with-temp-text "* H"
  5299. (let ((org-adapt-indentation nil)
  5300. (org-last-inserted-timestamp nil))
  5301. (org-schedule nil "<2012-03-29 Tue +2y>"))
  5302. (replace-regexp-in-string
  5303. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5304. ;; Remove CLOSED keyword, if any.
  5305. (should
  5306. (equal "* H\nSCHEDULED: <2012-03-29>"
  5307. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  5308. (let ((org-adapt-indentation nil)
  5309. (org-last-inserted-timestamp nil))
  5310. (org-schedule nil "<2012-03-29 Tue>"))
  5311. (replace-regexp-in-string
  5312. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5313. ;; With C-u argument, remove SCHEDULED keyword.
  5314. (should
  5315. (equal "* H\n"
  5316. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5317. (let ((org-adapt-indentation nil)
  5318. (org-last-inserted-timestamp nil))
  5319. (org-schedule '(4)))
  5320. (buffer-string))))
  5321. (should
  5322. (equal "* H"
  5323. (org-test-with-temp-text "* H"
  5324. (let ((org-adapt-indentation nil)
  5325. (org-last-inserted-timestamp nil))
  5326. (org-schedule '(4)))
  5327. (buffer-string))))
  5328. ;; With C-u C-u argument, prompt for a delay cookie.
  5329. (should
  5330. (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
  5331. (cl-letf (((symbol-function 'org-read-date)
  5332. (lambda (&rest args)
  5333. (apply #'encode-time
  5334. (org-parse-time-string "2014-03-04")))))
  5335. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5336. (let ((org-adapt-indentation nil)
  5337. (org-last-inserted-timestamp nil))
  5338. (org-schedule '(16)))
  5339. (buffer-string)))))
  5340. (should-error
  5341. (cl-letf (((symbol-function 'org-read-date)
  5342. (lambda (&rest args)
  5343. (apply #'encode-time
  5344. (org-parse-time-string "2014-03-04")))))
  5345. (org-test-with-temp-text "* H"
  5346. (let ((org-adapt-indentation nil)
  5347. (org-last-inserted-timestamp nil))
  5348. (org-schedule '(16)))
  5349. (buffer-string))))
  5350. ;; When a region is active and
  5351. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5352. ;; same value in all headlines in region.
  5353. (should
  5354. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5355. (org-test-with-temp-text "* H1\n* H2"
  5356. (let ((org-adapt-indentation nil)
  5357. (org-last-inserted-timestamp nil)
  5358. (org-loop-over-headlines-in-active-region t))
  5359. (transient-mark-mode 1)
  5360. (push-mark (point) t t)
  5361. (goto-char (point-max))
  5362. (org-schedule nil "2012-03-29"))
  5363. (replace-regexp-in-string
  5364. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5365. (should-not
  5366. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5367. (org-test-with-temp-text "* H1\n* H2"
  5368. (let ((org-adapt-indentation nil)
  5369. (org-last-inserted-timestamp nil)
  5370. (org-loop-over-headlines-in-active-region nil))
  5371. (transient-mark-mode 1)
  5372. (push-mark (point) t t)
  5373. (goto-char (point-max))
  5374. (org-schedule nil "2012-03-29"))
  5375. (replace-regexp-in-string
  5376. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5377. (should
  5378. ;; check if a repeater survives re-scheduling.
  5379. (string-match-p
  5380. "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
  5381. (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
  5382. (let ((org-adapt-indentation nil)
  5383. (org-last-inserted-timestamp nil))
  5384. (org-schedule nil "2017-02-01"))
  5385. (buffer-string)))))
  5386. ;;; Property API
  5387. (ert-deftest test-org/buffer-property-keys ()
  5388. "Test `org-buffer-property-keys' specifications."
  5389. ;; Retrieve properties across siblings.
  5390. (should
  5391. (equal '("A" "B")
  5392. (org-test-with-temp-text "
  5393. * H1
  5394. :PROPERTIES:
  5395. :A: 1
  5396. :END:
  5397. * H2
  5398. :PROPERTIES:
  5399. :B: 1
  5400. :END:"
  5401. (org-buffer-property-keys))))
  5402. ;; Retrieve properties across children.
  5403. (should
  5404. (equal '("A" "B")
  5405. (org-test-with-temp-text "
  5406. * H1
  5407. :PROPERTIES:
  5408. :A: 1
  5409. :END:
  5410. ** H2
  5411. :PROPERTIES:
  5412. :B: 1
  5413. :END:"
  5414. (org-buffer-property-keys))))
  5415. ;; Retrieve muliple properties in the same drawer.
  5416. (should
  5417. (equal '("A" "B")
  5418. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5419. (org-buffer-property-keys))))
  5420. ;; Ignore extension symbol in property name.
  5421. (should
  5422. (equal '("A")
  5423. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5424. (org-buffer-property-keys))))
  5425. ;; Add bare property if xxx_ALL property is there
  5426. (should
  5427. (equal '("A" "B" "B_ALL")
  5428. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B_ALL: foo bar\n:END:"
  5429. (org-buffer-property-keys))))
  5430. ;; Add bare property if xxx_ALL property is there - check dupes
  5431. (should
  5432. (equal '("A" "B" "B_ALL")
  5433. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:B_ALL: foo bar\n:END:"
  5434. (org-buffer-property-keys))))
  5435. ;; Retrieve properties from #+PROPERTY keyword lines
  5436. (should
  5437. (equal '("A" "C")
  5438. (org-test-with-temp-text "#+PROPERTY: C foo\n* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5439. (org-buffer-property-keys))))
  5440. ;; Retrieve properties from #+PROPERTY keyword lines - make sure an _ALL property also
  5441. ;; adds the bare property
  5442. (should
  5443. (equal '("A" "C" "C_ALL")
  5444. (org-test-with-temp-text "#+PROPERTY: C_ALL foo bar\n* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5445. (org-buffer-property-keys))))
  5446. ;; With non-nil COLUMNS, extract property names from columns.
  5447. (should
  5448. (equal '("A" "B")
  5449. (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
  5450. (org-buffer-property-keys nil nil t))))
  5451. (should
  5452. (equal '("A" "B" "COLUMNS")
  5453. (org-test-with-temp-text
  5454. "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
  5455. (org-buffer-property-keys nil nil t))))
  5456. ;; In COLUMNS, ignore title and summary-type.
  5457. (should
  5458. (equal '("A")
  5459. (org-test-with-temp-text "#+COLUMNS: %A(Foo)"
  5460. (org-buffer-property-keys nil nil t))))
  5461. (should
  5462. (equal '("A")
  5463. (org-test-with-temp-text "#+COLUMNS: %A{Foo}"
  5464. (org-buffer-property-keys nil nil t))))
  5465. (should
  5466. (equal '("A")
  5467. (org-test-with-temp-text "#+COLUMNS: %A(Foo){Bar}"
  5468. (org-buffer-property-keys nil nil t)))))
  5469. (ert-deftest test-org/property-values ()
  5470. "Test `org-property-values' specifications."
  5471. ;; Regular test.
  5472. (should
  5473. (equal '("2" "1")
  5474. (org-test-with-temp-text
  5475. "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
  5476. (org-property-values "A"))))
  5477. ;; Ignore empty values.
  5478. (should-not
  5479. (org-test-with-temp-text
  5480. "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
  5481. (org-property-values "A")))
  5482. ;; Take into consideration extended values.
  5483. (should
  5484. (equal '("1 2")
  5485. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5486. (org-property-values "A")))))
  5487. (ert-deftest test-org/set-property ()
  5488. "Test `org-set-property' specifications."
  5489. (should
  5490. (equal
  5491. ":PROPERTIES:\n:TEST: t\n:END:\n"
  5492. (org-test-with-temp-text ""
  5493. (let ((org-property-format "%s %s"))
  5494. (org-set-property "TEST" "t"))
  5495. (buffer-string))))
  5496. (should
  5497. (equal
  5498. "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5499. (org-test-with-temp-text "* H"
  5500. (let ((org-adapt-indentation nil)
  5501. (org-property-format "%s %s"))
  5502. (org-set-property "TEST" "t"))
  5503. (buffer-string)))))
  5504. (ert-deftest test-org/delete-property ()
  5505. "Test `org-delete-property' specifications."
  5506. (should
  5507. (equal
  5508. ""
  5509. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5510. (org-delete-property "TEST")
  5511. (buffer-string))))
  5512. (should
  5513. (equal
  5514. ":PROPERTIES:\n:TEST1: t\n:END:\n"
  5515. (org-test-with-temp-text ":PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5516. (org-delete-property "TEST2")
  5517. (buffer-string))))
  5518. (should
  5519. (equal
  5520. "* H\n"
  5521. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5522. (org-delete-property "TEST")
  5523. (buffer-string))))
  5524. (should
  5525. (equal
  5526. "* H\n:PROPERTIES:\n:TEST1: t\n:END:\n"
  5527. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5528. (org-delete-property "TEST2")
  5529. (buffer-string)))))
  5530. (ert-deftest test-org/delete-property-globally ()
  5531. "Test `org-delete-property-global' specifications."
  5532. (should
  5533. (equal
  5534. ""
  5535. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5536. (org-delete-property-globally "TEST")
  5537. (buffer-string))))
  5538. (should
  5539. (equal
  5540. "* H\n"
  5541. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n* H\n:PROPERTIES:\n:TEST: nil\n:END:"
  5542. (org-delete-property-globally "TEST")
  5543. (buffer-string)))))
  5544. (ert-deftest test-org/find-property ()
  5545. "Test `org-find-property' specifications."
  5546. ;; Regular test.
  5547. (should
  5548. (= 1
  5549. (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
  5550. (org-find-property "prop"))))
  5551. ;; Find properties in top-level property drawer.
  5552. (should
  5553. (= 1
  5554. (org-test-with-temp-text ":PROPERTIES:\n:PROP: value\n:END:"
  5555. (org-find-property "prop"))))
  5556. ;; Ignore false positives.
  5557. (should
  5558. (= 27
  5559. (org-test-with-temp-text
  5560. "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
  5561. (org-find-property "A"))))
  5562. ;; Return first entry found in buffer.
  5563. (should
  5564. (= 1
  5565. (org-test-with-temp-text
  5566. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5567. (org-find-property "A"))))
  5568. ;; Only search visible part of the buffer.
  5569. (should
  5570. (= 31
  5571. (org-test-with-temp-text
  5572. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5573. (org-narrow-to-subtree)
  5574. (org-find-property "A"))))
  5575. ;; With optional argument, only find entries with a specific value.
  5576. (should-not
  5577. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5578. (org-find-property "A" "2")))
  5579. (should
  5580. (= 31
  5581. (org-test-with-temp-text
  5582. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
  5583. (org-find-property "A" "2"))))
  5584. ;; Use "nil" for explicit nil values.
  5585. (should
  5586. (= 31
  5587. (org-test-with-temp-text
  5588. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
  5589. (org-find-property "A" "nil")))))
  5590. (ert-deftest test-org/entry-delete ()
  5591. "Test `org-entry-delete' specifications."
  5592. ;; Regular test.
  5593. (should
  5594. (string-match
  5595. " *:PROPERTIES:\n *:B: +2\n *:END:"
  5596. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5597. (org-entry-delete (point) "A")
  5598. (buffer-string))))
  5599. ;; Also remove accumulated properties.
  5600. (should-not
  5601. (string-match
  5602. ":A"
  5603. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
  5604. (org-entry-delete (point) "A")
  5605. (buffer-string))))
  5606. ;; When last property is removed, remove the property drawer.
  5607. (should-not
  5608. (string-match
  5609. ":PROPERTIES:"
  5610. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
  5611. (org-entry-delete (point) "A")
  5612. (buffer-string))))
  5613. ;; Return a non-nil value when some property was removed.
  5614. (should
  5615. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5616. (org-entry-delete (point) "A")))
  5617. (should-not
  5618. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5619. (org-entry-delete (point) "C")))
  5620. ;; Special properties cannot be located in a drawer. Allow to
  5621. ;; remove them anyway, in case of user error.
  5622. (should
  5623. (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
  5624. (org-entry-delete (point) "SCHEDULED"))))
  5625. (ert-deftest test-org/entry-get ()
  5626. "Test `org-entry-get' specifications."
  5627. ;; Regular test.
  5628. (should
  5629. (equal "1"
  5630. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:"
  5631. (org-entry-get (point) "A"))))
  5632. (should
  5633. (equal "1"
  5634. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5635. (org-entry-get (point) "A"))))
  5636. ;; Ignore case.
  5637. (should
  5638. (equal "1"
  5639. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5640. (org-entry-get (point) "a"))))
  5641. ;; Handle extended values, both before and after base value.
  5642. (should
  5643. (equal "1 2 3"
  5644. (org-test-with-temp-text
  5645. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5646. (org-entry-get (point) "A"))))
  5647. ;; Empty values are returned as the empty string.
  5648. (should
  5649. (equal ""
  5650. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
  5651. (org-entry-get (point) "A"))))
  5652. ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
  5653. ;; otherwise, return nil.
  5654. (should-not
  5655. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5656. (org-entry-get (point) "A")))
  5657. (should
  5658. (equal "nil"
  5659. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5660. (org-entry-get (point) "A" nil t))))
  5661. ;; Return nil when no property is found, independently on the
  5662. ;; LITERAL-NIL argument.
  5663. (should-not
  5664. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5665. (org-entry-get (point) "B")))
  5666. (should-not
  5667. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5668. (org-entry-get (point) "B" nil t)))
  5669. ;; Handle inheritance, when allowed. Include extended values and
  5670. ;; possibly global values.
  5671. (should
  5672. (equal
  5673. "1"
  5674. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:\n* H"
  5675. (org-entry-get (point-max) "A" t))))
  5676. (should
  5677. (equal
  5678. "1"
  5679. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5680. (org-entry-get (point-max) "A" t))))
  5681. (should
  5682. (equal
  5683. "1"
  5684. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5685. (let ((org-use-property-inheritance t))
  5686. (org-entry-get (point-max) "A" 'selective)))))
  5687. (should-not
  5688. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5689. (let ((org-use-property-inheritance nil))
  5690. (org-entry-get (point-max) "A" 'selective))))
  5691. (should
  5692. (equal
  5693. "1 2"
  5694. (org-test-with-temp-text
  5695. ":PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5696. (org-entry-get (point-max) "A" t))))
  5697. (should
  5698. (equal
  5699. "1 2"
  5700. (org-test-with-temp-text
  5701. "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5702. (org-entry-get (point-max) "A" t))))
  5703. (should
  5704. (equal
  5705. "1 2"
  5706. (org-test-with-temp-text
  5707. ":PROPERTIES:\n:A: 1\n:END:\n* H1\n* H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5708. (org-entry-get (point-max) "A" t))))
  5709. (should
  5710. (equal
  5711. "1 2"
  5712. (org-test-with-temp-text
  5713. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2.1\n** H2.2\n:PROPERTIES:\n:A+: 2\n:END:"
  5714. (org-entry-get (point-max) "A" t))))
  5715. (should
  5716. (equal "1"
  5717. (org-test-with-temp-text
  5718. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
  5719. (org-mode-restart)
  5720. (org-entry-get (point-max) "A" t))))
  5721. (should
  5722. (equal "0 1"
  5723. (org-test-with-temp-text
  5724. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
  5725. (org-mode-restart)
  5726. (org-entry-get (point-max) "A" t))))
  5727. ;; document level property-drawer has precedance over
  5728. ;; global-property by PROPERTY-keyword.
  5729. (should
  5730. (equal "0 2"
  5731. (org-test-with-temp-text
  5732. ":PROPERTIES:\n:A: 0\n:END:\n#+PROPERTY: A 1\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5733. (org-mode-restart)
  5734. (org-entry-get (point-max) "A" t)))))
  5735. (ert-deftest test-org/entry-properties ()
  5736. "Test `org-entry-properties' specifications."
  5737. ;; Get "ITEM" property.
  5738. (should
  5739. (equal "H"
  5740. (org-test-with-temp-text "* TODO H"
  5741. (cdr (assoc "ITEM" (org-entry-properties nil "ITEM"))))))
  5742. (should
  5743. (equal "H"
  5744. (org-test-with-temp-text "* TODO H"
  5745. (cdr (assoc "ITEM" (org-entry-properties))))))
  5746. ;; Get "TODO" property. TODO keywords are case sensitive.
  5747. (should
  5748. (equal "TODO"
  5749. (org-test-with-temp-text "* TODO H"
  5750. (cdr (assoc "TODO" (org-entry-properties nil "TODO"))))))
  5751. (should
  5752. (equal "TODO"
  5753. (org-test-with-temp-text "* TODO H"
  5754. (cdr (assoc "TODO" (org-entry-properties))))))
  5755. (should-not
  5756. (org-test-with-temp-text "* H"
  5757. (assoc "TODO" (org-entry-properties nil "TODO"))))
  5758. (should-not
  5759. (org-test-with-temp-text "* todo H"
  5760. (assoc "TODO" (org-entry-properties nil "TODO"))))
  5761. ;; Get "PRIORITY" property.
  5762. (should
  5763. (equal "A"
  5764. (org-test-with-temp-text "* [#A] H"
  5765. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  5766. (should
  5767. (equal "A"
  5768. (org-test-with-temp-text "* [#A] H"
  5769. (cdr (assoc "PRIORITY" (org-entry-properties))))))
  5770. (should
  5771. (equal (char-to-string org-priority-default)
  5772. (org-test-with-temp-text "* H"
  5773. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  5774. ;; Get "FILE" property.
  5775. (should
  5776. (org-test-with-temp-text-in-file "* H\nParagraph"
  5777. (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil "FILE")))
  5778. (buffer-file-name))))
  5779. (should
  5780. (org-test-with-temp-text-in-file "* H\nParagraph"
  5781. (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
  5782. (buffer-file-name))))
  5783. (should-not
  5784. (org-test-with-temp-text "* H\nParagraph"
  5785. (cdr (assoc "FILE" (org-entry-properties nil "FILE")))))
  5786. ;; Get "TAGS" property.
  5787. (should
  5788. (equal ":tag1:tag2:"
  5789. (org-test-with-temp-text "* H :tag1:tag2:"
  5790. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS"))))))
  5791. (should
  5792. (equal ":tag1:tag2:"
  5793. (org-test-with-temp-text "* H :tag1:tag2:"
  5794. (cdr (assoc "TAGS" (org-entry-properties))))))
  5795. (should-not
  5796. (org-test-with-temp-text "* H"
  5797. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS")))))
  5798. ;; Get "ALLTAGS" property.
  5799. (should
  5800. (equal ":tag1:tag2:"
  5801. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  5802. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS"))))))
  5803. (should
  5804. (equal ":tag1:tag2:"
  5805. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  5806. (cdr (assoc "ALLTAGS" (org-entry-properties))))))
  5807. (should-not
  5808. (org-test-with-temp-text "* H"
  5809. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS")))))
  5810. ;; Get "BLOCKED" property.
  5811. (should
  5812. (equal "t"
  5813. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  5814. (let ((org-enforce-todo-dependencies t)
  5815. (org-blocker-hook
  5816. '(org-block-todo-from-children-or-siblings-or-parent)))
  5817. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  5818. (should
  5819. (equal ""
  5820. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  5821. (let ((org-enforce-todo-dependencies t)
  5822. (org-blocker-hook
  5823. '(org-block-todo-from-children-or-siblings-or-parent)))
  5824. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  5825. ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
  5826. (should
  5827. (equal
  5828. "[2012-03-29 thu.]"
  5829. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  5830. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED"))))))
  5831. (should
  5832. (equal
  5833. "[2012-03-29 thu.]"
  5834. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  5835. (cdr (assoc "CLOSED" (org-entry-properties))))))
  5836. (should-not
  5837. (org-test-with-temp-text "* H"
  5838. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED")))))
  5839. (should
  5840. (equal
  5841. "<2014-03-04 tue.>"
  5842. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5843. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE"))))))
  5844. (should
  5845. (equal
  5846. "<2014-03-04 tue.>"
  5847. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5848. (cdr (assoc "DEADLINE" (org-entry-properties))))))
  5849. (should-not
  5850. (org-test-with-temp-text "* H"
  5851. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE")))))
  5852. (should
  5853. (equal
  5854. "<2014-03-04 tue.>"
  5855. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5856. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED"))))))
  5857. (should
  5858. (equal
  5859. "<2014-03-04 tue.>"
  5860. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5861. (cdr (assoc "SCHEDULED" (org-entry-properties))))))
  5862. (should-not
  5863. (org-test-with-temp-text "* H"
  5864. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED")))))
  5865. ;; Get "CATEGORY"
  5866. (should
  5867. (equal "cat"
  5868. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  5869. (cdr (assoc "CATEGORY" (org-entry-properties))))))
  5870. (should
  5871. (equal "cat"
  5872. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  5873. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5874. (should
  5875. (equal "cat"
  5876. (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
  5877. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5878. (should
  5879. (equal "cat2"
  5880. (org-test-with-temp-text
  5881. (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  5882. "\n"
  5883. "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
  5884. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5885. ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
  5886. (should
  5887. (equal "<2012-03-29 thu.>"
  5888. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
  5889. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  5890. (should
  5891. (equal "[2012-03-29 thu.]"
  5892. (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
  5893. (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
  5894. (should
  5895. (equal "<2012-03-29 thu.>"
  5896. (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
  5897. (cdr (assoc "TIMESTAMP" (org-entry-properties nil "TIMESTAMP"))))))
  5898. (should
  5899. (equal "[2014-03-04 tue.]"
  5900. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
  5901. (cdr (assoc "TIMESTAMP_IA"
  5902. (org-entry-properties nil "TIMESTAMP_IA"))))))
  5903. (should-not
  5904. (equal "<2012-03-29 thu.>"
  5905. (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
  5906. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  5907. ;; Get standard properties.
  5908. (should
  5909. (equal "1"
  5910. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5911. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5912. ;; Handle extended properties.
  5913. (should
  5914. (equal "1 2 3"
  5915. (org-test-with-temp-text
  5916. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5917. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5918. (should
  5919. (equal "1 2 3"
  5920. (org-test-with-temp-text
  5921. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
  5922. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5923. ;; Ignore forbidden (special) properties.
  5924. (should-not
  5925. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
  5926. (cdr (assoc "TODO" (org-entry-properties nil 'standard))))))
  5927. (ert-deftest test-org/entry-put ()
  5928. "Test `org-entry-put' specifications."
  5929. ;; Error when not a string or nil.
  5930. (should-error
  5931. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5932. (org-entry-put 1 "test" 2)))
  5933. ;; Error when property name is invalid.
  5934. (should-error
  5935. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5936. (org-entry-put 1 "no space" "value")))
  5937. (should-error
  5938. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5939. (org-entry-put 1 "" "value")))
  5940. ;; Set "TODO" property.
  5941. (should
  5942. (string-match (regexp-quote " TODO H")
  5943. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  5944. (org-entry-put (point) "TODO" "TODO")
  5945. (buffer-string))))
  5946. (should
  5947. (string-match (regexp-quote "* H")
  5948. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  5949. (org-entry-put (point) "TODO" nil)
  5950. (buffer-string))))
  5951. ;; Set "PRIORITY" property.
  5952. (should
  5953. (equal "* [#A] H"
  5954. (org-test-with-temp-text "* [#B] H"
  5955. (org-entry-put (point) "PRIORITY" "A")
  5956. (buffer-string))))
  5957. (should
  5958. (equal "* H"
  5959. (org-test-with-temp-text "* [#B] H"
  5960. (org-entry-put (point) "PRIORITY" nil)
  5961. (buffer-string))))
  5962. ;; Set "SCHEDULED" property.
  5963. (should
  5964. (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
  5965. (org-test-with-temp-text "* H"
  5966. (org-entry-put (point) "SCHEDULED" "2014-03-04")
  5967. (buffer-string))))
  5968. (should
  5969. (string= "* H\n"
  5970. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5971. (org-entry-put (point) "SCHEDULED" nil)
  5972. (buffer-string))))
  5973. (should
  5974. (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
  5975. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5976. (org-entry-put (point) "SCHEDULED" "earlier")
  5977. (buffer-string))))
  5978. (should
  5979. (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
  5980. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5981. (org-entry-put (point) "SCHEDULED" "later")
  5982. (buffer-string))))
  5983. ;; Set "DEADLINE" property.
  5984. (should
  5985. (string-match "^ *DEADLINE: <2014-03-04 .*?>"
  5986. (org-test-with-temp-text "* H"
  5987. (org-entry-put (point) "DEADLINE" "2014-03-04")
  5988. (buffer-string))))
  5989. (should
  5990. (string= "* H\n"
  5991. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5992. (org-entry-put (point) "DEADLINE" nil)
  5993. (buffer-string))))
  5994. (should
  5995. (string-match "^ *DEADLINE: <2014-03-03 .*?>"
  5996. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5997. (org-entry-put (point) "DEADLINE" "earlier")
  5998. (buffer-string))))
  5999. (should
  6000. (string-match "^ *DEADLINE: <2014-03-05 .*?>"
  6001. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6002. (org-entry-put (point) "DEADLINE" "later")
  6003. (buffer-string))))
  6004. ;; Set "CATEGORY" property
  6005. (should
  6006. (string-match "^ *:CATEGORY: cat"
  6007. (org-test-with-temp-text "* H"
  6008. (org-entry-put (point) "CATEGORY" "cat")
  6009. (buffer-string))))
  6010. ;; Regular properties, with or without pre-existing drawer.
  6011. (should
  6012. (string-match "^ *:A: +2$"
  6013. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6014. (org-entry-put (point) "A" "2")
  6015. (buffer-string))))
  6016. (should
  6017. (string-match "^ *:A: +1$"
  6018. (org-test-with-temp-text "* H"
  6019. (org-entry-put (point) "A" "1")
  6020. (buffer-string))))
  6021. ;; Special case: two consecutive headlines.
  6022. (should
  6023. (string-match "\\* A\n *:PROPERTIES:"
  6024. (org-test-with-temp-text "* A\n** B"
  6025. (org-entry-put (point) "A" "1")
  6026. (buffer-string)))))
  6027. (ert-deftest test-org/refresh-properties ()
  6028. "Test `org-refresh-properties' specifications."
  6029. (should
  6030. (equal "1"
  6031. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6032. (org-refresh-properties "A" 'org-test)
  6033. (get-text-property (point) 'org-test))))
  6034. (should-not
  6035. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6036. (org-refresh-properties "B" 'org-test)
  6037. (get-text-property (point) 'org-test)))
  6038. ;; Handle properties only defined with extension syntax, i.e.,
  6039. ;; "PROPERTY+".
  6040. (should
  6041. (equal "1"
  6042. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
  6043. (org-refresh-properties "A" 'org-test)
  6044. (get-text-property (point) 'org-test))))
  6045. ;; When property is inherited, add text property to the whole
  6046. ;; sub-tree.
  6047. (should
  6048. (equal "1"
  6049. (org-test-with-temp-text
  6050. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
  6051. (let ((org-use-property-inheritance t))
  6052. (org-refresh-properties "A" 'org-test))
  6053. (get-text-property (point) 'org-test))))
  6054. ;; When a document level property-drawer is used, those properties
  6055. ;; should work exactly like headline-properties as if at a
  6056. ;; headline-level 0.
  6057. (should
  6058. (equal "1"
  6059. (org-test-with-temp-text
  6060. ":PROPERTIES:\n:A: 1\n:END:\n"
  6061. (org-mode-restart)
  6062. (let ((org-use-property-inheritance t))
  6063. (org-refresh-properties "A" 'org-test))
  6064. (get-text-property (point) 'org-test))))
  6065. (should-not
  6066. (equal "1"
  6067. (org-test-with-temp-text
  6068. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  6069. (org-mode-restart)
  6070. (let ((org-use-property-inheritance nil))
  6071. (org-refresh-properties "A" 'org-test))
  6072. (get-text-property (point) 'org-test))))
  6073. (should
  6074. (equal "1"
  6075. (org-test-with-temp-text
  6076. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  6077. (org-mode-restart)
  6078. (let ((org-use-property-inheritance t))
  6079. (org-refresh-properties "A" 'org-test))
  6080. (get-text-property (point) 'org-test))))
  6081. (should
  6082. (equal "2"
  6083. (org-test-with-temp-text
  6084. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1\n:PROPERTIES:\n:A: 2\n:END:"
  6085. (org-mode-restart)
  6086. (let ((org-use-property-inheritance t))
  6087. (org-refresh-properties "A" 'org-test))
  6088. (get-text-property (point) 'org-test))))
  6089. ;; When property is inherited, use global value across the whole
  6090. ;; buffer. However local values have precedence, as well as the
  6091. ;; document level property-drawer.
  6092. (should-not
  6093. (equal "1"
  6094. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  6095. (org-mode-restart)
  6096. (let ((org-use-property-inheritance nil))
  6097. (org-refresh-properties "A" 'org-test))
  6098. (get-text-property (point) 'org-test))))
  6099. (should
  6100. (equal "1"
  6101. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  6102. (org-mode-restart)
  6103. (let ((org-use-property-inheritance t))
  6104. (org-refresh-properties "A" 'org-test))
  6105. (get-text-property (point) 'org-test))))
  6106. (should
  6107. (equal "2"
  6108. (org-test-with-temp-text
  6109. "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
  6110. (org-mode-restart)
  6111. (let ((org-use-property-inheritance t))
  6112. (org-refresh-properties "A" 'org-test))
  6113. (get-text-property (point) 'org-test))))
  6114. ;; When both keyword-property and document-level property-block is
  6115. ;; defined, the property-block has precedance.
  6116. (should
  6117. (equal "1"
  6118. (org-test-with-temp-text
  6119. ":PROPERTIES:\n:A: 1\n:END:\n#+PROPERTY: A 2\n<point>* H1"
  6120. (org-mode-restart)
  6121. (let ((org-use-property-inheritance t))
  6122. (org-refresh-properties "A" 'org-test))
  6123. (get-text-property (point) 'org-test)))))
  6124. (ert-deftest test-org/refresh-category-properties ()
  6125. "Test `org-refresh-category-properties' specifications"
  6126. (should
  6127. (equal "cat1"
  6128. (org-test-with-temp-text
  6129. ":PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6130. (org-refresh-category-properties)
  6131. (org-get-category))))
  6132. (should
  6133. (equal "cat1"
  6134. (org-test-with-temp-text
  6135. "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6136. (org-refresh-category-properties)
  6137. (org-get-category))))
  6138. ;; Even though property-inheritance is deactivated, category
  6139. ;; property should be inherited. As described in
  6140. ;; `org-use-property-inheritance'.
  6141. (should
  6142. (equal "cat1"
  6143. (org-test-with-temp-text
  6144. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  6145. (org-mode-restart)
  6146. (let ((org-use-property-inheritance nil))
  6147. (org-refresh-category-properties))
  6148. (org-get-category))))
  6149. (should
  6150. (equal "cat1"
  6151. (org-test-with-temp-text
  6152. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  6153. (org-mode-restart)
  6154. (let ((org-use-property-inheritance t))
  6155. (org-refresh-category-properties))
  6156. (org-get-category))))
  6157. (should
  6158. (equal "cat2"
  6159. (org-test-with-temp-text
  6160. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H\n:PROPERTIES:\n:CATEGORY: cat2\n:END:\n"
  6161. (org-mode-restart)
  6162. (let ((org-use-property-inheritance t))
  6163. (org-refresh-category-properties))
  6164. (org-get-category)))))
  6165. ;;; Refile
  6166. (ert-deftest test-org/refile-get-targets ()
  6167. "Test `org-refile-get-targets' specifications."
  6168. ;; :maxlevel includes all headings above specified value.
  6169. (should
  6170. (equal '("H1" "H2" "H3")
  6171. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6172. (let ((org-refile-use-outline-path nil)
  6173. (org-refile-targets `((nil :maxlevel . 3))))
  6174. (mapcar #'car (org-refile-get-targets))))))
  6175. (should
  6176. (equal '("H1" "H2")
  6177. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6178. (let ((org-refile-use-outline-path nil)
  6179. (org-refile-targets `((nil :maxlevel . 2))))
  6180. (mapcar #'car (org-refile-get-targets))))))
  6181. ;; :level limits targets to headlines with the specified level.
  6182. (should
  6183. (equal '("H2")
  6184. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6185. (let ((org-refile-use-outline-path nil)
  6186. (org-refile-targets `((nil :level . 2))))
  6187. (mapcar #'car (org-refile-get-targets))))))
  6188. ;; :tag limits targets to headlines with specified tag.
  6189. (should
  6190. (equal '("H1")
  6191. (org-test-with-temp-text "* H1 :foo:\n** H2\n*** H3 :bar:"
  6192. (let ((org-refile-use-outline-path nil)
  6193. (org-refile-targets `((nil :tag . "foo"))))
  6194. (mapcar #'car (org-refile-get-targets))))))
  6195. ;; :todo limits targets to headlines with specified TODO keyword.
  6196. (should
  6197. (equal '("H2")
  6198. (org-test-with-temp-text "* H1\n** TODO H2\n*** DONE H3"
  6199. (let ((org-refile-use-outline-path nil)
  6200. (org-refile-targets `((nil :todo . "TODO"))))
  6201. (mapcar #'car (org-refile-get-targets))))))
  6202. ;; :regexp filters targets matching provided regexp.
  6203. (should
  6204. (equal '("F2" "F3")
  6205. (org-test-with-temp-text "* H1\n** F2\n*** F3"
  6206. (let ((org-refile-use-outline-path nil)
  6207. (org-refile-targets `((nil :regexp . "F"))))
  6208. (mapcar #'car (org-refile-get-targets))))))
  6209. ;; A nil `org-refile-targets' includes only top level headlines in
  6210. ;; current buffer.
  6211. (should
  6212. (equal '("H1" "H2")
  6213. (org-test-with-temp-text "* H1\n** S1\n* H2"
  6214. (let ((org-refile-use-outline-path nil)
  6215. (org-refile-targets nil))
  6216. (mapcar #'car (org-refile-get-targets))))))
  6217. ;; Return value is the union of the targets according to all the
  6218. ;; defined rules. However, prevent duplicates.
  6219. (should
  6220. (equal '("F2" "F3" "H1")
  6221. (org-test-with-temp-text "* TODO H1\n** F2\n*** F3"
  6222. (let ((org-refile-use-outline-path nil)
  6223. (org-refile-targets `((nil :regexp . "F")
  6224. (nil :todo . "TODO"))))
  6225. (mapcar #'car (org-refile-get-targets))))))
  6226. (should
  6227. (equal '("F2" "F3" "H1")
  6228. (org-test-with-temp-text "* TODO H1\n** TODO F2\n*** F3"
  6229. (let ((org-refile-use-outline-path nil)
  6230. (org-refile-targets `((nil :regexp . "F")
  6231. (nil :todo . "TODO"))))
  6232. (mapcar #'car (org-refile-get-targets))))))
  6233. ;; When `org-refile-use-outline-path' is non-nil, provide targets as
  6234. ;; paths.
  6235. (should
  6236. (equal '("H1" "H1/H2" "H1/H2/H3")
  6237. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6238. (let ((org-refile-use-outline-path t)
  6239. (org-refile-targets `((nil :maxlevel . 3))))
  6240. (mapcar #'car (org-refile-get-targets))))))
  6241. ;; When providing targets as paths, escape forward slashes in
  6242. ;; headings with backslashes.
  6243. (should
  6244. (equal '("H1\\/foo")
  6245. (org-test-with-temp-text "* H1/foo"
  6246. (let ((org-refile-use-outline-path t)
  6247. (org-refile-targets `((nil :maxlevel . 1))))
  6248. (mapcar #'car (org-refile-get-targets))))))
  6249. ;; When `org-refile-use-outline-path' is `file', include file name
  6250. ;; without directory in targets.
  6251. (should
  6252. (org-test-with-temp-text-in-file "* H1"
  6253. (let* ((filename (buffer-file-name))
  6254. (org-refile-use-outline-path 'file)
  6255. (org-refile-targets `(((,filename) :level . 1))))
  6256. (member (file-name-nondirectory filename)
  6257. (mapcar #'car (org-refile-get-targets))))))
  6258. ;; When `org-refile-use-outline-path' is `full-file-path', include
  6259. ;; full file name.
  6260. (should
  6261. (org-test-with-temp-text-in-file "* H1"
  6262. (let* ((filename (file-truename (buffer-file-name)))
  6263. (org-refile-use-outline-path 'full-file-path)
  6264. (org-refile-targets `(((,filename) :level . 1))))
  6265. (member filename (mapcar #'car (org-refile-get-targets))))))
  6266. ;; When `org-refile-use-outline-path' is `buffer-name', include
  6267. ;; buffer name.
  6268. (should
  6269. (org-test-with-temp-text "* H1"
  6270. (let* ((org-refile-use-outline-path 'buffer-name)
  6271. (org-refile-targets `((nil :level . 1))))
  6272. (member (buffer-name) (mapcar #'car (org-refile-get-targets)))))))
  6273. ;;; Sparse trees
  6274. (ert-deftest test-org/match-sparse-tree ()
  6275. "Test `org-match-sparse-tree' specifications."
  6276. ;; Match tags.
  6277. (should-not
  6278. (org-test-with-temp-text "* H\n** H1 :tag:"
  6279. (org-match-sparse-tree nil "tag")
  6280. (search-forward "H1")
  6281. (org-invisible-p2)))
  6282. (should
  6283. (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
  6284. (org-match-sparse-tree nil "tag")
  6285. (search-forward "H2")
  6286. (org-invisible-p2)))
  6287. ;; "-" operator for tags.
  6288. (should-not
  6289. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6290. (org-match-sparse-tree nil "tag1-tag2")
  6291. (search-forward "H1")
  6292. (org-invisible-p2)))
  6293. (should
  6294. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6295. (org-match-sparse-tree nil "tag1-tag2")
  6296. (search-forward "H2")
  6297. (org-invisible-p2)))
  6298. ;; "&" operator for tags.
  6299. (should
  6300. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6301. (org-match-sparse-tree nil "tag1&tag2")
  6302. (search-forward "H1")
  6303. (org-invisible-p2)))
  6304. (should-not
  6305. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6306. (org-match-sparse-tree nil "tag1&tag2")
  6307. (search-forward "H2")
  6308. (org-invisible-p2)))
  6309. ;; "|" operator for tags.
  6310. (should-not
  6311. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6312. (org-match-sparse-tree nil "tag1|tag2")
  6313. (search-forward "H1")
  6314. (org-invisible-p2)))
  6315. (should-not
  6316. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6317. (org-match-sparse-tree nil "tag1|tag2")
  6318. (search-forward "H2")
  6319. (org-invisible-p2)))
  6320. ;; Regexp match on tags.
  6321. (should-not
  6322. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6323. (org-match-sparse-tree nil "{^tag.*}")
  6324. (search-forward "H1")
  6325. (org-invisible-p2)))
  6326. (should
  6327. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6328. (org-match-sparse-tree nil "{^tag.*}")
  6329. (search-forward "H2")
  6330. (org-invisible-p2)))
  6331. ;; Match group tags.
  6332. (should-not
  6333. (org-test-with-temp-text
  6334. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6335. (org-match-sparse-tree nil "work")
  6336. (search-forward "H1")
  6337. (org-invisible-p2)))
  6338. (should-not
  6339. (org-test-with-temp-text
  6340. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6341. (org-match-sparse-tree nil "work")
  6342. (search-forward "H2")
  6343. (org-invisible-p2)))
  6344. ;; Match group tags with hard brackets.
  6345. (should-not
  6346. (org-test-with-temp-text
  6347. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6348. (org-match-sparse-tree nil "work")
  6349. (search-forward "H1")
  6350. (org-invisible-p2)))
  6351. (should-not
  6352. (org-test-with-temp-text
  6353. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6354. (org-match-sparse-tree nil "work")
  6355. (search-forward "H2")
  6356. (org-invisible-p2)))
  6357. ;; Match tags in hierarchies
  6358. (should-not
  6359. (org-test-with-temp-text
  6360. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6361. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6362. #+TAGS: { Lev_3 : Lev_4 }\n
  6363. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6364. (org-match-sparse-tree nil "Lev_1")
  6365. (search-forward "H4")
  6366. (org-invisible-p2)))
  6367. (should-not
  6368. (org-test-with-temp-text
  6369. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6370. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6371. #+TAGS: { Lev_3 : Lev_4 }\n
  6372. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6373. (org-match-sparse-tree nil "Lev_1+Lev_3")
  6374. (search-forward "H4")
  6375. (org-invisible-p2)))
  6376. ;; Match regular expressions in tags
  6377. (should-not
  6378. (org-test-with-temp-text
  6379. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
  6380. (org-match-sparse-tree nil "Lev")
  6381. (search-forward "H1")
  6382. (org-invisible-p2)))
  6383. (should
  6384. (org-test-with-temp-text
  6385. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
  6386. (org-match-sparse-tree nil "Lev")
  6387. (search-forward "H1")
  6388. (org-invisible-p2)))
  6389. ;; Match properties.
  6390. (should
  6391. (org-test-with-temp-text
  6392. "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
  6393. (org-match-sparse-tree nil "A=\"1\"")
  6394. (search-forward "H2")
  6395. (org-invisible-p2)))
  6396. (should-not
  6397. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6398. (org-match-sparse-tree nil "A=\"1\"")
  6399. (search-forward "H2")
  6400. (org-invisible-p2)))
  6401. ;; Case is not significant when matching properties.
  6402. (should-not
  6403. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6404. (org-match-sparse-tree nil "a=\"1\"")
  6405. (search-forward "H2")
  6406. (org-invisible-p2)))
  6407. (should-not
  6408. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
  6409. (org-match-sparse-tree nil "A=\"1\"")
  6410. (search-forward "H2")
  6411. (org-invisible-p2)))
  6412. ;; Match special LEVEL property.
  6413. (should-not
  6414. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6415. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6416. (search-forward "H1")
  6417. (org-invisible-p2)))
  6418. (should
  6419. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6420. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6421. (search-forward "H2")
  6422. (org-invisible-p2)))
  6423. ;; Comparison operators when matching properties.
  6424. (should
  6425. (org-test-with-temp-text
  6426. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6427. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6428. (search-forward "H1")
  6429. (org-invisible-p2)))
  6430. (should-not
  6431. (org-test-with-temp-text
  6432. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6433. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6434. (search-forward "H2")
  6435. (org-invisible-p2)))
  6436. ;; Regexp match on properties values.
  6437. (should-not
  6438. (org-test-with-temp-text
  6439. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6440. (org-match-sparse-tree nil "A={f.*}")
  6441. (search-forward "H1")
  6442. (org-invisible-p2)))
  6443. (should
  6444. (org-test-with-temp-text
  6445. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6446. (org-match-sparse-tree nil "A={f.*}")
  6447. (search-forward "H2")
  6448. (org-invisible-p2)))
  6449. ;; With an optional argument, limit match to TODO entries.
  6450. (should-not
  6451. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6452. (org-match-sparse-tree t "tag")
  6453. (search-forward "H1")
  6454. (org-invisible-p2)))
  6455. (should
  6456. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6457. (org-match-sparse-tree t "tag")
  6458. (search-forward "H2")
  6459. (org-invisible-p2))))
  6460. (ert-deftest test-org/occur ()
  6461. "Test `org-occur' specifications."
  6462. ;; Count number of matches.
  6463. (should
  6464. (= 1
  6465. (org-test-with-temp-text "* H\nA\n* H2"
  6466. (org-occur "A"))))
  6467. (should
  6468. (= 2
  6469. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6470. (org-occur "A"))))
  6471. ;; Test CALLBACK optional argument.
  6472. (should
  6473. (= 0
  6474. (org-test-with-temp-text "* H\nA\n* H2"
  6475. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6476. (should
  6477. (= 1
  6478. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6479. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6480. ;; Case-fold searches according to `org-occur-case-fold-search'.
  6481. (should
  6482. (= 2
  6483. (org-test-with-temp-text "Aa"
  6484. (let ((org-occur-case-fold-search t)) (org-occur "A")))))
  6485. (should
  6486. (= 2
  6487. (org-test-with-temp-text "Aa"
  6488. (let ((org-occur-case-fold-search t)) (org-occur "a")))))
  6489. (should
  6490. (= 1
  6491. (org-test-with-temp-text "Aa"
  6492. (let ((org-occur-case-fold-search nil)) (org-occur "A")))))
  6493. (should
  6494. (= 1
  6495. (org-test-with-temp-text "Aa"
  6496. (let ((org-occur-case-fold-search nil)) (org-occur "a")))))
  6497. (should
  6498. (= 1
  6499. (org-test-with-temp-text "Aa"
  6500. (let ((org-occur-case-fold-search 'smart)) (org-occur "A")))))
  6501. (should
  6502. (= 2
  6503. (org-test-with-temp-text "Aa"
  6504. (let ((org-occur-case-fold-search 'smart)) (org-occur "a"))))))
  6505. ;;; Tags
  6506. (ert-deftest test-org/tag-string-to-alist ()
  6507. "Test `org-tag-string-to-alist' specifications."
  6508. ;; Tag without selection key.
  6509. (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
  6510. ;; Tag with selection key.
  6511. (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t))))
  6512. ;; Tag group.
  6513. (should
  6514. (equal
  6515. (org-tag-string-to-alist "[ group : t1 t2 ]")
  6516. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag))))
  6517. ;; Mutually exclusive tags.
  6518. (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
  6519. '((:startgroup) ("tag1") ("tag2") (:endgroup))))
  6520. (should
  6521. (equal
  6522. (org-tag-string-to-alist "{ group : tag1 tag2 }")
  6523. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))))
  6524. (ert-deftest test-org/tag-alist-to-string ()
  6525. "Test `org-tag-alist-to-string' specifications."
  6526. (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
  6527. (should (equal (org-tag-alist-to-string '(("tag1" . ?t))) "tag1(t)"))
  6528. (should
  6529. (equal
  6530. (org-tag-alist-to-string
  6531. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6532. "[ group : t1 t2 ]"))
  6533. (should
  6534. (equal (org-tag-alist-to-string
  6535. '((:startgroup) ("tag1") ("tag2") (:endgroup)))
  6536. "{ tag1 tag2 }"))
  6537. (should
  6538. (equal
  6539. (org-tag-alist-to-string
  6540. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))
  6541. "{ group : tag1 tag2 }")))
  6542. (ert-deftest test-org/tag-alist-to-groups ()
  6543. "Test `org-tag-alist-to-groups' specifications."
  6544. (should
  6545. (equal (org-tag-alist-to-groups
  6546. '((:startgroup) ("group") (:grouptags) ("t1") ("t2") (:endgroup)))
  6547. '(("group" "t1" "t2"))))
  6548. (should
  6549. (equal
  6550. (org-tag-alist-to-groups
  6551. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6552. '(("group" "t1" "t2"))))
  6553. (should-not
  6554. (org-tag-alist-to-groups
  6555. '((:startgroup) ("group") ("t1") ("t2") (:endgroup)))))
  6556. (ert-deftest test-org/tag-align ()
  6557. "Test tags alignment."
  6558. ;; Test aligning tags with different display width.
  6559. (should
  6560. ;; 12345678901234567890
  6561. (equal "* Test :abc:"
  6562. (org-test-with-temp-text "* Test :abc:"
  6563. (let ((org-tags-column -20)
  6564. (indent-tabs-mode nil))
  6565. (org-fix-tags-on-the-fly))
  6566. (buffer-string))))
  6567. (should
  6568. ;; 12345678901234567890
  6569. (equal "* Test :日本語:"
  6570. (org-test-with-temp-text "* Test :日本語:"
  6571. (let ((org-tags-column -20)
  6572. (indent-tabs-mode nil))
  6573. (org-fix-tags-on-the-fly))
  6574. (buffer-string))))
  6575. ;; Make sure aligning tags do not skip invisible text.
  6576. (should
  6577. (equal "* [[linkx]] :tag:"
  6578. (org-test-with-temp-text "* [[link<point>]] :tag:"
  6579. (let ((org-tags-column 0))
  6580. (org-fix-tags-on-the-fly)
  6581. (insert "x")
  6582. (buffer-string)))))
  6583. ;; Aligning tags preserve position.
  6584. (should
  6585. (= 6 (org-test-with-temp-text "* 345 <point> :tag:"
  6586. (let ((org-tags-column 78)
  6587. (indent-tabs-mode nil))
  6588. (org-fix-tags-on-the-fly))
  6589. (current-column))))
  6590. ;; Aligning all tags in visible buffer.
  6591. (should
  6592. ;; 12345678901234567890
  6593. (equal (concat "* Level 1 :abc:\n"
  6594. "** Level 2 :def:")
  6595. (org-test-with-temp-text (concat "* Level 1 :abc:\n"
  6596. "** Level 2 :def:")
  6597. (let ((org-tags-column -20)
  6598. (indent-tabs-mode nil))
  6599. ;; (org-align-tags :all) must work even when the point
  6600. ;; is at the end of the buffer.
  6601. (goto-char (point-max))
  6602. (org-align-tags :all))
  6603. (buffer-string)))))
  6604. (ert-deftest test-org/get-tags ()
  6605. "Test `org-get-tags' specifications."
  6606. ;; Standard test.
  6607. (should
  6608. (equal '("foo")
  6609. (org-test-with-temp-text "* Test :foo:" (org-get-tags))))
  6610. (should
  6611. (equal '("foo" "bar")
  6612. (org-test-with-temp-text "* Test :foo:bar:" (org-get-tags))))
  6613. ;; Tags for inlinetasks.
  6614. (should
  6615. (equal '("foo" "bar")
  6616. (progn
  6617. (require 'org-inlinetask)
  6618. (org-test-with-temp-text (concat (make-string org-inlinetask-min-level ?*) " Test :foo:bar:")
  6619. (org-get-tags (org-element-at-point))))))
  6620. (should
  6621. (equal '("foo" "bar")
  6622. (progn
  6623. (require 'org-inlinetask)
  6624. (org-test-with-temp-text (concat (make-string org-inlinetask-min-level ?*) " Test :foo:bar:")
  6625. (org-get-tags nil)))))
  6626. ;; Return nil when there is no tag.
  6627. (should-not
  6628. (org-test-with-temp-text "* Test" (org-get-tags)))
  6629. ;; Tags are inherited from parent headlines.
  6630. (should
  6631. (equal '("tag")
  6632. (let ((org-use-tag-inheritance t))
  6633. (org-test-with-temp-text "* H0 :foo:\n* H1 :tag:\n<point>** H2"
  6634. (org-get-tags)))))
  6635. ;; Tags are inherited from `org-file-tags'.
  6636. (should
  6637. (equal '("tag")
  6638. (org-test-with-temp-text "* H1"
  6639. (let ((org-file-tags '("tag"))
  6640. (org-use-tag-inheritance t))
  6641. (org-get-tags)))))
  6642. ;; Only inherited tags have the `inherited' text property.
  6643. (should
  6644. (get-text-property 0 'inherited
  6645. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6646. (let ((org-use-tag-inheritance t))
  6647. (assoc-string "foo" (org-get-tags))))))
  6648. (should-not
  6649. (get-text-property 0 'inherited
  6650. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6651. (let ((org-use-tag-inheritance t))
  6652. (assoc-string "bar" (org-get-tags))))))
  6653. ;; Obey to `org-use-tag-inheritance'.
  6654. (should-not
  6655. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6656. (let ((org-use-tag-inheritance nil))
  6657. (assoc-string "foo" (org-get-tags)))))
  6658. (should-not
  6659. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6660. (let ((org-use-tag-inheritance nil)
  6661. (org-file-tags '("foo")))
  6662. (assoc-string "foo" (org-get-tags)))))
  6663. (should-not
  6664. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6665. (let ((org-use-tag-inheritance '("bar")))
  6666. (assoc-string "foo" (org-get-tags)))))
  6667. (should
  6668. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6669. (let ((org-use-tag-inheritance '("bar")))
  6670. (assoc-string "bar" (org-get-tags)))))
  6671. (should-not
  6672. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6673. (let ((org-use-tag-inheritance "b.*"))
  6674. (assoc-string "foo" (org-get-tags)))))
  6675. (should
  6676. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6677. (let ((org-use-tag-inheritance "b.*"))
  6678. (assoc-string "bar" (org-get-tags)))))
  6679. ;; When optional argument LOCAL is non-nil, ignore tag inheritance.
  6680. (should
  6681. (equal '("baz")
  6682. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6683. (let ((org-use-tag-inheritance t))
  6684. (org-get-tags nil t)))))
  6685. ;; When optional argument POS is non-nil, get tags there instead.
  6686. (should
  6687. (equal '("foo")
  6688. (org-test-with-temp-text "* H1 :foo:\n* <point>H2 :bar:"
  6689. (org-get-tags 1))))
  6690. ;; Make sure tags excluded from inheritance are returned if local
  6691. (should
  6692. (equal '("foo")
  6693. (org-test-with-temp-text "* Test :foo:"
  6694. (let ((org-use-tag-inheritance t)
  6695. (org-tags-exclude-from-inheritance '("foo")))
  6696. (org-get-tags)))))
  6697. ;; Test the collection of tags from #+filetags and parent tags.
  6698. (should
  6699. (equal '("a" "b" "c" "d")
  6700. (org-test-with-temp-text (concat "#+filetags: a\n"
  6701. "* Level 1 :b:\n"
  6702. "** Level 2 :c:\n"
  6703. "*** Level 3 :d:\n"
  6704. "<point>")
  6705. (let ((org-use-tag-inheritance t))
  6706. (org-mode-restart) ;So that `org-file-tags' get populated from #+filetags
  6707. (org-get-tags)))))
  6708. ;; Pathological case: tagged headline with an empty body.
  6709. (should (org-test-with-temp-text "* :tag:" (org-get-tags))))
  6710. (ert-deftest test-org/set-tags ()
  6711. "Test `org-set-tags' specifications."
  6712. ;; Throw an error on invalid data.
  6713. (should-error
  6714. (org-test-with-temp-text "* H"
  6715. (org-set-tags 'foo)))
  6716. ;; `nil', an empty, and a blank string remove all tags.
  6717. (should
  6718. (equal "* H"
  6719. (org-test-with-temp-text "* H :tag1:tag2:"
  6720. (org-set-tags nil)
  6721. (buffer-string))))
  6722. (should
  6723. (equal "* H"
  6724. (org-test-with-temp-text "* H :tag1:tag2:"
  6725. (org-set-tags "")
  6726. (buffer-string))))
  6727. (should
  6728. (equal "* H"
  6729. (org-test-with-temp-text "* H :tag1:tag2:"
  6730. (org-set-tags " ")
  6731. (buffer-string))))
  6732. ;; If there's nothing to remove, just bail out.
  6733. (should
  6734. (equal "* H"
  6735. (org-test-with-temp-text "* H"
  6736. (org-set-tags nil)
  6737. (buffer-string))))
  6738. (should
  6739. (equal "* "
  6740. (org-test-with-temp-text "* "
  6741. (org-set-tags nil)
  6742. (buffer-string))))
  6743. ;; If DATA is a tag string, set current tags to it, even if it means
  6744. ;; replacing old tags.
  6745. (should
  6746. (equal "* H :tag0:"
  6747. (org-test-with-temp-text "* H :tag1:tag2:"
  6748. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  6749. (buffer-string))))
  6750. (should
  6751. (equal "* H :tag0:"
  6752. (org-test-with-temp-text "* H"
  6753. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  6754. (buffer-string))))
  6755. ;; If DATA is a list, set tags to this list, even if it means
  6756. ;; replacing old tags.
  6757. (should
  6758. (equal "* H :tag0:"
  6759. (org-test-with-temp-text "* H :tag1:tag2:"
  6760. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6761. (buffer-string))))
  6762. (should
  6763. (equal "* H :tag0:"
  6764. (org-test-with-temp-text "* H"
  6765. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6766. (buffer-string))))
  6767. ;; When set, apply `org-tags-sort-function'.
  6768. (should
  6769. (equal "* H :a:b:"
  6770. (org-test-with-temp-text "* H"
  6771. (let ((org-tags-column 1)
  6772. (org-tags-sort-function #'string<))
  6773. (org-set-tags '("b" "a"))
  6774. (buffer-string)))))
  6775. ;; When new tags are identical to the previous ones, still align.
  6776. (should
  6777. (equal "* H :foo:"
  6778. (org-test-with-temp-text "* H :foo:"
  6779. (let ((org-tags-column 1))
  6780. (org-set-tags '("foo"))
  6781. (buffer-string)))))
  6782. ;; When tags have been changed, run `org-after-tags-change-hook'.
  6783. (should
  6784. (catch :return
  6785. (org-test-with-temp-text "* H :foo:"
  6786. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  6787. (org-set-tags '("bar"))
  6788. nil))))
  6789. (should-not
  6790. (catch :return
  6791. (org-test-with-temp-text "* H :foo:"
  6792. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  6793. (org-set-tags '("foo"))
  6794. nil))))
  6795. ;; Special case: handle empty headlines.
  6796. (should
  6797. (equal "* :tag0:"
  6798. (org-test-with-temp-text "* "
  6799. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6800. (buffer-string))))
  6801. ;; Modify buffer only when a tag change happens or alignment is
  6802. ;; done.
  6803. (should-not
  6804. (org-test-with-temp-text "* H :foo:"
  6805. (set-buffer-modified-p nil)
  6806. (let ((org-tags-column 1)) (org-set-tags '("foo")))
  6807. (buffer-modified-p)))
  6808. (should
  6809. (org-test-with-temp-text "* H :foo:"
  6810. (set-buffer-modified-p nil)
  6811. (let ((org-tags-column 10)) (org-set-tags '("foo")))
  6812. (buffer-modified-p)))
  6813. (should
  6814. (org-test-with-temp-text "* H :foo:"
  6815. (set-buffer-modified-p nil)
  6816. (let ((org-tags-column 10)) (org-set-tags '("bar")))
  6817. (buffer-modified-p)))
  6818. ;; Pathological case: when setting tags of a folded headline, do not
  6819. ;; let new tags being sucked into invisibility.
  6820. (should-not
  6821. (org-test-with-temp-text "* H1\nContent\n* H2\n\n Other Content"
  6822. ;; Show only headlines
  6823. (org-content)
  6824. ;; Set NEXT tag on current entry
  6825. (org-set-tags ":NEXT:")
  6826. ;; Move point to that NEXT tag
  6827. (search-forward "NEXT") (backward-word)
  6828. ;; And it should be visible (i.e. no overlays)
  6829. (overlays-at (point)))))
  6830. (ert-deftest test-org/set-tags-command ()
  6831. "Test `org-set-tags-command' specifications"
  6832. ;; Set tags at current headline.
  6833. (should
  6834. (equal "* H1 :foo:"
  6835. (org-test-with-temp-text "* H1"
  6836. (cl-letf (((symbol-function 'completing-read-multiple)
  6837. (lambda (&rest args) '("foo"))))
  6838. (let ((org-use-fast-tag-selection nil)
  6839. (org-tags-column 1))
  6840. (org-set-tags-command)))
  6841. (buffer-string))))
  6842. ;; Preserve position when called from the section below.
  6843. (should
  6844. (equal "* H1 :foo:\nContents"
  6845. (org-test-with-temp-text "* H1\n<point>Contents"
  6846. (cl-letf (((symbol-function 'completing-read-multiple)
  6847. (lambda (&rest args) '("foo"))))
  6848. (let ((org-use-fast-tag-selection nil)
  6849. (org-tags-column 1))
  6850. (org-set-tags-command)))
  6851. (buffer-string))))
  6852. (should-not
  6853. (equal "* H1 :foo:\nContents2"
  6854. (org-test-with-temp-text "* H1\n<point>Contents2"
  6855. (cl-letf (((symbol-function 'completing-read-multiple)
  6856. (lambda (&rest args) '("foo"))))
  6857. (let ((org-use-fast-tag-selection nil)
  6858. (org-tags-column 1))
  6859. (org-set-tags-command)))
  6860. (org-at-heading-p))))
  6861. ;; When a region is active and
  6862. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  6863. ;; same value in all headlines in region.
  6864. (should
  6865. (equal "* H1 :foo:\nContents\n* H2 :foo:"
  6866. (org-test-with-temp-text "* H1\nContents\n* H2"
  6867. (cl-letf (((symbol-function 'completing-read-multiple)
  6868. (lambda (&rest args) '("foo"))))
  6869. (let ((org-use-fast-tag-selection nil)
  6870. (org-loop-over-headlines-in-active-region t)
  6871. (org-tags-column 1))
  6872. (transient-mark-mode 1)
  6873. (push-mark (point) t t)
  6874. (goto-char (point-max))
  6875. (org-set-tags-command)))
  6876. (buffer-string))))
  6877. (should
  6878. (equal "* H1\nContents\n* H2 :foo:"
  6879. (org-test-with-temp-text "* H1\nContents\n* H2"
  6880. (cl-letf (((symbol-function 'completing-read-multiple)
  6881. (lambda (&rest args) '("foo"))))
  6882. (let ((org-use-fast-tag-selection nil)
  6883. (org-loop-over-headlines-in-active-region nil)
  6884. (org-tags-column 1))
  6885. (transient-mark-mode 1)
  6886. (push-mark (point) t t)
  6887. (goto-char (point-max))
  6888. (org-set-tags-command)))
  6889. (buffer-string))))
  6890. ;; With a C-u prefix argument, align all tags in the buffer.
  6891. (should
  6892. (equal "* H1 :foo:\n* H2 :bar:"
  6893. (org-test-with-temp-text "* H1 :foo:\n* H2 :bar:"
  6894. (let ((org-tags-column 1)) (org-set-tags-command '(4)))
  6895. (buffer-string))))
  6896. ;; Point does not move with empty headline.
  6897. (should
  6898. (equal ":foo:"
  6899. (org-test-with-temp-text "* <point>"
  6900. (cl-letf (((symbol-function 'completing-read-multiple)
  6901. (lambda (&rest args) '("foo"))))
  6902. (let ((org-use-fast-tag-selection nil)
  6903. (org-tags-column 1))
  6904. (org-set-tags-command)))
  6905. (buffer-substring (point) (line-end-position)))))
  6906. ;; Point does not move at start of line.
  6907. (should
  6908. (equal "* H1 :foo:"
  6909. (org-test-with-temp-text "* H1"
  6910. (cl-letf (((symbol-function 'completing-read-multiple)
  6911. (lambda (&rest args) '("foo"))))
  6912. (let ((org-use-fast-tag-selection nil)
  6913. (org-tags-column 1))
  6914. (org-set-tags-command)))
  6915. (buffer-substring (point) (line-end-position)))))
  6916. ;; Point does not move when within *'s.
  6917. (should
  6918. (equal "* H1 :foo:"
  6919. (org-test-with-temp-text "*<point>* H1"
  6920. (cl-letf (((symbol-function 'completing-read-multiple)
  6921. (lambda (&rest args) '("foo"))))
  6922. (let ((org-use-fast-tag-selection nil)
  6923. (org-tags-column 1))
  6924. (org-set-tags-command)))
  6925. (buffer-substring (point) (line-end-position)))))
  6926. ;; Point workaround does not get fooled when looking at a space.
  6927. (should
  6928. (equal " b :foo:"
  6929. (org-test-with-temp-text "* a<point> b"
  6930. (cl-letf (((symbol-function 'completing-read-multiple)
  6931. (lambda (&rest args) '("foo"))))
  6932. (let ((org-use-fast-tag-selection nil)
  6933. (org-tags-column 1))
  6934. (org-set-tags-command)))
  6935. (buffer-substring (point) (line-end-position)))))
  6936. ;; Handle tags both set locally and inherited.
  6937. (should
  6938. (equal "b :foo:"
  6939. (org-test-with-temp-text "* a :foo:\n** <point>b :foo:"
  6940. (cl-letf (((symbol-function 'completing-read-multiple)
  6941. (lambda (prompt coll &optional pred req initial &rest args)
  6942. (list initial))))
  6943. (let ((org-use-fast-tag-selection nil)
  6944. (org-tags-column 1))
  6945. (org-set-tags-command)))
  6946. (buffer-substring (point) (line-end-position))))))
  6947. (ert-deftest test-org/toggle-tag ()
  6948. "Test `org-toggle-tag' specifications."
  6949. ;; Insert missing tag.
  6950. (should
  6951. (equal "* H :tag:"
  6952. (org-test-with-temp-text "* H"
  6953. (let ((org-tags-column 1)) (org-toggle-tag "tag"))
  6954. (buffer-string))))
  6955. (should
  6956. (equal "* H :tag1:tag2:"
  6957. (org-test-with-temp-text "* H :tag1:"
  6958. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  6959. (buffer-string))))
  6960. ;; Remove existing tag.
  6961. (should
  6962. (equal "* H"
  6963. (org-test-with-temp-text "* H :tag:"
  6964. (org-toggle-tag "tag")
  6965. (buffer-string))))
  6966. (should
  6967. (equal "* H :tag1:"
  6968. (org-test-with-temp-text "* H :tag1:tag2:"
  6969. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  6970. (buffer-string))))
  6971. (should
  6972. (equal "* H :tag2:"
  6973. (org-test-with-temp-text "* H :tag1:tag2:"
  6974. (let ((org-tags-column 1)) (org-toggle-tag "tag1"))
  6975. (buffer-string))))
  6976. ;; With optional argument ONOFF set to `on', try to insert the tag,
  6977. ;; even if its already there.
  6978. (should
  6979. (equal "* H :tag:"
  6980. (org-test-with-temp-text "* H"
  6981. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  6982. (buffer-string))))
  6983. (should
  6984. (equal "* H :tag:"
  6985. (org-test-with-temp-text "* H :tag:"
  6986. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  6987. (buffer-string))))
  6988. ;; With optional argument ONOFF set to `off', try to remove the tag,
  6989. ;; even if its not there.
  6990. (should
  6991. (equal "* H"
  6992. (org-test-with-temp-text "* H :tag:"
  6993. (org-toggle-tag "tag" 'off)
  6994. (buffer-string))))
  6995. (should
  6996. (equal "* H :tag:"
  6997. (org-test-with-temp-text "* H :tag:"
  6998. (let ((org-tags-column 1)) (org-toggle-tag "foo" 'off))
  6999. (buffer-string))))
  7000. ;; Special case: Handle properly tag inheritance. In particular, do
  7001. ;; not set inherited tags.
  7002. (should
  7003. (equal "* H1 :tag:\n** H2 :tag2:tag:"
  7004. (org-test-with-temp-text "* H1 :tag:\n** <point>H2 :tag2:"
  7005. (let ((org-use-tag-inheritance t)
  7006. (org-tags-column 1))
  7007. (org-toggle-tag "tag"))
  7008. (buffer-string))))
  7009. (should
  7010. (equal "* H1 :tag1:tag2:\n** H2 :foo:"
  7011. (org-test-with-temp-text "* H1 :tag1:tag2:\n** <point>H2"
  7012. (let ((org-use-tag-inheritance t)
  7013. (org-tags-column 1))
  7014. (org-toggle-tag "foo"))
  7015. (buffer-string)))))
  7016. (ert-deftest test-org/tags-expand ()
  7017. "Test `org-tags-expand' specifications."
  7018. ;; Expand tag groups as a regexp enclosed within curly brackets.
  7019. (should
  7020. (equal "{\\<[ABC]\\>}"
  7021. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7022. (org-mode-restart)
  7023. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  7024. (should
  7025. (equal "{\\<\\(?:Aa\\|Bb\\|Cc\\)\\>}"
  7026. (org-test-with-temp-text "#+TAGS: [ Aa : Bb Cc ]"
  7027. (org-mode-restart)
  7028. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "Aa")))))
  7029. ;; Preserve operator before the regexp.
  7030. (should
  7031. (equal "+{\\<[ABC]\\>}"
  7032. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7033. (org-mode-restart)
  7034. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "+A")))))
  7035. (should
  7036. (equal "-{\\<[ABC]\\>}"
  7037. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7038. (org-mode-restart)
  7039. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "-A")))))
  7040. ;; Handle "|" syntax.
  7041. (should
  7042. (equal "{\\<[ABC]\\>}|D"
  7043. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7044. (org-mode-restart)
  7045. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|D")))))
  7046. ;; Handle nested groups.
  7047. (should
  7048. (equal "{\\<[A-D]\\>}"
  7049. (org-test-with-temp-text "#+TAGS: [ A : B C ]\n#+TAGS: [ B : D ]"
  7050. (org-mode-restart)
  7051. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  7052. ;; Expand multiple occurrences of the same group.
  7053. (should
  7054. (equal "{\\<[ABC]\\>}|{\\<[ABC]\\>}"
  7055. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7056. (org-mode-restart)
  7057. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|A")))))
  7058. ;; Preserve regexp matches.
  7059. (should
  7060. (equal "{A+}"
  7061. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7062. (org-mode-restart)
  7063. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "{A+}"))))))
  7064. ;;; TODO keywords
  7065. (ert-deftest test-org/auto-repeat-maybe ()
  7066. "Test `org-auto-repeat-maybe' specifications."
  7067. ;; Do not auto repeat when there is no valid time stamp with
  7068. ;; a repeater in the entry.
  7069. (should-not
  7070. (string-prefix-p
  7071. "* TODO H"
  7072. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7073. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
  7074. (org-todo "DONE")
  7075. (buffer-string)))))
  7076. (should-not
  7077. (string-prefix-p
  7078. "* TODO H"
  7079. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7080. (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
  7081. (org-todo "DONE")
  7082. (buffer-string)))))
  7083. ;; When switching to DONE state, switch back to first TODO keyword
  7084. ;; in sequence, or the same keyword if they have different types.
  7085. (should
  7086. (string-prefix-p
  7087. "* TODO H"
  7088. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7089. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7090. (org-todo "DONE")
  7091. (buffer-string)))))
  7092. (should
  7093. (string-prefix-p
  7094. "* KWD1 H"
  7095. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  7096. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  7097. (org-todo "DONE")
  7098. (buffer-string)))))
  7099. (should
  7100. (string-prefix-p
  7101. "* KWD2 H"
  7102. (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
  7103. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  7104. (org-todo "DONE")
  7105. (buffer-string)))))
  7106. ;; If there was no TODO keyword in the first place, do not insert
  7107. ;; any either.
  7108. (should
  7109. (string-prefix-p
  7110. "* H"
  7111. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7112. (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
  7113. (org-todo "DONE")
  7114. (buffer-string)))))
  7115. ;; Revert to REPEAT_TO_STATE, if set.
  7116. (should
  7117. (string-prefix-p
  7118. "* KWD2 H"
  7119. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  7120. (org-test-with-temp-text
  7121. "* KWD2 H
  7122. :PROPERTIES:
  7123. :REPEAT_TO_STATE: KWD2
  7124. :END:
  7125. <2012-03-29 Thu +2y>"
  7126. (org-todo "DONE")
  7127. (buffer-string)))))
  7128. ;; When switching to DONE state, update base date. If there are
  7129. ;; multiple repeated time stamps, update them all.
  7130. (should
  7131. (string-match-p
  7132. "<2014-03-29 .* \\+2y>"
  7133. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7134. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7135. (org-todo "DONE")
  7136. (buffer-string)))))
  7137. (should
  7138. (string-match-p
  7139. "<2015-03-04 .* \\+1y>"
  7140. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7141. (org-test-with-temp-text
  7142. "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
  7143. (org-todo "DONE")
  7144. (buffer-string)))))
  7145. ;; Throw an error if repeater unit is the hour and no time is
  7146. ;; provided in the time-stamp.
  7147. (should-error
  7148. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7149. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
  7150. (org-todo "DONE")
  7151. (buffer-string))))
  7152. ;; Handle every repeater type using hours step.
  7153. (should
  7154. (string-match-p
  7155. "2014-03-04 .* 02:00"
  7156. (org-test-at-time "<2014-03-04 02:35>"
  7157. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 +8h>"
  7158. (org-todo "DONE")
  7159. (buffer-string)))))
  7160. (should
  7161. (string-match-p
  7162. "2014-03-04 .* 10:00"
  7163. (org-test-at-time "<2014-03-04 02:35>"
  7164. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 ++8h>"
  7165. (org-todo "DONE")
  7166. (buffer-string)))))
  7167. (should
  7168. (string-match-p
  7169. "2014-03-04 .* 10:35"
  7170. (org-test-at-time "<2014-03-04 02:35>"
  7171. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 .+8h>"
  7172. (org-todo "DONE")
  7173. (buffer-string)))))
  7174. ;; Do not repeat inactive time stamps with a repeater.
  7175. (should-not
  7176. (string-match-p
  7177. "\\[2014-03-29 .* \\+2y\\]"
  7178. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7179. (org-test-with-temp-text
  7180. "* TODO H\n[2012-03-29 Thu. +2y]"
  7181. (org-todo "DONE")
  7182. (buffer-string)))))
  7183. ;; Do not repeat commented time stamps.
  7184. (should-not
  7185. (string-prefix-p
  7186. "<2015-03-04 .* \\+1y>"
  7187. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7188. (org-test-with-temp-text
  7189. "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
  7190. (org-todo "DONE")
  7191. (buffer-string)))))
  7192. (should-not
  7193. (string-prefix-p
  7194. "<2015-03-04 .* \\+1y>"
  7195. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7196. (org-test-with-temp-text
  7197. "* TODO H
  7198. <2012-03-29 Thu. +2y>
  7199. #+BEGIN_EXAMPLE
  7200. <2014-03-04 Tue +1y>
  7201. #+END_EXAMPLE"
  7202. (org-todo "DONE")
  7203. (buffer-string)))))
  7204. ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
  7205. ;; entry, record time of last repeat.
  7206. (should-not
  7207. (string-match-p
  7208. ":LAST_REPEAT:"
  7209. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  7210. (org-log-repeat nil))
  7211. (cl-letf (((symbol-function 'org-add-log-setup)
  7212. (lambda (&rest args) nil)))
  7213. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  7214. (org-todo "DONE")
  7215. (buffer-string))))))
  7216. (should
  7217. (string-match-p
  7218. ":LAST_REPEAT:"
  7219. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  7220. (org-log-repeat t))
  7221. (cl-letf (((symbol-function 'org-add-log-setup)
  7222. (lambda (&rest args) nil)))
  7223. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  7224. (org-todo "DONE")
  7225. (buffer-string))))))
  7226. (should
  7227. (string-match-p
  7228. ":LAST_REPEAT:"
  7229. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7230. (cl-letf (((symbol-function 'org-add-log-setup)
  7231. (lambda (&rest args) nil)))
  7232. (org-test-with-temp-text
  7233. "* TODO H\n<2012-03-29 Thu +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
  7234. (org-todo "DONE")
  7235. (buffer-string))))))
  7236. ;; When a SCHEDULED entry has no repeater, remove it upon repeating
  7237. ;; the entry as it is no longer relevant.
  7238. (should-not
  7239. (string-match-p
  7240. "^SCHEDULED:"
  7241. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7242. (org-test-with-temp-text
  7243. "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
  7244. (org-todo "DONE")
  7245. (buffer-string)))))
  7246. ;; Properly advance repeater even when a clock entry is specified
  7247. ;; and `org-log-repeat' is nil.
  7248. (should
  7249. (string-match-p
  7250. "SCHEDULED: <2014-03-29"
  7251. (let ((org-log-repeat nil)
  7252. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7253. (org-test-with-temp-text
  7254. "* TODO H
  7255. SCHEDULED: <2012-03-29 Thu +2y>
  7256. CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] => 6:40"
  7257. (org-todo "DONE")
  7258. (buffer-string)))))
  7259. ;; Make sure that logbook state change record does not get
  7260. ;; duplicated when `org-log-repeat' `org-log-done' are non-nil.
  7261. (should
  7262. (string-match-p
  7263. (rx "* TODO Read book
  7264. SCHEDULED: <2021-06-16 Wed +1d>
  7265. :PROPERTIES:
  7266. :LAST_REPEAT:" (1+ nonl) "
  7267. :END:
  7268. - State \"DONE\" from \"TODO\"" (1+ nonl) buffer-end)
  7269. (let ((org-log-repeat 'time)
  7270. (org-todo-keywords '((sequence "TODO" "|" "DONE(d!)")))
  7271. (org-log-into-drawer nil))
  7272. (org-test-with-temp-text
  7273. "* TODO Read book
  7274. SCHEDULED: <2021-06-15 Tue +1d>"
  7275. (org-todo "DONE")
  7276. (when (memq 'org-add-log-note post-command-hook)
  7277. (org-add-log-note))
  7278. (buffer-string))))))
  7279. (ert-deftest test-org/org-log-done ()
  7280. "Test `org-log-done' specifications."
  7281. ;; nil value.
  7282. (should
  7283. (string=
  7284. "* DONE task"
  7285. (let ((org-log-done nil)
  7286. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7287. (org-test-with-temp-text
  7288. "* TODO task"
  7289. (org-todo "DONE")
  7290. (when (memq 'org-add-log-note post-command-hook)
  7291. (org-add-log-note))
  7292. (buffer-string)))))
  7293. ;; `time' value.
  7294. (should
  7295. (string=
  7296. (format
  7297. "* DONE task
  7298. CLOSED: %s"
  7299. (org-test-with-temp-text ""
  7300. (org-insert-time-stamp (current-time) t t)
  7301. (buffer-string)))
  7302. (let ((org-log-done 'time)
  7303. (org-log-done-with-time t)
  7304. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7305. (org-test-with-temp-text
  7306. "* TODO task"
  7307. (org-todo "DONE")
  7308. (when (memq 'org-add-log-note post-command-hook)
  7309. (org-add-log-note))
  7310. (buffer-string)))))
  7311. (should
  7312. (string=
  7313. (format
  7314. "* DONE task
  7315. CLOSED: %s"
  7316. (org-test-with-temp-text ""
  7317. (org-insert-time-stamp (current-time) nil t)
  7318. (buffer-string)))
  7319. (let ((org-log-done 'time)
  7320. (org-log-done-with-time nil)
  7321. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7322. (org-test-with-temp-text
  7323. "* TODO task"
  7324. (org-todo "DONE")
  7325. (when (memq 'org-add-log-note post-command-hook)
  7326. (org-add-log-note))
  7327. (buffer-string)))))
  7328. ;; TODO: Test `note' value.
  7329. ;; Test startup overrides.
  7330. (should
  7331. (string=
  7332. "#+STARTUP: nologdone
  7333. * DONE task"
  7334. (let ((org-log-done 'time)
  7335. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7336. (org-test-with-temp-text
  7337. "#+STARTUP: nologdone
  7338. <point>* TODO task"
  7339. (org-set-regexps-and-options)
  7340. (org-todo "DONE")
  7341. (when (memq 'org-add-log-note post-command-hook)
  7342. (org-add-log-note))
  7343. (buffer-string)))))
  7344. (should
  7345. (string=
  7346. (format
  7347. "#+STARTUP: logdone
  7348. * DONE task
  7349. CLOSED: %s"
  7350. (org-test-with-temp-text ""
  7351. (org-insert-time-stamp (current-time) t t)
  7352. (buffer-string)))
  7353. (let ((org-log-done nil)
  7354. (org-log-done-with-time t)
  7355. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7356. (org-test-with-temp-text
  7357. "#+STARTUP: logdone
  7358. <point>* TODO task"
  7359. (org-set-regexps-and-options)
  7360. (org-todo "DONE")
  7361. (when (memq 'org-add-log-note post-command-hook)
  7362. (org-add-log-note))
  7363. (buffer-string)))))
  7364. ;; Test local property overrides.
  7365. (should
  7366. (string=
  7367. "* DONE task
  7368. :PROPERTIES:
  7369. :LOGGING: nil
  7370. :END:"
  7371. (let ((org-log-done 'time)
  7372. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7373. (org-test-with-temp-text
  7374. "* TODO task
  7375. :PROPERTIES:
  7376. :LOGGING: nil
  7377. :END:"
  7378. (org-todo "DONE")
  7379. (when (memq 'org-add-log-note post-command-hook)
  7380. (org-add-log-note))
  7381. (buffer-string)))))
  7382. (should
  7383. (string=
  7384. (format
  7385. "* DONE task
  7386. CLOSED: %s
  7387. :PROPERTIES:
  7388. :LOGGING: logdone
  7389. :END:"
  7390. (org-test-with-temp-text ""
  7391. (org-insert-time-stamp (current-time) t t)
  7392. (buffer-string)))
  7393. (let ((org-log-done nil)
  7394. (org-log-done-with-time t)
  7395. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7396. (org-test-with-temp-text
  7397. "* TODO task
  7398. :PROPERTIES:
  7399. :LOGGING: logdone
  7400. :END:"
  7401. (org-todo "DONE")
  7402. (when (memq 'org-add-log-note post-command-hook)
  7403. (org-add-log-note))
  7404. (buffer-string))))))
  7405. ;;; Timestamps API
  7406. (ert-deftest test-org/at-timestamp-p ()
  7407. "Test `org-at-timestamp-p' specifications."
  7408. (should
  7409. (org-test-with-temp-text "<2012-03-29 Thu>"
  7410. (org-at-timestamp-p)))
  7411. (should-not
  7412. (org-test-with-temp-text "2012-03-29 Thu"
  7413. (org-at-timestamp-p)))
  7414. ;; Test return values.
  7415. (should
  7416. (eq 'bracket
  7417. (org-test-with-temp-text "<2012-03-29 Thu>"
  7418. (org-at-timestamp-p))))
  7419. (should
  7420. (eq 'year
  7421. (org-test-with-temp-text "<<point>2012-03-29 Thu>"
  7422. (org-at-timestamp-p))))
  7423. (should
  7424. (eq 'month
  7425. (org-test-with-temp-text "<2012-<point>03-29 Thu>"
  7426. (org-at-timestamp-p))))
  7427. (should
  7428. (eq 'day
  7429. (org-test-with-temp-text "<2012-03-<point>29 Thu>"
  7430. (org-at-timestamp-p))))
  7431. (should
  7432. (eq 'day
  7433. (org-test-with-temp-text "<2012-03-29 T<point>hu>"
  7434. (org-at-timestamp-p))))
  7435. (should
  7436. (wholenump
  7437. (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
  7438. (org-at-timestamp-p))))
  7439. (should
  7440. (eq 'bracket
  7441. (org-test-with-temp-text "<2012-03-29 Thu<point>>"
  7442. (org-at-timestamp-p))))
  7443. (should
  7444. (eq 'after
  7445. (org-test-with-temp-text "<2012-03-29 Thu><point>»"
  7446. (org-at-timestamp-p))))
  7447. ;; Test `inactive' optional argument.
  7448. (should
  7449. (org-test-with-temp-text "[2012-03-29 Thu]"
  7450. (org-at-timestamp-p 'inactive)))
  7451. (should-not
  7452. (org-test-with-temp-text "[2012-03-29 Thu]"
  7453. (org-at-timestamp-p)))
  7454. ;; When optional argument is `agenda', recognize time-stamps in
  7455. ;; planning info line, property drawers and clocks.
  7456. (should
  7457. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7458. (org-at-timestamp-p 'agenda)))
  7459. (should-not
  7460. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7461. (org-at-timestamp-p)))
  7462. (should
  7463. (org-test-with-temp-text
  7464. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7465. (org-at-timestamp-p 'agenda)))
  7466. (should-not
  7467. (org-test-with-temp-text
  7468. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7469. (org-at-timestamp-p)))
  7470. (should
  7471. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7472. (let ((org-agenda-include-inactive-timestamps t))
  7473. (org-at-timestamp-p 'agenda))))
  7474. (should-not
  7475. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7476. (let ((org-agenda-include-inactive-timestamps t))
  7477. (org-at-timestamp-p))))
  7478. (should-not
  7479. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7480. (let ((org-agenda-include-inactive-timestamps t))
  7481. (org-at-timestamp-p 'inactive))))
  7482. ;; When optional argument is `lax', match any part of the document
  7483. ;; with Org timestamp syntax.
  7484. (should
  7485. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7486. (org-at-timestamp-p 'lax)))
  7487. (should-not
  7488. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7489. (org-at-timestamp-p)))
  7490. (should
  7491. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7492. (org-at-timestamp-p 'lax)))
  7493. (should-not
  7494. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7495. (org-at-timestamp-p)))
  7496. (should
  7497. (org-test-with-temp-text
  7498. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7499. (org-at-timestamp-p 'lax)))
  7500. (should-not
  7501. (org-test-with-temp-text
  7502. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7503. (org-at-timestamp-p)))
  7504. ;; Optional argument `lax' also matches inactive timestamps.
  7505. (should
  7506. (org-test-with-temp-text "# [2012-03-29 Thu]<point>"
  7507. (org-at-timestamp-p 'lax))))
  7508. (ert-deftest test-org/time-stamp ()
  7509. "Test `org-time-stamp' specifications."
  7510. ;; Insert chosen time stamp at point.
  7511. (should
  7512. (string-match
  7513. "Te<2014-03-04 .*?>xt"
  7514. (org-test-with-temp-text "Te<point>xt"
  7515. (cl-letf (((symbol-function 'org-read-date)
  7516. (lambda (&rest args)
  7517. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7518. (org-time-stamp nil)
  7519. (buffer-string)))))
  7520. ;; With a prefix argument, also insert time.
  7521. (should
  7522. (string-match
  7523. "Te<2014-03-04 .*? 00:41>xt"
  7524. (org-test-with-temp-text "Te<point>xt"
  7525. (cl-letf (((symbol-function 'org-read-date)
  7526. (lambda (&rest args)
  7527. (apply #'encode-time
  7528. (org-parse-time-string "2014-03-04 00:41")))))
  7529. (org-time-stamp '(4))
  7530. (buffer-string)))))
  7531. ;; With two universal prefix arguments, insert an active timestamp
  7532. ;; with the current time without prompting the user.
  7533. (should
  7534. (string-match
  7535. "Te<2014-03-04 .*? 00:41>xt"
  7536. (org-test-with-temp-text "Te<point>xt"
  7537. (org-test-at-time "2014-03-04 00:41"
  7538. (org-time-stamp '(16))
  7539. (buffer-string)))))
  7540. ;; When optional argument is non-nil, insert an inactive timestamp.
  7541. (should
  7542. (string-match
  7543. "Te\\[2014-03-04 .*?\\]xt"
  7544. (org-test-with-temp-text "Te<point>xt"
  7545. (cl-letf (((symbol-function 'org-read-date)
  7546. (lambda (&rest args)
  7547. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7548. (org-time-stamp nil t)
  7549. (buffer-string)))))
  7550. ;; When called from a timestamp, replace existing one.
  7551. (should
  7552. (string-match
  7553. "<2014-03-04 .*?>"
  7554. (org-test-with-temp-text "<2012-03-29<point> thu.>"
  7555. (cl-letf (((symbol-function 'org-read-date)
  7556. (lambda (&rest args)
  7557. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7558. (org-time-stamp nil)
  7559. (buffer-string)))))
  7560. (should
  7561. (string-match
  7562. "<2014-03-04 .*?>--<2014-03-04 .*?>"
  7563. (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
  7564. (cl-letf (((symbol-function 'org-read-date)
  7565. (lambda (&rest args)
  7566. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7567. (org-time-stamp nil)
  7568. (buffer-string)))))
  7569. ;; When replacing a timestamp, preserve repeater, if any.
  7570. (should
  7571. (string-match
  7572. "<2014-03-04 .*? \\+2y>"
  7573. (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
  7574. (cl-letf (((symbol-function 'org-read-date)
  7575. (lambda (&rest args)
  7576. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7577. (org-time-stamp nil)
  7578. (buffer-string)))))
  7579. ;; When called twice in a raw, build a date range.
  7580. (should
  7581. (string-match
  7582. "<2012-03-29 .*?>--<2014-03-04 .*?>"
  7583. (org-test-with-temp-text "<2012-03-29 thu.><point>"
  7584. (cl-letf (((symbol-function 'org-read-date)
  7585. (lambda (&rest args)
  7586. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7587. (let ((last-command 'org-time-stamp)
  7588. (this-command 'org-time-stamp))
  7589. (org-time-stamp nil))
  7590. (buffer-string))))))
  7591. (ert-deftest test-org/timestamp-has-time-p ()
  7592. "Test `org-timestamp-has-time-p' specifications."
  7593. ;; With time.
  7594. (should
  7595. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7596. (org-timestamp-has-time-p (org-element-context))))
  7597. ;; Without time.
  7598. (should-not
  7599. (org-test-with-temp-text "<2012-03-29 Thu>"
  7600. (org-timestamp-has-time-p (org-element-context)))))
  7601. (ert-deftest test-org/get-repeat ()
  7602. "Test `org-get-repeat' specifications."
  7603. (should
  7604. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
  7605. (org-get-repeat)))
  7606. (should-not
  7607. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
  7608. (org-get-repeat)))
  7609. ;; Return proper repeat string.
  7610. (should
  7611. (equal "+2y"
  7612. (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
  7613. (org-get-repeat))))
  7614. ;; Prevent false positive (commented or verbatim time stamps)
  7615. (should-not
  7616. (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
  7617. (org-get-repeat)))
  7618. (should-not
  7619. (org-test-with-temp-text
  7620. "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
  7621. (org-get-repeat)))
  7622. ;; Return nil when called before first heading.
  7623. (should-not
  7624. (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
  7625. (org-get-repeat)))
  7626. ;; When called with an optional argument, extract repeater from that
  7627. ;; string instead.
  7628. (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
  7629. (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
  7630. (ert-deftest test-org/timestamp-format ()
  7631. "Test `org-timestamp-format' specifications."
  7632. ;; Regular test.
  7633. (should
  7634. (equal
  7635. "2012-03-29 16:40"
  7636. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7637. (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
  7638. ;; Range end.
  7639. (should
  7640. (equal
  7641. "2012-03-29"
  7642. (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
  7643. (org-timestamp-format (org-element-context) "%Y-%m-%d" t)))))
  7644. (ert-deftest test-org/timestamp-split-range ()
  7645. "Test `org-timestamp-split-range' specifications."
  7646. ;; Extract range start (active).
  7647. (should
  7648. (equal '(2012 3 29)
  7649. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7650. (let ((ts (org-timestamp-split-range (org-element-context))))
  7651. (mapcar (lambda (p) (org-element-property p ts))
  7652. '(:year-end :month-end :day-end))))))
  7653. ;; Extract range start (inactive)
  7654. (should
  7655. (equal '(2012 3 29)
  7656. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7657. (let ((ts (org-timestamp-split-range (org-element-context))))
  7658. (mapcar (lambda (p) (org-element-property p ts))
  7659. '(:year-end :month-end :day-end))))))
  7660. ;; Extract range end (active).
  7661. (should
  7662. (equal '(2012 3 30)
  7663. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7664. (let ((ts (org-timestamp-split-range
  7665. (org-element-context) t)))
  7666. (mapcar (lambda (p) (org-element-property p ts))
  7667. '(:year-end :month-end :day-end))))))
  7668. ;; Extract range end (inactive)
  7669. (should
  7670. (equal '(2012 3 30)
  7671. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7672. (let ((ts (org-timestamp-split-range
  7673. (org-element-context) t)))
  7674. (mapcar (lambda (p) (org-element-property p ts))
  7675. '(:year-end :month-end :day-end))))))
  7676. ;; Return the timestamp if not a range.
  7677. (should
  7678. (org-test-with-temp-text "[2012-03-29 Thu]"
  7679. (let* ((ts-orig (org-element-context))
  7680. (ts-copy (org-timestamp-split-range ts-orig)))
  7681. (eq ts-orig ts-copy))))
  7682. (should
  7683. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7684. (let* ((ts-orig (org-element-context))
  7685. (ts-copy (org-timestamp-split-range ts-orig)))
  7686. (eq ts-orig ts-copy)))))
  7687. (ert-deftest test-org/timestamp-translate ()
  7688. "Test `org-timestamp-translate' specifications."
  7689. ;; Translate whole date range.
  7690. (should
  7691. (equal "<29>--<30>"
  7692. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7693. (let ((org-display-custom-times t)
  7694. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7695. (org-timestamp-translate (org-element-context))))))
  7696. ;; Translate date range start.
  7697. (should
  7698. (equal "<29>"
  7699. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7700. (let ((org-display-custom-times t)
  7701. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7702. (org-timestamp-translate (org-element-context) 'start)))))
  7703. ;; Translate date range end.
  7704. (should
  7705. (equal "<30>"
  7706. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7707. (let ((org-display-custom-times t)
  7708. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7709. (org-timestamp-translate (org-element-context) 'end)))))
  7710. ;; Translate time range.
  7711. (should
  7712. (equal "<08>--<16>"
  7713. (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
  7714. (let ((org-display-custom-times t)
  7715. (org-time-stamp-custom-formats '("<%d>" . "<%H>")))
  7716. (org-timestamp-translate (org-element-context))))))
  7717. ;; Translate non-range timestamp.
  7718. (should
  7719. (equal "<29>"
  7720. (org-test-with-temp-text "<2012-03-29 Thu>"
  7721. (let ((org-display-custom-times t)
  7722. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7723. (org-timestamp-translate (org-element-context))))))
  7724. ;; Do not change `diary' timestamps.
  7725. (should
  7726. (equal "<%%(org-float t 4 2)>"
  7727. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7728. (let ((org-display-custom-times t)
  7729. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7730. (org-timestamp-translate (org-element-context)))))))
  7731. (ert-deftest test-org/timestamp-from-string ()
  7732. "Test `org-timestamp-from-string' specifications."
  7733. ;; Return nil if argument is not a valid Org timestamp.
  7734. (should-not (org-timestamp-from-string ""))
  7735. (should-not (org-timestamp-from-string nil))
  7736. (should-not (org-timestamp-from-string "<2012-03-29"))
  7737. ;; Otherwise, return a valid Org timestamp object.
  7738. (should
  7739. (string-match-p "<2012-03-29 .+>"
  7740. (org-element-interpret-data
  7741. (org-timestamp-from-string "<2012-03-29 Thu>"))))
  7742. (should
  7743. (string-match-p "[2014-03-04 .+]"
  7744. (org-element-interpret-data
  7745. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  7746. (ert-deftest test-org/timestamp-from-time ()
  7747. "Test `org-timestamp-from-time' specifications."
  7748. ;; Standard test.
  7749. (should
  7750. (string-match-p
  7751. "<2012-03-29 .+>"
  7752. (org-element-interpret-data
  7753. (org-timestamp-from-time
  7754. (apply #'encode-time
  7755. (org-parse-time-string "<2012-03-29 Thu 16:40>"))))))
  7756. ;; When optional argument WITH-TIME is non-nil, provide time
  7757. ;; information.
  7758. (should
  7759. (string-match-p
  7760. "<2012-03-29 .+ 16:40>"
  7761. (org-element-interpret-data
  7762. (org-timestamp-from-time
  7763. (apply #'encode-time
  7764. (org-parse-time-string "<2012-03-29 Thu 16:40>"))
  7765. t))))
  7766. ;; When optional argument INACTIVE is non-nil, return an inactive
  7767. ;; timestamp.
  7768. (should
  7769. (string-match-p
  7770. "[2012-03-29 .+]"
  7771. (org-element-interpret-data
  7772. (org-timestamp-from-time
  7773. (apply #'encode-time
  7774. (org-parse-time-string "<2012-03-29 Thu 16:40>"))
  7775. nil t)))))
  7776. (ert-deftest test-org/timestamp-to-time ()
  7777. "Test `org-timestamp-to-time' specifications."
  7778. (should
  7779. (equal "2014-03-04"
  7780. (format-time-string
  7781. "%Y-%m-%d"
  7782. (org-timestamp-to-time
  7783. (org-timestamp-from-string "<2014-03-04 Tue>")))))
  7784. (should
  7785. (equal "2014-03-04"
  7786. (format-time-string
  7787. "%Y-%m-%d"
  7788. (org-timestamp-to-time
  7789. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  7790. (should
  7791. (equal "2012-03-29 08:30"
  7792. (format-time-string
  7793. "%Y-%m-%d %H:%M"
  7794. (org-timestamp-to-time
  7795. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")))))
  7796. (should
  7797. (equal "2012-03-29"
  7798. (format-time-string
  7799. "%Y-%m-%d"
  7800. (org-timestamp-to-time
  7801. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")))))
  7802. (should
  7803. (equal "2012-03-29"
  7804. (format-time-string
  7805. "%Y-%m-%d"
  7806. (org-timestamp-to-time
  7807. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")))))
  7808. ;; When optional argument END is non-nil, use end of date range or
  7809. ;; time range.
  7810. (should
  7811. (equal "2012-03-29 16:40"
  7812. (format-time-string
  7813. "%Y-%m-%d %H:%M"
  7814. (org-timestamp-to-time
  7815. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")
  7816. t))))
  7817. (should
  7818. (equal "2014-03-04"
  7819. (format-time-string
  7820. "%Y-%m-%d"
  7821. (org-timestamp-to-time
  7822. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")
  7823. t))))
  7824. (should
  7825. (equal "2014-03-04"
  7826. (format-time-string
  7827. "%Y-%m-%d"
  7828. (org-timestamp-to-time
  7829. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")
  7830. t)))))
  7831. ;;; Visibility
  7832. (ert-deftest test-org/hide-drawer-toggle ()
  7833. "Test `org-hide-drawer-toggle' specifications."
  7834. ;; Error when not at a drawer.
  7835. (should-error
  7836. (org-test-with-temp-text ":fake-drawer:\ncontents"
  7837. (org-hide-drawer-toggle 'off)
  7838. (get-char-property (line-end-position) 'invisible)))
  7839. (should-error
  7840. (org-test-with-temp-text
  7841. "#+begin_example\n<point>:D:\nc\n:END:\n#+end_example"
  7842. (org-hide-drawer-toggle t)))
  7843. ;; Hide drawer.
  7844. (should
  7845. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7846. (org-hide-drawer-toggle)
  7847. (get-char-property (line-end-position) 'invisible)))
  7848. ;; Show drawer unconditionally when optional argument is `off'.
  7849. (should-not
  7850. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7851. (org-hide-drawer-toggle)
  7852. (org-hide-drawer-toggle 'off)
  7853. (get-char-property (line-end-position) 'invisible)))
  7854. ;; Hide drawer unconditionally when optional argument is non-nil.
  7855. (should
  7856. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7857. (org-hide-drawer-toggle t)
  7858. (get-char-property (line-end-position) 'invisible)))
  7859. ;; Do not hide drawer when called from final blank lines.
  7860. (should-not
  7861. (org-test-with-temp-text ":drawer:\ncontents\n:end:\n\n<point>"
  7862. (org-hide-drawer-toggle)
  7863. (goto-char (point-min))
  7864. (get-char-property (line-end-position) 'invisible)))
  7865. ;; Don't leave point in an invisible part of the buffer when hiding
  7866. ;; a drawer away.
  7867. (should-not
  7868. (org-test-with-temp-text ":drawer:\ncontents\n<point>:end:"
  7869. (org-hide-drawer-toggle)
  7870. (get-char-property (point) 'invisible))))
  7871. (ert-deftest test-org/hide-block-toggle ()
  7872. "Test `org-hide-block-toggle' specifications."
  7873. ;; Error when not at a block.
  7874. (should-error
  7875. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
  7876. (org-hide-block-toggle 'off)
  7877. (get-char-property (line-end-position) 'invisible)))
  7878. ;; Hide block.
  7879. (should
  7880. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  7881. (org-hide-block-toggle)
  7882. (get-char-property (line-end-position) 'invisible)))
  7883. (should
  7884. (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
  7885. (org-hide-block-toggle)
  7886. (get-char-property (line-end-position) 'invisible)))
  7887. ;; Show block unconditionally when optional argument is `off'.
  7888. (should-not
  7889. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7890. (org-hide-block-toggle)
  7891. (org-hide-block-toggle 'off)
  7892. (get-char-property (line-end-position) 'invisible)))
  7893. (should-not
  7894. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7895. (org-hide-block-toggle 'off)
  7896. (get-char-property (line-end-position) 'invisible)))
  7897. ;; Hide block unconditionally when optional argument is non-nil.
  7898. (should
  7899. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7900. (org-hide-block-toggle t)
  7901. (get-char-property (line-end-position) 'invisible)))
  7902. (should
  7903. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7904. (org-hide-block-toggle)
  7905. (org-hide-block-toggle t)
  7906. (get-char-property (line-end-position) 'invisible)))
  7907. ;; Do not hide block when called from final blank lines.
  7908. (should-not
  7909. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
  7910. (org-hide-block-toggle)
  7911. (goto-char (point-min))
  7912. (get-char-property (line-end-position) 'invisible)))
  7913. ;; Don't leave point in an invisible part of the buffer when hiding
  7914. ;; a block away.
  7915. (should-not
  7916. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
  7917. (org-hide-block-toggle)
  7918. (get-char-property (point) 'invisible))))
  7919. (ert-deftest test-org/hide-block-toggle-maybe ()
  7920. "Test `org-hide-block-toggle-maybe' specifications."
  7921. (should
  7922. (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
  7923. (org-hide-block-toggle-maybe)))
  7924. (should-not
  7925. (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
  7926. (ert-deftest test-org/show-set-visibility ()
  7927. "Test `org-show-set-visibility' specifications."
  7928. ;; Do not throw an error before first heading.
  7929. (should
  7930. (org-test-with-temp-text "Preamble\n* Headline"
  7931. (org-show-set-visibility 'tree)
  7932. t))
  7933. ;; Test all visibility spans, both on headline and in entry.
  7934. (let ((list-visible-lines
  7935. (lambda (state headerp)
  7936. (org-test-with-temp-text "* Grandmother (0)
  7937. ** Uncle (1)
  7938. *** Heir (2)
  7939. ** Father (3)
  7940. Ancestor text (4)
  7941. *** Sister (5)
  7942. Sibling text (6)
  7943. *** Self (7)
  7944. Match (8)
  7945. **** First born (9)
  7946. Child text (10)
  7947. **** The other child (11)
  7948. *** Brother (12)
  7949. ** Aunt (13)
  7950. "
  7951. (org-cycle t)
  7952. (search-forward (if headerp "Self" "Match"))
  7953. (org-show-set-visibility state)
  7954. (goto-char (point-min))
  7955. (let (result (line 0))
  7956. (while (not (eobp))
  7957. (unless (org-invisible-p2) (push line result))
  7958. (cl-incf line)
  7959. (forward-line))
  7960. (nreverse result))))))
  7961. (should (equal '(0 7) (funcall list-visible-lines 'minimal t)))
  7962. (should (equal '(0 7 8) (funcall list-visible-lines 'minimal nil)))
  7963. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local t)))
  7964. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local nil)))
  7965. (should (equal '(0 3 7) (funcall list-visible-lines 'ancestors t)))
  7966. (should (equal '(0 3 7 8) (funcall list-visible-lines 'ancestors nil)))
  7967. (should (equal '(0 3 7 8 9 10 11)
  7968. (funcall list-visible-lines 'ancestors-full t)))
  7969. (should (equal '(0 3 7 8 9 10 11)
  7970. (funcall list-visible-lines 'ancestors-full nil)))
  7971. (should (equal '(0 3 5 7 12) (funcall list-visible-lines 'lineage t)))
  7972. (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines 'lineage nil)))
  7973. (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines 'tree t)))
  7974. (should (equal '(0 1 3 5 7 8 9 11 12 13)
  7975. (funcall list-visible-lines 'tree nil)))
  7976. (should (equal '(0 1 3 4 5 7 12 13)
  7977. (funcall list-visible-lines 'canonical t)))
  7978. (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
  7979. (funcall list-visible-lines 'canonical nil))))
  7980. ;; When point is hidden in a drawer or a block, make sure to make it
  7981. ;; visible.
  7982. (should-not
  7983. (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
  7984. (org-hide-block-toggle)
  7985. (search-forward "Text")
  7986. (org-show-set-visibility 'minimal)
  7987. (org-invisible-p2)))
  7988. (should-not
  7989. (org-test-with-temp-text ":DRAWER:\nText\n:END:"
  7990. (org-hide-drawer-toggle)
  7991. (search-forward "Text")
  7992. (org-show-set-visibility 'minimal)
  7993. (org-invisible-p2)))
  7994. (should-not
  7995. (org-test-with-temp-text
  7996. "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
  7997. (org-hide-drawer-toggle)
  7998. (forward-line -1)
  7999. (org-hide-block-toggle)
  8000. (search-forward "Text")
  8001. (org-show-set-visibility 'minimal)
  8002. (org-invisible-p2))))
  8003. (defun test-org/copy-visible ()
  8004. "Test `org-copy-visible' specifications."
  8005. (should
  8006. (equal "Foo"
  8007. (org-test-with-temp-text "Foo"
  8008. (let ((kill-ring nil))
  8009. (org-copy-visible (point-min) (point-max))
  8010. (current-kill 0 t)))))
  8011. ;; Skip invisible characters by text property.
  8012. (should
  8013. (equal "Foo"
  8014. (org-test-with-temp-text #("F<hidden>oo" 1 7 (invisible t))
  8015. (let ((kill-ring nil))
  8016. (org-copy-visible (point-min) (point-max))
  8017. (current-kill 0 t)))))
  8018. ;; Skip invisible characters by overlay.
  8019. (should
  8020. (equal "Foo"
  8021. (org-test-with-temp-text "F<hidden>oo"
  8022. (let ((o (make-overlay 2 10)))
  8023. (overlay-put o 'invisible t))
  8024. (let ((kill-ring nil))
  8025. (org-copy-visible (point-min) (point-max))
  8026. (current-kill 0 t)))))
  8027. ;; Handle invisible characters at the beginning and the end of the
  8028. ;; buffer.
  8029. (should
  8030. (equal "Foo"
  8031. (org-test-with-temp-text #("<hidden>Foo" 0 8 (invisible t))
  8032. (let ((kill-ring nil))
  8033. (org-copy-visible (point-min) (point-max))
  8034. (current-kill 0 t)))))
  8035. (should
  8036. (equal "Foo"
  8037. (org-test-with-temp-text #("Foo<hidden>" 3 11 (invisible t))
  8038. (let ((kill-ring nil))
  8039. (org-copy-visible (point-min) (point-max))
  8040. (current-kill 0 t)))))
  8041. ;; Handle multiple visible parts.
  8042. (should
  8043. (equal "abc"
  8044. (org-test-with-temp-text
  8045. #("aXbXc" 1 2 (invisible t) 3 4 (invisible t))
  8046. (let ((kill-ring nil))
  8047. (org-copy-visible (point-min) (point-max))
  8048. (current-kill 0 t))))))
  8049. (ert-deftest test-org/set-visibility-according-to-property ()
  8050. "Test `org-set-visibility-according-to-property' specifications."
  8051. ;; "folded" state.
  8052. (should
  8053. (org-test-with-temp-text
  8054. "
  8055. * a
  8056. :PROPERTIES:
  8057. :VISIBILITY: folded
  8058. :END:
  8059. ** <point>b"
  8060. (org-set-visibility-according-to-property)
  8061. (invisible-p (point))))
  8062. ;; "children" state.
  8063. (should
  8064. (org-test-with-temp-text
  8065. "
  8066. * a
  8067. :PROPERTIES:
  8068. :VISIBILITY: children
  8069. :END:
  8070. ** b
  8071. <point>Contents
  8072. ** c"
  8073. (org-set-visibility-according-to-property)
  8074. (invisible-p (point))))
  8075. (should
  8076. (org-test-with-temp-text
  8077. "
  8078. * a
  8079. :PROPERTIES:
  8080. :VISIBILITY: children
  8081. :END:
  8082. ** b
  8083. Contents
  8084. *** <point>c"
  8085. (org-set-visibility-according-to-property)
  8086. (invisible-p (point))))
  8087. ;; "content" state.
  8088. (should
  8089. (org-test-with-temp-text
  8090. "
  8091. * a
  8092. :PROPERTIES:
  8093. :VISIBILITY: content
  8094. :END:
  8095. ** b
  8096. <point>Contents
  8097. *** c"
  8098. (org-set-visibility-according-to-property)
  8099. (invisible-p (point))))
  8100. (should
  8101. (org-test-with-temp-text
  8102. "
  8103. * a
  8104. :PROPERTIES:
  8105. :VISIBILITY: content
  8106. :END:
  8107. ** b
  8108. Contents
  8109. *** <point>c"
  8110. (org-set-visibility-according-to-property)
  8111. (not (invisible-p (point)))))
  8112. ;; "showall" state.
  8113. (should
  8114. (org-test-with-temp-text
  8115. "
  8116. * a
  8117. :PROPERTIES:
  8118. :VISIBILITY: showall
  8119. :END:
  8120. ** b
  8121. <point>Contents
  8122. *** c"
  8123. (org-set-visibility-according-to-property)
  8124. (not (invisible-p (point)))))
  8125. (should
  8126. (org-test-with-temp-text
  8127. "
  8128. * a
  8129. :PROPERTIES:
  8130. :VISIBILITY: showall
  8131. :END:
  8132. ** b
  8133. Contents
  8134. *** <point>c"
  8135. (org-set-visibility-according-to-property)
  8136. (not (invisible-p (point)))))
  8137. ;; When VISIBILITY properties are nested, ignore inner ones.
  8138. (should
  8139. (org-test-with-temp-text
  8140. "
  8141. * A
  8142. :PROPERTIES:
  8143. :VISIBILITY: folded
  8144. :END:
  8145. ** <point>B
  8146. :PROPERTIES:
  8147. :VISIBILITY: folded
  8148. :END:"
  8149. (org-set-visibility-according-to-property)
  8150. (invisible-p (point)))))
  8151. (ert-deftest test-org/visibility-show-branches ()
  8152. "Test visibility of inline archived subtrees."
  8153. (org-test-with-temp-text
  8154. "* Foo<point>
  8155. ** Bar :ARCHIVE:
  8156. *** Baz
  8157. "
  8158. (org-kill-note-or-show-branches)
  8159. (should (org-invisible-p (- (point-max) 2)))))
  8160. ;;; Yank and Kill
  8161. (ert-deftest test-org/paste-subtree ()
  8162. "Test `org-paste-subtree' specifications."
  8163. ;; Return an error if text to yank is not a set of subtrees.
  8164. (should-error (org-paste-subtree nil "Text"))
  8165. ;; Adjust level according to current one.
  8166. (should
  8167. (equal "* H\n* Text\n"
  8168. (org-test-with-temp-text "* H\n<point>"
  8169. (org-paste-subtree nil "* Text")
  8170. (buffer-string))))
  8171. (should
  8172. (equal "* H1\n** H2\n** Text\n"
  8173. (org-test-with-temp-text "* H1\n** H2\n<point>"
  8174. (org-paste-subtree nil "* Text")
  8175. (buffer-string))))
  8176. ;; When not on a heading, move to next heading before yanking.
  8177. (should
  8178. (equal "* H1\nParagraph\n* Text\n* H2"
  8179. (org-test-with-temp-text "* H1\n<point>Paragraph\n* H2"
  8180. (org-paste-subtree nil "* Text")
  8181. (buffer-string))))
  8182. ;; If point is between two headings, use the deepest level.
  8183. (should
  8184. (equal "* H1\n\n* Text\n* H2"
  8185. (org-test-with-temp-text "* H1\n<point>\n* H2"
  8186. (org-paste-subtree nil "* Text")
  8187. (buffer-string))))
  8188. (should
  8189. (equal "** H1\n\n** Text\n* H2"
  8190. (org-test-with-temp-text "** H1\n<point>\n* H2"
  8191. (org-paste-subtree nil "* Text")
  8192. (buffer-string))))
  8193. (should
  8194. (equal "* H1\n\n** Text\n** H2"
  8195. (org-test-with-temp-text "* H1\n<point>\n** H2"
  8196. (org-paste-subtree nil "* Text")
  8197. (buffer-string))))
  8198. ;; When on an empty heading, after the stars, deduce the new level
  8199. ;; from the number of stars.
  8200. (should
  8201. (equal "*** Text\n"
  8202. (org-test-with-temp-text "*** <point>"
  8203. (org-paste-subtree nil "* Text")
  8204. (buffer-string))))
  8205. ;; Optional argument LEVEL forces a level for the subtree.
  8206. (should
  8207. (equal "* H\n*** Text\n"
  8208. (org-test-with-temp-text "* H<point>"
  8209. (org-paste-subtree 3 "* Text")
  8210. (buffer-string)))))
  8211. (ert-deftest test-org/cut-and-paste-subtree ()
  8212. "Test `org-cut-subtree' and `org-paste-subtree'."
  8213. (should
  8214. (equal
  8215. "* Two
  8216. two
  8217. * One
  8218. "
  8219. (org-test-with-temp-text
  8220. "* One
  8221. <point>* Two
  8222. two
  8223. "
  8224. (call-interactively #'org-cut-subtree)
  8225. (goto-char (point-min))
  8226. (call-interactively #'org-paste-subtree)
  8227. (buffer-string))))
  8228. (should
  8229. (equal
  8230. "* One
  8231. * Two
  8232. "
  8233. (org-test-with-temp-text
  8234. "* One
  8235. <point>* Two
  8236. "
  8237. (call-interactively #'org-cut-subtree)
  8238. (backward-char)
  8239. (call-interactively #'org-paste-subtree)
  8240. (buffer-string)))))
  8241. (provide 'test-org)
  8242. ;;; test-org.el ends here