test-org.el 274 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425
  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. ;;; Helpers
  19. (defmacro org-test-with-timezone (tz &rest body)
  20. "Evaluate BODY with TZ environment temporary set to the passed value."
  21. (declare (indent 1))
  22. (org-with-gensyms (tz-saved)
  23. `(let ((,tz-saved (getenv "TZ")))
  24. (unwind-protect
  25. (progn
  26. (setenv "TZ" ,tz)
  27. ,@body)
  28. (setenv "TZ" ,tz-saved)))))
  29. ;;; Comments
  30. (ert-deftest test-org/toggle-comment ()
  31. "Test `org-toggle-comment' specifications."
  32. ;; Simple headline.
  33. (should
  34. (equal "* Test"
  35. (org-test-with-temp-text "* COMMENT Test"
  36. (org-toggle-comment)
  37. (buffer-string))))
  38. (should
  39. (equal "* COMMENT Test"
  40. (org-test-with-temp-text "* Test"
  41. (org-toggle-comment)
  42. (buffer-string))))
  43. ;; Headline with a regular keyword.
  44. (should
  45. (equal "* TODO Test"
  46. (org-test-with-temp-text "* TODO COMMENT Test"
  47. (org-toggle-comment)
  48. (buffer-string))))
  49. (should
  50. (equal "* TODO COMMENT Test"
  51. (org-test-with-temp-text "* TODO Test"
  52. (org-toggle-comment)
  53. (buffer-string))))
  54. ;; Empty headline.
  55. (should
  56. (equal "* "
  57. (org-test-with-temp-text "* COMMENT"
  58. (org-toggle-comment)
  59. (buffer-string))))
  60. (should
  61. (equal "* COMMENT"
  62. (org-test-with-temp-text "* "
  63. (org-toggle-comment)
  64. (buffer-string))))
  65. ;; Headline with a single keyword.
  66. (should
  67. (equal "* TODO "
  68. (org-test-with-temp-text "* TODO COMMENT"
  69. (org-toggle-comment)
  70. (buffer-string))))
  71. (should
  72. (equal "* TODO COMMENT"
  73. (org-test-with-temp-text "* TODO"
  74. (org-toggle-comment)
  75. (buffer-string))))
  76. ;; Headline with a keyword, a priority cookie and contents.
  77. (should
  78. (equal "* TODO [#A] Headline"
  79. (org-test-with-temp-text "* TODO [#A] COMMENT Headline"
  80. (org-toggle-comment)
  81. (buffer-string))))
  82. (should
  83. (equal "* TODO [#A] COMMENT Headline"
  84. (org-test-with-temp-text "* TODO [#A] Headline"
  85. (org-toggle-comment)
  86. (buffer-string)))))
  87. (ert-deftest test-org/comment-dwim ()
  88. "Test `comment-dwim' behaviour in an Org buffer."
  89. ;; No region selected, no comment on current line and line not
  90. ;; empty: insert comment on line above.
  91. (should
  92. (equal "# \nComment"
  93. (org-test-with-temp-text "Comment"
  94. (call-interactively #'org-comment-dwim)
  95. (buffer-string))))
  96. ;; No region selected, no comment on current line and line empty:
  97. ;; insert comment on this line.
  98. (should
  99. (equal "# \nParagraph"
  100. (org-test-with-temp-text "\nParagraph"
  101. (call-interactively #'org-comment-dwim)
  102. (buffer-string))))
  103. ;; No region selected, and a comment on this line: indent it.
  104. (should
  105. (equal "* Headline\n # Comment"
  106. (org-test-with-temp-text "* Headline\n# <point>Comment"
  107. (let ((org-adapt-indentation t))
  108. (call-interactively #'org-comment-dwim))
  109. (buffer-string))))
  110. ;; Also recognize single # at column 0 as comments.
  111. (should
  112. (equal "# Comment"
  113. (org-test-with-temp-text "# Comment"
  114. (call-interactively #'org-comment-dwim)
  115. (buffer-string))))
  116. ;; Region selected and only comments and blank lines within it:
  117. ;; un-comment all commented lines.
  118. (should
  119. (equal "Comment 1\n\nComment 2"
  120. (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
  121. (transient-mark-mode 1)
  122. (push-mark (point) t t)
  123. (goto-char (point-max))
  124. (call-interactively #'org-comment-dwim)
  125. (buffer-string))))
  126. ;; Region selected without comments: comment all lines if
  127. ;; `comment-empty-lines' is non-nil, only non-blank lines otherwise.
  128. (should
  129. (equal "# Comment 1\n\n# Comment 2"
  130. (org-test-with-temp-text "Comment 1\n\nComment 2"
  131. (transient-mark-mode 1)
  132. (push-mark (point) t t)
  133. (goto-char (point-max))
  134. (let ((comment-empty-lines nil))
  135. (call-interactively #'org-comment-dwim))
  136. (buffer-string))))
  137. (should
  138. (equal "# Comment 1\n# \n# Comment 2"
  139. (org-test-with-temp-text "Comment 1\n\nComment 2"
  140. (transient-mark-mode 1)
  141. (push-mark (point) t t)
  142. (goto-char (point-max))
  143. (let ((comment-empty-lines t))
  144. (call-interactively #'org-comment-dwim))
  145. (buffer-string))))
  146. ;; In front of a keyword without region, insert a new comment.
  147. (should
  148. (equal "# \n#+KEYWORD: value"
  149. (org-test-with-temp-text "#+KEYWORD: value"
  150. (call-interactively #'org-comment-dwim)
  151. (buffer-string))))
  152. ;; Comment a heading
  153. (should
  154. (equal "* COMMENT Test"
  155. (org-test-with-temp-text "* Test"
  156. (call-interactively #'org-comment-dwim)
  157. (buffer-string))))
  158. ;; In a source block, use appropriate syntax.
  159. (should
  160. (equal " ;; "
  161. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n<point>\n#+END_SRC"
  162. (let ((org-edit-src-content-indentation 2))
  163. (call-interactively #'org-comment-dwim))
  164. (buffer-substring-no-properties (line-beginning-position)
  165. (point)))))
  166. (should
  167. (equal "#+BEGIN_SRC emacs-lisp\n ;; a\n ;; b\n#+END_SRC"
  168. (org-test-with-temp-text
  169. "#+BEGIN_SRC emacs-lisp\n<point>a\nb\n#+END_SRC"
  170. (transient-mark-mode 1)
  171. (push-mark (point) t t)
  172. (forward-line 2)
  173. (let ((org-edit-src-content-indentation 2))
  174. (call-interactively #'org-comment-dwim))
  175. (buffer-string)))))
  176. ;;; Date and time analysis
  177. (ert-deftest test-org/org-encode-time ()
  178. "Test various ways to call `org-encode-time'"
  179. (org-test-with-timezone "UTC"
  180. ;; list as the sole argument
  181. (should (string-equal
  182. "2022-03-24 23:30:01"
  183. (format-time-string
  184. "%F %T"
  185. (org-encode-time '(1 30 23 24 3 2022 nil -1 nil)))))
  186. ;; SECOND...YEAR
  187. (should (string-equal
  188. "2022-03-24 23:30:02"
  189. (format-time-string
  190. "%F %T"
  191. (org-encode-time 2 30 23 24 3 2022))))
  192. ;; SECOND...YEAR IGNORED DST ZONE
  193. (should (string-equal
  194. "2022-03-24 23:30:03"
  195. (format-time-string
  196. "%F %T"
  197. (org-encode-time 3 30 23 24 3 2022 nil -1 nil))))
  198. ;; function call
  199. (should (string-equal
  200. "2022-03-24 23:30:04"
  201. (format-time-string
  202. "%F %T"
  203. (org-encode-time (apply #'list 4 30 23 '(24 3 2022 nil -1 nil))))))
  204. ;; wrong number of arguments
  205. (if (not (version< emacs-version "27.1"))
  206. (should-error (string-equal
  207. "2022-03-24 23:30:05"
  208. (format-time-string
  209. "%F %T"
  210. (org-encode-time 5 30 23 24 3 2022 nil))))))
  211. ;; daylight saving time
  212. (if (not (version< emacs-version "27.1"))
  213. ;; DST value is not ignored for multiple arguments unlike for `encode-time'
  214. (should (string-equal
  215. "2022-04-01 00:30:06 +0200 CEST"
  216. (format-time-string
  217. "%F %T %z %Z"
  218. (org-encode-time 6 30 23 31 3 2022 nil nil "Europe/Madrid")
  219. "Europe/Madrid")))
  220. (should (string-equal
  221. "2022-03-31 23:30:07 +0200 CEST"
  222. (format-time-string
  223. "%F %T %z %Z"
  224. (org-encode-time 7 30 23 31 3 2022 nil t "Europe/Madrid")
  225. "Europe/Madrid"))))
  226. (org-test-with-timezone "Europe/Madrid"
  227. ;; Standard time is not forced when DST is not specified
  228. (should (string-equal
  229. "2022-03-31 23:30:08"
  230. (format-time-string
  231. "%F %T"
  232. (org-encode-time 8 30 23 31 3 2022))))))
  233. (ert-deftest test-org/org-time-string-to-time ()
  234. "Test `org-time-string-to-time' around DST transition."
  235. (org-test-with-timezone "UTC"
  236. (should (string-equal
  237. "2022-03-31 23:31:00"
  238. (format-time-string
  239. "%F %T"
  240. (org-time-string-to-time "2022-03-31 23:31")))))
  241. (org-test-with-timezone "Europe/Madrid"
  242. (should (string-equal
  243. "2022-03-24 23:32:00 +0100 CET"
  244. (format-time-string
  245. "%F %T %z %Z"
  246. (org-time-string-to-time "2022-03-24 23:32"))))
  247. (should (string-equal
  248. "2022-03-31 23:33:00 +0200 CEST"
  249. (format-time-string
  250. "%F %T %z %Z"
  251. (org-time-string-to-time "2022-03-31 23:33"))))))
  252. (ert-deftest test-org/org-read-date ()
  253. "Test `org-read-date' specifications."
  254. ;; Parse ISO date with abbreviated year and month.
  255. (should (equal "2012-03-29 16:40"
  256. (let ((org-time-was-given t))
  257. (org-read-date t nil "12-3-29 16:40"))))
  258. ;; Parse Europeans dates.
  259. (should (equal "2012-03-29 16:40"
  260. (let ((org-time-was-given t))
  261. (org-read-date t nil "29.03.2012 16:40"))))
  262. ;; Parse Europeans dates without year.
  263. (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
  264. (let ((org-time-was-given t))
  265. (org-read-date t nil "29.03. 16:40"))))
  266. ;; Relative date applied to current time if there is single
  267. ;; plus/minus, or to default date when there are two of them.
  268. (should
  269. (equal
  270. "2015-03-04"
  271. (org-test-at-time "2014-03-04"
  272. (org-read-date
  273. t nil "+1y" nil
  274. (org-time-string-to-time "2012-03-29")))))
  275. (should
  276. (equal
  277. "2013-03-29"
  278. (org-test-at-time "2014-03-04"
  279. (org-read-date
  280. t nil "++1y" nil
  281. (org-time-string-to-time "2012-03-29")))))
  282. ;; When `org-read-date-prefer-future' is non-nil, prefer future
  283. ;; dates (relatively to now) when incomplete. Otherwise, use
  284. ;; default date.
  285. (should
  286. (equal
  287. "2014-04-01"
  288. (org-test-at-time "2014-03-04"
  289. (let ((org-read-date-prefer-future t))
  290. (org-read-date t nil "1")))))
  291. (should
  292. (equal
  293. "2013-03-04"
  294. (org-test-at-time "2012-03-29"
  295. (let ((org-read-date-prefer-future t))
  296. (org-read-date t nil "3-4")))))
  297. (should
  298. (equal
  299. "2012-03-04"
  300. (org-test-at-time "2012-03-29"
  301. (let ((org-read-date-prefer-future nil))
  302. (org-read-date t nil "3-4")))))
  303. ;; When set to `org-read-date-prefer-future' is set to `time', read
  304. ;; day is moved to tomorrow if specified hour is before current
  305. ;; time. However, it only happens in no other part of the date is
  306. ;; specified.
  307. (should
  308. (equal
  309. "2012-03-30"
  310. (org-test-at-time "2012-03-29 16:40"
  311. (let ((org-read-date-prefer-future 'time))
  312. (org-read-date t nil "00:40" nil)))))
  313. (should-not
  314. (equal
  315. "2012-03-30"
  316. (org-test-at-time "2012-03-29 16:40"
  317. (let ((org-read-date-prefer-future 'time))
  318. (org-read-date t nil "29 00:40" nil)))))
  319. ;; Caveat: `org-read-date-prefer-future' always refers to current
  320. ;; time, not default time, when they differ.
  321. (should
  322. (equal
  323. "2014-04-01"
  324. (org-test-at-time "2014-03-04"
  325. (let ((org-read-date-prefer-future t))
  326. (org-read-date
  327. t nil "1" nil
  328. (org-time-string-to-time "2012-03-29"))))))
  329. (should
  330. (equal
  331. "2014-03-25"
  332. (org-test-at-time "2014-03-04"
  333. (let ((org-read-date-prefer-future t))
  334. (org-read-date
  335. t nil "25" nil
  336. (org-time-string-to-time "2012-03-29")))))))
  337. (ert-deftest test-org/org-parse-time-string ()
  338. "Test `org-parse-time-string'."
  339. (should (equal (org-parse-time-string "2012-03-29 16:40")
  340. '(0 40 16 29 3 2012 nil -1 nil)))
  341. (should (equal (org-parse-time-string "[2012-03-29 16:40]")
  342. '(0 40 16 29 3 2012 nil -1 nil)))
  343. (should (equal (org-parse-time-string "<2012-03-29 16:40>")
  344. '(0 40 16 29 3 2012 nil -1 nil)))
  345. (should (equal (org-parse-time-string "<2012-03-29>")
  346. '(0 0 0 29 3 2012 nil -1 nil)))
  347. (should (equal (org-parse-time-string "<2012-03-29>" t)
  348. '(0 nil nil 29 3 2012 nil -1 nil))))
  349. (ert-deftest test-org/closest-date ()
  350. "Test `org-closest-date' specifications."
  351. (require 'calendar)
  352. ;; Time stamps without a repeater are returned unchanged.
  353. (should
  354. (equal
  355. '(3 29 2012)
  356. (calendar-gregorian-from-absolute
  357. (org-closest-date "<2012-03-29>" "<2014-03-04>" nil))))
  358. ;; Time stamps with a null repeater are returned unchanged.
  359. (should
  360. (equal
  361. '(3 29 2012)
  362. (calendar-gregorian-from-absolute
  363. (org-closest-date "<2012-03-29 +0d>" "<2014-03-04>" nil))))
  364. ;; if PREFER is set to `past' always return a date before, or equal
  365. ;; to CURRENT.
  366. (should
  367. (equal
  368. '(3 1 2014)
  369. (calendar-gregorian-from-absolute
  370. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'past))))
  371. (should
  372. (equal
  373. '(3 4 2014)
  374. (calendar-gregorian-from-absolute
  375. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'past))))
  376. ;; if PREFER is set to `future' always return a date before, or equal
  377. ;; to CURRENT.
  378. (should
  379. (equal
  380. '(3 29 2014)
  381. (calendar-gregorian-from-absolute
  382. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'future))))
  383. (should
  384. (equal
  385. '(3 4 2014)
  386. (calendar-gregorian-from-absolute
  387. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'future))))
  388. ;; If PREFER is neither `past' nor `future', select closest date.
  389. (should
  390. (equal
  391. '(3 1 2014)
  392. (calendar-gregorian-from-absolute
  393. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" nil))))
  394. (should
  395. (equal
  396. '(5 4 2014)
  397. (calendar-gregorian-from-absolute
  398. (org-closest-date "<2012-03-04 +1m>" "<2014-04-28>" nil))))
  399. ;; Test "day" repeater.
  400. (should
  401. (equal '(3 8 2014)
  402. (calendar-gregorian-from-absolute
  403. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'past))))
  404. (should
  405. (equal '(3 10 2014)
  406. (calendar-gregorian-from-absolute
  407. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'future))))
  408. ;; Test "month" repeater.
  409. (should
  410. (equal '(1 5 2015)
  411. (calendar-gregorian-from-absolute
  412. (org-closest-date "<2014-03-05 +2m>" "<2015-02-04>" 'past))))
  413. (should
  414. (equal '(3 29 2014)
  415. (calendar-gregorian-from-absolute
  416. (org-closest-date "<2012-03-29 +2m>" "<2014-03-04>" 'future))))
  417. ;; Test "year" repeater.
  418. (should
  419. (equal '(3 5 2014)
  420. (calendar-gregorian-from-absolute
  421. (org-closest-date "<2014-03-05 +2y>" "<2015-02-04>" 'past))))
  422. (should
  423. (equal '(3 29 2014)
  424. (calendar-gregorian-from-absolute
  425. (org-closest-date "<2012-03-29 +2y>" "<2014-03-04>" 'future)))))
  426. (ert-deftest test-org/deadline-close-p ()
  427. "Test `org-deadline-close-p' specifications."
  428. (org-test-at-time "2016-06-03 Fri 01:43"
  429. ;; Timestamps are close if they are within `ndays' of lead time.
  430. (org-test-with-temp-text "* Heading"
  431. (should (org-deadline-close-p "2016-06-03 Fri" 0))
  432. (should (org-deadline-close-p "2016-06-02 Thu" 0))
  433. (should-not (org-deadline-close-p "2016-06-04 Sat" 0))
  434. (should (org-deadline-close-p "2016-06-04 Sat" 1))
  435. (should (org-deadline-close-p "2016-06-03 Fri 12:00" 0)))
  436. ;; Read `ndays' from timestamp if argument not given.
  437. (org-test-with-temp-text "* H"
  438. (should (org-deadline-close-p "2016-06-04 Sat -1d"))
  439. (should-not (org-deadline-close-p "2016-06-04 Sat -0d"))
  440. (should (org-deadline-close-p "2016-06-10 Fri -1w"))
  441. (should-not (org-deadline-close-p "2016-06-11 Sat -1w")))
  442. ;; Prefer `ndays' argument over lead time in timestamp.
  443. (org-test-with-temp-text "* H"
  444. (should (org-deadline-close-p "2016-06-04 Sat -0d" 1))
  445. (should-not (org-deadline-close-p "2016-06-04 Sat -0d" 0)))
  446. ;; Completed tasks are never close.
  447. (let ((org-todo-keywords '(("TODO" "|" "DONE"))))
  448. (org-test-with-temp-text "* TODO Heading"
  449. (should (org-deadline-close-p "2016-06-03")))
  450. (org-test-with-temp-text "* DONE Heading"
  451. (should-not (org-deadline-close-p "2016-06-03"))))))
  452. ;;; Drawers
  453. (ert-deftest test-org/at-property-p ()
  454. "Test `org-at-property-p' specifications."
  455. (should
  456. (equal 't
  457. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:PROP: t\n:END:\n"
  458. (org-at-property-p))))
  459. (should
  460. (equal 't
  461. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n:END:\n"
  462. (org-at-property-p)))))
  463. (ert-deftest test-org/at-property-drawer-p ()
  464. "Test `org-at-property-drawer-p' specifications."
  465. (should
  466. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:PROP: t\n:END:\n"
  467. (org-at-property-drawer-p)))
  468. (should
  469. (org-test-with-temp-text ":PROPERTIES:\n:PROP: t\n:END:\n"
  470. (org-at-property-drawer-p)))
  471. ;; The function only returns t if point is at the first line of
  472. ;; a property block.
  473. (should-not
  474. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n:END:\n"
  475. (org-at-property-drawer-p)))
  476. ;; The function ignores incomplete drawers.
  477. (should-not
  478. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n"
  479. (org-at-property-drawer-p)))
  480. ;; tab separating the value.
  481. (should
  482. (org-test-with-temp-text ":PROPERTIES:\n:PROP: t\n:END:\n"
  483. (org-at-property-drawer-p))))
  484. (ert-deftest test-org/get-property-block ()
  485. "Test `org-get-property-block' specifications."
  486. (should
  487. (equal '(14 . 14)
  488. (org-test-with-temp-text ":PROPERTIES:\n:END:\n* H\n"
  489. (org-get-property-block))))
  490. (should
  491. (equal '(14 . 14)
  492. (org-test-with-temp-text ":PROPERTIES:\n:END:\n"
  493. (org-get-property-block))))
  494. ;; Comments above a document property block is ok.
  495. (should
  496. (equal '(18 . 18)
  497. (org-test-with-temp-text "# C\n:PROPERTIES:\n:END:\n"
  498. (org-get-property-block))))
  499. ;; Keywords above a document property block is ok.
  500. (should
  501. (equal '(22 . 22)
  502. (org-test-with-temp-text "# C\n# C\n:PROPERTIES:\n:END:\n"
  503. (org-get-property-block))))
  504. ;; Comments and keywords are allowed before a document property block.
  505. (should
  506. (equal '(18 . 27)
  507. (org-test-with-temp-text "# C\n:PROPERTIES:\n:KEY: V:\n:END:\n"
  508. (org-get-property-block))))
  509. ;; A document property block will not be valid if there are lines
  510. ;; with whitespace above it
  511. (should-not
  512. (org-test-with-temp-text "\n:PROPERTIES:\n:END:\n"
  513. (org-get-property-block)))
  514. (should
  515. (equal '(18 . 18)
  516. (org-test-with-temp-text "* H\n:PROPERTIES:\n:END:\n<point>"
  517. (org-get-property-block))))
  518. (should
  519. (equal "* H\n:PROPERTIES:\n:END:\n"
  520. (org-test-with-temp-text "* H"
  521. (let ((org-adapt-indentation nil))
  522. (org-get-property-block nil 'force))
  523. (buffer-string))))
  524. (should
  525. (equal ":PROPERTIES:\n:END:\n"
  526. (org-test-with-temp-text ""
  527. (org-get-property-block nil 'force)
  528. (buffer-string))))
  529. (should
  530. (equal "* H1\n :PROPERTIES:\n :END:\n* H2"
  531. (org-test-with-temp-text "* H1\n* H2"
  532. (let ((org-adapt-indentation t))
  533. (org-get-property-block nil 'force))
  534. (buffer-string)))))
  535. (ert-deftest test-org/insert-property-drawer ()
  536. "Test `org-insert-property-drawer' specifications."
  537. ;; Insert drawer in empty buffer
  538. (should
  539. (equal ":PROPERTIES:\n:END:\n"
  540. (org-test-with-temp-text ""
  541. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  542. (buffer-string))))
  543. ;; Insert drawer in document header with existing comment and
  544. ;; keyword.
  545. (should
  546. (equal "# C\n:PROPERTIES:\n:END:\n#+TITLE: T"
  547. (org-test-with-temp-text "# C\n#+TITLE: T"
  548. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  549. (buffer-string))))
  550. ;; Insert drawer in document header with existing keyword.
  551. (should
  552. (equal ":PROPERTIES:\n:END:\n#+TITLE: T"
  553. (org-test-with-temp-text "#+TITLE: T"
  554. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  555. (buffer-string))))
  556. (should
  557. (equal ":PROPERTIES:\n:END:"
  558. (org-test-with-temp-text ":PROPERTIES:\n:END:"
  559. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  560. (buffer-string))))
  561. ;; Insert drawer in document header with one existing heading in buffer.
  562. (should
  563. (equal ":PROPERTIES:\n:END:\n\n* T\n"
  564. (org-test-with-temp-text "\n* T\n"
  565. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  566. (buffer-string))))
  567. ;; Insert drawer right after headline if there is no planning line,
  568. ;; or after it otherwise.
  569. (should
  570. (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
  571. (org-test-with-temp-text "* H\nParagraph<point>"
  572. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  573. (buffer-string))))
  574. (should
  575. (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
  576. (org-test-with-temp-text
  577. "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
  578. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  579. (buffer-string))))
  580. ;; Indent inserted drawer.
  581. (should
  582. (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
  583. (org-test-with-temp-text "* H\nParagraph<point>"
  584. (let ((org-adapt-indentation t)) (org-insert-property-drawer))
  585. (buffer-string))))
  586. ;; Handle insertion at eob.
  587. (should
  588. (equal "* H\n:PROPERTIES:\n:END:\n"
  589. (org-test-with-temp-text "* H"
  590. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  591. (buffer-string))))
  592. ;; Skip inlinetasks before point.
  593. (when (featurep 'org-inlinetask)
  594. (should
  595. (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
  596. (org-test-with-temp-text
  597. "* H\n*************** I\n*************** END\nP<point>"
  598. (let ((org-adapt-indentation nil)
  599. (org-inlinetask-min-level 15))
  600. (org-insert-property-drawer))
  601. (buffer-string)))))
  602. ;; Correctly set drawer in an inlinetask.
  603. (when (featurep 'org-inlinetask)
  604. (should
  605. (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
  606. (org-test-with-temp-text
  607. "* H\n*************** I\nP<point>\n*************** END"
  608. (let ((org-adapt-indentation nil)
  609. (org-inlinetask-min-level 15))
  610. (org-insert-property-drawer))
  611. (buffer-string))))))
  612. ;;; Filling
  613. (ert-deftest test-org/fill-element ()
  614. "Test `org-fill-element' specifications."
  615. ;; At an Org table, align it.
  616. (should
  617. (equal "| a |\n"
  618. (org-test-with-temp-text "|a|"
  619. (org-fill-element)
  620. (buffer-string))))
  621. (should
  622. (equal "#+name: table\n| a |\n"
  623. (org-test-with-temp-text "#+name: table\n| a |\n"
  624. (org-fill-element)
  625. (buffer-string))))
  626. ;; At a paragraph, preserve line breaks.
  627. (org-test-with-temp-text "some \\\\\nlong\ntext"
  628. (let ((fill-column 20))
  629. (org-fill-element)
  630. (should (equal (buffer-string) "some \\\\\nlong text"))))
  631. ;; Correctly fill a paragraph when point is at its very end.
  632. (should
  633. (equal "A B"
  634. (org-test-with-temp-text "A\nB"
  635. (let ((fill-column 20))
  636. (goto-char (point-max))
  637. (org-fill-element)
  638. (buffer-string)))))
  639. ;; Correctly fill the last paragraph of a greater element.
  640. (should
  641. (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
  642. (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
  643. (let ((fill-column 8))
  644. (forward-line)
  645. (end-of-line)
  646. (org-fill-element)
  647. (buffer-string)))))
  648. ;; Correctly fill an element in a narrowed buffer.
  649. (should
  650. (equal "01234\n6"
  651. (org-test-with-temp-text "01234 6789"
  652. (let ((fill-column 5))
  653. (narrow-to-region 1 8)
  654. (org-fill-element)
  655. (buffer-string)))))
  656. ;; Handle `adaptive-fill-regexp' in paragraphs.
  657. (should
  658. (equal "> a b"
  659. (org-test-with-temp-text "> a\n> b"
  660. (let ((fill-column 5)
  661. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  662. (org-fill-element)
  663. (buffer-string)))))
  664. ;; Special case: Fill first paragraph when point is at an item or
  665. ;; a plain-list or a footnote reference.
  666. (should
  667. (equal "- A B"
  668. (org-test-with-temp-text "- A\n B"
  669. (let ((fill-column 20))
  670. (org-fill-element)
  671. (buffer-string)))))
  672. (should
  673. (equal "[fn:1] A B"
  674. (org-test-with-temp-text "[fn:1] A\nB"
  675. (let ((fill-column 20))
  676. (org-fill-element)
  677. (buffer-string)))))
  678. (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
  679. (let ((fill-column 20))
  680. (org-fill-element)
  681. (should (equal (buffer-string)
  682. "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
  683. ;; Fill contents of `comment-block' elements.
  684. (should
  685. (equal
  686. (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
  687. (let ((fill-column 20))
  688. (forward-line)
  689. (org-fill-element)
  690. (buffer-string)))
  691. "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
  692. ;; Fill `comment' elements.
  693. (should
  694. (equal " # A B"
  695. (org-test-with-temp-text " # A\n # B"
  696. (let ((fill-column 20))
  697. (org-fill-element)
  698. (buffer-string)))))
  699. ;; Do not mix consecutive comments when filling one of them.
  700. (should
  701. (equal "# A B\n\n# C"
  702. (org-test-with-temp-text "# A\n# B\n\n# C"
  703. (let ((fill-column 20))
  704. (org-fill-element)
  705. (buffer-string)))))
  706. ;; Use commented empty lines as separators when filling comments.
  707. (should
  708. (equal "# A B\n#\n# C"
  709. (org-test-with-temp-text "# A\n# B\n#\n# C"
  710. (let ((fill-column 20))
  711. (org-fill-element)
  712. (buffer-string)))))
  713. ;; Handle `adaptive-fill-regexp' in comments.
  714. (should
  715. (equal "# > a b"
  716. (org-test-with-temp-text "# > a\n# > b"
  717. (let ((fill-column 20)
  718. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  719. (org-fill-element)
  720. (buffer-string)))))
  721. ;; Do nothing at affiliated keywords.
  722. (should
  723. (equal "#+NAME: para\nSome\ntext."
  724. (org-test-with-temp-text "#+NAME: para\nSome\ntext."
  725. (let ((fill-column 20))
  726. (org-fill-element)
  727. (buffer-string)))))
  728. ;; Do not move point after table when filling a table.
  729. (should-not
  730. (org-test-with-temp-text "| a | b |\n| c | d |\n"
  731. (forward-char)
  732. (org-fill-element)
  733. (eobp)))
  734. ;; Do not fill "n" macro, with or without arguments, followed by
  735. ;; a dot or a closing parenthesis since it could be confused with
  736. ;; a numbered bullet.
  737. (should-not
  738. (equal "123456789\n{{{n}}}."
  739. (org-test-with-temp-text "123456789 {{{n}}}."
  740. (let ((fill-column 10))
  741. (org-fill-element)
  742. (buffer-string)))))
  743. (should-not
  744. (equal "123456789\n{{{n}}}\)"
  745. (org-test-with-temp-text "123456789 {{{n}}}\)"
  746. (let ((fill-column 10))
  747. (org-fill-element)
  748. (buffer-string)))))
  749. (should-not
  750. (equal "123456789\n{{{n()}}}."
  751. (org-test-with-temp-text "123456789 {{{n()}}}."
  752. (let ((fill-column 10))
  753. (org-fill-element)
  754. (buffer-string)))))
  755. (should-not
  756. (equal "123456789\n{{{n(counter)}}}."
  757. (org-test-with-temp-text "123456789 {{{n(counter)}}}."
  758. (let ((fill-column 10))
  759. (org-fill-element)
  760. (buffer-string))))))
  761. (ert-deftest test-org/fill-paragraph ()
  762. "Test `org-fill-paragraph' specifications."
  763. ;; Regular test.
  764. (should
  765. (equal "012345678\n9"
  766. (org-test-with-temp-text "012345678 9"
  767. (let ((fill-column 10))
  768. (org-fill-paragraph)
  769. (buffer-string)))))
  770. ;; Fill paragraph even at end of buffer.
  771. (should
  772. (equal "012345678\n9\n"
  773. (org-test-with-temp-text "012345678 9\n<point>"
  774. (let ((fill-column 10))
  775. (org-fill-paragraph)
  776. (buffer-string)))))
  777. ;; Between two paragraphs, fill the next one.
  778. (should
  779. (equal "012345678 9\n\n012345678\n9"
  780. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  781. (let ((fill-column 10))
  782. (org-fill-paragraph)
  783. (buffer-string)))))
  784. (should
  785. (equal "012345678\n9\n\n012345678 9"
  786. (org-test-with-temp-text "012345678 9<point>\n\n012345678 9"
  787. (let ((fill-column 10))
  788. (org-fill-paragraph)
  789. (buffer-string)))))
  790. ;; Fill paragraph in a comment block.
  791. (should
  792. (equal "#+begin_comment\n012345678\n9\n#+end_comment"
  793. (org-test-with-temp-text
  794. "#+begin_comment\n<point>012345678 9\n#+end_comment"
  795. (let ((fill-column 10))
  796. (org-fill-paragraph)
  797. (buffer-string)))))
  798. ;; When a region is selected, fill every paragraph in the region.
  799. (should
  800. (equal "012345678\n9\n\n012345678\n9"
  801. (org-test-with-temp-text "012345678 9\n\n012345678 9"
  802. (let ((fill-column 10))
  803. (transient-mark-mode 1)
  804. (push-mark (point-min) t t)
  805. (goto-char (point-max))
  806. (call-interactively #'org-fill-paragraph)
  807. (buffer-string)))))
  808. (should
  809. (equal "012345678\n9\n\n012345678 9"
  810. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  811. (let ((fill-column 10))
  812. (transient-mark-mode 1)
  813. (push-mark (point) t t)
  814. (goto-char (point-min))
  815. (call-interactively #'org-fill-paragraph)
  816. (buffer-string)))))
  817. (should
  818. (equal "012345678 9\n\n012345678\n9"
  819. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  820. (let ((fill-column 10))
  821. (transient-mark-mode 1)
  822. (push-mark (point) t t)
  823. (goto-char (point-max))
  824. (call-interactively #'org-fill-paragraph)
  825. (buffer-string)))))
  826. ;; Fill every list item in a region
  827. (should
  828. (equal "\n- 2345678\n 9\n- 2345678\n 9"
  829. (org-test-with-temp-text "\n- 2345678 9\n- 2345678 9"
  830. (let ((fill-column 10))
  831. (transient-mark-mode 1)
  832. (push-mark (point-min) t t)
  833. (goto-char (point-max))
  834. (call-interactively #'org-fill-paragraph)
  835. (buffer-string)))))
  836. (should
  837. (equal "\n- 2345678\n 9\n- 2345678"
  838. (org-test-with-temp-text "\n- 2345678 9\n- 2345678"
  839. (let ((fill-column 10))
  840. (transient-mark-mode 1)
  841. (push-mark (point-min) t t)
  842. (goto-char (point-max))
  843. (call-interactively #'org-fill-paragraph)
  844. (buffer-string))))))
  845. (ert-deftest test-org/fill-region ()
  846. "Test `fill-region' behaviour."
  847. ;; fill-region should fill every item of a list
  848. (should
  849. (equal "\n- 2345678\n 9\n- 2345678\n 9"
  850. (org-test-with-temp-text "\n- 2345678 9\n- 2345678 9"
  851. (let ((fill-column 10))
  852. (transient-mark-mode 1)
  853. (push-mark (point-min) t t)
  854. (goto-char (point-max))
  855. (call-interactively #'fill-region)
  856. (buffer-string)))))
  857. (should
  858. (equal "\n- 1 2\n- 1 2"
  859. (org-test-with-temp-text "\n- 1\n 2\n- 1\n 2"
  860. (let ((fill-column 10))
  861. (transient-mark-mode 1)
  862. (push-mark (point-min) t t)
  863. (goto-char (point-max))
  864. (call-interactively #'fill-region)
  865. (buffer-string))))) )
  866. (ert-deftest test-org/auto-fill-function ()
  867. "Test auto-filling features."
  868. ;; Auto fill paragraph.
  869. (should
  870. (equal "12345\n7890"
  871. (org-test-with-temp-text "12345 7890"
  872. (let ((fill-column 5))
  873. (end-of-line)
  874. (org-auto-fill-function)
  875. (buffer-string)))))
  876. ;; Auto fill first paragraph in an item.
  877. (should
  878. (equal "- 12345\n 7890"
  879. (org-test-with-temp-text "- 12345 7890"
  880. (let ((fill-column 7))
  881. (end-of-line)
  882. (org-auto-fill-function)
  883. (buffer-string)))))
  884. ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
  885. (should
  886. (equal "> 12345\n 7890"
  887. (org-test-with-temp-text "> 12345 7890"
  888. (let ((fill-column 10)
  889. (adaptive-fill-regexp "[ \t]*>+[ \t]*")
  890. (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
  891. (end-of-line)
  892. (org-auto-fill-function)
  893. (buffer-string)))))
  894. (should
  895. (equal "> 12345\n> 12345\n> 7890"
  896. (org-test-with-temp-text "> 12345\n> 12345 7890"
  897. (let ((fill-column 10)
  898. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  899. (goto-char (point-max))
  900. (org-auto-fill-function)
  901. (buffer-string)))))
  902. (should-not
  903. (equal " 12345\n *12345\n *12345"
  904. (org-test-with-temp-text " 12345\n *12345 12345"
  905. (let ((fill-column 10)
  906. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  907. (goto-char (point-max))
  908. (org-auto-fill-function)
  909. (buffer-string)))))
  910. ;; Auto fill comments.
  911. (should
  912. (equal " # 12345\n # 7890"
  913. (org-test-with-temp-text " # 12345 7890"
  914. (let ((fill-column 10))
  915. (end-of-line)
  916. (org-auto-fill-function)
  917. (buffer-string)))))
  918. ;; A hash within a line isn't a comment.
  919. (should-not
  920. (equal "12345 # 7890\n# 1"
  921. (org-test-with-temp-text "12345 # 7890 1"
  922. (let ((fill-column 12))
  923. (end-of-line)
  924. (org-auto-fill-function)
  925. (buffer-string)))))
  926. ;; Correctly interpret empty prefix.
  927. (should-not
  928. (equal "# a\n# b\nRegular\n# paragraph"
  929. (org-test-with-temp-text "# a\n# b\nRegular paragraph"
  930. (let ((fill-column 12))
  931. (end-of-line 3)
  932. (org-auto-fill-function)
  933. (buffer-string)))))
  934. ;; Comment block: auto fill contents.
  935. (should
  936. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  937. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  938. (let ((fill-column 5))
  939. (forward-line)
  940. (end-of-line)
  941. (org-auto-fill-function)
  942. (buffer-string)))))
  943. (should
  944. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  945. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  946. (let ((fill-column 5))
  947. (forward-line)
  948. (end-of-line)
  949. (org-auto-fill-function)
  950. (buffer-string)))))
  951. ;; Do not fill if a new item could be created.
  952. (should-not
  953. (equal "12345\n- 90"
  954. (org-test-with-temp-text "12345 - 90"
  955. (let ((fill-column 5))
  956. (end-of-line)
  957. (org-auto-fill-function)
  958. (buffer-string)))))
  959. ;; Do not fill if a line break could be introduced.
  960. (should-not
  961. (equal "123\\\\\n7890"
  962. (org-test-with-temp-text "123\\\\ 7890"
  963. (let ((fill-column 6))
  964. (end-of-line)
  965. (org-auto-fill-function)
  966. (buffer-string)))))
  967. ;; Do not fill affiliated keywords.
  968. (should-not
  969. (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
  970. (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
  971. (let ((fill-column 20))
  972. (end-of-line)
  973. (org-auto-fill-function)
  974. (buffer-string))))))
  975. ;;; Indentation
  976. (ert-deftest test-org/indent-line ()
  977. "Test `org-indent-line' specifications."
  978. ;; Do not indent diary sexps, footnote definitions or headlines.
  979. (should
  980. (zerop
  981. (org-test-with-temp-text "%%(org-calendar-holiday)"
  982. (org-indent-line)
  983. (org-get-indentation))))
  984. (should
  985. (zerop
  986. (org-test-with-temp-text "[fn:1] fn"
  987. (let ((org-adapt-indentation t)) (org-indent-line))
  988. (org-get-indentation))))
  989. (should
  990. (zerop
  991. (org-test-with-temp-text "* H"
  992. (org-indent-line)
  993. (org-get-indentation))))
  994. ;; Do not indent before first headline.
  995. (should
  996. (zerop
  997. (org-test-with-temp-text ""
  998. (org-indent-line)
  999. (org-get-indentation))))
  1000. ;; Indent according to headline level otherwise, unless
  1001. ;; `org-adapt-indentation' is nil.
  1002. (should
  1003. (= 2
  1004. (org-test-with-temp-text "* H\n<point>A"
  1005. (let ((org-adapt-indentation t)) (org-indent-line))
  1006. (org-get-indentation))))
  1007. (should
  1008. (= 2
  1009. (org-test-with-temp-text "* H\n<point>\nA"
  1010. (let ((org-adapt-indentation t)) (org-indent-line))
  1011. (org-get-indentation))))
  1012. (should
  1013. (zerop
  1014. (org-test-with-temp-text "* H\n<point>A"
  1015. (let ((org-adapt-indentation nil)) (org-indent-line))
  1016. (org-get-indentation))))
  1017. ;; Indenting preserves point position.
  1018. (should
  1019. (org-test-with-temp-text "* H\nA<point>B"
  1020. (let ((org-adapt-indentation t)) (org-indent-line))
  1021. (looking-at "B")))
  1022. ;; Do not change indentation at an item or a LaTeX environment.
  1023. (should
  1024. (= 1
  1025. (org-test-with-temp-text "* H\n<point> - A"
  1026. (let ((org-adapt-indentation t)) (org-indent-line))
  1027. (org-get-indentation))))
  1028. (should
  1029. (= 1
  1030. (org-test-with-temp-text
  1031. "\\begin{equation}\n <point>1+1=2\n\\end{equation}"
  1032. (org-indent-line)
  1033. (org-get-indentation))))
  1034. ;; On blank lines at the end of a list, indent like last element
  1035. ;; within it if the line is still in the list. If the last element
  1036. ;; is an item, indent like its contents. Otherwise, indent like the
  1037. ;; whole list.
  1038. (should
  1039. (= 4
  1040. (org-test-with-temp-text "* H\n- A\n - AA\n<point>"
  1041. (let ((org-adapt-indentation t)) (org-indent-line))
  1042. (org-get-indentation))))
  1043. (should
  1044. (= 4
  1045. (org-test-with-temp-text "* H\n- A\n -\n\n<point>"
  1046. (let ((org-adapt-indentation t)) (org-indent-line))
  1047. (org-get-indentation))))
  1048. (should
  1049. (zerop
  1050. (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n<point>"
  1051. (let ((org-adapt-indentation t)) (org-indent-line))
  1052. (org-get-indentation))))
  1053. (should
  1054. (= 4
  1055. (org-test-with-temp-text "* H\n- A\n - \n<point>"
  1056. (let ((org-adapt-indentation t)) (org-indent-line))
  1057. (org-get-indentation))))
  1058. (should
  1059. (= 4
  1060. (org-test-with-temp-text
  1061. "* H\n - \n #+BEGIN_SRC emacs-lisp\n t\n #+END_SRC\n<point>"
  1062. (let ((org-adapt-indentation t)) (org-indent-line))
  1063. (org-get-indentation))))
  1064. (should
  1065. (= 2
  1066. (org-test-with-temp-text "- A\n B\n\n<point>"
  1067. (let ((org-adapt-indentation nil)) (org-indent-line))
  1068. (org-get-indentation))))
  1069. (should
  1070. (= 2
  1071. (org-test-with-temp-text
  1072. "- A\n \begin{cases} 1 + 1\n \end{cases}\n\n<point>"
  1073. (let ((org-adapt-indentation nil)) (org-indent-line))
  1074. (org-get-indentation))))
  1075. ;; Likewise, on a blank line at the end of a footnote definition,
  1076. ;; indent at column 0 if line belongs to the definition. Otherwise,
  1077. ;; indent like the definition itself.
  1078. (should
  1079. (zerop
  1080. (org-test-with-temp-text "* H\n[fn:1] Definition\n<point>"
  1081. (let ((org-adapt-indentation t)) (org-indent-line))
  1082. (org-get-indentation))))
  1083. (should
  1084. (zerop
  1085. (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n<point>"
  1086. (let ((org-adapt-indentation t)) (org-indent-line))
  1087. (org-get-indentation))))
  1088. ;; After the end of the contents of a greater element, indent like
  1089. ;; the beginning of the element.
  1090. (should
  1091. (= 1
  1092. (org-test-with-temp-text
  1093. " #+BEGIN_CENTER\n Contents\n<point>#+END_CENTER"
  1094. (org-indent-line)
  1095. (org-get-indentation))))
  1096. ;; On blank lines after a paragraph, indent like its last non-empty
  1097. ;; line.
  1098. (should
  1099. (= 1
  1100. (org-test-with-temp-text " Paragraph\n\n<point>"
  1101. (org-indent-line)
  1102. (org-get-indentation))))
  1103. ;; At the first line of an element, indent like previous element's
  1104. ;; first line, ignoring footnotes definitions and inline tasks, or
  1105. ;; according to parent.
  1106. (let ((org-adapt-indentation t))
  1107. (should
  1108. (= 2
  1109. (org-test-with-temp-text "A\n\n B\n\nC<point>"
  1110. (org-indent-line)
  1111. (org-get-indentation))))
  1112. (should
  1113. (= 1
  1114. (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC<point>"
  1115. (org-indent-line)
  1116. (org-get-indentation))))
  1117. (should
  1118. (= 1
  1119. (org-test-with-temp-text
  1120. " #+BEGIN_CENTER\n<point> Contents\n#+END_CENTER"
  1121. (org-indent-line)
  1122. (org-get-indentation)))))
  1123. ;; Within code part of a source block, use language major mode if
  1124. ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
  1125. ;; according to line above.
  1126. (should
  1127. (= 6
  1128. (org-test-with-temp-text
  1129. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  1130. (let ((org-src-tab-acts-natively t)
  1131. (org-edit-src-content-indentation 0))
  1132. (org-indent-line))
  1133. (org-get-indentation))))
  1134. (should
  1135. (= 1
  1136. (org-test-with-temp-text
  1137. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  1138. (let ((org-src-tab-acts-natively nil)
  1139. (org-edit-src-content-indentation 0))
  1140. (org-indent-line))
  1141. (org-get-indentation))))
  1142. ;; Otherwise, indent like the first non-blank line above.
  1143. (should
  1144. (zerop
  1145. (org-test-with-temp-text
  1146. "#+BEGIN_CENTER\nline1\n\n<point> line2\n#+END_CENTER"
  1147. (org-indent-line)
  1148. (org-get-indentation))))
  1149. ;; Align node properties according to `org-property-format'. Handle
  1150. ;; nicely empty values.
  1151. (should
  1152. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1153. (org-test-with-temp-text
  1154. "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
  1155. (let ((org-property-format "%-10s %s")) (org-indent-line))
  1156. (buffer-string))))
  1157. (should
  1158. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1159. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
  1160. (let ((org-property-format "%-10s %s")) (org-indent-line))
  1161. (buffer-string)))))
  1162. (ert-deftest test-org/indent-region ()
  1163. "Test `org-indent-region' specifications."
  1164. ;; Indent paragraph.
  1165. (let ((org-adapt-indentation t))
  1166. (should
  1167. (equal "A\nB\nC"
  1168. (org-test-with-temp-text " A\nB\n C"
  1169. (org-indent-region (point-min) (point-max))
  1170. (buffer-string)))))
  1171. ;; Indent greater elements along with their contents.
  1172. (should
  1173. (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
  1174. (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
  1175. (org-indent-region (point-min) (point-max))
  1176. (buffer-string))))
  1177. ;; Ignore contents of verse blocks. Only indent block delimiters.
  1178. (should
  1179. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1180. (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1181. (org-indent-region (point-min) (point-max))
  1182. (buffer-string))))
  1183. (let ((org-adapt-indentation t))
  1184. (should
  1185. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1186. (org-test-with-temp-text " #+BEGIN_VERSE\n A\n B\n #+END_VERSE"
  1187. (org-indent-region (point-min) (point-max))
  1188. (buffer-string)))))
  1189. ;; Indent example blocks as a single block, unless indentation
  1190. ;; should be preserved. In this case only indent the block markers.
  1191. (should
  1192. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1193. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1194. (org-indent-region (point-min) (point-max))
  1195. (buffer-string))))
  1196. (let ((org-adapt-indentation t))
  1197. (should
  1198. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1199. (org-test-with-temp-text " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1200. (org-indent-region (point-min) (point-max))
  1201. (buffer-string))))
  1202. (should
  1203. (equal "#+BEGIN_EXAMPLE -i\n A\n B\n#+END_EXAMPLE"
  1204. (org-test-with-temp-text
  1205. " #+BEGIN_EXAMPLE -i\n A\n B\n #+END_EXAMPLE"
  1206. (org-indent-region (point-min) (point-max))
  1207. (buffer-string))))
  1208. (should
  1209. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1210. (org-test-with-temp-text
  1211. " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1212. (let ((org-src-preserve-indentation t))
  1213. (org-indent-region (point-min) (point-max)))
  1214. (buffer-string)))))
  1215. ;; Treat export blocks as a whole.
  1216. (should
  1217. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1218. (org-test-with-temp-text "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1219. (org-indent-region (point-min) (point-max))
  1220. (buffer-string))))
  1221. (let ((org-adapt-indentation t))
  1222. (should
  1223. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1224. (org-test-with-temp-text
  1225. " #+BEGIN_EXPORT latex\n A\n B\n #+END_EXPORT"
  1226. (org-indent-region (point-min) (point-max))
  1227. (buffer-string)))))
  1228. ;; Indent according to mode if `org-src-tab-acts-natively' is
  1229. ;; non-nil. Otherwise, do not indent code at all.
  1230. (should
  1231. (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
  1232. (org-test-with-temp-text
  1233. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1234. (let ((org-src-tab-acts-natively t)
  1235. (org-edit-src-content-indentation 0))
  1236. (org-indent-region (point-min) (point-max)))
  1237. (buffer-string))))
  1238. (should
  1239. (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1240. (org-test-with-temp-text
  1241. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1242. (let ((org-src-tab-acts-natively nil)
  1243. (org-edit-src-content-indentation 0))
  1244. (org-indent-region (point-min) (point-max)))
  1245. (buffer-string))))
  1246. ;; Align node properties according to `org-property-format'. Handle
  1247. ;; nicely empty values.
  1248. (should
  1249. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1250. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
  1251. (let ((org-property-format "%-10s %s")
  1252. (org-adapt-indentation nil))
  1253. (org-indent-region (point) (point-max)))
  1254. (buffer-string))))
  1255. (should
  1256. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1257. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
  1258. (let ((org-property-format "%-10s %s")
  1259. (org-adapt-indentation nil))
  1260. (org-indent-region (point) (point-max)))
  1261. (buffer-string))))
  1262. ;; Indent property drawers according to `org-adapt-indentation'.
  1263. (let ((org-adapt-indentation 'headline-data))
  1264. (should
  1265. (equal "* H\n :PROPERTIES:\n :key:\n :END:"
  1266. (org-test-with-temp-text "* H\n:PROPERTIES:\n:key:\n:END:"
  1267. (org-indent-region (point-min) (point-max))
  1268. (buffer-string)))))
  1269. ;; Indent plain lists.
  1270. (let ((org-adapt-indentation t))
  1271. (should
  1272. (equal "- A\n B\n - C\n\n D"
  1273. (org-test-with-temp-text "- A\n B\n - C\n\n D"
  1274. (org-indent-region (point-min) (point-max))
  1275. (buffer-string))))
  1276. (should
  1277. (equal "- A\n\n- B"
  1278. (org-test-with-temp-text " - A\n\n - B"
  1279. (org-indent-region (point-min) (point-max))
  1280. (buffer-string)))))
  1281. ;; Indent footnote definitions.
  1282. (should
  1283. (equal "[fn:1] Definition\n\nDefinition"
  1284. (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
  1285. (org-indent-region (point-min) (point-max))
  1286. (buffer-string))))
  1287. ;; Special case: Start indenting on a blank line.
  1288. (should
  1289. (equal "\nParagraph"
  1290. (org-test-with-temp-text "\n Paragraph"
  1291. (org-indent-region (point-min) (point-max))
  1292. (buffer-string)))))
  1293. ;;; Editing
  1294. (ert-deftest test-org/delete-indentation ()
  1295. "Test `org-delete-indentation' specifications."
  1296. ;; Regular test.
  1297. (should (equal "foo bar"
  1298. (org-test-with-temp-text
  1299. "foo \n bar<point>"
  1300. (org-delete-indentation)
  1301. (buffer-string))))
  1302. ;; With optional argument.
  1303. (should (equal "foo bar"
  1304. (org-test-with-temp-text
  1305. "foo<point> \n bar"
  1306. (org-delete-indentation t)
  1307. (buffer-string))))
  1308. ;; At headline text should be appended to the headline text.
  1309. (should
  1310. (equal"* foo bar :tag:"
  1311. (let (org-auto-align-tags)
  1312. (org-test-with-temp-text
  1313. "* foo :tag:\n bar<point>"
  1314. (org-delete-indentation)
  1315. (buffer-string)))))
  1316. (should
  1317. (equal "* foo bar :tag:"
  1318. (let (org-auto-align-tags)
  1319. (org-test-with-temp-text
  1320. "* foo <point>:tag:\n bar"
  1321. (org-delete-indentation t)
  1322. (buffer-string))))))
  1323. (ert-deftest test-org/return ()
  1324. "Test `org-return' specifications."
  1325. ;; Regular test.
  1326. (should
  1327. (equal "Para\ngraph"
  1328. (org-test-with-temp-text "Para<point>graph"
  1329. (org-return)
  1330. (buffer-string))))
  1331. ;; With optional argument, indent line.
  1332. (should
  1333. (equal " Para\n graph"
  1334. (org-test-with-temp-text " Para<point>graph"
  1335. (org-return t)
  1336. (buffer-string))))
  1337. ;; On a table, call `org-table-next-row'.
  1338. (should
  1339. (org-test-with-temp-text "| <point>a |\n| b |"
  1340. (org-return)
  1341. (looking-at-p "b")))
  1342. ;; Open link or timestamp under point when `org-return-follows-link'
  1343. ;; is non-nil.
  1344. (should
  1345. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1346. (let ((org-return-follows-link t)
  1347. (org-link-search-must-match-exact-headline nil))
  1348. (org-return))
  1349. (looking-at-p "<<target>>")))
  1350. (should-not
  1351. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1352. (let ((org-return-follows-link nil)) (org-return))
  1353. (looking-at-p "<<target>>")))
  1354. (should
  1355. (org-test-with-temp-text "* [[b][a<point>]]\n* b"
  1356. (let ((org-return-follows-link t)) (org-return))
  1357. (looking-at-p "* b")))
  1358. (should
  1359. (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
  1360. (let ((org-return-follows-link t)
  1361. (org-link-search-must-match-exact-headline nil))
  1362. (org-return))
  1363. (looking-at-p "<<target>>")))
  1364. (should-not
  1365. (org-test-with-temp-text "Link [[target]]<point> <<target>>"
  1366. (let ((org-return-follows-link t)
  1367. (org-link-search-must-match-exact-headline nil))
  1368. (org-return))
  1369. (looking-at-p "<<target>>")))
  1370. ;; When `org-return-follows-link' is non-nil, tolerate links and
  1371. ;; timestamps in comments, node properties, etc.
  1372. (should
  1373. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1374. (let ((org-return-follows-link t)
  1375. (org-link-search-must-match-exact-headline nil))
  1376. (org-return))
  1377. (looking-at-p "<<target>>")))
  1378. (should-not
  1379. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1380. (let ((org-return-follows-link nil)) (org-return))
  1381. (looking-at-p "<<target>>")))
  1382. (should-not
  1383. (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
  1384. (let ((org-return-follows-link t)
  1385. (org-link-search-must-match-exact-headline nil))
  1386. (org-return))
  1387. (looking-at-p "<<target>>")))
  1388. ;; Non-nil `org-return-follows-link' ignores read-only state of
  1389. ;; a buffer.
  1390. (should
  1391. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1392. (let ((org-return-follows-link t)
  1393. (org-link-search-must-match-exact-headline nil))
  1394. (setq buffer-read-only t)
  1395. (call-interactively #'org-return))
  1396. (looking-at-p "<<target>>")))
  1397. ;; `org-return-follows-link' handle multi-line lines.
  1398. (should
  1399. (org-test-with-temp-text
  1400. "[[target][This is a very\n long description<point>]]\n <<target>>"
  1401. (let ((org-return-follows-link t)
  1402. (org-link-search-must-match-exact-headline nil))
  1403. (org-return))
  1404. (looking-at-p "<<target>>")))
  1405. (should-not
  1406. (org-test-with-temp-text
  1407. "[[target][This is a very\n long description]]<point>\n <<target>>"
  1408. (let ((org-return-follows-link t)
  1409. (org-link-search-must-match-exact-headline nil))
  1410. (org-return))
  1411. (looking-at-p "<<target>>")))
  1412. ;; However, do not open link when point is in a table.
  1413. (should
  1414. (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
  1415. (let ((org-return-follows-link t)) (org-return))
  1416. (looking-at-p "between")))
  1417. ;; Special case: in a list, when indenting, do not break structure.
  1418. (should
  1419. (equal "- A\n B"
  1420. (org-test-with-temp-text "- A <point>B"
  1421. (org-return t)
  1422. (buffer-string))))
  1423. (should
  1424. (equal "- A\n\n- B"
  1425. (org-test-with-temp-text "- A\n<point>- B"
  1426. (org-return t)
  1427. (buffer-string))))
  1428. ;; On tags part of a headline, add a newline below it instead of
  1429. ;; breaking it.
  1430. (should
  1431. (equal "* H :tag:\n"
  1432. (org-test-with-temp-text "* H :<point>tag:"
  1433. (org-return)
  1434. (buffer-string))))
  1435. ;; Before headline text, add a newline below it instead of breaking
  1436. ;; it.
  1437. (should
  1438. (equal "* TODO H :tag:\n"
  1439. (org-test-with-temp-text "* <point>TODO H :tag:"
  1440. (org-return)
  1441. (buffer-string))))
  1442. (should
  1443. (equal "* TODO [#B] H :tag:\n"
  1444. (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
  1445. (org-return)
  1446. (buffer-string))))
  1447. (should ;TODO are case-sensitive
  1448. (equal "* \nTodo"
  1449. (org-test-with-temp-text "* <point>Todo"
  1450. (org-return)
  1451. (buffer-string))))
  1452. ;; At headline text, break headline text but preserve tags.
  1453. (should
  1454. (equal "* TODO [#B] foo :tag:\nbar"
  1455. (let (org-auto-align-tags)
  1456. (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
  1457. (org-return)
  1458. (buffer-string)))))
  1459. ;; At bol of headline insert newline.
  1460. (should
  1461. (equal "\n* h"
  1462. (org-test-with-temp-text "<point>* h"
  1463. (org-return)
  1464. (buffer-string))))
  1465. ;; Refuse to leave invalid headline in buffer.
  1466. (should
  1467. (equal "* h\n"
  1468. (org-test-with-temp-text "*<point> h"
  1469. (org-return)
  1470. (buffer-string))))
  1471. ;; Before first column or after last one in a table, split the
  1472. ;; table.
  1473. (should
  1474. (equal "| a |\n\n| b |"
  1475. (org-test-with-temp-text "| a |\n<point>| b |"
  1476. (org-return)
  1477. (buffer-string))))
  1478. (should
  1479. (equal "| a |\n\n| b |"
  1480. (org-test-with-temp-text "| a |<point>\n| b |"
  1481. (org-return)
  1482. (buffer-string))))
  1483. ;; Do not auto-fill on hitting <RET> inside a property drawer.
  1484. (should
  1485. (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:"
  1486. (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:"
  1487. (setq-local fill-column 10)
  1488. (auto-fill-mode 1)
  1489. (org-return)
  1490. (buffer-string)))))
  1491. (ert-deftest test-org/with-electric-indent ()
  1492. "Test RET and C-j specifications with `electric-indent-mode' on."
  1493. ;; Call commands interactively, since this is how `newline' knows it
  1494. ;; must run `post-self-insert-hook'.
  1495. ;;
  1496. ;; RET, like `newline', should indent.
  1497. (should
  1498. (equal " Para\n graph"
  1499. (org-test-with-temp-text " Para<point>graph"
  1500. (electric-indent-local-mode 1)
  1501. (call-interactively 'org-return)
  1502. (buffer-string))))
  1503. (should
  1504. (equal "- item1\n item2"
  1505. (org-test-with-temp-text "- item1<point>item2"
  1506. (electric-indent-local-mode 1)
  1507. (call-interactively 'org-return)
  1508. (buffer-string))))
  1509. ;; TODO: test more values of `org-adapt-indentation'.
  1510. (let ((org-adapt-indentation t))
  1511. (should
  1512. (equal "* heading\n body"
  1513. (org-test-with-temp-text "* heading<point>body"
  1514. (electric-indent-local-mode 1)
  1515. (call-interactively 'org-return)
  1516. (buffer-string)))))
  1517. ;; C-j, like `electric-newline-and-maybe-indent', should not indent.
  1518. (should
  1519. (equal " Para\ngraph"
  1520. (org-test-with-temp-text " Para<point>graph"
  1521. (electric-indent-local-mode 1)
  1522. (call-interactively 'org-return-and-maybe-indent)
  1523. (buffer-string))))
  1524. (should
  1525. (equal "- item1\nitem2"
  1526. (org-test-with-temp-text "- item1<point>item2"
  1527. (electric-indent-local-mode 1)
  1528. (call-interactively 'org-return-and-maybe-indent)
  1529. (buffer-string))))
  1530. ;; TODO: test more values of `org-adapt-indentation'.
  1531. (let ((org-adapt-indentation t))
  1532. (should
  1533. (equal "* heading\nbody"
  1534. (org-test-with-temp-text "* heading<point>body"
  1535. (electric-indent-local-mode 1)
  1536. (call-interactively 'org-return-and-maybe-indent)
  1537. (buffer-string))))))
  1538. (ert-deftest test-org/without-electric-indent ()
  1539. "Test RET and C-j specifications with `electric-indent-mode' off."
  1540. ;; Call commands interactively, since this is how `newline' knows it
  1541. ;; must run `post-self-insert-hook'.
  1542. ;;
  1543. ;; RET, like `newline', should not indent.
  1544. (should
  1545. (equal " Para\ngraph"
  1546. (org-test-with-temp-text " Para<point>graph"
  1547. (electric-indent-local-mode 0)
  1548. (call-interactively 'org-return)
  1549. (buffer-string))))
  1550. (should
  1551. (equal "- item1\nitem2"
  1552. (org-test-with-temp-text "- item1<point>item2"
  1553. (electric-indent-local-mode 0)
  1554. (call-interactively 'org-return)
  1555. (buffer-string))))
  1556. (should
  1557. (equal "* heading\nbody"
  1558. (org-test-with-temp-text "* heading<point>body"
  1559. (electric-indent-local-mode 0)
  1560. (call-interactively 'org-return)
  1561. (buffer-string))))
  1562. ;; C-j, like `electric-newline-and-maybe-indent', should indent.
  1563. (should
  1564. (equal " Para\n graph"
  1565. (org-test-with-temp-text " Para<point>graph"
  1566. (electric-indent-local-mode 0)
  1567. (call-interactively 'org-return-and-maybe-indent)
  1568. (buffer-string))))
  1569. (should
  1570. (equal "- item1\n item2"
  1571. (org-test-with-temp-text "- item1<point>item2"
  1572. (electric-indent-local-mode 0)
  1573. (call-interactively 'org-return-and-maybe-indent)
  1574. (buffer-string))))
  1575. ;; TODO: test more values of `org-adapt-indentation'.
  1576. (let ((org-adapt-indentation t))
  1577. (should
  1578. (equal "* heading\n body"
  1579. (org-test-with-temp-text "* heading<point>body"
  1580. (electric-indent-local-mode 0)
  1581. (call-interactively 'org-return-and-maybe-indent)
  1582. (buffer-string))))))
  1583. (ert-deftest test-org/meta-return ()
  1584. "Test M-RET (`org-meta-return') specifications."
  1585. ;; In a table field insert a row above.
  1586. (should
  1587. (org-test-with-temp-text "| a |"
  1588. (forward-char)
  1589. (org-meta-return)
  1590. (forward-line -1)
  1591. (looking-at "| |$")))
  1592. ;; In a paragraph change current line into a header.
  1593. (should
  1594. (org-test-with-temp-text "a"
  1595. (org-meta-return)
  1596. (beginning-of-line)
  1597. (looking-at "\* a$")))
  1598. ;; In an item insert an item, in this case above.
  1599. (should
  1600. (org-test-with-temp-text "- a"
  1601. (org-meta-return)
  1602. (beginning-of-line)
  1603. (looking-at "- $")))
  1604. ;; In a drawer and item insert an item, in this case above.
  1605. (should
  1606. (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
  1607. (forward-line)
  1608. (org-fold-reveal)
  1609. (org-meta-return)
  1610. (beginning-of-line)
  1611. (looking-at "- $"))))
  1612. (ert-deftest test-org/insert-heading ()
  1613. "Test `org-insert-heading' specifications."
  1614. ;; In an empty buffer, insert a new headline.
  1615. (should
  1616. (equal "* "
  1617. (org-test-with-temp-text ""
  1618. (org-insert-heading)
  1619. (buffer-string))))
  1620. ;; At the beginning of a line, turn it into a headline.
  1621. (should
  1622. (equal "* P"
  1623. (org-test-with-temp-text "<point>P"
  1624. (org-insert-heading)
  1625. (buffer-string))))
  1626. ;; In the middle of a line, split the line if allowed, otherwise,
  1627. ;; insert the headline at its end.
  1628. (should
  1629. (equal "Para\n* graph"
  1630. (org-test-with-temp-text "Para<point>graph"
  1631. (let ((org-M-RET-may-split-line '((default . t))))
  1632. (org-insert-heading))
  1633. (buffer-string))))
  1634. (should
  1635. (equal "Paragraph\n* "
  1636. (org-test-with-temp-text "Para<point>graph"
  1637. (let ((org-M-RET-may-split-line '((default . nil))))
  1638. (org-insert-heading))
  1639. (buffer-string))))
  1640. ;; At the beginning of a headline, create one above.
  1641. (should
  1642. (equal "* \n* H"
  1643. (org-test-with-temp-text "* H"
  1644. (org-insert-heading)
  1645. (buffer-string))))
  1646. ;; In the middle of a headline, split it if allowed.
  1647. (should
  1648. (equal "* H\n* 1"
  1649. (org-test-with-temp-text "* H<point>1"
  1650. (let ((org-M-RET-may-split-line '((headline . t))))
  1651. (org-insert-heading))
  1652. (buffer-string))))
  1653. (should
  1654. (equal "* H1\n* "
  1655. (org-test-with-temp-text "* H<point>1"
  1656. (let ((org-M-RET-may-split-line '((headline . nil))))
  1657. (org-insert-heading))
  1658. (buffer-string))))
  1659. ;; However, splitting cannot happen on TODO keywords, priorities or
  1660. ;; tags.
  1661. (should
  1662. (equal "* TODO H1\n* "
  1663. (org-test-with-temp-text "* TO<point>DO H1"
  1664. (let ((org-M-RET-may-split-line '((headline . t))))
  1665. (org-insert-heading))
  1666. (buffer-string))))
  1667. (should
  1668. (equal "* [#A] H1\n* "
  1669. (org-test-with-temp-text "* [#<point>A] H1"
  1670. (let ((org-M-RET-may-split-line '((headline . t))))
  1671. (org-insert-heading))
  1672. (buffer-string))))
  1673. (should
  1674. (equal "* H1 :tag:\n* "
  1675. (org-test-with-temp-text "* H1 :ta<point>g:"
  1676. (let ((org-M-RET-may-split-line '((headline . t))))
  1677. (org-insert-heading))
  1678. (buffer-string))))
  1679. ;; New headline level depends on the level of the headline above.
  1680. (should
  1681. (equal "** H\n** P"
  1682. (org-test-with-temp-text "** H\n<point>P"
  1683. (org-insert-heading)
  1684. (buffer-string))))
  1685. (should
  1686. (equal "** H\nPara\n** graph"
  1687. (org-test-with-temp-text "** H\nPara<point>graph"
  1688. (let ((org-M-RET-may-split-line '((default . t))))
  1689. (org-insert-heading))
  1690. (buffer-string))))
  1691. (should
  1692. (equal "** \n** H"
  1693. (org-test-with-temp-text "** H"
  1694. (org-insert-heading)
  1695. (buffer-string))))
  1696. ;; When called with one universal argument, insert a new headline at
  1697. ;; the end of the current subtree, independently on the position of
  1698. ;; point.
  1699. (should
  1700. (equal
  1701. "* "
  1702. (org-test-with-temp-text ""
  1703. (let ((org-insert-heading-respect-content nil))
  1704. (org-insert-heading '(4)))
  1705. (buffer-string))))
  1706. (should
  1707. (equal
  1708. "entry
  1709. * "
  1710. (org-test-with-temp-text "entry"
  1711. (let ((org-insert-heading-respect-content nil))
  1712. (org-insert-heading '(4)))
  1713. (buffer-string))))
  1714. (should
  1715. (equal
  1716. "* H1\n** H2\n* "
  1717. (org-test-with-temp-text "* H1\n** H2"
  1718. (let ((org-insert-heading-respect-content nil))
  1719. (org-insert-heading '(4)))
  1720. (buffer-string))))
  1721. (should
  1722. (equal
  1723. "* H1\n** H2\n* "
  1724. (org-test-with-temp-text "* H<point>1\n** H2"
  1725. (let ((org-insert-heading-respect-content nil))
  1726. (org-insert-heading '(4)))
  1727. (buffer-string))))
  1728. ;; When called with two universal arguments, insert a new headline
  1729. ;; at the end of the grandparent subtree.
  1730. (should
  1731. (equal "* H1\n** H3\n- item\n** H2\n** "
  1732. (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
  1733. (let ((org-insert-heading-respect-content nil))
  1734. (org-insert-heading '(16)))
  1735. (buffer-string))))
  1736. ;; When optional TOP-LEVEL argument is non-nil, always insert
  1737. ;; a level 1 heading.
  1738. (should
  1739. (equal "* H1\n** H2\n* "
  1740. (org-test-with-temp-text "* H1\n** H2<point>"
  1741. (org-insert-heading nil nil t)
  1742. (buffer-string))))
  1743. (should
  1744. (equal "* H1\n- item\n* "
  1745. (org-test-with-temp-text "* H1\n- item<point>"
  1746. (org-insert-heading nil nil t)
  1747. (buffer-string))))
  1748. ;; Obey `org-blank-before-new-entry'.
  1749. (should
  1750. (equal "* H1\n\n* "
  1751. (org-test-with-temp-text "* H1<point>"
  1752. (let ((org-blank-before-new-entry '((heading . t))))
  1753. (org-insert-heading))
  1754. (buffer-string))))
  1755. (should
  1756. (equal "* H1\n* "
  1757. (org-test-with-temp-text "* H1<point>"
  1758. (let ((org-blank-before-new-entry '((heading . nil))))
  1759. (org-insert-heading))
  1760. (buffer-string))))
  1761. (should
  1762. (equal "* H1\n* H2\n* "
  1763. (org-test-with-temp-text "* H1\n* H2<point>"
  1764. (let ((org-blank-before-new-entry '((heading . auto))))
  1765. (org-insert-heading))
  1766. (buffer-string))))
  1767. (should
  1768. (equal "* H1\n\n* H2\n\n* "
  1769. (org-test-with-temp-text "* H1\n\n* H2<point>"
  1770. (let ((org-blank-before-new-entry '((heading . auto))))
  1771. (org-insert-heading))
  1772. (buffer-string))))
  1773. ;; Corner case: correctly insert a headline after an empty one.
  1774. (should
  1775. (equal "* \n* "
  1776. (org-test-with-temp-text "* <point>"
  1777. (org-insert-heading)
  1778. (buffer-string))))
  1779. (should
  1780. (org-test-with-temp-text "* <point>\n"
  1781. (org-insert-heading)
  1782. (looking-at-p "\n\\'")))
  1783. ;; Do not insert spurious headlines when inserting a new headline.
  1784. (should
  1785. (equal "* H1\n* H2\n* \n"
  1786. (org-test-with-temp-text "* H1\n* H2<point>\n"
  1787. (org-insert-heading)
  1788. (buffer-string))))
  1789. ;; Preserve visibility at beginning of line. In particular, when
  1790. ;; removing spurious blank lines, do not visually merge heading with
  1791. ;; the line visible above.
  1792. (should-not
  1793. (org-test-with-temp-text "* H1<point>\nContents\n\n* H2\n"
  1794. (org-overview)
  1795. (let ((org-blank-before-new-entry '((heading . nil))))
  1796. (org-insert-heading '(4)))
  1797. (invisible-p (line-end-position 0))))
  1798. ;; Properly handle empty lines when forcing a headline below current
  1799. ;; one.
  1800. (should
  1801. (equal "* H1\n\n* H\n\n* "
  1802. (org-test-with-temp-text "* H1\n\n* H<point>"
  1803. (let ((org-blank-before-new-entry '((heading . t))))
  1804. (org-insert-heading '(4))
  1805. (buffer-string))))))
  1806. (ert-deftest test-org/insert-todo-heading-respect-content ()
  1807. "Test `org-insert-todo-heading-respect-content' specifications."
  1808. ;; Create a TODO heading.
  1809. (should
  1810. (org-test-with-temp-text "* H1\n Body"
  1811. (org-insert-todo-heading-respect-content)
  1812. (nth 2 (org-heading-components))))
  1813. ;; Add headline at the end of the first subtree
  1814. (should
  1815. (equal
  1816. "* TODO "
  1817. (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
  1818. (org-insert-todo-heading-respect-content)
  1819. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1820. ;; In a list, do not create a new item.
  1821. (should
  1822. (equal
  1823. "* TODO "
  1824. (org-test-with-temp-text "* H\n- an item\n- another one"
  1825. (search-forward "an ")
  1826. (org-insert-todo-heading-respect-content)
  1827. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1828. ;; Use the same TODO keyword as current heading.
  1829. (should
  1830. (equal
  1831. "* TODO \n"
  1832. (org-test-with-temp-text "* TODO\n** WAITING\n"
  1833. (org-insert-todo-heading-respect-content)
  1834. (buffer-substring-no-properties (line-beginning-position) (point-max))))))
  1835. (ert-deftest test-org/clone-with-time-shift ()
  1836. "Test `org-clone-subtree-with-time-shift'."
  1837. ;; Raise an error before first heading.
  1838. (should-error
  1839. (org-test-with-temp-text ""
  1840. (org-clone-subtree-with-time-shift 1)))
  1841. ;; Raise an error on invalid number of clones.
  1842. (should-error
  1843. (org-test-with-temp-text "* Clone me"
  1844. (org-clone-subtree-with-time-shift -1)))
  1845. ;; Clone non-repeating once.
  1846. (should
  1847. (equal "\
  1848. * H1\n<2015-06-21>
  1849. * H1\n<2015-06-23>
  1850. "
  1851. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1852. (org-clone-subtree-with-time-shift 1 "+2d")
  1853. (replace-regexp-in-string
  1854. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1855. nil nil 1))))
  1856. ;; Clone repeating once.
  1857. (should
  1858. (equal "\
  1859. * H1\n<2015-06-21>
  1860. * H1\n<2015-06-23>
  1861. * H1\n<2015-06-25 +1w>
  1862. "
  1863. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1864. (org-clone-subtree-with-time-shift 1 "+2d")
  1865. (replace-regexp-in-string
  1866. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1867. nil nil 1))))
  1868. ;; Clone repeating once in backward.
  1869. (should
  1870. (equal "\
  1871. * H1\n<2015-06-21>
  1872. * H1\n<2015-06-19>
  1873. * H1\n<2015-06-17 +1w>
  1874. "
  1875. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1876. (org-clone-subtree-with-time-shift 1 "-2d")
  1877. (replace-regexp-in-string
  1878. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1879. nil nil 1))))
  1880. ;; Clone non-repeating zero times.
  1881. (should
  1882. (equal "\
  1883. * H1\n<2015-06-21>
  1884. "
  1885. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1886. (org-clone-subtree-with-time-shift 0 "+2d")
  1887. (replace-regexp-in-string
  1888. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1889. nil nil 1))))
  1890. ;; Clone repeating "zero" times.
  1891. (should
  1892. (equal "\
  1893. * H1\n<2015-06-21>
  1894. * H1\n<2015-06-23 +1w>
  1895. "
  1896. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1897. (org-clone-subtree-with-time-shift 0 "+2d")
  1898. (replace-regexp-in-string
  1899. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1900. nil nil 1))))
  1901. ;; Clone with blank SHIFT argument.
  1902. (should
  1903. (string-prefix-p
  1904. "* H <2012-03-29"
  1905. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1906. (org-clone-subtree-with-time-shift 1 "")
  1907. (buffer-substring-no-properties (line-beginning-position 2)
  1908. (line-end-position 2)))))
  1909. ;; Find time stamps before point. If SHIFT is not specified, ask
  1910. ;; for a time shift.
  1911. (should
  1912. (string-prefix-p
  1913. "* H <2012-03-30"
  1914. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1915. (org-clone-subtree-with-time-shift 1 "+1d")
  1916. (buffer-substring-no-properties (line-beginning-position 2)
  1917. (line-end-position 2)))))
  1918. (should
  1919. (string-prefix-p
  1920. "* H <2014-03-05"
  1921. (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
  1922. (cl-letf (((symbol-function 'read-from-minibuffer)
  1923. (lambda (&rest args) "+1d")))
  1924. (org-clone-subtree-with-time-shift 1))
  1925. (buffer-substring-no-properties (line-beginning-position 2)
  1926. (line-end-position 2)))))
  1927. ;; Hour shift.
  1928. (should
  1929. (equal "\
  1930. * H1\n<2015-06-21 20:00>
  1931. * H1\n<2015-06-21 23:00>
  1932. * H1\n<2015-06-22 02:00>
  1933. "
  1934. (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>"
  1935. (org-clone-subtree-with-time-shift 2 "+3h")
  1936. (replace-regexp-in-string
  1937. "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" ""
  1938. (buffer-substring-no-properties (point-min) (point-max))
  1939. nil nil 1))))
  1940. (should
  1941. (equal "\
  1942. * H1\n<2015-06-21 20:00>
  1943. * H1\n<2015-06-21 18:00>
  1944. "
  1945. (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>"
  1946. (org-clone-subtree-with-time-shift 1 "-2h")
  1947. (replace-regexp-in-string
  1948. "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" ""
  1949. (buffer-substring-no-properties (point-min) (point-max))
  1950. nil nil 1)))))
  1951. ;;; Fixed-Width Areas
  1952. (ert-deftest test-org/toggle-fixed-width ()
  1953. "Test `org-toggle-fixed-width' specifications."
  1954. ;; No region: Toggle on fixed-width marker in paragraphs.
  1955. (should
  1956. (equal ": A"
  1957. (org-test-with-temp-text "A"
  1958. (org-toggle-fixed-width)
  1959. (buffer-string))))
  1960. ;; No region: Toggle off fixed-width markers in fixed-width areas.
  1961. (should
  1962. (equal "A"
  1963. (org-test-with-temp-text ": A"
  1964. (org-toggle-fixed-width)
  1965. (buffer-string))))
  1966. ;; No region: Toggle on marker in blank lines after elements or just
  1967. ;; after a headline.
  1968. (should
  1969. (equal "* H\n: "
  1970. (org-test-with-temp-text "* H\n"
  1971. (forward-line)
  1972. (org-toggle-fixed-width)
  1973. (buffer-string))))
  1974. (should
  1975. (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
  1976. (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
  1977. (goto-char (point-max))
  1978. (org-toggle-fixed-width)
  1979. (buffer-string))))
  1980. ;; No region: Toggle on marker in front of one line elements (e.g.,
  1981. ;; headlines, clocks)
  1982. (should
  1983. (equal ": * Headline"
  1984. (org-test-with-temp-text "* Headline"
  1985. (org-toggle-fixed-width)
  1986. (buffer-string))))
  1987. (should
  1988. (equal ": #+KEYWORD: value"
  1989. (org-test-with-temp-text "#+KEYWORD: value"
  1990. (org-toggle-fixed-width)
  1991. (buffer-string))))
  1992. ;; No region: error in other situations.
  1993. (should-error
  1994. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
  1995. (forward-line)
  1996. (org-toggle-fixed-width)
  1997. (buffer-string)))
  1998. ;; No region: Indentation is preserved.
  1999. (should
  2000. (equal "- A\n : B"
  2001. (org-test-with-temp-text "- A\n B"
  2002. (forward-line)
  2003. (org-toggle-fixed-width)
  2004. (buffer-string))))
  2005. ;; Region: If it contains only fixed-width elements and blank lines,
  2006. ;; toggle off fixed-width markup.
  2007. (should
  2008. (equal "A\n\nB"
  2009. (org-test-with-temp-text ": A\n\n: B"
  2010. (transient-mark-mode 1)
  2011. (push-mark (point) t t)
  2012. (goto-char (point-max))
  2013. (org-toggle-fixed-width)
  2014. (buffer-string))))
  2015. ;; Region: If it contains anything else, toggle on fixed-width but
  2016. ;; not on fixed-width areas.
  2017. (should
  2018. (equal ": A\n: \n: B\n: \n: C"
  2019. (org-test-with-temp-text "A\n\n: B\n\nC"
  2020. (transient-mark-mode 1)
  2021. (push-mark (point) t t)
  2022. (goto-char (point-max))
  2023. (org-toggle-fixed-width)
  2024. (buffer-string))))
  2025. ;; Region: Ignore blank lines at its end, unless it contains only
  2026. ;; such lines.
  2027. (should
  2028. (equal ": A\n\n"
  2029. (org-test-with-temp-text "A\n\n"
  2030. (transient-mark-mode 1)
  2031. (push-mark (point) t t)
  2032. (goto-char (point-max))
  2033. (org-toggle-fixed-width)
  2034. (buffer-string))))
  2035. (should
  2036. (equal ": \n: \n"
  2037. (org-test-with-temp-text "\n\n"
  2038. (transient-mark-mode 1)
  2039. (push-mark (point) t t)
  2040. (goto-char (point-max))
  2041. (org-toggle-fixed-width)
  2042. (buffer-string)))))
  2043. (ert-deftest test-org/kill-line ()
  2044. "Test `org-kill-line' specifications."
  2045. ;; At the beginning of a line, kill whole line.
  2046. (should
  2047. (equal ""
  2048. (org-test-with-temp-text "abc"
  2049. (org-kill-line)
  2050. (buffer-string))))
  2051. ;; In the middle of a line, kill line until its end.
  2052. (should
  2053. (equal "a"
  2054. (org-test-with-temp-text "a<point>bc"
  2055. (org-kill-line)
  2056. (buffer-string))))
  2057. ;; Do not kill newline character.
  2058. (should
  2059. (equal "\n123"
  2060. (org-test-with-temp-text "abc\n123"
  2061. (org-kill-line)
  2062. (buffer-string))))
  2063. (should
  2064. (equal "a\n123"
  2065. (org-test-with-temp-text "a<point>bc\n123"
  2066. (org-kill-line)
  2067. (buffer-string))))
  2068. ;; When `org-special-ctrl-k' is non-nil and point is at a headline,
  2069. ;; kill until tags.
  2070. (should
  2071. (equal "* A :tag:"
  2072. (org-test-with-temp-text "* A<point>B :tag:"
  2073. (let ((org-special-ctrl-k t)
  2074. (org-tags-column 0))
  2075. (org-kill-line))
  2076. (buffer-string))))
  2077. ;; If point is on tags, only kill part left until the end of line.
  2078. (should
  2079. (equal "* A :tag:"
  2080. (org-test-with-temp-text "* A :tag:<point>tag2:"
  2081. (let ((org-special-ctrl-k t)
  2082. (org-tags-column 0))
  2083. (org-kill-line))
  2084. (buffer-string))))
  2085. ;; However, if point is at the beginning of the line, kill whole
  2086. ;; headline.
  2087. (should
  2088. (equal ""
  2089. (org-test-with-temp-text "* AB :tag:"
  2090. (let ((org-special-ctrl-k t)
  2091. (org-tags-column 0))
  2092. (org-kill-line))
  2093. (buffer-string))))
  2094. ;; When `org-ctrl-k-protect-subtree' is non-nil, and point is in
  2095. ;; invisible text, ask before removing it. When set to `error',
  2096. ;; throw an error.
  2097. (should-error
  2098. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  2099. (org-overview)
  2100. (let ((org-special-ctrl-k nil)
  2101. (org-ctrl-k-protect-subtree t))
  2102. (cl-letf (((symbol-function 'y-or-n-p) 'ignore))
  2103. (org-kill-line)))))
  2104. (should-error
  2105. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  2106. (org-overview)
  2107. (let ((org-special-ctrl-k nil)
  2108. (org-ctrl-k-protect-subtree 'error))
  2109. (org-kill-line)))))
  2110. ;;; Headline
  2111. (ert-deftest test-org/get-heading ()
  2112. "Test `org-get-heading' specifications."
  2113. ;; Return current heading, even if point is not on it.
  2114. (should
  2115. (equal "H"
  2116. (org-test-with-temp-text "* H"
  2117. (org-get-heading))))
  2118. (should
  2119. (equal "H"
  2120. (org-test-with-temp-text "* H\nText<point>"
  2121. (org-get-heading))))
  2122. ;; Without any optional argument, return TODO keyword, priority
  2123. ;; cookie, COMMENT keyword and tags.
  2124. (should
  2125. (equal "TODO H"
  2126. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2127. (org-get-heading))))
  2128. (should
  2129. (equal "[#A] H"
  2130. (org-test-with-temp-text "* [#A] H"
  2131. (org-get-heading))))
  2132. (should
  2133. (equal "COMMENT H"
  2134. (org-test-with-temp-text "* COMMENT H"
  2135. (org-get-heading))))
  2136. (should
  2137. (equal "H :tag:"
  2138. (org-test-with-temp-text "* H :tag:"
  2139. (org-get-heading))))
  2140. ;; With NO-TAGS argument, ignore tags.
  2141. (should
  2142. (equal "TODO H"
  2143. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2144. (org-get-heading t))))
  2145. (should
  2146. (equal "H"
  2147. (org-test-with-temp-text "* H :tag:"
  2148. (org-get-heading t))))
  2149. ;; With NO-TODO, ignore TODO keyword.
  2150. (should
  2151. (equal "H"
  2152. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2153. (org-get-heading nil t))))
  2154. (should
  2155. (equal "H :tag:"
  2156. (org-test-with-temp-text "* H :tag:"
  2157. (org-get-heading nil t))))
  2158. ;; TODO keywords are case-sensitive.
  2159. (should
  2160. (equal "Todo H"
  2161. (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
  2162. (org-get-heading nil t))))
  2163. ;; With NO-PRIORITY, ignore priority.
  2164. (should
  2165. (equal "H"
  2166. (org-test-with-temp-text "* [#A] H"
  2167. (org-get-heading nil nil t))))
  2168. (should
  2169. (equal "H"
  2170. (org-test-with-temp-text "* H"
  2171. (org-get-heading nil nil t))))
  2172. (should
  2173. (equal "TODO H"
  2174. (org-test-with-temp-text "* TODO [#A] H"
  2175. (org-get-heading nil nil t))))
  2176. ;; With NO-COMMENT, ignore COMMENT keyword.
  2177. (should
  2178. (equal "H"
  2179. (org-test-with-temp-text "* COMMENT H"
  2180. (org-get-heading nil nil nil t))))
  2181. (should
  2182. (equal "H"
  2183. (org-test-with-temp-text "* H"
  2184. (org-get-heading nil nil nil t))))
  2185. (should
  2186. (equal "TODO [#A] H"
  2187. (org-test-with-temp-text "* TODO [#A] COMMENT H"
  2188. (org-get-heading nil nil nil t))))
  2189. ;; On an empty headline, return value is consistent.
  2190. (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
  2191. (should (equal "" (org-test-with-temp-text "* " (org-get-heading t))))
  2192. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t))))
  2193. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t))))
  2194. (should
  2195. (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t)))))
  2196. (ert-deftest test-org/in-commented-heading-p ()
  2197. "Test `org-in-commented-heading-p' specifications."
  2198. ;; Commented headline.
  2199. (should
  2200. (org-test-with-temp-text "* COMMENT Headline\nBody"
  2201. (goto-char (point-max))
  2202. (org-in-commented-heading-p)))
  2203. ;; Commented ancestor.
  2204. (should
  2205. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  2206. (goto-char (point-max))
  2207. (org-in-commented-heading-p)))
  2208. ;; Comment keyword is case-sensitive.
  2209. (should-not
  2210. (org-test-with-temp-text "* Comment Headline\nBody"
  2211. (goto-char (point-max))
  2212. (org-in-commented-heading-p)))
  2213. ;; Keyword is standalone.
  2214. (should-not
  2215. (org-test-with-temp-text "* COMMENTHeadline\nBody"
  2216. (goto-char (point-max))
  2217. (org-in-commented-heading-p)))
  2218. ;; Optional argument.
  2219. (should-not
  2220. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  2221. (goto-char (point-max))
  2222. (org-in-commented-heading-p t))))
  2223. (ert-deftest test-org/in-archived-heading-p ()
  2224. "Test `org-in-archived-heading-p' specifications."
  2225. ;; Archived headline.
  2226. (should
  2227. (org-test-with-temp-text "* Headline :ARCHIVE:\nBody"
  2228. (goto-char (point-max))
  2229. (org-in-archived-heading-p)))
  2230. ;; Archived ancestor.
  2231. (should
  2232. (org-test-with-temp-text "* Headline :ARCHIVE:\n** Level 2\nBody"
  2233. (goto-char (point-max))
  2234. (org-in-archived-heading-p)))
  2235. ;; Optional argument.
  2236. (should-not
  2237. (org-test-with-temp-text "* Headline :ARCHIVE:\n** Level 2\nBody"
  2238. (goto-char (point-max))
  2239. (org-in-archived-heading-p t)))
  2240. ;; Archive tag containing ARCHIVE as substring
  2241. (should-not
  2242. (org-test-with-temp-text "* Headline :NOARCHIVE:\n** Level 2\nBody"
  2243. (goto-char (point-max))
  2244. (org-in-archived-heading-p))))
  2245. (ert-deftest test-org/entry-blocked-p ()
  2246. ;; Check other dependencies.
  2247. (should
  2248. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  2249. (let ((org-enforce-todo-dependencies t)
  2250. (org-blocker-hook
  2251. '(org-block-todo-from-children-or-siblings-or-parent)))
  2252. (org-entry-blocked-p))))
  2253. (should-not
  2254. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  2255. (let ((org-enforce-todo-dependencies t)
  2256. (org-blocker-hook
  2257. '(org-block-todo-from-children-or-siblings-or-parent)))
  2258. (org-entry-blocked-p))))
  2259. ;; Entry without a TODO keyword or with a DONE keyword cannot be
  2260. ;; blocked.
  2261. (should-not
  2262. (org-test-with-temp-text "* Blocked\n** TODO one"
  2263. (let ((org-enforce-todo-dependencies t)
  2264. (org-blocker-hook
  2265. '(org-block-todo-from-children-or-siblings-or-parent)))
  2266. (org-entry-blocked-p))))
  2267. (should-not
  2268. (org-test-with-temp-text "* DONE Blocked\n** TODO one"
  2269. (let ((org-enforce-todo-dependencies t)
  2270. (org-blocker-hook
  2271. '(org-block-todo-from-children-or-siblings-or-parent)))
  2272. (org-entry-blocked-p))))
  2273. ;; Follow :ORDERED: specifications.
  2274. (should
  2275. (org-test-with-temp-text
  2276. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
  2277. (let ((org-enforce-todo-dependencies t)
  2278. (org-blocker-hook
  2279. '(org-block-todo-from-children-or-siblings-or-parent)))
  2280. (org-entry-blocked-p))))
  2281. (should-not
  2282. (org-test-with-temp-text
  2283. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
  2284. (let ((org-enforce-todo-dependencies t)
  2285. (org-blocker-hook
  2286. '(org-block-todo-from-children-or-siblings-or-parent)))
  2287. (org-entry-blocked-p)))))
  2288. (ert-deftest test-org/get-outline-path ()
  2289. "Test `org-get-outline-path' specifications."
  2290. ;; Top-level headlines have no outline path.
  2291. (should-not
  2292. (org-test-with-temp-text "* H"
  2293. (org-get-outline-path)))
  2294. ;; Otherwise, outline path is the path leading to the headline.
  2295. (should
  2296. (equal '("H")
  2297. (org-test-with-temp-text "* H\n** S<point>"
  2298. (org-get-outline-path))))
  2299. ;; Find path even when point is not on a headline.
  2300. (should
  2301. (equal '("H")
  2302. (org-test-with-temp-text "* H\n** S\nText<point>"
  2303. (org-get-outline-path))))
  2304. ;; TODO keywords, tags and statistics cookies are ignored.
  2305. (should
  2306. (equal '("H")
  2307. (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
  2308. (org-get-outline-path))))
  2309. ;; Links are replaced with their description or their path.
  2310. (should
  2311. (equal '("Org")
  2312. (org-test-with-temp-text
  2313. "* [[https://orgmode.org][Org]]\n** S<point>"
  2314. (org-get-outline-path))))
  2315. (should
  2316. (equal '("https://orgmode.org")
  2317. (org-test-with-temp-text
  2318. "* [[https://orgmode.org]]\n** S<point>"
  2319. (org-get-outline-path))))
  2320. ;; When WITH-SELF is non-nil, include current heading.
  2321. (should
  2322. (equal '("H")
  2323. (org-test-with-temp-text "* H"
  2324. (org-get-outline-path t))))
  2325. (should
  2326. (equal '("H" "S")
  2327. (org-test-with-temp-text "* H\n** S\nText<point>"
  2328. (org-get-outline-path t))))
  2329. ;; Using cache is transparent to the user.
  2330. (should
  2331. (equal '("H")
  2332. (org-test-with-temp-text "* H\n** S<point>"
  2333. (setq org-outline-path-cache nil)
  2334. (org-get-outline-path nil t))))
  2335. ;; Do not corrupt cache when finding outline path in distant part of
  2336. ;; the buffer.
  2337. (should
  2338. (equal '("H2")
  2339. (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
  2340. (setq org-outline-path-cache nil)
  2341. (org-get-outline-path nil t)
  2342. (search-forward "S2")
  2343. (org-get-outline-path nil t))))
  2344. ;; Do not choke on empty headlines.
  2345. (should
  2346. (org-test-with-temp-text "* H\n** <point>"
  2347. (org-get-outline-path)))
  2348. (should
  2349. (org-test-with-temp-text "* \n** H<point>"
  2350. (org-get-outline-path))))
  2351. (ert-deftest test-org/format-outline-path ()
  2352. "Test `org-format-outline-path' specifications."
  2353. (should
  2354. (string= (org-format-outline-path (list "one" "two" "three"))
  2355. "one/two/three"))
  2356. ;; Empty path.
  2357. (should
  2358. (string= (org-format-outline-path '())
  2359. ""))
  2360. (should
  2361. (string= (org-format-outline-path '(nil))
  2362. ""))
  2363. ;; Empty path and prefix.
  2364. (should
  2365. (string= (org-format-outline-path '() nil ">>")
  2366. ">>"))
  2367. ;; Trailing whitespace in headings.
  2368. (should
  2369. (string= (org-format-outline-path (list "one\t" "tw o " "three "))
  2370. "one/tw o/three"))
  2371. ;; Non-default prefix and separators.
  2372. (should
  2373. (string= (org-format-outline-path (list "one" "two" "three") nil ">>" "|")
  2374. ">>|one|two|three"))
  2375. ;; Truncate.
  2376. (should
  2377. (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
  2378. "one/two/.."))
  2379. ;; Give a very narrow width.
  2380. (should
  2381. (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
  2382. "on"))
  2383. ;; Give a prefix that extends beyond the width.
  2384. (should
  2385. (string= (org-format-outline-path (list "one" "two" "three" "four") 10
  2386. ">>>>>>>>>>")
  2387. ">>>>>>>>..")))
  2388. (ert-deftest test-org/org-find-olp ()
  2389. "Test `org-find-olp' specifications."
  2390. (org-test-with-temp-text
  2391. "
  2392. * Headline
  2393. ** COMMENT headline2
  2394. ** TODO headline3
  2395. *** [#A] headline4 :tags:
  2396. ** [#A]headline5
  2397. ** [0%] headline6
  2398. ** headline7 [100%]
  2399. ** headline8 [1/5] :some:more:tags:
  2400. * Test
  2401. "
  2402. (should (org-find-olp '("Headline") t))
  2403. (should-error (org-find-olp '("Headline" "Test") t))
  2404. (should-error (org-find-olp '("Headlinealksjd") t))
  2405. (should (org-find-olp '("Headline" "headline2") t))
  2406. (should (org-find-olp '("Headline" "headline3") t))
  2407. (should (org-find-olp '("Headline" "headline3" "headline4") t))
  2408. (should-error (org-find-olp '("Headline" "headline5") t))
  2409. (should (org-find-olp '("Headline" "headline6") t))
  2410. (should (org-find-olp '("Headline" "headline7") t))
  2411. (should (org-find-olp '("Headline" "headline8") t))))
  2412. (ert-deftest test-org/map-entries ()
  2413. "Test `org-map-entries' specifications."
  2414. ;; Full match.
  2415. (should
  2416. (equal '(1 11)
  2417. (org-test-with-temp-text "* Level 1\n** Level 2"
  2418. (org-map-entries #'point))))
  2419. ;; Level match.
  2420. (should
  2421. (equal '(1)
  2422. (org-test-with-temp-text "* Level 1\n** Level 2"
  2423. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL=1")))))
  2424. (should
  2425. (equal '(11)
  2426. (org-test-with-temp-text "* Level 1\n** Level 2"
  2427. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL>1")))))
  2428. ;; Tag match.
  2429. (should
  2430. (equal '(11)
  2431. (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
  2432. (org-map-entries #'point "yes"))))
  2433. (should
  2434. (equal '(14)
  2435. (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
  2436. (org-map-entries #'point "+yes-a"))))
  2437. (should
  2438. (equal '(11 23)
  2439. (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
  2440. (org-map-entries #'point "{yes?}"))))
  2441. ;; Priority match.
  2442. (should
  2443. (equal '(1)
  2444. (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
  2445. (org-map-entries #'point "PRIORITY=\"A\""))))
  2446. ;; Date match.
  2447. (should
  2448. (equal '(36)
  2449. (org-test-with-temp-text "
  2450. * H1
  2451. SCHEDULED: <2012-03-29 thu.>
  2452. * H2
  2453. SCHEDULED: <2014-03-04 tue.>"
  2454. (org-map-entries #'point "SCHEDULED=\"<2014-03-04 tue.>\""))))
  2455. (should
  2456. (equal '(2)
  2457. (org-test-with-temp-text "
  2458. * H1
  2459. SCHEDULED: <2012-03-29 thu.>
  2460. * H2
  2461. SCHEDULED: <2014-03-04 tue.>"
  2462. (org-map-entries #'point "SCHEDULED<\"<2013-01-01>\""))))
  2463. ;; Regular property match.
  2464. (should
  2465. (equal '(2)
  2466. (org-test-with-temp-text "
  2467. * H1
  2468. :PROPERTIES:
  2469. :TEST: 1
  2470. :END:
  2471. * H2
  2472. :PROPERTIES:
  2473. :TEST: 2
  2474. :END:"
  2475. (org-map-entries #'point "TEST=1"))))
  2476. ;; Multiple criteria.
  2477. (should
  2478. (equal '(23)
  2479. (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
  2480. (let (org-odd-levels-only
  2481. (org-use-tag-inheritance nil))
  2482. (org-map-entries #'point "yes+LEVEL=1")))))
  2483. ;; "or" criteria.
  2484. (should
  2485. (equal '(12 24)
  2486. (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
  2487. (let (org-odd-levels-only)
  2488. (org-map-entries #'point "LEVEL=2|no")))))
  2489. (should
  2490. (equal '(1 12)
  2491. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
  2492. (let (org-odd-levels-only)
  2493. (org-map-entries #'point "yes|no")))))
  2494. ;; "and" criteria.
  2495. (should
  2496. (equal '(22)
  2497. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
  2498. (let (org-odd-levels-only)
  2499. (org-map-entries #'point "yes&no")))))
  2500. ;; Setting `org-map-continue-from'
  2501. (should
  2502. (string= ""
  2503. (org-test-with-temp-text "* H1\n* H2\n* H3n* H4"
  2504. (org-map-entries
  2505. (lambda ()
  2506. (org-cut-subtree)
  2507. (setq org-map-continue-from (point))))
  2508. (buffer-string))))
  2509. (should
  2510. (string= "* H1\n* H2\n* H3\n"
  2511. (org-test-with-temp-text "* H1\n* H2\n* H3\n* H4"
  2512. (org-map-entries
  2513. (lambda ()
  2514. (when (string= "H4"
  2515. (org-element-property
  2516. :raw-value (org-element-at-point)))
  2517. (org-cut-subtree)
  2518. (setq org-map-continue-from
  2519. (org-element-property
  2520. :begin (org-element-at-point))))))
  2521. (buffer-string)))))
  2522. (ert-deftest test-org/edit-headline ()
  2523. "Test `org-edit-headline' specifications."
  2524. (should
  2525. (equal "* B"
  2526. (org-test-with-temp-text "* A"
  2527. (org-edit-headline "B")
  2528. (buffer-string))))
  2529. ;; Handle empty headings.
  2530. (should
  2531. (equal "* "
  2532. (org-test-with-temp-text "* A"
  2533. (org-edit-headline "")
  2534. (buffer-string))))
  2535. (should
  2536. (equal "* A"
  2537. (org-test-with-temp-text "* "
  2538. (org-edit-headline "A")
  2539. (buffer-string))))
  2540. ;; Handle TODO keywords and priority cookies.
  2541. (should
  2542. (equal "* TODO B"
  2543. (org-test-with-temp-text "* TODO A"
  2544. (org-edit-headline "B")
  2545. (buffer-string))))
  2546. (should
  2547. (equal "* [#A] B"
  2548. (org-test-with-temp-text "* [#A] A"
  2549. (org-edit-headline "B")
  2550. (buffer-string))))
  2551. (should
  2552. (equal "* TODO [#A] B"
  2553. (org-test-with-temp-text "* TODO [#A] A"
  2554. (org-edit-headline "B")
  2555. (buffer-string))))
  2556. ;; Handle tags.
  2557. (equal "* B :tag:"
  2558. (org-test-with-temp-text "* A :tag:"
  2559. (let ((org-tags-column 4)) (org-edit-headline "B"))
  2560. (buffer-string))))
  2561. ;;; Keywords
  2562. (ert-deftest test-org/set-regexps-and-options ()
  2563. "Test `org-set-regexps-and-options' specifications."
  2564. ;; TAGS keyword.
  2565. (should
  2566. (equal '(("A"))
  2567. (let ((org-tag-alist '(("A")))
  2568. (org-tag-persistent-alist nil))
  2569. (org-test-with-temp-text ""
  2570. (org-mode-restart)
  2571. org-current-tag-alist))))
  2572. (should
  2573. (equal '(("B"))
  2574. (let ((org-tag-alist '(("A")))
  2575. (org-tag-persistent-alist nil))
  2576. (org-test-with-temp-text "#+TAGS: B"
  2577. (org-mode-restart)
  2578. org-current-tag-alist))))
  2579. (should
  2580. (equal '(("C") ("B"))
  2581. (let ((org-tag-alist '(("A")))
  2582. (org-tag-persistent-alist '(("C"))))
  2583. (org-test-with-temp-text "#+TAGS: B"
  2584. (org-mode-restart)
  2585. org-current-tag-alist))))
  2586. (should
  2587. (equal '(("B"))
  2588. (let ((org-tag-alist '(("A")))
  2589. (org-tag-persistent-alist '(("C"))))
  2590. (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
  2591. (org-mode-restart)
  2592. org-current-tag-alist))))
  2593. (should
  2594. (equal '(("A" . ?a) ("B") ("C"))
  2595. (let ((org-tag-persistant-alist nil))
  2596. (org-test-with-temp-text "#+TAGS: A(a) B C"
  2597. (org-mode-restart)
  2598. org-current-tag-alist))))
  2599. (should
  2600. (equal '(("A") (:newline) ("B"))
  2601. (let ((org-tag-persistent-alist nil))
  2602. (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
  2603. (org-mode-restart)
  2604. org-current-tag-alist))))
  2605. (should
  2606. (equal '((:startgroup) ("A") ("B") (:endgroup) ("C"))
  2607. (let ((org-tag-persistent-alist nil))
  2608. (org-test-with-temp-text "#+TAGS: { A B } C"
  2609. (org-mode-restart)
  2610. org-current-tag-alist))))
  2611. (should
  2612. (equal '((:startgroup) ("A") (:grouptags) ("B") ("C") (:endgroup))
  2613. (let ((org-tag-persistent-alist nil))
  2614. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2615. (org-mode-restart)
  2616. org-current-tag-alist))))
  2617. (should
  2618. (equal '(("A" "B" "C"))
  2619. (let ((org-tag-persistent-alist nil))
  2620. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2621. (org-mode-restart)
  2622. org-tag-groups-alist))))
  2623. (should
  2624. (equal '((:startgrouptag) ("A") (:grouptags) ("B") ("C") (:endgrouptag))
  2625. (let ((org-tag-persistent-alist nil))
  2626. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2627. (org-mode-restart)
  2628. org-current-tag-alist))))
  2629. (should
  2630. (equal '(("A" "B" "C"))
  2631. (let ((org-tag-persistent-alist nil))
  2632. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2633. (org-mode-restart)
  2634. org-tag-groups-alist))))
  2635. (should-not
  2636. (let ((org-tag-alist '(("A"))))
  2637. (org-test-with-temp-text "#+TAGS:"
  2638. (org-mode-restart)
  2639. org-current-tag-alist)))
  2640. ;; FILETAGS keyword.
  2641. (should
  2642. (equal '("A" "B" "C")
  2643. (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
  2644. (org-mode-restart)
  2645. org-file-tags)))
  2646. ;; PROPERTY keyword. Property names are case-insensitive.
  2647. (should
  2648. (equal "foo=1"
  2649. (org-test-with-temp-text "#+PROPERTY: var foo=1"
  2650. (org-mode-restart)
  2651. (cdr (assoc "var" org-keyword-properties)))))
  2652. (should
  2653. (equal
  2654. "foo=1 bar=2"
  2655. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
  2656. (org-mode-restart)
  2657. (cdr (assoc "var" org-keyword-properties)))))
  2658. (should
  2659. (equal
  2660. "foo=1 bar=2"
  2661. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
  2662. (org-mode-restart)
  2663. (cdr (assoc "var" org-keyword-properties)))))
  2664. ;; ARCHIVE keyword.
  2665. (should
  2666. (equal "%s_done::"
  2667. (org-test-with-temp-text "#+ARCHIVE: %s_done::"
  2668. (org-mode-restart)
  2669. org-archive-location)))
  2670. ;; CATEGORY keyword.
  2671. (should
  2672. (eq 'test
  2673. (org-test-with-temp-text "#+CATEGORY: test"
  2674. (org-mode-restart)
  2675. org-category)))
  2676. (should
  2677. (equal "test"
  2678. (org-test-with-temp-text "#+CATEGORY: test"
  2679. (org-mode-restart)
  2680. (cdr (assoc "CATEGORY" org-keyword-properties)))))
  2681. ;; COLUMNS keyword.
  2682. (should
  2683. (equal "%25ITEM %TAGS %PRIORITY %TODO"
  2684. (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
  2685. (org-mode-restart)
  2686. org-columns-default-format)))
  2687. ;; CONSTANTS keyword. Constants names are case sensitive.
  2688. (should
  2689. (equal '("299792458." "3.14")
  2690. (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
  2691. (org-mode-restart)
  2692. (mapcar
  2693. (lambda (n) (cdr (assoc n org-table-formula-constants-local)))
  2694. '("c" "pi")))))
  2695. (should
  2696. (equal "3.14"
  2697. (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
  2698. (org-mode-restart)
  2699. (cdr (assoc "pi" org-table-formula-constants-local)))))
  2700. (should
  2701. (equal "22/7"
  2702. (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
  2703. (org-mode-restart)
  2704. (cdr (assoc "PI" org-table-formula-constants-local)))))
  2705. ;; LINK keyword.
  2706. (should
  2707. (equal
  2708. '("url1" "url2")
  2709. (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
  2710. (org-mode-restart)
  2711. (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local)))
  2712. '("a" "b")))))
  2713. ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
  2714. (should
  2715. (equal
  2716. '(?X ?Z ?Y)
  2717. (org-test-with-temp-text "#+PRIORITIES: X Z Y"
  2718. (org-mode-restart)
  2719. (list org-priority-highest org-priority-lowest org-priority-default))))
  2720. (should
  2721. (equal
  2722. '(?A ?C ?B)
  2723. (org-test-with-temp-text "#+PRIORITIES: X Z"
  2724. (org-mode-restart)
  2725. (list org-priority-highest org-priority-lowest org-priority-default))))
  2726. ;; STARTUP keyword.
  2727. (should
  2728. (equal '(t t)
  2729. (org-test-with-temp-text "#+STARTUP: fold odd"
  2730. (org-mode-restart)
  2731. (list org-startup-folded org-odd-levels-only))))
  2732. ;; TODO keywords.
  2733. (should
  2734. (equal '(("A" "B") ("C"))
  2735. (org-test-with-temp-text "#+TODO: A B | C"
  2736. (org-mode-restart)
  2737. (list org-not-done-keywords org-done-keywords))))
  2738. (should
  2739. (equal '(("A" "C") ("B" "D"))
  2740. (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
  2741. (org-mode-restart)
  2742. (list org-not-done-keywords org-done-keywords))))
  2743. (should
  2744. (equal '(("A" "B") ("C"))
  2745. (org-test-with-temp-text "#+TYP_TODO: A B | C"
  2746. (org-mode-restart)
  2747. (list org-not-done-keywords org-done-keywords))))
  2748. (should
  2749. (equal '((:startgroup) ("A" . ?a) (:endgroup))
  2750. (org-test-with-temp-text "#+TODO: A(a)"
  2751. (org-mode-restart)
  2752. org-todo-key-alist)))
  2753. (should
  2754. (equal '(("D" note nil) ("C" time nil) ("B" note time))
  2755. (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
  2756. (org-mode-restart)
  2757. org-todo-log-states)))
  2758. ;; Enter SETUPFILE keyword.
  2759. (should
  2760. (equal "1"
  2761. (org-test-with-temp-text
  2762. (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
  2763. (org-mode-restart)
  2764. (cdr (assoc "a" org-keyword-properties))))))
  2765. (ert-deftest test-org/collect-keywords ()
  2766. "Test `org-collect-keywords'."
  2767. (should-not
  2768. (org-test-with-temp-text "#+begin_example\n#+foo: bar\n#+end_example"
  2769. (org-collect-keywords '("FOO")))))
  2770. ;;; Links
  2771. ;;;; Coderefs
  2772. (ert-deftest test-org/coderef ()
  2773. "Test coderef links specifications."
  2774. (should
  2775. (org-test-with-temp-text "
  2776. #+BEGIN_SRC emacs-lisp
  2777. \(+ 1 1) (ref:sc)
  2778. #+END_SRC
  2779. \[[(sc)<point>]]"
  2780. (org-open-at-point)
  2781. (looking-at "(ref:sc)")))
  2782. ;; Find coderef even with alternate label format.
  2783. (should
  2784. (org-test-with-temp-text "
  2785. #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
  2786. \(+ 1 1) {ref:sc}
  2787. #+END_SRC
  2788. \[[(sc)<point>]]"
  2789. (org-open-at-point)
  2790. (looking-at "{ref:sc}"))))
  2791. ;;;; Custom ID
  2792. (ert-deftest test-org/custom-id ()
  2793. "Test custom ID links specifications."
  2794. (should
  2795. (org-test-with-temp-text
  2796. "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2797. (org-open-at-point)
  2798. (looking-at-p "\\* H1")))
  2799. ;; Handle escape characters.
  2800. (should
  2801. (org-test-with-temp-text
  2802. "* H1\n:PROPERTIES:\n:CUSTOM_ID: [%]\n:END:\n* H2\n[[#\\[%\\]<point>]]"
  2803. (org-open-at-point)
  2804. (looking-at-p "\\* H1")))
  2805. ;; Throw an error on false positives.
  2806. (should-error
  2807. (org-test-with-temp-text
  2808. "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2809. (org-open-at-point)
  2810. (looking-at-p "\\* H1"))))
  2811. ;;;; Fuzzy Links
  2812. ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
  2813. ;; a named element (#+name: text) and to headlines (* Text).
  2814. (ert-deftest test-org/fuzzy-links ()
  2815. "Test fuzzy links specifications."
  2816. ;; Fuzzy link goes in priority to a matching target.
  2817. (should
  2818. (org-test-with-temp-text
  2819. "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
  2820. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2821. (looking-at "<<Test>>")))
  2822. ;; Then fuzzy link points to an element with a given name.
  2823. (should
  2824. (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
  2825. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2826. (looking-at "#\\+NAME: Test")))
  2827. ;; A target still lead to a matching headline otherwise.
  2828. (should
  2829. (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
  2830. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2831. (looking-at "\\* Head2")))
  2832. ;; With a leading star in link, enforce heading match.
  2833. (should
  2834. (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
  2835. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2836. (looking-at "\\* Test")))
  2837. ;; With a leading star in link, enforce exact heading match, even
  2838. ;; with `org-link-search-must-match-exact-headline' set to nil.
  2839. (should-error
  2840. (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
  2841. (let ((org-link-search-must-match-exact-headline nil))
  2842. (org-open-at-point))))
  2843. ;; Handle non-nil `org-link-search-must-match-exact-headline'.
  2844. (should
  2845. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
  2846. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2847. (looking-at "\\* Test")))
  2848. (should
  2849. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
  2850. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2851. (looking-at "\\* Test")))
  2852. ;; Heading match should not care about spaces, cookies, TODO
  2853. ;; keywords, priorities, and tags. However, TODO keywords are
  2854. ;; case-sensitive.
  2855. (should
  2856. (let ((first-line
  2857. "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
  2858. (org-test-with-temp-text
  2859. (concat first-line "\nFoo Bar\n<point>[[*Test 1 2]]")
  2860. (let ((org-link-search-must-match-exact-headline nil)
  2861. (org-todo-regexp "TODO"))
  2862. (org-open-at-point))
  2863. (looking-at (regexp-quote first-line)))))
  2864. (should-error
  2865. (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
  2866. (let ((org-link-search-must-match-exact-headline nil)
  2867. (org-todo-regexp "TODO"))
  2868. (org-open-at-point))))
  2869. ;; Heading match should still be exact.
  2870. (should-error
  2871. (org-test-with-temp-text "
  2872. ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
  2873. Foo Bar
  2874. <point>[[*Test 1]]"
  2875. (let ((org-link-search-must-match-exact-headline nil)
  2876. (org-todo-regexp "TODO"))
  2877. (org-open-at-point))))
  2878. (should
  2879. (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
  2880. (let ((org-link-search-must-match-exact-headline nil)
  2881. (org-todo-regexp "TODO"))
  2882. (org-open-at-point))
  2883. (looking-at-p (regexp-quote "** Test 1 2"))))
  2884. ;; Heading match ignores COMMENT keyword.
  2885. (should
  2886. (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
  2887. (org-open-at-point)
  2888. (looking-at "\\* COMMENT Test")))
  2889. (should
  2890. (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
  2891. (org-open-at-point)
  2892. (looking-at "\\* TODO COMMENT Test")))
  2893. ;; Correctly un-escape fuzzy links.
  2894. (should
  2895. (org-test-with-temp-text "* [foo]\n[[*\\[foo\\]][With escaped characters]]"
  2896. (org-open-at-point)
  2897. (bobp)))
  2898. ;; Match search strings containing newline characters, including
  2899. ;; blank lines.
  2900. (should
  2901. (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
  2902. (let ((file (buffer-file-name)))
  2903. (goto-char (point-max))
  2904. (insert (format "[[file:%s::line1 line2]]" file))
  2905. (beginning-of-line)
  2906. (let ((org-link-search-must-match-exact-headline nil))
  2907. (org-open-at-point 0))
  2908. (looking-at-p "line1"))))
  2909. (should
  2910. (org-test-with-temp-text-in-file "Paragraph\n\nline1\n\nline2\n\n"
  2911. (let ((file (buffer-file-name)))
  2912. (goto-char (point-max))
  2913. (insert (format "[[file:%s::line1 line2]]" file))
  2914. (beginning-of-line)
  2915. (let ((org-link-search-must-match-exact-headline nil))
  2916. (org-open-at-point 0))
  2917. (looking-at-p "line1")))))
  2918. ;;;; Open at point
  2919. (ert-deftest test-org/open-at-point/keyword ()
  2920. "Does `org-open-at-point' open link in a keyword line?"
  2921. (should
  2922. (org-test-with-temp-text
  2923. "<<top>>\n#+KEYWORD: <point>[[top]]"
  2924. (org-open-at-point) t))
  2925. (should
  2926. (org-test-with-temp-text
  2927. "* H\n<<top>>\n#+KEYWORD: <point>[[top]]"
  2928. (org-open-at-point) t)))
  2929. (ert-deftest test-org/open-at-point/property ()
  2930. "Does `org-open-at-point' open link in property drawer?"
  2931. (should
  2932. (org-test-with-temp-text
  2933. "* Headline
  2934. :PROPERTIES:
  2935. :URL: <point>[[*Headline]]
  2936. :END:"
  2937. (org-open-at-point) t)))
  2938. (ert-deftest test-org/open-at-point/comment ()
  2939. "Does `org-open-at-point' open link in a commented line?"
  2940. (should
  2941. (org-test-with-temp-text
  2942. "<<top>>\n# <point>[[top]]"
  2943. (org-open-at-point) t))
  2944. (should
  2945. (org-test-with-temp-text
  2946. "* H\n<<top>>\n# <point>[[top]]"
  2947. (org-open-at-point) t)))
  2948. (ert-deftest test-org/open-at-point/inline-image ()
  2949. "Test `org-open-at-point' on nested links."
  2950. (should
  2951. (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
  2952. (org-open-at-point)
  2953. (bobp))))
  2954. (ert-deftest test-org/open-at-point/radio-target ()
  2955. "Test `org-open-at-point' on radio targets."
  2956. (should
  2957. (org-test-with-temp-text "<<<target>>> <point>target"
  2958. (org-update-radio-target-regexp)
  2959. (org-open-at-point)
  2960. (eq (org-element-type (org-element-context)) 'radio-target))))
  2961. (ert-deftest test-org/open-at-point/radio-target-shadowed ()
  2962. "Test `org-open-at-point' on shadowed radio targets."
  2963. (should
  2964. (org-test-with-temp-text
  2965. "<<<target shadowed>>> <<<target>>> <point>target shadowed"
  2966. (org-update-radio-target-regexp)
  2967. (org-open-at-point)
  2968. (string=
  2969. (org-element-property :value
  2970. (org-element-radio-target-parser))
  2971. "target shadowed"))))
  2972. (ert-deftest test-org/open-at-point/tag ()
  2973. "Test `org-open-at-point' on tags."
  2974. (should
  2975. (org-test-with-temp-text "* H :<point>tag:"
  2976. (catch :result
  2977. (cl-letf (((symbol-function 'org-tags-view)
  2978. (lambda (&rest args) (throw :result t))))
  2979. (org-open-at-point)
  2980. nil))))
  2981. (should-not
  2982. (org-test-with-temp-text-in-file "* H<point> :tag:"
  2983. (catch :result
  2984. (cl-letf (((symbol-function 'org-tags-view)
  2985. (lambda (&rest args) (throw :result t))))
  2986. ;; When point isn't on a tag it's going to try other things,
  2987. ;; possibly trying to open attachments which will return an
  2988. ;; error if there isn't an attachment. Suppress that error.
  2989. (ignore-errors
  2990. (org-open-at-point))
  2991. nil)))))
  2992. ;;; Node Properties
  2993. (ert-deftest test-org/accumulated-properties-in-drawers ()
  2994. "Ensure properties accumulate in subtree drawers."
  2995. (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
  2996. (org-babel-next-src-block)
  2997. (should (equal '(2 1) (org-babel-execute-src-block)))))
  2998. (ert-deftest test-org/custom-properties ()
  2999. "Test custom properties specifications."
  3000. ;; Standard test.
  3001. (should
  3002. (let ((org-custom-properties '("FOO")))
  3003. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  3004. (org-toggle-custom-properties-visibility)
  3005. (org-invisible-p2))))
  3006. ;; Properties are case-insensitive.
  3007. (should
  3008. (let ((org-custom-properties '("FOO")))
  3009. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
  3010. (org-toggle-custom-properties-visibility)
  3011. (org-invisible-p2))))
  3012. (should
  3013. (let ((org-custom-properties '("foo")))
  3014. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  3015. (org-toggle-custom-properties-visibility)
  3016. (org-invisible-p2))))
  3017. ;; Multiple custom properties in the same drawer.
  3018. (should
  3019. (let ((org-custom-properties '("FOO" "BAR")))
  3020. (org-test-with-temp-text
  3021. "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
  3022. (org-fold-reveal)
  3023. (org-toggle-custom-properties-visibility)
  3024. (and (org-invisible-p2)
  3025. (not (progn (forward-line) (org-invisible-p2)))
  3026. (progn (forward-line) (org-invisible-p2))))))
  3027. ;; Hide custom properties with an empty value.
  3028. (should
  3029. (let ((org-custom-properties '("FOO")))
  3030. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
  3031. (org-toggle-custom-properties-visibility)
  3032. (org-invisible-p2))))
  3033. ;; Do not hide fake properties.
  3034. (should-not
  3035. (let ((org-custom-properties '("FOO")))
  3036. (org-test-with-temp-text ":FOO: val\n"
  3037. (org-toggle-custom-properties-visibility)
  3038. (org-invisible-p2))))
  3039. (should-not
  3040. (let ((org-custom-properties '("A")))
  3041. (org-test-with-temp-text
  3042. "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
  3043. (org-fold-reveal)
  3044. (org-toggle-custom-properties-visibility)
  3045. (org-invisible-p2)))))
  3046. ;;; Mark Region
  3047. (ert-deftest test-org/mark-element ()
  3048. "Test `org-mark-element' specifications."
  3049. ;; Mark beginning and end of element.
  3050. (should
  3051. (equal '(t t)
  3052. (org-test-with-temp-text "Para<point>graph"
  3053. (org-mark-element)
  3054. (list (bobp) (= (mark) (point-max))))))
  3055. (should
  3056. (equal '(t t)
  3057. (org-test-with-temp-text "P1\n\nPara<point>graph\n\nP2"
  3058. (org-mark-element)
  3059. (list (looking-at "Paragraph")
  3060. (org-with-point-at (mark) (looking-at "P2"))))))
  3061. ;; Do not set mark past (point-max).
  3062. (should
  3063. (org-test-with-temp-text "Para<point>graph"
  3064. (narrow-to-region 2 6)
  3065. (org-mark-element)
  3066. (= 6 (mark)))))
  3067. (ert-deftest test-org/mark-subtree ()
  3068. "Test `org-mark-subtree' specifications."
  3069. ;; Error when point is before first headline.
  3070. (should-error
  3071. (org-test-with-temp-text "Paragraph\n* Headline\nBody"
  3072. (progn (transient-mark-mode 1)
  3073. (org-mark-subtree))))
  3074. ;; Without argument, mark current subtree.
  3075. (should
  3076. (equal
  3077. '(12 32)
  3078. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  3079. (progn (transient-mark-mode 1)
  3080. (forward-line 2)
  3081. (org-mark-subtree)
  3082. (list (region-beginning) (region-end))))))
  3083. ;; With an argument, move ARG up.
  3084. (should
  3085. (equal
  3086. '(1 32)
  3087. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  3088. (progn (transient-mark-mode 1)
  3089. (forward-line 2)
  3090. (org-mark-subtree 1)
  3091. (list (region-beginning) (region-end))))))
  3092. ;; Do not get fooled by inlinetasks.
  3093. (when (featurep 'org-inlinetask)
  3094. (should
  3095. (= 1
  3096. (org-test-with-temp-text "* Headline\n*************** Task\nContents"
  3097. (progn (transient-mark-mode 1)
  3098. (forward-line 1)
  3099. (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
  3100. (region-beginning)))))))
  3101. ;;; Miscellaneous
  3102. (ert-deftest test-org/sort-entries ()
  3103. "Test `org-sort-entries'."
  3104. ;; Sort alphabetically.
  3105. (should
  3106. (equal "\n* abc\n* def\n* xyz\n"
  3107. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  3108. (org-sort-entries nil ?a)
  3109. (buffer-string))))
  3110. (should
  3111. (equal "\n* xyz\n* def\n* abc\n"
  3112. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  3113. (org-sort-entries nil ?A)
  3114. (buffer-string))))
  3115. (should
  3116. (equal "\n* \n* klm\n* xyz\n"
  3117. (org-test-with-temp-text "\n* xyz\n* \n* klm\n"
  3118. (org-sort-entries nil ?a)
  3119. (buffer-string))))
  3120. ;; Sort numerically.
  3121. (should
  3122. (equal "\n* 1\n* 2\n* 10\n"
  3123. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  3124. (org-sort-entries nil ?n)
  3125. (buffer-string))))
  3126. (should
  3127. (equal "\n* 10\n* 2\n* 1\n"
  3128. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  3129. (org-sort-entries nil ?N)
  3130. (buffer-string))))
  3131. (should
  3132. (equal "\n* \n* 1\n* 2\n"
  3133. (org-test-with-temp-text "\n* 1\n* \n* 2\n"
  3134. (org-sort-entries nil ?n)
  3135. (buffer-string))))
  3136. ;; Sort by custom function.
  3137. (should
  3138. (equal "\n* b\n* aa\n* ccc\n"
  3139. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  3140. (org-sort-entries nil ?f
  3141. (lambda ()
  3142. (length (buffer-substring (point-at-bol)
  3143. (point-at-eol))))
  3144. #'<)
  3145. (buffer-string))))
  3146. (should
  3147. (equal "\n* ccc\n* aa\n* b\n"
  3148. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  3149. (org-sort-entries nil ?F
  3150. (lambda ()
  3151. (length (buffer-substring (point-at-bol)
  3152. (point-at-eol))))
  3153. #'<)
  3154. (buffer-string))))
  3155. ;; Sort by TODO keyword.
  3156. (should
  3157. (equal "\n* TODO h1\n* TODO h3\n* DONE h2\n"
  3158. (org-test-with-temp-text
  3159. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  3160. (org-sort-entries nil ?o)
  3161. (buffer-string))))
  3162. (should
  3163. (equal "\n* DONE h2\n* TODO h1\n* TODO h3\n"
  3164. (org-test-with-temp-text
  3165. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  3166. (org-sort-entries nil ?O)
  3167. (buffer-string))))
  3168. ;; Sort by priority.
  3169. (should
  3170. (equal "\n* [#A] h2\n* [#B] h3\n* [#C] h1\n"
  3171. (org-test-with-temp-text
  3172. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  3173. (org-sort-entries nil ?p)
  3174. (buffer-string))))
  3175. (should
  3176. (equal "\n* [#C] h1\n* [#B] h3\n* [#A] h2\n"
  3177. (org-test-with-temp-text
  3178. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  3179. (org-sort-entries nil ?P)
  3180. (buffer-string))))
  3181. ;; Sort by creation time.
  3182. (should
  3183. (equal "
  3184. * h3
  3185. [2017-05-08 Mon]
  3186. * h2
  3187. [2017-05-09 Tue]
  3188. * h1
  3189. [2018-05-09 Wed]
  3190. "
  3191. (org-test-with-temp-text
  3192. "
  3193. * h1
  3194. [2018-05-09 Wed]
  3195. * h2
  3196. [2017-05-09 Tue]
  3197. * h3
  3198. [2017-05-08 Mon]
  3199. "
  3200. (org-sort-entries nil ?c)
  3201. (buffer-string))))
  3202. ;; Sort by scheduled date.
  3203. (should
  3204. (equal "
  3205. * TODO h4
  3206. SCHEDULED: <2017-05-06 Sat>
  3207. * TODO h3
  3208. SCHEDULED: <2017-05-08 Mon>
  3209. * TODO h2
  3210. DEADLINE: <2017-05-09 Tue>
  3211. * TODO h1
  3212. DEADLINE: <2017-05-07 Sun>
  3213. "
  3214. (org-test-with-temp-text
  3215. "
  3216. * TODO h2
  3217. DEADLINE: <2017-05-09 Tue>
  3218. * TODO h1
  3219. DEADLINE: <2017-05-07 Sun>
  3220. * TODO h3
  3221. SCHEDULED: <2017-05-08 Mon>
  3222. * TODO h4
  3223. SCHEDULED: <2017-05-06 Sat>
  3224. "
  3225. (org-sort-entries nil ?s)
  3226. (buffer-string))))
  3227. ;; Sort by deadline date.
  3228. (should
  3229. (equal "
  3230. * TODO h1
  3231. DEADLINE: <2017-05-07 Sun>
  3232. * TODO h2
  3233. DEADLINE: <2017-05-09 Tue>
  3234. * TODO h3
  3235. SCHEDULED: <2017-05-08 Mon>
  3236. * TODO h4
  3237. SCHEDULED: <2017-05-06 Sat>
  3238. "
  3239. (org-test-with-temp-text
  3240. "
  3241. * TODO h2
  3242. DEADLINE: <2017-05-09 Tue>
  3243. * TODO h1
  3244. DEADLINE: <2017-05-07 Sun>
  3245. * TODO h3
  3246. SCHEDULED: <2017-05-08 Mon>
  3247. * TODO h4
  3248. SCHEDULED: <2017-05-06 Sat>
  3249. "
  3250. (org-sort-entries nil ?d)
  3251. (buffer-string))))
  3252. ;; Sort by any date/time
  3253. (should
  3254. (equal "
  3255. * TODO h4
  3256. SCHEDULED: <2017-05-06 Sat>
  3257. * TODO h1
  3258. DEADLINE: <2017-05-07 Sun>
  3259. * TODO h3
  3260. SCHEDULED: <2017-05-08 Mon>
  3261. * TODO h2
  3262. DEADLINE: <2017-05-09 Tue>
  3263. "
  3264. (org-test-with-temp-text
  3265. "
  3266. * TODO h2
  3267. DEADLINE: <2017-05-09 Tue>
  3268. * TODO h1
  3269. DEADLINE: <2017-05-07 Sun>
  3270. * TODO h3
  3271. SCHEDULED: <2017-05-08 Mon>
  3272. * TODO h4
  3273. SCHEDULED: <2017-05-06 Sat>
  3274. "
  3275. (org-sort-entries nil ?t)
  3276. (buffer-string))))
  3277. ;; Sort by clocking time.
  3278. (should
  3279. (equal "
  3280. * clocked h2
  3281. :LOGBOOK:
  3282. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3283. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  3284. :END:
  3285. * clocked h1
  3286. :LOGBOOK:
  3287. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3288. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  3289. :END:
  3290. "
  3291. (org-test-with-temp-text
  3292. "
  3293. * clocked h1
  3294. :LOGBOOK:
  3295. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3296. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  3297. :END:
  3298. * clocked h2
  3299. :LOGBOOK:
  3300. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3301. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  3302. :END:
  3303. "
  3304. (org-sort-entries nil ?k)
  3305. (buffer-string))))
  3306. ;; Preserve file local variables when sorting.
  3307. (should
  3308. (equal "\n* A\n* B\n# Local Variables:\n# foo: t\n# End:\n"
  3309. (org-test-with-temp-text
  3310. "\n* B\n* A\n# Local Variables:\n# foo: t\n# End:"
  3311. (org-sort-entries nil ?a)
  3312. (buffer-string)))))
  3313. (ert-deftest test-org/string-collate-greaterp ()
  3314. "Test `org-string-collate-greaterp' specifications."
  3315. (should (org-string-collate-greaterp "def" "abc"))
  3316. (should-not (org-string-collate-greaterp "abc" "def")))
  3317. (ert-deftest test-org/file-contents ()
  3318. "Test `org-file-contents' specifications."
  3319. ;; Open files.
  3320. (should
  3321. (string= "#+BIND: variable value
  3322. #+DESCRIPTION: l2
  3323. #+LANGUAGE: en
  3324. #+SELECT_TAGS: b
  3325. #+TITLE: b
  3326. #+PROPERTY: a 1
  3327. " (org-file-contents (expand-file-name "setupfile3.org"
  3328. (concat org-test-dir "examples/")))))
  3329. ;; Throw error when trying to access an invalid file.
  3330. (should-error (org-file-contents "this-file-must-not-exist"))
  3331. ;; Try to access an invalid file, but do not throw an error.
  3332. (should
  3333. (progn (org-file-contents "this-file-must-not-exist" :noerror) t))
  3334. ;; Open URL.
  3335. (should
  3336. (string= "foo"
  3337. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3338. (unwind-protect
  3339. ;; Simulate successful retrieval of a URL.
  3340. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3341. (lambda (&rest_)
  3342. (with-current-buffer buffer
  3343. (insert "HTTP/1.1 200 OK\n\nfoo"))
  3344. buffer)))
  3345. (org-file-contents "http://some-valid-url"))
  3346. (kill-buffer buffer)))))
  3347. ;; Throw error when trying to access an invalid URL.
  3348. (should-error
  3349. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3350. (unwind-protect
  3351. ;; Simulate unsuccessful retrieval of a URL.
  3352. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3353. (lambda (&rest_)
  3354. (with-current-buffer buffer
  3355. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3356. buffer)))
  3357. (org-file-contents "http://this-url-must-not-exist"))
  3358. (kill-buffer buffer))))
  3359. ;; Try to access an invalid URL, but do not throw an error.
  3360. (should-error
  3361. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3362. (unwind-protect
  3363. ;; Simulate unsuccessful retrieval of a URL.
  3364. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3365. (lambda (&rest_)
  3366. (with-current-buffer buffer
  3367. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3368. buffer)))
  3369. (org-file-contents "http://this-url-must-not-exist"))
  3370. (kill-buffer buffer))))
  3371. (should
  3372. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3373. (unwind-protect
  3374. ;; Simulate unsuccessful retrieval of a URL.
  3375. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3376. (lambda (&rest_)
  3377. (with-current-buffer buffer
  3378. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3379. buffer)))
  3380. (org-file-contents "http://this-url-must-not-exist" :noerror))
  3381. (kill-buffer buffer))
  3382. t)))
  3383. ;;; Navigation
  3384. (ert-deftest test-org/next-visible-heading ()
  3385. "Test `org-next-visible-heading' specifications."
  3386. ;; Move to the beginning of the next headline, taking into
  3387. ;; consideration ARG.
  3388. (should
  3389. (org-test-with-temp-text "* H1\n* H2"
  3390. (org-next-visible-heading 1)
  3391. (looking-at "\\* H2")))
  3392. (should
  3393. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3394. (org-next-visible-heading 2)
  3395. (looking-at "\\* H3")))
  3396. ;; Ignore invisible headlines.
  3397. (should
  3398. (org-test-with-temp-text "* H1\n** H2\n* H3"
  3399. (org-cycle)
  3400. (org-next-visible-heading 1)
  3401. (looking-at "\\* H3")))
  3402. ;; Move point between headlines, not on blank lines between.
  3403. (should
  3404. (org-test-with-temp-text "* H1\n** H2\n\n\n\n* H3"
  3405. (let ((org-cycle-separator-lines 1))
  3406. (org-cycle)
  3407. (org-next-visible-heading 1))
  3408. (looking-at "\\* H3")))
  3409. ;; Move at end of buffer when there is no more headline.
  3410. (should
  3411. (org-test-with-temp-text "* H1"
  3412. (org-next-visible-heading 1)
  3413. (eobp)))
  3414. (should
  3415. (org-test-with-temp-text "* H1\n* H2"
  3416. (org-next-visible-heading 2)
  3417. (eobp)))
  3418. ;; With a negative argument, move backwards.
  3419. (should
  3420. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3421. (org-next-visible-heading -1)
  3422. (looking-at "\\* H2")))
  3423. (should
  3424. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3425. (org-next-visible-heading -2)
  3426. (looking-at "\\* H1"))))
  3427. (ert-deftest test-org/previous-visible-heading ()
  3428. "Test `org-previous-visible-heading' specifications."
  3429. ;; Move to the beginning of the next headline, taking into
  3430. ;; consideration ARG.
  3431. (should
  3432. (org-test-with-temp-text "* H1\n<point>* H2"
  3433. (org-previous-visible-heading 1)
  3434. (looking-at "\\* H1")))
  3435. (should
  3436. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3437. (org-previous-visible-heading 2)
  3438. (looking-at "\\* H1")))
  3439. ;; Ignore invisible headlines.
  3440. (should
  3441. (org-test-with-temp-text "* H1\n** H2\n<point>* H3"
  3442. (org-overview)
  3443. (org-previous-visible-heading 1)
  3444. (looking-at "\\* H1")))
  3445. ;; Move point between headlines, not on blank lines between.
  3446. (should
  3447. (org-test-with-temp-text "* H1\n\n\n\n** H2\n<point>* H3"
  3448. (let ((org-cycle-separator-lines 1))
  3449. (org-overview)
  3450. (org-previous-visible-heading 1))
  3451. (looking-at "\\* H1")))
  3452. ;; Move at end of buffer when there is no more headline.
  3453. (should
  3454. (org-test-with-temp-text "* H1"
  3455. (org-previous-visible-heading 1)
  3456. (bobp)))
  3457. (should
  3458. (org-test-with-temp-text "* H1\n* <point>H2"
  3459. (org-previous-visible-heading 2)
  3460. (bobp)))
  3461. ;; Invisible parts may not start at a headline, i.e., when revealing
  3462. ;; parts of the buffer. Handle this.
  3463. (should
  3464. (org-test-with-temp-text "* Main\n** H1\nFoo\n** H2\nBar\n** H3\nBaz"
  3465. (org-overview)
  3466. (search-forward "H1")
  3467. (org-show-context 'minimal)
  3468. (org-cycle)
  3469. (search-forward "H3")
  3470. (org-show-context 'minimal)
  3471. ;; At this point, buffer displays, with point at "|",
  3472. ;;
  3473. ;; * Main
  3474. ;; ** H1
  3475. ;; Foo
  3476. ;; ** H3|
  3477. (org-previous-visible-heading 1)
  3478. (looking-at "\\*+ H1"))))
  3479. (ert-deftest test-org/forward-heading-same-level ()
  3480. "Test `org-forward-heading-same-level' specifications."
  3481. ;; Test navigation at top level, forward and backward.
  3482. (should
  3483. (equal "* H2"
  3484. (org-test-with-temp-text "* H1\n* H2"
  3485. (org-forward-heading-same-level 1)
  3486. (buffer-substring-no-properties (point) (line-end-position)))))
  3487. (should
  3488. (equal "* H1"
  3489. (org-test-with-temp-text "* H1\n<point>* H2"
  3490. (org-forward-heading-same-level -1)
  3491. (buffer-substring-no-properties (point) (line-end-position)))))
  3492. ;; Test navigation in a sub-tree, forward and backward.
  3493. (should
  3494. (equal "* H2"
  3495. (org-test-with-temp-text "* H1\n** H11\n** H12\n* H2"
  3496. (org-forward-heading-same-level 1)
  3497. (buffer-substring-no-properties (point) (line-end-position)))))
  3498. (should
  3499. (equal "* H1"
  3500. (org-test-with-temp-text "* H1\n** H11\n** H12\n<point>* H2"
  3501. (org-forward-heading-same-level -1)
  3502. (buffer-substring-no-properties (point) (line-end-position)))))
  3503. ;; Stop at first or last sub-heading.
  3504. (should-not
  3505. (equal "* H2"
  3506. (org-test-with-temp-text "* H1\n** H11\n<point>** H12\n* H2"
  3507. (org-forward-heading-same-level 1)
  3508. (buffer-substring-no-properties (point) (line-end-position)))))
  3509. (should-not
  3510. (equal "* H2"
  3511. (org-test-with-temp-text "* H1\n<point>** H11\n** H12\n* H2"
  3512. (org-forward-heading-same-level -1)
  3513. (buffer-substring-no-properties (point) (line-end-position)))))
  3514. ;; Allow multiple moves.
  3515. (should
  3516. (equal "* H3"
  3517. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3518. (org-forward-heading-same-level 2)
  3519. (buffer-substring-no-properties (point) (line-end-position)))))
  3520. (should
  3521. (equal "* H1"
  3522. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3523. (org-forward-heading-same-level -2)
  3524. (buffer-substring-no-properties (point) (line-end-position)))))
  3525. ;; Ignore spurious moves when first (or last) sibling is reached.
  3526. (should
  3527. (equal "** H3"
  3528. (org-test-with-temp-text "* First\n<point>** H1\n** H2\n** H3\n* Last"
  3529. (org-forward-heading-same-level 100)
  3530. (buffer-substring-no-properties (point) (line-end-position)))))
  3531. (should
  3532. (equal "** H1"
  3533. (org-test-with-temp-text "* First\n** H1\n** H2\n<point>** H3\n* Last"
  3534. (org-forward-heading-same-level -100)
  3535. (buffer-substring-no-properties (point) (line-end-position))))))
  3536. (ert-deftest test-org/end-of-meta-data ()
  3537. "Test `org-end-of-meta-data' specifications."
  3538. ;; Skip planning line.
  3539. (should
  3540. (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
  3541. (org-end-of-meta-data)
  3542. (eobp)))
  3543. ;; Skip properties drawer.
  3544. (should
  3545. (org-test-with-temp-text
  3546. "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
  3547. (org-end-of-meta-data)
  3548. (eobp)))
  3549. ;; Skip both.
  3550. (should
  3551. (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
  3552. (org-end-of-meta-data)
  3553. (eobp)))
  3554. ;; Nothing to skip, go to first line.
  3555. (should
  3556. (org-test-with-temp-text "* Headline\nContents"
  3557. (org-end-of-meta-data)
  3558. (looking-at "Contents")))
  3559. ;; With option argument, skip empty lines, regular drawers and
  3560. ;; clocking lines.
  3561. (should
  3562. (org-test-with-temp-text "* Headline\n\nContents"
  3563. (org-end-of-meta-data t)
  3564. (looking-at "Contents")))
  3565. (should
  3566. (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
  3567. (org-end-of-meta-data t)
  3568. (looking-at "Contents")))
  3569. (should
  3570. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
  3571. (org-end-of-meta-data t)
  3572. (looking-at "Contents")))
  3573. ;; Special case: do not skip incomplete drawers.
  3574. (should
  3575. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
  3576. (org-end-of-meta-data t)
  3577. (looking-at ":LOGBOOK:")))
  3578. ;; Special case: Be careful about consecutive headlines.
  3579. (should-not
  3580. (org-test-with-temp-text "* H1\n*H2\nContents"
  3581. (org-end-of-meta-data t)
  3582. (looking-at "Contents"))))
  3583. (ert-deftest test-org/shiftright-heading ()
  3584. "Test `org-shiftright' on headings."
  3585. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  3586. (should
  3587. (equal "* TODO a1\n** a2\n* DONE b1\n"
  3588. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3589. (org-shiftright)
  3590. (buffer-string))))
  3591. (should
  3592. (equal "* TODO a1\n** TODO a2\n* b1\n"
  3593. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3594. (let ((org-loop-over-headlines-in-active-region t))
  3595. (transient-mark-mode 1)
  3596. (push-mark (point) t t)
  3597. (search-forward "* DONE b1")
  3598. (org-shiftright))
  3599. (buffer-string))))
  3600. (should
  3601. (equal "* TODO a1\n** a2\n* b1\n"
  3602. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3603. (let ((org-loop-over-headlines-in-active-region 'start-level))
  3604. (transient-mark-mode 1)
  3605. (push-mark (point) t t)
  3606. (search-forward "* DONE b1")
  3607. (org-shiftright))
  3608. (buffer-string))))))
  3609. (ert-deftest test-org/beginning-of-line ()
  3610. "Test `org-beginning-of-line' specifications."
  3611. ;; Move to beginning of line. If current line in invisible, move to
  3612. ;; beginning of visible line instead.
  3613. (should
  3614. (org-test-with-temp-text "Some text\nSome other text<point>"
  3615. (org-beginning-of-line)
  3616. (bolp)))
  3617. (should
  3618. (org-test-with-temp-text "* H1\n** H2<point>"
  3619. (org-overview)
  3620. (org-beginning-of-line)
  3621. (= (line-beginning-position) 1)))
  3622. ;; With `visual-line-mode' active, move to beginning of visual line.
  3623. (should-not
  3624. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3625. (visual-line-mode)
  3626. (dotimes (i 1000) (insert "very "))
  3627. (org-beginning-of-line)
  3628. (bolp)))
  3629. ;; In a wide headline, with `visual-line-mode', prefer going to the
  3630. ;; beginning of a visual line than to the logical beginning of line,
  3631. ;; even if special movement is active.
  3632. (should-not
  3633. (org-test-with-temp-text "* A <point>long headline"
  3634. (visual-line-mode)
  3635. (dotimes (i 1000) (insert "very "))
  3636. (goto-char (point-max))
  3637. (org-beginning-of-line)
  3638. (bobp)))
  3639. (should-not
  3640. (org-test-with-temp-text "* A <point>long headline"
  3641. (visual-line-mode)
  3642. (dotimes (i 1000) (insert "very "))
  3643. (goto-char (point-max))
  3644. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line))
  3645. (bobp)))
  3646. ;; At an headline with special movement, first move at beginning of
  3647. ;; title, then at the beginning of line, rinse, repeat.
  3648. (should
  3649. (org-test-with-temp-text "* TODO Headline<point>"
  3650. (let ((org-special-ctrl-a/e t))
  3651. (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
  3652. (progn (org-beginning-of-line) (bolp))
  3653. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3654. (should
  3655. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3656. (let ((org-special-ctrl-a/e t))
  3657. (org-beginning-of-line)
  3658. (looking-at "Headline"))))
  3659. (should
  3660. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3661. (let ((org-special-ctrl-a/e '(t . nil)))
  3662. (org-beginning-of-line)
  3663. (looking-at "Headline"))))
  3664. (should-not
  3665. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3666. (let ((org-special-ctrl-a/e '(nil . nil)))
  3667. (org-beginning-of-line)
  3668. (looking-at "Headline"))))
  3669. ;; At an headline with reversed movement, first move to beginning of
  3670. ;; line, then to the beginning of title.
  3671. (should
  3672. (org-test-with-temp-text "* TODO Headline<point>"
  3673. (let ((org-special-ctrl-a/e 'reversed)
  3674. (this-command last-command))
  3675. (and (progn (org-beginning-of-line) (bolp))
  3676. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3677. (should
  3678. (org-test-with-temp-text "* TODO Headline<point>"
  3679. (let ((org-special-ctrl-a/e '(reversed . nil))
  3680. (this-command last-command))
  3681. (and (progn (org-beginning-of-line) (bolp))
  3682. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3683. (should-not
  3684. (org-test-with-temp-text "* TODO Headline<point>"
  3685. (let ((org-special-ctrl-a/e '(t . nil))
  3686. (this-command last-command))
  3687. (and (progn (org-beginning-of-line) (bolp))
  3688. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3689. ;; At an item with special movement, first move after to beginning
  3690. ;; of title, then to the beginning of line, rinse, repeat.
  3691. (should
  3692. (org-test-with-temp-text "- [ ] Item<point>"
  3693. (let ((org-special-ctrl-a/e t))
  3694. (and (progn (org-beginning-of-line) (looking-at-p "Item"))
  3695. (progn (org-beginning-of-line) (bolp))
  3696. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3697. ;; At an item with reversed movement, first move to beginning of
  3698. ;; line, then to the beginning of title.
  3699. (should
  3700. (org-test-with-temp-text "- [X] Item<point>"
  3701. (let ((org-special-ctrl-a/e 'reversed)
  3702. (this-command last-command))
  3703. (and (progn (org-beginning-of-line) (bolp))
  3704. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3705. ;; Leave point before invisible characters at column 0.
  3706. (should
  3707. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3708. (let ((org-special-ctrl-a/e nil))
  3709. (org-beginning-of-line)
  3710. (bolp))))
  3711. (should
  3712. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3713. (let ((org-special-ctrl-a/e t))
  3714. (org-beginning-of-line)
  3715. (bolp))))
  3716. (should
  3717. (org-test-with-temp-text "[[http<point>://orgmode.org]]"
  3718. (visual-line-mode)
  3719. (org-beginning-of-line)
  3720. (bolp)))
  3721. ;; Special case: Do not error when the buffer contains only a single
  3722. ;; asterisk.
  3723. (should
  3724. (org-test-with-temp-text "*<point>"
  3725. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line) t)))
  3726. (should
  3727. (org-test-with-temp-text "*<point>"
  3728. (let ((org-special-ctrl-a/e nil)) (org-beginning-of-line) t))))
  3729. (ert-deftest test-org/end-of-line ()
  3730. "Test `org-end-of-line' specifications."
  3731. ;; Standard test.
  3732. (should
  3733. (org-test-with-temp-text "Some text\nSome other text"
  3734. (org-end-of-line)
  3735. (eolp)))
  3736. ;; With `visual-line-mode' active, move to end of visible line.
  3737. ;; However, never go past ellipsis.
  3738. (should-not
  3739. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3740. (visual-line-mode)
  3741. (dotimes (i 1000) (insert "very "))
  3742. (goto-char (point-min))
  3743. (org-end-of-line)
  3744. (eolp)))
  3745. (should-not
  3746. (org-test-with-temp-text "* A short headline\nSome contents"
  3747. (visual-line-mode)
  3748. (org-overview)
  3749. (org-end-of-line)
  3750. (eobp)))
  3751. ;; In a wide headline, with `visual-line-mode', prefer going to end
  3752. ;; of visible line if tags, or end of line, are farther.
  3753. (should-not
  3754. (org-test-with-temp-text "* A <point>long headline"
  3755. (visual-line-mode)
  3756. (dotimes (i 1000) (insert "very "))
  3757. (goto-char (point-min))
  3758. (org-end-of-line)
  3759. (eolp)))
  3760. (should-not
  3761. (org-test-with-temp-text "* A <point>long headline :tag:"
  3762. (visual-line-mode)
  3763. (dotimes (i 1000) (insert "very "))
  3764. (goto-char (point-min))
  3765. (org-end-of-line)
  3766. (eolp)))
  3767. ;; At an headline without special movement, go to end of line.
  3768. ;; However, never go past ellipsis.
  3769. (should
  3770. (org-test-with-temp-text "* Headline2b :tag:\n"
  3771. (let ((org-special-ctrl-a/e nil))
  3772. (and (progn (org-end-of-line) (eolp))
  3773. (progn (org-end-of-line) (eolp))))))
  3774. (should
  3775. (org-test-with-temp-text "* Headline2b :tag:\n"
  3776. (let ((org-special-ctrl-a/e '(t . nil)))
  3777. (and (progn (org-end-of-line) (eolp))
  3778. (progn (org-end-of-line) (eolp))))))
  3779. (should
  3780. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3781. (org-overview)
  3782. (let ((org-special-ctrl-a/e nil))
  3783. (org-end-of-line)
  3784. (= 1 (line-beginning-position)))))
  3785. ;; At an headline with special movement, first move before tags,
  3786. ;; then at the end of line, rinse, repeat. However, never go past
  3787. ;; ellipsis.
  3788. (should
  3789. (org-test-with-temp-text "* Headline1 :tag:\n"
  3790. (let ((org-special-ctrl-a/e t))
  3791. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3792. (progn (org-end-of-line) (eolp))
  3793. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3794. (should
  3795. (org-test-with-temp-text "* Headline1 :tag:\n"
  3796. (let ((org-special-ctrl-a/e '(nil . t)))
  3797. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3798. (progn (org-end-of-line) (eolp))
  3799. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3800. (should-not
  3801. (org-test-with-temp-text "* Headline1 :tag:\n"
  3802. (let ((org-special-ctrl-a/e '(nil . nil)))
  3803. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3804. (progn (org-end-of-line) (eolp))
  3805. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3806. (should
  3807. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3808. (org-overview)
  3809. (let ((org-special-ctrl-a/e t))
  3810. (org-end-of-line)
  3811. (org-end-of-line)
  3812. (= 1 (line-beginning-position)))))
  3813. ;; At an headline, with reversed movement, first go to end of line,
  3814. ;; then before tags. However, never go past ellipsis.
  3815. (should
  3816. (org-test-with-temp-text "* Headline3 :tag:\n"
  3817. (let ((org-special-ctrl-a/e 'reversed)
  3818. (this-command last-command))
  3819. (and (progn (org-end-of-line) (eolp))
  3820. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3821. (should
  3822. (org-test-with-temp-text "* Headline3 :tag:\n"
  3823. (let ((org-special-ctrl-a/e '(nil . reversed))
  3824. (this-command last-command))
  3825. (and (progn (org-end-of-line) (eolp))
  3826. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3827. (should-not
  3828. (org-test-with-temp-text "* Headline3 :tag:\n"
  3829. (let ((org-special-ctrl-a/e '(nil . t))
  3830. (this-command last-command))
  3831. (and (progn (org-end-of-line) (eolp))
  3832. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3833. (should
  3834. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3835. (org-overview)
  3836. (let ((org-special-ctrl-a/e 'reversed))
  3837. (org-end-of-line)
  3838. (= 1 (line-beginning-position)))))
  3839. ;; At a block without hidden contents.
  3840. (should
  3841. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3842. (progn (org-end-of-line) (eolp))))
  3843. ;; At a block with hidden contents.
  3844. (should-not
  3845. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3846. (let ((org-special-ctrl-a/e t))
  3847. (org-fold-hide-block-toggle)
  3848. (org-end-of-line)
  3849. (eobp))))
  3850. ;; Get past invisible characters at the end of line.
  3851. (should
  3852. (org-test-with-temp-text "[[https://orgmode.org]]"
  3853. (org-end-of-line)
  3854. (eolp))))
  3855. (ert-deftest test-org/open-line ()
  3856. "Test `org-open-line' specifications."
  3857. ;; Call `open-line' outside of tables.
  3858. (should
  3859. (equal "\nText"
  3860. (org-test-with-temp-text "Text"
  3861. (org-open-line 1)
  3862. (buffer-string))))
  3863. ;; At a table, create a row above.
  3864. (should
  3865. (equal "\n| |\n| a |"
  3866. (org-test-with-temp-text "\n<point>| a |"
  3867. (org-open-line 1)
  3868. (buffer-string))))
  3869. ;; At the very first character of the buffer, also call `open-line'.
  3870. (should
  3871. (equal "\n| a |"
  3872. (org-test-with-temp-text "| a |"
  3873. (org-open-line 1)
  3874. (buffer-string))))
  3875. ;; Narrowing does not count.
  3876. (should
  3877. (equal "Text\n| |\n| a |"
  3878. (org-test-with-temp-text "Text\n<point>| a |"
  3879. (narrow-to-region (point) (point-max))
  3880. (org-open-line 1)
  3881. (widen)
  3882. (buffer-string)))))
  3883. (ert-deftest test-org/forward-sentence ()
  3884. "Test `org-forward-sentence' specifications."
  3885. ;; At the end of a table cell, move to the end of the next one.
  3886. (should
  3887. (org-test-with-temp-text "| a<point> | b |"
  3888. (org-forward-sentence)
  3889. (looking-at " |$")))
  3890. ;; Elsewhere in a cell, move to its end.
  3891. (should
  3892. (org-test-with-temp-text "| a<point>c | b |"
  3893. (org-forward-sentence)
  3894. (looking-at " | b |$")))
  3895. ;; Otherwise, simply call `forward-sentence'.
  3896. (should
  3897. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3898. (org-forward-sentence)
  3899. (looking-at " Sentence 2.")))
  3900. (should
  3901. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3902. (org-forward-sentence)
  3903. (org-forward-sentence)
  3904. (eobp)))
  3905. ;; At the end of an element, jump to the next one, without stopping
  3906. ;; on blank lines in-between.
  3907. (should
  3908. (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
  3909. (org-forward-sentence)
  3910. (eobp)))
  3911. ;; Headlines are considered to be sentences by themselves, even if
  3912. ;; they do not end with a full stop.
  3913. (should
  3914. (equal
  3915. "* Headline"
  3916. (org-test-with-temp-text "* <point>Headline\nSentence."
  3917. (org-forward-sentence)
  3918. (buffer-substring-no-properties (line-beginning-position) (point)))))
  3919. (should
  3920. (org-test-with-temp-text "* Headline<point>\nSentence."
  3921. (org-forward-sentence)
  3922. (eobp)))
  3923. (should
  3924. (org-test-with-temp-text "Sentence.<point>\n\n* Headline\n\nSentence 2."
  3925. (org-forward-sentence)
  3926. (and (org-at-heading-p) (eolp)))))
  3927. (ert-deftest test-org/backward-sentence ()
  3928. "Test `org-backward-sentence' specifications."
  3929. ;; At the beginning of a table cell, move to the beginning of the
  3930. ;; previous one.
  3931. (should
  3932. (org-test-with-temp-text "| a | <point>b |"
  3933. (org-backward-sentence)
  3934. (looking-at "a | b |$")))
  3935. ;; Elsewhere in a cell, move to its beginning.
  3936. (should
  3937. (org-test-with-temp-text "| a | b<point>c |"
  3938. (org-backward-sentence)
  3939. (looking-at "bc |$")))
  3940. ;; Otherwise, simply call `backward-sentence'.
  3941. (should
  3942. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3943. (org-backward-sentence)
  3944. (looking-at "Sentence 2.")))
  3945. (should
  3946. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3947. (org-backward-sentence)
  3948. (org-backward-sentence)
  3949. (bobp)))
  3950. ;; Make sure to hit the beginning of a sentence on the same line as
  3951. ;; an item.
  3952. (should
  3953. (org-test-with-temp-text "- Line 1\n line <point>2."
  3954. (org-backward-sentence)
  3955. (looking-at "Line 1"))))
  3956. (ert-deftest test-org/forward-paragraph ()
  3957. "Test `org-forward-paragraph' specifications."
  3958. ;; At end of buffer, do not return an error.
  3959. (should
  3960. (org-test-with-temp-text "Paragraph"
  3961. (goto-char (point-max))
  3962. (org-forward-paragraph)
  3963. t))
  3964. ;; Standard test.
  3965. (should
  3966. (= 2
  3967. (org-test-with-temp-text "P1\n\nP2"
  3968. (org-forward-paragraph)
  3969. (org-current-line))))
  3970. (should
  3971. (= 2
  3972. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  3973. (org-forward-paragraph)
  3974. (org-current-line))))
  3975. ;; Enter greater elements.
  3976. (should
  3977. (= 2
  3978. (org-test-with-temp-text "#+begin_center\nP1\n#+end_center\nP2"
  3979. (org-forward-paragraph)
  3980. (org-current-line))))
  3981. ;; Do not enter elements with invisible contents.
  3982. (should
  3983. (= 4
  3984. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  3985. (org-cycle)
  3986. (org-forward-paragraph)
  3987. (org-current-line))))
  3988. (should
  3989. (= 6
  3990. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\nP3"
  3991. (org-fold-hide-block-toggle)
  3992. (org-forward-paragraph)
  3993. (org-current-line))))
  3994. ;; On an item or a footnote definition, move past the first element
  3995. ;; inside, if any.
  3996. (should
  3997. (= 2
  3998. (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
  3999. (org-forward-paragraph)
  4000. (org-current-line))))
  4001. (should
  4002. (= 2
  4003. (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
  4004. (org-forward-paragraph)
  4005. (org-current-line))))
  4006. ;; On a table (resp. a property drawer) do not move through table
  4007. ;; rows (resp. node properties).
  4008. (should
  4009. (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
  4010. (org-forward-paragraph)
  4011. (looking-at "Paragraph")))
  4012. (should
  4013. (org-test-with-temp-text
  4014. "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
  4015. (org-forward-paragraph)
  4016. (looking-at "Paragraph")))
  4017. ;; Skip consecutive keywords, clocks and diary S-exps.
  4018. (should
  4019. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n"
  4020. (org-forward-paragraph)
  4021. (eobp)))
  4022. (should
  4023. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n"
  4024. (org-forward-paragraph)
  4025. (eobp)))
  4026. (should
  4027. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n"
  4028. (org-forward-paragraph)
  4029. (eobp)))
  4030. (should-not
  4031. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n"
  4032. (org-forward-paragraph)
  4033. (eobp)))
  4034. (should-not
  4035. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n"
  4036. (org-forward-paragraph)
  4037. (eobp)))
  4038. ;; In a plain list with one item every line, skip the whole list,
  4039. ;; even with point in the middle of the list.
  4040. (should
  4041. (org-test-with-temp-text "- A\n - B\n- C\n"
  4042. (org-forward-paragraph)
  4043. (eobp)))
  4044. (should
  4045. (org-test-with-temp-text "- A\n - <point>B\n- C\n"
  4046. (org-forward-paragraph)
  4047. (eobp)))
  4048. ;; On a comment, verse or source block, stop at "contents"
  4049. ;; boundaries and blank lines.
  4050. (should
  4051. (= 2
  4052. (org-test-with-temp-text "#+begin_src emacs-lisp\nL1\n\nL2\n#+end_src"
  4053. (org-forward-paragraph)
  4054. (org-current-line))))
  4055. (should
  4056. (= 3
  4057. (org-test-with-temp-text "#+begin_verse\n<point>L1\n\nL2\n#+end_verse"
  4058. (org-forward-paragraph)
  4059. (org-current-line))))
  4060. (should
  4061. (= 5
  4062. (org-test-with-temp-text "#+begin_comment\nL1\n\n<point>L2\n#+end_comment"
  4063. (org-forward-paragraph)
  4064. (org-current-line))))
  4065. ;; Being on an affiliated keyword shouldn't make any difference.
  4066. (should
  4067. (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
  4068. (org-forward-paragraph)
  4069. (eobp))))
  4070. (ert-deftest test-org/backward-paragraph ()
  4071. "Test `org-backward-paragraph' specifications."
  4072. ;; Do not error at beginning of buffer.
  4073. (should
  4074. (org-test-with-temp-text "Paragraph"
  4075. (org-backward-paragraph)
  4076. t))
  4077. ;; At blank lines at the very beginning of a buffer, move to
  4078. ;; point-min.
  4079. (should
  4080. (org-test-with-temp-text "\n\n<point>\n\nParagraph"
  4081. (org-backward-paragraph)
  4082. (bobp)))
  4083. ;; Regular test.
  4084. (should
  4085. (= 2
  4086. (org-test-with-temp-text "P1\n\nP2<point>"
  4087. (org-backward-paragraph)
  4088. (org-current-line))))
  4089. (should
  4090. (= 4
  4091. (org-test-with-temp-text "P1\n\nP2\n\nP3<point>"
  4092. (org-backward-paragraph)
  4093. (org-current-line))))
  4094. ;; Try to move on the line above current element.
  4095. (should
  4096. (= 2
  4097. (org-test-with-temp-text "\n\n<point>Paragraph"
  4098. (org-backward-paragraph)
  4099. (org-current-line))))
  4100. ;; Do not leave point in an invisible area.
  4101. (should
  4102. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  4103. (org-cycle)
  4104. (goto-char (point-max))
  4105. (beginning-of-line)
  4106. (org-backward-paragraph)
  4107. (bobp)))
  4108. (should
  4109. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\n"
  4110. (org-fold-hide-block-toggle)
  4111. (goto-char (point-max))
  4112. (org-backward-paragraph)
  4113. (bobp)))
  4114. ;; On the first element in an item or a footnote definition, jump
  4115. ;; before the footnote or the item.
  4116. (should
  4117. (org-test-with-temp-text "- line1<point>"
  4118. (org-backward-paragraph)
  4119. (bobp)))
  4120. (should
  4121. (org-test-with-temp-text "[fn:1] line1n<point>"
  4122. (org-backward-paragraph)
  4123. (bobp)))
  4124. ;; On the second element in an item or a footnote definition, jump
  4125. ;; to item or the definition.
  4126. (should
  4127. (= 2
  4128. (org-test-with-temp-text "- line1\n\n<point> line2"
  4129. (org-backward-paragraph)
  4130. (org-current-line))))
  4131. (should
  4132. (= 2
  4133. (org-test-with-temp-text "[fn:1] line1\n\n<point> line2"
  4134. (org-backward-paragraph)
  4135. (org-current-line))))
  4136. ;; On a table (resp. a property drawer), ignore table rows
  4137. ;; (resp. node properties).
  4138. (should
  4139. (org-test-with-temp-text "| a | b |\n| c | d |\n<point>P1"
  4140. (org-backward-paragraph)
  4141. (bobp)))
  4142. (should
  4143. (= 2
  4144. (org-test-with-temp-text
  4145. "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
  4146. (org-backward-paragraph)
  4147. (org-current-line))))
  4148. ;; In a plain list with one item every line, skip the whole list,
  4149. ;; even with point in the middle of the list.
  4150. (should
  4151. (org-test-with-temp-text "- A\n - B\n- C\n<point>"
  4152. (org-backward-paragraph)
  4153. (bobp)))
  4154. (should
  4155. (org-test-with-temp-text "- A\n - B\n- <point>C\n"
  4156. (org-backward-paragraph)
  4157. (bobp)))
  4158. ;; Skip consecutive keywords, clocks and diary S-exps.
  4159. (should
  4160. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n<point>"
  4161. (org-backward-paragraph)
  4162. (bobp)))
  4163. (should
  4164. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n<point>"
  4165. (org-backward-paragraph)
  4166. (bobp)))
  4167. (should
  4168. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n<point>"
  4169. (org-backward-paragraph)
  4170. (bobp)))
  4171. (should-not
  4172. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n<point>"
  4173. (org-backward-paragraph)
  4174. (bobp)))
  4175. (should-not
  4176. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n<point>"
  4177. (org-backward-paragraph)
  4178. (bobp)))
  4179. ;; On a comment, example, source and verse blocks, stop at blank
  4180. ;; lines.
  4181. (should
  4182. (= 1
  4183. (org-test-with-temp-text
  4184. "#+begin_comment\n<point>L1\n\nL2\n\nL3\n#+end_comment"
  4185. (org-backward-paragraph)
  4186. (org-current-line))))
  4187. (should
  4188. (= 2
  4189. (org-test-with-temp-text
  4190. "#+begin_verse\nL1\n\n<point>L2\n\nL3\n#+end_verse"
  4191. (org-backward-paragraph)
  4192. (org-current-line))))
  4193. (should
  4194. (= 3
  4195. (org-test-with-temp-text
  4196. "#+begin_src emacs-lisp\nL1\n\nL2\n\n<point>L3\n#+end_src"
  4197. (org-backward-paragraph)
  4198. (org-current-line))))
  4199. ;; When called from the opening line itself, however, move to
  4200. ;; beginning of block.
  4201. (should
  4202. (org-test-with-temp-text "#+begin_<point>example\nL1\n#+end_example"
  4203. (org-backward-paragraph)
  4204. (bobp)))
  4205. ;; On an empty heading, move above it.
  4206. (should
  4207. (org-test-with-temp-text "\n* <point>"
  4208. (org-backward-paragraph)
  4209. (bobp)))
  4210. (should
  4211. (org-test-with-temp-text "\n* \n<point>"
  4212. (org-backward-paragraph)
  4213. (bobp))))
  4214. (ert-deftest test-org/forward-element ()
  4215. "Test `org-forward-element' specifications."
  4216. ;; 1. At EOB: should error.
  4217. (org-test-with-temp-text "Some text\n"
  4218. (goto-char (point-max))
  4219. (should-error (org-forward-element)))
  4220. ;; 2. Standard move: expected to ignore blank lines.
  4221. (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
  4222. (org-forward-element)
  4223. (should (looking-at (regexp-quote "Second paragraph."))))
  4224. ;; 3. Headline tests.
  4225. (org-test-with-temp-text "
  4226. * Head 1
  4227. ** Head 1.1
  4228. *** Head 1.1.1
  4229. ** Head 1.2"
  4230. ;; 3.1. At an headline beginning: move to next headline at the
  4231. ;; same level.
  4232. (goto-line 3)
  4233. (org-forward-element)
  4234. (should (looking-at (regexp-quote "** Head 1.2")))
  4235. ;; 3.2. At an headline beginning: move to parent headline if no
  4236. ;; headline at the same level.
  4237. (goto-line 3)
  4238. (org-forward-element)
  4239. (should (looking-at (regexp-quote "** Head 1.2"))))
  4240. ;; 4. Greater element tests.
  4241. (org-test-with-temp-text
  4242. "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
  4243. ;; 4.1. At a greater element: expected to skip contents.
  4244. (org-forward-element)
  4245. (should (looking-at (regexp-quote "Outside.")))
  4246. ;; 4.2. At the end of greater element contents: expected to skip
  4247. ;; to the end of the greater element.
  4248. (goto-line 2)
  4249. (org-forward-element)
  4250. (should (looking-at (regexp-quote "Outside."))))
  4251. ;; 5. List tests.
  4252. (org-test-with-temp-text "
  4253. - item1
  4254. - sub1
  4255. - sub2
  4256. - sub3
  4257. Inner paragraph.
  4258. - item2
  4259. Outside."
  4260. ;; 5.1. At list top point: expected to move to the element after
  4261. ;; the list.
  4262. (goto-line 2)
  4263. (org-forward-element)
  4264. (should (looking-at (regexp-quote "Outside.")))
  4265. ;; 5.2. Special case: at the first line of a sub-list, but not at
  4266. ;; beginning of line, move to next item.
  4267. (goto-line 2)
  4268. (forward-char)
  4269. (org-forward-element)
  4270. (should (looking-at "- item2"))
  4271. (goto-line 4)
  4272. (forward-char)
  4273. (org-forward-element)
  4274. (should (looking-at " - sub2"))
  4275. ;; 5.3 At sub-list beginning: expected to move after the sub-list.
  4276. (goto-line 4)
  4277. (org-forward-element)
  4278. (should (looking-at (regexp-quote " Inner paragraph.")))
  4279. ;; 5.4. At sub-list end: expected to move outside the sub-list.
  4280. (goto-line 8)
  4281. (org-forward-element)
  4282. (should (looking-at (regexp-quote " Inner paragraph.")))
  4283. ;; 5.5. At an item: expected to move to next item, if any.
  4284. (goto-line 6)
  4285. (org-forward-element)
  4286. (should (looking-at " - sub3"))))
  4287. (ert-deftest test-org/backward-element ()
  4288. "Test `org-backward-element' specifications."
  4289. ;; 1. Should error at BOB.
  4290. (org-test-with-temp-text " \nParagraph."
  4291. (should-error (org-backward-element)))
  4292. ;; 2. Should move at BOB when called on the first element in buffer.
  4293. (should
  4294. (org-test-with-temp-text "\n#+TITLE: test"
  4295. (progn (forward-line)
  4296. (org-backward-element)
  4297. (bobp))))
  4298. ;; 3. Not at the beginning of an element: move at its beginning.
  4299. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  4300. (goto-line 3)
  4301. (end-of-line)
  4302. (org-backward-element)
  4303. (should (looking-at (regexp-quote "Paragraph2."))))
  4304. ;; 4. Headline tests.
  4305. (org-test-with-temp-text "
  4306. * Head 1
  4307. ** Head 1.1
  4308. *** Head 1.1.1
  4309. ** Head 1.2"
  4310. ;; 4.1. At an headline beginning: move to previous headline at the
  4311. ;; same level.
  4312. (goto-line 5)
  4313. (org-backward-element)
  4314. (should (looking-at (regexp-quote "** Head 1.1")))
  4315. ;; 4.2. At an headline beginning: move to parent headline if no
  4316. ;; headline at the same level.
  4317. (goto-line 3)
  4318. (org-backward-element)
  4319. (should (looking-at (regexp-quote "* Head 1")))
  4320. ;; 4.3. At the first top-level headline: should error.
  4321. (goto-line 2)
  4322. (should-error (org-backward-element)))
  4323. ;; 5. At beginning of first element inside a greater element:
  4324. ;; expected to move to greater element's beginning.
  4325. (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
  4326. (goto-line 3)
  4327. (org-backward-element)
  4328. (should (looking-at "#\\+BEGIN_CENTER")))
  4329. ;; 6. At the beginning of the first element in a section: should
  4330. ;; move back to headline, if any.
  4331. (should
  4332. (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
  4333. (progn (goto-char (point-max))
  4334. (beginning-of-line)
  4335. (org-backward-element)
  4336. (org-at-heading-p))))
  4337. ;; 7. List tests.
  4338. (org-test-with-temp-text "
  4339. - item1
  4340. - sub1
  4341. - sub2
  4342. - sub3
  4343. Inner paragraph.
  4344. - item2
  4345. Outside."
  4346. ;; 7.1. At beginning of sub-list: expected to move to the
  4347. ;; paragraph before it.
  4348. (goto-line 4)
  4349. (org-backward-element)
  4350. (should (looking-at "item1"))
  4351. ;; 7.2. At an item in a list: expected to move at previous item.
  4352. (goto-line 8)
  4353. (org-backward-element)
  4354. (should (looking-at " - sub2"))
  4355. (goto-line 12)
  4356. (org-backward-element)
  4357. (should (looking-at "- item1"))
  4358. ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
  4359. ;; beginning.
  4360. (goto-line 10)
  4361. (org-backward-element)
  4362. (should (looking-at " - sub1"))
  4363. (goto-line 15)
  4364. (org-backward-element)
  4365. (should (looking-at "- item1"))
  4366. ;; 7.4. At blank-lines before list end: expected to move to top
  4367. ;; item.
  4368. (goto-line 14)
  4369. (org-backward-element)
  4370. (should (looking-at "- item1"))))
  4371. (ert-deftest test-org/up-element ()
  4372. "Test `org-up-element' specifications."
  4373. ;; 1. At BOB or with no surrounding element: should error.
  4374. (org-test-with-temp-text "Paragraph."
  4375. (should-error (org-up-element)))
  4376. (org-test-with-temp-text "* Head1\n* Head2"
  4377. (goto-line 2)
  4378. (should-error (org-up-element)))
  4379. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  4380. (goto-line 3)
  4381. (should-error (org-up-element)))
  4382. ;; 2. At an headline: move to parent headline.
  4383. (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
  4384. (goto-line 3)
  4385. (org-up-element)
  4386. (should (looking-at "\\* Head1")))
  4387. ;; 3. Inside a greater element: move to greater element beginning.
  4388. (org-test-with-temp-text
  4389. "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
  4390. (goto-line 3)
  4391. (org-up-element)
  4392. (should (looking-at "#\\+BEGIN_CENTER")))
  4393. ;; 4. List tests.
  4394. (org-test-with-temp-text "* Top
  4395. - item1
  4396. - sub1
  4397. - sub2
  4398. Paragraph within sub2.
  4399. - item2"
  4400. ;; 4.1. Within an item: move to the item beginning.
  4401. (goto-line 8)
  4402. (org-up-element)
  4403. (should (looking-at " - sub2"))
  4404. ;; 4.2. At an item in a sub-list: move to parent item.
  4405. (goto-line 4)
  4406. (org-up-element)
  4407. (should (looking-at "- item1"))
  4408. ;; 4.3. At an item in top list: move to beginning of whole list.
  4409. (goto-line 10)
  4410. (org-up-element)
  4411. (should (looking-at "- item1"))
  4412. ;; 4.4. Special case. At very top point: should move to parent of
  4413. ;; list.
  4414. (goto-line 2)
  4415. (org-up-element)
  4416. (should (looking-at "\\* Top"))))
  4417. (ert-deftest test-org/down-element ()
  4418. "Test `org-down-element' specifications."
  4419. ;; Error when the element hasn't got a recursive type.
  4420. (org-test-with-temp-text "Paragraph."
  4421. (should-error (org-down-element)))
  4422. ;; Error when the element has no contents
  4423. (org-test-with-temp-text "* Headline"
  4424. (should-error (org-down-element)))
  4425. ;; When at a plain-list, move to first item.
  4426. (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
  4427. (goto-line 2)
  4428. (org-down-element)
  4429. (should (looking-at " - Item 1.1")))
  4430. (org-test-with-temp-text "#+NAME: list\n- Item 1"
  4431. (org-down-element)
  4432. (should (looking-at " Item 1")))
  4433. ;; When at a table, move to first row
  4434. (org-test-with-temp-text "#+NAME: table\n| a | b |"
  4435. (org-down-element)
  4436. (should (looking-at " a | b |")))
  4437. ;; Otherwise, move inside the greater element.
  4438. (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
  4439. (org-down-element)
  4440. (should (looking-at "Paragraph"))))
  4441. (ert-deftest test-org/drag-element-backward ()
  4442. "Test `org-drag-element-backward' specifications."
  4443. ;; Standard test.
  4444. (should
  4445. (equal
  4446. "#+key2: val2\n#+key1: val1\n#+key3: val3"
  4447. (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
  4448. (org-drag-element-backward)
  4449. (buffer-string))))
  4450. (should
  4451. (equal
  4452. "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
  4453. (org-test-with-temp-text
  4454. "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
  4455. (org-drag-element-backward)
  4456. (buffer-string))))
  4457. ;; Preserve blank lines.
  4458. (should
  4459. (equal "Paragraph 2\n\n\nPara1\n\nPara3"
  4460. (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
  4461. (org-drag-element-backward)
  4462. (buffer-string))))
  4463. ;; Preserve column.
  4464. (should
  4465. (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
  4466. (org-drag-element-backward)
  4467. (looking-at-p "2")))
  4468. ;; Error when trying to move first element of buffer.
  4469. (should-error
  4470. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4471. (org-drag-element-backward))
  4472. :type 'user-error)
  4473. ;; Error when trying to swap nested elements.
  4474. (should-error
  4475. (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
  4476. (org-drag-element-backward))
  4477. :type 'user-error)
  4478. ;; Error when trying to swap an headline element and a non-headline
  4479. ;; element.
  4480. (should-error
  4481. (org-test-with-temp-text "Test.\n<point>* Head 1"
  4482. (org-drag-element-backward))
  4483. :type 'error)
  4484. ;; Error when called before first element.
  4485. (should-error
  4486. (org-test-with-temp-text "\n<point>"
  4487. (org-drag-element-backward))
  4488. :type 'user-error)
  4489. ;; Preserve visibility of elements and their contents.
  4490. (should
  4491. (equal '((63 . 82) (26 . 48))
  4492. (let ((org-fold-core-style 'text-properties))
  4493. (org-test-with-temp-text
  4494. "
  4495. #+BEGIN_CENTER
  4496. Text.
  4497. #+END_CENTER
  4498. - item 1
  4499. #+BEGIN_QUOTE
  4500. Text.
  4501. #+END_QUOTE"
  4502. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4503. (search-backward "- item 1")
  4504. (org-drag-element-backward)
  4505. (let (regions)
  4506. (goto-char (point-min))
  4507. (while (< (point) (point-max))
  4508. (let ((region (org-fold-get-region-at-point)))
  4509. (if (not region)
  4510. (goto-char (org-fold-next-folding-state-change))
  4511. (goto-char (cdr region))
  4512. (push region regions))))
  4513. regions)))))
  4514. (should
  4515. (equal '((63 . 82) (26 . 48))
  4516. (let ((org-fold-core-style 'overlays))
  4517. (org-test-with-temp-text
  4518. "
  4519. #+BEGIN_CENTER
  4520. Text.
  4521. #+END_CENTER
  4522. - item 1
  4523. #+BEGIN_QUOTE
  4524. Text.
  4525. #+END_QUOTE"
  4526. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4527. (search-backward "- item 1")
  4528. (org-drag-element-backward)
  4529. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4530. (overlays-in (point-min) (point-max)))))))
  4531. ;; Pathological case: handle call with point in blank lines right
  4532. ;; after a headline.
  4533. (should
  4534. (equal "* H2\n\n* H1\nText\n"
  4535. (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
  4536. (org-drag-element-backward)
  4537. (buffer-string)))))
  4538. (ert-deftest test-org/drag-element-forward ()
  4539. "Test `org-drag-element-forward' specifications."
  4540. ;; 1. Error when trying to move first element of buffer.
  4541. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4542. (goto-line 3)
  4543. (should-error (org-drag-element-forward)))
  4544. ;; 2. Error when trying to swap nested elements.
  4545. (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
  4546. (forward-line)
  4547. (should-error (org-drag-element-forward)))
  4548. ;; 3. Error when trying to swap a non-headline element and an
  4549. ;; headline.
  4550. (org-test-with-temp-text "Test.\n* Head 1"
  4551. (should-error (org-drag-element-forward)))
  4552. ;; 4. Error when called before first element.
  4553. (should-error
  4554. (org-test-with-temp-text "\n"
  4555. (forward-line)
  4556. (org-drag-element-backward))
  4557. :type 'user-error)
  4558. ;; 5. Otherwise, swap elements, preserving column and blank lines
  4559. ;; between elements.
  4560. (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
  4561. (search-forward "graph")
  4562. (org-drag-element-forward)
  4563. (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
  4564. (should (looking-at " 1")))
  4565. ;; 5. Preserve visibility of elements and their contents.
  4566. (let ((org-fold-core-style 'text-properties))
  4567. (org-test-with-temp-text
  4568. "
  4569. #+BEGIN_CENTER
  4570. Text.
  4571. #+END_CENTER
  4572. - item 1
  4573. #+BEGIN_QUOTE
  4574. Text.
  4575. #+END_QUOTE"
  4576. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4577. (search-backward "#+BEGIN_CENTER")
  4578. (org-drag-element-forward)
  4579. (should
  4580. (equal
  4581. '((63 . 82) (26 . 48))
  4582. (let (regions)
  4583. (goto-char (point-min))
  4584. (while (< (point) (point-max))
  4585. (let ((region (org-fold-get-region-at-point)))
  4586. (if (not region)
  4587. (goto-char (org-fold-next-folding-state-change))
  4588. (goto-char (cdr region))
  4589. (push region regions))))
  4590. regions)))))
  4591. (let ((org-fold-core-style 'overlays))
  4592. (org-test-with-temp-text
  4593. "
  4594. #+BEGIN_CENTER
  4595. Text.
  4596. #+END_CENTER
  4597. - item 1
  4598. #+BEGIN_QUOTE
  4599. Text.
  4600. #+END_QUOTE"
  4601. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4602. (search-backward "#+BEGIN_CENTER")
  4603. (org-drag-element-forward)
  4604. (should
  4605. (equal
  4606. '((63 . 82) (26 . 48))
  4607. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4608. (overlays-in (point-min) (point-max))))))))
  4609. (ert-deftest test-org/next-block ()
  4610. "Test `org-next-block' specifications."
  4611. ;; Regular test.
  4612. (should
  4613. (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  4614. (org-next-block 1)
  4615. (looking-at "#\\+BEGIN_CENTER")))
  4616. ;; Ignore case.
  4617. (should
  4618. (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
  4619. (let ((case-fold-search nil))
  4620. (org-next-block 1)
  4621. (looking-at "#\\+begin_center"))))
  4622. ;; Ignore current line.
  4623. (should
  4624. (org-test-with-temp-text
  4625. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
  4626. (org-next-block 1)
  4627. (looking-at "#\\+BEGIN_CENTER")))
  4628. ;; Throw an error when no block is found.
  4629. (should-error
  4630. (org-test-with-temp-text "Paragraph"
  4631. (org-next-block 1)))
  4632. ;; With an argument, skip many blocks at once.
  4633. (should
  4634. (org-test-with-temp-text
  4635. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4636. (org-next-block 2)
  4637. (looking-at "#\\+BEGIN_QUOTE")))
  4638. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4639. (should
  4640. (org-test-with-temp-text
  4641. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4642. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4643. (looking-at "#\\+BEGIN_QUOTE")))
  4644. ;; Optional argument is also case-insensitive.
  4645. (should
  4646. (org-test-with-temp-text
  4647. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
  4648. (let ((case-fold-search nil))
  4649. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4650. (looking-at "#\\+begin_quote")))))
  4651. (ert-deftest test-org/insert-structure-template ()
  4652. "Test `org-insert-structure-template'."
  4653. ;; Test in empty buffer.
  4654. (should
  4655. (string= "#+begin_foo\n#+end_foo\n"
  4656. (org-test-with-temp-text ""
  4657. (org-insert-structure-template "foo")
  4658. (buffer-string))))
  4659. ;; Test with multiple lines in buffer.
  4660. (should
  4661. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4662. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4663. (transient-mark-mode 1)
  4664. (org-mark-element)
  4665. (org-insert-structure-template "foo")
  4666. (buffer-string))))
  4667. ;; Mark only the current line.
  4668. (should
  4669. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4670. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4671. (transient-mark-mode 1)
  4672. (set-mark (point-min))
  4673. (end-of-line)
  4674. (org-insert-structure-template "foo")
  4675. (buffer-string))))
  4676. ;; Middle of paragraph.
  4677. (should
  4678. (string= "p1\n#+begin_foo\np2\n#+end_foo\np3"
  4679. (org-test-with-temp-text "p1\n<point>p2\np3"
  4680. (set-mark (line-beginning-position))
  4681. (end-of-line)
  4682. (activate-mark)
  4683. (org-insert-structure-template "foo")
  4684. (buffer-string))))
  4685. ;; Test with text in buffer, no region, no final newline.
  4686. (should
  4687. (string= "#+begin_foo\nI'm a paragraph.\n#+end_foo\n"
  4688. (org-test-with-temp-text "I'm a paragraph."
  4689. (org-mark-element)
  4690. (org-insert-structure-template "foo")
  4691. (buffer-string))))
  4692. ;; Test with text in buffer and region set.
  4693. (should
  4694. (string= "#+begin_foo\nI'm a paragraph\n\nI'm a second paragrah\n#+end_foo\n"
  4695. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragrah"
  4696. (set-mark (point))
  4697. (goto-char (point-max))
  4698. (org-insert-structure-template "foo")
  4699. (buffer-string))))
  4700. ;; Test with example escaping.
  4701. (should
  4702. (string= "#+begin_example\n,* Heading\n#+end_example\n"
  4703. (org-test-with-temp-text "* Heading"
  4704. (org-mark-element)
  4705. (org-insert-structure-template "example")
  4706. (buffer-string))))
  4707. ;; Test with indentation.
  4708. (should
  4709. (string= " #+begin_foo\n This is a paragraph\n #+end_foo\n"
  4710. (org-test-with-temp-text " This is a paragraph"
  4711. (org-mark-element)
  4712. (org-insert-structure-template "foo")
  4713. (buffer-string))))
  4714. (should
  4715. (string= " #+begin_foo\n Line 1\n Line2\n #+end_foo\n"
  4716. (org-test-with-temp-text " Line 1\n Line2"
  4717. (org-mark-element)
  4718. (org-insert-structure-template "foo")
  4719. (buffer-string))))
  4720. ;; Test point location.
  4721. (should
  4722. (string= "#+begin_foo\n"
  4723. (org-test-with-temp-text ""
  4724. (org-insert-structure-template "foo")
  4725. (buffer-substring (point-min) (point)))))
  4726. (should
  4727. (string= "#+begin_src "
  4728. (org-test-with-temp-text ""
  4729. (org-insert-structure-template "src")
  4730. (buffer-substring (point-min) (point))))))
  4731. (ert-deftest test-org/previous-block ()
  4732. "Test `org-previous-block' specifications."
  4733. ;; Regular test.
  4734. (should
  4735. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
  4736. (org-previous-block 1)
  4737. (looking-at "#\\+BEGIN_CENTER")))
  4738. ;; Ignore case.
  4739. (should
  4740. (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
  4741. (let ((case-fold-search nil))
  4742. (org-previous-block 1)
  4743. (looking-at "#\\+begin_center"))))
  4744. ;; Ignore current line.
  4745. (should
  4746. (org-test-with-temp-text
  4747. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
  4748. (org-previous-block 1)
  4749. (looking-at "#\\+BEGIN_QUOTE")))
  4750. ;; Throw an error when no block is found.
  4751. (should-error
  4752. (org-test-with-temp-text "Paragraph<point>"
  4753. (org-previous-block 1)))
  4754. ;; With an argument, skip many blocks at once.
  4755. (should
  4756. (org-test-with-temp-text
  4757. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4758. (org-previous-block 2)
  4759. (looking-at "#\\+BEGIN_CENTER")))
  4760. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4761. (should
  4762. (org-test-with-temp-text
  4763. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4764. (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4765. (looking-at "#\\+BEGIN_QUOTE")))
  4766. ;; Optional argument is also case-insensitive.
  4767. (should
  4768. (org-test-with-temp-text
  4769. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
  4770. (let ((case-fold-search nil))
  4771. (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4772. (looking-at "#\\+begin_quote")))))
  4773. ;;; Outline structure
  4774. (ert-deftest test-org/demote ()
  4775. "Test `org-demote' specifications."
  4776. ;; Add correct number of stars according to `org-odd-levels-only'.
  4777. (should
  4778. (= 2
  4779. (org-test-with-temp-text "* H"
  4780. (let ((org-odd-levels-only nil)) (org-demote))
  4781. (org-current-level))))
  4782. (should
  4783. (= 3
  4784. (org-test-with-temp-text "* H"
  4785. (let ((org-odd-levels-only t)) (org-demote))
  4786. (org-current-level))))
  4787. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4788. (should
  4789. (org-test-with-temp-text "* H :tag:"
  4790. (let ((org-tags-column 10)
  4791. (org-auto-align-tags t)
  4792. (org-odd-levels-only nil))
  4793. (org-demote))
  4794. (org-move-to-column 10)
  4795. (looking-at-p ":tag:$")))
  4796. (should-not
  4797. (org-test-with-temp-text "* H :tag:"
  4798. (let ((org-tags-column 10)
  4799. (org-auto-align-tags nil)
  4800. (org-odd-levels-only nil))
  4801. (org-demote))
  4802. (org-move-to-column 10)
  4803. (looking-at-p ":tag:$")))
  4804. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4805. ;; info and property drawers accordingly.
  4806. (should
  4807. (= 3
  4808. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4809. (let ((org-odd-levels-only nil)
  4810. (org-adapt-indentation t))
  4811. (org-demote))
  4812. (forward-line)
  4813. (org-get-indentation))))
  4814. (should
  4815. (= 3
  4816. (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4817. (let ((org-odd-levels-only nil)
  4818. (org-adapt-indentation t))
  4819. (org-demote))
  4820. (forward-line)
  4821. (org-get-indentation))))
  4822. (should-not
  4823. (= 3
  4824. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4825. (let ((org-odd-levels-only nil)
  4826. (org-adapt-indentation nil))
  4827. (org-demote))
  4828. (forward-line)
  4829. (org-get-indentation))))
  4830. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4831. ;; section accordingly. Ignore, however, footnote definitions and
  4832. ;; inlinetasks boundaries.
  4833. (should
  4834. (= 3
  4835. (org-test-with-temp-text "* H\n Paragraph"
  4836. (let ((org-odd-levels-only nil)
  4837. (org-adapt-indentation t))
  4838. (org-demote))
  4839. (forward-line)
  4840. (org-get-indentation))))
  4841. (should
  4842. (= 2
  4843. (org-test-with-temp-text "* H\n Paragraph"
  4844. (let ((org-odd-levels-only nil)
  4845. (org-adapt-indentation nil))
  4846. (org-demote))
  4847. (forward-line)
  4848. (org-get-indentation))))
  4849. (should
  4850. (zerop
  4851. (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
  4852. (let ((org-odd-levels-only nil)
  4853. (org-adapt-indentation t))
  4854. (org-demote))
  4855. (goto-char (point-max))
  4856. (org-get-indentation))))
  4857. (should
  4858. (= 3
  4859. (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
  4860. (let ((org-odd-levels-only nil)
  4861. (org-adapt-indentation t))
  4862. (org-demote))
  4863. (goto-char (point-max))
  4864. (org-get-indentation))))
  4865. (when (featurep 'org-inlinetask)
  4866. (should
  4867. (zerop
  4868. (let ((org-inlinetask-min-level 5)
  4869. (org-adapt-indentation t))
  4870. (org-test-with-temp-text "* H\n***** I\n***** END"
  4871. (org-demote)
  4872. (forward-line)
  4873. (org-get-indentation))))))
  4874. (when (featurep 'org-inlinetask)
  4875. (should
  4876. (= 3
  4877. (let ((org-inlinetask-min-level 5)
  4878. (org-adapt-indentation t))
  4879. (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
  4880. (org-demote)
  4881. (forward-line 2)
  4882. (org-get-indentation))))))
  4883. ;; When `org-adapt-indentation' is non-nil, log drawers are
  4884. ;; adjusted.
  4885. (should
  4886. (equal
  4887. "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4888. (org-test-with-temp-text "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4889. (let ((org-odd-levels-only nil)
  4890. (org-adapt-indentation t))
  4891. (org-demote))
  4892. (buffer-string))))
  4893. (should
  4894. (equal
  4895. "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4896. (org-test-with-temp-text "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4897. (let ((org-odd-levels-only nil)
  4898. (org-adapt-indentation 'headline-data))
  4899. (org-demote))
  4900. (buffer-string))))
  4901. (should
  4902. (equal
  4903. "** H\n :LOGBOOK:\n - a\n :END:"
  4904. (org-test-with-temp-text "* H\n:LOGBOOK:\n- a\n:END:"
  4905. (let ((org-odd-levels-only nil)
  4906. (org-adapt-indentation t))
  4907. (org-demote))
  4908. (buffer-string))))
  4909. ;; Ignore contents of source blocks or example blocks when
  4910. ;; indentation should be preserved (through
  4911. ;; `org-src-preserve-indentation' or "-i" flag).
  4912. (should-not
  4913. (zerop
  4914. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4915. (let ((org-adapt-indentation t)
  4916. (org-src-preserve-indentation nil))
  4917. (org-demote))
  4918. (forward-line 2)
  4919. (org-get-indentation))))
  4920. (should
  4921. (zerop
  4922. (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
  4923. (let ((org-adapt-indentation t)
  4924. (org-src-preserve-indentation t))
  4925. (org-demote))
  4926. (forward-line 2)
  4927. (org-get-indentation))))
  4928. (should
  4929. (zerop
  4930. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4931. (let ((org-adapt-indentation t)
  4932. (org-src-preserve-indentation t))
  4933. (org-demote))
  4934. (forward-line 2)
  4935. (org-get-indentation))))
  4936. (should
  4937. (zerop
  4938. (org-test-with-temp-text
  4939. "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
  4940. (let ((org-adapt-indentation t)
  4941. (org-src-preserve-indentation nil))
  4942. (org-demote))
  4943. (forward-line 2)
  4944. (org-get-indentation)))))
  4945. (ert-deftest test-org/promote ()
  4946. "Test `org-promote' specifications."
  4947. ;; Return an error if headline is to be promoted to level 0, unless
  4948. ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
  4949. ;; headline becomes a comment.
  4950. (should-error
  4951. (org-test-with-temp-text "* H"
  4952. (let ((org-allow-promoting-top-level-subtree nil)) (org-promote))))
  4953. (should
  4954. (equal "# H"
  4955. (org-test-with-temp-text "* H"
  4956. (let ((org-allow-promoting-top-level-subtree t)) (org-promote))
  4957. (buffer-string))))
  4958. ;; Remove correct number of stars according to
  4959. ;; `org-odd-levels-only'.
  4960. (should
  4961. (= 2
  4962. (org-test-with-temp-text "*** H"
  4963. (let ((org-odd-levels-only nil)) (org-promote))
  4964. (org-current-level))))
  4965. (should
  4966. (= 1
  4967. (org-test-with-temp-text "*** H"
  4968. (let ((org-odd-levels-only t)) (org-promote))
  4969. (org-current-level))))
  4970. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4971. (should
  4972. (org-test-with-temp-text "** H :tag:"
  4973. (let ((org-tags-column 10)
  4974. (org-auto-align-tags t)
  4975. (org-odd-levels-only nil))
  4976. (org-promote))
  4977. (org-move-to-column 10)
  4978. (looking-at-p ":tag:$")))
  4979. (should-not
  4980. (org-test-with-temp-text "** H :tag:"
  4981. (let ((org-tags-column 10)
  4982. (org-auto-align-tags nil)
  4983. (org-odd-levels-only nil))
  4984. (org-promote))
  4985. (org-move-to-column 10)
  4986. (looking-at-p ":tag:$")))
  4987. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4988. ;; info and property drawers.
  4989. (should
  4990. (= 2
  4991. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4992. (let ((org-odd-levels-only nil)
  4993. (org-adapt-indentation t))
  4994. (org-promote))
  4995. (forward-line)
  4996. (org-get-indentation))))
  4997. (should
  4998. (= 2
  4999. (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  5000. (let ((org-odd-levels-only nil)
  5001. (org-adapt-indentation t))
  5002. (org-promote))
  5003. (forward-line)
  5004. (org-get-indentation))))
  5005. (should-not
  5006. (= 2
  5007. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  5008. (let ((org-odd-levels-only nil)
  5009. (org-adapt-indentation nil))
  5010. (org-promote))
  5011. (forward-line)
  5012. (org-get-indentation))))
  5013. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  5014. ;; section accordingly. Ignore, however, footnote definitions and
  5015. ;; inlinetasks boundaries.
  5016. (should
  5017. (= 2
  5018. (org-test-with-temp-text "** H\n Paragraph"
  5019. (let ((org-odd-levels-only nil)
  5020. (org-adapt-indentation t))
  5021. (org-promote))
  5022. (forward-line)
  5023. (org-get-indentation))))
  5024. (should-not
  5025. (= 2
  5026. (org-test-with-temp-text "** H\n Paragraph"
  5027. (let ((org-odd-levels-only nil)
  5028. (org-adapt-indentation nil))
  5029. (org-promote))
  5030. (forward-line)
  5031. (org-get-indentation))))
  5032. (should
  5033. (= 2
  5034. (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
  5035. (let ((org-odd-levels-only nil)
  5036. (org-adapt-indentation t))
  5037. (org-promote))
  5038. (forward-line)
  5039. (org-get-indentation))))
  5040. (when (featurep 'org-inlinetask)
  5041. (should
  5042. (zerop
  5043. (let ((org-inlinetask-min-level 5)
  5044. (org-adapt-indentation t))
  5045. (org-test-with-temp-text "** H\n***** I\n***** END"
  5046. (org-promote)
  5047. (forward-line)
  5048. (org-get-indentation))))))
  5049. (when (featurep 'org-inlinetask)
  5050. (should
  5051. (= 2
  5052. (let ((org-inlinetask-min-level 5)
  5053. (org-adapt-indentation t))
  5054. (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
  5055. (org-promote)
  5056. (forward-line 2)
  5057. (org-get-indentation))))))
  5058. ;; Give up shifting if it would break document's structure
  5059. ;; otherwise.
  5060. (should
  5061. (= 3
  5062. (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
  5063. (let ((org-odd-levels-only nil)
  5064. (org-adapt-indentation t))
  5065. (org-promote))
  5066. (forward-line)
  5067. (org-get-indentation))))
  5068. (should
  5069. (= 3
  5070. (org-test-with-temp-text "** H\n Paragraph\n * list."
  5071. (let ((org-odd-levels-only nil)
  5072. (org-adapt-indentation t))
  5073. (org-promote))
  5074. (forward-line)
  5075. (org-get-indentation))))
  5076. ;; When `org-adapt-indentation' is non-nil, log drawers are
  5077. ;; adjusted.
  5078. (should
  5079. (equal
  5080. "* H\n :LOGBOOK:\n - a\n :END:\n b"
  5081. (org-test-with-temp-text "** H\n :LOGBOOK:\n - a\n :END:\n b"
  5082. (let ((org-odd-levels-only nil)
  5083. (org-adapt-indentation t))
  5084. (org-promote))
  5085. (buffer-string))))
  5086. (should
  5087. (equal
  5088. "* H\n :LOGBOOK:\n - a\n :END:\n b"
  5089. (org-test-with-temp-text "** H\n :LOGBOOK:\n - a\n :END:\n b"
  5090. (let ((org-odd-levels-only nil)
  5091. (org-adapt-indentation 'headline-data))
  5092. (org-promote))
  5093. (buffer-string))))
  5094. (should
  5095. (equal
  5096. "* H\n:LOGBOOK:\n- a\n:END:"
  5097. (org-test-with-temp-text "** H\n:LOGBOOK:\n- a\n:END:"
  5098. (let ((org-odd-levels-only nil)
  5099. (org-adapt-indentation t))
  5100. (org-promote))
  5101. (buffer-string))))
  5102. (should
  5103. (equal
  5104. "# H\n:LOGBOOK:\n- a\n:END:"
  5105. (org-test-with-temp-text "* H\n:LOGBOOK:\n- a\n:END:"
  5106. (let ((org-odd-levels-only nil)
  5107. (org-allow-promoting-top-level-subtree t)
  5108. (org-adapt-indentation t))
  5109. (org-promote))
  5110. (buffer-string))))
  5111. ;; Ignore contents of source blocks or example blocks when
  5112. ;; indentation should be preserved (through
  5113. ;; `org-src-preserve-indentation' or "-i" flag).
  5114. (should-not
  5115. (zerop
  5116. (org-test-with-temp-text
  5117. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  5118. (let ((org-adapt-indentation t)
  5119. (org-src-preserve-indentation nil)
  5120. (org-odd-levels-only nil))
  5121. (org-promote))
  5122. (forward-line)
  5123. (org-get-indentation))))
  5124. (should
  5125. (zerop
  5126. (org-test-with-temp-text
  5127. "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
  5128. (let ((org-adapt-indentation t)
  5129. (org-src-preserve-indentation t)
  5130. (org-odd-levels-only nil))
  5131. (org-promote))
  5132. (forward-line)
  5133. (org-get-indentation))))
  5134. (should
  5135. (zerop
  5136. (org-test-with-temp-text
  5137. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  5138. (let ((org-adapt-indentation t)
  5139. (org-src-preserve-indentation t)
  5140. (org-odd-levels-only nil))
  5141. (org-promote))
  5142. (forward-line)
  5143. (org-get-indentation))))
  5144. (should
  5145. (zerop
  5146. (org-test-with-temp-text
  5147. "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
  5148. (let ((org-adapt-indentation t)
  5149. (org-src-preserve-indentation nil)
  5150. (org-odd-levels-only nil))
  5151. (org-promote))
  5152. (forward-line)
  5153. (org-get-indentation)))))
  5154. (ert-deftest test-org/org-get-valid-level ()
  5155. "Test function `org-get-valid-level' specifications."
  5156. (let ((org-odd-levels-only nil))
  5157. (should (equal 1 (org-get-valid-level 0 0)))
  5158. (should (equal 1 (org-get-valid-level 0 1)))
  5159. (should (equal 2 (org-get-valid-level 0 2)))
  5160. (should (equal 3 (org-get-valid-level 0 3)))
  5161. (should (equal 1 (org-get-valid-level 1 0)))
  5162. (should (equal 2 (org-get-valid-level 1 1)))
  5163. (should (equal 23 (org-get-valid-level 1 22)))
  5164. (should (equal 1 (org-get-valid-level 1 -1)))
  5165. (should (equal 1 (org-get-valid-level 2 -1))))
  5166. (let ((org-odd-levels-only t))
  5167. (should (equal 1 (org-get-valid-level 0 0)))
  5168. (should (equal 1 (org-get-valid-level 0 1)))
  5169. (should (equal 3 (org-get-valid-level 0 2)))
  5170. (should (equal 5 (org-get-valid-level 0 3)))
  5171. (should (equal 1 (org-get-valid-level 1 0)))
  5172. (should (equal 3 (org-get-valid-level 1 1)))
  5173. (should (equal 3 (org-get-valid-level 2 1)))
  5174. (should (equal 5 (org-get-valid-level 3 1)))
  5175. (should (equal 5 (org-get-valid-level 4 1)))
  5176. (should (equal 43 (org-get-valid-level 1 21)))
  5177. (should (equal 1 (org-get-valid-level 1 -1)))
  5178. (should (equal 1 (org-get-valid-level 2 -1)))
  5179. (should (equal 1 (org-get-valid-level 3 -1)))
  5180. (should (equal 3 (org-get-valid-level 4 -1)))
  5181. (should (equal 3 (org-get-valid-level 5 -1)))))
  5182. ;;; Planning
  5183. (ert-deftest test-org/at-planning-p ()
  5184. "Test `org-at-planning-p' specifications."
  5185. ;; Regular test.
  5186. (should
  5187. (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
  5188. (org-at-planning-p)))
  5189. (should-not
  5190. (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
  5191. (org-at-planning-p)))
  5192. ;; Correctly find planning attached to inlinetasks.
  5193. (when (featurep 'org-inlinetask)
  5194. (should
  5195. (org-test-with-temp-text
  5196. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
  5197. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  5198. (should-not
  5199. (org-test-with-temp-text
  5200. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  5201. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  5202. (should-not
  5203. (org-test-with-temp-text
  5204. "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  5205. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  5206. (should-not
  5207. (org-test-with-temp-text
  5208. "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
  5209. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
  5210. (ert-deftest test-org/add-planning-info ()
  5211. "Test `org-add-planning-info'."
  5212. ;; Create deadline when `org-adapt-indentation' is non-nil.
  5213. (should
  5214. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5215. (org-test-with-temp-text "* H\nParagraph<point>"
  5216. (let ((org-adapt-indentation t))
  5217. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5218. (replace-regexp-in-string
  5219. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5220. nil nil 1))))
  5221. ;; Create deadline when `org-adapt-indentation' is nil.
  5222. (should
  5223. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  5224. (org-test-with-temp-text "* H\nParagraph<point>"
  5225. (let ((org-adapt-indentation nil))
  5226. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5227. (replace-regexp-in-string
  5228. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5229. nil nil 1))))
  5230. ;; Update deadline when `org-adapt-indentation' is non-nil.
  5231. (should
  5232. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5233. (org-test-with-temp-text "\
  5234. * H
  5235. DEADLINE: <2015-06-24 Wed>
  5236. Paragraph<point>"
  5237. (let ((org-adapt-indentation t))
  5238. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5239. (replace-regexp-in-string
  5240. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5241. nil nil 1))))
  5242. ;; Update deadline when `org-adapt-indentation' is nil.
  5243. (should
  5244. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  5245. (org-test-with-temp-text "\
  5246. * H
  5247. DEADLINE: <2015-06-24 Wed>
  5248. Paragraph<point>"
  5249. (let ((org-adapt-indentation nil))
  5250. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5251. (replace-regexp-in-string
  5252. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5253. nil nil 1))))
  5254. ;; Schedule when `org-adapt-indentation' is non-nil.
  5255. (should
  5256. (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
  5257. (org-test-with-temp-text "* H\nParagraph<point>"
  5258. (let ((org-adapt-indentation t))
  5259. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  5260. (replace-regexp-in-string
  5261. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5262. nil nil 1))))
  5263. ;; Schedule when `org-adapt-indentation' is nil.
  5264. (should
  5265. (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
  5266. (org-test-with-temp-text "* H\nParagraph<point>"
  5267. (let ((org-adapt-indentation nil))
  5268. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  5269. (replace-regexp-in-string
  5270. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5271. nil nil 1))))
  5272. ;; Add deadline when scheduled.
  5273. (should
  5274. (equal "\
  5275. * H
  5276. DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
  5277. Paragraph"
  5278. (org-test-with-temp-text "\
  5279. * H
  5280. SCHEDULED: <2015-06-24 Wed>
  5281. Paragraph<point>"
  5282. (let ((org-adapt-indentation t))
  5283. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5284. (replace-regexp-in-string
  5285. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5286. nil nil 1))))
  5287. ;; Remove middle entry.
  5288. (should
  5289. (equal "\
  5290. * H
  5291. CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
  5292. Paragraph"
  5293. (org-test-with-temp-text "\
  5294. * H
  5295. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  5296. Paragraph<point>"
  5297. (let ((org-adapt-indentation t))
  5298. (org-add-planning-info nil nil 'deadline))
  5299. (replace-regexp-in-string
  5300. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  5301. nil nil 1))))
  5302. ;; Remove last entry and then middle entry (order should not
  5303. ;; matter).
  5304. (should
  5305. (equal "\
  5306. * H
  5307. CLOSED: [2015-06-24]
  5308. Paragraph"
  5309. (org-test-with-temp-text "\
  5310. * H
  5311. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  5312. Paragraph<point>"
  5313. (let ((org-adapt-indentation t))
  5314. (org-add-planning-info nil nil 'scheduled 'deadline))
  5315. (replace-regexp-in-string
  5316. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  5317. nil nil 1))))
  5318. ;; Remove closed when `org-adapt-indentation' is non-nil.
  5319. (should
  5320. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5321. (org-test-with-temp-text "\
  5322. * H
  5323. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  5324. Paragraph<point>"
  5325. (let ((org-adapt-indentation t))
  5326. (org-add-planning-info nil nil 'closed))
  5327. (replace-regexp-in-string
  5328. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5329. nil nil 1))))
  5330. (should
  5331. (equal "* H\n Paragraph"
  5332. (org-test-with-temp-text "\
  5333. * H
  5334. CLOSED: [2015-06-25 Thu]
  5335. Paragraph<point>"
  5336. (let ((org-adapt-indentation t))
  5337. (org-add-planning-info nil nil 'closed))
  5338. (replace-regexp-in-string
  5339. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5340. nil nil 1))))
  5341. ;; Remove closed when `org-adapt-indentation' is nil.
  5342. (should
  5343. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  5344. (org-test-with-temp-text "\
  5345. * H
  5346. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  5347. Paragraph<point>"
  5348. (let ((org-adapt-indentation nil))
  5349. (org-add-planning-info nil nil 'closed))
  5350. (replace-regexp-in-string
  5351. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5352. nil nil 1))))
  5353. (should
  5354. (equal "* H\nParagraph"
  5355. (org-test-with-temp-text "\
  5356. * H
  5357. CLOSED: [2015-06-25 Thu]
  5358. Paragraph<point>"
  5359. (let ((org-adapt-indentation nil))
  5360. (org-add-planning-info nil nil 'closed))
  5361. (replace-regexp-in-string
  5362. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5363. nil nil 1))))
  5364. ;; Remove closed entry and delete empty line.
  5365. (should
  5366. (equal "\
  5367. * H
  5368. Paragraph"
  5369. (org-test-with-temp-text "\
  5370. * H
  5371. CLOSED: [2015-06-24 Wed]
  5372. Paragraph<point>"
  5373. (let ((org-adapt-indentation t))
  5374. (org-add-planning-info nil nil 'closed))
  5375. (replace-regexp-in-string
  5376. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5377. nil nil 1))))
  5378. ;; Remove one entry and update another.
  5379. (should
  5380. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5381. (org-test-with-temp-text "\
  5382. * H
  5383. SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
  5384. Paragraph<point>"
  5385. (let ((org-adapt-indentation t))
  5386. (org-add-planning-info 'deadline "<2015-06-25 Thu>" 'scheduled))
  5387. (replace-regexp-in-string
  5388. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5389. nil nil 1)))))
  5390. (ert-deftest test-org/deadline ()
  5391. "Test `org-deadline' specifications."
  5392. ;; Insert a new value or replace existing one.
  5393. (should
  5394. (equal "* H\nDEADLINE: <2012-03-29>"
  5395. (org-test-with-temp-text "* H"
  5396. (let ((org-adapt-indentation nil)
  5397. (org-last-inserted-timestamp nil))
  5398. (org-deadline nil "<2012-03-29 Tue>"))
  5399. (replace-regexp-in-string
  5400. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5401. nil nil 1))))
  5402. (should
  5403. (equal "* H\nDEADLINE: <2014-03-04>"
  5404. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5405. (let ((org-adapt-indentation nil)
  5406. (org-last-inserted-timestamp nil))
  5407. (org-deadline nil "<2014-03-04 Thu>"))
  5408. (replace-regexp-in-string
  5409. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5410. nil nil 1))))
  5411. ;; Accept delta time, e.g., "+2d".
  5412. (should
  5413. (equal "* H\nDEADLINE: <2015-03-04>"
  5414. (org-test-at-time "2014-03-04"
  5415. (org-test-with-temp-text "* H"
  5416. (let ((org-adapt-indentation nil)
  5417. (org-last-inserted-timestamp nil))
  5418. (org-deadline nil "+1y"))
  5419. (replace-regexp-in-string
  5420. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5421. ;; Preserve repeater.
  5422. (should
  5423. (equal "* H\nDEADLINE: <2012-03-29 +2y>"
  5424. (org-test-with-temp-text "* H"
  5425. (let ((org-adapt-indentation nil)
  5426. (org-last-inserted-timestamp nil))
  5427. (org-deadline nil "<2012-03-29 Tue +2y>"))
  5428. (replace-regexp-in-string
  5429. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5430. ;; Preserve warning period.
  5431. (should
  5432. (equal "* H\nDEADLINE: <2021-07-20 -1d>"
  5433. (org-test-with-temp-text "* H"
  5434. (let ((org-adapt-indentation nil)
  5435. (org-last-inserted-timestamp nil))
  5436. (org-deadline nil "<2021-07-20 Tue -1d>"))
  5437. (replace-regexp-in-string
  5438. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5439. (should
  5440. (equal "* H\nDEADLINE: <2021-07-20 +1m -3d>"
  5441. (org-test-with-temp-text "* H"
  5442. (let ((org-adapt-indentation nil)
  5443. (org-last-inserted-timestamp nil))
  5444. (org-deadline nil "<2021-07-20 Tue +1m -3d>"))
  5445. (replace-regexp-in-string
  5446. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5447. ;; Remove CLOSED keyword, if any.
  5448. (should
  5449. (equal "* H\nDEADLINE: <2012-03-29>"
  5450. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  5451. (let ((org-adapt-indentation nil)
  5452. (org-last-inserted-timestamp nil))
  5453. (org-deadline nil "<2012-03-29 Tue>"))
  5454. (replace-regexp-in-string
  5455. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5456. ;; With C-u argument, remove DEADLINE keyword.
  5457. (should
  5458. (equal "* H\n"
  5459. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5460. (let ((org-adapt-indentation nil)
  5461. (org-last-inserted-timestamp nil))
  5462. (org-deadline '(4)))
  5463. (buffer-string))))
  5464. (should
  5465. (equal "* H"
  5466. (org-test-with-temp-text "* H"
  5467. (let ((org-adapt-indentation nil)
  5468. (org-last-inserted-timestamp nil))
  5469. (org-deadline '(4)))
  5470. (buffer-string))))
  5471. ;; With C-u C-u argument, prompt for a delay cookie.
  5472. (should
  5473. (equal "* H\nDEADLINE: <2012-03-29 -705d>"
  5474. (cl-letf (((symbol-function 'org-read-date)
  5475. (lambda (&rest args)
  5476. (org-time-string-to-time "2014-03-04"))))
  5477. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5478. (let ((org-adapt-indentation nil)
  5479. (org-last-inserted-timestamp nil))
  5480. (org-deadline '(16)))
  5481. (buffer-string)))))
  5482. (should-error
  5483. (cl-letf (((symbol-function 'org-read-date)
  5484. (lambda (&rest args)
  5485. (org-time-string-to-time "2014-03-04"))))
  5486. (org-test-with-temp-text "* H"
  5487. (let ((org-adapt-indentation nil)
  5488. (org-last-inserted-timestamp nil))
  5489. (org-deadline '(16)))
  5490. (buffer-string))))
  5491. ;; When a region is active and
  5492. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5493. ;; same value in all headlines in region.
  5494. (should
  5495. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5496. (org-test-with-temp-text "* H1\n* H2"
  5497. (let ((org-adapt-indentation nil)
  5498. (org-last-inserted-timestamp nil)
  5499. (org-loop-over-headlines-in-active-region t))
  5500. (transient-mark-mode 1)
  5501. (push-mark (point) t t)
  5502. (goto-char (point-max))
  5503. (org-deadline nil "2012-03-29"))
  5504. (replace-regexp-in-string
  5505. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5506. (should-not
  5507. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5508. (org-test-with-temp-text "* H1\n* H2"
  5509. (let ((org-adapt-indentation nil)
  5510. (org-last-inserted-timestamp nil)
  5511. (org-loop-over-headlines-in-active-region nil))
  5512. (transient-mark-mode 1)
  5513. (push-mark (point) t t)
  5514. (goto-char (point-max))
  5515. (org-deadline nil "2012-03-29"))
  5516. (replace-regexp-in-string
  5517. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5518. (ert-deftest test-org/schedule ()
  5519. "Test `org-schedule' specifications."
  5520. ;; Insert a new value or replace existing one.
  5521. (should
  5522. (equal "* H\nSCHEDULED: <2012-03-29>"
  5523. (org-test-with-temp-text "* H"
  5524. (let ((org-adapt-indentation nil)
  5525. (org-last-inserted-timestamp nil))
  5526. (org-schedule nil "<2012-03-29 Tue>"))
  5527. (replace-regexp-in-string
  5528. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5529. nil nil 1))))
  5530. (should
  5531. (equal "* H\nSCHEDULED: <2014-03-04>"
  5532. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5533. (let ((org-adapt-indentation nil)
  5534. (org-last-inserted-timestamp nil))
  5535. (org-schedule nil "<2014-03-04 Thu>"))
  5536. (replace-regexp-in-string
  5537. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5538. nil nil 1))))
  5539. ;; Accept delta time, e.g., "+2d".
  5540. (should
  5541. (equal "* H\nSCHEDULED: <2015-03-04>"
  5542. (org-test-at-time "2014-03-04"
  5543. (org-test-with-temp-text "* H"
  5544. (let ((org-adapt-indentation nil)
  5545. (org-last-inserted-timestamp nil))
  5546. (org-schedule nil "+1y"))
  5547. (replace-regexp-in-string
  5548. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5549. ;; Preserve repeater.
  5550. (should
  5551. (equal "* H\nSCHEDULED: <2012-03-29 +2y>"
  5552. (org-test-with-temp-text "* H"
  5553. (let ((org-adapt-indentation nil)
  5554. (org-last-inserted-timestamp nil))
  5555. (org-schedule nil "<2012-03-29 Tue +2y>"))
  5556. (replace-regexp-in-string
  5557. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5558. ;; Remove CLOSED keyword, if any.
  5559. (should
  5560. (equal "* H\nSCHEDULED: <2012-03-29>"
  5561. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  5562. (let ((org-adapt-indentation nil)
  5563. (org-last-inserted-timestamp nil))
  5564. (org-schedule nil "<2012-03-29 Tue>"))
  5565. (replace-regexp-in-string
  5566. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5567. ;; With C-u argument, remove SCHEDULED keyword.
  5568. (should
  5569. (equal "* H\n"
  5570. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5571. (let ((org-adapt-indentation nil)
  5572. (org-last-inserted-timestamp nil))
  5573. (org-schedule '(4)))
  5574. (buffer-string))))
  5575. (should
  5576. (equal "* H"
  5577. (org-test-with-temp-text "* H"
  5578. (let ((org-adapt-indentation nil)
  5579. (org-last-inserted-timestamp nil))
  5580. (org-schedule '(4)))
  5581. (buffer-string))))
  5582. ;; With C-u C-u argument, prompt for a delay cookie.
  5583. (should
  5584. (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
  5585. (cl-letf (((symbol-function 'org-read-date)
  5586. (lambda (&rest args)
  5587. (org-time-string-to-time "2014-03-04"))))
  5588. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5589. (let ((org-adapt-indentation nil)
  5590. (org-last-inserted-timestamp nil))
  5591. (org-schedule '(16)))
  5592. (buffer-string)))))
  5593. (should-error
  5594. (cl-letf (((symbol-function 'org-read-date)
  5595. (lambda (&rest args)
  5596. (org-time-string-to-time "2014-03-04"))))
  5597. (org-test-with-temp-text "* H"
  5598. (let ((org-adapt-indentation nil)
  5599. (org-last-inserted-timestamp nil))
  5600. (org-schedule '(16)))
  5601. (buffer-string))))
  5602. ;; When a region is active and
  5603. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5604. ;; same value in all headlines in region.
  5605. (should
  5606. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5607. (org-test-with-temp-text "* H1\n* H2"
  5608. (let ((org-adapt-indentation nil)
  5609. (org-last-inserted-timestamp nil)
  5610. (org-loop-over-headlines-in-active-region t))
  5611. (transient-mark-mode 1)
  5612. (push-mark (point) t t)
  5613. (goto-char (point-max))
  5614. (org-schedule nil "2012-03-29"))
  5615. (replace-regexp-in-string
  5616. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5617. (should-not
  5618. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5619. (org-test-with-temp-text "* H1\n* H2"
  5620. (let ((org-adapt-indentation nil)
  5621. (org-last-inserted-timestamp nil)
  5622. (org-loop-over-headlines-in-active-region nil))
  5623. (transient-mark-mode 1)
  5624. (push-mark (point) t t)
  5625. (goto-char (point-max))
  5626. (org-schedule nil "2012-03-29"))
  5627. (replace-regexp-in-string
  5628. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5629. (should
  5630. ;; check if a repeater survives re-scheduling.
  5631. (string-match-p
  5632. "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
  5633. (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
  5634. (let ((org-adapt-indentation nil)
  5635. (org-last-inserted-timestamp nil))
  5636. (org-schedule nil "2017-02-01"))
  5637. (buffer-string)))))
  5638. ;;; Property API
  5639. (ert-deftest test-org/buffer-property-keys ()
  5640. "Test `org-buffer-property-keys' specifications."
  5641. ;; Retrieve properties across siblings.
  5642. (should
  5643. (equal '("A" "B")
  5644. (org-test-with-temp-text "
  5645. * H1
  5646. :PROPERTIES:
  5647. :A: 1
  5648. :END:
  5649. * H2
  5650. :PROPERTIES:
  5651. :B: 1
  5652. :END:"
  5653. (org-buffer-property-keys))))
  5654. ;; Retrieve properties across children.
  5655. (should
  5656. (equal '("A" "B")
  5657. (org-test-with-temp-text "
  5658. * H1
  5659. :PROPERTIES:
  5660. :A: 1
  5661. :END:
  5662. ** H2
  5663. :PROPERTIES:
  5664. :B: 1
  5665. :END:"
  5666. (org-buffer-property-keys))))
  5667. ;; Retrieve muliple properties in the same drawer.
  5668. (should
  5669. (equal '("A" "B")
  5670. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5671. (org-buffer-property-keys))))
  5672. ;; Ignore extension symbol in property name.
  5673. (should
  5674. (equal '("A")
  5675. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5676. (org-buffer-property-keys))))
  5677. ;; Add bare property if xxx_ALL property is there
  5678. (should
  5679. (equal '("A" "B" "B_ALL")
  5680. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B_ALL: foo bar\n:END:"
  5681. (org-buffer-property-keys))))
  5682. ;; Add bare property if xxx_ALL property is there - check dupes
  5683. (should
  5684. (equal '("A" "B" "B_ALL")
  5685. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:B_ALL: foo bar\n:END:"
  5686. (org-buffer-property-keys))))
  5687. ;; Retrieve properties from #+PROPERTY keyword lines
  5688. (should
  5689. (equal '("A" "C")
  5690. (org-test-with-temp-text "#+PROPERTY: C foo\n* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5691. (org-buffer-property-keys))))
  5692. ;; Retrieve properties from #+PROPERTY keyword lines - make sure an _ALL property also
  5693. ;; adds the bare property
  5694. (should
  5695. (equal '("A" "C" "C_ALL")
  5696. (org-test-with-temp-text "#+PROPERTY: C_ALL foo bar\n* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5697. (org-buffer-property-keys))))
  5698. ;; With non-nil COLUMNS, extract property names from columns.
  5699. (should
  5700. (equal '("A" "B")
  5701. (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
  5702. (org-buffer-property-keys nil nil t))))
  5703. (should
  5704. (equal '("A" "B" "COLUMNS")
  5705. (org-test-with-temp-text
  5706. "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
  5707. (org-buffer-property-keys nil nil t))))
  5708. ;; In COLUMNS, ignore title and summary-type.
  5709. (should
  5710. (equal '("A")
  5711. (org-test-with-temp-text "#+COLUMNS: %A(Foo)"
  5712. (org-buffer-property-keys nil nil t))))
  5713. (should
  5714. (equal '("A")
  5715. (org-test-with-temp-text "#+COLUMNS: %A{Foo}"
  5716. (org-buffer-property-keys nil nil t))))
  5717. (should
  5718. (equal '("A")
  5719. (org-test-with-temp-text "#+COLUMNS: %A(Foo){Bar}"
  5720. (org-buffer-property-keys nil nil t)))))
  5721. (ert-deftest test-org/property-values ()
  5722. "Test `org-property-values' specifications."
  5723. ;; Regular test.
  5724. (should
  5725. (equal '("2" "1")
  5726. (org-test-with-temp-text
  5727. "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
  5728. (org-property-values "A"))))
  5729. ;; Ignore empty values.
  5730. (should-not
  5731. (org-test-with-temp-text
  5732. "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
  5733. (org-property-values "A")))
  5734. ;; Take into consideration extended values.
  5735. (should
  5736. (equal '("1 2")
  5737. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5738. (org-property-values "A")))))
  5739. (ert-deftest test-org/set-property ()
  5740. "Test `org-set-property' specifications."
  5741. (should
  5742. (equal
  5743. ":PROPERTIES:\n:TEST: t\n:END:\n"
  5744. (org-test-with-temp-text ""
  5745. (let ((org-property-format "%s %s"))
  5746. (org-set-property "TEST" "t"))
  5747. (buffer-string))))
  5748. (should
  5749. (equal
  5750. "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5751. (org-test-with-temp-text "* H"
  5752. (let ((org-adapt-indentation nil)
  5753. (org-property-format "%s %s"))
  5754. (org-set-property "TEST" "t"))
  5755. (buffer-string)))))
  5756. (ert-deftest test-org/delete-property ()
  5757. "Test `org-delete-property' specifications."
  5758. (should
  5759. (equal
  5760. ""
  5761. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5762. (org-delete-property "TEST")
  5763. (buffer-string))))
  5764. (should
  5765. (equal
  5766. ":PROPERTIES:\n:TEST1: t\n:END:\n"
  5767. (org-test-with-temp-text ":PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5768. (org-delete-property "TEST2")
  5769. (buffer-string))))
  5770. (should
  5771. (equal
  5772. "* H\n"
  5773. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5774. (org-delete-property "TEST")
  5775. (buffer-string))))
  5776. (should
  5777. (equal
  5778. "* H\n:PROPERTIES:\n:TEST1: t\n:END:\n"
  5779. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5780. (org-delete-property "TEST2")
  5781. (buffer-string)))))
  5782. (ert-deftest test-org/delete-property-globally ()
  5783. "Test `org-delete-property-global' specifications."
  5784. (should
  5785. (equal
  5786. ""
  5787. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5788. (org-delete-property-globally "TEST")
  5789. (buffer-string))))
  5790. (should
  5791. (equal
  5792. "* H\n"
  5793. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n* H\n:PROPERTIES:\n:TEST: nil\n:END:"
  5794. (org-delete-property-globally "TEST")
  5795. (buffer-string)))))
  5796. (ert-deftest test-org/find-property ()
  5797. "Test `org-find-property' specifications."
  5798. ;; Regular test.
  5799. (should
  5800. (= 1
  5801. (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
  5802. (org-find-property "prop"))))
  5803. ;; Find properties in top-level property drawer.
  5804. (should
  5805. (= 1
  5806. (org-test-with-temp-text ":PROPERTIES:\n:PROP: value\n:END:"
  5807. (org-find-property "prop"))))
  5808. ;; Ignore false positives.
  5809. (should
  5810. (= 27
  5811. (org-test-with-temp-text
  5812. "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
  5813. (org-find-property "A"))))
  5814. ;; Return first entry found in buffer.
  5815. (should
  5816. (= 1
  5817. (org-test-with-temp-text
  5818. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5819. (org-find-property "A"))))
  5820. ;; Only search visible part of the buffer.
  5821. (should
  5822. (= 31
  5823. (org-test-with-temp-text
  5824. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5825. (org-narrow-to-subtree)
  5826. (org-find-property "A"))))
  5827. ;; With optional argument, only find entries with a specific value.
  5828. (should-not
  5829. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5830. (org-find-property "A" "2")))
  5831. (should
  5832. (= 31
  5833. (org-test-with-temp-text
  5834. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
  5835. (org-find-property "A" "2"))))
  5836. ;; Use "nil" for explicit nil values.
  5837. (should
  5838. (= 31
  5839. (org-test-with-temp-text
  5840. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
  5841. (org-find-property "A" "nil")))))
  5842. (ert-deftest test-org/entry-delete ()
  5843. "Test `org-entry-delete' specifications."
  5844. ;; Regular test.
  5845. (should
  5846. (string-match
  5847. " *:PROPERTIES:\n *:B: +2\n *:END:"
  5848. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5849. (org-entry-delete (point) "A")
  5850. (buffer-string))))
  5851. ;; Also remove accumulated properties.
  5852. (should-not
  5853. (string-match
  5854. ":A"
  5855. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
  5856. (org-entry-delete (point) "A")
  5857. (buffer-string))))
  5858. ;; When last property is removed, remove the property drawer.
  5859. (should-not
  5860. (string-match
  5861. ":PROPERTIES:"
  5862. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
  5863. (org-entry-delete (point) "A")
  5864. (buffer-string))))
  5865. ;; Return a non-nil value when some property was removed.
  5866. (should
  5867. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5868. (org-entry-delete (point) "A")))
  5869. (should-not
  5870. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5871. (org-entry-delete (point) "C")))
  5872. ;; Special properties cannot be located in a drawer. Allow to
  5873. ;; remove them anyway, in case of user error.
  5874. (should
  5875. (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
  5876. (org-entry-delete (point) "SCHEDULED"))))
  5877. (ert-deftest test-org/entry-get ()
  5878. "Test `org-entry-get' specifications."
  5879. ;; Regular test.
  5880. (should
  5881. (equal "1"
  5882. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:"
  5883. (org-entry-get (point) "A"))))
  5884. (should
  5885. (equal "1"
  5886. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5887. (org-entry-get (point) "A"))))
  5888. ;; Ignore case.
  5889. (should
  5890. (equal "1"
  5891. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5892. (org-entry-get (point) "a"))))
  5893. ;; Handle extended values, both before and after base value.
  5894. (should
  5895. (equal "1 2 3"
  5896. (org-test-with-temp-text
  5897. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5898. (org-entry-get (point) "A"))))
  5899. ;; Empty values are returned as the empty string.
  5900. (should
  5901. (equal ""
  5902. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
  5903. (org-entry-get (point) "A"))))
  5904. ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
  5905. ;; otherwise, return nil.
  5906. (should-not
  5907. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5908. (org-entry-get (point) "A")))
  5909. (should
  5910. (equal "nil"
  5911. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5912. (org-entry-get (point) "A" nil t))))
  5913. ;; Return nil when no property is found, independently on the
  5914. ;; LITERAL-NIL argument.
  5915. (should-not
  5916. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5917. (org-entry-get (point) "B")))
  5918. (should-not
  5919. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5920. (org-entry-get (point) "B" nil t)))
  5921. ;; Handle inheritance, when allowed. Include extended values and
  5922. ;; possibly global values.
  5923. (should
  5924. (equal
  5925. "1"
  5926. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:\n* H"
  5927. (org-entry-get (point-max) "A" t))))
  5928. (should
  5929. (equal
  5930. "1"
  5931. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5932. (org-entry-get (point-max) "A" t))))
  5933. (should
  5934. (equal
  5935. "1"
  5936. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5937. (let ((org-use-property-inheritance t))
  5938. (org-entry-get (point-max) "A" 'selective)))))
  5939. (should-not
  5940. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5941. (let ((org-use-property-inheritance nil))
  5942. (org-entry-get (point-max) "A" 'selective))))
  5943. (should-not
  5944. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H2"
  5945. (let ((org-use-property-inheritance t))
  5946. (org-entry-get (point-max) "A" t))))
  5947. (should
  5948. (equal
  5949. "1 2"
  5950. (org-test-with-temp-text
  5951. ":PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5952. (org-entry-get (point-max) "A" t))))
  5953. (should
  5954. (equal
  5955. "1 2"
  5956. (org-test-with-temp-text
  5957. "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5958. (org-entry-get (point-max) "A" t))))
  5959. (should
  5960. (equal
  5961. "1 2"
  5962. (org-test-with-temp-text
  5963. ":PROPERTIES:\n:A: 1\n:END:\n* H1\n* H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5964. (org-entry-get (point-max) "A" t))))
  5965. (should
  5966. (equal
  5967. "1 2"
  5968. (org-test-with-temp-text
  5969. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2.1\n** H2.2\n:PROPERTIES:\n:A+: 2\n:END:"
  5970. (org-entry-get (point-max) "A" t))))
  5971. (should
  5972. (equal "1"
  5973. (org-test-with-temp-text
  5974. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
  5975. (org-mode-restart)
  5976. (org-entry-get (point-max) "A" t))))
  5977. (should
  5978. (equal "0 1"
  5979. (org-test-with-temp-text
  5980. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
  5981. (org-mode-restart)
  5982. (org-entry-get (point-max) "A" t))))
  5983. ;; document level property-drawer has precedance over
  5984. ;; global-property by PROPERTY-keyword.
  5985. (should
  5986. (equal "0 2"
  5987. (org-test-with-temp-text
  5988. ":PROPERTIES:\n:A: 0\n:END:\n#+PROPERTY: A 1\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5989. (org-mode-restart)
  5990. (org-entry-get (point-max) "A" t))))
  5991. ;; Use alternate separators
  5992. (should
  5993. (equal "0~2"
  5994. (org-test-with-temp-text
  5995. ":PROPERTIES:\n:A: 0\n:A+: 2\n:END:"
  5996. (let ((org-property-separators '((("A") . "~"))))
  5997. (org-entry-get (point) "A")))))
  5998. ;; Default separator is single space
  5999. (should
  6000. (equal "0 2"
  6001. (org-test-with-temp-text
  6002. ":PROPERTIES:\n:A: 0\n:B: 1\n:A+: 2\n:B+: 3\n:END:"
  6003. (let ((org-property-separators '((("B") . "~"))))
  6004. (org-entry-get (point) "A")))))
  6005. ;; Regular expression matching for separator
  6006. (should
  6007. (equal "0/2"
  6008. (org-test-with-temp-text
  6009. ":PROPERTIES:\n:A: 0\n:A+: 2\n:END:"
  6010. (let ((org-property-separators '((("B") . "~") ("[AC]" . "/"))))
  6011. (org-entry-get (point) "A")))))
  6012. ;; Separator works with inheritance
  6013. (should
  6014. (equal "1~2"
  6015. (org-test-with-temp-text
  6016. "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
  6017. (let ((org-property-separators '((("A") . "~"))))
  6018. (org-entry-get (point-max) "A" t))))))
  6019. (ert-deftest test-org/entry-properties ()
  6020. "Test `org-entry-properties' specifications."
  6021. ;; Get "ITEM" property.
  6022. (should
  6023. (equal "H"
  6024. (org-test-with-temp-text "* TODO H"
  6025. (cdr (assoc "ITEM" (org-entry-properties nil "ITEM"))))))
  6026. (should
  6027. (equal "H"
  6028. (org-test-with-temp-text "* TODO H"
  6029. (cdr (assoc "ITEM" (org-entry-properties))))))
  6030. ;; Get "TODO" property. TODO keywords are case sensitive.
  6031. (should
  6032. (equal "TODO"
  6033. (org-test-with-temp-text "* TODO H"
  6034. (cdr (assoc "TODO" (org-entry-properties nil "TODO"))))))
  6035. (should
  6036. (equal "TODO"
  6037. (org-test-with-temp-text "* TODO H"
  6038. (cdr (assoc "TODO" (org-entry-properties))))))
  6039. (should-not
  6040. (org-test-with-temp-text "* H"
  6041. (assoc "TODO" (org-entry-properties nil "TODO"))))
  6042. (should-not
  6043. (org-test-with-temp-text "* todo H"
  6044. (assoc "TODO" (org-entry-properties nil "TODO"))))
  6045. ;; Get "PRIORITY" property.
  6046. (should
  6047. (equal "A"
  6048. (org-test-with-temp-text "* [#A] H"
  6049. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  6050. (should
  6051. (equal "A"
  6052. (org-test-with-temp-text "* [#A] H"
  6053. (cdr (assoc "PRIORITY" (org-entry-properties))))))
  6054. (should
  6055. (equal (char-to-string org-priority-default)
  6056. (org-test-with-temp-text "* H"
  6057. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  6058. ;; Get "FILE" property.
  6059. (should
  6060. (org-test-with-temp-text-in-file "* H\nParagraph"
  6061. (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil "FILE")))
  6062. (buffer-file-name))))
  6063. (should
  6064. (org-test-with-temp-text-in-file "* H\nParagraph"
  6065. (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
  6066. (buffer-file-name))))
  6067. (should-not
  6068. (org-test-with-temp-text "* H\nParagraph"
  6069. (cdr (assoc "FILE" (org-entry-properties nil "FILE")))))
  6070. ;; Get "TAGS" property.
  6071. (should
  6072. (equal ":tag1:tag2:"
  6073. (org-test-with-temp-text "* H :tag1:tag2:"
  6074. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS"))))))
  6075. (should
  6076. (equal ":tag1:tag2:"
  6077. (org-test-with-temp-text "* H :tag1:tag2:"
  6078. (cdr (assoc "TAGS" (org-entry-properties))))))
  6079. (should-not
  6080. (org-test-with-temp-text "* H"
  6081. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS")))))
  6082. ;; Get "ALLTAGS" property.
  6083. (should
  6084. (equal ":tag1:tag2:"
  6085. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  6086. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS"))))))
  6087. (should
  6088. (equal ":tag1:tag2:"
  6089. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  6090. (cdr (assoc "ALLTAGS" (org-entry-properties))))))
  6091. (should-not
  6092. (org-test-with-temp-text "* H"
  6093. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS")))))
  6094. ;; Get "BLOCKED" property.
  6095. (should
  6096. (equal "t"
  6097. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  6098. (let ((org-enforce-todo-dependencies t)
  6099. (org-blocker-hook
  6100. '(org-block-todo-from-children-or-siblings-or-parent)))
  6101. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  6102. (should
  6103. (equal ""
  6104. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  6105. (let ((org-enforce-todo-dependencies t)
  6106. (org-blocker-hook
  6107. '(org-block-todo-from-children-or-siblings-or-parent)))
  6108. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  6109. ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
  6110. (should
  6111. (equal
  6112. "[2012-03-29 thu.]"
  6113. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  6114. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED"))))))
  6115. (should
  6116. (equal
  6117. "[2012-03-29 thu.]"
  6118. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  6119. (cdr (assoc "CLOSED" (org-entry-properties))))))
  6120. (should-not
  6121. (org-test-with-temp-text "* H"
  6122. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED")))))
  6123. (should
  6124. (equal
  6125. "<2014-03-04 tue.>"
  6126. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6127. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE"))))))
  6128. (should
  6129. (equal
  6130. "<2014-03-04 tue.>"
  6131. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6132. (cdr (assoc "DEADLINE" (org-entry-properties))))))
  6133. (should-not
  6134. (org-test-with-temp-text "* H"
  6135. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE")))))
  6136. (should
  6137. (equal
  6138. "<2014-03-04 tue.>"
  6139. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6140. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED"))))))
  6141. (should
  6142. (equal
  6143. "<2014-03-04 tue.>"
  6144. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6145. (cdr (assoc "SCHEDULED" (org-entry-properties))))))
  6146. (should-not
  6147. (org-test-with-temp-text "* H"
  6148. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED")))))
  6149. ;; Get "CATEGORY"
  6150. (should
  6151. (equal "cat"
  6152. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  6153. (cdr (assoc "CATEGORY" (org-entry-properties))))))
  6154. (should
  6155. (equal "cat"
  6156. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  6157. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  6158. (should
  6159. (equal "cat"
  6160. (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
  6161. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  6162. (should
  6163. (equal "cat2"
  6164. (org-test-with-temp-text
  6165. (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6166. "\n"
  6167. "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
  6168. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  6169. ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
  6170. (should
  6171. (equal "<2012-03-29 thu.>"
  6172. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
  6173. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  6174. (should
  6175. (equal "[2012-03-29 thu.]"
  6176. (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
  6177. (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
  6178. (should
  6179. (equal "<2012-03-29 thu.>"
  6180. (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
  6181. (cdr (assoc "TIMESTAMP" (org-entry-properties nil "TIMESTAMP"))))))
  6182. (should
  6183. (equal "[2014-03-04 tue.]"
  6184. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
  6185. (cdr (assoc "TIMESTAMP_IA"
  6186. (org-entry-properties nil "TIMESTAMP_IA"))))))
  6187. (should-not
  6188. (equal "<2012-03-29 thu.>"
  6189. (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
  6190. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  6191. ;; Get standard properties.
  6192. (should
  6193. (equal "1"
  6194. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6195. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  6196. ;; Handle extended properties.
  6197. (should
  6198. (equal "1 2 3"
  6199. (org-test-with-temp-text
  6200. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  6201. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  6202. (should
  6203. (equal "1 2 3"
  6204. (org-test-with-temp-text
  6205. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
  6206. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  6207. ;; Ignore forbidden (special) properties.
  6208. (should-not
  6209. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
  6210. (cdr (assoc "TODO" (org-entry-properties nil 'standard))))))
  6211. (ert-deftest test-org/entry-put ()
  6212. "Test `org-entry-put' specifications."
  6213. ;; Error when not a string or nil.
  6214. (should-error
  6215. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  6216. (org-entry-put 1 "test" 2)))
  6217. ;; Error when property name is invalid.
  6218. (should-error
  6219. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  6220. (org-entry-put 1 "no space" "value")))
  6221. (should-error
  6222. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  6223. (org-entry-put 1 "" "value")))
  6224. ;; Set "TODO" property.
  6225. (should
  6226. (string-match (regexp-quote " TODO H")
  6227. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  6228. (org-entry-put (point) "TODO" "TODO")
  6229. (buffer-string))))
  6230. (should
  6231. (string-match (regexp-quote "* H")
  6232. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  6233. (org-entry-put (point) "TODO" nil)
  6234. (buffer-string))))
  6235. ;; Set "PRIORITY" property.
  6236. (should
  6237. (equal "* [#A] H"
  6238. (org-test-with-temp-text "* [#B] H"
  6239. (org-entry-put (point) "PRIORITY" "A")
  6240. (buffer-string))))
  6241. (should
  6242. (equal "* H"
  6243. (org-test-with-temp-text "* [#B] H"
  6244. (org-entry-put (point) "PRIORITY" nil)
  6245. (buffer-string))))
  6246. ;; Set "SCHEDULED" property.
  6247. (should
  6248. (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
  6249. (org-test-with-temp-text "* H"
  6250. (org-entry-put (point) "SCHEDULED" "2014-03-04")
  6251. (buffer-string))))
  6252. (should
  6253. (string= "* H\n"
  6254. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6255. (org-entry-put (point) "SCHEDULED" nil)
  6256. (buffer-string))))
  6257. (should
  6258. (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
  6259. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6260. (org-entry-put (point) "SCHEDULED" "earlier")
  6261. (buffer-string))))
  6262. (should
  6263. (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
  6264. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6265. (org-entry-put (point) "SCHEDULED" "later")
  6266. (buffer-string))))
  6267. ;; Set "DEADLINE" property.
  6268. (should
  6269. (string-match "^ *DEADLINE: <2014-03-04 .*?>"
  6270. (org-test-with-temp-text "* H"
  6271. (org-entry-put (point) "DEADLINE" "2014-03-04")
  6272. (buffer-string))))
  6273. (should
  6274. (string= "* H\n"
  6275. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6276. (org-entry-put (point) "DEADLINE" nil)
  6277. (buffer-string))))
  6278. (should
  6279. (string-match "^ *DEADLINE: <2014-03-03 .*?>"
  6280. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6281. (org-entry-put (point) "DEADLINE" "earlier")
  6282. (buffer-string))))
  6283. (should
  6284. (string-match "^ *DEADLINE: <2014-03-05 .*?>"
  6285. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6286. (org-entry-put (point) "DEADLINE" "later")
  6287. (buffer-string))))
  6288. ;; Set "CATEGORY" property
  6289. (should
  6290. (string-match "^ *:CATEGORY: cat"
  6291. (org-test-with-temp-text "* H"
  6292. (org-entry-put (point) "CATEGORY" "cat")
  6293. (buffer-string))))
  6294. ;; Regular properties, with or without pre-existing drawer.
  6295. (should
  6296. (string-match "^ *:A: +2$"
  6297. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6298. (org-entry-put (point) "A" "2")
  6299. (buffer-string))))
  6300. (should
  6301. (string-match "^ *:A: +1$"
  6302. (org-test-with-temp-text "* H"
  6303. (org-entry-put (point) "A" "1")
  6304. (buffer-string))))
  6305. ;; Special case: two consecutive headlines.
  6306. (should
  6307. (string-match "\\* A\n *:PROPERTIES:"
  6308. (org-test-with-temp-text "* A\n** B"
  6309. (org-entry-put (point) "A" "1")
  6310. (buffer-string)))))
  6311. (ert-deftest test-org/refresh-properties ()
  6312. "Test `org-refresh-properties' specifications."
  6313. (should
  6314. (equal "1"
  6315. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6316. (org-refresh-properties "A" 'org-test)
  6317. (get-text-property (point) 'org-test))))
  6318. (should-not
  6319. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6320. (org-refresh-properties "B" 'org-test)
  6321. (get-text-property (point) 'org-test)))
  6322. ;; Handle properties only defined with extension syntax, i.e.,
  6323. ;; "PROPERTY+".
  6324. (should
  6325. (equal "1"
  6326. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
  6327. (org-refresh-properties "A" 'org-test)
  6328. (get-text-property (point) 'org-test))))
  6329. ;; When property is inherited, add text property to the whole
  6330. ;; sub-tree.
  6331. (should
  6332. (equal "1"
  6333. (org-test-with-temp-text
  6334. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
  6335. (let ((org-use-property-inheritance t))
  6336. (org-refresh-properties "A" 'org-test))
  6337. (get-text-property (point) 'org-test))))
  6338. ;; When a document level property-drawer is used, those properties
  6339. ;; should work exactly like headline-properties as if at a
  6340. ;; headline-level 0.
  6341. (should
  6342. (equal "1"
  6343. (org-test-with-temp-text
  6344. ":PROPERTIES:\n:A: 1\n:END:\n"
  6345. (org-mode-restart)
  6346. (let ((org-use-property-inheritance t))
  6347. (org-refresh-properties "A" 'org-test))
  6348. (get-text-property (point) 'org-test))))
  6349. (should-not
  6350. (equal "1"
  6351. (org-test-with-temp-text
  6352. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  6353. (org-mode-restart)
  6354. (let ((org-use-property-inheritance nil))
  6355. (org-refresh-properties "A" 'org-test))
  6356. (get-text-property (point) 'org-test))))
  6357. (should
  6358. (equal "1"
  6359. (org-test-with-temp-text
  6360. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  6361. (org-mode-restart)
  6362. (let ((org-use-property-inheritance t))
  6363. (org-refresh-properties "A" 'org-test))
  6364. (get-text-property (point) 'org-test))))
  6365. (should
  6366. (equal "2"
  6367. (org-test-with-temp-text
  6368. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1\n:PROPERTIES:\n:A: 2\n:END:"
  6369. (org-mode-restart)
  6370. (let ((org-use-property-inheritance t))
  6371. (org-refresh-properties "A" 'org-test))
  6372. (get-text-property (point) 'org-test))))
  6373. ;; When property is inherited, use global value across the whole
  6374. ;; buffer. However local values have precedence, as well as the
  6375. ;; document level property-drawer.
  6376. (should-not
  6377. (equal "1"
  6378. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  6379. (org-mode-restart)
  6380. (let ((org-use-property-inheritance nil))
  6381. (org-refresh-properties "A" 'org-test))
  6382. (get-text-property (point) 'org-test))))
  6383. (should
  6384. (equal "1"
  6385. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  6386. (org-mode-restart)
  6387. (let ((org-use-property-inheritance t))
  6388. (org-refresh-properties "A" 'org-test))
  6389. (get-text-property (point) 'org-test))))
  6390. (should
  6391. (equal "2"
  6392. (org-test-with-temp-text
  6393. "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
  6394. (org-mode-restart)
  6395. (let ((org-use-property-inheritance t))
  6396. (org-refresh-properties "A" 'org-test))
  6397. (get-text-property (point) 'org-test))))
  6398. ;; When both keyword-property and document-level property-block is
  6399. ;; defined, the property-block has precedance.
  6400. (should
  6401. (equal "1"
  6402. (org-test-with-temp-text
  6403. ":PROPERTIES:\n:A: 1\n:END:\n#+PROPERTY: A 2\n<point>* H1"
  6404. (org-mode-restart)
  6405. (let ((org-use-property-inheritance t))
  6406. (org-refresh-properties "A" 'org-test))
  6407. (get-text-property (point) 'org-test)))))
  6408. (ert-deftest test-org/refresh-category-properties ()
  6409. "Test `org-refresh-category-properties' specifications"
  6410. (should
  6411. (equal "cat1"
  6412. (org-test-with-temp-text
  6413. ":PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6414. (org-refresh-category-properties)
  6415. (org-get-category))))
  6416. (should
  6417. (equal "cat1"
  6418. (org-test-with-temp-text
  6419. "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6420. (org-refresh-category-properties)
  6421. (org-get-category))))
  6422. ;; Even though property-inheritance is deactivated, category
  6423. ;; property should be inherited. As described in
  6424. ;; `org-use-property-inheritance'.
  6425. (should
  6426. (equal "cat1"
  6427. (org-test-with-temp-text
  6428. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  6429. (org-mode-restart)
  6430. (let ((org-use-property-inheritance nil))
  6431. (org-refresh-category-properties))
  6432. (org-get-category))))
  6433. (should
  6434. (equal "cat1"
  6435. (org-test-with-temp-text
  6436. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  6437. (org-mode-restart)
  6438. (let ((org-use-property-inheritance t))
  6439. (org-refresh-category-properties))
  6440. (org-get-category))))
  6441. (should
  6442. (equal "cat2"
  6443. (org-test-with-temp-text
  6444. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H\n:PROPERTIES:\n:CATEGORY: cat2\n:END:\n"
  6445. (org-mode-restart)
  6446. (let ((org-use-property-inheritance t))
  6447. (org-refresh-category-properties))
  6448. (org-get-category)))))
  6449. ;;; Refile
  6450. (ert-deftest test-org/refile-get-targets ()
  6451. "Test `org-refile-get-targets' specifications."
  6452. ;; :maxlevel includes all headings above specified value.
  6453. (should
  6454. (equal '("H1" "H2" "H3")
  6455. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6456. (let ((org-refile-use-outline-path nil)
  6457. (org-refile-targets `((nil :maxlevel . 3))))
  6458. (mapcar #'car (org-refile-get-targets))))))
  6459. (should
  6460. (equal '("H1" "H2")
  6461. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6462. (let ((org-refile-use-outline-path nil)
  6463. (org-refile-targets `((nil :maxlevel . 2))))
  6464. (mapcar #'car (org-refile-get-targets))))))
  6465. ;; :level limits targets to headlines with the specified level.
  6466. (should
  6467. (equal '("H2")
  6468. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6469. (let ((org-refile-use-outline-path nil)
  6470. (org-refile-targets `((nil :level . 2))))
  6471. (mapcar #'car (org-refile-get-targets))))))
  6472. ;; :tag limits targets to headlines with specified tag.
  6473. (should
  6474. (equal '("H1")
  6475. (org-test-with-temp-text "* H1 :foo:\n** H2\n*** H3 :bar:"
  6476. (let ((org-refile-use-outline-path nil)
  6477. (org-refile-targets `((nil :tag . "foo"))))
  6478. (mapcar #'car (org-refile-get-targets))))))
  6479. ;; :todo limits targets to headlines with specified TODO keyword.
  6480. (should
  6481. (equal '("H2")
  6482. (org-test-with-temp-text "* H1\n** TODO H2\n*** DONE H3"
  6483. (let ((org-refile-use-outline-path nil)
  6484. (org-refile-targets `((nil :todo . "TODO"))))
  6485. (mapcar #'car (org-refile-get-targets))))))
  6486. ;; :regexp filters targets matching provided regexp.
  6487. (should
  6488. (equal '("F2" "F3")
  6489. (org-test-with-temp-text "* H1\n** F2\n*** F3"
  6490. (let ((org-refile-use-outline-path nil)
  6491. (org-refile-targets `((nil :regexp . "F"))))
  6492. (mapcar #'car (org-refile-get-targets))))))
  6493. ;; A nil `org-refile-targets' includes only top level headlines in
  6494. ;; current buffer.
  6495. (should
  6496. (equal '("H1" "H2")
  6497. (org-test-with-temp-text "* H1\n** S1\n* H2"
  6498. (let ((org-refile-use-outline-path nil)
  6499. (org-refile-targets nil))
  6500. (mapcar #'car (org-refile-get-targets))))))
  6501. ;; Return value is the union of the targets according to all the
  6502. ;; defined rules. However, prevent duplicates.
  6503. (should
  6504. (equal '("F2" "F3" "H1")
  6505. (org-test-with-temp-text "* TODO H1\n** F2\n*** F3"
  6506. (let ((org-refile-use-outline-path nil)
  6507. (org-refile-targets `((nil :regexp . "F")
  6508. (nil :todo . "TODO"))))
  6509. (mapcar #'car (org-refile-get-targets))))))
  6510. (should
  6511. (equal '("F2" "F3" "H1")
  6512. (org-test-with-temp-text "* TODO H1\n** TODO F2\n*** F3"
  6513. (let ((org-refile-use-outline-path nil)
  6514. (org-refile-targets `((nil :regexp . "F")
  6515. (nil :todo . "TODO"))))
  6516. (mapcar #'car (org-refile-get-targets))))))
  6517. ;; When `org-refile-use-outline-path' is non-nil, provide targets as
  6518. ;; paths.
  6519. (should
  6520. (equal '("H1" "H1/H2" "H1/H2/H3")
  6521. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6522. (let ((org-refile-use-outline-path t)
  6523. (org-refile-targets `((nil :maxlevel . 3))))
  6524. (mapcar #'car (org-refile-get-targets))))))
  6525. ;; When providing targets as paths, escape forward slashes in
  6526. ;; headings with backslashes.
  6527. (should
  6528. (equal '("H1\\/foo")
  6529. (org-test-with-temp-text "* H1/foo"
  6530. (let ((org-refile-use-outline-path t)
  6531. (org-refile-targets `((nil :maxlevel . 1))))
  6532. (mapcar #'car (org-refile-get-targets))))))
  6533. ;; When `org-refile-use-outline-path' is `file', include file name
  6534. ;; without directory in targets.
  6535. (should
  6536. (org-test-with-temp-text-in-file "* H1"
  6537. (let* ((filename (buffer-file-name))
  6538. (org-refile-use-outline-path 'file)
  6539. (org-refile-targets `(((,filename) :level . 1))))
  6540. (member (file-name-nondirectory filename)
  6541. (mapcar #'car (org-refile-get-targets))))))
  6542. ;; When `org-refile-use-outline-path' is `full-file-path', include
  6543. ;; full file name.
  6544. (should
  6545. (org-test-with-temp-text-in-file "* H1"
  6546. (let* ((filename (file-truename (buffer-file-name)))
  6547. (org-refile-use-outline-path 'full-file-path)
  6548. (org-refile-targets `(((,filename) :level . 1))))
  6549. (member filename (mapcar #'car (org-refile-get-targets))))))
  6550. ;; When `org-refile-use-outline-path' is `buffer-name', include
  6551. ;; buffer name.
  6552. (should
  6553. (org-test-with-temp-text "* H1"
  6554. (let* ((org-refile-use-outline-path 'buffer-name)
  6555. (org-refile-targets `((nil :level . 1))))
  6556. (member (buffer-name) (mapcar #'car (org-refile-get-targets)))))))
  6557. ;;; Sparse trees
  6558. (ert-deftest test-org/match-sparse-tree ()
  6559. "Test `org-match-sparse-tree' specifications."
  6560. ;; Match tags.
  6561. (should-not
  6562. (org-test-with-temp-text "* H\n** H1 :tag:"
  6563. (org-match-sparse-tree nil "tag")
  6564. (search-forward "H1")
  6565. (org-invisible-p2)))
  6566. (should
  6567. (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
  6568. (org-match-sparse-tree nil "tag")
  6569. (search-forward "H2")
  6570. (org-invisible-p2)))
  6571. ;; "-" operator for tags.
  6572. (should-not
  6573. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6574. (org-match-sparse-tree nil "tag1-tag2")
  6575. (search-forward "H1")
  6576. (org-invisible-p2)))
  6577. (should
  6578. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6579. (org-match-sparse-tree nil "tag1-tag2")
  6580. (search-forward "H2")
  6581. (org-invisible-p2)))
  6582. ;; "&" operator for tags.
  6583. (should
  6584. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6585. (org-match-sparse-tree nil "tag1&tag2")
  6586. (search-forward "H1")
  6587. (org-invisible-p2)))
  6588. (should-not
  6589. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6590. (org-match-sparse-tree nil "tag1&tag2")
  6591. (search-forward "H2")
  6592. (org-invisible-p2)))
  6593. ;; "|" operator for tags.
  6594. (should-not
  6595. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6596. (org-match-sparse-tree nil "tag1|tag2")
  6597. (search-forward "H1")
  6598. (org-invisible-p2)))
  6599. (should-not
  6600. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6601. (org-match-sparse-tree nil "tag1|tag2")
  6602. (search-forward "H2")
  6603. (org-invisible-p2)))
  6604. ;; Regexp match on tags.
  6605. (should-not
  6606. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6607. (org-match-sparse-tree nil "{^tag.*}")
  6608. (search-forward "H1")
  6609. (org-invisible-p2)))
  6610. (should
  6611. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6612. (org-match-sparse-tree nil "{^tag.*}")
  6613. (search-forward "H2")
  6614. (org-invisible-p2)))
  6615. ;; Match group tags.
  6616. (should-not
  6617. (org-test-with-temp-text
  6618. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6619. (org-match-sparse-tree nil "work")
  6620. (search-forward "H1")
  6621. (org-invisible-p2)))
  6622. (should-not
  6623. (org-test-with-temp-text
  6624. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6625. (org-match-sparse-tree nil "work")
  6626. (search-forward "H2")
  6627. (org-invisible-p2)))
  6628. ;; Match group tags with hard brackets.
  6629. (should-not
  6630. (org-test-with-temp-text
  6631. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6632. (org-match-sparse-tree nil "work")
  6633. (search-forward "H1")
  6634. (org-invisible-p2)))
  6635. (should-not
  6636. (org-test-with-temp-text
  6637. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6638. (org-match-sparse-tree nil "work")
  6639. (search-forward "H2")
  6640. (org-invisible-p2)))
  6641. ;; Match tags in hierarchies
  6642. (should-not
  6643. (org-test-with-temp-text
  6644. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6645. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6646. #+TAGS: { Lev_3 : Lev_4 }\n
  6647. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6648. (org-match-sparse-tree nil "Lev_1")
  6649. (search-forward "H4")
  6650. (org-invisible-p2)))
  6651. (should-not
  6652. (org-test-with-temp-text
  6653. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6654. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6655. #+TAGS: { Lev_3 : Lev_4 }\n
  6656. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6657. (org-match-sparse-tree nil "Lev_1+Lev_3")
  6658. (search-forward "H4")
  6659. (org-invisible-p2)))
  6660. ;; Match regular expressions in tags
  6661. (should-not
  6662. (org-test-with-temp-text
  6663. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
  6664. (org-match-sparse-tree nil "Lev")
  6665. (search-forward "H1")
  6666. (org-invisible-p2)))
  6667. (should
  6668. (org-test-with-temp-text
  6669. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
  6670. (org-match-sparse-tree nil "Lev")
  6671. (search-forward "H1")
  6672. (org-invisible-p2)))
  6673. ;; Match properties.
  6674. (should
  6675. (org-test-with-temp-text
  6676. "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
  6677. (org-match-sparse-tree nil "A=\"1\"")
  6678. (search-forward "H2")
  6679. (org-invisible-p2)))
  6680. (should-not
  6681. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6682. (org-match-sparse-tree nil "A=\"1\"")
  6683. (search-forward "H2")
  6684. (org-invisible-p2)))
  6685. ;; Case is not significant when matching properties.
  6686. (should-not
  6687. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6688. (org-match-sparse-tree nil "a=\"1\"")
  6689. (search-forward "H2")
  6690. (org-invisible-p2)))
  6691. (should-not
  6692. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
  6693. (org-match-sparse-tree nil "A=\"1\"")
  6694. (search-forward "H2")
  6695. (org-invisible-p2)))
  6696. ;; Match special LEVEL property.
  6697. (should-not
  6698. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6699. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6700. (search-forward "H1")
  6701. (org-invisible-p2)))
  6702. (should
  6703. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6704. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6705. (search-forward "H2")
  6706. (org-invisible-p2)))
  6707. ;; Comparison operators when matching properties.
  6708. (should
  6709. (org-test-with-temp-text
  6710. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6711. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6712. (search-forward "H1")
  6713. (org-invisible-p2)))
  6714. (should-not
  6715. (org-test-with-temp-text
  6716. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6717. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6718. (search-forward "H2")
  6719. (org-invisible-p2)))
  6720. ;; Regexp match on properties values.
  6721. (should-not
  6722. (org-test-with-temp-text
  6723. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6724. (org-match-sparse-tree nil "A={f.*}")
  6725. (search-forward "H1")
  6726. (org-invisible-p2)))
  6727. (should
  6728. (org-test-with-temp-text
  6729. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6730. (org-match-sparse-tree nil "A={f.*}")
  6731. (search-forward "H2")
  6732. (org-invisible-p2)))
  6733. ;; With an optional argument, limit match to TODO entries.
  6734. (should-not
  6735. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6736. (org-match-sparse-tree t "tag")
  6737. (search-forward "H1")
  6738. (org-invisible-p2)))
  6739. (should
  6740. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6741. (org-match-sparse-tree t "tag")
  6742. (search-forward "H2")
  6743. (org-invisible-p2))))
  6744. (ert-deftest test-org/occur ()
  6745. "Test `org-occur' specifications."
  6746. ;; Count number of matches.
  6747. (should
  6748. (= 1
  6749. (org-test-with-temp-text "* H\nA\n* H2"
  6750. (org-occur "A"))))
  6751. (should
  6752. (= 2
  6753. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6754. (org-occur "A"))))
  6755. ;; Test CALLBACK optional argument.
  6756. (should
  6757. (= 0
  6758. (org-test-with-temp-text "* H\nA\n* H2"
  6759. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6760. (should
  6761. (= 1
  6762. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6763. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6764. ;; Case-fold searches according to `org-occur-case-fold-search'.
  6765. (should
  6766. (= 2
  6767. (org-test-with-temp-text "Aa"
  6768. (let ((org-occur-case-fold-search t)) (org-occur "A")))))
  6769. (should
  6770. (= 2
  6771. (org-test-with-temp-text "Aa"
  6772. (let ((org-occur-case-fold-search t)) (org-occur "a")))))
  6773. (should
  6774. (= 1
  6775. (org-test-with-temp-text "Aa"
  6776. (let ((org-occur-case-fold-search nil)) (org-occur "A")))))
  6777. (should
  6778. (= 1
  6779. (org-test-with-temp-text "Aa"
  6780. (let ((org-occur-case-fold-search nil)) (org-occur "a")))))
  6781. (should
  6782. (= 1
  6783. (org-test-with-temp-text "Aa"
  6784. (let ((org-occur-case-fold-search 'smart)) (org-occur "A")))))
  6785. (should
  6786. (= 2
  6787. (org-test-with-temp-text "Aa"
  6788. (let ((org-occur-case-fold-search 'smart)) (org-occur "a"))))))
  6789. ;;; Tags
  6790. (ert-deftest test-org/tag-string-to-alist ()
  6791. "Test `org-tag-string-to-alist' specifications."
  6792. ;; Tag without selection key.
  6793. (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
  6794. ;; Tag with selection key.
  6795. (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t))))
  6796. ;; Tag group.
  6797. (should
  6798. (equal
  6799. (org-tag-string-to-alist "[ group : t1 t2 ]")
  6800. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag))))
  6801. ;; Mutually exclusive tags.
  6802. (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
  6803. '((:startgroup) ("tag1") ("tag2") (:endgroup))))
  6804. (should
  6805. (equal
  6806. (org-tag-string-to-alist "{ group : tag1 tag2 }")
  6807. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))))
  6808. (ert-deftest test-org/tag-alist-to-string ()
  6809. "Test `org-tag-alist-to-string' specifications."
  6810. (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
  6811. (should (equal (org-tag-alist-to-string '(("tag1" . ?t))) "tag1(t)"))
  6812. (should
  6813. (equal
  6814. (org-tag-alist-to-string
  6815. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6816. "[ group : t1 t2 ]"))
  6817. (should
  6818. (equal (org-tag-alist-to-string
  6819. '((:startgroup) ("tag1") ("tag2") (:endgroup)))
  6820. "{ tag1 tag2 }"))
  6821. (should
  6822. (equal
  6823. (org-tag-alist-to-string
  6824. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))
  6825. "{ group : tag1 tag2 }")))
  6826. (ert-deftest test-org/tag-alist-to-groups ()
  6827. "Test `org-tag-alist-to-groups' specifications."
  6828. (should
  6829. (equal (org-tag-alist-to-groups
  6830. '((:startgroup) ("group") (:grouptags) ("t1") ("t2") (:endgroup)))
  6831. '(("group" "t1" "t2"))))
  6832. (should
  6833. (equal
  6834. (org-tag-alist-to-groups
  6835. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6836. '(("group" "t1" "t2"))))
  6837. (should-not
  6838. (org-tag-alist-to-groups
  6839. '((:startgroup) ("group") ("t1") ("t2") (:endgroup)))))
  6840. (ert-deftest test-org/tag-align ()
  6841. "Test tags alignment."
  6842. ;; Test aligning tags with different display width.
  6843. (should
  6844. ;; 12345678901234567890
  6845. (equal "* Test :abc:"
  6846. (org-test-with-temp-text "* Test :abc:"
  6847. (let ((org-tags-column -20)
  6848. (indent-tabs-mode nil))
  6849. (org-fix-tags-on-the-fly))
  6850. (buffer-string))))
  6851. (should
  6852. ;; 12345678901234567890
  6853. (equal "* Test :日本語:"
  6854. (org-test-with-temp-text "* Test :日本語:"
  6855. (let ((org-tags-column -20)
  6856. (indent-tabs-mode nil))
  6857. (org-fix-tags-on-the-fly))
  6858. (buffer-string))))
  6859. ;; Make sure aligning tags do not skip invisible text.
  6860. (should
  6861. (equal "* [[linkx]] :tag:"
  6862. (org-test-with-temp-text "* [[link<point>]] :tag:"
  6863. (let ((org-tags-column 0))
  6864. (org-fix-tags-on-the-fly)
  6865. (insert "x")
  6866. (buffer-string)))))
  6867. ;; Aligning tags preserve position.
  6868. (should
  6869. (= 6 (org-test-with-temp-text "* 345 <point> :tag:"
  6870. (let ((org-tags-column 78)
  6871. (indent-tabs-mode nil))
  6872. (org-fix-tags-on-the-fly))
  6873. (current-column))))
  6874. ;; Aligning all tags in visible buffer.
  6875. (should
  6876. ;; 12345678901234567890
  6877. (equal (concat "* Level 1 :abc:\n"
  6878. "** Level 2 :def:")
  6879. (org-test-with-temp-text (concat "* Level 1 :abc:\n"
  6880. "** Level 2 :def:")
  6881. (let ((org-tags-column -20)
  6882. (indent-tabs-mode nil))
  6883. ;; (org-align-tags :all) must work even when the point
  6884. ;; is at the end of the buffer.
  6885. (goto-char (point-max))
  6886. (org-align-tags :all))
  6887. (buffer-string)))))
  6888. (ert-deftest test-org/get-tags ()
  6889. "Test `org-get-tags' specifications."
  6890. ;; Standard test.
  6891. (should
  6892. (equal '("foo")
  6893. (org-test-with-temp-text "* Test :foo:" (org-get-tags))))
  6894. (should
  6895. (equal '("foo" "bar")
  6896. (org-test-with-temp-text "* Test :foo:bar:" (org-get-tags))))
  6897. ;; Tags for inlinetasks.
  6898. (should
  6899. (equal '("foo" "bar")
  6900. (progn
  6901. (require 'org-inlinetask)
  6902. (org-test-with-temp-text (concat (make-string org-inlinetask-min-level ?*) " Test :foo:bar:")
  6903. (org-get-tags (org-element-at-point))))))
  6904. (should
  6905. (equal '("foo" "bar")
  6906. (progn
  6907. (require 'org-inlinetask)
  6908. (org-test-with-temp-text (concat (make-string org-inlinetask-min-level ?*) " Test :foo:bar:")
  6909. (org-get-tags nil)))))
  6910. ;; Return nil when there is no tag.
  6911. (should-not
  6912. (org-test-with-temp-text "* Test" (org-get-tags)))
  6913. ;; Tags are inherited from parent headlines.
  6914. (should
  6915. (equal '("tag")
  6916. (let ((org-use-tag-inheritance t))
  6917. (org-test-with-temp-text "* H0 :foo:\n* H1 :tag:\n<point>** H2"
  6918. (org-get-tags)))))
  6919. ;; Tags are inherited from `org-file-tags'.
  6920. (should
  6921. (equal '("tag")
  6922. (org-test-with-temp-text "* H1"
  6923. (let ((org-file-tags '("tag"))
  6924. (org-use-tag-inheritance t))
  6925. (org-get-tags)))))
  6926. ;; Only inherited tags have the `inherited' text property.
  6927. (should
  6928. (get-text-property 0 'inherited
  6929. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6930. (let ((org-use-tag-inheritance t))
  6931. (assoc-string "foo" (org-get-tags))))))
  6932. (should-not
  6933. (get-text-property 0 'inherited
  6934. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6935. (let ((org-use-tag-inheritance t))
  6936. (assoc-string "bar" (org-get-tags))))))
  6937. ;; Obey to `org-use-tag-inheritance'.
  6938. (should-not
  6939. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6940. (let ((org-use-tag-inheritance nil))
  6941. (assoc-string "foo" (org-get-tags)))))
  6942. (should-not
  6943. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6944. (let ((org-use-tag-inheritance nil)
  6945. (org-file-tags '("foo")))
  6946. (assoc-string "foo" (org-get-tags)))))
  6947. (should-not
  6948. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6949. (let ((org-use-tag-inheritance '("bar")))
  6950. (assoc-string "foo" (org-get-tags)))))
  6951. (should
  6952. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6953. (let ((org-use-tag-inheritance '("bar")))
  6954. (assoc-string "bar" (org-get-tags)))))
  6955. (should-not
  6956. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6957. (let ((org-use-tag-inheritance "b.*"))
  6958. (assoc-string "foo" (org-get-tags)))))
  6959. (should
  6960. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6961. (let ((org-use-tag-inheritance "b.*"))
  6962. (assoc-string "bar" (org-get-tags)))))
  6963. ;; When optional argument LOCAL is non-nil, ignore tag inheritance.
  6964. (should
  6965. (equal '("baz")
  6966. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6967. (let ((org-use-tag-inheritance t))
  6968. (org-get-tags nil t)))))
  6969. ;; When optional argument POS is non-nil, get tags there instead.
  6970. (should
  6971. (equal '("foo")
  6972. (org-test-with-temp-text "* H1 :foo:\n* <point>H2 :bar:"
  6973. (org-get-tags 1))))
  6974. ;; Make sure tags excluded from inheritance are returned if local
  6975. (should
  6976. (equal '("foo")
  6977. (org-test-with-temp-text "* Test :foo:"
  6978. (let ((org-use-tag-inheritance t)
  6979. (org-tags-exclude-from-inheritance '("foo")))
  6980. (org-get-tags)))))
  6981. ;; Test the collection of tags from #+filetags and parent tags.
  6982. (should
  6983. (equal '("a" "b" "c" "d")
  6984. (org-test-with-temp-text (concat "#+filetags: a\n"
  6985. "* Level 1 :b:\n"
  6986. "** Level 2 :c:\n"
  6987. "*** Level 3 :d:\n"
  6988. "<point>")
  6989. (let ((org-use-tag-inheritance t))
  6990. (org-mode-restart) ;So that `org-file-tags' get populated from #+filetags
  6991. (org-get-tags)))))
  6992. ;; Pathological case: tagged headline with an empty body.
  6993. (should (org-test-with-temp-text "* :tag:" (org-get-tags))))
  6994. (ert-deftest test-org/set-tags ()
  6995. "Test `org-set-tags' specifications."
  6996. ;; Throw an error on invalid data.
  6997. (should-error
  6998. (org-test-with-temp-text "* H"
  6999. (org-set-tags 'foo)))
  7000. ;; `nil', an empty, and a blank string remove all tags.
  7001. (should
  7002. (equal "* H"
  7003. (org-test-with-temp-text "* H :tag1:tag2:"
  7004. (org-set-tags nil)
  7005. (buffer-string))))
  7006. (should
  7007. (equal "* H"
  7008. (org-test-with-temp-text "* H :tag1:tag2:"
  7009. (org-set-tags "")
  7010. (buffer-string))))
  7011. (should
  7012. (equal "* H"
  7013. (org-test-with-temp-text "* H :tag1:tag2:"
  7014. (org-set-tags " ")
  7015. (buffer-string))))
  7016. ;; If there's nothing to remove, just bail out.
  7017. (should
  7018. (equal "* H"
  7019. (org-test-with-temp-text "* H"
  7020. (org-set-tags nil)
  7021. (buffer-string))))
  7022. (should
  7023. (equal "* "
  7024. (org-test-with-temp-text "* "
  7025. (org-set-tags nil)
  7026. (buffer-string))))
  7027. ;; If DATA is a tag string, set current tags to it, even if it means
  7028. ;; replacing old tags.
  7029. (should
  7030. (equal "* H :tag0:"
  7031. (org-test-with-temp-text "* H :tag1:tag2:"
  7032. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  7033. (buffer-string))))
  7034. (should
  7035. (equal "* H :tag0:"
  7036. (org-test-with-temp-text "* H"
  7037. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  7038. (buffer-string))))
  7039. ;; If DATA is a list, set tags to this list, even if it means
  7040. ;; replacing old tags.
  7041. (should
  7042. (equal "* H :tag0:"
  7043. (org-test-with-temp-text "* H :tag1:tag2:"
  7044. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  7045. (buffer-string))))
  7046. (should
  7047. (equal "* H :tag0:"
  7048. (org-test-with-temp-text "* H"
  7049. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  7050. (buffer-string))))
  7051. ;; When set, apply `org-tags-sort-function'.
  7052. (should
  7053. (equal "* H :a:b:"
  7054. (org-test-with-temp-text "* H"
  7055. (let ((org-tags-column 1)
  7056. (org-tags-sort-function #'string<))
  7057. (org-set-tags '("b" "a"))
  7058. (buffer-string)))))
  7059. ;; When new tags are identical to the previous ones, still align.
  7060. (should
  7061. (equal "* H :foo:"
  7062. (org-test-with-temp-text "* H :foo:"
  7063. (let ((org-tags-column 1))
  7064. (org-set-tags '("foo"))
  7065. (buffer-string)))))
  7066. ;; When tags have been changed, run `org-after-tags-change-hook'.
  7067. (should
  7068. (catch :return
  7069. (org-test-with-temp-text "* H :foo:"
  7070. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  7071. (org-set-tags '("bar"))
  7072. nil))))
  7073. (should-not
  7074. (catch :return
  7075. (org-test-with-temp-text "* H :foo:"
  7076. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  7077. (org-set-tags '("foo"))
  7078. nil))))
  7079. ;; Special case: handle empty headlines.
  7080. (should
  7081. (equal "* :tag0:"
  7082. (org-test-with-temp-text "* "
  7083. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  7084. (buffer-string))))
  7085. ;; Modify buffer only when a tag change happens or alignment is
  7086. ;; done.
  7087. (should-not
  7088. (org-test-with-temp-text "* H :foo:"
  7089. (set-buffer-modified-p nil)
  7090. (let ((org-tags-column 1)) (org-set-tags '("foo")))
  7091. (buffer-modified-p)))
  7092. (should
  7093. (org-test-with-temp-text "* H :foo:"
  7094. (set-buffer-modified-p nil)
  7095. (let ((org-tags-column 10)) (org-set-tags '("foo")))
  7096. (buffer-modified-p)))
  7097. (should
  7098. (org-test-with-temp-text "* H :foo:"
  7099. (set-buffer-modified-p nil)
  7100. (let ((org-tags-column 10)) (org-set-tags '("bar")))
  7101. (buffer-modified-p)))
  7102. ;; Pathological case: when setting tags of a folded headline, do not
  7103. ;; let new tags being sucked into invisibility.
  7104. (should-not
  7105. (org-test-with-temp-text "* H1\nContent\n* H2\n\n Other Content"
  7106. ;; Show only headlines
  7107. (org-content)
  7108. ;; Set NEXT tag on current entry
  7109. (org-set-tags ":NEXT:")
  7110. ;; Move point to that NEXT tag
  7111. (search-forward "NEXT") (backward-word)
  7112. ;; And it should be visible (i.e. no overlays)
  7113. (overlays-at (point)))))
  7114. (ert-deftest test-org/set-tags-command ()
  7115. "Test `org-set-tags-command' specifications"
  7116. ;; Set tags at current headline.
  7117. (should
  7118. (equal "* H1 :foo:"
  7119. (org-test-with-temp-text "* H1"
  7120. (cl-letf (((symbol-function 'completing-read-multiple)
  7121. (lambda (&rest args) '("foo"))))
  7122. (let ((org-use-fast-tag-selection nil)
  7123. (org-tags-column 1))
  7124. (org-set-tags-command)))
  7125. (buffer-string))))
  7126. ;; Preserve position when called from the section below.
  7127. (should
  7128. (equal "* H1 :foo:\nContents"
  7129. (org-test-with-temp-text "* H1\n<point>Contents"
  7130. (cl-letf (((symbol-function 'completing-read-multiple)
  7131. (lambda (&rest args) '("foo"))))
  7132. (let ((org-use-fast-tag-selection nil)
  7133. (org-tags-column 1))
  7134. (org-set-tags-command)))
  7135. (buffer-string))))
  7136. (should-not
  7137. (equal "* H1 :foo:\nContents2"
  7138. (org-test-with-temp-text "* H1\n<point>Contents2"
  7139. (cl-letf (((symbol-function 'completing-read-multiple)
  7140. (lambda (&rest args) '("foo"))))
  7141. (let ((org-use-fast-tag-selection nil)
  7142. (org-tags-column 1))
  7143. (org-set-tags-command)))
  7144. (org-at-heading-p))))
  7145. ;; When a region is active and
  7146. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  7147. ;; same value in all headlines in region.
  7148. (should
  7149. (equal "* H1 :foo:\nContents\n* H2 :foo:"
  7150. (org-test-with-temp-text "* H1\nContents\n* H2"
  7151. (cl-letf (((symbol-function 'completing-read-multiple)
  7152. (lambda (&rest args) '("foo"))))
  7153. (let ((org-use-fast-tag-selection nil)
  7154. (org-loop-over-headlines-in-active-region t)
  7155. (org-tags-column 1))
  7156. (transient-mark-mode 1)
  7157. (push-mark (point) t t)
  7158. (goto-char (point-max))
  7159. (org-set-tags-command)))
  7160. (buffer-string))))
  7161. (should
  7162. (equal "* H1\nContents\n* H2 :foo:"
  7163. (org-test-with-temp-text "* H1\nContents\n* H2"
  7164. (cl-letf (((symbol-function 'completing-read-multiple)
  7165. (lambda (&rest args) '("foo"))))
  7166. (let ((org-use-fast-tag-selection nil)
  7167. (org-loop-over-headlines-in-active-region nil)
  7168. (org-tags-column 1))
  7169. (transient-mark-mode 1)
  7170. (push-mark (point) t t)
  7171. (goto-char (point-max))
  7172. (org-set-tags-command)))
  7173. (buffer-string))))
  7174. ;; With a C-u prefix argument, align all tags in the buffer.
  7175. (should
  7176. (equal "* H1 :foo:\n* H2 :bar:"
  7177. (org-test-with-temp-text "* H1 :foo:\n* H2 :bar:"
  7178. (let ((org-tags-column 1)) (org-set-tags-command '(4)))
  7179. (buffer-string))))
  7180. ;; Point does not move with empty headline.
  7181. (should
  7182. (equal ":foo:"
  7183. (org-test-with-temp-text "* <point>"
  7184. (cl-letf (((symbol-function 'completing-read-multiple)
  7185. (lambda (&rest args) '("foo"))))
  7186. (let ((org-use-fast-tag-selection nil)
  7187. (org-tags-column 1))
  7188. (org-set-tags-command)))
  7189. (buffer-substring (point) (line-end-position)))))
  7190. ;; Point does not move at start of line.
  7191. (should
  7192. (equal "* H1 :foo:"
  7193. (org-test-with-temp-text "* H1"
  7194. (cl-letf (((symbol-function 'completing-read-multiple)
  7195. (lambda (&rest args) '("foo"))))
  7196. (let ((org-use-fast-tag-selection nil)
  7197. (org-tags-column 1))
  7198. (org-set-tags-command)))
  7199. (buffer-substring (point) (line-end-position)))))
  7200. ;; Point does not move when within *'s.
  7201. (should
  7202. (equal "* H1 :foo:"
  7203. (org-test-with-temp-text "*<point>* H1"
  7204. (cl-letf (((symbol-function 'completing-read-multiple)
  7205. (lambda (&rest args) '("foo"))))
  7206. (let ((org-use-fast-tag-selection nil)
  7207. (org-tags-column 1))
  7208. (org-set-tags-command)))
  7209. (buffer-substring (point) (line-end-position)))))
  7210. ;; Point workaround does not get fooled when looking at a space.
  7211. (should
  7212. (equal " b :foo:"
  7213. (org-test-with-temp-text "* a<point> b"
  7214. (cl-letf (((symbol-function 'completing-read-multiple)
  7215. (lambda (&rest args) '("foo"))))
  7216. (let ((org-use-fast-tag-selection nil)
  7217. (org-tags-column 1))
  7218. (org-set-tags-command)))
  7219. (buffer-substring (point) (line-end-position)))))
  7220. ;; Handle tags both set locally and inherited.
  7221. (should
  7222. (equal "b :foo:"
  7223. (org-test-with-temp-text "* a :foo:\n** <point>b :foo:"
  7224. (cl-letf (((symbol-function 'completing-read-multiple)
  7225. (lambda (prompt coll &optional pred req initial &rest args)
  7226. (list initial))))
  7227. (let ((org-use-fast-tag-selection nil)
  7228. (org-tags-column 1))
  7229. (org-set-tags-command)))
  7230. (buffer-substring (point) (line-end-position))))))
  7231. (ert-deftest test-org/toggle-tag ()
  7232. "Test `org-toggle-tag' specifications."
  7233. ;; Insert missing tag.
  7234. (should
  7235. (equal "* H :tag:"
  7236. (org-test-with-temp-text "* H"
  7237. (let ((org-tags-column 1)) (org-toggle-tag "tag"))
  7238. (buffer-string))))
  7239. (should
  7240. (equal "* H :tag1:tag2:"
  7241. (org-test-with-temp-text "* H :tag1:"
  7242. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  7243. (buffer-string))))
  7244. ;; Remove existing tag.
  7245. (should
  7246. (equal "* H"
  7247. (org-test-with-temp-text "* H :tag:"
  7248. (org-toggle-tag "tag")
  7249. (buffer-string))))
  7250. (should
  7251. (equal "* H :tag1:"
  7252. (org-test-with-temp-text "* H :tag1:tag2:"
  7253. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  7254. (buffer-string))))
  7255. (should
  7256. (equal "* H :tag2:"
  7257. (org-test-with-temp-text "* H :tag1:tag2:"
  7258. (let ((org-tags-column 1)) (org-toggle-tag "tag1"))
  7259. (buffer-string))))
  7260. ;; With optional argument ONOFF set to `on', try to insert the tag,
  7261. ;; even if its already there.
  7262. (should
  7263. (equal "* H :tag:"
  7264. (org-test-with-temp-text "* H"
  7265. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  7266. (buffer-string))))
  7267. (should
  7268. (equal "* H :tag:"
  7269. (org-test-with-temp-text "* H :tag:"
  7270. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  7271. (buffer-string))))
  7272. ;; With optional argument ONOFF set to `off', try to remove the tag,
  7273. ;; even if its not there.
  7274. (should
  7275. (equal "* H"
  7276. (org-test-with-temp-text "* H :tag:"
  7277. (org-toggle-tag "tag" 'off)
  7278. (buffer-string))))
  7279. (should
  7280. (equal "* H :tag:"
  7281. (org-test-with-temp-text "* H :tag:"
  7282. (let ((org-tags-column 1)) (org-toggle-tag "foo" 'off))
  7283. (buffer-string))))
  7284. ;; Special case: Handle properly tag inheritance. In particular, do
  7285. ;; not set inherited tags.
  7286. (should
  7287. (equal "* H1 :tag:\n** H2 :tag2:tag:"
  7288. (org-test-with-temp-text "* H1 :tag:\n** <point>H2 :tag2:"
  7289. (let ((org-use-tag-inheritance t)
  7290. (org-tags-column 1))
  7291. (org-toggle-tag "tag"))
  7292. (buffer-string))))
  7293. (should
  7294. (equal "* H1 :tag1:tag2:\n** H2 :foo:"
  7295. (org-test-with-temp-text "* H1 :tag1:tag2:\n** <point>H2"
  7296. (let ((org-use-tag-inheritance t)
  7297. (org-tags-column 1))
  7298. (org-toggle-tag "foo"))
  7299. (buffer-string)))))
  7300. (ert-deftest test-org/tags-expand ()
  7301. "Test `org-tags-expand' specifications."
  7302. ;; Expand tag groups as a regexp enclosed within curly brackets.
  7303. (should
  7304. (equal "{\\<[ABC]\\>}"
  7305. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7306. (org-mode-restart)
  7307. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  7308. (should
  7309. (equal "{\\<\\(?:Aa\\|Bb\\|Cc\\)\\>}"
  7310. (org-test-with-temp-text "#+TAGS: [ Aa : Bb Cc ]"
  7311. (org-mode-restart)
  7312. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "Aa")))))
  7313. ;; Preserve operator before the regexp.
  7314. (should
  7315. (equal "+{\\<[ABC]\\>}"
  7316. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7317. (org-mode-restart)
  7318. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "+A")))))
  7319. (should
  7320. (equal "-{\\<[ABC]\\>}"
  7321. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7322. (org-mode-restart)
  7323. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "-A")))))
  7324. ;; Handle "|" syntax.
  7325. (should
  7326. (equal "{\\<[ABC]\\>}|D"
  7327. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7328. (org-mode-restart)
  7329. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|D")))))
  7330. ;; Handle nested groups.
  7331. (should
  7332. (equal "{\\<[A-D]\\>}"
  7333. (org-test-with-temp-text "#+TAGS: [ A : B C ]\n#+TAGS: [ B : D ]"
  7334. (org-mode-restart)
  7335. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  7336. ;; Expand multiple occurrences of the same group.
  7337. (should
  7338. (equal "{\\<[ABC]\\>}|{\\<[ABC]\\>}"
  7339. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7340. (org-mode-restart)
  7341. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|A")))))
  7342. ;; Preserve regexp matches.
  7343. (should
  7344. (equal "{A+}"
  7345. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7346. (org-mode-restart)
  7347. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "{A+}"))))))
  7348. ;;; TODO keywords
  7349. (ert-deftest test-org/auto-repeat-maybe ()
  7350. "Test `org-auto-repeat-maybe' specifications."
  7351. ;; Do not auto repeat when there is no valid time stamp with
  7352. ;; a repeater in the entry.
  7353. (should-not
  7354. (string-prefix-p
  7355. "* TODO H"
  7356. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7357. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
  7358. (org-todo "DONE")
  7359. (buffer-string)))))
  7360. (should-not
  7361. (string-prefix-p
  7362. "* TODO H"
  7363. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7364. (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
  7365. (org-todo "DONE")
  7366. (buffer-string)))))
  7367. ;; When switching to DONE state, switch back to first TODO keyword
  7368. ;; in sequence, or the same keyword if they have different types.
  7369. (should
  7370. (string-prefix-p
  7371. "* TODO H"
  7372. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7373. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7374. (org-todo "DONE")
  7375. (buffer-string)))))
  7376. (should
  7377. (string-prefix-p
  7378. "* KWD1 H"
  7379. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  7380. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  7381. (org-todo "DONE")
  7382. (buffer-string)))))
  7383. (should
  7384. (string-prefix-p
  7385. "* KWD2 H"
  7386. (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
  7387. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  7388. (org-todo "DONE")
  7389. (buffer-string)))))
  7390. ;; If there was no TODO keyword in the first place, do not insert
  7391. ;; any either.
  7392. (should
  7393. (string-prefix-p
  7394. "* H"
  7395. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7396. (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
  7397. (org-todo "DONE")
  7398. (buffer-string)))))
  7399. ;; Revert to REPEAT_TO_STATE, if set.
  7400. (should
  7401. (string-prefix-p
  7402. "* KWD2 H"
  7403. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  7404. (org-test-with-temp-text
  7405. "* KWD2 H
  7406. :PROPERTIES:
  7407. :REPEAT_TO_STATE: KWD2
  7408. :END:
  7409. <2012-03-29 Thu +2y>"
  7410. (org-todo "DONE")
  7411. (buffer-string)))))
  7412. ;; When switching to DONE state, update base date. If there are
  7413. ;; multiple repeated time stamps, update them all.
  7414. (should
  7415. (string-match-p
  7416. "<2014-03-29 .* \\+2y>"
  7417. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7418. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7419. (org-todo "DONE")
  7420. (buffer-string)))))
  7421. (should
  7422. (string-match-p
  7423. "<2015-03-04 .* \\+1y>"
  7424. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7425. (org-test-with-temp-text
  7426. "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
  7427. (org-todo "DONE")
  7428. (buffer-string)))))
  7429. ;; Throw an error if repeater unit is the hour and no time is
  7430. ;; provided in the time-stamp.
  7431. (should-error
  7432. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7433. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
  7434. (org-todo "DONE")
  7435. (buffer-string))))
  7436. ;; Handle every repeater type using hours step.
  7437. (should
  7438. (string-match-p
  7439. "2014-03-04 .* 02:00"
  7440. (org-test-at-time "<2014-03-04 02:35>"
  7441. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 +8h>"
  7442. (org-todo "DONE")
  7443. (buffer-string)))))
  7444. (should
  7445. (string-match-p
  7446. "2014-03-04 .* 10:00"
  7447. (org-test-at-time "<2014-03-04 02:35>"
  7448. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 ++8h>"
  7449. (org-todo "DONE")
  7450. (buffer-string)))))
  7451. (should
  7452. (string-match-p
  7453. "2014-03-04 .* 10:35"
  7454. (org-test-at-time "<2014-03-04 02:35>"
  7455. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 .+8h>"
  7456. (org-todo "DONE")
  7457. (buffer-string)))))
  7458. ;; Do not repeat inactive time stamps with a repeater.
  7459. (should-not
  7460. (string-match-p
  7461. "\\[2014-03-29 .* \\+2y\\]"
  7462. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7463. (org-test-with-temp-text
  7464. "* TODO H\n[2012-03-29 Thu. +2y]"
  7465. (org-todo "DONE")
  7466. (buffer-string)))))
  7467. ;; Do not repeat commented time stamps.
  7468. (should-not
  7469. (string-prefix-p
  7470. "<2015-03-04 .* \\+1y>"
  7471. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7472. (org-test-with-temp-text
  7473. "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
  7474. (org-todo "DONE")
  7475. (buffer-string)))))
  7476. (should-not
  7477. (string-prefix-p
  7478. "<2015-03-04 .* \\+1y>"
  7479. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7480. (org-test-with-temp-text
  7481. "* TODO H
  7482. <2012-03-29 Thu. +2y>
  7483. #+BEGIN_EXAMPLE
  7484. <2014-03-04 Tue +1y>
  7485. #+END_EXAMPLE"
  7486. (org-todo "DONE")
  7487. (buffer-string)))))
  7488. ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
  7489. ;; entry, record time of last repeat.
  7490. (should-not
  7491. (string-match-p
  7492. ":LAST_REPEAT:"
  7493. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  7494. (org-log-repeat nil))
  7495. (cl-letf (((symbol-function 'org-add-log-setup)
  7496. (lambda (&rest args) nil)))
  7497. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  7498. (org-todo "DONE")
  7499. (buffer-string))))))
  7500. (should
  7501. (string-match-p
  7502. ":LAST_REPEAT:"
  7503. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  7504. (org-log-repeat t))
  7505. (cl-letf (((symbol-function 'org-add-log-setup)
  7506. (lambda (&rest args) nil)))
  7507. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  7508. (org-todo "DONE")
  7509. (buffer-string))))))
  7510. (should
  7511. (string-match-p
  7512. ":LAST_REPEAT:"
  7513. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7514. (cl-letf (((symbol-function 'org-add-log-setup)
  7515. (lambda (&rest args) nil)))
  7516. (org-test-with-temp-text
  7517. "* TODO H\n<2012-03-29 Thu +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
  7518. (org-todo "DONE")
  7519. (buffer-string))))))
  7520. ;; When a SCHEDULED entry has no repeater, remove it upon repeating
  7521. ;; the entry as it is no longer relevant.
  7522. (should-not
  7523. (string-match-p
  7524. "^SCHEDULED:"
  7525. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7526. (org-test-with-temp-text
  7527. "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
  7528. (org-todo "DONE")
  7529. (buffer-string)))))
  7530. ;; Properly advance repeater even when a clock entry is specified
  7531. ;; and `org-log-repeat' is nil.
  7532. (should
  7533. (string-match-p
  7534. "SCHEDULED: <2014-03-29"
  7535. (let ((org-log-repeat nil)
  7536. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7537. (org-test-with-temp-text
  7538. "* TODO H
  7539. SCHEDULED: <2012-03-29 Thu +2y>
  7540. CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] => 6:40"
  7541. (org-todo "DONE")
  7542. (buffer-string)))))
  7543. ;; Make sure that logbook state change record does not get
  7544. ;; duplicated when `org-log-repeat' `org-log-done' are non-nil.
  7545. (should
  7546. (string-match-p
  7547. (rx "* TODO Read book
  7548. SCHEDULED: <2021-06-16 " (1+ (not space)) " +1d>
  7549. :PROPERTIES:
  7550. :LAST_REPEAT:" (1+ nonl) "
  7551. :END:
  7552. - State \"DONE\" from \"TODO\"" (1+ nonl) buffer-end)
  7553. (let ((org-log-repeat 'time)
  7554. (org-todo-keywords '((sequence "TODO" "|" "DONE(d!)")))
  7555. (org-log-into-drawer nil))
  7556. (org-test-with-temp-text
  7557. "* TODO Read book
  7558. SCHEDULED: <2021-06-15 Tue +1d>"
  7559. (org-todo "DONE")
  7560. (when (memq 'org-add-log-note post-command-hook)
  7561. (org-add-log-note))
  7562. (buffer-string))))))
  7563. (ert-deftest test-org/org-log-done ()
  7564. "Test `org-log-done' specifications."
  7565. ;; nil value.
  7566. (should
  7567. (string=
  7568. "* DONE task"
  7569. (let ((org-log-done nil)
  7570. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7571. (org-test-with-temp-text
  7572. "* TODO task"
  7573. (org-todo "DONE")
  7574. (when (memq 'org-add-log-note post-command-hook)
  7575. (org-add-log-note))
  7576. (buffer-string)))))
  7577. ;; `time' value.
  7578. (should
  7579. (string=
  7580. (format
  7581. "* DONE task
  7582. CLOSED: %s"
  7583. (org-test-with-temp-text ""
  7584. (org-insert-time-stamp (current-time) t t)
  7585. (buffer-string)))
  7586. (let ((org-log-done 'time)
  7587. (org-log-done-with-time t)
  7588. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7589. (org-test-with-temp-text
  7590. "* TODO task"
  7591. (org-todo "DONE")
  7592. (when (memq 'org-add-log-note post-command-hook)
  7593. (org-add-log-note))
  7594. (buffer-string)))))
  7595. (should
  7596. (string=
  7597. (format
  7598. "* DONE task
  7599. CLOSED: %s"
  7600. (org-test-with-temp-text ""
  7601. (org-insert-time-stamp (current-time) nil t)
  7602. (buffer-string)))
  7603. (let ((org-log-done 'time)
  7604. (org-log-done-with-time nil)
  7605. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7606. (org-test-with-temp-text
  7607. "* TODO task"
  7608. (org-todo "DONE")
  7609. (when (memq 'org-add-log-note post-command-hook)
  7610. (org-add-log-note))
  7611. (buffer-string)))))
  7612. ;; TODO: Test `note' value.
  7613. ;; Test startup overrides.
  7614. (should
  7615. (string=
  7616. "#+STARTUP: nologdone
  7617. * DONE task"
  7618. (let ((org-log-done 'time)
  7619. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7620. (org-test-with-temp-text
  7621. "#+STARTUP: nologdone
  7622. <point>* TODO task"
  7623. (org-set-regexps-and-options)
  7624. (org-todo "DONE")
  7625. (when (memq 'org-add-log-note post-command-hook)
  7626. (org-add-log-note))
  7627. (buffer-string)))))
  7628. (should
  7629. (string=
  7630. (format
  7631. "#+STARTUP: logdone
  7632. * DONE task
  7633. CLOSED: %s"
  7634. (org-test-with-temp-text ""
  7635. (org-insert-time-stamp (current-time) t t)
  7636. (buffer-string)))
  7637. (let ((org-log-done nil)
  7638. (org-log-done-with-time t)
  7639. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7640. (org-test-with-temp-text
  7641. "#+STARTUP: logdone
  7642. <point>* TODO task"
  7643. (org-set-regexps-and-options)
  7644. (org-todo "DONE")
  7645. (when (memq 'org-add-log-note post-command-hook)
  7646. (org-add-log-note))
  7647. (buffer-string)))))
  7648. ;; Test local property overrides.
  7649. (should
  7650. (string=
  7651. "* DONE task
  7652. :PROPERTIES:
  7653. :LOGGING: nil
  7654. :END:"
  7655. (let ((org-log-done 'time)
  7656. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7657. (org-test-with-temp-text
  7658. "* TODO task
  7659. :PROPERTIES:
  7660. :LOGGING: nil
  7661. :END:"
  7662. (org-todo "DONE")
  7663. (when (memq 'org-add-log-note post-command-hook)
  7664. (org-add-log-note))
  7665. (buffer-string)))))
  7666. (should
  7667. (string=
  7668. (format
  7669. "* DONE task
  7670. CLOSED: %s
  7671. :PROPERTIES:
  7672. :LOGGING: logdone
  7673. :END:"
  7674. (org-test-with-temp-text ""
  7675. (org-insert-time-stamp (current-time) t t)
  7676. (buffer-string)))
  7677. (let ((org-log-done nil)
  7678. (org-log-done-with-time t)
  7679. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7680. (org-test-with-temp-text
  7681. "* TODO task
  7682. :PROPERTIES:
  7683. :LOGGING: logdone
  7684. :END:"
  7685. (org-todo "DONE")
  7686. (when (memq 'org-add-log-note post-command-hook)
  7687. (org-add-log-note))
  7688. (buffer-string))))))
  7689. (ert-deftest test-org/org-todo-prefix ()
  7690. "Test `org-todo' prefix arg behavior."
  7691. ;; FIXME: Add tests for all other allowed prefix arguments.
  7692. ;; -1 prefix arg should cancel repeater and mark DONE.
  7693. (should
  7694. (string-match-p
  7695. "DONE H\\(.*\n\\)*<2012-03-29 Thu \\+0y>"
  7696. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7697. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7698. (org-todo -1)
  7699. (buffer-string)))))
  7700. ;; - prefix arg should cancel repeater and mark DONE.
  7701. (should
  7702. (string-match-p
  7703. "DONE H\\(.*\n\\)*<2012-03-29 Thu \\+0y>"
  7704. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7705. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7706. (org-todo '-)
  7707. (buffer-string))))))
  7708. ;;; Timestamps API
  7709. (ert-deftest test-org/at-timestamp-p ()
  7710. "Test `org-at-timestamp-p' specifications."
  7711. (should
  7712. (org-test-with-temp-text "<2012-03-29 Thu>"
  7713. (org-at-timestamp-p)))
  7714. (should-not
  7715. (org-test-with-temp-text "2012-03-29 Thu"
  7716. (org-at-timestamp-p)))
  7717. ;; Test return values.
  7718. (should
  7719. (eq 'bracket
  7720. (org-test-with-temp-text "<2012-03-29 Thu>"
  7721. (org-at-timestamp-p))))
  7722. (should
  7723. (eq 'year
  7724. (org-test-with-temp-text "<<point>2012-03-29 Thu>"
  7725. (org-at-timestamp-p))))
  7726. (should
  7727. (eq 'month
  7728. (org-test-with-temp-text "<2012-<point>03-29 Thu>"
  7729. (org-at-timestamp-p))))
  7730. (should
  7731. (eq 'day
  7732. (org-test-with-temp-text "<2012-03-<point>29 Thu>"
  7733. (org-at-timestamp-p))))
  7734. (should
  7735. (eq 'day
  7736. (org-test-with-temp-text "<2012-03-29 T<point>hu>"
  7737. (org-at-timestamp-p))))
  7738. (should
  7739. (wholenump
  7740. (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
  7741. (org-at-timestamp-p))))
  7742. (should
  7743. (eq 'bracket
  7744. (org-test-with-temp-text "<2012-03-29 Thu<point>>"
  7745. (org-at-timestamp-p))))
  7746. (should
  7747. (eq 'after
  7748. (org-test-with-temp-text "<2012-03-29 Thu><point>»"
  7749. (org-at-timestamp-p))))
  7750. ;; Test `inactive' optional argument.
  7751. (should
  7752. (org-test-with-temp-text "[2012-03-29 Thu]"
  7753. (org-at-timestamp-p 'inactive)))
  7754. (should-not
  7755. (org-test-with-temp-text "[2012-03-29 Thu]"
  7756. (org-at-timestamp-p)))
  7757. ;; When optional argument is `agenda', recognize time-stamps in
  7758. ;; planning info line, property drawers and clocks.
  7759. (should
  7760. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7761. (org-at-timestamp-p 'agenda)))
  7762. (should-not
  7763. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7764. (org-at-timestamp-p)))
  7765. (should
  7766. (org-test-with-temp-text
  7767. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7768. (org-at-timestamp-p 'agenda)))
  7769. (should-not
  7770. (org-test-with-temp-text
  7771. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7772. (org-at-timestamp-p)))
  7773. (should
  7774. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7775. (let ((org-agenda-include-inactive-timestamps t))
  7776. (org-at-timestamp-p 'agenda))))
  7777. (should-not
  7778. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7779. (let ((org-agenda-include-inactive-timestamps t))
  7780. (org-at-timestamp-p))))
  7781. (should-not
  7782. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7783. (let ((org-agenda-include-inactive-timestamps t))
  7784. (org-at-timestamp-p 'inactive))))
  7785. ;; When optional argument is `lax', match any part of the document
  7786. ;; with Org timestamp syntax.
  7787. (should
  7788. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7789. (org-at-timestamp-p 'lax)))
  7790. (should-not
  7791. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7792. (org-at-timestamp-p)))
  7793. (should
  7794. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7795. (org-at-timestamp-p 'lax)))
  7796. (should-not
  7797. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7798. (org-at-timestamp-p)))
  7799. (should
  7800. (org-test-with-temp-text
  7801. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7802. (org-at-timestamp-p 'lax)))
  7803. (should-not
  7804. (org-test-with-temp-text
  7805. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7806. (org-at-timestamp-p)))
  7807. ;; Optional argument `lax' also matches inactive timestamps.
  7808. (should
  7809. (org-test-with-temp-text "# [2012-03-29 Thu]<point>"
  7810. (org-at-timestamp-p 'lax))))
  7811. (ert-deftest test-org/time-stamp ()
  7812. "Test `org-time-stamp' specifications."
  7813. ;; Insert chosen time stamp at point.
  7814. (should
  7815. (string-match
  7816. "Te<2014-03-04 .*?>xt"
  7817. (org-test-with-temp-text "Te<point>xt"
  7818. (cl-letf (((symbol-function 'org-read-date)
  7819. (lambda (&rest args)
  7820. (org-time-string-to-time "2014-03-04"))))
  7821. (org-time-stamp nil)
  7822. (buffer-string)))))
  7823. ;; With a prefix argument, also insert time.
  7824. (should
  7825. (string-match
  7826. "Te<2014-03-04 .*? 00:41>xt"
  7827. (org-test-with-temp-text "Te<point>xt"
  7828. (cl-letf (((symbol-function 'org-read-date)
  7829. (lambda (&rest args)
  7830. (org-time-string-to-time "2014-03-04 00:41"))))
  7831. (org-time-stamp '(4))
  7832. (buffer-string)))))
  7833. ;; With two universal prefix arguments, insert an active timestamp
  7834. ;; with the current time without prompting the user.
  7835. (should
  7836. (string-match
  7837. "Te<2014-03-04 .*? 00:41>xt"
  7838. (org-test-with-temp-text "Te<point>xt"
  7839. (org-test-at-time "2014-03-04 00:41"
  7840. (org-time-stamp '(16))
  7841. (buffer-string)))))
  7842. ;; When optional argument is non-nil, insert an inactive timestamp.
  7843. (should
  7844. (string-match
  7845. "Te\\[2014-03-04 .*?\\]xt"
  7846. (org-test-with-temp-text "Te<point>xt"
  7847. (cl-letf (((symbol-function 'org-read-date)
  7848. (lambda (&rest args)
  7849. (org-time-string-to-time "2014-03-04"))))
  7850. (org-time-stamp nil t)
  7851. (buffer-string)))))
  7852. ;; When called from a timestamp, replace existing one.
  7853. (should
  7854. (string-match
  7855. "<2014-03-04 .*?>"
  7856. (org-test-with-temp-text "<2012-03-29<point> thu.>"
  7857. (cl-letf (((symbol-function 'org-read-date)
  7858. (lambda (&rest args)
  7859. (org-time-string-to-time "2014-03-04"))))
  7860. (org-time-stamp nil)
  7861. (buffer-string)))))
  7862. (should
  7863. (string-match
  7864. "<2014-03-04 .*?>--<2014-03-04 .*?>"
  7865. (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
  7866. (cl-letf (((symbol-function 'org-read-date)
  7867. (lambda (&rest args)
  7868. (org-time-string-to-time "2014-03-04"))))
  7869. (org-time-stamp nil)
  7870. (buffer-string)))))
  7871. ;; When replacing a timestamp, preserve repeater, if any.
  7872. (should
  7873. (string-match
  7874. "<2014-03-04 .*? \\+2y>"
  7875. (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
  7876. (cl-letf (((symbol-function 'org-read-date)
  7877. (lambda (&rest args)
  7878. (org-time-string-to-time "2014-03-04"))))
  7879. (org-time-stamp nil)
  7880. (buffer-string)))))
  7881. ;; When called twice in a raw, build a date range.
  7882. (should
  7883. (string-match
  7884. "<2012-03-29 .*?>--<2014-03-04 .*?>"
  7885. (org-test-with-temp-text "<2012-03-29 thu.><point>"
  7886. (cl-letf (((symbol-function 'org-read-date)
  7887. (lambda (&rest args)
  7888. (org-time-string-to-time "2014-03-04"))))
  7889. (let ((last-command 'org-time-stamp)
  7890. (this-command 'org-time-stamp))
  7891. (org-time-stamp nil))
  7892. (buffer-string))))))
  7893. (ert-deftest test-org/timestamp-has-time-p ()
  7894. "Test `org-timestamp-has-time-p' specifications."
  7895. ;; With time.
  7896. (should
  7897. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7898. (org-timestamp-has-time-p (org-element-context))))
  7899. ;; Without time.
  7900. (should-not
  7901. (org-test-with-temp-text "<2012-03-29 Thu>"
  7902. (org-timestamp-has-time-p (org-element-context)))))
  7903. (ert-deftest test-org/get-repeat ()
  7904. "Test `org-get-repeat' specifications."
  7905. (should
  7906. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
  7907. (org-get-repeat)))
  7908. (should-not
  7909. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
  7910. (org-get-repeat)))
  7911. ;; Return proper repeat string.
  7912. (should
  7913. (equal "+2y"
  7914. (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
  7915. (org-get-repeat))))
  7916. ;; Prevent false positive (commented or verbatim time stamps)
  7917. (should-not
  7918. (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
  7919. (org-get-repeat)))
  7920. (should-not
  7921. (org-test-with-temp-text
  7922. "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
  7923. (org-get-repeat)))
  7924. ;; Return nil when called before first heading.
  7925. (should-not
  7926. (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
  7927. (org-get-repeat)))
  7928. ;; When called with an optional argument, extract repeater from that
  7929. ;; string instead.
  7930. (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
  7931. (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
  7932. (ert-deftest test-org/timestamp-format ()
  7933. "Test `org-timestamp-format' specifications."
  7934. ;; Regular test.
  7935. (should
  7936. (equal
  7937. "2012-03-29 16:40"
  7938. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7939. (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
  7940. ;; Range end.
  7941. (should
  7942. (equal
  7943. "2012-03-29"
  7944. (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
  7945. (org-timestamp-format (org-element-context) "%Y-%m-%d" t)))))
  7946. (ert-deftest test-org/timestamp-split-range ()
  7947. "Test `org-timestamp-split-range' specifications."
  7948. ;; Extract range start (active).
  7949. (should
  7950. (equal '(2012 3 29)
  7951. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7952. (let ((ts (org-timestamp-split-range (org-element-context))))
  7953. (mapcar (lambda (p) (org-element-property p ts))
  7954. '(:year-end :month-end :day-end))))))
  7955. ;; Extract range start (inactive)
  7956. (should
  7957. (equal '(2012 3 29)
  7958. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7959. (let ((ts (org-timestamp-split-range (org-element-context))))
  7960. (mapcar (lambda (p) (org-element-property p ts))
  7961. '(:year-end :month-end :day-end))))))
  7962. ;; Extract range end (active).
  7963. (should
  7964. (equal '(2012 3 30)
  7965. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7966. (let ((ts (org-timestamp-split-range
  7967. (org-element-context) t)))
  7968. (mapcar (lambda (p) (org-element-property p ts))
  7969. '(:year-end :month-end :day-end))))))
  7970. ;; Extract range end (inactive)
  7971. (should
  7972. (equal '(2012 3 30)
  7973. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7974. (let ((ts (org-timestamp-split-range
  7975. (org-element-context) t)))
  7976. (mapcar (lambda (p) (org-element-property p ts))
  7977. '(:year-end :month-end :day-end))))))
  7978. ;; Return the timestamp if not a range.
  7979. (should
  7980. (org-test-with-temp-text "[2012-03-29 Thu]"
  7981. (let* ((ts-orig (org-element-context))
  7982. (ts-copy (org-timestamp-split-range ts-orig)))
  7983. (eq ts-orig ts-copy))))
  7984. (should
  7985. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7986. (let* ((ts-orig (org-element-context))
  7987. (ts-copy (org-timestamp-split-range ts-orig)))
  7988. (eq ts-orig ts-copy)))))
  7989. (ert-deftest test-org/timestamp-translate ()
  7990. "Test `org-timestamp-translate' specifications."
  7991. ;; Translate whole date range.
  7992. (should
  7993. (equal "<29>--<30>"
  7994. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7995. (let ((org-display-custom-times t)
  7996. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7997. (org-timestamp-translate (org-element-context))))))
  7998. ;; Translate date range start.
  7999. (should
  8000. (equal "<29>"
  8001. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  8002. (let ((org-display-custom-times t)
  8003. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  8004. (org-timestamp-translate (org-element-context) 'start)))))
  8005. ;; Translate date range end.
  8006. (should
  8007. (equal "<30>"
  8008. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  8009. (let ((org-display-custom-times t)
  8010. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  8011. (org-timestamp-translate (org-element-context) 'end)))))
  8012. ;; Translate time range.
  8013. (should
  8014. (equal "<08>--<16>"
  8015. (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
  8016. (let ((org-display-custom-times t)
  8017. (org-time-stamp-custom-formats '("<%d>" . "<%H>")))
  8018. (org-timestamp-translate (org-element-context))))))
  8019. ;; Translate non-range timestamp.
  8020. (should
  8021. (equal "<29>"
  8022. (org-test-with-temp-text "<2012-03-29 Thu>"
  8023. (let ((org-display-custom-times t)
  8024. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  8025. (org-timestamp-translate (org-element-context))))))
  8026. ;; Do not change `diary' timestamps.
  8027. (should
  8028. (equal "<%%(org-float t 4 2)>"
  8029. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  8030. (let ((org-display-custom-times t)
  8031. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  8032. (org-timestamp-translate (org-element-context)))))))
  8033. (ert-deftest test-org/timestamp-from-string ()
  8034. "Test `org-timestamp-from-string' specifications."
  8035. ;; Return nil if argument is not a valid Org timestamp.
  8036. (should-not (org-timestamp-from-string ""))
  8037. (should-not (org-timestamp-from-string nil))
  8038. (should-not (org-timestamp-from-string "<2012-03-29"))
  8039. ;; Otherwise, return a valid Org timestamp object.
  8040. (should
  8041. (string-match-p "<2012-03-29 .+>"
  8042. (org-element-interpret-data
  8043. (org-timestamp-from-string "<2012-03-29 Thu>"))))
  8044. (should
  8045. (string-match-p "[2014-03-04 .+]"
  8046. (org-element-interpret-data
  8047. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  8048. (ert-deftest test-org/timestamp-from-time ()
  8049. "Test `org-timestamp-from-time' specifications."
  8050. ;; Standard test.
  8051. (should
  8052. (string-match-p
  8053. "<2012-03-29 .+>"
  8054. (org-element-interpret-data
  8055. (org-timestamp-from-time
  8056. (org-time-string-to-time "<2012-03-29 Thu 16:40>")))))
  8057. ;; When optional argument WITH-TIME is non-nil, provide time
  8058. ;; information.
  8059. (should
  8060. (string-match-p
  8061. "<2012-03-29 .+ 16:40>"
  8062. (org-element-interpret-data
  8063. (org-timestamp-from-time
  8064. (org-time-string-to-time "<2012-03-29 Thu 16:40>")
  8065. t))))
  8066. ;; When optional argument INACTIVE is non-nil, return an inactive
  8067. ;; timestamp.
  8068. (should
  8069. (string-match-p
  8070. "[2012-03-29 .+]"
  8071. (org-element-interpret-data
  8072. (org-timestamp-from-time
  8073. (org-time-string-to-time "<2012-03-29 Thu 16:40>")
  8074. nil t)))))
  8075. (ert-deftest test-org/timestamp-to-time ()
  8076. "Test `org-timestamp-to-time' specifications."
  8077. (should
  8078. (equal "2014-03-04"
  8079. (format-time-string
  8080. "%Y-%m-%d"
  8081. (org-timestamp-to-time
  8082. (org-timestamp-from-string "<2014-03-04 Tue>")))))
  8083. (should
  8084. (equal "2014-03-04"
  8085. (format-time-string
  8086. "%Y-%m-%d"
  8087. (org-timestamp-to-time
  8088. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  8089. (should
  8090. (equal "2012-03-29 08:30"
  8091. (format-time-string
  8092. "%Y-%m-%d %H:%M"
  8093. (org-timestamp-to-time
  8094. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")))))
  8095. (should
  8096. (equal "2012-03-29"
  8097. (format-time-string
  8098. "%Y-%m-%d"
  8099. (org-timestamp-to-time
  8100. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")))))
  8101. (should
  8102. (equal "2012-03-29"
  8103. (format-time-string
  8104. "%Y-%m-%d"
  8105. (org-timestamp-to-time
  8106. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")))))
  8107. ;; When optional argument END is non-nil, use end of date range or
  8108. ;; time range.
  8109. (should
  8110. (equal "2012-03-29 16:40"
  8111. (format-time-string
  8112. "%Y-%m-%d %H:%M"
  8113. (org-timestamp-to-time
  8114. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")
  8115. t))))
  8116. (should
  8117. (equal "2014-03-04"
  8118. (format-time-string
  8119. "%Y-%m-%d"
  8120. (org-timestamp-to-time
  8121. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")
  8122. t))))
  8123. (should
  8124. (equal "2014-03-04"
  8125. (format-time-string
  8126. "%Y-%m-%d"
  8127. (org-timestamp-to-time
  8128. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")
  8129. t)))))
  8130. ;;; Yank and Kill
  8131. (ert-deftest test-org/paste-subtree ()
  8132. "Test `org-paste-subtree' specifications."
  8133. ;; Return an error if text to yank is not a set of subtrees.
  8134. (should-error (org-paste-subtree nil "Text"))
  8135. ;; Adjust level according to current one.
  8136. (should
  8137. (equal "* H\n* Text\n"
  8138. (org-test-with-temp-text "* H\n<point>"
  8139. (org-paste-subtree nil "* Text")
  8140. (buffer-string))))
  8141. (should
  8142. (equal "* H1\n** H2\n** Text\n"
  8143. (org-test-with-temp-text "* H1\n** H2\n<point>"
  8144. (org-paste-subtree nil "* Text")
  8145. (buffer-string))))
  8146. ;; When not on a heading, move to next heading before yanking.
  8147. (should
  8148. (equal "* H1\nParagraph\n* Text\n* H2"
  8149. (org-test-with-temp-text "* H1\n<point>Paragraph\n* H2"
  8150. (org-paste-subtree nil "* Text")
  8151. (buffer-string))))
  8152. ;; If point is between two headings, use the deepest level.
  8153. (should
  8154. (equal "* H1\n\n* Text\n* H2"
  8155. (org-test-with-temp-text "* H1\n<point>\n* H2"
  8156. (org-paste-subtree nil "* Text")
  8157. (buffer-string))))
  8158. (should
  8159. (equal "** H1\n\n** Text\n* H2"
  8160. (org-test-with-temp-text "** H1\n<point>\n* H2"
  8161. (org-paste-subtree nil "* Text")
  8162. (buffer-string))))
  8163. (should
  8164. (equal "* H1\n\n** Text\n** H2"
  8165. (org-test-with-temp-text "* H1\n<point>\n** H2"
  8166. (org-paste-subtree nil "* Text")
  8167. (buffer-string))))
  8168. ;; When on an empty heading, after the stars, deduce the new level
  8169. ;; from the number of stars.
  8170. (should
  8171. (equal "*** Text\n"
  8172. (org-test-with-temp-text "*** <point>"
  8173. (org-paste-subtree nil "* Text")
  8174. (buffer-string))))
  8175. ;; Optional argument LEVEL forces a level for the subtree.
  8176. (should
  8177. (equal "* H\n*** Text\n"
  8178. (org-test-with-temp-text "* H<point>"
  8179. (org-paste-subtree 3 "* Text")
  8180. (buffer-string)))))
  8181. (ert-deftest test-org/cut-and-paste-subtree ()
  8182. "Test `org-cut-subtree' and `org-paste-subtree'."
  8183. (should
  8184. (equal
  8185. "* Two
  8186. two
  8187. * One
  8188. "
  8189. (org-test-with-temp-text
  8190. "* One
  8191. <point>* Two
  8192. two
  8193. "
  8194. (call-interactively #'org-cut-subtree)
  8195. (goto-char (point-min))
  8196. (call-interactively #'org-paste-subtree)
  8197. (buffer-string))))
  8198. (should
  8199. (equal
  8200. "* One
  8201. * Two
  8202. "
  8203. (org-test-with-temp-text
  8204. "* One
  8205. <point>* Two
  8206. "
  8207. (call-interactively #'org-cut-subtree)
  8208. (backward-char)
  8209. (call-interactively #'org-paste-subtree)
  8210. (buffer-string)))))
  8211. (provide 'test-org)
  8212. ;;; test-org.el ends here