test-org.el 269 KB

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