test-org.el 259 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020
  1. ;;; test-org.el --- tests for org.el
  2. ;; Copyright (c) David Maus
  3. ;; Authors: David Maus
  4. ;; This file is not part of GNU Emacs.
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;; Template test file for Org tests
  16. ;;; Code:
  17. (eval-and-compile (require 'cl-lib))
  18. ;;; Comments
  19. (ert-deftest test-org/toggle-comment ()
  20. "Test `org-toggle-comment' specifications."
  21. ;; Simple headline.
  22. (should
  23. (equal "* Test"
  24. (org-test-with-temp-text "* COMMENT Test"
  25. (org-toggle-comment)
  26. (buffer-string))))
  27. (should
  28. (equal "* COMMENT Test"
  29. (org-test-with-temp-text "* Test"
  30. (org-toggle-comment)
  31. (buffer-string))))
  32. ;; Headline with a regular keyword.
  33. (should
  34. (equal "* TODO Test"
  35. (org-test-with-temp-text "* TODO COMMENT Test"
  36. (org-toggle-comment)
  37. (buffer-string))))
  38. (should
  39. (equal "* TODO COMMENT Test"
  40. (org-test-with-temp-text "* TODO Test"
  41. (org-toggle-comment)
  42. (buffer-string))))
  43. ;; Empty headline.
  44. (should
  45. (equal "* "
  46. (org-test-with-temp-text "* COMMENT"
  47. (org-toggle-comment)
  48. (buffer-string))))
  49. (should
  50. (equal "* COMMENT"
  51. (org-test-with-temp-text "* "
  52. (org-toggle-comment)
  53. (buffer-string))))
  54. ;; Headline with a single keyword.
  55. (should
  56. (equal "* TODO "
  57. (org-test-with-temp-text "* TODO COMMENT"
  58. (org-toggle-comment)
  59. (buffer-string))))
  60. (should
  61. (equal "* TODO COMMENT"
  62. (org-test-with-temp-text "* TODO"
  63. (org-toggle-comment)
  64. (buffer-string))))
  65. ;; Headline with a keyword, a priority cookie and contents.
  66. (should
  67. (equal "* TODO [#A] Headline"
  68. (org-test-with-temp-text "* TODO [#A] COMMENT Headline"
  69. (org-toggle-comment)
  70. (buffer-string))))
  71. (should
  72. (equal "* TODO [#A] COMMENT Headline"
  73. (org-test-with-temp-text "* TODO [#A] Headline"
  74. (org-toggle-comment)
  75. (buffer-string)))))
  76. (ert-deftest test-org/comment-dwim ()
  77. "Test `comment-dwim' behaviour in an Org buffer."
  78. ;; No region selected, no comment on current line and line not
  79. ;; empty: insert comment on line above.
  80. (should
  81. (equal "# \nComment"
  82. (org-test-with-temp-text "Comment"
  83. (call-interactively #'org-comment-dwim)
  84. (buffer-string))))
  85. ;; No region selected, no comment on current line and line empty:
  86. ;; insert comment on this line.
  87. (should
  88. (equal "# \nParagraph"
  89. (org-test-with-temp-text "\nParagraph"
  90. (call-interactively #'org-comment-dwim)
  91. (buffer-string))))
  92. ;; No region selected, and a comment on this line: indent it.
  93. (should
  94. (equal "* Headline\n # Comment"
  95. (org-test-with-temp-text "* Headline\n# <point>Comment"
  96. (let ((org-adapt-indentation t))
  97. (call-interactively #'org-comment-dwim))
  98. (buffer-string))))
  99. ;; Also recognize single # at column 0 as comments.
  100. (should
  101. (equal "# Comment"
  102. (org-test-with-temp-text "# Comment"
  103. (call-interactively #'org-comment-dwim)
  104. (buffer-string))))
  105. ;; Region selected and only comments and blank lines within it:
  106. ;; un-comment all commented lines.
  107. (should
  108. (equal "Comment 1\n\nComment 2"
  109. (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
  110. (transient-mark-mode 1)
  111. (push-mark (point) t t)
  112. (goto-char (point-max))
  113. (call-interactively #'org-comment-dwim)
  114. (buffer-string))))
  115. ;; Region selected without comments: comment all lines if
  116. ;; `comment-empty-lines' is non-nil, only non-blank lines otherwise.
  117. (should
  118. (equal "# Comment 1\n\n# Comment 2"
  119. (org-test-with-temp-text "Comment 1\n\nComment 2"
  120. (transient-mark-mode 1)
  121. (push-mark (point) t t)
  122. (goto-char (point-max))
  123. (let ((comment-empty-lines nil))
  124. (call-interactively #'org-comment-dwim))
  125. (buffer-string))))
  126. (should
  127. (equal "# Comment 1\n# \n# Comment 2"
  128. (org-test-with-temp-text "Comment 1\n\nComment 2"
  129. (transient-mark-mode 1)
  130. (push-mark (point) t t)
  131. (goto-char (point-max))
  132. (let ((comment-empty-lines t))
  133. (call-interactively #'org-comment-dwim))
  134. (buffer-string))))
  135. ;; In front of a keyword without region, insert a new comment.
  136. (should
  137. (equal "# \n#+KEYWORD: value"
  138. (org-test-with-temp-text "#+KEYWORD: value"
  139. (call-interactively #'org-comment-dwim)
  140. (buffer-string))))
  141. ;; Comment a heading
  142. (should
  143. (equal "* COMMENT Test"
  144. (org-test-with-temp-text "* Test"
  145. (call-interactively #'org-comment-dwim)
  146. (buffer-string))))
  147. ;; In a source block, use appropriate syntax.
  148. (should
  149. (equal " ;; "
  150. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n<point>\n#+END_SRC"
  151. (let ((org-edit-src-content-indentation 2))
  152. (call-interactively #'org-comment-dwim))
  153. (buffer-substring-no-properties (line-beginning-position)
  154. (point)))))
  155. (should
  156. (equal "#+BEGIN_SRC emacs-lisp\n ;; a\n ;; b\n#+END_SRC"
  157. (org-test-with-temp-text
  158. "#+BEGIN_SRC emacs-lisp\n<point>a\nb\n#+END_SRC"
  159. (transient-mark-mode 1)
  160. (push-mark (point) t t)
  161. (forward-line 2)
  162. (let ((org-edit-src-content-indentation 2))
  163. (call-interactively #'org-comment-dwim))
  164. (buffer-string)))))
  165. ;;; Date and time analysis
  166. (ert-deftest test-org/org-read-date ()
  167. "Test `org-read-date' specifications."
  168. ;; Parse ISO date with abbreviated year and month.
  169. (should (equal "2012-03-29 16:40"
  170. (let ((org-time-was-given t))
  171. (org-read-date t nil "12-3-29 16:40"))))
  172. ;; Parse Europeans dates.
  173. (should (equal "2012-03-29 16:40"
  174. (let ((org-time-was-given t))
  175. (org-read-date t nil "29.03.2012 16:40"))))
  176. ;; Parse Europeans dates without year.
  177. (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
  178. (let ((org-time-was-given t))
  179. (org-read-date t nil "29.03. 16:40"))))
  180. ;; Relative date applied to current time if there is single
  181. ;; plus/minus, or to default date when there are two of them.
  182. (should
  183. (equal
  184. "2015-03-04"
  185. (org-test-at-time "2014-03-04"
  186. (org-read-date
  187. t nil "+1y" nil
  188. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))
  189. (should
  190. (equal
  191. "2013-03-29"
  192. (org-test-at-time "2014-03-04"
  193. (org-read-date
  194. t nil "++1y" nil
  195. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))
  196. ;; When `org-read-date-prefer-future' is non-nil, prefer future
  197. ;; dates (relatively to now) when incomplete. Otherwise, use
  198. ;; default date.
  199. (should
  200. (equal
  201. "2014-04-01"
  202. (org-test-at-time "2014-03-04"
  203. (let ((org-read-date-prefer-future t))
  204. (org-read-date t nil "1")))))
  205. (should
  206. (equal
  207. "2013-03-04"
  208. (org-test-at-time "2012-03-29"
  209. (let ((org-read-date-prefer-future t))
  210. (org-read-date t nil "3-4")))))
  211. (should
  212. (equal
  213. "2012-03-04"
  214. (org-test-at-time "2012-03-29"
  215. (let ((org-read-date-prefer-future nil))
  216. (org-read-date t nil "3-4")))))
  217. ;; When set to `org-read-date-prefer-future' is set to `time', read
  218. ;; day is moved to tomorrow if specified hour is before current
  219. ;; time. However, it only happens in no other part of the date is
  220. ;; specified.
  221. (should
  222. (equal
  223. "2012-03-30"
  224. (org-test-at-time "2012-03-29 16:40"
  225. (let ((org-read-date-prefer-future 'time))
  226. (org-read-date t nil "00:40" nil)))))
  227. (should-not
  228. (equal
  229. "2012-03-30"
  230. (org-test-at-time "2012-03-29 16:40"
  231. (let ((org-read-date-prefer-future 'time))
  232. (org-read-date t nil "29 00:40" nil)))))
  233. ;; Caveat: `org-read-date-prefer-future' always refers to current
  234. ;; time, not default time, when they differ.
  235. (should
  236. (equal
  237. "2014-04-01"
  238. (org-test-at-time "2014-03-04"
  239. (let ((org-read-date-prefer-future t))
  240. (org-read-date
  241. t nil "1" nil
  242. (apply #'encode-time (org-parse-time-string "2012-03-29")))))))
  243. (should
  244. (equal
  245. "2014-03-25"
  246. (org-test-at-time "2014-03-04"
  247. (let ((org-read-date-prefer-future t))
  248. (org-read-date
  249. t nil "25" nil
  250. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))))
  251. (ert-deftest test-org/org-parse-time-string ()
  252. "Test `org-parse-time-string'."
  253. (should (equal (org-parse-time-string "2012-03-29 16:40")
  254. '(0 40 16 29 3 2012 nil nil nil)))
  255. (should (equal (org-parse-time-string "[2012-03-29 16:40]")
  256. '(0 40 16 29 3 2012 nil nil nil)))
  257. (should (equal (org-parse-time-string "<2012-03-29 16:40>")
  258. '(0 40 16 29 3 2012 nil nil nil)))
  259. (should (equal (org-parse-time-string "<2012-03-29>")
  260. '(0 0 0 29 3 2012 nil nil nil)))
  261. (should (equal (org-parse-time-string "<2012-03-29>" t)
  262. '(0 nil nil 29 3 2012 nil nil nil))))
  263. (ert-deftest test-org/closest-date ()
  264. "Test `org-closest-date' specifications."
  265. (require 'calendar)
  266. ;; Time stamps without a repeater are returned unchanged.
  267. (should
  268. (equal
  269. '(3 29 2012)
  270. (calendar-gregorian-from-absolute
  271. (org-closest-date "<2012-03-29>" "<2014-03-04>" nil))))
  272. ;; Time stamps with a null repeater are returned unchanged.
  273. (should
  274. (equal
  275. '(3 29 2012)
  276. (calendar-gregorian-from-absolute
  277. (org-closest-date "<2012-03-29 +0d>" "<2014-03-04>" nil))))
  278. ;; if PREFER is set to `past' always return a date before, or equal
  279. ;; to CURRENT.
  280. (should
  281. (equal
  282. '(3 1 2014)
  283. (calendar-gregorian-from-absolute
  284. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'past))))
  285. (should
  286. (equal
  287. '(3 4 2014)
  288. (calendar-gregorian-from-absolute
  289. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'past))))
  290. ;; if PREFER is set to `future' always return a date before, or equal
  291. ;; to CURRENT.
  292. (should
  293. (equal
  294. '(3 29 2014)
  295. (calendar-gregorian-from-absolute
  296. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'future))))
  297. (should
  298. (equal
  299. '(3 4 2014)
  300. (calendar-gregorian-from-absolute
  301. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'future))))
  302. ;; If PREFER is neither `past' nor `future', select closest date.
  303. (should
  304. (equal
  305. '(3 1 2014)
  306. (calendar-gregorian-from-absolute
  307. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" nil))))
  308. (should
  309. (equal
  310. '(5 4 2014)
  311. (calendar-gregorian-from-absolute
  312. (org-closest-date "<2012-03-04 +1m>" "<2014-04-28>" nil))))
  313. ;; Test "day" repeater.
  314. (should
  315. (equal '(3 8 2014)
  316. (calendar-gregorian-from-absolute
  317. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'past))))
  318. (should
  319. (equal '(3 10 2014)
  320. (calendar-gregorian-from-absolute
  321. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'future))))
  322. ;; Test "month" repeater.
  323. (should
  324. (equal '(1 5 2015)
  325. (calendar-gregorian-from-absolute
  326. (org-closest-date "<2014-03-05 +2m>" "<2015-02-04>" 'past))))
  327. (should
  328. (equal '(3 29 2014)
  329. (calendar-gregorian-from-absolute
  330. (org-closest-date "<2012-03-29 +2m>" "<2014-03-04>" 'future))))
  331. ;; Test "year" repeater.
  332. (should
  333. (equal '(3 5 2014)
  334. (calendar-gregorian-from-absolute
  335. (org-closest-date "<2014-03-05 +2y>" "<2015-02-04>" 'past))))
  336. (should
  337. (equal '(3 29 2014)
  338. (calendar-gregorian-from-absolute
  339. (org-closest-date "<2012-03-29 +2y>" "<2014-03-04>" 'future)))))
  340. (ert-deftest test-org/deadline-close-p ()
  341. "Test `org-deadline-close-p' specifications."
  342. (org-test-at-time "2016-06-03 Fri 01:43"
  343. ;; Timestamps are close if they are within `ndays' of lead time.
  344. (org-test-with-temp-text "* Heading"
  345. (should (org-deadline-close-p "2016-06-03 Fri" 0))
  346. (should (org-deadline-close-p "2016-06-02 Thu" 0))
  347. (should-not (org-deadline-close-p "2016-06-04 Sat" 0))
  348. (should (org-deadline-close-p "2016-06-04 Sat" 1))
  349. (should (org-deadline-close-p "2016-06-03 Fri 12:00" 0)))
  350. ;; Read `ndays' from timestamp if argument not given.
  351. (org-test-with-temp-text "* H"
  352. (should (org-deadline-close-p "2016-06-04 Sat -1d"))
  353. (should-not (org-deadline-close-p "2016-06-04 Sat -0d"))
  354. (should (org-deadline-close-p "2016-06-10 Fri -1w"))
  355. (should-not (org-deadline-close-p "2016-06-11 Sat -1w")))
  356. ;; Prefer `ndays' argument over lead time in timestamp.
  357. (org-test-with-temp-text "* H"
  358. (should (org-deadline-close-p "2016-06-04 Sat -0d" 1))
  359. (should-not (org-deadline-close-p "2016-06-04 Sat -0d" 0)))
  360. ;; Completed tasks are never close.
  361. (let ((org-todo-keywords '(("TODO" "|" "DONE"))))
  362. (org-test-with-temp-text "* TODO Heading"
  363. (should (org-deadline-close-p "2016-06-03")))
  364. (org-test-with-temp-text "* DONE Heading"
  365. (should-not (org-deadline-close-p "2016-06-03"))))))
  366. ;;; Drawers
  367. (ert-deftest test-org/at-property-p ()
  368. "Test `org-at-property-p' specifications."
  369. (should
  370. (equal 't
  371. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:PROP: t\n:END:\n"
  372. (org-at-property-p))))
  373. (should
  374. (equal 't
  375. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n:END:\n"
  376. (org-at-property-p)))))
  377. (ert-deftest test-org/at-property-drawer-p ()
  378. "Test `org-at-property-drawer-p' specifications."
  379. (should
  380. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:PROP: t\n:END:\n"
  381. (org-at-property-drawer-p)))
  382. (should
  383. (org-test-with-temp-text ":PROPERTIES:\n:PROP: t\n:END:\n"
  384. (org-at-property-drawer-p)))
  385. ;; The function only returns t if point is at the first line of
  386. ;; a property block.
  387. (should-not
  388. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n:END:\n"
  389. (org-at-property-drawer-p)))
  390. ;; The function ignores incomplete drawers.
  391. (should-not
  392. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n"
  393. (org-at-property-drawer-p))))
  394. (ert-deftest test-org/get-property-block ()
  395. "Test `org-get-property-block' specifications."
  396. (should
  397. (equal '(14 . 14)
  398. (org-test-with-temp-text ":PROPERTIES:\n:END:\n* H\n"
  399. (org-get-property-block))))
  400. (should
  401. (equal '(14 . 14)
  402. (org-test-with-temp-text ":PROPERTIES:\n:END:\n"
  403. (org-get-property-block))))
  404. ;; Comments above a document property block is ok.
  405. (should
  406. (equal '(18 . 18)
  407. (org-test-with-temp-text "# C\n:PROPERTIES:\n:END:\n"
  408. (org-get-property-block))))
  409. ;; Keywords above a document property block is ok.
  410. (should
  411. (equal '(22 . 22)
  412. (org-test-with-temp-text "# C\n# C\n:PROPERTIES:\n:END:\n"
  413. (org-get-property-block))))
  414. ;; Comments and keywords are allowed before a document property block.
  415. (should
  416. (equal '(18 . 27)
  417. (org-test-with-temp-text "# C\n:PROPERTIES:\n:KEY: V:\n:END:\n"
  418. (org-get-property-block))))
  419. ;; A document property block will not be valid if there are lines
  420. ;; with whitespace above it
  421. (should-not
  422. (org-test-with-temp-text "\n:PROPERTIES:\n:END:\n"
  423. (org-get-property-block)))
  424. (should
  425. (equal '(18 . 18)
  426. (org-test-with-temp-text "* H\n:PROPERTIES:\n:END:\n<point>"
  427. (org-get-property-block))))
  428. (should
  429. (equal "* H\n:PROPERTIES:\n:END:\n"
  430. (org-test-with-temp-text "* H"
  431. (let ((org-adapt-indentation nil))
  432. (org-get-property-block nil 'force))
  433. (buffer-string))))
  434. (should
  435. (equal ":PROPERTIES:\n:END:\n"
  436. (org-test-with-temp-text ""
  437. (org-get-property-block nil 'force)
  438. (buffer-string))))
  439. (should
  440. (equal "* H1\n :PROPERTIES:\n :END:\n* H2"
  441. (org-test-with-temp-text "* H1\n* H2"
  442. (let ((org-adapt-indentation t))
  443. (org-get-property-block nil 'force))
  444. (buffer-string)))))
  445. (ert-deftest test-org/insert-property-drawer ()
  446. "Test `org-insert-property-drawer' specifications."
  447. ;; Insert drawer in empty buffer
  448. (should
  449. (equal ":PROPERTIES:\n:END:\n"
  450. (org-test-with-temp-text ""
  451. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  452. (buffer-string))))
  453. ;; Insert drawer in document header with existing comment and
  454. ;; keyword.
  455. (should
  456. (equal "# C\n:PROPERTIES:\n:END:\n#+TITLE: T"
  457. (org-test-with-temp-text "# C\n#+TITLE: T"
  458. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  459. (buffer-string))))
  460. ;; Insert drawer in document header with existing keyword.
  461. (should
  462. (equal ":PROPERTIES:\n:END:\n#+TITLE: T"
  463. (org-test-with-temp-text "#+TITLE: T"
  464. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  465. (buffer-string))))
  466. (should
  467. (equal ":PROPERTIES:\n:END:"
  468. (org-test-with-temp-text ":PROPERTIES:\n:END:"
  469. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  470. (buffer-string))))
  471. ;; Insert drawer in document header with one existing heading in buffer.
  472. (should
  473. (equal ":PROPERTIES:\n:END:\n\n* T\n"
  474. (org-test-with-temp-text "\n* T\n"
  475. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  476. (buffer-string))))
  477. ;; Insert drawer right after headline if there is no planning line,
  478. ;; or after it otherwise.
  479. (should
  480. (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
  481. (org-test-with-temp-text "* H\nParagraph<point>"
  482. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  483. (buffer-string))))
  484. (should
  485. (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
  486. (org-test-with-temp-text
  487. "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
  488. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  489. (buffer-string))))
  490. ;; Indent inserted drawer.
  491. (should
  492. (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
  493. (org-test-with-temp-text "* H\nParagraph<point>"
  494. (let ((org-adapt-indentation t)) (org-insert-property-drawer))
  495. (buffer-string))))
  496. ;; Handle insertion at eob.
  497. (should
  498. (equal "* H\n:PROPERTIES:\n:END:\n"
  499. (org-test-with-temp-text "* H"
  500. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  501. (buffer-string))))
  502. ;; Skip inlinetasks before point.
  503. (when (featurep 'org-inlinetask)
  504. (should
  505. (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
  506. (org-test-with-temp-text
  507. "* H\n*************** I\n*************** END\nP<point>"
  508. (let ((org-adapt-indentation nil)
  509. (org-inlinetask-min-level 15))
  510. (org-insert-property-drawer))
  511. (buffer-string)))))
  512. ;; Correctly set drawer in an inlinetask.
  513. (when (featurep 'org-inlinetask)
  514. (should
  515. (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
  516. (org-test-with-temp-text
  517. "* H\n*************** I\nP<point>\n*************** END"
  518. (let ((org-adapt-indentation nil)
  519. (org-inlinetask-min-level 15))
  520. (org-insert-property-drawer))
  521. (buffer-string))))))
  522. ;;; Filling
  523. (ert-deftest test-org/fill-element ()
  524. "Test `org-fill-element' specifications."
  525. ;; At an Org table, align it.
  526. (should
  527. (equal "| a |\n"
  528. (org-test-with-temp-text "|a|"
  529. (org-fill-element)
  530. (buffer-string))))
  531. (should
  532. (equal "#+name: table\n| a |\n"
  533. (org-test-with-temp-text "#+name: table\n| a |\n"
  534. (org-fill-element)
  535. (buffer-string))))
  536. ;; At a paragraph, preserve line breaks.
  537. (org-test-with-temp-text "some \\\\\nlong\ntext"
  538. (let ((fill-column 20))
  539. (org-fill-element)
  540. (should (equal (buffer-string) "some \\\\\nlong text"))))
  541. ;; Correctly fill a paragraph when point is at its very end.
  542. (should
  543. (equal "A B"
  544. (org-test-with-temp-text "A\nB"
  545. (let ((fill-column 20))
  546. (goto-char (point-max))
  547. (org-fill-element)
  548. (buffer-string)))))
  549. ;; Correctly fill the last paragraph of a greater element.
  550. (should
  551. (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
  552. (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
  553. (let ((fill-column 8))
  554. (forward-line)
  555. (end-of-line)
  556. (org-fill-element)
  557. (buffer-string)))))
  558. ;; Correctly fill an element in a narrowed buffer.
  559. (should
  560. (equal "01234\n6"
  561. (org-test-with-temp-text "01234 6789"
  562. (let ((fill-column 5))
  563. (narrow-to-region 1 8)
  564. (org-fill-element)
  565. (buffer-string)))))
  566. ;; Handle `adaptive-fill-regexp' in paragraphs.
  567. (should
  568. (equal "> a b"
  569. (org-test-with-temp-text "> a\n> b"
  570. (let ((fill-column 5)
  571. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  572. (org-fill-element)
  573. (buffer-string)))))
  574. ;; Special case: Fill first paragraph when point is at an item or
  575. ;; a plain-list or a footnote reference.
  576. (should
  577. (equal "- A B"
  578. (org-test-with-temp-text "- A\n B"
  579. (let ((fill-column 20))
  580. (org-fill-element)
  581. (buffer-string)))))
  582. (should
  583. (equal "[fn:1] A B"
  584. (org-test-with-temp-text "[fn:1] A\nB"
  585. (let ((fill-column 20))
  586. (org-fill-element)
  587. (buffer-string)))))
  588. (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
  589. (let ((fill-column 20))
  590. (org-fill-element)
  591. (should (equal (buffer-string)
  592. "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
  593. ;; Fill contents of `comment-block' elements.
  594. (should
  595. (equal
  596. (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
  597. (let ((fill-column 20))
  598. (forward-line)
  599. (org-fill-element)
  600. (buffer-string)))
  601. "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
  602. ;; Fill `comment' elements.
  603. (should
  604. (equal " # A B"
  605. (org-test-with-temp-text " # A\n # B"
  606. (let ((fill-column 20))
  607. (org-fill-element)
  608. (buffer-string)))))
  609. ;; Do not mix consecutive comments when filling one of them.
  610. (should
  611. (equal "# A B\n\n# C"
  612. (org-test-with-temp-text "# A\n# B\n\n# C"
  613. (let ((fill-column 20))
  614. (org-fill-element)
  615. (buffer-string)))))
  616. ;; Use commented empty lines as separators when filling comments.
  617. (should
  618. (equal "# A B\n#\n# C"
  619. (org-test-with-temp-text "# A\n# B\n#\n# C"
  620. (let ((fill-column 20))
  621. (org-fill-element)
  622. (buffer-string)))))
  623. ;; Handle `adaptive-fill-regexp' in comments.
  624. (should
  625. (equal "# > a b"
  626. (org-test-with-temp-text "# > a\n# > b"
  627. (let ((fill-column 20)
  628. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  629. (org-fill-element)
  630. (buffer-string)))))
  631. ;; Do nothing at affiliated keywords.
  632. (should
  633. (equal "#+NAME: para\nSome\ntext."
  634. (org-test-with-temp-text "#+NAME: para\nSome\ntext."
  635. (let ((fill-column 20))
  636. (org-fill-element)
  637. (buffer-string)))))
  638. ;; Do not move point after table when filling a table.
  639. (should-not
  640. (org-test-with-temp-text "| a | b |\n| c | d |\n"
  641. (forward-char)
  642. (org-fill-element)
  643. (eobp)))
  644. ;; Do not fill "n" macro, with or without arguments, followed by
  645. ;; a dot or a closing parenthesis since it could be confused with
  646. ;; a numbered bullet.
  647. (should-not
  648. (equal "123456789\n{{{n}}}."
  649. (org-test-with-temp-text "123456789 {{{n}}}."
  650. (let ((fill-column 10))
  651. (org-fill-element)
  652. (buffer-string)))))
  653. (should-not
  654. (equal "123456789\n{{{n}}}\)"
  655. (org-test-with-temp-text "123456789 {{{n}}}\)"
  656. (let ((fill-column 10))
  657. (org-fill-element)
  658. (buffer-string)))))
  659. (should-not
  660. (equal "123456789\n{{{n()}}}."
  661. (org-test-with-temp-text "123456789 {{{n()}}}."
  662. (let ((fill-column 10))
  663. (org-fill-element)
  664. (buffer-string)))))
  665. (should-not
  666. (equal "123456789\n{{{n(counter)}}}."
  667. (org-test-with-temp-text "123456789 {{{n(counter)}}}."
  668. (let ((fill-column 10))
  669. (org-fill-element)
  670. (buffer-string))))))
  671. (ert-deftest test-org/auto-fill-function ()
  672. "Test auto-filling features."
  673. ;; Auto fill paragraph.
  674. (should
  675. (equal "12345\n7890"
  676. (org-test-with-temp-text "12345 7890"
  677. (let ((fill-column 5))
  678. (end-of-line)
  679. (org-auto-fill-function)
  680. (buffer-string)))))
  681. ;; Auto fill first paragraph in an item.
  682. (should
  683. (equal "- 12345\n 7890"
  684. (org-test-with-temp-text "- 12345 7890"
  685. (let ((fill-column 7))
  686. (end-of-line)
  687. (org-auto-fill-function)
  688. (buffer-string)))))
  689. ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
  690. (should
  691. (equal "> 12345\n 7890"
  692. (org-test-with-temp-text "> 12345 7890"
  693. (let ((fill-column 10)
  694. (adaptive-fill-regexp "[ \t]*>+[ \t]*")
  695. (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
  696. (end-of-line)
  697. (org-auto-fill-function)
  698. (buffer-string)))))
  699. (should
  700. (equal "> 12345\n> 12345\n> 7890"
  701. (org-test-with-temp-text "> 12345\n> 12345 7890"
  702. (let ((fill-column 10)
  703. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  704. (goto-char (point-max))
  705. (org-auto-fill-function)
  706. (buffer-string)))))
  707. (should-not
  708. (equal " 12345\n *12345\n *12345"
  709. (org-test-with-temp-text " 12345\n *12345 12345"
  710. (let ((fill-column 10)
  711. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  712. (goto-char (point-max))
  713. (org-auto-fill-function)
  714. (buffer-string)))))
  715. ;; Auto fill comments.
  716. (should
  717. (equal " # 12345\n # 7890"
  718. (org-test-with-temp-text " # 12345 7890"
  719. (let ((fill-column 10))
  720. (end-of-line)
  721. (org-auto-fill-function)
  722. (buffer-string)))))
  723. ;; A hash within a line isn't a comment.
  724. (should-not
  725. (equal "12345 # 7890\n# 1"
  726. (org-test-with-temp-text "12345 # 7890 1"
  727. (let ((fill-column 12))
  728. (end-of-line)
  729. (org-auto-fill-function)
  730. (buffer-string)))))
  731. ;; Correctly interpret empty prefix.
  732. (should-not
  733. (equal "# a\n# b\nRegular\n# paragraph"
  734. (org-test-with-temp-text "# a\n# b\nRegular paragraph"
  735. (let ((fill-column 12))
  736. (end-of-line 3)
  737. (org-auto-fill-function)
  738. (buffer-string)))))
  739. ;; Comment block: auto fill contents.
  740. (should
  741. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  742. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  743. (let ((fill-column 5))
  744. (forward-line)
  745. (end-of-line)
  746. (org-auto-fill-function)
  747. (buffer-string)))))
  748. (should
  749. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  750. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  751. (let ((fill-column 5))
  752. (forward-line)
  753. (end-of-line)
  754. (org-auto-fill-function)
  755. (buffer-string)))))
  756. ;; Do not fill if a new item could be created.
  757. (should-not
  758. (equal "12345\n- 90"
  759. (org-test-with-temp-text "12345 - 90"
  760. (let ((fill-column 5))
  761. (end-of-line)
  762. (org-auto-fill-function)
  763. (buffer-string)))))
  764. ;; Do not fill if a line break could be introduced.
  765. (should-not
  766. (equal "123\\\\\n7890"
  767. (org-test-with-temp-text "123\\\\ 7890"
  768. (let ((fill-column 6))
  769. (end-of-line)
  770. (org-auto-fill-function)
  771. (buffer-string)))))
  772. ;; Do not fill affiliated keywords.
  773. (should-not
  774. (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
  775. (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
  776. (let ((fill-column 20))
  777. (end-of-line)
  778. (org-auto-fill-function)
  779. (buffer-string))))))
  780. ;;; Indentation
  781. (ert-deftest test-org/indent-line ()
  782. "Test `org-indent-line' specifications."
  783. ;; Do not indent diary sexps, footnote definitions or headlines.
  784. (should
  785. (zerop
  786. (org-test-with-temp-text "%%(org-calendar-holiday)"
  787. (org-indent-line)
  788. (org-get-indentation))))
  789. (should
  790. (zerop
  791. (org-test-with-temp-text "[fn:1] fn"
  792. (let ((org-adapt-indentation t)) (org-indent-line))
  793. (org-get-indentation))))
  794. (should
  795. (zerop
  796. (org-test-with-temp-text "* H"
  797. (org-indent-line)
  798. (org-get-indentation))))
  799. ;; Do not indent before first headline.
  800. (should
  801. (zerop
  802. (org-test-with-temp-text ""
  803. (org-indent-line)
  804. (org-get-indentation))))
  805. ;; Indent according to headline level otherwise, unless
  806. ;; `org-adapt-indentation' is nil.
  807. (should
  808. (= 2
  809. (org-test-with-temp-text "* H\n<point>A"
  810. (let ((org-adapt-indentation t)) (org-indent-line))
  811. (org-get-indentation))))
  812. (should
  813. (= 2
  814. (org-test-with-temp-text "* H\n<point>\nA"
  815. (let ((org-adapt-indentation t)) (org-indent-line))
  816. (org-get-indentation))))
  817. (should
  818. (zerop
  819. (org-test-with-temp-text "* H\n<point>A"
  820. (let ((org-adapt-indentation nil)) (org-indent-line))
  821. (org-get-indentation))))
  822. ;; Indenting preserves point position.
  823. (should
  824. (org-test-with-temp-text "* H\nA<point>B"
  825. (let ((org-adapt-indentation t)) (org-indent-line))
  826. (looking-at "B")))
  827. ;; Do not change indentation at an item or a LaTeX environment.
  828. (should
  829. (= 1
  830. (org-test-with-temp-text "* H\n<point> - A"
  831. (let ((org-adapt-indentation t)) (org-indent-line))
  832. (org-get-indentation))))
  833. (should
  834. (= 1
  835. (org-test-with-temp-text
  836. "\\begin{equation}\n <point>1+1=2\n\\end{equation}"
  837. (org-indent-line)
  838. (org-get-indentation))))
  839. ;; On blank lines at the end of a list, indent like last element
  840. ;; within it if the line is still in the list. If the last element
  841. ;; is an item, indent like its contents. Otherwise, indent like the
  842. ;; whole list.
  843. (should
  844. (= 4
  845. (org-test-with-temp-text "* H\n- A\n - AA\n<point>"
  846. (let ((org-adapt-indentation t)) (org-indent-line))
  847. (org-get-indentation))))
  848. (should
  849. (= 4
  850. (org-test-with-temp-text "* H\n- A\n -\n\n<point>"
  851. (let ((org-adapt-indentation t)) (org-indent-line))
  852. (org-get-indentation))))
  853. (should
  854. (zerop
  855. (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n<point>"
  856. (let ((org-adapt-indentation t)) (org-indent-line))
  857. (org-get-indentation))))
  858. (should
  859. (= 4
  860. (org-test-with-temp-text "* H\n- A\n - \n<point>"
  861. (let ((org-adapt-indentation t)) (org-indent-line))
  862. (org-get-indentation))))
  863. (should
  864. (= 4
  865. (org-test-with-temp-text
  866. "* H\n - \n #+BEGIN_SRC emacs-lisp\n t\n #+END_SRC\n<point>"
  867. (let ((org-adapt-indentation t)) (org-indent-line))
  868. (org-get-indentation))))
  869. (should
  870. (= 2
  871. (org-test-with-temp-text "- A\n B\n\n<point>"
  872. (let ((org-adapt-indentation nil)) (org-indent-line))
  873. (org-get-indentation))))
  874. (should
  875. (= 2
  876. (org-test-with-temp-text
  877. "- A\n \begin{cases} 1 + 1\n \end{cases}\n\n<point>"
  878. (let ((org-adapt-indentation nil)) (org-indent-line))
  879. (org-get-indentation))))
  880. ;; Likewise, on a blank line at the end of a footnote definition,
  881. ;; indent at column 0 if line belongs to the definition. Otherwise,
  882. ;; indent like the definition itself.
  883. (should
  884. (zerop
  885. (org-test-with-temp-text "* H\n[fn:1] Definition\n<point>"
  886. (let ((org-adapt-indentation t)) (org-indent-line))
  887. (org-get-indentation))))
  888. (should
  889. (zerop
  890. (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n<point>"
  891. (let ((org-adapt-indentation t)) (org-indent-line))
  892. (org-get-indentation))))
  893. ;; After the end of the contents of a greater element, indent like
  894. ;; the beginning of the element.
  895. (should
  896. (= 1
  897. (org-test-with-temp-text
  898. " #+BEGIN_CENTER\n Contents\n<point>#+END_CENTER"
  899. (org-indent-line)
  900. (org-get-indentation))))
  901. ;; On blank lines after a paragraph, indent like its last non-empty
  902. ;; line.
  903. (should
  904. (= 1
  905. (org-test-with-temp-text " Paragraph\n\n<point>"
  906. (org-indent-line)
  907. (org-get-indentation))))
  908. ;; At the first line of an element, indent like previous element's
  909. ;; first line, ignoring footnotes definitions and inline tasks, or
  910. ;; according to parent.
  911. (should
  912. (= 2
  913. (org-test-with-temp-text "A\n\n B\n\nC<point>"
  914. (org-indent-line)
  915. (org-get-indentation))))
  916. (should
  917. (= 1
  918. (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC<point>"
  919. (org-indent-line)
  920. (org-get-indentation))))
  921. (should
  922. (= 1
  923. (org-test-with-temp-text
  924. " #+BEGIN_CENTER\n<point> Contents\n#+END_CENTER"
  925. (org-indent-line)
  926. (org-get-indentation))))
  927. ;; Within code part of a source block, use language major mode if
  928. ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
  929. ;; according to line above.
  930. (should
  931. (= 6
  932. (org-test-with-temp-text
  933. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  934. (let ((org-src-tab-acts-natively t)
  935. (org-edit-src-content-indentation 0))
  936. (org-indent-line))
  937. (org-get-indentation))))
  938. (should
  939. (= 1
  940. (org-test-with-temp-text
  941. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  942. (let ((org-src-tab-acts-natively nil)
  943. (org-edit-src-content-indentation 0))
  944. (org-indent-line))
  945. (org-get-indentation))))
  946. ;; Otherwise, indent like the first non-blank line above.
  947. (should
  948. (zerop
  949. (org-test-with-temp-text
  950. "#+BEGIN_CENTER\nline1\n\n<point> line2\n#+END_CENTER"
  951. (org-indent-line)
  952. (org-get-indentation))))
  953. ;; Align node properties according to `org-property-format'. Handle
  954. ;; nicely empty values.
  955. (should
  956. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  957. (org-test-with-temp-text
  958. "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
  959. (let ((org-property-format "%-10s %s")) (org-indent-line))
  960. (buffer-string))))
  961. (should
  962. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  963. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
  964. (let ((org-property-format "%-10s %s")) (org-indent-line))
  965. (buffer-string)))))
  966. (ert-deftest test-org/indent-region ()
  967. "Test `org-indent-region' specifications."
  968. ;; Indent paragraph.
  969. (should
  970. (equal "A\nB\nC"
  971. (org-test-with-temp-text " A\nB\n C"
  972. (org-indent-region (point-min) (point-max))
  973. (buffer-string))))
  974. ;; Indent greater elements along with their contents.
  975. (should
  976. (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
  977. (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
  978. (org-indent-region (point-min) (point-max))
  979. (buffer-string))))
  980. ;; Ignore contents of verse blocks. Only indent block delimiters.
  981. (should
  982. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  983. (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  984. (org-indent-region (point-min) (point-max))
  985. (buffer-string))))
  986. (should
  987. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  988. (org-test-with-temp-text " #+BEGIN_VERSE\n A\n B\n #+END_VERSE"
  989. (org-indent-region (point-min) (point-max))
  990. (buffer-string))))
  991. ;; Indent example blocks as a single block, unless indentation
  992. ;; should be preserved. In this case only indent the block markers.
  993. (should
  994. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  995. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  996. (org-indent-region (point-min) (point-max))
  997. (buffer-string))))
  998. (should
  999. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1000. (org-test-with-temp-text " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1001. (org-indent-region (point-min) (point-max))
  1002. (buffer-string))))
  1003. (should
  1004. (equal "#+BEGIN_EXAMPLE -i\n A\n B\n#+END_EXAMPLE"
  1005. (org-test-with-temp-text
  1006. " #+BEGIN_EXAMPLE -i\n A\n B\n #+END_EXAMPLE"
  1007. (org-indent-region (point-min) (point-max))
  1008. (buffer-string))))
  1009. (should
  1010. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1011. (org-test-with-temp-text
  1012. " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1013. (let ((org-src-preserve-indentation t))
  1014. (org-indent-region (point-min) (point-max)))
  1015. (buffer-string))))
  1016. ;; Treat export blocks as a whole.
  1017. (should
  1018. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1019. (org-test-with-temp-text "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1020. (org-indent-region (point-min) (point-max))
  1021. (buffer-string))))
  1022. (should
  1023. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1024. (org-test-with-temp-text
  1025. " #+BEGIN_EXPORT latex\n A\n B\n #+END_EXPORT"
  1026. (org-indent-region (point-min) (point-max))
  1027. (buffer-string))))
  1028. ;; Indent according to mode if `org-src-tab-acts-natively' is
  1029. ;; non-nil. Otherwise, do not indent code at all.
  1030. (should
  1031. (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
  1032. (org-test-with-temp-text
  1033. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1034. (let ((org-src-tab-acts-natively t)
  1035. (org-edit-src-content-indentation 0))
  1036. (org-indent-region (point-min) (point-max)))
  1037. (buffer-string))))
  1038. (should
  1039. (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1040. (org-test-with-temp-text
  1041. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1042. (let ((org-src-tab-acts-natively nil)
  1043. (org-edit-src-content-indentation 0))
  1044. (org-indent-region (point-min) (point-max)))
  1045. (buffer-string))))
  1046. ;; Align node properties according to `org-property-format'. Handle
  1047. ;; nicely empty values.
  1048. (should
  1049. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1050. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
  1051. (let ((org-property-format "%-10s %s")
  1052. (org-adapt-indentation nil))
  1053. (org-indent-region (point) (point-max)))
  1054. (buffer-string))))
  1055. (should
  1056. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1057. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
  1058. (let ((org-property-format "%-10s %s")
  1059. (org-adapt-indentation nil))
  1060. (org-indent-region (point) (point-max)))
  1061. (buffer-string))))
  1062. ;; Indent plain lists.
  1063. (should
  1064. (equal "- A\n B\n - C\n\n D"
  1065. (org-test-with-temp-text "- A\n B\n - C\n\n D"
  1066. (org-indent-region (point-min) (point-max))
  1067. (buffer-string))))
  1068. (should
  1069. (equal "- A\n\n- B"
  1070. (org-test-with-temp-text " - A\n\n - B"
  1071. (org-indent-region (point-min) (point-max))
  1072. (buffer-string))))
  1073. ;; Indent footnote definitions.
  1074. (should
  1075. (equal "[fn:1] Definition\n\nDefinition"
  1076. (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
  1077. (org-indent-region (point-min) (point-max))
  1078. (buffer-string))))
  1079. ;; Special case: Start indenting on a blank line.
  1080. (should
  1081. (equal "\nParagraph"
  1082. (org-test-with-temp-text "\n Paragraph"
  1083. (org-indent-region (point-min) (point-max))
  1084. (buffer-string)))))
  1085. ;;; Editing
  1086. (ert-deftest test-org/delete-indentation ()
  1087. "Test `org-delete-indentation' specifications."
  1088. ;; Regular test.
  1089. (should (equal "foo bar"
  1090. (org-test-with-temp-text
  1091. "foo \n bar<point>"
  1092. (org-delete-indentation)
  1093. (buffer-string))))
  1094. ;; With optional argument.
  1095. (should (equal "foo bar"
  1096. (org-test-with-temp-text
  1097. "foo<point> \n bar"
  1098. (org-delete-indentation t)
  1099. (buffer-string))))
  1100. ;; At headline text should be appended to the headline text.
  1101. (should
  1102. (equal"* foo bar :tag:"
  1103. (let (org-auto-align-tags)
  1104. (org-test-with-temp-text
  1105. "* foo :tag:\n bar<point>"
  1106. (org-delete-indentation)
  1107. (buffer-string)))))
  1108. (should
  1109. (equal "* foo bar :tag:"
  1110. (let (org-auto-align-tags)
  1111. (org-test-with-temp-text
  1112. "* foo <point>:tag:\n bar"
  1113. (org-delete-indentation t)
  1114. (buffer-string))))))
  1115. (ert-deftest test-org/return ()
  1116. "Test `org-return' specifications."
  1117. ;; Regular test.
  1118. (should
  1119. (equal "Para\ngraph"
  1120. (org-test-with-temp-text "Para<point>graph"
  1121. (org-return)
  1122. (buffer-string))))
  1123. ;; With optional argument, indent line.
  1124. (should
  1125. (equal " Para\n graph"
  1126. (org-test-with-temp-text " Para<point>graph"
  1127. (org-return t)
  1128. (buffer-string))))
  1129. ;; On a table, call `org-table-next-row'.
  1130. (should
  1131. (org-test-with-temp-text "| <point>a |\n| b |"
  1132. (org-return)
  1133. (looking-at-p "b")))
  1134. ;; Open link or timestamp under point when `org-return-follows-link'
  1135. ;; is non-nil.
  1136. (should
  1137. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1138. (let ((org-return-follows-link t)
  1139. (org-link-search-must-match-exact-headline nil))
  1140. (org-return))
  1141. (looking-at-p "<<target>>")))
  1142. (should-not
  1143. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1144. (let ((org-return-follows-link nil)) (org-return))
  1145. (looking-at-p "<<target>>")))
  1146. (should
  1147. (org-test-with-temp-text "* [[b][a<point>]]\n* b"
  1148. (let ((org-return-follows-link t)) (org-return))
  1149. (looking-at-p "* b")))
  1150. (should
  1151. (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
  1152. (let ((org-return-follows-link t)
  1153. (org-link-search-must-match-exact-headline nil))
  1154. (org-return))
  1155. (looking-at-p "<<target>>")))
  1156. (should-not
  1157. (org-test-with-temp-text "Link [[target]]<point> <<target>>"
  1158. (let ((org-return-follows-link t)
  1159. (org-link-search-must-match-exact-headline nil))
  1160. (org-return))
  1161. (looking-at-p "<<target>>")))
  1162. ;; When `org-return-follows-link' is non-nil, tolerate links and
  1163. ;; timestamps in comments, node properties, etc.
  1164. (should
  1165. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1166. (let ((org-return-follows-link t)
  1167. (org-link-search-must-match-exact-headline nil))
  1168. (org-return))
  1169. (looking-at-p "<<target>>")))
  1170. (should-not
  1171. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1172. (let ((org-return-follows-link nil)) (org-return))
  1173. (looking-at-p "<<target>>")))
  1174. (should-not
  1175. (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
  1176. (let ((org-return-follows-link t)
  1177. (org-link-search-must-match-exact-headline nil))
  1178. (org-return))
  1179. (looking-at-p "<<target>>")))
  1180. ;; Non-nil `org-return-follows-link' ignores read-only state of
  1181. ;; a buffer.
  1182. (should
  1183. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1184. (let ((org-return-follows-link t)
  1185. (org-link-search-must-match-exact-headline nil))
  1186. (setq buffer-read-only t)
  1187. (call-interactively #'org-return))
  1188. (looking-at-p "<<target>>")))
  1189. ;; `org-return-follows-link' handle multi-line lines.
  1190. (should
  1191. (org-test-with-temp-text
  1192. "[[target][This is a very\n long description<point>]]\n <<target>>"
  1193. (let ((org-return-follows-link t)
  1194. (org-link-search-must-match-exact-headline nil))
  1195. (org-return))
  1196. (looking-at-p "<<target>>")))
  1197. (should-not
  1198. (org-test-with-temp-text
  1199. "[[target][This is a very\n long description]]<point>\n <<target>>"
  1200. (let ((org-return-follows-link t)
  1201. (org-link-search-must-match-exact-headline nil))
  1202. (org-return))
  1203. (looking-at-p "<<target>>")))
  1204. ;; However, do not open link when point is in a table.
  1205. (should
  1206. (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
  1207. (let ((org-return-follows-link t)) (org-return))
  1208. (looking-at-p "between")))
  1209. ;; Special case: in a list, when indenting, do not break structure.
  1210. (should
  1211. (equal "- A\n B"
  1212. (org-test-with-temp-text "- A <point>B"
  1213. (org-return t)
  1214. (buffer-string))))
  1215. (should
  1216. (equal "- A\n\n- B"
  1217. (org-test-with-temp-text "- A\n<point>- B"
  1218. (org-return t)
  1219. (buffer-string))))
  1220. ;; On tags part of a headline, add a newline below it instead of
  1221. ;; breaking it.
  1222. (should
  1223. (equal "* H :tag:\n"
  1224. (org-test-with-temp-text "* H :<point>tag:"
  1225. (org-return)
  1226. (buffer-string))))
  1227. ;; Before headline text, add a newline below it instead of breaking
  1228. ;; it.
  1229. (should
  1230. (equal "* TODO H :tag:\n"
  1231. (org-test-with-temp-text "* <point>TODO H :tag:"
  1232. (org-return)
  1233. (buffer-string))))
  1234. (should
  1235. (equal "* TODO [#B] H :tag:\n"
  1236. (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
  1237. (org-return)
  1238. (buffer-string))))
  1239. (should ;TODO are case-sensitive
  1240. (equal "* \nTodo"
  1241. (org-test-with-temp-text "* <point>Todo"
  1242. (org-return)
  1243. (buffer-string))))
  1244. ;; At headline text, break headline text but preserve tags.
  1245. (should
  1246. (equal "* TODO [#B] foo :tag:\nbar"
  1247. (let (org-auto-align-tags)
  1248. (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
  1249. (org-return)
  1250. (buffer-string)))))
  1251. ;; At bol of headline insert newline.
  1252. (should
  1253. (equal "\n* h"
  1254. (org-test-with-temp-text "<point>* h"
  1255. (org-return)
  1256. (buffer-string))))
  1257. ;; Refuse to leave invalid headline in buffer.
  1258. (should
  1259. (equal "* h\n"
  1260. (org-test-with-temp-text "*<point> h"
  1261. (org-return)
  1262. (buffer-string))))
  1263. ;; Before first column or after last one in a table, split the
  1264. ;; table.
  1265. (should
  1266. (equal "| a |\n\n| b |"
  1267. (org-test-with-temp-text "| a |\n<point>| b |"
  1268. (org-return)
  1269. (buffer-string))))
  1270. (should
  1271. (equal "| a |\n\n| b |"
  1272. (org-test-with-temp-text "| a |<point>\n| b |"
  1273. (org-return)
  1274. (buffer-string))))
  1275. ;; Do not auto-fill on hitting <RET> inside a property drawer.
  1276. (should
  1277. (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:"
  1278. (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:"
  1279. (setq-local fill-column 10)
  1280. (auto-fill-mode 1)
  1281. (org-return)
  1282. (buffer-string)))))
  1283. (ert-deftest test-org/with-electric-indent ()
  1284. "Test RET and C-j specifications with `electric-indent-mode' on."
  1285. ;; Call commands interactively, since this is how `newline' knows it
  1286. ;; must run `post-self-insert-hook'.
  1287. ;;
  1288. ;; RET, like `newline', should indent.
  1289. (should
  1290. (equal " Para\n graph"
  1291. (org-test-with-temp-text " Para<point>graph"
  1292. (electric-indent-local-mode 1)
  1293. (call-interactively 'org-return)
  1294. (buffer-string))))
  1295. (should
  1296. (equal "- item1\n item2"
  1297. (org-test-with-temp-text "- item1<point>item2"
  1298. (electric-indent-local-mode 1)
  1299. (call-interactively 'org-return)
  1300. (buffer-string))))
  1301. (should
  1302. (equal "* heading\n body"
  1303. (org-test-with-temp-text "* heading<point>body"
  1304. (electric-indent-local-mode 1)
  1305. (call-interactively 'org-return)
  1306. (buffer-string))))
  1307. ;; C-j, like `electric-newline-and-maybe-indent', should not indent.
  1308. (should
  1309. (equal " Para\ngraph"
  1310. (org-test-with-temp-text " Para<point>graph"
  1311. (electric-indent-local-mode 1)
  1312. (call-interactively 'org-return-and-maybe-indent)
  1313. (buffer-string))))
  1314. (should
  1315. (equal "- item1\nitem2"
  1316. (org-test-with-temp-text "- item1<point>item2"
  1317. (electric-indent-local-mode 1)
  1318. (call-interactively 'org-return-and-maybe-indent)
  1319. (buffer-string))))
  1320. (should
  1321. (equal "* heading\nbody"
  1322. (org-test-with-temp-text "* heading<point>body"
  1323. (electric-indent-local-mode 1)
  1324. (call-interactively 'org-return-and-maybe-indent)
  1325. (buffer-string)))))
  1326. (ert-deftest test-org/without-electric-indent ()
  1327. "Test RET and C-j specifications with `electric-indent-mode' off."
  1328. ;; Call commands interactively, since this is how `newline' knows it
  1329. ;; must run `post-self-insert-hook'.
  1330. ;;
  1331. ;; RET, like `newline', should not indent.
  1332. (should
  1333. (equal " Para\ngraph"
  1334. (org-test-with-temp-text " Para<point>graph"
  1335. (electric-indent-local-mode 0)
  1336. (call-interactively 'org-return)
  1337. (buffer-string))))
  1338. (should
  1339. (equal "- item1\nitem2"
  1340. (org-test-with-temp-text "- item1<point>item2"
  1341. (electric-indent-local-mode 0)
  1342. (call-interactively 'org-return)
  1343. (buffer-string))))
  1344. (should
  1345. (equal "* heading\nbody"
  1346. (org-test-with-temp-text "* heading<point>body"
  1347. (electric-indent-local-mode 0)
  1348. (call-interactively 'org-return)
  1349. (buffer-string))))
  1350. ;; C-j, like `electric-newline-and-maybe-indent', should indent.
  1351. (should
  1352. (equal " Para\n graph"
  1353. (org-test-with-temp-text " Para<point>graph"
  1354. (electric-indent-local-mode 0)
  1355. (call-interactively 'org-return-and-maybe-indent)
  1356. (buffer-string))))
  1357. (should
  1358. (equal "- item1\n item2"
  1359. (org-test-with-temp-text "- item1<point>item2"
  1360. (electric-indent-local-mode 0)
  1361. (call-interactively 'org-return-and-maybe-indent)
  1362. (buffer-string))))
  1363. (should
  1364. (equal "* heading\n body"
  1365. (org-test-with-temp-text "* heading<point>body"
  1366. (electric-indent-local-mode 0)
  1367. (call-interactively 'org-return-and-maybe-indent)
  1368. (buffer-string)))))
  1369. (ert-deftest test-org/meta-return ()
  1370. "Test M-RET (`org-meta-return') specifications."
  1371. ;; In a table field insert a row above.
  1372. (should
  1373. (org-test-with-temp-text "| a |"
  1374. (forward-char)
  1375. (org-meta-return)
  1376. (forward-line -1)
  1377. (looking-at "| |$")))
  1378. ;; In a paragraph change current line into a header.
  1379. (should
  1380. (org-test-with-temp-text "a"
  1381. (org-meta-return)
  1382. (beginning-of-line)
  1383. (looking-at "\* a$")))
  1384. ;; In an item insert an item, in this case above.
  1385. (should
  1386. (org-test-with-temp-text "- a"
  1387. (org-meta-return)
  1388. (beginning-of-line)
  1389. (looking-at "- $")))
  1390. ;; In a drawer and item insert an item, in this case above.
  1391. (should
  1392. (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
  1393. (forward-line)
  1394. (org-meta-return)
  1395. (beginning-of-line)
  1396. (looking-at "- $"))))
  1397. (ert-deftest test-org/insert-heading ()
  1398. "Test `org-insert-heading' specifications."
  1399. ;; In an empty buffer, insert a new headline.
  1400. (should
  1401. (equal "* "
  1402. (org-test-with-temp-text ""
  1403. (org-insert-heading)
  1404. (buffer-string))))
  1405. ;; At the beginning of a line, turn it into a headline.
  1406. (should
  1407. (equal "* P"
  1408. (org-test-with-temp-text "<point>P"
  1409. (org-insert-heading)
  1410. (buffer-string))))
  1411. ;; In the middle of a line, split the line if allowed, otherwise,
  1412. ;; insert the headline at its end.
  1413. (should
  1414. (equal "Para\n* graph"
  1415. (org-test-with-temp-text "Para<point>graph"
  1416. (let ((org-M-RET-may-split-line '((default . t))))
  1417. (org-insert-heading))
  1418. (buffer-string))))
  1419. (should
  1420. (equal "Paragraph\n* "
  1421. (org-test-with-temp-text "Para<point>graph"
  1422. (let ((org-M-RET-may-split-line '((default . nil))))
  1423. (org-insert-heading))
  1424. (buffer-string))))
  1425. ;; At the beginning of a headline, create one above.
  1426. (should
  1427. (equal "* \n* H"
  1428. (org-test-with-temp-text "* H"
  1429. (org-insert-heading)
  1430. (buffer-string))))
  1431. ;; In the middle of a headline, split it if allowed.
  1432. (should
  1433. (equal "* H\n* 1"
  1434. (org-test-with-temp-text "* H<point>1"
  1435. (let ((org-M-RET-may-split-line '((headline . t))))
  1436. (org-insert-heading))
  1437. (buffer-string))))
  1438. (should
  1439. (equal "* H1\n* "
  1440. (org-test-with-temp-text "* H<point>1"
  1441. (let ((org-M-RET-may-split-line '((headline . nil))))
  1442. (org-insert-heading))
  1443. (buffer-string))))
  1444. ;; However, splitting cannot happen on TODO keywords, priorities or
  1445. ;; tags.
  1446. (should
  1447. (equal "* TODO H1\n* "
  1448. (org-test-with-temp-text "* TO<point>DO H1"
  1449. (let ((org-M-RET-may-split-line '((headline . t))))
  1450. (org-insert-heading))
  1451. (buffer-string))))
  1452. (should
  1453. (equal "* [#A] H1\n* "
  1454. (org-test-with-temp-text "* [#<point>A] H1"
  1455. (let ((org-M-RET-may-split-line '((headline . t))))
  1456. (org-insert-heading))
  1457. (buffer-string))))
  1458. (should
  1459. (equal "* H1 :tag:\n* "
  1460. (org-test-with-temp-text "* H1 :ta<point>g:"
  1461. (let ((org-M-RET-may-split-line '((headline . t))))
  1462. (org-insert-heading))
  1463. (buffer-string))))
  1464. ;; New headline level depends on the level of the headline above.
  1465. (should
  1466. (equal "** H\n** P"
  1467. (org-test-with-temp-text "** H\n<point>P"
  1468. (org-insert-heading)
  1469. (buffer-string))))
  1470. (should
  1471. (equal "** H\nPara\n** graph"
  1472. (org-test-with-temp-text "** H\nPara<point>graph"
  1473. (let ((org-M-RET-may-split-line '((default . t))))
  1474. (org-insert-heading))
  1475. (buffer-string))))
  1476. (should
  1477. (equal "** \n** H"
  1478. (org-test-with-temp-text "** H"
  1479. (org-insert-heading)
  1480. (buffer-string))))
  1481. ;; When called with one universal argument, insert a new headline at
  1482. ;; the end of the current subtree, independently on the position of
  1483. ;; point.
  1484. (should
  1485. (equal
  1486. "* H1\n** H2\n* "
  1487. (org-test-with-temp-text "* H1\n** H2"
  1488. (let ((org-insert-heading-respect-content nil))
  1489. (org-insert-heading '(4)))
  1490. (buffer-string))))
  1491. (should
  1492. (equal
  1493. "* H1\n** H2\n* "
  1494. (org-test-with-temp-text "* H<point>1\n** H2"
  1495. (let ((org-insert-heading-respect-content nil))
  1496. (org-insert-heading '(4)))
  1497. (buffer-string))))
  1498. ;; When called with two universal arguments, insert a new headline
  1499. ;; at the end of the grandparent subtree.
  1500. (should
  1501. (equal "* H1\n** H3\n- item\n** H2\n** "
  1502. (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
  1503. (let ((org-insert-heading-respect-content nil))
  1504. (org-insert-heading '(16)))
  1505. (buffer-string))))
  1506. ;; When optional TOP-LEVEL argument is non-nil, always insert
  1507. ;; a level 1 heading.
  1508. (should
  1509. (equal "* H1\n** H2\n* "
  1510. (org-test-with-temp-text "* H1\n** H2<point>"
  1511. (org-insert-heading nil nil t)
  1512. (buffer-string))))
  1513. (should
  1514. (equal "* H1\n- item\n* "
  1515. (org-test-with-temp-text "* H1\n- item<point>"
  1516. (org-insert-heading nil nil t)
  1517. (buffer-string))))
  1518. ;; Obey `org-blank-before-new-entry'.
  1519. (should
  1520. (equal "* H1\n\n* "
  1521. (org-test-with-temp-text "* H1<point>"
  1522. (let ((org-blank-before-new-entry '((heading . t))))
  1523. (org-insert-heading))
  1524. (buffer-string))))
  1525. (should
  1526. (equal "* H1\n* "
  1527. (org-test-with-temp-text "* H1<point>"
  1528. (let ((org-blank-before-new-entry '((heading . nil))))
  1529. (org-insert-heading))
  1530. (buffer-string))))
  1531. (should
  1532. (equal "* H1\n* H2\n* "
  1533. (org-test-with-temp-text "* H1\n* H2<point>"
  1534. (let ((org-blank-before-new-entry '((heading . auto))))
  1535. (org-insert-heading))
  1536. (buffer-string))))
  1537. (should
  1538. (equal "* H1\n\n* H2\n\n* "
  1539. (org-test-with-temp-text "* H1\n\n* H2<point>"
  1540. (let ((org-blank-before-new-entry '((heading . auto))))
  1541. (org-insert-heading))
  1542. (buffer-string))))
  1543. ;; Corner case: correctly insert a headline after an empty one.
  1544. (should
  1545. (equal "* \n* "
  1546. (org-test-with-temp-text "* <point>"
  1547. (org-insert-heading)
  1548. (buffer-string))))
  1549. (should
  1550. (org-test-with-temp-text "* <point>\n"
  1551. (org-insert-heading)
  1552. (looking-at-p "\n\\'")))
  1553. ;; Do not insert spurious headlines when inserting a new headline.
  1554. (should
  1555. (equal "* H1\n* H2\n* \n"
  1556. (org-test-with-temp-text "* H1\n* H2<point>\n"
  1557. (org-insert-heading)
  1558. (buffer-string))))
  1559. ;; Preserve visibility at beginning of line. In particular, when
  1560. ;; removing spurious blank lines, do not visually merge heading with
  1561. ;; the line visible above.
  1562. (should-not
  1563. (org-test-with-temp-text "* H1<point>\nContents\n\n* H2\n"
  1564. (org-overview)
  1565. (let ((org-blank-before-new-entry '((heading . nil))))
  1566. (org-insert-heading '(4)))
  1567. (invisible-p (line-end-position 0))))
  1568. ;; Properly handle empty lines when forcing a headline below current
  1569. ;; one.
  1570. (should
  1571. (equal "* H1\n\n* H\n\n* "
  1572. (org-test-with-temp-text "* H1\n\n* H<point>"
  1573. (let ((org-blank-before-new-entry '((heading . t))))
  1574. (org-insert-heading '(4))
  1575. (buffer-string))))))
  1576. (ert-deftest test-org/insert-todo-heading-respect-content ()
  1577. "Test `org-insert-todo-heading-respect-content' specifications."
  1578. ;; Create a TODO heading.
  1579. (should
  1580. (org-test-with-temp-text "* H1\n Body"
  1581. (org-insert-todo-heading-respect-content)
  1582. (nth 2 (org-heading-components))))
  1583. ;; Add headline at the end of the first subtree
  1584. (should
  1585. (equal
  1586. "* TODO "
  1587. (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
  1588. (org-insert-todo-heading-respect-content)
  1589. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1590. ;; In a list, do not create a new item.
  1591. (should
  1592. (equal
  1593. "* TODO "
  1594. (org-test-with-temp-text "* H\n- an item\n- another one"
  1595. (search-forward "an ")
  1596. (org-insert-todo-heading-respect-content)
  1597. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1598. ;; Use the same TODO keyword as current heading.
  1599. (should
  1600. (equal
  1601. "* TODO \n"
  1602. (org-test-with-temp-text "* TODO\n** WAITING\n"
  1603. (org-insert-todo-heading-respect-content)
  1604. (buffer-substring-no-properties (line-beginning-position) (point-max))))))
  1605. (ert-deftest test-org/clone-with-time-shift ()
  1606. "Test `org-clone-subtree-with-time-shift'."
  1607. ;; Raise an error before first heading.
  1608. (should-error
  1609. (org-test-with-temp-text ""
  1610. (org-clone-subtree-with-time-shift 1)))
  1611. ;; Raise an error on invalid number of clones.
  1612. (should-error
  1613. (org-test-with-temp-text "* Clone me"
  1614. (org-clone-subtree-with-time-shift -1)))
  1615. ;; Clone non-repeating once.
  1616. (should
  1617. (equal "\
  1618. * H1\n<2015-06-21>
  1619. * H1\n<2015-06-23>
  1620. "
  1621. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1622. (org-clone-subtree-with-time-shift 1 "+2d")
  1623. (replace-regexp-in-string
  1624. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1625. nil nil 1))))
  1626. ;; Clone repeating once.
  1627. (should
  1628. (equal "\
  1629. * H1\n<2015-06-21>
  1630. * H1\n<2015-06-23>
  1631. * H1\n<2015-06-25 +1w>
  1632. "
  1633. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1634. (org-clone-subtree-with-time-shift 1 "+2d")
  1635. (replace-regexp-in-string
  1636. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1637. nil nil 1))))
  1638. ;; Clone repeating once in backward.
  1639. (should
  1640. (equal "\
  1641. * H1\n<2015-06-21>
  1642. * H1\n<2015-06-19>
  1643. * H1\n<2015-06-17 +1w>
  1644. "
  1645. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1646. (org-clone-subtree-with-time-shift 1 "-2d")
  1647. (replace-regexp-in-string
  1648. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1649. nil nil 1))))
  1650. ;; Clone non-repeating zero times.
  1651. (should
  1652. (equal "\
  1653. * H1\n<2015-06-21>
  1654. "
  1655. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1656. (org-clone-subtree-with-time-shift 0 "+2d")
  1657. (replace-regexp-in-string
  1658. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1659. nil nil 1))))
  1660. ;; Clone repeating "zero" times.
  1661. (should
  1662. (equal "\
  1663. * H1\n<2015-06-21>
  1664. * H1\n<2015-06-23 +1w>
  1665. "
  1666. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1667. (org-clone-subtree-with-time-shift 0 "+2d")
  1668. (replace-regexp-in-string
  1669. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1670. nil nil 1))))
  1671. ;; Clone with blank SHIFT argument.
  1672. (should
  1673. (string-prefix-p
  1674. "* H <2012-03-29"
  1675. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1676. (org-clone-subtree-with-time-shift 1 "")
  1677. (buffer-substring-no-properties (line-beginning-position 2)
  1678. (line-end-position 2)))))
  1679. ;; Find time stamps before point. If SHIFT is not specified, ask
  1680. ;; for a time shift.
  1681. (should
  1682. (string-prefix-p
  1683. "* H <2012-03-30"
  1684. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1685. (org-clone-subtree-with-time-shift 1 "+1d")
  1686. (buffer-substring-no-properties (line-beginning-position 2)
  1687. (line-end-position 2)))))
  1688. (should
  1689. (string-prefix-p
  1690. "* H <2014-03-05"
  1691. (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
  1692. (cl-letf (((symbol-function 'read-from-minibuffer)
  1693. (lambda (&rest args) "+1d")))
  1694. (org-clone-subtree-with-time-shift 1))
  1695. (buffer-substring-no-properties (line-beginning-position 2)
  1696. (line-end-position 2))))))
  1697. ;;; Fixed-Width Areas
  1698. (ert-deftest test-org/toggle-fixed-width ()
  1699. "Test `org-toggle-fixed-width' specifications."
  1700. ;; No region: Toggle on fixed-width marker in paragraphs.
  1701. (should
  1702. (equal ": A"
  1703. (org-test-with-temp-text "A"
  1704. (org-toggle-fixed-width)
  1705. (buffer-string))))
  1706. ;; No region: Toggle off fixed-width markers in fixed-width areas.
  1707. (should
  1708. (equal "A"
  1709. (org-test-with-temp-text ": A"
  1710. (org-toggle-fixed-width)
  1711. (buffer-string))))
  1712. ;; No region: Toggle on marker in blank lines after elements or just
  1713. ;; after a headline.
  1714. (should
  1715. (equal "* H\n: "
  1716. (org-test-with-temp-text "* H\n"
  1717. (forward-line)
  1718. (org-toggle-fixed-width)
  1719. (buffer-string))))
  1720. (should
  1721. (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
  1722. (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
  1723. (goto-char (point-max))
  1724. (org-toggle-fixed-width)
  1725. (buffer-string))))
  1726. ;; No region: Toggle on marker in front of one line elements (e.g.,
  1727. ;; headlines, clocks)
  1728. (should
  1729. (equal ": * Headline"
  1730. (org-test-with-temp-text "* Headline"
  1731. (org-toggle-fixed-width)
  1732. (buffer-string))))
  1733. (should
  1734. (equal ": #+KEYWORD: value"
  1735. (org-test-with-temp-text "#+KEYWORD: value"
  1736. (org-toggle-fixed-width)
  1737. (buffer-string))))
  1738. ;; No region: error in other situations.
  1739. (should-error
  1740. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
  1741. (forward-line)
  1742. (org-toggle-fixed-width)
  1743. (buffer-string)))
  1744. ;; No region: Indentation is preserved.
  1745. (should
  1746. (equal "- A\n : B"
  1747. (org-test-with-temp-text "- A\n B"
  1748. (forward-line)
  1749. (org-toggle-fixed-width)
  1750. (buffer-string))))
  1751. ;; Region: If it contains only fixed-width elements and blank lines,
  1752. ;; toggle off fixed-width markup.
  1753. (should
  1754. (equal "A\n\nB"
  1755. (org-test-with-temp-text ": A\n\n: B"
  1756. (transient-mark-mode 1)
  1757. (push-mark (point) t t)
  1758. (goto-char (point-max))
  1759. (org-toggle-fixed-width)
  1760. (buffer-string))))
  1761. ;; Region: If it contains anything else, toggle on fixed-width but
  1762. ;; not on fixed-width areas.
  1763. (should
  1764. (equal ": A\n: \n: B\n: \n: C"
  1765. (org-test-with-temp-text "A\n\n: B\n\nC"
  1766. (transient-mark-mode 1)
  1767. (push-mark (point) t t)
  1768. (goto-char (point-max))
  1769. (org-toggle-fixed-width)
  1770. (buffer-string))))
  1771. ;; Region: Ignore blank lines at its end, unless it contains only
  1772. ;; such lines.
  1773. (should
  1774. (equal ": A\n\n"
  1775. (org-test-with-temp-text "A\n\n"
  1776. (transient-mark-mode 1)
  1777. (push-mark (point) t t)
  1778. (goto-char (point-max))
  1779. (org-toggle-fixed-width)
  1780. (buffer-string))))
  1781. (should
  1782. (equal ": \n: \n"
  1783. (org-test-with-temp-text "\n\n"
  1784. (transient-mark-mode 1)
  1785. (push-mark (point) t t)
  1786. (goto-char (point-max))
  1787. (org-toggle-fixed-width)
  1788. (buffer-string)))))
  1789. (ert-deftest test-org/kill-line ()
  1790. "Test `org-kill-line' specifications."
  1791. ;; At the beginning of a line, kill whole line.
  1792. (should
  1793. (equal ""
  1794. (org-test-with-temp-text "abc"
  1795. (org-kill-line)
  1796. (buffer-string))))
  1797. ;; In the middle of a line, kill line until its end.
  1798. (should
  1799. (equal "a"
  1800. (org-test-with-temp-text "a<point>bc"
  1801. (org-kill-line)
  1802. (buffer-string))))
  1803. ;; Do not kill newline character.
  1804. (should
  1805. (equal "\n123"
  1806. (org-test-with-temp-text "abc\n123"
  1807. (org-kill-line)
  1808. (buffer-string))))
  1809. (should
  1810. (equal "a\n123"
  1811. (org-test-with-temp-text "a<point>bc\n123"
  1812. (org-kill-line)
  1813. (buffer-string))))
  1814. ;; When `org-special-ctrl-k' is non-nil and point is at a headline,
  1815. ;; kill until tags.
  1816. (should
  1817. (equal "* A :tag:"
  1818. (org-test-with-temp-text "* A<point>B :tag:"
  1819. (let ((org-special-ctrl-k t)
  1820. (org-tags-column 0))
  1821. (org-kill-line))
  1822. (buffer-string))))
  1823. ;; If point is on tags, only kill part left until the end of line.
  1824. (should
  1825. (equal "* A :tag:"
  1826. (org-test-with-temp-text "* A :tag:<point>tag2:"
  1827. (let ((org-special-ctrl-k t)
  1828. (org-tags-column 0))
  1829. (org-kill-line))
  1830. (buffer-string))))
  1831. ;; However, if point is at the beginning of the line, kill whole
  1832. ;; headline.
  1833. (should
  1834. (equal ""
  1835. (org-test-with-temp-text "* AB :tag:"
  1836. (let ((org-special-ctrl-k t)
  1837. (org-tags-column 0))
  1838. (org-kill-line))
  1839. (buffer-string))))
  1840. ;; When `org-ctrl-k-protect-subtree' is non-nil, and point is in
  1841. ;; invisible text, ask before removing it. When set to `error',
  1842. ;; throw an error.
  1843. (should-error
  1844. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  1845. (org-overview)
  1846. (let ((org-special-ctrl-k nil)
  1847. (org-ctrl-k-protect-subtree t))
  1848. (cl-letf (((symbol-function 'y-or-n-p) 'ignore))
  1849. (org-kill-line)))))
  1850. (should-error
  1851. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  1852. (org-overview)
  1853. (let ((org-special-ctrl-k nil)
  1854. (org-ctrl-k-protect-subtree 'error))
  1855. (org-kill-line)))))
  1856. ;;; Headline
  1857. (ert-deftest test-org/get-heading ()
  1858. "Test `org-get-heading' specifications."
  1859. ;; Return current heading, even if point is not on it.
  1860. (should
  1861. (equal "H"
  1862. (org-test-with-temp-text "* H"
  1863. (org-get-heading))))
  1864. (should
  1865. (equal "H"
  1866. (org-test-with-temp-text "* H\nText<point>"
  1867. (org-get-heading))))
  1868. ;; Without any optional argument, return TODO keyword, priority
  1869. ;; cookie, COMMENT keyword and tags.
  1870. (should
  1871. (equal "TODO H"
  1872. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  1873. (org-get-heading))))
  1874. (should
  1875. (equal "[#A] H"
  1876. (org-test-with-temp-text "* [#A] H"
  1877. (org-get-heading))))
  1878. (should
  1879. (equal "COMMENT H"
  1880. (org-test-with-temp-text "* COMMENT H"
  1881. (org-get-heading))))
  1882. (should
  1883. (equal "H :tag:"
  1884. (org-test-with-temp-text "* H :tag:"
  1885. (org-get-heading))))
  1886. ;; With NO-TAGS argument, ignore tags.
  1887. (should
  1888. (equal "TODO H"
  1889. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  1890. (org-get-heading t))))
  1891. (should
  1892. (equal "H"
  1893. (org-test-with-temp-text "* H :tag:"
  1894. (org-get-heading t))))
  1895. ;; With NO-TODO, ignore TODO keyword.
  1896. (should
  1897. (equal "H"
  1898. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  1899. (org-get-heading nil t))))
  1900. (should
  1901. (equal "H :tag:"
  1902. (org-test-with-temp-text "* H :tag:"
  1903. (org-get-heading nil t))))
  1904. ;; TODO keywords are case-sensitive.
  1905. (should
  1906. (equal "Todo H"
  1907. (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
  1908. (org-get-heading nil t))))
  1909. ;; With NO-PRIORITY, ignore priority.
  1910. (should
  1911. (equal "H"
  1912. (org-test-with-temp-text "* [#A] H"
  1913. (org-get-heading nil nil t))))
  1914. (should
  1915. (equal "H"
  1916. (org-test-with-temp-text "* H"
  1917. (org-get-heading nil nil t))))
  1918. (should
  1919. (equal "TODO H"
  1920. (org-test-with-temp-text "* TODO [#A] H"
  1921. (org-get-heading nil nil t))))
  1922. ;; With NO-COMMENT, ignore COMMENT keyword.
  1923. (should
  1924. (equal "H"
  1925. (org-test-with-temp-text "* COMMENT H"
  1926. (org-get-heading nil nil nil t))))
  1927. (should
  1928. (equal "H"
  1929. (org-test-with-temp-text "* H"
  1930. (org-get-heading nil nil nil t))))
  1931. (should
  1932. (equal "TODO [#A] H"
  1933. (org-test-with-temp-text "* TODO [#A] COMMENT H"
  1934. (org-get-heading nil nil nil t))))
  1935. ;; On an empty headline, return value is consistent.
  1936. (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
  1937. (should (equal "" (org-test-with-temp-text "* " (org-get-heading t))))
  1938. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t))))
  1939. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t))))
  1940. (should
  1941. (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t)))))
  1942. (ert-deftest test-org/in-commented-heading-p ()
  1943. "Test `org-in-commented-heading-p' specifications."
  1944. ;; Commented headline.
  1945. (should
  1946. (org-test-with-temp-text "* COMMENT Headline\nBody"
  1947. (goto-char (point-max))
  1948. (org-in-commented-heading-p)))
  1949. ;; Commented ancestor.
  1950. (should
  1951. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  1952. (goto-char (point-max))
  1953. (org-in-commented-heading-p)))
  1954. ;; Comment keyword is case-sensitive.
  1955. (should-not
  1956. (org-test-with-temp-text "* Comment Headline\nBody"
  1957. (goto-char (point-max))
  1958. (org-in-commented-heading-p)))
  1959. ;; Keyword is standalone.
  1960. (should-not
  1961. (org-test-with-temp-text "* COMMENTHeadline\nBody"
  1962. (goto-char (point-max))
  1963. (org-in-commented-heading-p)))
  1964. ;; Optional argument.
  1965. (should-not
  1966. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  1967. (goto-char (point-max))
  1968. (org-in-commented-heading-p t))))
  1969. (ert-deftest test-org/entry-blocked-p ()
  1970. ;; Check other dependencies.
  1971. (should
  1972. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  1973. (let ((org-enforce-todo-dependencies t)
  1974. (org-blocker-hook
  1975. '(org-block-todo-from-children-or-siblings-or-parent)))
  1976. (org-entry-blocked-p))))
  1977. (should-not
  1978. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  1979. (let ((org-enforce-todo-dependencies t)
  1980. (org-blocker-hook
  1981. '(org-block-todo-from-children-or-siblings-or-parent)))
  1982. (org-entry-blocked-p))))
  1983. ;; Entry without a TODO keyword or with a DONE keyword cannot be
  1984. ;; blocked.
  1985. (should-not
  1986. (org-test-with-temp-text "* Blocked\n** TODO one"
  1987. (let ((org-enforce-todo-dependencies t)
  1988. (org-blocker-hook
  1989. '(org-block-todo-from-children-or-siblings-or-parent)))
  1990. (org-entry-blocked-p))))
  1991. (should-not
  1992. (org-test-with-temp-text "* DONE Blocked\n** TODO one"
  1993. (let ((org-enforce-todo-dependencies t)
  1994. (org-blocker-hook
  1995. '(org-block-todo-from-children-or-siblings-or-parent)))
  1996. (org-entry-blocked-p))))
  1997. ;; Follow :ORDERED: specifications.
  1998. (should
  1999. (org-test-with-temp-text
  2000. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
  2001. (let ((org-enforce-todo-dependencies t)
  2002. (org-blocker-hook
  2003. '(org-block-todo-from-children-or-siblings-or-parent)))
  2004. (org-entry-blocked-p))))
  2005. (should-not
  2006. (org-test-with-temp-text
  2007. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
  2008. (let ((org-enforce-todo-dependencies t)
  2009. (org-blocker-hook
  2010. '(org-block-todo-from-children-or-siblings-or-parent)))
  2011. (org-entry-blocked-p)))))
  2012. (ert-deftest test-org/get-outline-path ()
  2013. "Test `org-get-outline-path' specifications."
  2014. ;; Top-level headlines have no outline path.
  2015. (should-not
  2016. (org-test-with-temp-text "* H"
  2017. (org-get-outline-path)))
  2018. ;; Otherwise, outline path is the path leading to the headline.
  2019. (should
  2020. (equal '("H")
  2021. (org-test-with-temp-text "* H\n** S<point>"
  2022. (org-get-outline-path))))
  2023. ;; Find path even when point is not on a headline.
  2024. (should
  2025. (equal '("H")
  2026. (org-test-with-temp-text "* H\n** S\nText<point>"
  2027. (org-get-outline-path))))
  2028. ;; TODO keywords, tags and statistics cookies are ignored.
  2029. (should
  2030. (equal '("H")
  2031. (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
  2032. (org-get-outline-path))))
  2033. ;; Links are replaced with their description or their path.
  2034. (should
  2035. (equal '("Org")
  2036. (org-test-with-temp-text
  2037. "* [[https://orgmode.org][Org]]\n** S<point>"
  2038. (org-get-outline-path))))
  2039. (should
  2040. (equal '("https://orgmode.org")
  2041. (org-test-with-temp-text
  2042. "* [[https://orgmode.org]]\n** S<point>"
  2043. (org-get-outline-path))))
  2044. ;; When WITH-SELF is non-nil, include current heading.
  2045. (should
  2046. (equal '("H")
  2047. (org-test-with-temp-text "* H"
  2048. (org-get-outline-path t))))
  2049. (should
  2050. (equal '("H" "S")
  2051. (org-test-with-temp-text "* H\n** S\nText<point>"
  2052. (org-get-outline-path t))))
  2053. ;; Using cache is transparent to the user.
  2054. (should
  2055. (equal '("H")
  2056. (org-test-with-temp-text "* H\n** S<point>"
  2057. (setq org-outline-path-cache nil)
  2058. (org-get-outline-path nil t))))
  2059. ;; Do not corrupt cache when finding outline path in distant part of
  2060. ;; the buffer.
  2061. (should
  2062. (equal '("H2")
  2063. (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
  2064. (setq org-outline-path-cache nil)
  2065. (org-get-outline-path nil t)
  2066. (search-forward "S2")
  2067. (org-get-outline-path nil t))))
  2068. ;; Do not choke on empty headlines.
  2069. (should
  2070. (org-test-with-temp-text "* H\n** <point>"
  2071. (org-get-outline-path)))
  2072. (should
  2073. (org-test-with-temp-text "* \n** H<point>"
  2074. (org-get-outline-path))))
  2075. (ert-deftest test-org/format-outline-path ()
  2076. "Test `org-format-outline-path' specifications."
  2077. (should
  2078. (string= (org-format-outline-path (list "one" "two" "three"))
  2079. "one/two/three"))
  2080. ;; Empty path.
  2081. (should
  2082. (string= (org-format-outline-path '())
  2083. ""))
  2084. (should
  2085. (string= (org-format-outline-path '(nil))
  2086. ""))
  2087. ;; Empty path and prefix.
  2088. (should
  2089. (string= (org-format-outline-path '() nil ">>")
  2090. ">>"))
  2091. ;; Trailing whitespace in headings.
  2092. (should
  2093. (string= (org-format-outline-path (list "one\t" "tw o " "three "))
  2094. "one/tw o/three"))
  2095. ;; Non-default prefix and separators.
  2096. (should
  2097. (string= (org-format-outline-path (list "one" "two" "three") nil ">>" "|")
  2098. ">>|one|two|three"))
  2099. ;; Truncate.
  2100. (should
  2101. (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
  2102. "one/two/.."))
  2103. ;; Give a very narrow width.
  2104. (should
  2105. (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
  2106. "on"))
  2107. ;; Give a prefix that extends beyond the width.
  2108. (should
  2109. (string= (org-format-outline-path (list "one" "two" "three" "four") 10
  2110. ">>>>>>>>>>")
  2111. ">>>>>>>>..")))
  2112. (ert-deftest test-org/map-entries ()
  2113. "Test `org-map-entries' specifications."
  2114. ;; Full match.
  2115. (should
  2116. (equal '(1 11)
  2117. (org-test-with-temp-text "* Level 1\n** Level 2"
  2118. (org-map-entries #'point))))
  2119. ;; Level match.
  2120. (should
  2121. (equal '(1)
  2122. (org-test-with-temp-text "* Level 1\n** Level 2"
  2123. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL=1")))))
  2124. (should
  2125. (equal '(11)
  2126. (org-test-with-temp-text "* Level 1\n** Level 2"
  2127. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL>1")))))
  2128. ;; Tag match.
  2129. (should
  2130. (equal '(11)
  2131. (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
  2132. (org-map-entries #'point "yes"))))
  2133. (should
  2134. (equal '(14)
  2135. (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
  2136. (org-map-entries #'point "+yes-a"))))
  2137. (should
  2138. (equal '(11 23)
  2139. (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
  2140. (org-map-entries #'point "{yes?}"))))
  2141. ;; Priority match.
  2142. (should
  2143. (equal '(1)
  2144. (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
  2145. (org-map-entries #'point "PRIORITY=\"A\""))))
  2146. ;; Date match.
  2147. (should
  2148. (equal '(36)
  2149. (org-test-with-temp-text "
  2150. * H1
  2151. SCHEDULED: <2012-03-29 thu.>
  2152. * H2
  2153. SCHEDULED: <2014-03-04 tue.>"
  2154. (org-map-entries #'point "SCHEDULED=\"<2014-03-04 tue.>\""))))
  2155. (should
  2156. (equal '(2)
  2157. (org-test-with-temp-text "
  2158. * H1
  2159. SCHEDULED: <2012-03-29 thu.>
  2160. * H2
  2161. SCHEDULED: <2014-03-04 tue.>"
  2162. (org-map-entries #'point "SCHEDULED<\"<2013-01-01>\""))))
  2163. ;; Regular property match.
  2164. (should
  2165. (equal '(2)
  2166. (org-test-with-temp-text "
  2167. * H1
  2168. :PROPERTIES:
  2169. :TEST: 1
  2170. :END:
  2171. * H2
  2172. :PROPERTIES:
  2173. :TEST: 2
  2174. :END:"
  2175. (org-map-entries #'point "TEST=1"))))
  2176. ;; Multiple criteria.
  2177. (should
  2178. (equal '(23)
  2179. (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
  2180. (let (org-odd-levels-only
  2181. (org-use-tag-inheritance nil))
  2182. (org-map-entries #'point "yes+LEVEL=1")))))
  2183. ;; "or" criteria.
  2184. (should
  2185. (equal '(12 24)
  2186. (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
  2187. (let (org-odd-levels-only)
  2188. (org-map-entries #'point "LEVEL=2|no")))))
  2189. (should
  2190. (equal '(1 12)
  2191. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
  2192. (let (org-odd-levels-only)
  2193. (org-map-entries #'point "yes|no")))))
  2194. ;; "and" criteria.
  2195. (should
  2196. (equal '(22)
  2197. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
  2198. (let (org-odd-levels-only)
  2199. (org-map-entries #'point "yes&no"))))))
  2200. (ert-deftest test-org/edit-headline ()
  2201. "Test `org-edit-headline' specifications."
  2202. (should
  2203. (equal "* B"
  2204. (org-test-with-temp-text "* A"
  2205. (org-edit-headline "B")
  2206. (buffer-string))))
  2207. ;; Handle empty headings.
  2208. (should
  2209. (equal "* "
  2210. (org-test-with-temp-text "* A"
  2211. (org-edit-headline "")
  2212. (buffer-string))))
  2213. (should
  2214. (equal "* A"
  2215. (org-test-with-temp-text "* "
  2216. (org-edit-headline "A")
  2217. (buffer-string))))
  2218. ;; Handle TODO keywords and priority cookies.
  2219. (should
  2220. (equal "* TODO B"
  2221. (org-test-with-temp-text "* TODO A"
  2222. (org-edit-headline "B")
  2223. (buffer-string))))
  2224. (should
  2225. (equal "* [#A] B"
  2226. (org-test-with-temp-text "* [#A] A"
  2227. (org-edit-headline "B")
  2228. (buffer-string))))
  2229. (should
  2230. (equal "* TODO [#A] B"
  2231. (org-test-with-temp-text "* TODO [#A] A"
  2232. (org-edit-headline "B")
  2233. (buffer-string))))
  2234. ;; Handle tags.
  2235. (equal "* B :tag:"
  2236. (org-test-with-temp-text "* A :tag:"
  2237. (let ((org-tags-column 4)) (org-edit-headline "B"))
  2238. (buffer-string))))
  2239. ;;; Keywords
  2240. (ert-deftest test-org/set-regexps-and-options ()
  2241. "Test `org-set-regexps-and-options' specifications."
  2242. ;; TAGS keyword.
  2243. (should
  2244. (equal '(("A"))
  2245. (let ((org-tag-alist '(("A")))
  2246. (org-tag-persistent-alist nil))
  2247. (org-test-with-temp-text ""
  2248. (org-mode-restart)
  2249. org-current-tag-alist))))
  2250. (should
  2251. (equal '(("B"))
  2252. (let ((org-tag-alist '(("A")))
  2253. (org-tag-persistent-alist nil))
  2254. (org-test-with-temp-text "#+TAGS: B"
  2255. (org-mode-restart)
  2256. org-current-tag-alist))))
  2257. (should
  2258. (equal '(("C") ("B"))
  2259. (let ((org-tag-alist '(("A")))
  2260. (org-tag-persistent-alist '(("C"))))
  2261. (org-test-with-temp-text "#+TAGS: B"
  2262. (org-mode-restart)
  2263. org-current-tag-alist))))
  2264. (should
  2265. (equal '(("B"))
  2266. (let ((org-tag-alist '(("A")))
  2267. (org-tag-persistent-alist '(("C"))))
  2268. (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
  2269. (org-mode-restart)
  2270. org-current-tag-alist))))
  2271. (should
  2272. (equal '(("A" . ?a) ("B") ("C"))
  2273. (let ((org-tag-persistant-alist nil))
  2274. (org-test-with-temp-text "#+TAGS: A(a) B C"
  2275. (org-mode-restart)
  2276. org-current-tag-alist))))
  2277. (should
  2278. (equal '(("A") (:newline) ("B"))
  2279. (let ((org-tag-persistent-alist nil))
  2280. (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
  2281. (org-mode-restart)
  2282. org-current-tag-alist))))
  2283. (should
  2284. (equal '((:startgroup) ("A") ("B") (:endgroup) ("C"))
  2285. (let ((org-tag-persistent-alist nil))
  2286. (org-test-with-temp-text "#+TAGS: { A B } C"
  2287. (org-mode-restart)
  2288. org-current-tag-alist))))
  2289. (should
  2290. (equal '((:startgroup) ("A") (:grouptags) ("B") ("C") (:endgroup))
  2291. (let ((org-tag-persistent-alist nil))
  2292. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2293. (org-mode-restart)
  2294. org-current-tag-alist))))
  2295. (should
  2296. (equal '(("A" "B" "C"))
  2297. (let ((org-tag-persistent-alist nil))
  2298. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2299. (org-mode-restart)
  2300. org-tag-groups-alist))))
  2301. (should
  2302. (equal '((:startgrouptag) ("A") (:grouptags) ("B") ("C") (:endgrouptag))
  2303. (let ((org-tag-persistent-alist nil))
  2304. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2305. (org-mode-restart)
  2306. org-current-tag-alist))))
  2307. (should
  2308. (equal '(("A" "B" "C"))
  2309. (let ((org-tag-persistent-alist nil))
  2310. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2311. (org-mode-restart)
  2312. org-tag-groups-alist))))
  2313. ;; FILETAGS keyword.
  2314. (should
  2315. (equal '("A" "B" "C")
  2316. (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
  2317. (org-mode-restart)
  2318. org-file-tags)))
  2319. ;; PROPERTY keyword. Property names are case-insensitive.
  2320. (should
  2321. (equal "foo=1"
  2322. (org-test-with-temp-text "#+PROPERTY: var foo=1"
  2323. (org-mode-restart)
  2324. (cdr (assoc "var" org-keyword-properties)))))
  2325. (should
  2326. (equal
  2327. "foo=1 bar=2"
  2328. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
  2329. (org-mode-restart)
  2330. (cdr (assoc "var" org-keyword-properties)))))
  2331. (should
  2332. (equal
  2333. "foo=1 bar=2"
  2334. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
  2335. (org-mode-restart)
  2336. (cdr (assoc "var" org-keyword-properties)))))
  2337. ;; ARCHIVE keyword.
  2338. (should
  2339. (equal "%s_done::"
  2340. (org-test-with-temp-text "#+ARCHIVE: %s_done::"
  2341. (org-mode-restart)
  2342. org-archive-location)))
  2343. ;; CATEGORY keyword.
  2344. (should
  2345. (eq 'test
  2346. (org-test-with-temp-text "#+CATEGORY: test"
  2347. (org-mode-restart)
  2348. org-category)))
  2349. (should
  2350. (equal "test"
  2351. (org-test-with-temp-text "#+CATEGORY: test"
  2352. (org-mode-restart)
  2353. (cdr (assoc "CATEGORY" org-keyword-properties)))))
  2354. ;; COLUMNS keyword.
  2355. (should
  2356. (equal "%25ITEM %TAGS %PRIORITY %TODO"
  2357. (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
  2358. (org-mode-restart)
  2359. org-columns-default-format)))
  2360. ;; CONSTANTS keyword. Constants names are case sensitive.
  2361. (should
  2362. (equal '("299792458." "3.14")
  2363. (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
  2364. (org-mode-restart)
  2365. (mapcar
  2366. (lambda (n) (cdr (assoc n org-table-formula-constants-local)))
  2367. '("c" "pi")))))
  2368. (should
  2369. (equal "3.14"
  2370. (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
  2371. (org-mode-restart)
  2372. (cdr (assoc "pi" org-table-formula-constants-local)))))
  2373. (should
  2374. (equal "22/7"
  2375. (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
  2376. (org-mode-restart)
  2377. (cdr (assoc "PI" org-table-formula-constants-local)))))
  2378. ;; LINK keyword.
  2379. (should
  2380. (equal
  2381. '("url1" "url2")
  2382. (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
  2383. (org-mode-restart)
  2384. (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local)))
  2385. '("a" "b")))))
  2386. ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
  2387. (should
  2388. (equal
  2389. '(?X ?Z ?Y)
  2390. (org-test-with-temp-text "#+PRIORITIES: X Z Y"
  2391. (org-mode-restart)
  2392. (list org-priority-highest org-priority-lowest org-priority-default))))
  2393. (should
  2394. (equal
  2395. '(?A ?C ?B)
  2396. (org-test-with-temp-text "#+PRIORITIES: X Z"
  2397. (org-mode-restart)
  2398. (list org-priority-highest org-priority-lowest org-priority-default))))
  2399. ;; STARTUP keyword.
  2400. (should
  2401. (equal '(t t)
  2402. (org-test-with-temp-text "#+STARTUP: fold odd"
  2403. (org-mode-restart)
  2404. (list org-startup-folded org-odd-levels-only))))
  2405. ;; TODO keywords.
  2406. (should
  2407. (equal '(("A" "B") ("C"))
  2408. (org-test-with-temp-text "#+TODO: A B | C"
  2409. (org-mode-restart)
  2410. (list org-not-done-keywords org-done-keywords))))
  2411. (should
  2412. (equal '(("A" "C") ("B" "D"))
  2413. (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
  2414. (org-mode-restart)
  2415. (list org-not-done-keywords org-done-keywords))))
  2416. (should
  2417. (equal '(("A" "B") ("C"))
  2418. (org-test-with-temp-text "#+TYP_TODO: A B | C"
  2419. (org-mode-restart)
  2420. (list org-not-done-keywords org-done-keywords))))
  2421. (should
  2422. (equal '((:startgroup) ("A" . ?a) (:endgroup))
  2423. (org-test-with-temp-text "#+TODO: A(a)"
  2424. (org-mode-restart)
  2425. org-todo-key-alist)))
  2426. (should
  2427. (equal '(("D" note nil) ("C" time nil) ("B" note time))
  2428. (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
  2429. (org-mode-restart)
  2430. org-todo-log-states)))
  2431. ;; Enter SETUPFILE keyword.
  2432. (should
  2433. (equal "1"
  2434. (org-test-with-temp-text
  2435. (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
  2436. (org-mode-restart)
  2437. (cdr (assoc "a" org-keyword-properties))))))
  2438. ;;; Links
  2439. ;;;; Coderefs
  2440. (ert-deftest test-org/coderef ()
  2441. "Test coderef links specifications."
  2442. (should
  2443. (org-test-with-temp-text "
  2444. #+BEGIN_SRC emacs-lisp
  2445. \(+ 1 1) (ref:sc)
  2446. #+END_SRC
  2447. \[[(sc)<point>]]"
  2448. (org-open-at-point)
  2449. (looking-at "(ref:sc)")))
  2450. ;; Find coderef even with alternate label format.
  2451. (should
  2452. (org-test-with-temp-text "
  2453. #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
  2454. \(+ 1 1) {ref:sc}
  2455. #+END_SRC
  2456. \[[(sc)<point>]]"
  2457. (org-open-at-point)
  2458. (looking-at "{ref:sc}"))))
  2459. ;;;; Custom ID
  2460. (ert-deftest test-org/custom-id ()
  2461. "Test custom ID links specifications."
  2462. (should
  2463. (org-test-with-temp-text
  2464. "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2465. (org-open-at-point)
  2466. (looking-at-p "\\* H1")))
  2467. ;; Handle escape characters.
  2468. (should
  2469. (org-test-with-temp-text
  2470. "* H1\n:PROPERTIES:\n:CUSTOM_ID: [%]\n:END:\n* H2\n[[#\\[%\\]<point>]]"
  2471. (org-open-at-point)
  2472. (looking-at-p "\\* H1")))
  2473. ;; Throw an error on false positives.
  2474. (should-error
  2475. (org-test-with-temp-text
  2476. "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2477. (org-open-at-point)
  2478. (looking-at-p "\\* H1"))))
  2479. ;;;; Fuzzy Links
  2480. ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
  2481. ;; a named element (#+name: text) and to headlines (* Text).
  2482. (ert-deftest test-org/fuzzy-links ()
  2483. "Test fuzzy links specifications."
  2484. ;; Fuzzy link goes in priority to a matching target.
  2485. (should
  2486. (org-test-with-temp-text
  2487. "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
  2488. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2489. (looking-at "<<Test>>")))
  2490. ;; Then fuzzy link points to an element with a given name.
  2491. (should
  2492. (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
  2493. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2494. (looking-at "#\\+NAME: Test")))
  2495. ;; A target still lead to a matching headline otherwise.
  2496. (should
  2497. (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
  2498. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2499. (looking-at "\\* Head2")))
  2500. ;; With a leading star in link, enforce heading match.
  2501. (should
  2502. (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
  2503. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2504. (looking-at "\\* Test")))
  2505. ;; With a leading star in link, enforce exact heading match, even
  2506. ;; with `org-link-search-must-match-exact-headline' set to nil.
  2507. (should-error
  2508. (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
  2509. (let ((org-link-search-must-match-exact-headline nil))
  2510. (org-open-at-point))))
  2511. ;; Handle non-nil `org-link-search-must-match-exact-headline'.
  2512. (should
  2513. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
  2514. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2515. (looking-at "\\* Test")))
  2516. (should
  2517. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
  2518. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2519. (looking-at "\\* Test")))
  2520. ;; Heading match should not care about spaces, cookies, TODO
  2521. ;; keywords, priorities, and tags. However, TODO keywords are
  2522. ;; case-sensitive.
  2523. (should
  2524. (let ((first-line
  2525. "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
  2526. (org-test-with-temp-text
  2527. (concat first-line "\nFoo Bar\n<point>[[*Test 1 2]]")
  2528. (let ((org-link-search-must-match-exact-headline nil)
  2529. (org-todo-regexp "TODO"))
  2530. (org-open-at-point))
  2531. (looking-at (regexp-quote first-line)))))
  2532. (should-error
  2533. (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
  2534. (let ((org-link-search-must-match-exact-headline nil)
  2535. (org-todo-regexp "TODO"))
  2536. (org-open-at-point))))
  2537. ;; Heading match should still be exact.
  2538. (should-error
  2539. (org-test-with-temp-text "
  2540. ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
  2541. Foo Bar
  2542. <point>[[*Test 1]]"
  2543. (let ((org-link-search-must-match-exact-headline nil)
  2544. (org-todo-regexp "TODO"))
  2545. (org-open-at-point))))
  2546. (should
  2547. (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
  2548. (let ((org-link-search-must-match-exact-headline nil)
  2549. (org-todo-regexp "TODO"))
  2550. (org-open-at-point))
  2551. (looking-at-p (regexp-quote "** Test 1 2"))))
  2552. ;; Heading match ignores COMMENT keyword.
  2553. (should
  2554. (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
  2555. (org-open-at-point)
  2556. (looking-at "\\* COMMENT Test")))
  2557. (should
  2558. (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
  2559. (org-open-at-point)
  2560. (looking-at "\\* TODO COMMENT Test")))
  2561. ;; Correctly un-escape fuzzy links.
  2562. (should
  2563. (org-test-with-temp-text "* [foo]\n[[*\\[foo\\]][With escaped characters]]"
  2564. (org-open-at-point)
  2565. (bobp)))
  2566. ;; Match search strings containing newline characters, including
  2567. ;; blank lines.
  2568. (should
  2569. (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
  2570. (let ((file (buffer-file-name)))
  2571. (goto-char (point-max))
  2572. (insert (format "[[file:%s::line1 line2]]" file))
  2573. (beginning-of-line)
  2574. (let ((org-link-search-must-match-exact-headline nil))
  2575. (org-open-at-point 0))
  2576. (looking-at-p "line1"))))
  2577. (should
  2578. (org-test-with-temp-text-in-file "Paragraph\n\nline1\n\nline2\n\n"
  2579. (let ((file (buffer-file-name)))
  2580. (goto-char (point-max))
  2581. (insert (format "[[file:%s::line1 line2]]" file))
  2582. (beginning-of-line)
  2583. (let ((org-link-search-must-match-exact-headline nil))
  2584. (org-open-at-point 0))
  2585. (looking-at-p "line1")))))
  2586. ;;;; Open at point
  2587. (ert-deftest test-org/open-at-point/keyword ()
  2588. "Does `org-open-at-point' open link in a keyword line?"
  2589. (should
  2590. (org-test-with-temp-text
  2591. "<<top>>\n#+KEYWORD: <point>[[top]]"
  2592. (org-open-at-point) t))
  2593. (should
  2594. (org-test-with-temp-text
  2595. "* H\n<<top>>\n#+KEYWORD: <point>[[top]]"
  2596. (org-open-at-point) t)))
  2597. (ert-deftest test-org/open-at-point/property ()
  2598. "Does `org-open-at-point' open link in property drawer?"
  2599. (should
  2600. (org-test-with-temp-text
  2601. "* Headline
  2602. :PROPERTIES:
  2603. :URL: <point>[[*Headline]]
  2604. :END:"
  2605. (org-open-at-point) t)))
  2606. (ert-deftest test-org/open-at-point/comment ()
  2607. "Does `org-open-at-point' open link in a commented line?"
  2608. (should
  2609. (org-test-with-temp-text
  2610. "<<top>>\n# <point>[[top]]"
  2611. (org-open-at-point) t))
  2612. (should
  2613. (org-test-with-temp-text
  2614. "* H\n<<top>>\n# <point>[[top]]"
  2615. (org-open-at-point) t)))
  2616. (ert-deftest test-org/open-at-point/inline-image ()
  2617. "Test `org-open-at-point' on nested links."
  2618. (should
  2619. (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
  2620. (org-open-at-point)
  2621. (bobp))))
  2622. (ert-deftest test-org/open-at-point/radio-target ()
  2623. "Test `org-open-at-point' on radio targets."
  2624. (should
  2625. (org-test-with-temp-text "<<<target>>> <point>target"
  2626. (org-update-radio-target-regexp)
  2627. (org-open-at-point)
  2628. (eq (org-element-type (org-element-context)) 'radio-target))))
  2629. (ert-deftest test-org/open-at-point/tag ()
  2630. "Test `org-open-at-point' on tags."
  2631. (should
  2632. (org-test-with-temp-text "* H :<point>tag:"
  2633. (catch :result
  2634. (cl-letf (((symbol-function 'org-tags-view)
  2635. (lambda (&rest args) (throw :result t))))
  2636. (org-open-at-point)
  2637. nil))))
  2638. (should-not
  2639. (org-test-with-temp-text-in-file "* H<point> :tag:"
  2640. (catch :result
  2641. (cl-letf (((symbol-function 'org-tags-view)
  2642. (lambda (&rest args) (throw :result t))))
  2643. ;; When point isn't on a tag it's going to try other things,
  2644. ;; possibly trying to open attachments which will return an
  2645. ;; error if there isn't an attachment. Suppress that error.
  2646. (ignore-errors
  2647. (org-open-at-point))
  2648. nil)))))
  2649. ;;; Node Properties
  2650. (ert-deftest test-org/accumulated-properties-in-drawers ()
  2651. "Ensure properties accumulate in subtree drawers."
  2652. (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
  2653. (org-babel-next-src-block)
  2654. (should (equal '(2 1) (org-babel-execute-src-block)))))
  2655. (ert-deftest test-org/custom-properties ()
  2656. "Test custom properties specifications."
  2657. ;; Standard test.
  2658. (should
  2659. (let ((org-custom-properties '("FOO")))
  2660. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2661. (org-toggle-custom-properties-visibility)
  2662. (org-invisible-p2))))
  2663. ;; Properties are case-insensitive.
  2664. (should
  2665. (let ((org-custom-properties '("FOO")))
  2666. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
  2667. (org-toggle-custom-properties-visibility)
  2668. (org-invisible-p2))))
  2669. (should
  2670. (let ((org-custom-properties '("foo")))
  2671. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2672. (org-toggle-custom-properties-visibility)
  2673. (org-invisible-p2))))
  2674. ;; Multiple custom properties in the same drawer.
  2675. (should
  2676. (let ((org-custom-properties '("FOO" "BAR")))
  2677. (org-test-with-temp-text
  2678. "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
  2679. (org-toggle-custom-properties-visibility)
  2680. (and (org-invisible-p2)
  2681. (not (progn (forward-line) (org-invisible-p2)))
  2682. (progn (forward-line) (org-invisible-p2))))))
  2683. ;; Hide custom properties with an empty value.
  2684. (should
  2685. (let ((org-custom-properties '("FOO")))
  2686. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
  2687. (org-toggle-custom-properties-visibility)
  2688. (org-invisible-p2))))
  2689. ;; Do not hide fake properties.
  2690. (should-not
  2691. (let ((org-custom-properties '("FOO")))
  2692. (org-test-with-temp-text ":FOO: val\n"
  2693. (org-toggle-custom-properties-visibility)
  2694. (org-invisible-p2))))
  2695. (should-not
  2696. (let ((org-custom-properties '("A")))
  2697. (org-test-with-temp-text
  2698. "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
  2699. (org-toggle-custom-properties-visibility)
  2700. (org-invisible-p2)))))
  2701. ;;; Mark Region
  2702. (ert-deftest test-org/mark-element ()
  2703. "Test `org-mark-element' specifications."
  2704. ;; Mark beginning and end of element.
  2705. (should
  2706. (equal '(t t)
  2707. (org-test-with-temp-text "Para<point>graph"
  2708. (org-mark-element)
  2709. (list (bobp) (= (mark) (point-max))))))
  2710. (should
  2711. (equal '(t t)
  2712. (org-test-with-temp-text "P1\n\nPara<point>graph\n\nP2"
  2713. (org-mark-element)
  2714. (list (looking-at "Paragraph")
  2715. (org-with-point-at (mark) (looking-at "P2"))))))
  2716. ;; Do not set mark past (point-max).
  2717. (should
  2718. (org-test-with-temp-text "Para<point>graph"
  2719. (narrow-to-region 2 6)
  2720. (org-mark-element)
  2721. (= 6 (mark)))))
  2722. (ert-deftest test-org/mark-subtree ()
  2723. "Test `org-mark-subtree' specifications."
  2724. ;; Error when point is before first headline.
  2725. (should-error
  2726. (org-test-with-temp-text "Paragraph\n* Headline\nBody"
  2727. (progn (transient-mark-mode 1)
  2728. (org-mark-subtree))))
  2729. ;; Without argument, mark current subtree.
  2730. (should
  2731. (equal
  2732. '(12 32)
  2733. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  2734. (progn (transient-mark-mode 1)
  2735. (forward-line 2)
  2736. (org-mark-subtree)
  2737. (list (region-beginning) (region-end))))))
  2738. ;; With an argument, move ARG up.
  2739. (should
  2740. (equal
  2741. '(1 32)
  2742. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  2743. (progn (transient-mark-mode 1)
  2744. (forward-line 2)
  2745. (org-mark-subtree 1)
  2746. (list (region-beginning) (region-end))))))
  2747. ;; Do not get fooled by inlinetasks.
  2748. (when (featurep 'org-inlinetask)
  2749. (should
  2750. (= 1
  2751. (org-test-with-temp-text "* Headline\n*************** Task\nContents"
  2752. (progn (transient-mark-mode 1)
  2753. (forward-line 1)
  2754. (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
  2755. (region-beginning)))))))
  2756. ;;; Miscellaneous
  2757. (ert-deftest test-org/sort-entries ()
  2758. "Test `org-sort-entries'."
  2759. ;; Sort alphabetically.
  2760. (should
  2761. (equal "\n* abc\n* def\n* xyz\n"
  2762. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  2763. (org-sort-entries nil ?a)
  2764. (buffer-string))))
  2765. (should
  2766. (equal "\n* xyz\n* def\n* abc\n"
  2767. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  2768. (org-sort-entries nil ?A)
  2769. (buffer-string))))
  2770. (should
  2771. (equal "\n* \n* klm\n* xyz\n"
  2772. (org-test-with-temp-text "\n* xyz\n* \n* klm\n"
  2773. (org-sort-entries nil ?a)
  2774. (buffer-string))))
  2775. ;; Sort numerically.
  2776. (should
  2777. (equal "\n* 1\n* 2\n* 10\n"
  2778. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  2779. (org-sort-entries nil ?n)
  2780. (buffer-string))))
  2781. (should
  2782. (equal "\n* 10\n* 2\n* 1\n"
  2783. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  2784. (org-sort-entries nil ?N)
  2785. (buffer-string))))
  2786. (should
  2787. (equal "\n* \n* 1\n* 2\n"
  2788. (org-test-with-temp-text "\n* 1\n* \n* 2\n"
  2789. (org-sort-entries nil ?n)
  2790. (buffer-string))))
  2791. ;; Sort by custom function.
  2792. (should
  2793. (equal "\n* b\n* aa\n* ccc\n"
  2794. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  2795. (org-sort-entries nil ?f
  2796. (lambda ()
  2797. (length (buffer-substring (point-at-bol)
  2798. (point-at-eol))))
  2799. #'<)
  2800. (buffer-string))))
  2801. (should
  2802. (equal "\n* ccc\n* aa\n* b\n"
  2803. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  2804. (org-sort-entries nil ?F
  2805. (lambda ()
  2806. (length (buffer-substring (point-at-bol)
  2807. (point-at-eol))))
  2808. #'<)
  2809. (buffer-string))))
  2810. ;; Sort by TODO keyword.
  2811. (should
  2812. (equal "\n* TODO h1\n* TODO h3\n* DONE h2\n"
  2813. (org-test-with-temp-text
  2814. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  2815. (org-sort-entries nil ?o)
  2816. (buffer-string))))
  2817. (should
  2818. (equal "\n* DONE h2\n* TODO h1\n* TODO h3\n"
  2819. (org-test-with-temp-text
  2820. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  2821. (org-sort-entries nil ?O)
  2822. (buffer-string))))
  2823. ;; Sort by priority.
  2824. (should
  2825. (equal "\n* [#A] h2\n* [#B] h3\n* [#C] h1\n"
  2826. (org-test-with-temp-text
  2827. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  2828. (org-sort-entries nil ?p)
  2829. (buffer-string))))
  2830. (should
  2831. (equal "\n* [#C] h1\n* [#B] h3\n* [#A] h2\n"
  2832. (org-test-with-temp-text
  2833. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  2834. (org-sort-entries nil ?P)
  2835. (buffer-string))))
  2836. ;; Sort by creation time.
  2837. (should
  2838. (equal "
  2839. * h3
  2840. [2017-05-08 Mon]
  2841. * h2
  2842. [2017-05-09 Tue]
  2843. * h1
  2844. [2018-05-09 Wed]
  2845. "
  2846. (org-test-with-temp-text
  2847. "
  2848. * h1
  2849. [2018-05-09 Wed]
  2850. * h2
  2851. [2017-05-09 Tue]
  2852. * h3
  2853. [2017-05-08 Mon]
  2854. "
  2855. (org-sort-entries nil ?c)
  2856. (buffer-string))))
  2857. ;; Sort by scheduled date.
  2858. (should
  2859. (equal "
  2860. * TODO h4
  2861. SCHEDULED: <2017-05-06 Sat>
  2862. * TODO h3
  2863. SCHEDULED: <2017-05-08 Mon>
  2864. * TODO h2
  2865. DEADLINE: <2017-05-09 Tue>
  2866. * TODO h1
  2867. DEADLINE: <2017-05-07 Sun>
  2868. "
  2869. (org-test-with-temp-text
  2870. "
  2871. * TODO h2
  2872. DEADLINE: <2017-05-09 Tue>
  2873. * TODO h1
  2874. DEADLINE: <2017-05-07 Sun>
  2875. * TODO h3
  2876. SCHEDULED: <2017-05-08 Mon>
  2877. * TODO h4
  2878. SCHEDULED: <2017-05-06 Sat>
  2879. "
  2880. (org-sort-entries nil ?s)
  2881. (buffer-string))))
  2882. ;; Sort by deadline date.
  2883. (should
  2884. (equal "
  2885. * TODO h1
  2886. DEADLINE: <2017-05-07 Sun>
  2887. * TODO h2
  2888. DEADLINE: <2017-05-09 Tue>
  2889. * TODO h3
  2890. SCHEDULED: <2017-05-08 Mon>
  2891. * TODO h4
  2892. SCHEDULED: <2017-05-06 Sat>
  2893. "
  2894. (org-test-with-temp-text
  2895. "
  2896. * TODO h2
  2897. DEADLINE: <2017-05-09 Tue>
  2898. * TODO h1
  2899. DEADLINE: <2017-05-07 Sun>
  2900. * TODO h3
  2901. SCHEDULED: <2017-05-08 Mon>
  2902. * TODO h4
  2903. SCHEDULED: <2017-05-06 Sat>
  2904. "
  2905. (org-sort-entries nil ?d)
  2906. (buffer-string))))
  2907. ;; Sort by any date/time
  2908. (should
  2909. (equal "
  2910. * TODO h4
  2911. SCHEDULED: <2017-05-06 Sat>
  2912. * TODO h1
  2913. DEADLINE: <2017-05-07 Sun>
  2914. * TODO h3
  2915. SCHEDULED: <2017-05-08 Mon>
  2916. * TODO h2
  2917. DEADLINE: <2017-05-09 Tue>
  2918. "
  2919. (org-test-with-temp-text
  2920. "
  2921. * TODO h2
  2922. DEADLINE: <2017-05-09 Tue>
  2923. * TODO h1
  2924. DEADLINE: <2017-05-07 Sun>
  2925. * TODO h3
  2926. SCHEDULED: <2017-05-08 Mon>
  2927. * TODO h4
  2928. SCHEDULED: <2017-05-06 Sat>
  2929. "
  2930. (org-sort-entries nil ?t)
  2931. (buffer-string))))
  2932. ;; Sort by clocking time.
  2933. (should
  2934. (equal "
  2935. * clocked h2
  2936. :LOGBOOK:
  2937. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  2938. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  2939. :END:
  2940. * clocked h1
  2941. :LOGBOOK:
  2942. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  2943. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  2944. :END:
  2945. "
  2946. (org-test-with-temp-text
  2947. "
  2948. * clocked h1
  2949. :LOGBOOK:
  2950. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  2951. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  2952. :END:
  2953. * clocked h2
  2954. :LOGBOOK:
  2955. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  2956. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  2957. :END:
  2958. "
  2959. (org-sort-entries nil ?k)
  2960. (buffer-string))))
  2961. ;; Preserve file local variables when sorting.
  2962. (should
  2963. (equal "\n* A\n* B\n# Local Variables:\n# foo: t\n# End:\n"
  2964. (org-test-with-temp-text
  2965. "\n* B\n* A\n# Local Variables:\n# foo: t\n# End:"
  2966. (org-sort-entries nil ?a)
  2967. (buffer-string)))))
  2968. (ert-deftest test-org/string-collate-greaterp ()
  2969. "Test `org-string-collate-greaterp' specifications."
  2970. (should (org-string-collate-greaterp "def" "abc"))
  2971. (should-not (org-string-collate-greaterp "abc" "def")))
  2972. (ert-deftest test-org/file-contents ()
  2973. "Test `org-file-contents' specifications."
  2974. ;; Open files.
  2975. (should
  2976. (string= "#+BIND: variable value
  2977. #+DESCRIPTION: l2
  2978. #+LANGUAGE: en
  2979. #+SELECT_TAGS: b
  2980. #+TITLE: b
  2981. #+PROPERTY: a 1
  2982. " (org-file-contents (expand-file-name "setupfile3.org"
  2983. (concat org-test-dir "examples/")))))
  2984. ;; Throw error when trying to access an invalid file.
  2985. (should-error (org-file-contents "this-file-must-not-exist"))
  2986. ;; Try to access an invalid file, but do not throw an error.
  2987. (should
  2988. (progn (org-file-contents "this-file-must-not-exist" :noerror) t))
  2989. ;; Open URL.
  2990. (should
  2991. (string= "foo"
  2992. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  2993. (unwind-protect
  2994. ;; Simulate successful retrieval of a URL.
  2995. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  2996. (lambda (&rest_)
  2997. (with-current-buffer buffer
  2998. (insert "HTTP/1.1 200 OK\n\nfoo"))
  2999. buffer)))
  3000. (org-file-contents "http://some-valid-url"))
  3001. (kill-buffer buffer)))))
  3002. ;; Throw error when trying to access an invalid URL.
  3003. (should-error
  3004. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3005. (unwind-protect
  3006. ;; Simulate unsuccessful retrieval of a URL.
  3007. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3008. (lambda (&rest_)
  3009. (with-current-buffer buffer
  3010. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3011. buffer)))
  3012. (org-file-contents "http://this-url-must-not-exist"))
  3013. (kill-buffer buffer))))
  3014. ;; Try to access an invalid URL, but do not throw an error.
  3015. (should-error
  3016. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3017. (unwind-protect
  3018. ;; Simulate unsuccessful retrieval of a URL.
  3019. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3020. (lambda (&rest_)
  3021. (with-current-buffer buffer
  3022. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3023. buffer)))
  3024. (org-file-contents "http://this-url-must-not-exist"))
  3025. (kill-buffer buffer))))
  3026. (should
  3027. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3028. (unwind-protect
  3029. ;; Simulate unsuccessful retrieval of a URL.
  3030. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3031. (lambda (&rest_)
  3032. (with-current-buffer buffer
  3033. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3034. buffer)))
  3035. (org-file-contents "http://this-url-must-not-exist" :noerror))
  3036. (kill-buffer buffer))
  3037. t)))
  3038. ;;; Navigation
  3039. (ert-deftest test-org/next-visible-heading ()
  3040. "Test `org-next-visible-heading' specifications."
  3041. ;; Move to the beginning of the next headline, taking into
  3042. ;; consideration ARG.
  3043. (should
  3044. (org-test-with-temp-text "* H1\n* H2"
  3045. (org-next-visible-heading 1)
  3046. (looking-at "\\* H2")))
  3047. (should
  3048. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3049. (org-next-visible-heading 2)
  3050. (looking-at "\\* H3")))
  3051. ;; Ignore invisible headlines.
  3052. (should
  3053. (org-test-with-temp-text "* H1\n** H2\n* H3"
  3054. (org-cycle)
  3055. (org-next-visible-heading 1)
  3056. (looking-at "\\* H3")))
  3057. ;; Move point between headlines, not on blank lines between.
  3058. (should
  3059. (org-test-with-temp-text "* H1\n** H2\n\n\n\n* H3"
  3060. (let ((org-cycle-separator-lines 1))
  3061. (org-cycle)
  3062. (org-next-visible-heading 1))
  3063. (looking-at "\\* H3")))
  3064. ;; Move at end of buffer when there is no more headline.
  3065. (should
  3066. (org-test-with-temp-text "* H1"
  3067. (org-next-visible-heading 1)
  3068. (eobp)))
  3069. (should
  3070. (org-test-with-temp-text "* H1\n* H2"
  3071. (org-next-visible-heading 2)
  3072. (eobp)))
  3073. ;; With a negative argument, move backwards.
  3074. (should
  3075. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3076. (org-next-visible-heading -1)
  3077. (looking-at "\\* H2")))
  3078. (should
  3079. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3080. (org-next-visible-heading -2)
  3081. (looking-at "\\* H1"))))
  3082. (ert-deftest test-org/previous-visible-heading ()
  3083. "Test `org-previous-visible-heading' specifications."
  3084. ;; Move to the beginning of the next headline, taking into
  3085. ;; consideration ARG.
  3086. (should
  3087. (org-test-with-temp-text "* H1\n<point>* H2"
  3088. (org-previous-visible-heading 1)
  3089. (looking-at "\\* H1")))
  3090. (should
  3091. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3092. (org-previous-visible-heading 2)
  3093. (looking-at "\\* H1")))
  3094. ;; Ignore invisible headlines.
  3095. (should
  3096. (org-test-with-temp-text "* H1\n** H2\n<point>* H3"
  3097. (org-overview)
  3098. (org-previous-visible-heading 1)
  3099. (looking-at "\\* H1")))
  3100. ;; Move point between headlines, not on blank lines between.
  3101. (should
  3102. (org-test-with-temp-text "* H1\n\n\n\n** H2\n<point>* H3"
  3103. (let ((org-cycle-separator-lines 1))
  3104. (org-overview)
  3105. (org-previous-visible-heading 1))
  3106. (looking-at "\\* H1")))
  3107. ;; Move at end of buffer when there is no more headline.
  3108. (should
  3109. (org-test-with-temp-text "* H1"
  3110. (org-previous-visible-heading 1)
  3111. (bobp)))
  3112. (should
  3113. (org-test-with-temp-text "* H1\n* <point>H2"
  3114. (org-previous-visible-heading 2)
  3115. (bobp)))
  3116. ;; Invisible parts may not start at a headline, i.e., when revealing
  3117. ;; parts of the buffer. Handle this.
  3118. (should
  3119. (org-test-with-temp-text "* Main\n** H1\nFoo\n** H2\nBar\n** H3\nBaz"
  3120. (org-overview)
  3121. (search-forward "H1")
  3122. (org-show-context 'minimal)
  3123. (org-cycle)
  3124. (search-forward "H3")
  3125. (org-show-context 'minimal)
  3126. ;; At this point, buffer displays, with point at "|",
  3127. ;;
  3128. ;; * Main
  3129. ;; ** H1
  3130. ;; Foo
  3131. ;; ** H3|
  3132. (org-previous-visible-heading 1)
  3133. (looking-at "\\*+ H1"))))
  3134. (ert-deftest test-org/forward-heading-same-level ()
  3135. "Test `org-forward-heading-same-level' specifications."
  3136. ;; Test navigation at top level, forward and backward.
  3137. (should
  3138. (equal "* H2"
  3139. (org-test-with-temp-text "* H1\n* H2"
  3140. (org-forward-heading-same-level 1)
  3141. (buffer-substring-no-properties (point) (line-end-position)))))
  3142. (should
  3143. (equal "* H1"
  3144. (org-test-with-temp-text "* H1\n<point>* H2"
  3145. (org-forward-heading-same-level -1)
  3146. (buffer-substring-no-properties (point) (line-end-position)))))
  3147. ;; Test navigation in a sub-tree, forward and backward.
  3148. (should
  3149. (equal "* H2"
  3150. (org-test-with-temp-text "* H1\n** H11\n** H12\n* H2"
  3151. (org-forward-heading-same-level 1)
  3152. (buffer-substring-no-properties (point) (line-end-position)))))
  3153. (should
  3154. (equal "* H1"
  3155. (org-test-with-temp-text "* H1\n** H11\n** H12\n<point>* H2"
  3156. (org-forward-heading-same-level -1)
  3157. (buffer-substring-no-properties (point) (line-end-position)))))
  3158. ;; Stop at first or last sub-heading.
  3159. (should-not
  3160. (equal "* H2"
  3161. (org-test-with-temp-text "* H1\n** H11\n<point>** H12\n* H2"
  3162. (org-forward-heading-same-level 1)
  3163. (buffer-substring-no-properties (point) (line-end-position)))))
  3164. (should-not
  3165. (equal "* H2"
  3166. (org-test-with-temp-text "* H1\n<point>** H11\n** H12\n* H2"
  3167. (org-forward-heading-same-level -1)
  3168. (buffer-substring-no-properties (point) (line-end-position)))))
  3169. ;; Allow multiple moves.
  3170. (should
  3171. (equal "* H3"
  3172. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3173. (org-forward-heading-same-level 2)
  3174. (buffer-substring-no-properties (point) (line-end-position)))))
  3175. (should
  3176. (equal "* H1"
  3177. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3178. (org-forward-heading-same-level -2)
  3179. (buffer-substring-no-properties (point) (line-end-position)))))
  3180. ;; Ignore spurious moves when first (or last) sibling is reached.
  3181. (should
  3182. (equal "** H3"
  3183. (org-test-with-temp-text "* First\n<point>** H1\n** H2\n** H3\n* Last"
  3184. (org-forward-heading-same-level 100)
  3185. (buffer-substring-no-properties (point) (line-end-position)))))
  3186. (should
  3187. (equal "** H1"
  3188. (org-test-with-temp-text "* First\n** H1\n** H2\n<point>** H3\n* Last"
  3189. (org-forward-heading-same-level -100)
  3190. (buffer-substring-no-properties (point) (line-end-position))))))
  3191. (ert-deftest test-org/end-of-meta-data ()
  3192. "Test `org-end-of-meta-data' specifications."
  3193. ;; Skip planning line.
  3194. (should
  3195. (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
  3196. (org-end-of-meta-data)
  3197. (eobp)))
  3198. ;; Skip properties drawer.
  3199. (should
  3200. (org-test-with-temp-text
  3201. "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
  3202. (org-end-of-meta-data)
  3203. (eobp)))
  3204. ;; Skip both.
  3205. (should
  3206. (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
  3207. (org-end-of-meta-data)
  3208. (eobp)))
  3209. ;; Nothing to skip, go to first line.
  3210. (should
  3211. (org-test-with-temp-text "* Headline\nContents"
  3212. (org-end-of-meta-data)
  3213. (looking-at "Contents")))
  3214. ;; With option argument, skip empty lines, regular drawers and
  3215. ;; clocking lines.
  3216. (should
  3217. (org-test-with-temp-text "* Headline\n\nContents"
  3218. (org-end-of-meta-data t)
  3219. (looking-at "Contents")))
  3220. (should
  3221. (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
  3222. (org-end-of-meta-data t)
  3223. (looking-at "Contents")))
  3224. (should
  3225. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
  3226. (org-end-of-meta-data t)
  3227. (looking-at "Contents")))
  3228. ;; Special case: do not skip incomplete drawers.
  3229. (should
  3230. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
  3231. (org-end-of-meta-data t)
  3232. (looking-at ":LOGBOOK:")))
  3233. ;; Special case: Be careful about consecutive headlines.
  3234. (should-not
  3235. (org-test-with-temp-text "* H1\n*H2\nContents"
  3236. (org-end-of-meta-data t)
  3237. (looking-at "Contents"))))
  3238. (ert-deftest test-org/beginning-of-line ()
  3239. "Test `org-beginning-of-line' specifications."
  3240. ;; Move to beginning of line. If current line in invisible, move to
  3241. ;; beginning of visible line instead.
  3242. (should
  3243. (org-test-with-temp-text "Some text\nSome other text<point>"
  3244. (org-beginning-of-line)
  3245. (bolp)))
  3246. (should
  3247. (org-test-with-temp-text "* H1\n** H2<point>"
  3248. (org-overview)
  3249. (org-beginning-of-line)
  3250. (= (line-beginning-position) 1)))
  3251. ;; With `visual-line-mode' active, move to beginning of visual line.
  3252. (should-not
  3253. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3254. (visual-line-mode)
  3255. (dotimes (i 1000) (insert "very "))
  3256. (org-beginning-of-line)
  3257. (bolp)))
  3258. ;; In a wide headline, with `visual-line-mode', prefer going to the
  3259. ;; beginning of a visual line than to the logical beginning of line,
  3260. ;; even if special movement is active.
  3261. (should-not
  3262. (org-test-with-temp-text "* A <point>long headline"
  3263. (visual-line-mode)
  3264. (dotimes (i 1000) (insert "very "))
  3265. (goto-char (point-max))
  3266. (org-beginning-of-line)
  3267. (bobp)))
  3268. (should-not
  3269. (org-test-with-temp-text "* A <point>long headline"
  3270. (visual-line-mode)
  3271. (dotimes (i 1000) (insert "very "))
  3272. (goto-char (point-max))
  3273. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line))
  3274. (bobp)))
  3275. ;; At an headline with special movement, first move at beginning of
  3276. ;; title, then at the beginning of line, rinse, repeat.
  3277. (should
  3278. (org-test-with-temp-text "* TODO Headline<point>"
  3279. (let ((org-special-ctrl-a/e t))
  3280. (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
  3281. (progn (org-beginning-of-line) (bolp))
  3282. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3283. (should
  3284. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3285. (let ((org-special-ctrl-a/e t))
  3286. (org-beginning-of-line)
  3287. (looking-at "Headline"))))
  3288. (should
  3289. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3290. (let ((org-special-ctrl-a/e '(t . nil)))
  3291. (org-beginning-of-line)
  3292. (looking-at "Headline"))))
  3293. (should-not
  3294. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3295. (let ((org-special-ctrl-a/e '(nil . nil)))
  3296. (org-beginning-of-line)
  3297. (looking-at "Headline"))))
  3298. ;; At an headline with reversed movement, first move to beginning of
  3299. ;; line, then to the beginning of title.
  3300. (should
  3301. (org-test-with-temp-text "* TODO Headline<point>"
  3302. (let ((org-special-ctrl-a/e 'reversed)
  3303. (this-command last-command))
  3304. (and (progn (org-beginning-of-line) (bolp))
  3305. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3306. (should
  3307. (org-test-with-temp-text "* TODO Headline<point>"
  3308. (let ((org-special-ctrl-a/e '(reversed . nil))
  3309. (this-command last-command))
  3310. (and (progn (org-beginning-of-line) (bolp))
  3311. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3312. (should-not
  3313. (org-test-with-temp-text "* TODO Headline<point>"
  3314. (let ((org-special-ctrl-a/e '(t . nil))
  3315. (this-command last-command))
  3316. (and (progn (org-beginning-of-line) (bolp))
  3317. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3318. ;; At an item with special movement, first move after to beginning
  3319. ;; of title, then to the beginning of line, rinse, repeat.
  3320. (should
  3321. (org-test-with-temp-text "- [ ] Item<point>"
  3322. (let ((org-special-ctrl-a/e t))
  3323. (and (progn (org-beginning-of-line) (looking-at-p "Item"))
  3324. (progn (org-beginning-of-line) (bolp))
  3325. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3326. ;; At an item with reversed movement, first move to beginning of
  3327. ;; line, then to the beginning of title.
  3328. (should
  3329. (org-test-with-temp-text "- [X] Item<point>"
  3330. (let ((org-special-ctrl-a/e 'reversed)
  3331. (this-command last-command))
  3332. (and (progn (org-beginning-of-line) (bolp))
  3333. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3334. ;; Leave point before invisible characters at column 0.
  3335. (should
  3336. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3337. (let ((org-special-ctrl-a/e nil))
  3338. (org-beginning-of-line)
  3339. (bolp))))
  3340. (should
  3341. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3342. (let ((org-special-ctrl-a/e t))
  3343. (org-beginning-of-line)
  3344. (bolp))))
  3345. (should
  3346. (org-test-with-temp-text "[[http<point>://orgmode.org]]"
  3347. (visual-line-mode)
  3348. (org-beginning-of-line)
  3349. (bolp)))
  3350. ;; Special case: Do not error when the buffer contains only a single
  3351. ;; asterisk.
  3352. (should
  3353. (org-test-with-temp-text "*<point>"
  3354. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line) t)))
  3355. (should
  3356. (org-test-with-temp-text "*<point>"
  3357. (let ((org-special-ctrl-a/e nil)) (org-beginning-of-line) t))))
  3358. (ert-deftest test-org/end-of-line ()
  3359. "Test `org-end-of-line' specifications."
  3360. ;; Standard test.
  3361. (should
  3362. (org-test-with-temp-text "Some text\nSome other text"
  3363. (org-end-of-line)
  3364. (eolp)))
  3365. ;; With `visual-line-mode' active, move to end of visible line.
  3366. ;; However, never go past ellipsis.
  3367. (should-not
  3368. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3369. (visual-line-mode)
  3370. (dotimes (i 1000) (insert "very "))
  3371. (goto-char (point-min))
  3372. (org-end-of-line)
  3373. (eolp)))
  3374. (should-not
  3375. (org-test-with-temp-text "* A short headline\nSome contents"
  3376. (visual-line-mode)
  3377. (org-overview)
  3378. (org-end-of-line)
  3379. (eobp)))
  3380. ;; In a wide headline, with `visual-line-mode', prefer going to end
  3381. ;; of visible line if tags, or end of line, are farther.
  3382. (should-not
  3383. (org-test-with-temp-text "* A <point>long headline"
  3384. (visual-line-mode)
  3385. (dotimes (i 1000) (insert "very "))
  3386. (goto-char (point-min))
  3387. (org-end-of-line)
  3388. (eolp)))
  3389. (should-not
  3390. (org-test-with-temp-text "* A <point>long headline :tag:"
  3391. (visual-line-mode)
  3392. (dotimes (i 1000) (insert "very "))
  3393. (goto-char (point-min))
  3394. (org-end-of-line)
  3395. (eolp)))
  3396. ;; At an headline without special movement, go to end of line.
  3397. ;; However, never go past ellipsis.
  3398. (should
  3399. (org-test-with-temp-text "* Headline2b :tag:\n"
  3400. (let ((org-special-ctrl-a/e nil))
  3401. (and (progn (org-end-of-line) (eolp))
  3402. (progn (org-end-of-line) (eolp))))))
  3403. (should
  3404. (org-test-with-temp-text "* Headline2b :tag:\n"
  3405. (let ((org-special-ctrl-a/e '(t . nil)))
  3406. (and (progn (org-end-of-line) (eolp))
  3407. (progn (org-end-of-line) (eolp))))))
  3408. (should
  3409. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3410. (org-overview)
  3411. (let ((org-special-ctrl-a/e nil))
  3412. (org-end-of-line)
  3413. (= 1 (line-beginning-position)))))
  3414. ;; At an headline with special movement, first move before tags,
  3415. ;; then at the end of line, rinse, repeat. However, never go past
  3416. ;; ellipsis.
  3417. (should
  3418. (org-test-with-temp-text "* Headline1 :tag:\n"
  3419. (let ((org-special-ctrl-a/e t))
  3420. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3421. (progn (org-end-of-line) (eolp))
  3422. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3423. (should
  3424. (org-test-with-temp-text "* Headline1 :tag:\n"
  3425. (let ((org-special-ctrl-a/e '(nil . t)))
  3426. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3427. (progn (org-end-of-line) (eolp))
  3428. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3429. (should-not
  3430. (org-test-with-temp-text "* Headline1 :tag:\n"
  3431. (let ((org-special-ctrl-a/e '(nil . nil)))
  3432. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3433. (progn (org-end-of-line) (eolp))
  3434. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3435. (should
  3436. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3437. (org-overview)
  3438. (let ((org-special-ctrl-a/e t))
  3439. (org-end-of-line)
  3440. (org-end-of-line)
  3441. (= 1 (line-beginning-position)))))
  3442. ;; At an headline, with reversed movement, first go to end of line,
  3443. ;; then before tags. However, never go past ellipsis.
  3444. (should
  3445. (org-test-with-temp-text "* Headline3 :tag:\n"
  3446. (let ((org-special-ctrl-a/e 'reversed)
  3447. (this-command last-command))
  3448. (and (progn (org-end-of-line) (eolp))
  3449. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3450. (should
  3451. (org-test-with-temp-text "* Headline3 :tag:\n"
  3452. (let ((org-special-ctrl-a/e '(nil . reversed))
  3453. (this-command last-command))
  3454. (and (progn (org-end-of-line) (eolp))
  3455. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3456. (should-not
  3457. (org-test-with-temp-text "* Headline3 :tag:\n"
  3458. (let ((org-special-ctrl-a/e '(nil . t))
  3459. (this-command last-command))
  3460. (and (progn (org-end-of-line) (eolp))
  3461. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3462. (should
  3463. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3464. (org-overview)
  3465. (let ((org-special-ctrl-a/e 'reversed))
  3466. (org-end-of-line)
  3467. (= 1 (line-beginning-position)))))
  3468. ;; At a block without hidden contents.
  3469. (should
  3470. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3471. (progn (org-end-of-line) (eolp))))
  3472. ;; At a block with hidden contents.
  3473. (should-not
  3474. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3475. (let ((org-special-ctrl-a/e t))
  3476. (org-hide-block-toggle)
  3477. (org-end-of-line)
  3478. (eobp))))
  3479. ;; Get past invisible characters at the end of line.
  3480. (should
  3481. (org-test-with-temp-text "[[https://orgmode.org]]"
  3482. (org-end-of-line)
  3483. (eolp))))
  3484. (ert-deftest test-org/open-line ()
  3485. "Test `org-open-line' specifications."
  3486. ;; Call `open-line' outside of tables.
  3487. (should
  3488. (equal "\nText"
  3489. (org-test-with-temp-text "Text"
  3490. (org-open-line 1)
  3491. (buffer-string))))
  3492. ;; At a table, create a row above.
  3493. (should
  3494. (equal "\n| |\n| a |"
  3495. (org-test-with-temp-text "\n<point>| a |"
  3496. (org-open-line 1)
  3497. (buffer-string))))
  3498. ;; At the very first character of the buffer, also call `open-line'.
  3499. (should
  3500. (equal "\n| a |"
  3501. (org-test-with-temp-text "| a |"
  3502. (org-open-line 1)
  3503. (buffer-string))))
  3504. ;; Narrowing does not count.
  3505. (should
  3506. (equal "Text\n| |\n| a |"
  3507. (org-test-with-temp-text "Text\n<point>| a |"
  3508. (narrow-to-region (point) (point-max))
  3509. (org-open-line 1)
  3510. (widen)
  3511. (buffer-string)))))
  3512. (ert-deftest test-org/forward-sentence ()
  3513. "Test `org-forward-sentence' specifications."
  3514. ;; At the end of a table cell, move to the end of the next one.
  3515. (should
  3516. (org-test-with-temp-text "| a<point> | b |"
  3517. (org-forward-sentence)
  3518. (looking-at " |$")))
  3519. ;; Elsewhere in a cell, move to its end.
  3520. (should
  3521. (org-test-with-temp-text "| a<point>c | b |"
  3522. (org-forward-sentence)
  3523. (looking-at " | b |$")))
  3524. ;; Otherwise, simply call `forward-sentence'.
  3525. (should
  3526. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3527. (org-forward-sentence)
  3528. (looking-at " Sentence 2.")))
  3529. (should
  3530. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3531. (org-forward-sentence)
  3532. (org-forward-sentence)
  3533. (eobp)))
  3534. ;; At the end of an element, jump to the next one, without stopping
  3535. ;; on blank lines in-between.
  3536. (should
  3537. (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
  3538. (org-forward-sentence)
  3539. (eobp)))
  3540. ;; Headlines are considered to be sentences by themselves, even if
  3541. ;; they do not end with a full stop.
  3542. (should
  3543. (equal
  3544. "* Headline"
  3545. (org-test-with-temp-text "* <point>Headline\nSentence."
  3546. (org-forward-sentence)
  3547. (buffer-substring-no-properties (line-beginning-position) (point)))))
  3548. (should
  3549. (org-test-with-temp-text "* Headline<point>\nSentence."
  3550. (org-forward-sentence)
  3551. (eobp)))
  3552. (should
  3553. (org-test-with-temp-text "Sentence.<point>\n\n* Headline\n\nSentence 2."
  3554. (org-forward-sentence)
  3555. (and (org-at-heading-p) (eolp)))))
  3556. (ert-deftest test-org/backward-sentence ()
  3557. "Test `org-backward-sentence' specifications."
  3558. ;; At the beginning of a table cell, move to the beginning of the
  3559. ;; previous one.
  3560. (should
  3561. (org-test-with-temp-text "| a | <point>b |"
  3562. (org-backward-sentence)
  3563. (looking-at "a | b |$")))
  3564. ;; Elsewhere in a cell, move to its beginning.
  3565. (should
  3566. (org-test-with-temp-text "| a | b<point>c |"
  3567. (org-backward-sentence)
  3568. (looking-at "bc |$")))
  3569. ;; Otherwise, simply call `backward-sentence'.
  3570. (should
  3571. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3572. (org-backward-sentence)
  3573. (looking-at "Sentence 2.")))
  3574. (should
  3575. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3576. (org-backward-sentence)
  3577. (org-backward-sentence)
  3578. (bobp)))
  3579. ;; Make sure to hit the beginning of a sentence on the same line as
  3580. ;; an item.
  3581. (should
  3582. (org-test-with-temp-text "- Line 1\n line <point>2."
  3583. (org-backward-sentence)
  3584. (looking-at "Line 1"))))
  3585. (ert-deftest test-org/forward-paragraph ()
  3586. "Test `org-forward-paragraph' specifications."
  3587. ;; At end of buffer, do not return an error.
  3588. (should
  3589. (org-test-with-temp-text "Paragraph"
  3590. (goto-char (point-max))
  3591. (org-forward-paragraph)
  3592. t))
  3593. ;; Standard test.
  3594. (should
  3595. (= 2
  3596. (org-test-with-temp-text "P1\n\nP2"
  3597. (org-forward-paragraph)
  3598. (org-current-line))))
  3599. (should
  3600. (= 2
  3601. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  3602. (org-forward-paragraph)
  3603. (org-current-line))))
  3604. ;; Enter greater elements.
  3605. (should
  3606. (= 2
  3607. (org-test-with-temp-text "#+begin_center\nP1\n#+end_center\nP2"
  3608. (org-forward-paragraph)
  3609. (org-current-line))))
  3610. ;; Do not enter elements with invisible contents.
  3611. (should
  3612. (= 4
  3613. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  3614. (org-cycle)
  3615. (org-forward-paragraph)
  3616. (org-current-line))))
  3617. (should
  3618. (= 6
  3619. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\nP3"
  3620. (org-hide-block-toggle)
  3621. (org-forward-paragraph)
  3622. (org-current-line))))
  3623. ;; On an item or a footnote definition, move past the first element
  3624. ;; inside, if any.
  3625. (should
  3626. (= 2
  3627. (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
  3628. (org-forward-paragraph)
  3629. (org-current-line))))
  3630. (should
  3631. (= 2
  3632. (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
  3633. (org-forward-paragraph)
  3634. (org-current-line))))
  3635. ;; On a table (resp. a property drawer) do not move through table
  3636. ;; rows (resp. node properties).
  3637. (should
  3638. (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
  3639. (org-forward-paragraph)
  3640. (looking-at "Paragraph")))
  3641. (should
  3642. (org-test-with-temp-text
  3643. "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
  3644. (org-forward-paragraph)
  3645. (looking-at "Paragraph")))
  3646. ;; Skip consecutive keywords, clocks and diary S-exps.
  3647. (should
  3648. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n"
  3649. (org-forward-paragraph)
  3650. (eobp)))
  3651. (should
  3652. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n"
  3653. (org-forward-paragraph)
  3654. (eobp)))
  3655. (should
  3656. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n"
  3657. (org-forward-paragraph)
  3658. (eobp)))
  3659. (should-not
  3660. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n"
  3661. (org-forward-paragraph)
  3662. (eobp)))
  3663. (should-not
  3664. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n"
  3665. (org-forward-paragraph)
  3666. (eobp)))
  3667. ;; In a plain list with one item every line, skip the whole list,
  3668. ;; even with point in the middle of the list.
  3669. (should
  3670. (org-test-with-temp-text "- A\n - B\n- C\n"
  3671. (org-forward-paragraph)
  3672. (eobp)))
  3673. (should
  3674. (org-test-with-temp-text "- A\n - <point>B\n- C\n"
  3675. (org-forward-paragraph)
  3676. (eobp)))
  3677. ;; On a comment, verse or source block, stop at "contents"
  3678. ;; boundaries and blank lines.
  3679. (should
  3680. (= 2
  3681. (org-test-with-temp-text "#+begin_src emacs-lisp\nL1\n\nL2\n#+end_src"
  3682. (org-forward-paragraph)
  3683. (org-current-line))))
  3684. (should
  3685. (= 3
  3686. (org-test-with-temp-text "#+begin_verse\n<point>L1\n\nL2\n#+end_verse"
  3687. (org-forward-paragraph)
  3688. (org-current-line))))
  3689. (should
  3690. (= 5
  3691. (org-test-with-temp-text "#+begin_comment\nL1\n\n<point>L2\n#+end_comment"
  3692. (org-forward-paragraph)
  3693. (org-current-line))))
  3694. ;; Being on an affiliated keyword shouldn't make any difference.
  3695. (should
  3696. (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
  3697. (org-forward-paragraph)
  3698. (eobp))))
  3699. (ert-deftest test-org/backward-paragraph ()
  3700. "Test `org-backward-paragraph' specifications."
  3701. ;; Do not error at beginning of buffer.
  3702. (should
  3703. (org-test-with-temp-text "Paragraph"
  3704. (org-backward-paragraph)
  3705. t))
  3706. ;; At blank lines at the very beginning of a buffer, move to
  3707. ;; point-min.
  3708. (should
  3709. (org-test-with-temp-text "\n\n<point>\n\nParagraph"
  3710. (org-backward-paragraph)
  3711. (bobp)))
  3712. ;; Regular test.
  3713. (should
  3714. (= 2
  3715. (org-test-with-temp-text "P1\n\nP2<point>"
  3716. (org-backward-paragraph)
  3717. (org-current-line))))
  3718. (should
  3719. (= 4
  3720. (org-test-with-temp-text "P1\n\nP2\n\nP3<point>"
  3721. (org-backward-paragraph)
  3722. (org-current-line))))
  3723. ;; Try to move on the line above current element.
  3724. (should
  3725. (= 2
  3726. (org-test-with-temp-text "\n\n<point>Paragraph"
  3727. (org-backward-paragraph)
  3728. (org-current-line))))
  3729. ;; Do not leave point in an invisible area.
  3730. (should
  3731. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  3732. (org-cycle)
  3733. (goto-char (point-max))
  3734. (beginning-of-line)
  3735. (org-backward-paragraph)
  3736. (bobp)))
  3737. (should
  3738. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\n"
  3739. (org-hide-block-toggle)
  3740. (goto-char (point-max))
  3741. (org-backward-paragraph)
  3742. (bobp)))
  3743. ;; On the first element in an item or a footnote definition, jump
  3744. ;; before the footnote or the item.
  3745. (should
  3746. (org-test-with-temp-text "- line1<point>"
  3747. (org-backward-paragraph)
  3748. (bobp)))
  3749. (should
  3750. (org-test-with-temp-text "[fn:1] line1n<point>"
  3751. (org-backward-paragraph)
  3752. (bobp)))
  3753. ;; On the second element in an item or a footnote definition, jump
  3754. ;; to item or the definition.
  3755. (should
  3756. (= 2
  3757. (org-test-with-temp-text "- line1\n\n<point> line2"
  3758. (org-backward-paragraph)
  3759. (org-current-line))))
  3760. (should
  3761. (= 2
  3762. (org-test-with-temp-text "[fn:1] line1\n\n<point> line2"
  3763. (org-backward-paragraph)
  3764. (org-current-line))))
  3765. ;; On a table (resp. a property drawer), ignore table rows
  3766. ;; (resp. node properties).
  3767. (should
  3768. (org-test-with-temp-text "| a | b |\n| c | d |\n<point>P1"
  3769. (org-backward-paragraph)
  3770. (bobp)))
  3771. (should
  3772. (= 2
  3773. (org-test-with-temp-text
  3774. "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
  3775. (org-backward-paragraph)
  3776. (org-current-line))))
  3777. ;; In a plain list with one item every line, skip the whole list,
  3778. ;; even with point in the middle of the list.
  3779. (should
  3780. (org-test-with-temp-text "- A\n - B\n- C\n<point>"
  3781. (org-backward-paragraph)
  3782. (bobp)))
  3783. (should
  3784. (org-test-with-temp-text "- A\n - B\n- <point>C\n"
  3785. (org-backward-paragraph)
  3786. (bobp)))
  3787. ;; Skip consecutive keywords, clocks and diary S-exps.
  3788. (should
  3789. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n<point>"
  3790. (org-backward-paragraph)
  3791. (bobp)))
  3792. (should
  3793. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n<point>"
  3794. (org-backward-paragraph)
  3795. (bobp)))
  3796. (should
  3797. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n<point>"
  3798. (org-backward-paragraph)
  3799. (bobp)))
  3800. (should-not
  3801. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n<point>"
  3802. (org-backward-paragraph)
  3803. (bobp)))
  3804. (should-not
  3805. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n<point>"
  3806. (org-backward-paragraph)
  3807. (bobp)))
  3808. ;; On a comment, example, source and verse blocks, stop at blank
  3809. ;; lines.
  3810. (should
  3811. (= 1
  3812. (org-test-with-temp-text
  3813. "#+begin_comment\n<point>L1\n\nL2\n\nL3\n#+end_comment"
  3814. (org-backward-paragraph)
  3815. (org-current-line))))
  3816. (should
  3817. (= 2
  3818. (org-test-with-temp-text
  3819. "#+begin_verse\nL1\n\n<point>L2\n\nL3\n#+end_verse"
  3820. (org-backward-paragraph)
  3821. (org-current-line))))
  3822. (should
  3823. (= 3
  3824. (org-test-with-temp-text
  3825. "#+begin_src emacs-lisp\nL1\n\nL2\n\n<point>L3\n#+end_src"
  3826. (org-backward-paragraph)
  3827. (org-current-line))))
  3828. ;; When called from the opening line itself, however, move to
  3829. ;; beginning of block.
  3830. (should
  3831. (org-test-with-temp-text "#+begin_<point>example\nL1\n#+end_example"
  3832. (org-backward-paragraph)
  3833. (bobp)))
  3834. ;; On an empty heading, move above it.
  3835. (should
  3836. (org-test-with-temp-text "\n* <point>"
  3837. (org-backward-paragraph)
  3838. (bobp)))
  3839. (should
  3840. (org-test-with-temp-text "\n* \n<point>"
  3841. (org-backward-paragraph)
  3842. (bobp))))
  3843. (ert-deftest test-org/forward-element ()
  3844. "Test `org-forward-element' specifications."
  3845. ;; 1. At EOB: should error.
  3846. (org-test-with-temp-text "Some text\n"
  3847. (goto-char (point-max))
  3848. (should-error (org-forward-element)))
  3849. ;; 2. Standard move: expected to ignore blank lines.
  3850. (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
  3851. (org-forward-element)
  3852. (should (looking-at (regexp-quote "Second paragraph."))))
  3853. ;; 3. Headline tests.
  3854. (org-test-with-temp-text "
  3855. * Head 1
  3856. ** Head 1.1
  3857. *** Head 1.1.1
  3858. ** Head 1.2"
  3859. ;; 3.1. At an headline beginning: move to next headline at the
  3860. ;; same level.
  3861. (goto-line 3)
  3862. (org-forward-element)
  3863. (should (looking-at (regexp-quote "** Head 1.2")))
  3864. ;; 3.2. At an headline beginning: move to parent headline if no
  3865. ;; headline at the same level.
  3866. (goto-line 3)
  3867. (org-forward-element)
  3868. (should (looking-at (regexp-quote "** Head 1.2"))))
  3869. ;; 4. Greater element tests.
  3870. (org-test-with-temp-text
  3871. "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
  3872. ;; 4.1. At a greater element: expected to skip contents.
  3873. (org-forward-element)
  3874. (should (looking-at (regexp-quote "Outside.")))
  3875. ;; 4.2. At the end of greater element contents: expected to skip
  3876. ;; to the end of the greater element.
  3877. (goto-line 2)
  3878. (org-forward-element)
  3879. (should (looking-at (regexp-quote "Outside."))))
  3880. ;; 5. List tests.
  3881. (org-test-with-temp-text "
  3882. - item1
  3883. - sub1
  3884. - sub2
  3885. - sub3
  3886. Inner paragraph.
  3887. - item2
  3888. Outside."
  3889. ;; 5.1. At list top point: expected to move to the element after
  3890. ;; the list.
  3891. (goto-line 2)
  3892. (org-forward-element)
  3893. (should (looking-at (regexp-quote "Outside.")))
  3894. ;; 5.2. Special case: at the first line of a sub-list, but not at
  3895. ;; beginning of line, move to next item.
  3896. (goto-line 2)
  3897. (forward-char)
  3898. (org-forward-element)
  3899. (should (looking-at "- item2"))
  3900. (goto-line 4)
  3901. (forward-char)
  3902. (org-forward-element)
  3903. (should (looking-at " - sub2"))
  3904. ;; 5.3 At sub-list beginning: expected to move after the sub-list.
  3905. (goto-line 4)
  3906. (org-forward-element)
  3907. (should (looking-at (regexp-quote " Inner paragraph.")))
  3908. ;; 5.4. At sub-list end: expected to move outside the sub-list.
  3909. (goto-line 8)
  3910. (org-forward-element)
  3911. (should (looking-at (regexp-quote " Inner paragraph.")))
  3912. ;; 5.5. At an item: expected to move to next item, if any.
  3913. (goto-line 6)
  3914. (org-forward-element)
  3915. (should (looking-at " - sub3"))))
  3916. (ert-deftest test-org/backward-element ()
  3917. "Test `org-backward-element' specifications."
  3918. ;; 1. Should error at BOB.
  3919. (org-test-with-temp-text " \nParagraph."
  3920. (should-error (org-backward-element)))
  3921. ;; 2. Should move at BOB when called on the first element in buffer.
  3922. (should
  3923. (org-test-with-temp-text "\n#+TITLE: test"
  3924. (progn (forward-line)
  3925. (org-backward-element)
  3926. (bobp))))
  3927. ;; 3. Not at the beginning of an element: move at its beginning.
  3928. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  3929. (goto-line 3)
  3930. (end-of-line)
  3931. (org-backward-element)
  3932. (should (looking-at (regexp-quote "Paragraph2."))))
  3933. ;; 4. Headline tests.
  3934. (org-test-with-temp-text "
  3935. * Head 1
  3936. ** Head 1.1
  3937. *** Head 1.1.1
  3938. ** Head 1.2"
  3939. ;; 4.1. At an headline beginning: move to previous headline at the
  3940. ;; same level.
  3941. (goto-line 5)
  3942. (org-backward-element)
  3943. (should (looking-at (regexp-quote "** Head 1.1")))
  3944. ;; 4.2. At an headline beginning: move to parent headline if no
  3945. ;; headline at the same level.
  3946. (goto-line 3)
  3947. (org-backward-element)
  3948. (should (looking-at (regexp-quote "* Head 1")))
  3949. ;; 4.3. At the first top-level headline: should error.
  3950. (goto-line 2)
  3951. (should-error (org-backward-element)))
  3952. ;; 5. At beginning of first element inside a greater element:
  3953. ;; expected to move to greater element's beginning.
  3954. (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
  3955. (goto-line 3)
  3956. (org-backward-element)
  3957. (should (looking-at "#\\+BEGIN_CENTER")))
  3958. ;; 6. At the beginning of the first element in a section: should
  3959. ;; move back to headline, if any.
  3960. (should
  3961. (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
  3962. (progn (goto-char (point-max))
  3963. (beginning-of-line)
  3964. (org-backward-element)
  3965. (org-at-heading-p))))
  3966. ;; 7. List tests.
  3967. (org-test-with-temp-text "
  3968. - item1
  3969. - sub1
  3970. - sub2
  3971. - sub3
  3972. Inner paragraph.
  3973. - item2
  3974. Outside."
  3975. ;; 7.1. At beginning of sub-list: expected to move to the
  3976. ;; paragraph before it.
  3977. (goto-line 4)
  3978. (org-backward-element)
  3979. (should (looking-at "item1"))
  3980. ;; 7.2. At an item in a list: expected to move at previous item.
  3981. (goto-line 8)
  3982. (org-backward-element)
  3983. (should (looking-at " - sub2"))
  3984. (goto-line 12)
  3985. (org-backward-element)
  3986. (should (looking-at "- item1"))
  3987. ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
  3988. ;; beginning.
  3989. (goto-line 10)
  3990. (org-backward-element)
  3991. (should (looking-at " - sub1"))
  3992. (goto-line 15)
  3993. (org-backward-element)
  3994. (should (looking-at "- item1"))
  3995. ;; 7.4. At blank-lines before list end: expected to move to top
  3996. ;; item.
  3997. (goto-line 14)
  3998. (org-backward-element)
  3999. (should (looking-at "- item1"))))
  4000. (ert-deftest test-org/up-element ()
  4001. "Test `org-up-element' specifications."
  4002. ;; 1. At BOB or with no surrounding element: should error.
  4003. (org-test-with-temp-text "Paragraph."
  4004. (should-error (org-up-element)))
  4005. (org-test-with-temp-text "* Head1\n* Head2"
  4006. (goto-line 2)
  4007. (should-error (org-up-element)))
  4008. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  4009. (goto-line 3)
  4010. (should-error (org-up-element)))
  4011. ;; 2. At an headline: move to parent headline.
  4012. (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
  4013. (goto-line 3)
  4014. (org-up-element)
  4015. (should (looking-at "\\* Head1")))
  4016. ;; 3. Inside a greater element: move to greater element beginning.
  4017. (org-test-with-temp-text
  4018. "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
  4019. (goto-line 3)
  4020. (org-up-element)
  4021. (should (looking-at "#\\+BEGIN_CENTER")))
  4022. ;; 4. List tests.
  4023. (org-test-with-temp-text "* Top
  4024. - item1
  4025. - sub1
  4026. - sub2
  4027. Paragraph within sub2.
  4028. - item2"
  4029. ;; 4.1. Within an item: move to the item beginning.
  4030. (goto-line 8)
  4031. (org-up-element)
  4032. (should (looking-at " - sub2"))
  4033. ;; 4.2. At an item in a sub-list: move to parent item.
  4034. (goto-line 4)
  4035. (org-up-element)
  4036. (should (looking-at "- item1"))
  4037. ;; 4.3. At an item in top list: move to beginning of whole list.
  4038. (goto-line 10)
  4039. (org-up-element)
  4040. (should (looking-at "- item1"))
  4041. ;; 4.4. Special case. At very top point: should move to parent of
  4042. ;; list.
  4043. (goto-line 2)
  4044. (org-up-element)
  4045. (should (looking-at "\\* Top"))))
  4046. (ert-deftest test-org/down-element ()
  4047. "Test `org-down-element' specifications."
  4048. ;; Error when the element hasn't got a recursive type.
  4049. (org-test-with-temp-text "Paragraph."
  4050. (should-error (org-down-element)))
  4051. ;; Error when the element has no contents
  4052. (org-test-with-temp-text "* Headline"
  4053. (should-error (org-down-element)))
  4054. ;; When at a plain-list, move to first item.
  4055. (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
  4056. (goto-line 2)
  4057. (org-down-element)
  4058. (should (looking-at " - Item 1.1")))
  4059. (org-test-with-temp-text "#+NAME: list\n- Item 1"
  4060. (org-down-element)
  4061. (should (looking-at " Item 1")))
  4062. ;; When at a table, move to first row
  4063. (org-test-with-temp-text "#+NAME: table\n| a | b |"
  4064. (org-down-element)
  4065. (should (looking-at " a | b |")))
  4066. ;; Otherwise, move inside the greater element.
  4067. (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
  4068. (org-down-element)
  4069. (should (looking-at "Paragraph"))))
  4070. (ert-deftest test-org/drag-element-backward ()
  4071. "Test `org-drag-element-backward' specifications."
  4072. ;; Standard test.
  4073. (should
  4074. (equal
  4075. "#+key2: val2\n#+key1: val1\n#+key3: val3"
  4076. (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
  4077. (org-drag-element-backward)
  4078. (buffer-string))))
  4079. (should
  4080. (equal
  4081. "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
  4082. (org-test-with-temp-text
  4083. "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
  4084. (org-drag-element-backward)
  4085. (buffer-string))))
  4086. ;; Preserve blank lines.
  4087. (should
  4088. (equal "Paragraph 2\n\n\nPara1\n\nPara3"
  4089. (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
  4090. (org-drag-element-backward)
  4091. (buffer-string))))
  4092. ;; Preserve column.
  4093. (should
  4094. (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
  4095. (org-drag-element-backward)
  4096. (looking-at-p "2")))
  4097. ;; Error when trying to move first element of buffer.
  4098. (should-error
  4099. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4100. (org-drag-element-backward))
  4101. :type 'user-error)
  4102. ;; Error when trying to swap nested elements.
  4103. (should-error
  4104. (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
  4105. (org-drag-element-backward))
  4106. :type 'user-error)
  4107. ;; Error when trying to swap an headline element and a non-headline
  4108. ;; element.
  4109. (should-error
  4110. (org-test-with-temp-text "Test.\n<point>* Head 1"
  4111. (org-drag-element-backward))
  4112. :type 'error)
  4113. ;; Error when called before first element.
  4114. (should-error
  4115. (org-test-with-temp-text "\n<point>"
  4116. (org-drag-element-backward))
  4117. :type 'user-error)
  4118. ;; Preserve visibility of elements and their contents.
  4119. (should
  4120. (equal '((63 . 82) (26 . 48))
  4121. (org-test-with-temp-text "
  4122. #+BEGIN_CENTER
  4123. Text.
  4124. #+END_CENTER
  4125. - item 1
  4126. #+BEGIN_QUOTE
  4127. Text.
  4128. #+END_QUOTE"
  4129. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4130. (search-backward "- item 1")
  4131. (org-drag-element-backward)
  4132. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4133. (overlays-in (point-min) (point-max))))))
  4134. ;; Pathological case: handle call with point in blank lines right
  4135. ;; after a headline.
  4136. (should
  4137. (equal "* H2\n\n* H1\nText\n"
  4138. (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
  4139. (org-drag-element-backward)
  4140. (buffer-string)))))
  4141. (ert-deftest test-org/drag-element-forward ()
  4142. "Test `org-drag-element-forward' specifications."
  4143. ;; 1. Error when trying to move first element of buffer.
  4144. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4145. (goto-line 3)
  4146. (should-error (org-drag-element-forward)))
  4147. ;; 2. Error when trying to swap nested elements.
  4148. (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
  4149. (forward-line)
  4150. (should-error (org-drag-element-forward)))
  4151. ;; 3. Error when trying to swap a non-headline element and an
  4152. ;; headline.
  4153. (org-test-with-temp-text "Test.\n* Head 1"
  4154. (should-error (org-drag-element-forward)))
  4155. ;; 4. Error when called before first element.
  4156. (should-error
  4157. (org-test-with-temp-text "\n"
  4158. (forward-line)
  4159. (org-drag-element-backward))
  4160. :type 'user-error)
  4161. ;; 5. Otherwise, swap elements, preserving column and blank lines
  4162. ;; between elements.
  4163. (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
  4164. (search-forward "graph")
  4165. (org-drag-element-forward)
  4166. (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
  4167. (should (looking-at " 1")))
  4168. ;; 5. Preserve visibility of elements and their contents.
  4169. (org-test-with-temp-text "
  4170. #+BEGIN_CENTER
  4171. Text.
  4172. #+END_CENTER
  4173. - item 1
  4174. #+BEGIN_QUOTE
  4175. Text.
  4176. #+END_QUOTE"
  4177. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4178. (search-backward "#+BEGIN_CENTER")
  4179. (org-drag-element-forward)
  4180. (should
  4181. (equal
  4182. '((63 . 82) (26 . 48))
  4183. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4184. (overlays-in (point-min) (point-max)))))))
  4185. (ert-deftest test-org/next-block ()
  4186. "Test `org-next-block' specifications."
  4187. ;; Regular test.
  4188. (should
  4189. (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  4190. (org-next-block 1)
  4191. (looking-at "#\\+BEGIN_CENTER")))
  4192. ;; Ignore case.
  4193. (should
  4194. (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
  4195. (let ((case-fold-search nil))
  4196. (org-next-block 1)
  4197. (looking-at "#\\+begin_center"))))
  4198. ;; Ignore current line.
  4199. (should
  4200. (org-test-with-temp-text
  4201. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
  4202. (org-next-block 1)
  4203. (looking-at "#\\+BEGIN_CENTER")))
  4204. ;; Throw an error when no block is found.
  4205. (should-error
  4206. (org-test-with-temp-text "Paragraph"
  4207. (org-next-block 1)))
  4208. ;; With an argument, skip many blocks at once.
  4209. (should
  4210. (org-test-with-temp-text
  4211. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4212. (org-next-block 2)
  4213. (looking-at "#\\+BEGIN_QUOTE")))
  4214. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4215. (should
  4216. (org-test-with-temp-text
  4217. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4218. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4219. (looking-at "#\\+BEGIN_QUOTE")))
  4220. ;; Optional argument is also case-insensitive.
  4221. (should
  4222. (org-test-with-temp-text
  4223. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
  4224. (let ((case-fold-search nil))
  4225. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4226. (looking-at "#\\+begin_quote")))))
  4227. (ert-deftest test-org/insert-structure-template ()
  4228. "Test `org-insert-structure-template'."
  4229. ;; Test in empty buffer.
  4230. (should
  4231. (string= "#+begin_foo\n#+end_foo\n"
  4232. (org-test-with-temp-text ""
  4233. (org-insert-structure-template "foo")
  4234. (buffer-string))))
  4235. ;; Test with multiple lines in buffer.
  4236. (should
  4237. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4238. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4239. (transient-mark-mode 1)
  4240. (org-mark-element)
  4241. (org-insert-structure-template "foo")
  4242. (buffer-string))))
  4243. ;; Mark only the current line.
  4244. (should
  4245. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4246. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4247. (transient-mark-mode 1)
  4248. (set-mark (point-min))
  4249. (end-of-line)
  4250. (org-insert-structure-template "foo")
  4251. (buffer-string))))
  4252. ;; Middle of paragraph.
  4253. (should
  4254. (string= "p1\n#+begin_foo\np2\n#+end_foo\np3"
  4255. (org-test-with-temp-text "p1\n<point>p2\np3"
  4256. (set-mark (line-beginning-position))
  4257. (end-of-line)
  4258. (activate-mark)
  4259. (org-insert-structure-template "foo")
  4260. (buffer-string))))
  4261. ;; Test with text in buffer, no region, no final newline.
  4262. (should
  4263. (string= "#+begin_foo\nI'm a paragraph.\n#+end_foo\n"
  4264. (org-test-with-temp-text "I'm a paragraph."
  4265. (org-mark-element)
  4266. (org-insert-structure-template "foo")
  4267. (buffer-string))))
  4268. ;; Test with text in buffer and region set.
  4269. (should
  4270. (string= "#+begin_foo\nI'm a paragraph\n\nI'm a second paragrah\n#+end_foo\n"
  4271. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragrah"
  4272. (set-mark (point))
  4273. (goto-char (point-max))
  4274. (org-insert-structure-template "foo")
  4275. (buffer-string))))
  4276. ;; Test with example escaping.
  4277. (should
  4278. (string= "#+begin_example\n,* Heading\n#+end_example\n"
  4279. (org-test-with-temp-text "* Heading"
  4280. (org-mark-element)
  4281. (org-insert-structure-template "example")
  4282. (buffer-string))))
  4283. ;; Test with indentation.
  4284. (should
  4285. (string= " #+begin_foo\n This is a paragraph\n #+end_foo\n"
  4286. (org-test-with-temp-text " This is a paragraph"
  4287. (org-mark-element)
  4288. (org-insert-structure-template "foo")
  4289. (buffer-string))))
  4290. (should
  4291. (string= " #+begin_foo\n Line 1\n Line2\n #+end_foo\n"
  4292. (org-test-with-temp-text " Line 1\n Line2"
  4293. (org-mark-element)
  4294. (org-insert-structure-template "foo")
  4295. (buffer-string))))
  4296. ;; Test point location.
  4297. (should
  4298. (string= "#+begin_foo\n"
  4299. (org-test-with-temp-text ""
  4300. (org-insert-structure-template "foo")
  4301. (buffer-substring (point-min) (point)))))
  4302. (should
  4303. (string= "#+begin_src "
  4304. (org-test-with-temp-text ""
  4305. (org-insert-structure-template "src")
  4306. (buffer-substring (point-min) (point))))))
  4307. (ert-deftest test-org/previous-block ()
  4308. "Test `org-previous-block' specifications."
  4309. ;; Regular test.
  4310. (should
  4311. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
  4312. (org-previous-block 1)
  4313. (looking-at "#\\+BEGIN_CENTER")))
  4314. ;; Ignore case.
  4315. (should
  4316. (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
  4317. (let ((case-fold-search nil))
  4318. (org-previous-block 1)
  4319. (looking-at "#\\+begin_center"))))
  4320. ;; Ignore current line.
  4321. (should
  4322. (org-test-with-temp-text
  4323. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
  4324. (org-previous-block 1)
  4325. (looking-at "#\\+BEGIN_QUOTE")))
  4326. ;; Throw an error when no block is found.
  4327. (should-error
  4328. (org-test-with-temp-text "Paragraph<point>"
  4329. (org-previous-block 1)))
  4330. ;; With an argument, skip many blocks at once.
  4331. (should
  4332. (org-test-with-temp-text
  4333. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4334. (org-previous-block 2)
  4335. (looking-at "#\\+BEGIN_CENTER")))
  4336. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4337. (should
  4338. (org-test-with-temp-text
  4339. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4340. (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4341. (looking-at "#\\+BEGIN_QUOTE")))
  4342. ;; Optional argument is also case-insensitive.
  4343. (should
  4344. (org-test-with-temp-text
  4345. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
  4346. (let ((case-fold-search nil))
  4347. (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4348. (looking-at "#\\+begin_quote")))))
  4349. ;;; Outline structure
  4350. (ert-deftest test-org/demote ()
  4351. "Test `org-demote' specifications."
  4352. ;; Add correct number of stars according to `org-odd-levels-only'.
  4353. (should
  4354. (= 2
  4355. (org-test-with-temp-text "* H"
  4356. (let ((org-odd-levels-only nil)) (org-demote))
  4357. (org-current-level))))
  4358. (should
  4359. (= 3
  4360. (org-test-with-temp-text "* H"
  4361. (let ((org-odd-levels-only t)) (org-demote))
  4362. (org-current-level))))
  4363. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4364. (should
  4365. (org-test-with-temp-text "* H :tag:"
  4366. (let ((org-tags-column 10)
  4367. (org-auto-align-tags t)
  4368. (org-odd-levels-only nil))
  4369. (org-demote))
  4370. (org-move-to-column 10)
  4371. (looking-at-p ":tag:$")))
  4372. (should-not
  4373. (org-test-with-temp-text "* H :tag:"
  4374. (let ((org-tags-column 10)
  4375. (org-auto-align-tags nil)
  4376. (org-odd-levels-only nil))
  4377. (org-demote))
  4378. (org-move-to-column 10)
  4379. (looking-at-p ":tag:$")))
  4380. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4381. ;; info and property drawers accordingly.
  4382. (should
  4383. (= 3
  4384. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4385. (let ((org-odd-levels-only nil)
  4386. (org-adapt-indentation t))
  4387. (org-demote))
  4388. (forward-line)
  4389. (org-get-indentation))))
  4390. (should
  4391. (= 3
  4392. (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4393. (let ((org-odd-levels-only nil)
  4394. (org-adapt-indentation t))
  4395. (org-demote))
  4396. (forward-line)
  4397. (org-get-indentation))))
  4398. (should-not
  4399. (= 3
  4400. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4401. (let ((org-odd-levels-only nil)
  4402. (org-adapt-indentation nil))
  4403. (org-demote))
  4404. (forward-line)
  4405. (org-get-indentation))))
  4406. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4407. ;; section accordingly. Ignore, however, footnote definitions and
  4408. ;; inlinetasks boundaries.
  4409. (should
  4410. (= 3
  4411. (org-test-with-temp-text "* H\n Paragraph"
  4412. (let ((org-odd-levels-only nil)
  4413. (org-adapt-indentation t))
  4414. (org-demote))
  4415. (forward-line)
  4416. (org-get-indentation))))
  4417. (should
  4418. (= 2
  4419. (org-test-with-temp-text "* H\n Paragraph"
  4420. (let ((org-odd-levels-only nil)
  4421. (org-adapt-indentation nil))
  4422. (org-demote))
  4423. (forward-line)
  4424. (org-get-indentation))))
  4425. (should
  4426. (zerop
  4427. (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
  4428. (let ((org-odd-levels-only nil)
  4429. (org-adapt-indentation t))
  4430. (org-demote))
  4431. (goto-char (point-max))
  4432. (org-get-indentation))))
  4433. (should
  4434. (= 3
  4435. (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
  4436. (let ((org-odd-levels-only nil)
  4437. (org-adapt-indentation t))
  4438. (org-demote))
  4439. (goto-char (point-max))
  4440. (org-get-indentation))))
  4441. (when (featurep 'org-inlinetask)
  4442. (should
  4443. (zerop
  4444. (let ((org-inlinetask-min-level 5)
  4445. (org-adapt-indentation t))
  4446. (org-test-with-temp-text "* H\n***** I\n***** END"
  4447. (org-demote)
  4448. (forward-line)
  4449. (org-get-indentation))))))
  4450. (when (featurep 'org-inlinetask)
  4451. (should
  4452. (= 3
  4453. (let ((org-inlinetask-min-level 5)
  4454. (org-adapt-indentation t))
  4455. (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
  4456. (org-demote)
  4457. (forward-line 2)
  4458. (org-get-indentation))))))
  4459. ;; Ignore contents of source blocks or example blocks when
  4460. ;; indentation should be preserved (through
  4461. ;; `org-src-preserve-indentation' or "-i" flag).
  4462. (should-not
  4463. (zerop
  4464. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4465. (let ((org-adapt-indentation t)
  4466. (org-src-preserve-indentation nil))
  4467. (org-demote))
  4468. (forward-line 2)
  4469. (org-get-indentation))))
  4470. (should
  4471. (zerop
  4472. (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
  4473. (let ((org-adapt-indentation t)
  4474. (org-src-preserve-indentation t))
  4475. (org-demote))
  4476. (forward-line 2)
  4477. (org-get-indentation))))
  4478. (should
  4479. (zerop
  4480. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4481. (let ((org-adapt-indentation t)
  4482. (org-src-preserve-indentation t))
  4483. (org-demote))
  4484. (forward-line 2)
  4485. (org-get-indentation))))
  4486. (should
  4487. (zerop
  4488. (org-test-with-temp-text
  4489. "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
  4490. (let ((org-adapt-indentation t)
  4491. (org-src-preserve-indentation nil))
  4492. (org-demote))
  4493. (forward-line 2)
  4494. (org-get-indentation)))))
  4495. (ert-deftest test-org/promote ()
  4496. "Test `org-promote' specifications."
  4497. ;; Return an error if headline is to be promoted to level 0, unless
  4498. ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
  4499. ;; headline becomes a comment.
  4500. (should-error
  4501. (org-test-with-temp-text "* H"
  4502. (let ((org-allow-promoting-top-level-subtree nil)) (org-promote))))
  4503. (should
  4504. (equal "# H"
  4505. (org-test-with-temp-text "* H"
  4506. (let ((org-allow-promoting-top-level-subtree t)) (org-promote))
  4507. (buffer-string))))
  4508. ;; Remove correct number of stars according to
  4509. ;; `org-odd-levels-only'.
  4510. (should
  4511. (= 2
  4512. (org-test-with-temp-text "*** H"
  4513. (let ((org-odd-levels-only nil)) (org-promote))
  4514. (org-current-level))))
  4515. (should
  4516. (= 1
  4517. (org-test-with-temp-text "*** H"
  4518. (let ((org-odd-levels-only t)) (org-promote))
  4519. (org-current-level))))
  4520. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4521. (should
  4522. (org-test-with-temp-text "** H :tag:"
  4523. (let ((org-tags-column 10)
  4524. (org-auto-align-tags t)
  4525. (org-odd-levels-only nil))
  4526. (org-promote))
  4527. (org-move-to-column 10)
  4528. (looking-at-p ":tag:$")))
  4529. (should-not
  4530. (org-test-with-temp-text "** H :tag:"
  4531. (let ((org-tags-column 10)
  4532. (org-auto-align-tags nil)
  4533. (org-odd-levels-only nil))
  4534. (org-promote))
  4535. (org-move-to-column 10)
  4536. (looking-at-p ":tag:$")))
  4537. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4538. ;; info and property drawers.
  4539. (should
  4540. (= 2
  4541. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4542. (let ((org-odd-levels-only nil)
  4543. (org-adapt-indentation t))
  4544. (org-promote))
  4545. (forward-line)
  4546. (org-get-indentation))))
  4547. (should
  4548. (= 2
  4549. (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4550. (let ((org-odd-levels-only nil)
  4551. (org-adapt-indentation t))
  4552. (org-promote))
  4553. (forward-line)
  4554. (org-get-indentation))))
  4555. (should-not
  4556. (= 2
  4557. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4558. (let ((org-odd-levels-only nil)
  4559. (org-adapt-indentation nil))
  4560. (org-promote))
  4561. (forward-line)
  4562. (org-get-indentation))))
  4563. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4564. ;; section accordingly. Ignore, however, footnote definitions and
  4565. ;; inlinetasks boundaries.
  4566. (should
  4567. (= 2
  4568. (org-test-with-temp-text "** H\n Paragraph"
  4569. (let ((org-odd-levels-only nil)
  4570. (org-adapt-indentation t))
  4571. (org-promote))
  4572. (forward-line)
  4573. (org-get-indentation))))
  4574. (should-not
  4575. (= 2
  4576. (org-test-with-temp-text "** H\n Paragraph"
  4577. (let ((org-odd-levels-only nil)
  4578. (org-adapt-indentation nil))
  4579. (org-promote))
  4580. (forward-line)
  4581. (org-get-indentation))))
  4582. (should
  4583. (= 2
  4584. (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
  4585. (let ((org-odd-levels-only nil)
  4586. (org-adapt-indentation t))
  4587. (org-promote))
  4588. (forward-line)
  4589. (org-get-indentation))))
  4590. (when (featurep 'org-inlinetask)
  4591. (should
  4592. (zerop
  4593. (let ((org-inlinetask-min-level 5)
  4594. (org-adapt-indentation t))
  4595. (org-test-with-temp-text "** H\n***** I\n***** END"
  4596. (org-promote)
  4597. (forward-line)
  4598. (org-get-indentation))))))
  4599. (when (featurep 'org-inlinetask)
  4600. (should
  4601. (= 2
  4602. (let ((org-inlinetask-min-level 5)
  4603. (org-adapt-indentation t))
  4604. (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
  4605. (org-promote)
  4606. (forward-line 2)
  4607. (org-get-indentation))))))
  4608. ;; Give up shifting if it would break document's structure
  4609. ;; otherwise.
  4610. (should
  4611. (= 3
  4612. (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
  4613. (let ((org-odd-levels-only nil)
  4614. (org-adapt-indentation t))
  4615. (org-promote))
  4616. (forward-line)
  4617. (org-get-indentation))))
  4618. (should
  4619. (= 3
  4620. (org-test-with-temp-text "** H\n Paragraph\n * list."
  4621. (let ((org-odd-levels-only nil)
  4622. (org-adapt-indentation t))
  4623. (org-promote))
  4624. (forward-line)
  4625. (org-get-indentation))))
  4626. ;; Ignore contents of source blocks or example blocks when
  4627. ;; indentation should be preserved (through
  4628. ;; `org-src-preserve-indentation' or "-i" flag).
  4629. (should-not
  4630. (zerop
  4631. (org-test-with-temp-text
  4632. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  4633. (let ((org-adapt-indentation t)
  4634. (org-src-preserve-indentation nil)
  4635. (org-odd-levels-only nil))
  4636. (org-promote))
  4637. (forward-line)
  4638. (org-get-indentation))))
  4639. (should
  4640. (zerop
  4641. (org-test-with-temp-text
  4642. "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
  4643. (let ((org-adapt-indentation t)
  4644. (org-src-preserve-indentation t)
  4645. (org-odd-levels-only nil))
  4646. (org-promote))
  4647. (forward-line)
  4648. (org-get-indentation))))
  4649. (should
  4650. (zerop
  4651. (org-test-with-temp-text
  4652. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  4653. (let ((org-adapt-indentation t)
  4654. (org-src-preserve-indentation t)
  4655. (org-odd-levels-only nil))
  4656. (org-promote))
  4657. (forward-line)
  4658. (org-get-indentation))))
  4659. (should
  4660. (zerop
  4661. (org-test-with-temp-text
  4662. "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
  4663. (let ((org-adapt-indentation t)
  4664. (org-src-preserve-indentation nil)
  4665. (org-odd-levels-only nil))
  4666. (org-promote))
  4667. (forward-line)
  4668. (org-get-indentation)))))
  4669. (ert-deftest test-org/org-get-valid-level ()
  4670. "Test function `org-get-valid-level' specifications."
  4671. (let ((org-odd-levels-only nil))
  4672. (should (equal 1 (org-get-valid-level 0 0)))
  4673. (should (equal 1 (org-get-valid-level 0 1)))
  4674. (should (equal 2 (org-get-valid-level 0 2)))
  4675. (should (equal 3 (org-get-valid-level 0 3)))
  4676. (should (equal 1 (org-get-valid-level 1 0)))
  4677. (should (equal 2 (org-get-valid-level 1 1)))
  4678. (should (equal 23 (org-get-valid-level 1 22)))
  4679. (should (equal 1 (org-get-valid-level 1 -1)))
  4680. (should (equal 1 (org-get-valid-level 2 -1))))
  4681. (let ((org-odd-levels-only t))
  4682. (should (equal 1 (org-get-valid-level 0 0)))
  4683. (should (equal 1 (org-get-valid-level 0 1)))
  4684. (should (equal 3 (org-get-valid-level 0 2)))
  4685. (should (equal 5 (org-get-valid-level 0 3)))
  4686. (should (equal 1 (org-get-valid-level 1 0)))
  4687. (should (equal 3 (org-get-valid-level 1 1)))
  4688. (should (equal 3 (org-get-valid-level 2 1)))
  4689. (should (equal 5 (org-get-valid-level 3 1)))
  4690. (should (equal 5 (org-get-valid-level 4 1)))
  4691. (should (equal 43 (org-get-valid-level 1 21)))
  4692. (should (equal 1 (org-get-valid-level 1 -1)))
  4693. (should (equal 1 (org-get-valid-level 2 -1)))
  4694. (should (equal 1 (org-get-valid-level 3 -1)))
  4695. (should (equal 3 (org-get-valid-level 4 -1)))
  4696. (should (equal 3 (org-get-valid-level 5 -1)))))
  4697. ;;; Planning
  4698. (ert-deftest test-org/at-planning-p ()
  4699. "Test `org-at-planning-p' specifications."
  4700. ;; Regular test.
  4701. (should
  4702. (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
  4703. (org-at-planning-p)))
  4704. (should-not
  4705. (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
  4706. (org-at-planning-p)))
  4707. ;; Correctly find planning attached to inlinetasks.
  4708. (when (featurep 'org-inlinetask)
  4709. (should
  4710. (org-test-with-temp-text
  4711. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
  4712. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4713. (should-not
  4714. (org-test-with-temp-text
  4715. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  4716. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4717. (should-not
  4718. (org-test-with-temp-text
  4719. "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  4720. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4721. (should-not
  4722. (org-test-with-temp-text
  4723. "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
  4724. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
  4725. (ert-deftest test-org/add-planning-info ()
  4726. "Test `org-add-planning-info'."
  4727. ;; Create deadline when `org-adapt-indentation' is non-nil.
  4728. (should
  4729. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4730. (org-test-with-temp-text "* H\nParagraph<point>"
  4731. (let ((org-adapt-indentation t))
  4732. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4733. (replace-regexp-in-string
  4734. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4735. nil nil 1))))
  4736. ;; Create deadline when `org-adapt-indentation' is nil.
  4737. (should
  4738. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  4739. (org-test-with-temp-text "* H\nParagraph<point>"
  4740. (let ((org-adapt-indentation nil))
  4741. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4742. (replace-regexp-in-string
  4743. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4744. nil nil 1))))
  4745. ;; Update deadline when `org-adapt-indentation' is non-nil.
  4746. (should
  4747. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4748. (org-test-with-temp-text "\
  4749. * H
  4750. DEADLINE: <2015-06-24 Wed>
  4751. Paragraph<point>"
  4752. (let ((org-adapt-indentation t))
  4753. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4754. (replace-regexp-in-string
  4755. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4756. nil nil 1))))
  4757. ;; Update deadline when `org-adapt-indentation' is nil.
  4758. (should
  4759. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  4760. (org-test-with-temp-text "\
  4761. * H
  4762. DEADLINE: <2015-06-24 Wed>
  4763. Paragraph<point>"
  4764. (let ((org-adapt-indentation nil))
  4765. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4766. (replace-regexp-in-string
  4767. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4768. nil nil 1))))
  4769. ;; Schedule when `org-adapt-indentation' is non-nil.
  4770. (should
  4771. (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
  4772. (org-test-with-temp-text "* H\nParagraph<point>"
  4773. (let ((org-adapt-indentation t))
  4774. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  4775. (replace-regexp-in-string
  4776. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4777. nil nil 1))))
  4778. ;; Schedule when `org-adapt-indentation' is nil.
  4779. (should
  4780. (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
  4781. (org-test-with-temp-text "* H\nParagraph<point>"
  4782. (let ((org-adapt-indentation nil))
  4783. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  4784. (replace-regexp-in-string
  4785. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4786. nil nil 1))))
  4787. ;; Add deadline when scheduled.
  4788. (should
  4789. (equal "\
  4790. * H
  4791. DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
  4792. Paragraph"
  4793. (org-test-with-temp-text "\
  4794. * H
  4795. SCHEDULED: <2015-06-24 Wed>
  4796. Paragraph<point>"
  4797. (let ((org-adapt-indentation t))
  4798. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4799. (replace-regexp-in-string
  4800. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4801. nil nil 1))))
  4802. ;; Remove middle entry.
  4803. (should
  4804. (equal "\
  4805. * H
  4806. CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
  4807. Paragraph"
  4808. (org-test-with-temp-text "\
  4809. * H
  4810. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  4811. Paragraph<point>"
  4812. (let ((org-adapt-indentation t))
  4813. (org-add-planning-info nil nil 'deadline))
  4814. (replace-regexp-in-string
  4815. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  4816. nil nil 1))))
  4817. ;; Remove last entry and then middle entry (order should not
  4818. ;; matter).
  4819. (should
  4820. (equal "\
  4821. * H
  4822. CLOSED: [2015-06-24]
  4823. Paragraph"
  4824. (org-test-with-temp-text "\
  4825. * H
  4826. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  4827. Paragraph<point>"
  4828. (let ((org-adapt-indentation t))
  4829. (org-add-planning-info nil nil 'scheduled 'deadline))
  4830. (replace-regexp-in-string
  4831. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  4832. nil nil 1))))
  4833. ;; Remove closed when `org-adapt-indentation' is non-nil.
  4834. (should
  4835. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4836. (org-test-with-temp-text "\
  4837. * H
  4838. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  4839. Paragraph<point>"
  4840. (let ((org-adapt-indentation t))
  4841. (org-add-planning-info nil nil 'closed))
  4842. (replace-regexp-in-string
  4843. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4844. nil nil 1))))
  4845. (should
  4846. (equal "* H\n Paragraph"
  4847. (org-test-with-temp-text "\
  4848. * H
  4849. CLOSED: [2015-06-25 Thu]
  4850. Paragraph<point>"
  4851. (let ((org-adapt-indentation t))
  4852. (org-add-planning-info nil nil 'closed))
  4853. (replace-regexp-in-string
  4854. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4855. nil nil 1))))
  4856. ;; Remove closed when `org-adapt-indentation' is nil.
  4857. (should
  4858. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  4859. (org-test-with-temp-text "\
  4860. * H
  4861. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  4862. Paragraph<point>"
  4863. (let ((org-adapt-indentation nil))
  4864. (org-add-planning-info nil nil 'closed))
  4865. (replace-regexp-in-string
  4866. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4867. nil nil 1))))
  4868. (should
  4869. (equal "* H\nParagraph"
  4870. (org-test-with-temp-text "\
  4871. * H
  4872. CLOSED: [2015-06-25 Thu]
  4873. Paragraph<point>"
  4874. (let ((org-adapt-indentation nil))
  4875. (org-add-planning-info nil nil 'closed))
  4876. (replace-regexp-in-string
  4877. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4878. nil nil 1))))
  4879. ;; Remove closed entry and delete empty line.
  4880. (should
  4881. (equal "\
  4882. * H
  4883. Paragraph"
  4884. (org-test-with-temp-text "\
  4885. * H
  4886. CLOSED: [2015-06-24 Wed]
  4887. Paragraph<point>"
  4888. (let ((org-adapt-indentation t))
  4889. (org-add-planning-info nil nil 'closed))
  4890. (replace-regexp-in-string
  4891. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4892. nil nil 1))))
  4893. ;; Remove one entry and update another.
  4894. (should
  4895. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4896. (org-test-with-temp-text "\
  4897. * H
  4898. SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
  4899. Paragraph<point>"
  4900. (let ((org-adapt-indentation t))
  4901. (org-add-planning-info 'deadline "<2015-06-25 Thu>" 'scheduled))
  4902. (replace-regexp-in-string
  4903. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4904. nil nil 1)))))
  4905. (ert-deftest test-org/deadline ()
  4906. "Test `org-deadline' specifications."
  4907. ;; Insert a new value or replace existing one.
  4908. (should
  4909. (equal "* H\nDEADLINE: <2012-03-29>"
  4910. (org-test-with-temp-text "* H"
  4911. (let ((org-adapt-indentation nil)
  4912. (org-last-inserted-timestamp nil))
  4913. (org-deadline nil "<2012-03-29 Tue>"))
  4914. (replace-regexp-in-string
  4915. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4916. nil nil 1))))
  4917. (should
  4918. (equal "* H\nDEADLINE: <2014-03-04>"
  4919. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  4920. (let ((org-adapt-indentation nil)
  4921. (org-last-inserted-timestamp nil))
  4922. (org-deadline nil "<2014-03-04 Thu>"))
  4923. (replace-regexp-in-string
  4924. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4925. nil nil 1))))
  4926. ;; Accept delta time, e.g., "+2d".
  4927. (should
  4928. (equal "* H\nDEADLINE: <2015-03-04>"
  4929. (org-test-at-time "2014-03-04"
  4930. (org-test-with-temp-text "* H"
  4931. (let ((org-adapt-indentation nil)
  4932. (org-last-inserted-timestamp nil))
  4933. (org-deadline nil "+1y"))
  4934. (replace-regexp-in-string
  4935. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  4936. ;; Preserve repeater.
  4937. (should
  4938. (equal "* H\nDEADLINE: <2012-03-29 +2y>"
  4939. (org-test-with-temp-text "* H"
  4940. (let ((org-adapt-indentation nil)
  4941. (org-last-inserted-timestamp nil))
  4942. (org-deadline nil "<2012-03-29 Tue +2y>"))
  4943. (replace-regexp-in-string
  4944. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  4945. ;; Remove CLOSED keyword, if any.
  4946. (should
  4947. (equal "* H\nDEADLINE: <2012-03-29>"
  4948. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  4949. (let ((org-adapt-indentation nil)
  4950. (org-last-inserted-timestamp nil))
  4951. (org-deadline nil "<2012-03-29 Tue>"))
  4952. (replace-regexp-in-string
  4953. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  4954. ;; With C-u argument, remove DEADLINE keyword.
  4955. (should
  4956. (equal "* H\n"
  4957. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  4958. (let ((org-adapt-indentation nil)
  4959. (org-last-inserted-timestamp nil))
  4960. (org-deadline '(4)))
  4961. (buffer-string))))
  4962. (should
  4963. (equal "* H"
  4964. (org-test-with-temp-text "* H"
  4965. (let ((org-adapt-indentation nil)
  4966. (org-last-inserted-timestamp nil))
  4967. (org-deadline '(4)))
  4968. (buffer-string))))
  4969. ;; With C-u C-u argument, prompt for a delay cookie.
  4970. (should
  4971. (equal "* H\nDEADLINE: <2012-03-29 -705d>"
  4972. (cl-letf (((symbol-function 'org-read-date)
  4973. (lambda (&rest args)
  4974. (apply #'encode-time
  4975. (org-parse-time-string "2014-03-04")))))
  4976. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  4977. (let ((org-adapt-indentation nil)
  4978. (org-last-inserted-timestamp nil))
  4979. (org-deadline '(16)))
  4980. (buffer-string)))))
  4981. (should-error
  4982. (cl-letf (((symbol-function 'org-read-date)
  4983. (lambda (&rest args)
  4984. (apply #'encode-time
  4985. (org-parse-time-string "2014-03-04")))))
  4986. (org-test-with-temp-text "* H"
  4987. (let ((org-adapt-indentation nil)
  4988. (org-last-inserted-timestamp nil))
  4989. (org-deadline '(16)))
  4990. (buffer-string))))
  4991. ;; When a region is active and
  4992. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  4993. ;; same value in all headlines in region.
  4994. (should
  4995. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  4996. (org-test-with-temp-text "* H1\n* H2"
  4997. (let ((org-adapt-indentation nil)
  4998. (org-last-inserted-timestamp nil)
  4999. (org-loop-over-headlines-in-active-region t))
  5000. (transient-mark-mode 1)
  5001. (push-mark (point) t t)
  5002. (goto-char (point-max))
  5003. (org-deadline nil "2012-03-29"))
  5004. (replace-regexp-in-string
  5005. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5006. (should-not
  5007. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5008. (org-test-with-temp-text "* H1\n* H2"
  5009. (let ((org-adapt-indentation nil)
  5010. (org-last-inserted-timestamp nil)
  5011. (org-loop-over-headlines-in-active-region nil))
  5012. (transient-mark-mode 1)
  5013. (push-mark (point) t t)
  5014. (goto-char (point-max))
  5015. (org-deadline nil "2012-03-29"))
  5016. (replace-regexp-in-string
  5017. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5018. (ert-deftest test-org/schedule ()
  5019. "Test `org-schedule' specifications."
  5020. ;; Insert a new value or replace existing one.
  5021. (should
  5022. (equal "* H\nSCHEDULED: <2012-03-29>"
  5023. (org-test-with-temp-text "* H"
  5024. (let ((org-adapt-indentation nil)
  5025. (org-last-inserted-timestamp nil))
  5026. (org-schedule nil "<2012-03-29 Tue>"))
  5027. (replace-regexp-in-string
  5028. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5029. nil nil 1))))
  5030. (should
  5031. (equal "* H\nSCHEDULED: <2014-03-04>"
  5032. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5033. (let ((org-adapt-indentation nil)
  5034. (org-last-inserted-timestamp nil))
  5035. (org-schedule nil "<2014-03-04 Thu>"))
  5036. (replace-regexp-in-string
  5037. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5038. nil nil 1))))
  5039. ;; Accept delta time, e.g., "+2d".
  5040. (should
  5041. (equal "* H\nSCHEDULED: <2015-03-04>"
  5042. (org-test-at-time "2014-03-04"
  5043. (org-test-with-temp-text "* H"
  5044. (let ((org-adapt-indentation nil)
  5045. (org-last-inserted-timestamp nil))
  5046. (org-schedule nil "+1y"))
  5047. (replace-regexp-in-string
  5048. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5049. ;; Preserve repeater.
  5050. (should
  5051. (equal "* H\nSCHEDULED: <2012-03-29 +2y>"
  5052. (org-test-with-temp-text "* H"
  5053. (let ((org-adapt-indentation nil)
  5054. (org-last-inserted-timestamp nil))
  5055. (org-schedule nil "<2012-03-29 Tue +2y>"))
  5056. (replace-regexp-in-string
  5057. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5058. ;; Remove CLOSED keyword, if any.
  5059. (should
  5060. (equal "* H\nSCHEDULED: <2012-03-29>"
  5061. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  5062. (let ((org-adapt-indentation nil)
  5063. (org-last-inserted-timestamp nil))
  5064. (org-schedule nil "<2012-03-29 Tue>"))
  5065. (replace-regexp-in-string
  5066. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5067. ;; With C-u argument, remove SCHEDULED keyword.
  5068. (should
  5069. (equal "* H\n"
  5070. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5071. (let ((org-adapt-indentation nil)
  5072. (org-last-inserted-timestamp nil))
  5073. (org-schedule '(4)))
  5074. (buffer-string))))
  5075. (should
  5076. (equal "* H"
  5077. (org-test-with-temp-text "* H"
  5078. (let ((org-adapt-indentation nil)
  5079. (org-last-inserted-timestamp nil))
  5080. (org-schedule '(4)))
  5081. (buffer-string))))
  5082. ;; With C-u C-u argument, prompt for a delay cookie.
  5083. (should
  5084. (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
  5085. (cl-letf (((symbol-function 'org-read-date)
  5086. (lambda (&rest args)
  5087. (apply #'encode-time
  5088. (org-parse-time-string "2014-03-04")))))
  5089. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5090. (let ((org-adapt-indentation nil)
  5091. (org-last-inserted-timestamp nil))
  5092. (org-schedule '(16)))
  5093. (buffer-string)))))
  5094. (should-error
  5095. (cl-letf (((symbol-function 'org-read-date)
  5096. (lambda (&rest args)
  5097. (apply #'encode-time
  5098. (org-parse-time-string "2014-03-04")))))
  5099. (org-test-with-temp-text "* H"
  5100. (let ((org-adapt-indentation nil)
  5101. (org-last-inserted-timestamp nil))
  5102. (org-schedule '(16)))
  5103. (buffer-string))))
  5104. ;; When a region is active and
  5105. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5106. ;; same value in all headlines in region.
  5107. (should
  5108. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5109. (org-test-with-temp-text "* H1\n* H2"
  5110. (let ((org-adapt-indentation nil)
  5111. (org-last-inserted-timestamp nil)
  5112. (org-loop-over-headlines-in-active-region t))
  5113. (transient-mark-mode 1)
  5114. (push-mark (point) t t)
  5115. (goto-char (point-max))
  5116. (org-schedule nil "2012-03-29"))
  5117. (replace-regexp-in-string
  5118. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5119. (should-not
  5120. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5121. (org-test-with-temp-text "* H1\n* H2"
  5122. (let ((org-adapt-indentation nil)
  5123. (org-last-inserted-timestamp nil)
  5124. (org-loop-over-headlines-in-active-region nil))
  5125. (transient-mark-mode 1)
  5126. (push-mark (point) t t)
  5127. (goto-char (point-max))
  5128. (org-schedule nil "2012-03-29"))
  5129. (replace-regexp-in-string
  5130. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5131. (should
  5132. ;; check if a repeater survives re-scheduling.
  5133. (string-match-p
  5134. "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
  5135. (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
  5136. (let ((org-adapt-indentation nil)
  5137. (org-last-inserted-timestamp nil))
  5138. (org-schedule nil "2017-02-01"))
  5139. (buffer-string)))))
  5140. ;;; Property API
  5141. (ert-deftest test-org/buffer-property-keys ()
  5142. "Test `org-buffer-property-keys' specifications."
  5143. ;; Retrieve properties across siblings.
  5144. (should
  5145. (equal '("A" "B")
  5146. (org-test-with-temp-text "
  5147. * H1
  5148. :PROPERTIES:
  5149. :A: 1
  5150. :END:
  5151. * H2
  5152. :PROPERTIES:
  5153. :B: 1
  5154. :END:"
  5155. (org-buffer-property-keys))))
  5156. ;; Retrieve properties across children.
  5157. (should
  5158. (equal '("A" "B")
  5159. (org-test-with-temp-text "
  5160. * H1
  5161. :PROPERTIES:
  5162. :A: 1
  5163. :END:
  5164. ** H2
  5165. :PROPERTIES:
  5166. :B: 1
  5167. :END:"
  5168. (org-buffer-property-keys))))
  5169. ;; Retrieve muliple properties in the same drawer.
  5170. (should
  5171. (equal '("A" "B")
  5172. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5173. (org-buffer-property-keys))))
  5174. ;; Ignore extension symbol in property name.
  5175. (should
  5176. (equal '("A")
  5177. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5178. (org-buffer-property-keys))))
  5179. ;; With non-nil COLUMNS, extract property names from columns.
  5180. (should
  5181. (equal '("A" "B")
  5182. (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
  5183. (org-buffer-property-keys nil nil t))))
  5184. (should
  5185. (equal '("A" "B" "COLUMNS")
  5186. (org-test-with-temp-text
  5187. "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
  5188. (org-buffer-property-keys nil nil t))))
  5189. ;; In COLUMNS, ignore title and summary-type.
  5190. (should
  5191. (equal '("A")
  5192. (org-test-with-temp-text "#+COLUMNS: %A(Foo)"
  5193. (org-buffer-property-keys nil nil t))))
  5194. (should
  5195. (equal '("A")
  5196. (org-test-with-temp-text "#+COLUMNS: %A{Foo}"
  5197. (org-buffer-property-keys nil nil t))))
  5198. (should
  5199. (equal '("A")
  5200. (org-test-with-temp-text "#+COLUMNS: %A(Foo){Bar}"
  5201. (org-buffer-property-keys nil nil t)))))
  5202. (ert-deftest test-org/property-values ()
  5203. "Test `org-property-values' specifications."
  5204. ;; Regular test.
  5205. (should
  5206. (equal '("2" "1")
  5207. (org-test-with-temp-text
  5208. "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
  5209. (org-property-values "A"))))
  5210. ;; Ignore empty values.
  5211. (should-not
  5212. (org-test-with-temp-text
  5213. "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
  5214. (org-property-values "A")))
  5215. ;; Take into consideration extended values.
  5216. (should
  5217. (equal '("1 2")
  5218. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5219. (org-property-values "A")))))
  5220. (ert-deftest test-org/set-property ()
  5221. "Test `org-set-property' specifications."
  5222. (should
  5223. (equal
  5224. ":PROPERTIES:\n:TEST: t\n:END:\n"
  5225. (org-test-with-temp-text ""
  5226. (let ((org-property-format "%s %s"))
  5227. (org-set-property "TEST" "t"))
  5228. (buffer-string))))
  5229. (should
  5230. (equal
  5231. "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5232. (org-test-with-temp-text "* H"
  5233. (let ((org-adapt-indentation nil)
  5234. (org-property-format "%s %s"))
  5235. (org-set-property "TEST" "t"))
  5236. (buffer-string)))))
  5237. (ert-deftest test-org/delete-property ()
  5238. "Test `org-delete-property' specifications."
  5239. (should
  5240. (equal
  5241. ""
  5242. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5243. (org-delete-property "TEST")
  5244. (buffer-string))))
  5245. (should
  5246. (equal
  5247. ":PROPERTIES:\n:TEST1: t\n:END:\n"
  5248. (org-test-with-temp-text ":PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5249. (org-delete-property "TEST2")
  5250. (buffer-string))))
  5251. (should
  5252. (equal
  5253. "* H\n"
  5254. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5255. (org-delete-property "TEST")
  5256. (buffer-string))))
  5257. (should
  5258. (equal
  5259. "* H\n:PROPERTIES:\n:TEST1: t\n:END:\n"
  5260. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5261. (org-delete-property "TEST2")
  5262. (buffer-string)))))
  5263. (ert-deftest test-org/delete-property-globally ()
  5264. "Test `org-delete-property-global' specifications."
  5265. (should
  5266. (equal
  5267. ""
  5268. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5269. (org-delete-property-globally "TEST")
  5270. (buffer-string))))
  5271. (should
  5272. (equal
  5273. "* H\n"
  5274. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n* H\n:PROPERTIES:\n:TEST: nil\n:END:"
  5275. (org-delete-property-globally "TEST")
  5276. (buffer-string)))))
  5277. (ert-deftest test-org/find-property ()
  5278. "Test `org-find-property' specifications."
  5279. ;; Regular test.
  5280. (should
  5281. (= 1
  5282. (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
  5283. (org-find-property "prop"))))
  5284. ;; Find properties in top-level property drawer.
  5285. (should
  5286. (= 1
  5287. (org-test-with-temp-text ":PROPERTIES:\n:PROP: value\n:END:"
  5288. (org-find-property "prop"))))
  5289. ;; Ignore false positives.
  5290. (should
  5291. (= 27
  5292. (org-test-with-temp-text
  5293. "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
  5294. (org-find-property "A"))))
  5295. ;; Return first entry found in buffer.
  5296. (should
  5297. (= 1
  5298. (org-test-with-temp-text
  5299. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5300. (org-find-property "A"))))
  5301. ;; Only search visible part of the buffer.
  5302. (should
  5303. (= 31
  5304. (org-test-with-temp-text
  5305. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5306. (org-narrow-to-subtree)
  5307. (org-find-property "A"))))
  5308. ;; With optional argument, only find entries with a specific value.
  5309. (should-not
  5310. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5311. (org-find-property "A" "2")))
  5312. (should
  5313. (= 31
  5314. (org-test-with-temp-text
  5315. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
  5316. (org-find-property "A" "2"))))
  5317. ;; Use "nil" for explicit nil values.
  5318. (should
  5319. (= 31
  5320. (org-test-with-temp-text
  5321. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
  5322. (org-find-property "A" "nil")))))
  5323. (ert-deftest test-org/entry-delete ()
  5324. "Test `org-entry-delete' specifications."
  5325. ;; Regular test.
  5326. (should
  5327. (string-match
  5328. " *:PROPERTIES:\n *:B: +2\n *:END:"
  5329. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5330. (org-entry-delete (point) "A")
  5331. (buffer-string))))
  5332. ;; Also remove accumulated properties.
  5333. (should-not
  5334. (string-match
  5335. ":A"
  5336. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
  5337. (org-entry-delete (point) "A")
  5338. (buffer-string))))
  5339. ;; When last property is removed, remove the property drawer.
  5340. (should-not
  5341. (string-match
  5342. ":PROPERTIES:"
  5343. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
  5344. (org-entry-delete (point) "A")
  5345. (buffer-string))))
  5346. ;; Return a non-nil value when some property was removed.
  5347. (should
  5348. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5349. (org-entry-delete (point) "A")))
  5350. (should-not
  5351. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5352. (org-entry-delete (point) "C")))
  5353. ;; Special properties cannot be located in a drawer. Allow to
  5354. ;; remove them anyway, in case of user error.
  5355. (should
  5356. (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
  5357. (org-entry-delete (point) "SCHEDULED"))))
  5358. (ert-deftest test-org/entry-get ()
  5359. "Test `org-entry-get' specifications."
  5360. ;; Regular test.
  5361. (should
  5362. (equal "1"
  5363. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:"
  5364. (org-entry-get (point) "A"))))
  5365. (should
  5366. (equal "1"
  5367. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5368. (org-entry-get (point) "A"))))
  5369. ;; Ignore case.
  5370. (should
  5371. (equal "1"
  5372. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5373. (org-entry-get (point) "a"))))
  5374. ;; Handle extended values, both before and after base value.
  5375. (should
  5376. (equal "1 2 3"
  5377. (org-test-with-temp-text
  5378. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5379. (org-entry-get (point) "A"))))
  5380. ;; Empty values are returned as the empty string.
  5381. (should
  5382. (equal ""
  5383. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
  5384. (org-entry-get (point) "A"))))
  5385. ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
  5386. ;; otherwise, return nil.
  5387. (should-not
  5388. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5389. (org-entry-get (point) "A")))
  5390. (should
  5391. (equal "nil"
  5392. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5393. (org-entry-get (point) "A" nil t))))
  5394. ;; Return nil when no property is found, independently on the
  5395. ;; LITERAL-NIL argument.
  5396. (should-not
  5397. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5398. (org-entry-get (point) "B")))
  5399. (should-not
  5400. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5401. (org-entry-get (point) "B" nil t)))
  5402. ;; Handle inheritance, when allowed. Include extended values and
  5403. ;; possibly global values.
  5404. (should
  5405. (equal
  5406. "1"
  5407. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:\n* H"
  5408. (org-entry-get (point-max) "A" t))))
  5409. (should
  5410. (equal
  5411. "1"
  5412. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5413. (org-entry-get (point-max) "A" t))))
  5414. (should
  5415. (equal
  5416. "1"
  5417. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5418. (let ((org-use-property-inheritance t))
  5419. (org-entry-get (point-max) "A" 'selective)))))
  5420. (should-not
  5421. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5422. (let ((org-use-property-inheritance nil))
  5423. (org-entry-get (point-max) "A" 'selective))))
  5424. (should
  5425. (equal
  5426. "1 2"
  5427. (org-test-with-temp-text
  5428. ":PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5429. (org-entry-get (point-max) "A" t))))
  5430. (should
  5431. (equal
  5432. "1 2"
  5433. (org-test-with-temp-text
  5434. "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5435. (org-entry-get (point-max) "A" t))))
  5436. (should
  5437. (equal
  5438. "1 2"
  5439. (org-test-with-temp-text
  5440. ":PROPERTIES:\n:A: 1\n:END:\n* H1\n* H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5441. (org-entry-get (point-max) "A" t))))
  5442. (should
  5443. (equal
  5444. "1 2"
  5445. (org-test-with-temp-text
  5446. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2.1\n* H2.2\n:PROPERTIES:\n:A+: 2\n:END:"
  5447. (org-entry-get (point-max) "A" t))))
  5448. (should
  5449. (equal "1"
  5450. (org-test-with-temp-text
  5451. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
  5452. (org-mode-restart)
  5453. (org-entry-get (point-max) "A" t))))
  5454. (should
  5455. (equal "0 1"
  5456. (org-test-with-temp-text
  5457. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
  5458. (org-mode-restart)
  5459. (org-entry-get (point-max) "A" t))))
  5460. ;; document level property-drawer has precedance over
  5461. ;; global-property by PROPERTY-keyword.
  5462. (should
  5463. (equal "0 2"
  5464. (org-test-with-temp-text
  5465. ":PROPERTIES:\n:A: 0\n:END:\n#+PROPERTY: A 1\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5466. (org-mode-restart)
  5467. (org-entry-get (point-max) "A" t)))))
  5468. (ert-deftest test-org/entry-properties ()
  5469. "Test `org-entry-properties' specifications."
  5470. ;; Get "ITEM" property.
  5471. (should
  5472. (equal "H"
  5473. (org-test-with-temp-text "* TODO H"
  5474. (cdr (assoc "ITEM" (org-entry-properties nil "ITEM"))))))
  5475. (should
  5476. (equal "H"
  5477. (org-test-with-temp-text "* TODO H"
  5478. (cdr (assoc "ITEM" (org-entry-properties))))))
  5479. ;; Get "TODO" property. TODO keywords are case sensitive.
  5480. (should
  5481. (equal "TODO"
  5482. (org-test-with-temp-text "* TODO H"
  5483. (cdr (assoc "TODO" (org-entry-properties nil "TODO"))))))
  5484. (should
  5485. (equal "TODO"
  5486. (org-test-with-temp-text "* TODO H"
  5487. (cdr (assoc "TODO" (org-entry-properties))))))
  5488. (should-not
  5489. (org-test-with-temp-text "* H"
  5490. (assoc "TODO" (org-entry-properties nil "TODO"))))
  5491. (should-not
  5492. (org-test-with-temp-text "* todo H"
  5493. (assoc "TODO" (org-entry-properties nil "TODO"))))
  5494. ;; Get "PRIORITY" property.
  5495. (should
  5496. (equal "A"
  5497. (org-test-with-temp-text "* [#A] H"
  5498. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  5499. (should
  5500. (equal "A"
  5501. (org-test-with-temp-text "* [#A] H"
  5502. (cdr (assoc "PRIORITY" (org-entry-properties))))))
  5503. (should
  5504. (equal (char-to-string org-priority-default)
  5505. (org-test-with-temp-text "* H"
  5506. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  5507. ;; Get "FILE" property.
  5508. (should
  5509. (org-test-with-temp-text-in-file "* H\nParagraph"
  5510. (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil "FILE")))
  5511. (buffer-file-name))))
  5512. (should
  5513. (org-test-with-temp-text-in-file "* H\nParagraph"
  5514. (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
  5515. (buffer-file-name))))
  5516. (should-not
  5517. (org-test-with-temp-text "* H\nParagraph"
  5518. (cdr (assoc "FILE" (org-entry-properties nil "FILE")))))
  5519. ;; Get "TAGS" property.
  5520. (should
  5521. (equal ":tag1:tag2:"
  5522. (org-test-with-temp-text "* H :tag1:tag2:"
  5523. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS"))))))
  5524. (should
  5525. (equal ":tag1:tag2:"
  5526. (org-test-with-temp-text "* H :tag1:tag2:"
  5527. (cdr (assoc "TAGS" (org-entry-properties))))))
  5528. (should-not
  5529. (org-test-with-temp-text "* H"
  5530. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS")))))
  5531. ;; Get "ALLTAGS" property.
  5532. (should
  5533. (equal ":tag1:tag2:"
  5534. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  5535. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS"))))))
  5536. (should
  5537. (equal ":tag1:tag2:"
  5538. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  5539. (cdr (assoc "ALLTAGS" (org-entry-properties))))))
  5540. (should-not
  5541. (org-test-with-temp-text "* H"
  5542. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS")))))
  5543. ;; Get "BLOCKED" property.
  5544. (should
  5545. (equal "t"
  5546. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  5547. (let ((org-enforce-todo-dependencies t)
  5548. (org-blocker-hook
  5549. '(org-block-todo-from-children-or-siblings-or-parent)))
  5550. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  5551. (should
  5552. (equal ""
  5553. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  5554. (let ((org-enforce-todo-dependencies t)
  5555. (org-blocker-hook
  5556. '(org-block-todo-from-children-or-siblings-or-parent)))
  5557. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  5558. ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
  5559. (should
  5560. (equal
  5561. "[2012-03-29 thu.]"
  5562. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  5563. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED"))))))
  5564. (should
  5565. (equal
  5566. "[2012-03-29 thu.]"
  5567. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  5568. (cdr (assoc "CLOSED" (org-entry-properties))))))
  5569. (should-not
  5570. (org-test-with-temp-text "* H"
  5571. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED")))))
  5572. (should
  5573. (equal
  5574. "<2014-03-04 tue.>"
  5575. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5576. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE"))))))
  5577. (should
  5578. (equal
  5579. "<2014-03-04 tue.>"
  5580. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5581. (cdr (assoc "DEADLINE" (org-entry-properties))))))
  5582. (should-not
  5583. (org-test-with-temp-text "* H"
  5584. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE")))))
  5585. (should
  5586. (equal
  5587. "<2014-03-04 tue.>"
  5588. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5589. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED"))))))
  5590. (should
  5591. (equal
  5592. "<2014-03-04 tue.>"
  5593. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5594. (cdr (assoc "SCHEDULED" (org-entry-properties))))))
  5595. (should-not
  5596. (org-test-with-temp-text "* H"
  5597. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED")))))
  5598. ;; Get "CATEGORY"
  5599. (should
  5600. (equal "cat"
  5601. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  5602. (cdr (assoc "CATEGORY" (org-entry-properties))))))
  5603. (should
  5604. (equal "cat"
  5605. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  5606. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5607. (should
  5608. (equal "cat"
  5609. (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
  5610. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5611. (should
  5612. (equal "cat2"
  5613. (org-test-with-temp-text
  5614. (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  5615. "\n"
  5616. "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
  5617. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5618. ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
  5619. (should
  5620. (equal "<2012-03-29 thu.>"
  5621. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
  5622. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  5623. (should
  5624. (equal "[2012-03-29 thu.]"
  5625. (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
  5626. (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
  5627. (should
  5628. (equal "<2012-03-29 thu.>"
  5629. (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
  5630. (cdr (assoc "TIMESTAMP" (org-entry-properties nil "TIMESTAMP"))))))
  5631. (should
  5632. (equal "[2014-03-04 tue.]"
  5633. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
  5634. (cdr (assoc "TIMESTAMP_IA"
  5635. (org-entry-properties nil "TIMESTAMP_IA"))))))
  5636. (should-not
  5637. (equal "<2012-03-29 thu.>"
  5638. (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
  5639. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  5640. ;; Get standard properties.
  5641. (should
  5642. (equal "1"
  5643. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5644. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5645. ;; Handle extended properties.
  5646. (should
  5647. (equal "1 2 3"
  5648. (org-test-with-temp-text
  5649. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5650. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5651. (should
  5652. (equal "1 2 3"
  5653. (org-test-with-temp-text
  5654. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
  5655. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5656. ;; Ignore forbidden (special) properties.
  5657. (should-not
  5658. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
  5659. (cdr (assoc "TODO" (org-entry-properties nil 'standard))))))
  5660. (ert-deftest test-org/entry-put ()
  5661. "Test `org-entry-put' specifications."
  5662. ;; Error when not a string or nil.
  5663. (should-error
  5664. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5665. (org-entry-put 1 "test" 2)))
  5666. ;; Error when property name is invalid.
  5667. (should-error
  5668. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5669. (org-entry-put 1 "no space" "value")))
  5670. (should-error
  5671. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5672. (org-entry-put 1 "" "value")))
  5673. ;; Set "TODO" property.
  5674. (should
  5675. (string-match (regexp-quote " TODO H")
  5676. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  5677. (org-entry-put (point) "TODO" "TODO")
  5678. (buffer-string))))
  5679. (should
  5680. (string-match (regexp-quote "* H")
  5681. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  5682. (org-entry-put (point) "TODO" nil)
  5683. (buffer-string))))
  5684. ;; Set "PRIORITY" property.
  5685. (should
  5686. (equal "* [#A] H"
  5687. (org-test-with-temp-text "* [#B] H"
  5688. (org-entry-put (point) "PRIORITY" "A")
  5689. (buffer-string))))
  5690. (should
  5691. (equal "* H"
  5692. (org-test-with-temp-text "* [#B] H"
  5693. (org-entry-put (point) "PRIORITY" nil)
  5694. (buffer-string))))
  5695. ;; Set "SCHEDULED" property.
  5696. (should
  5697. (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
  5698. (org-test-with-temp-text "* H"
  5699. (org-entry-put (point) "SCHEDULED" "2014-03-04")
  5700. (buffer-string))))
  5701. (should
  5702. (string= "* H\n"
  5703. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5704. (org-entry-put (point) "SCHEDULED" nil)
  5705. (buffer-string))))
  5706. (should
  5707. (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
  5708. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5709. (org-entry-put (point) "SCHEDULED" "earlier")
  5710. (buffer-string))))
  5711. (should
  5712. (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
  5713. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5714. (org-entry-put (point) "SCHEDULED" "later")
  5715. (buffer-string))))
  5716. ;; Set "DEADLINE" property.
  5717. (should
  5718. (string-match "^ *DEADLINE: <2014-03-04 .*?>"
  5719. (org-test-with-temp-text "* H"
  5720. (org-entry-put (point) "DEADLINE" "2014-03-04")
  5721. (buffer-string))))
  5722. (should
  5723. (string= "* H\n"
  5724. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5725. (org-entry-put (point) "DEADLINE" nil)
  5726. (buffer-string))))
  5727. (should
  5728. (string-match "^ *DEADLINE: <2014-03-03 .*?>"
  5729. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5730. (org-entry-put (point) "DEADLINE" "earlier")
  5731. (buffer-string))))
  5732. (should
  5733. (string-match "^ *DEADLINE: <2014-03-05 .*?>"
  5734. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5735. (org-entry-put (point) "DEADLINE" "later")
  5736. (buffer-string))))
  5737. ;; Set "CATEGORY" property
  5738. (should
  5739. (string-match "^ *:CATEGORY: cat"
  5740. (org-test-with-temp-text "* H"
  5741. (org-entry-put (point) "CATEGORY" "cat")
  5742. (buffer-string))))
  5743. ;; Regular properties, with or without pre-existing drawer.
  5744. (should
  5745. (string-match "^ *:A: +2$"
  5746. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5747. (org-entry-put (point) "A" "2")
  5748. (buffer-string))))
  5749. (should
  5750. (string-match "^ *:A: +1$"
  5751. (org-test-with-temp-text "* H"
  5752. (org-entry-put (point) "A" "1")
  5753. (buffer-string))))
  5754. ;; Special case: two consecutive headlines.
  5755. (should
  5756. (string-match "\\* A\n *:PROPERTIES:"
  5757. (org-test-with-temp-text "* A\n** B"
  5758. (org-entry-put (point) "A" "1")
  5759. (buffer-string)))))
  5760. (ert-deftest test-org/refresh-properties ()
  5761. "Test `org-refresh-properties' specifications."
  5762. (should
  5763. (equal "1"
  5764. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5765. (org-refresh-properties "A" 'org-test)
  5766. (get-text-property (point) 'org-test))))
  5767. (should-not
  5768. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5769. (org-refresh-properties "B" 'org-test)
  5770. (get-text-property (point) 'org-test)))
  5771. ;; Handle properties only defined with extension syntax, i.e.,
  5772. ;; "PROPERTY+".
  5773. (should
  5774. (equal "1"
  5775. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
  5776. (org-refresh-properties "A" 'org-test)
  5777. (get-text-property (point) 'org-test))))
  5778. ;; When property is inherited, add text property to the whole
  5779. ;; sub-tree.
  5780. (should
  5781. (equal "1"
  5782. (org-test-with-temp-text
  5783. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
  5784. (let ((org-use-property-inheritance t))
  5785. (org-refresh-properties "A" 'org-test))
  5786. (get-text-property (point) 'org-test))))
  5787. ;; When a document level property-drawer is used, those properties
  5788. ;; should work exactly like headline-properties as if at a
  5789. ;; headline-level 0.
  5790. (should
  5791. (equal "1"
  5792. (org-test-with-temp-text
  5793. ":PROPERTIES:\n:A: 1\n:END:\n"
  5794. (org-mode-restart)
  5795. (let ((org-use-property-inheritance t))
  5796. (org-refresh-properties "A" 'org-test))
  5797. (get-text-property (point) 'org-test))))
  5798. (should-not
  5799. (equal "1"
  5800. (org-test-with-temp-text
  5801. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  5802. (org-mode-restart)
  5803. (let ((org-use-property-inheritance nil))
  5804. (org-refresh-properties "A" 'org-test))
  5805. (get-text-property (point) 'org-test))))
  5806. (should
  5807. (equal "1"
  5808. (org-test-with-temp-text
  5809. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  5810. (org-mode-restart)
  5811. (let ((org-use-property-inheritance t))
  5812. (org-refresh-properties "A" 'org-test))
  5813. (get-text-property (point) 'org-test))))
  5814. (should
  5815. (equal "2"
  5816. (org-test-with-temp-text
  5817. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1\n:PROPERTIES:\n:A: 2\n:END:"
  5818. (org-mode-restart)
  5819. (let ((org-use-property-inheritance t))
  5820. (org-refresh-properties "A" 'org-test))
  5821. (get-text-property (point) 'org-test))))
  5822. ;; When property is inherited, use global value across the whole
  5823. ;; buffer. However local values have precedence, as well as the
  5824. ;; document level property-drawer.
  5825. (should-not
  5826. (equal "1"
  5827. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  5828. (org-mode-restart)
  5829. (let ((org-use-property-inheritance nil))
  5830. (org-refresh-properties "A" 'org-test))
  5831. (get-text-property (point) 'org-test))))
  5832. (should
  5833. (equal "1"
  5834. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  5835. (org-mode-restart)
  5836. (let ((org-use-property-inheritance t))
  5837. (org-refresh-properties "A" 'org-test))
  5838. (get-text-property (point) 'org-test))))
  5839. (should
  5840. (equal "2"
  5841. (org-test-with-temp-text
  5842. "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
  5843. (org-mode-restart)
  5844. (let ((org-use-property-inheritance t))
  5845. (org-refresh-properties "A" 'org-test))
  5846. (get-text-property (point) 'org-test))))
  5847. ;; When both keyword-property and document-level property-block is
  5848. ;; defined, the property-block has precedance.
  5849. (should
  5850. (equal "1"
  5851. (org-test-with-temp-text
  5852. ":PROPERTIES:\n:A: 1\n:END:\n#+PROPERTY: A 2\n<point>* H1"
  5853. (org-mode-restart)
  5854. (let ((org-use-property-inheritance t))
  5855. (org-refresh-properties "A" 'org-test))
  5856. (get-text-property (point) 'org-test)))))
  5857. (ert-deftest test-org/refresh-category-properties ()
  5858. "Test `org-refresh-category-properties' specifications"
  5859. (should
  5860. (equal "cat1"
  5861. (org-test-with-temp-text
  5862. ":PROPERTIES:\n:CATEGORY: cat1\n:END:"
  5863. (org-refresh-category-properties)
  5864. (get-text-property (point) 'org-category))))
  5865. (should
  5866. (equal "cat1"
  5867. (org-test-with-temp-text
  5868. "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  5869. (org-refresh-category-properties)
  5870. (get-text-property (point) 'org-category))))
  5871. ;; Even though property-inheritance is deactivated, category
  5872. ;; property should be inherited. As described in
  5873. ;; `org-use-property-inheritance'.
  5874. (should
  5875. (equal "cat1"
  5876. (org-test-with-temp-text
  5877. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  5878. (org-mode-restart)
  5879. (let ((org-use-property-inheritance nil))
  5880. (org-refresh-category-properties))
  5881. (get-text-property (point) 'org-category))))
  5882. (should
  5883. (equal "cat1"
  5884. (org-test-with-temp-text
  5885. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  5886. (org-mode-restart)
  5887. (let ((org-use-property-inheritance t))
  5888. (org-refresh-category-properties))
  5889. (get-text-property (point) 'org-category))))
  5890. (should
  5891. (equal "cat2"
  5892. (org-test-with-temp-text
  5893. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H\n:PROPERTIES:\n:CATEGORY: cat2\n:END:\n"
  5894. (org-mode-restart)
  5895. (let ((org-use-property-inheritance t))
  5896. (org-refresh-category-properties))
  5897. (get-text-property (point) 'org-category)))))
  5898. ;;; Refile
  5899. (ert-deftest test-org/refile-get-targets ()
  5900. "Test `org-refile-get-targets' specifications."
  5901. ;; :maxlevel includes all headings above specified value.
  5902. (should
  5903. (equal '("H1" "H2" "H3")
  5904. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  5905. (let ((org-refile-use-outline-path nil)
  5906. (org-refile-targets `((nil :maxlevel . 3))))
  5907. (mapcar #'car (org-refile-get-targets))))))
  5908. (should
  5909. (equal '("H1" "H2")
  5910. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  5911. (let ((org-refile-use-outline-path nil)
  5912. (org-refile-targets `((nil :maxlevel . 2))))
  5913. (mapcar #'car (org-refile-get-targets))))))
  5914. ;; :level limits targets to headlines with the specified level.
  5915. (should
  5916. (equal '("H2")
  5917. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  5918. (let ((org-refile-use-outline-path nil)
  5919. (org-refile-targets `((nil :level . 2))))
  5920. (mapcar #'car (org-refile-get-targets))))))
  5921. ;; :tag limits targets to headlines with specified tag.
  5922. (should
  5923. (equal '("H1")
  5924. (org-test-with-temp-text "* H1 :foo:\n** H2\n*** H3 :bar:"
  5925. (let ((org-refile-use-outline-path nil)
  5926. (org-refile-targets `((nil :tag . "foo"))))
  5927. (mapcar #'car (org-refile-get-targets))))))
  5928. ;; :todo limits targets to headlines with specified TODO keyword.
  5929. (should
  5930. (equal '("H2")
  5931. (org-test-with-temp-text "* H1\n** TODO H2\n*** DONE H3"
  5932. (let ((org-refile-use-outline-path nil)
  5933. (org-refile-targets `((nil :todo . "TODO"))))
  5934. (mapcar #'car (org-refile-get-targets))))))
  5935. ;; :regexp filters targets matching provided regexp.
  5936. (should
  5937. (equal '("F2" "F3")
  5938. (org-test-with-temp-text "* H1\n** F2\n*** F3"
  5939. (let ((org-refile-use-outline-path nil)
  5940. (org-refile-targets `((nil :regexp . "F"))))
  5941. (mapcar #'car (org-refile-get-targets))))))
  5942. ;; A nil `org-refile-targets' includes only top level headlines in
  5943. ;; current buffer.
  5944. (should
  5945. (equal '("H1" "H2")
  5946. (org-test-with-temp-text "* H1\n** S1\n* H2"
  5947. (let ((org-refile-use-outline-path nil)
  5948. (org-refile-targets nil))
  5949. (mapcar #'car (org-refile-get-targets))))))
  5950. ;; Return value is the union of the targets according to all the
  5951. ;; defined rules. However, prevent duplicates.
  5952. (should
  5953. (equal '("F2" "F3" "H1")
  5954. (org-test-with-temp-text "* TODO H1\n** F2\n*** F3"
  5955. (let ((org-refile-use-outline-path nil)
  5956. (org-refile-targets `((nil :regexp . "F")
  5957. (nil :todo . "TODO"))))
  5958. (mapcar #'car (org-refile-get-targets))))))
  5959. (should
  5960. (equal '("F2" "F3" "H1")
  5961. (org-test-with-temp-text "* TODO H1\n** TODO F2\n*** F3"
  5962. (let ((org-refile-use-outline-path nil)
  5963. (org-refile-targets `((nil :regexp . "F")
  5964. (nil :todo . "TODO"))))
  5965. (mapcar #'car (org-refile-get-targets))))))
  5966. ;; When `org-refile-use-outline-path' is non-nil, provide targets as
  5967. ;; paths.
  5968. (should
  5969. (equal '("H1" "H1/H2" "H1/H2/H3")
  5970. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  5971. (let ((org-refile-use-outline-path t)
  5972. (org-refile-targets `((nil :maxlevel . 3))))
  5973. (mapcar #'car (org-refile-get-targets))))))
  5974. ;; When providing targets as paths, escape forward slashes in
  5975. ;; headings with backslashes.
  5976. (should
  5977. (equal '("H1\\/foo")
  5978. (org-test-with-temp-text "* H1/foo"
  5979. (let ((org-refile-use-outline-path t)
  5980. (org-refile-targets `((nil :maxlevel . 1))))
  5981. (mapcar #'car (org-refile-get-targets))))))
  5982. ;; When `org-refile-use-outline-path' is `file', include file name
  5983. ;; without directory in targets.
  5984. (should
  5985. (org-test-with-temp-text-in-file "* H1"
  5986. (let* ((filename (buffer-file-name))
  5987. (org-refile-use-outline-path 'file)
  5988. (org-refile-targets `(((,filename) :level . 1))))
  5989. (member (file-name-nondirectory filename)
  5990. (mapcar #'car (org-refile-get-targets))))))
  5991. ;; When `org-refile-use-outline-path' is `full-file-path', include
  5992. ;; full file name.
  5993. (should
  5994. (org-test-with-temp-text-in-file "* H1"
  5995. (let* ((filename (file-truename (buffer-file-name)))
  5996. (org-refile-use-outline-path 'full-file-path)
  5997. (org-refile-targets `(((,filename) :level . 1))))
  5998. (member filename (mapcar #'car (org-refile-get-targets))))))
  5999. ;; When `org-refile-use-outline-path' is `buffer-name', include
  6000. ;; buffer name.
  6001. (should
  6002. (org-test-with-temp-text "* H1"
  6003. (let* ((org-refile-use-outline-path 'buffer-name)
  6004. (org-refile-targets `((nil :level . 1))))
  6005. (member (buffer-name) (mapcar #'car (org-refile-get-targets)))))))
  6006. ;;; Sparse trees
  6007. (ert-deftest test-org/match-sparse-tree ()
  6008. "Test `org-match-sparse-tree' specifications."
  6009. ;; Match tags.
  6010. (should-not
  6011. (org-test-with-temp-text "* H\n** H1 :tag:"
  6012. (org-match-sparse-tree nil "tag")
  6013. (search-forward "H1")
  6014. (org-invisible-p2)))
  6015. (should
  6016. (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
  6017. (org-match-sparse-tree nil "tag")
  6018. (search-forward "H2")
  6019. (org-invisible-p2)))
  6020. ;; "-" operator for tags.
  6021. (should-not
  6022. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6023. (org-match-sparse-tree nil "tag1-tag2")
  6024. (search-forward "H1")
  6025. (org-invisible-p2)))
  6026. (should
  6027. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6028. (org-match-sparse-tree nil "tag1-tag2")
  6029. (search-forward "H2")
  6030. (org-invisible-p2)))
  6031. ;; "&" operator for tags.
  6032. (should
  6033. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6034. (org-match-sparse-tree nil "tag1&tag2")
  6035. (search-forward "H1")
  6036. (org-invisible-p2)))
  6037. (should-not
  6038. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6039. (org-match-sparse-tree nil "tag1&tag2")
  6040. (search-forward "H2")
  6041. (org-invisible-p2)))
  6042. ;; "|" operator for tags.
  6043. (should-not
  6044. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6045. (org-match-sparse-tree nil "tag1|tag2")
  6046. (search-forward "H1")
  6047. (org-invisible-p2)))
  6048. (should-not
  6049. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6050. (org-match-sparse-tree nil "tag1|tag2")
  6051. (search-forward "H2")
  6052. (org-invisible-p2)))
  6053. ;; Regexp match on tags.
  6054. (should-not
  6055. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6056. (org-match-sparse-tree nil "{^tag.*}")
  6057. (search-forward "H1")
  6058. (org-invisible-p2)))
  6059. (should
  6060. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6061. (org-match-sparse-tree nil "{^tag.*}")
  6062. (search-forward "H2")
  6063. (org-invisible-p2)))
  6064. ;; Match group tags.
  6065. (should-not
  6066. (org-test-with-temp-text
  6067. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6068. (org-match-sparse-tree nil "work")
  6069. (search-forward "H1")
  6070. (org-invisible-p2)))
  6071. (should-not
  6072. (org-test-with-temp-text
  6073. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6074. (org-match-sparse-tree nil "work")
  6075. (search-forward "H2")
  6076. (org-invisible-p2)))
  6077. ;; Match group tags with hard brackets.
  6078. (should-not
  6079. (org-test-with-temp-text
  6080. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6081. (org-match-sparse-tree nil "work")
  6082. (search-forward "H1")
  6083. (org-invisible-p2)))
  6084. (should-not
  6085. (org-test-with-temp-text
  6086. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6087. (org-match-sparse-tree nil "work")
  6088. (search-forward "H2")
  6089. (org-invisible-p2)))
  6090. ;; Match tags in hierarchies
  6091. (should-not
  6092. (org-test-with-temp-text
  6093. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6094. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6095. #+TAGS: { Lev_3 : Lev_4 }\n
  6096. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6097. (org-match-sparse-tree nil "Lev_1")
  6098. (search-forward "H4")
  6099. (org-invisible-p2)))
  6100. (should-not
  6101. (org-test-with-temp-text
  6102. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6103. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6104. #+TAGS: { Lev_3 : Lev_4 }\n
  6105. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6106. (org-match-sparse-tree nil "Lev_1+Lev_3")
  6107. (search-forward "H4")
  6108. (org-invisible-p2)))
  6109. ;; Match regular expressions in tags
  6110. (should-not
  6111. (org-test-with-temp-text
  6112. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
  6113. (org-match-sparse-tree nil "Lev")
  6114. (search-forward "H1")
  6115. (org-invisible-p2)))
  6116. (should
  6117. (org-test-with-temp-text
  6118. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
  6119. (org-match-sparse-tree nil "Lev")
  6120. (search-forward "H1")
  6121. (org-invisible-p2)))
  6122. ;; Match properties.
  6123. (should
  6124. (org-test-with-temp-text
  6125. "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
  6126. (org-match-sparse-tree nil "A=\"1\"")
  6127. (search-forward "H2")
  6128. (org-invisible-p2)))
  6129. (should-not
  6130. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6131. (org-match-sparse-tree nil "A=\"1\"")
  6132. (search-forward "H2")
  6133. (org-invisible-p2)))
  6134. ;; Case is not significant when matching properties.
  6135. (should-not
  6136. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6137. (org-match-sparse-tree nil "a=\"1\"")
  6138. (search-forward "H2")
  6139. (org-invisible-p2)))
  6140. (should-not
  6141. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
  6142. (org-match-sparse-tree nil "A=\"1\"")
  6143. (search-forward "H2")
  6144. (org-invisible-p2)))
  6145. ;; Match special LEVEL property.
  6146. (should-not
  6147. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6148. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6149. (search-forward "H1")
  6150. (org-invisible-p2)))
  6151. (should
  6152. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6153. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6154. (search-forward "H2")
  6155. (org-invisible-p2)))
  6156. ;; Comparison operators when matching properties.
  6157. (should
  6158. (org-test-with-temp-text
  6159. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6160. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6161. (search-forward "H1")
  6162. (org-invisible-p2)))
  6163. (should-not
  6164. (org-test-with-temp-text
  6165. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6166. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6167. (search-forward "H2")
  6168. (org-invisible-p2)))
  6169. ;; Regexp match on properties values.
  6170. (should-not
  6171. (org-test-with-temp-text
  6172. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6173. (org-match-sparse-tree nil "A={f.*}")
  6174. (search-forward "H1")
  6175. (org-invisible-p2)))
  6176. (should
  6177. (org-test-with-temp-text
  6178. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6179. (org-match-sparse-tree nil "A={f.*}")
  6180. (search-forward "H2")
  6181. (org-invisible-p2)))
  6182. ;; With an optional argument, limit match to TODO entries.
  6183. (should-not
  6184. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6185. (org-match-sparse-tree t "tag")
  6186. (search-forward "H1")
  6187. (org-invisible-p2)))
  6188. (should
  6189. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6190. (org-match-sparse-tree t "tag")
  6191. (search-forward "H2")
  6192. (org-invisible-p2))))
  6193. (ert-deftest test-org/occur ()
  6194. "Test `org-occur' specifications."
  6195. ;; Count number of matches.
  6196. (should
  6197. (= 1
  6198. (org-test-with-temp-text "* H\nA\n* H2"
  6199. (org-occur "A"))))
  6200. (should
  6201. (= 2
  6202. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6203. (org-occur "A"))))
  6204. ;; Test CALLBACK optional argument.
  6205. (should
  6206. (= 0
  6207. (org-test-with-temp-text "* H\nA\n* H2"
  6208. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6209. (should
  6210. (= 1
  6211. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6212. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6213. ;; Case-fold searches according to `org-occur-case-fold-search'.
  6214. (should
  6215. (= 2
  6216. (org-test-with-temp-text "Aa"
  6217. (let ((org-occur-case-fold-search t)) (org-occur "A")))))
  6218. (should
  6219. (= 2
  6220. (org-test-with-temp-text "Aa"
  6221. (let ((org-occur-case-fold-search t)) (org-occur "a")))))
  6222. (should
  6223. (= 1
  6224. (org-test-with-temp-text "Aa"
  6225. (let ((org-occur-case-fold-search nil)) (org-occur "A")))))
  6226. (should
  6227. (= 1
  6228. (org-test-with-temp-text "Aa"
  6229. (let ((org-occur-case-fold-search nil)) (org-occur "a")))))
  6230. (should
  6231. (= 1
  6232. (org-test-with-temp-text "Aa"
  6233. (let ((org-occur-case-fold-search 'smart)) (org-occur "A")))))
  6234. (should
  6235. (= 2
  6236. (org-test-with-temp-text "Aa"
  6237. (let ((org-occur-case-fold-search 'smart)) (org-occur "a"))))))
  6238. ;;; Tags
  6239. (ert-deftest test-org/tag-string-to-alist ()
  6240. "Test `org-tag-string-to-alist' specifications."
  6241. ;; Tag without selection key.
  6242. (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
  6243. ;; Tag with selection key.
  6244. (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t))))
  6245. ;; Tag group.
  6246. (should
  6247. (equal
  6248. (org-tag-string-to-alist "[ group : t1 t2 ]")
  6249. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag))))
  6250. ;; Mutually exclusive tags.
  6251. (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
  6252. '((:startgroup) ("tag1") ("tag2") (:endgroup))))
  6253. (should
  6254. (equal
  6255. (org-tag-string-to-alist "{ group : tag1 tag2 }")
  6256. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))))
  6257. (ert-deftest test-org/tag-alist-to-string ()
  6258. "Test `org-tag-alist-to-string' specifications."
  6259. (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
  6260. (should (equal (org-tag-alist-to-string '(("tag1" . ?t))) "tag1(t)"))
  6261. (should
  6262. (equal
  6263. (org-tag-alist-to-string
  6264. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6265. "[ group : t1 t2 ]"))
  6266. (should
  6267. (equal (org-tag-alist-to-string
  6268. '((:startgroup) ("tag1") ("tag2") (:endgroup)))
  6269. "{ tag1 tag2 }"))
  6270. (should
  6271. (equal
  6272. (org-tag-alist-to-string
  6273. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))
  6274. "{ group : tag1 tag2 }")))
  6275. (ert-deftest test-org/tag-alist-to-groups ()
  6276. "Test `org-tag-alist-to-groups' specifications."
  6277. (should
  6278. (equal (org-tag-alist-to-groups
  6279. '((:startgroup) ("group") (:grouptags) ("t1") ("t2") (:endgroup)))
  6280. '(("group" "t1" "t2"))))
  6281. (should
  6282. (equal
  6283. (org-tag-alist-to-groups
  6284. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6285. '(("group" "t1" "t2"))))
  6286. (should-not
  6287. (org-tag-alist-to-groups
  6288. '((:startgroup) ("group") ("t1") ("t2") (:endgroup)))))
  6289. (ert-deftest test-org/tag-align ()
  6290. "Test tags alignment."
  6291. ;; Test aligning tags with different display width.
  6292. (should
  6293. ;; 12345678901234567890
  6294. (equal "* Test :abc:"
  6295. (org-test-with-temp-text "* Test :abc:"
  6296. (let ((org-tags-column -20)
  6297. (indent-tabs-mode nil))
  6298. (org-fix-tags-on-the-fly))
  6299. (buffer-string))))
  6300. (should
  6301. ;; 12345678901234567890
  6302. (equal "* Test :日本語:"
  6303. (org-test-with-temp-text "* Test :日本語:"
  6304. (let ((org-tags-column -20)
  6305. (indent-tabs-mode nil))
  6306. (org-fix-tags-on-the-fly))
  6307. (buffer-string))))
  6308. ;; Make sure aligning tags do not skip invisible text.
  6309. (should
  6310. (equal "* [[linkx]] :tag:"
  6311. (org-test-with-temp-text "* [[link<point>]] :tag:"
  6312. (let ((org-tags-column 0))
  6313. (org-fix-tags-on-the-fly)
  6314. (insert "x")
  6315. (buffer-string)))))
  6316. ;; Aligning tags preserve position.
  6317. (should
  6318. (= 6 (org-test-with-temp-text "* 345 <point> :tag:"
  6319. (let ((org-tags-column 78)
  6320. (indent-tabs-mode nil))
  6321. (org-fix-tags-on-the-fly))
  6322. (current-column))))
  6323. ;; Aligning all tags in visible buffer.
  6324. (should
  6325. ;; 12345678901234567890
  6326. (equal (concat "* Level 1 :abc:\n"
  6327. "** Level 2 :def:")
  6328. (org-test-with-temp-text (concat "* Level 1 :abc:\n"
  6329. "** Level 2 :def:")
  6330. (let ((org-tags-column -20)
  6331. (indent-tabs-mode nil))
  6332. ;; (org-align-tags :all) must work even when the point
  6333. ;; is at the end of the buffer.
  6334. (goto-char (point-max))
  6335. (org-align-tags :all))
  6336. (buffer-string)))))
  6337. (ert-deftest test-org/get-tags ()
  6338. "Test `org-get-tags' specifications."
  6339. ;; Standard test.
  6340. (should
  6341. (equal '("foo")
  6342. (org-test-with-temp-text "* Test :foo:" (org-get-tags))))
  6343. (should
  6344. (equal '("foo" "bar")
  6345. (org-test-with-temp-text "* Test :foo:bar:" (org-get-tags))))
  6346. ;; Return nil when there is no tag.
  6347. (should-not
  6348. (org-test-with-temp-text "* Test" (org-get-tags)))
  6349. ;; Tags are inherited from parent headlines.
  6350. (should
  6351. (equal '("tag")
  6352. (let ((org-use-tag-inheritance t))
  6353. (org-test-with-temp-text "* H0 :foo:\n* H1 :tag:\n<point>** H2"
  6354. (org-get-tags)))))
  6355. ;; Tags are inherited from `org-file-tags'.
  6356. (should
  6357. (equal '("tag")
  6358. (org-test-with-temp-text "* H1"
  6359. (let ((org-file-tags '("tag"))
  6360. (org-use-tag-inheritance t))
  6361. (org-get-tags)))))
  6362. ;; Only inherited tags have the `inherited' text property.
  6363. (should
  6364. (get-text-property 0 'inherited
  6365. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6366. (let ((org-use-tag-inheritance t))
  6367. (assoc-string "foo" (org-get-tags))))))
  6368. (should-not
  6369. (get-text-property 0 'inherited
  6370. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6371. (let ((org-use-tag-inheritance t))
  6372. (assoc-string "bar" (org-get-tags))))))
  6373. ;; Obey to `org-use-tag-inheritance'.
  6374. (should-not
  6375. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6376. (let ((org-use-tag-inheritance nil))
  6377. (assoc-string "foo" (org-get-tags)))))
  6378. (should-not
  6379. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6380. (let ((org-use-tag-inheritance nil)
  6381. (org-file-tags '("foo")))
  6382. (assoc-string "foo" (org-get-tags)))))
  6383. (should-not
  6384. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6385. (let ((org-use-tag-inheritance '("bar")))
  6386. (assoc-string "foo" (org-get-tags)))))
  6387. (should
  6388. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6389. (let ((org-use-tag-inheritance '("bar")))
  6390. (assoc-string "bar" (org-get-tags)))))
  6391. (should-not
  6392. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6393. (let ((org-use-tag-inheritance "b.*"))
  6394. (assoc-string "foo" (org-get-tags)))))
  6395. (should
  6396. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6397. (let ((org-use-tag-inheritance "b.*"))
  6398. (assoc-string "bar" (org-get-tags)))))
  6399. ;; When optional argument LOCAL is non-nil, ignore tag inheritance.
  6400. (should
  6401. (equal '("baz")
  6402. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6403. (let ((org-use-tag-inheritance t))
  6404. (org-get-tags nil t)))))
  6405. ;; When optional argument POS is non-nil, get tags there instead.
  6406. (should
  6407. (equal '("foo")
  6408. (org-test-with-temp-text "* H1 :foo:\n* <point>H2 :bar:"
  6409. (org-get-tags 1))))
  6410. ;; Make sure tags excluded from inheritance are returned if local
  6411. (should
  6412. (equal '("foo")
  6413. (org-test-with-temp-text "* Test :foo:"
  6414. (let ((org-use-tag-inheritance t)
  6415. (org-tags-exclude-from-inheritance '("foo")))
  6416. (org-get-tags)))))
  6417. ;; Test the collection of tags from #+filetags and parent tags.
  6418. (should
  6419. (equal '("a" "b" "c" "d")
  6420. (org-test-with-temp-text (concat "#+filetags: a\n"
  6421. "* Level 1 :b:\n"
  6422. "** Level 2 :c:\n"
  6423. "*** Level 3 :d:\n"
  6424. "<point>")
  6425. (let ((org-use-tag-inheritance t))
  6426. (org-mode-restart) ;So that `org-file-tags' get populated from #+filetags
  6427. (org-get-tags)))))
  6428. ;; Pathological case: tagged headline with an empty body.
  6429. (should (org-test-with-temp-text "* :tag:" (org-get-tags))))
  6430. (ert-deftest test-org/set-tags ()
  6431. "Test `org-set-tags' specifications."
  6432. ;; Throw an error on invalid data.
  6433. (should-error
  6434. (org-test-with-temp-text "* H"
  6435. (org-set-tags 'foo)))
  6436. ;; `nil', an empty, and a blank string remove all tags.
  6437. (should
  6438. (equal "* H"
  6439. (org-test-with-temp-text "* H :tag1:tag2:"
  6440. (org-set-tags nil)
  6441. (buffer-string))))
  6442. (should
  6443. (equal "* H"
  6444. (org-test-with-temp-text "* H :tag1:tag2:"
  6445. (org-set-tags "")
  6446. (buffer-string))))
  6447. (should
  6448. (equal "* H"
  6449. (org-test-with-temp-text "* H :tag1:tag2:"
  6450. (org-set-tags " ")
  6451. (buffer-string))))
  6452. ;; If there's nothing to remove, just bail out.
  6453. (should
  6454. (equal "* H"
  6455. (org-test-with-temp-text "* H"
  6456. (org-set-tags nil)
  6457. (buffer-string))))
  6458. (should
  6459. (equal "* "
  6460. (org-test-with-temp-text "* "
  6461. (org-set-tags nil)
  6462. (buffer-string))))
  6463. ;; If DATA is a tag string, set current tags to it, even if it means
  6464. ;; replacing old tags.
  6465. (should
  6466. (equal "* H :tag0:"
  6467. (org-test-with-temp-text "* H :tag1:tag2:"
  6468. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  6469. (buffer-string))))
  6470. (should
  6471. (equal "* H :tag0:"
  6472. (org-test-with-temp-text "* H"
  6473. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  6474. (buffer-string))))
  6475. ;; If DATA is a list, set tags to this list, even if it means
  6476. ;; replacing old tags.
  6477. (should
  6478. (equal "* H :tag0:"
  6479. (org-test-with-temp-text "* H :tag1:tag2:"
  6480. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6481. (buffer-string))))
  6482. (should
  6483. (equal "* H :tag0:"
  6484. (org-test-with-temp-text "* H"
  6485. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6486. (buffer-string))))
  6487. ;; When set, apply `org-tags-sort-function'.
  6488. (should
  6489. (equal "* H :a:b:"
  6490. (org-test-with-temp-text "* H"
  6491. (let ((org-tags-column 1)
  6492. (org-tags-sort-function #'string<))
  6493. (org-set-tags '("b" "a"))
  6494. (buffer-string)))))
  6495. ;; When new tags are identical to the previous ones, still align.
  6496. (should
  6497. (equal "* H :foo:"
  6498. (org-test-with-temp-text "* H :foo:"
  6499. (let ((org-tags-column 1))
  6500. (org-set-tags '("foo"))
  6501. (buffer-string)))))
  6502. ;; When tags have been changed, run `org-after-tags-change-hook'.
  6503. (should
  6504. (catch :return
  6505. (org-test-with-temp-text "* H :foo:"
  6506. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  6507. (org-set-tags '("bar"))
  6508. nil))))
  6509. (should-not
  6510. (catch :return
  6511. (org-test-with-temp-text "* H :foo:"
  6512. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  6513. (org-set-tags '("foo"))
  6514. nil))))
  6515. ;; Special case: handle empty headlines.
  6516. (should
  6517. (equal "* :tag0:"
  6518. (org-test-with-temp-text "* "
  6519. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6520. (buffer-string))))
  6521. ;; Modify buffer only when a tag change happens or alignment is
  6522. ;; done.
  6523. (should-not
  6524. (org-test-with-temp-text "* H :foo:"
  6525. (set-buffer-modified-p nil)
  6526. (let ((org-tags-column 1)) (org-set-tags '("foo")))
  6527. (buffer-modified-p)))
  6528. (should
  6529. (org-test-with-temp-text "* H :foo:"
  6530. (set-buffer-modified-p nil)
  6531. (let ((org-tags-column 10)) (org-set-tags '("foo")))
  6532. (buffer-modified-p)))
  6533. (should
  6534. (org-test-with-temp-text "* H :foo:"
  6535. (set-buffer-modified-p nil)
  6536. (let ((org-tags-column 10)) (org-set-tags '("bar")))
  6537. (buffer-modified-p)))
  6538. ;; Pathological case: when setting tags of a folded headline, do not
  6539. ;; let new tags being sucked into invisibility.
  6540. (should-not
  6541. (org-test-with-temp-text "* H1\nContent\n* H2\n\n Other Content"
  6542. ;; Show only headlines
  6543. (org-content)
  6544. ;; Set NEXT tag on current entry
  6545. (org-set-tags ":NEXT:")
  6546. ;; Move point to that NEXT tag
  6547. (search-forward "NEXT") (backward-word)
  6548. ;; And it should be visible (i.e. no overlays)
  6549. (overlays-at (point)))))
  6550. (ert-deftest test-org/set-tags-command ()
  6551. "Test `org-set-tags-command' specifications"
  6552. ;; Set tags at current headline.
  6553. (should
  6554. (equal "* H1 :foo:"
  6555. (org-test-with-temp-text "* H1"
  6556. (cl-letf (((symbol-function 'completing-read)
  6557. (lambda (&rest args) ":foo:")))
  6558. (let ((org-use-fast-tag-selection nil)
  6559. (org-tags-column 1))
  6560. (org-set-tags-command)))
  6561. (buffer-string))))
  6562. ;; Preserve position when called from the section below.
  6563. (should
  6564. (equal "* H1 :foo:\nContents"
  6565. (org-test-with-temp-text "* H1\n<point>Contents"
  6566. (cl-letf (((symbol-function 'completing-read)
  6567. (lambda (&rest args) ":foo:")))
  6568. (let ((org-use-fast-tag-selection nil)
  6569. (org-tags-column 1))
  6570. (org-set-tags-command)))
  6571. (buffer-string))))
  6572. (should-not
  6573. (equal "* H1 :foo:\nContents2"
  6574. (org-test-with-temp-text "* H1\n<point>Contents2"
  6575. (cl-letf (((symbol-function 'completing-read)
  6576. (lambda (&rest args) ":foo:")))
  6577. (let ((org-use-fast-tag-selection nil)
  6578. (org-tags-column 1))
  6579. (org-set-tags-command)))
  6580. (org-at-heading-p))))
  6581. ;; Strip all forbidden characters from user-entered tags.
  6582. (should
  6583. (equal "* H1 :foo:"
  6584. (org-test-with-temp-text "* H1"
  6585. (cl-letf (((symbol-function 'completing-read)
  6586. (lambda (&rest args) ": foo *:")))
  6587. (let ((org-use-fast-tag-selection nil)
  6588. (org-tags-column 1))
  6589. (org-set-tags-command)))
  6590. (buffer-string))))
  6591. ;; When a region is active and
  6592. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  6593. ;; same value in all headlines in region.
  6594. (should
  6595. (equal "* H1 :foo:\nContents\n* H2 :foo:"
  6596. (org-test-with-temp-text "* H1\nContents\n* H2"
  6597. (cl-letf (((symbol-function 'completing-read)
  6598. (lambda (&rest args) ":foo:")))
  6599. (let ((org-use-fast-tag-selection nil)
  6600. (org-loop-over-headlines-in-active-region t)
  6601. (org-tags-column 1))
  6602. (transient-mark-mode 1)
  6603. (push-mark (point) t t)
  6604. (goto-char (point-max))
  6605. (org-set-tags-command)))
  6606. (buffer-string))))
  6607. (should
  6608. (equal "* H1\nContents\n* H2 :foo:"
  6609. (org-test-with-temp-text "* H1\nContents\n* H2"
  6610. (cl-letf (((symbol-function 'completing-read)
  6611. (lambda (&rest args) ":foo:")))
  6612. (let ((org-use-fast-tag-selection nil)
  6613. (org-loop-over-headlines-in-active-region nil)
  6614. (org-tags-column 1))
  6615. (transient-mark-mode 1)
  6616. (push-mark (point) t t)
  6617. (goto-char (point-max))
  6618. (org-set-tags-command)))
  6619. (buffer-string))))
  6620. ;; With a C-u prefix argument, align all tags in the buffer.
  6621. (should
  6622. (equal "* H1 :foo:\n* H2 :bar:"
  6623. (org-test-with-temp-text "* H1 :foo:\n* H2 :bar:"
  6624. (let ((org-tags-column 1)) (org-set-tags-command '(4)))
  6625. (buffer-string))))
  6626. ;; Point does not move with empty headline.
  6627. (should
  6628. (equal ":foo:"
  6629. (org-test-with-temp-text "* <point>"
  6630. (cl-letf (((symbol-function 'completing-read)
  6631. (lambda (&rest args) ":foo:")))
  6632. (let ((org-use-fast-tag-selection nil)
  6633. (org-tags-column 1))
  6634. (org-set-tags-command)))
  6635. (buffer-substring (point) (line-end-position)))))
  6636. ;; Point does not move at start of line.
  6637. (should
  6638. (equal "* H1 :foo:"
  6639. (org-test-with-temp-text "* H1"
  6640. (cl-letf (((symbol-function 'completing-read)
  6641. (lambda (&rest args) ":foo:")))
  6642. (let ((org-use-fast-tag-selection nil)
  6643. (org-tags-column 1))
  6644. (org-set-tags-command)))
  6645. (buffer-substring (point) (line-end-position)))))
  6646. ;; Point does not move when within *'s.
  6647. (should
  6648. (equal "* H1 :foo:"
  6649. (org-test-with-temp-text "*<point>* H1"
  6650. (cl-letf (((symbol-function 'completing-read)
  6651. (lambda (&rest args) ":foo:")))
  6652. (let ((org-use-fast-tag-selection nil)
  6653. (org-tags-column 1))
  6654. (org-set-tags-command)))
  6655. (buffer-substring (point) (line-end-position)))))
  6656. ;; Point workaround does not get fooled when looking at a space.
  6657. (should
  6658. (equal " b :foo:"
  6659. (org-test-with-temp-text "* a<point> b"
  6660. (cl-letf (((symbol-function 'completing-read)
  6661. (lambda (&rest args) ":foo:")))
  6662. (let ((org-use-fast-tag-selection nil)
  6663. (org-tags-column 1))
  6664. (org-set-tags-command)))
  6665. (buffer-substring (point) (line-end-position))))))
  6666. (ert-deftest test-org/toggle-tag ()
  6667. "Test `org-toggle-tag' specifications."
  6668. ;; Insert missing tag.
  6669. (should
  6670. (equal "* H :tag:"
  6671. (org-test-with-temp-text "* H"
  6672. (let ((org-tags-column 1)) (org-toggle-tag "tag"))
  6673. (buffer-string))))
  6674. (should
  6675. (equal "* H :tag1:tag2:"
  6676. (org-test-with-temp-text "* H :tag1:"
  6677. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  6678. (buffer-string))))
  6679. ;; Remove existing tag.
  6680. (should
  6681. (equal "* H"
  6682. (org-test-with-temp-text "* H :tag:"
  6683. (org-toggle-tag "tag")
  6684. (buffer-string))))
  6685. (should
  6686. (equal "* H :tag1:"
  6687. (org-test-with-temp-text "* H :tag1:tag2:"
  6688. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  6689. (buffer-string))))
  6690. (should
  6691. (equal "* H :tag2:"
  6692. (org-test-with-temp-text "* H :tag1:tag2:"
  6693. (let ((org-tags-column 1)) (org-toggle-tag "tag1"))
  6694. (buffer-string))))
  6695. ;; With optional argument ONOFF set to `on', try to insert the tag,
  6696. ;; even if its already there.
  6697. (should
  6698. (equal "* H :tag:"
  6699. (org-test-with-temp-text "* H"
  6700. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  6701. (buffer-string))))
  6702. (should
  6703. (equal "* H :tag:"
  6704. (org-test-with-temp-text "* H :tag:"
  6705. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  6706. (buffer-string))))
  6707. ;; With optional argument ONOFF set to `off', try to remove the tag,
  6708. ;; even if its not there.
  6709. (should
  6710. (equal "* H"
  6711. (org-test-with-temp-text "* H :tag:"
  6712. (org-toggle-tag "tag" 'off)
  6713. (buffer-string))))
  6714. (should
  6715. (equal "* H :tag:"
  6716. (org-test-with-temp-text "* H :tag:"
  6717. (let ((org-tags-column 1)) (org-toggle-tag "foo" 'off))
  6718. (buffer-string))))
  6719. ;; Special case: Handle properly tag inheritance. In particular, do
  6720. ;; not set inherited tags.
  6721. (should
  6722. (equal "* H1 :tag:\n** H2 :tag2:tag:"
  6723. (org-test-with-temp-text "* H1 :tag:\n** <point>H2 :tag2:"
  6724. (let ((org-use-tag-inheritance t)
  6725. (org-tags-column 1))
  6726. (org-toggle-tag "tag"))
  6727. (buffer-string))))
  6728. (should
  6729. (equal "* H1 :tag1:tag2:\n** H2 :foo:"
  6730. (org-test-with-temp-text "* H1 :tag1:tag2:\n** <point>H2"
  6731. (let ((org-use-tag-inheritance t)
  6732. (org-tags-column 1))
  6733. (org-toggle-tag "foo"))
  6734. (buffer-string)))))
  6735. (ert-deftest test-org/tags-expand ()
  6736. "Test `org-tags-expand' specifications."
  6737. ;; Expand tag groups as a regexp enclosed within curly brackets.
  6738. (should
  6739. (equal "{\\<[ABC]\\>}"
  6740. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6741. (org-mode-restart)
  6742. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  6743. (should
  6744. (equal "{\\<\\(?:Aa\\|Bb\\|Cc\\)\\>}"
  6745. (org-test-with-temp-text "#+TAGS: [ Aa : Bb Cc ]"
  6746. (org-mode-restart)
  6747. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "Aa")))))
  6748. ;; Preserve operator before the regexp.
  6749. (should
  6750. (equal "+{\\<[ABC]\\>}"
  6751. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6752. (org-mode-restart)
  6753. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "+A")))))
  6754. (should
  6755. (equal "-{\\<[ABC]\\>}"
  6756. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6757. (org-mode-restart)
  6758. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "-A")))))
  6759. ;; Handle "|" syntax.
  6760. (should
  6761. (equal "{\\<[ABC]\\>}|D"
  6762. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6763. (org-mode-restart)
  6764. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|D")))))
  6765. ;; Handle nested groups.
  6766. (should
  6767. (equal "{\\<[A-D]\\>}"
  6768. (org-test-with-temp-text "#+TAGS: [ A : B C ]\n#+TAGS: [ B : D ]"
  6769. (org-mode-restart)
  6770. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  6771. ;; Expand multiple occurrences of the same group.
  6772. (should
  6773. (equal "{\\<[ABC]\\>}|{\\<[ABC]\\>}"
  6774. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6775. (org-mode-restart)
  6776. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|A")))))
  6777. ;; Preserve regexp matches.
  6778. (should
  6779. (equal "{A+}"
  6780. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6781. (org-mode-restart)
  6782. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "{A+}"))))))
  6783. ;;; TODO keywords
  6784. (ert-deftest test-org/auto-repeat-maybe ()
  6785. "Test `org-auto-repeat-maybe' specifications."
  6786. ;; Do not auto repeat when there is no valid time stamp with
  6787. ;; a repeater in the entry.
  6788. (should-not
  6789. (string-prefix-p
  6790. "* TODO H"
  6791. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6792. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
  6793. (org-todo "DONE")
  6794. (buffer-string)))))
  6795. (should-not
  6796. (string-prefix-p
  6797. "* TODO H"
  6798. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6799. (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
  6800. (org-todo "DONE")
  6801. (buffer-string)))))
  6802. ;; When switching to DONE state, switch back to first TODO keyword
  6803. ;; in sequence, or the same keyword if they have different types.
  6804. (should
  6805. (string-prefix-p
  6806. "* TODO H"
  6807. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6808. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  6809. (org-todo "DONE")
  6810. (buffer-string)))))
  6811. (should
  6812. (string-prefix-p
  6813. "* KWD1 H"
  6814. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  6815. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  6816. (org-todo "DONE")
  6817. (buffer-string)))))
  6818. (should
  6819. (string-prefix-p
  6820. "* KWD2 H"
  6821. (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
  6822. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  6823. (org-todo "DONE")
  6824. (buffer-string)))))
  6825. ;; If there was no TODO keyword in the first place, do not insert
  6826. ;; any either.
  6827. (should
  6828. (string-prefix-p
  6829. "* H"
  6830. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6831. (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
  6832. (org-todo "DONE")
  6833. (buffer-string)))))
  6834. ;; Revert to REPEAT_TO_STATE, if set.
  6835. (should
  6836. (string-prefix-p
  6837. "* KWD2 H"
  6838. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  6839. (org-test-with-temp-text
  6840. "* KWD2 H
  6841. :PROPERTIES:
  6842. :REPEAT_TO_STATE: KWD2
  6843. :END:
  6844. <2012-03-29 Thu +2y>"
  6845. (org-todo "DONE")
  6846. (buffer-string)))))
  6847. ;; When switching to DONE state, update base date. If there are
  6848. ;; multiple repeated time stamps, update them all.
  6849. (should
  6850. (string-match-p
  6851. "<2014-03-29 .* \\+2y>"
  6852. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6853. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  6854. (org-todo "DONE")
  6855. (buffer-string)))))
  6856. (should
  6857. (string-match-p
  6858. "<2015-03-04 .* \\+1y>"
  6859. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6860. (org-test-with-temp-text
  6861. "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
  6862. (org-todo "DONE")
  6863. (buffer-string)))))
  6864. ;; Throw an error if repeater unit is the hour and no time is
  6865. ;; provided in the time-stamp.
  6866. (should-error
  6867. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6868. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
  6869. (org-todo "DONE")
  6870. (buffer-string))))
  6871. ;; Handle every repeater type using hours step.
  6872. (should
  6873. (string-match-p
  6874. "2014-03-04 .* 02:00"
  6875. (org-test-at-time "<2014-03-04 02:35>"
  6876. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 +8h>"
  6877. (org-todo "DONE")
  6878. (buffer-string)))))
  6879. (should
  6880. (string-match-p
  6881. "2014-03-04 .* 10:00"
  6882. (org-test-at-time "<2014-03-04 02:35>"
  6883. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 ++8h>"
  6884. (org-todo "DONE")
  6885. (buffer-string)))))
  6886. (should
  6887. (string-match-p
  6888. "2014-03-04 .* 10:35"
  6889. (org-test-at-time "<2014-03-04 02:35>"
  6890. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 .+8h>"
  6891. (org-todo "DONE")
  6892. (buffer-string)))))
  6893. ;; Do not repeat inactive time stamps with a repeater.
  6894. (should-not
  6895. (string-match-p
  6896. "\\[2014-03-29 .* \\+2y\\]"
  6897. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6898. (org-test-with-temp-text
  6899. "* TODO H\n[2012-03-29 Thu. +2y]"
  6900. (org-todo "DONE")
  6901. (buffer-string)))))
  6902. ;; Do not repeat commented time stamps.
  6903. (should-not
  6904. (string-prefix-p
  6905. "<2015-03-04 .* \\+1y>"
  6906. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6907. (org-test-with-temp-text
  6908. "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
  6909. (org-todo "DONE")
  6910. (buffer-string)))))
  6911. (should-not
  6912. (string-prefix-p
  6913. "<2015-03-04 .* \\+1y>"
  6914. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6915. (org-test-with-temp-text
  6916. "* TODO H
  6917. <2012-03-29 Thu. +2y>
  6918. #+BEGIN_EXAMPLE
  6919. <2014-03-04 Tue +1y>
  6920. #+END_EXAMPLE"
  6921. (org-todo "DONE")
  6922. (buffer-string)))))
  6923. ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
  6924. ;; entry, record time of last repeat.
  6925. (should-not
  6926. (string-match-p
  6927. ":LAST_REPEAT:"
  6928. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  6929. (org-log-repeat nil))
  6930. (cl-letf (((symbol-function 'org-add-log-setup)
  6931. (lambda (&rest args) nil)))
  6932. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  6933. (org-todo "DONE")
  6934. (buffer-string))))))
  6935. (should
  6936. (string-match-p
  6937. ":LAST_REPEAT:"
  6938. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  6939. (org-log-repeat t))
  6940. (cl-letf (((symbol-function 'org-add-log-setup)
  6941. (lambda (&rest args) nil)))
  6942. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  6943. (org-todo "DONE")
  6944. (buffer-string))))))
  6945. (should
  6946. (string-match-p
  6947. ":LAST_REPEAT:"
  6948. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6949. (cl-letf (((symbol-function 'org-add-log-setup)
  6950. (lambda (&rest args) nil)))
  6951. (org-test-with-temp-text
  6952. "* TODO H\n<2012-03-29 Thu +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
  6953. (org-todo "DONE")
  6954. (buffer-string))))))
  6955. ;; When a SCHEDULED entry has no repeater, remove it upon repeating
  6956. ;; the entry as it is no longer relevant.
  6957. (should-not
  6958. (string-match-p
  6959. "^SCHEDULED:"
  6960. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6961. (org-test-with-temp-text
  6962. "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
  6963. (org-todo "DONE")
  6964. (buffer-string)))))
  6965. ;; Properly advance repeater even when a clock entry is specified
  6966. ;; and `org-log-repeat' is nil.
  6967. (should
  6968. (string-match-p
  6969. "SCHEDULED: <2014-03-29"
  6970. (let ((org-log-repeat nil)
  6971. (org-todo-keywords '((sequence "TODO" "DONE"))))
  6972. (org-test-with-temp-text
  6973. "* TODO H
  6974. SCHEDULED: <2012-03-29 Thu +2y>
  6975. CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] => 6:40"
  6976. (org-todo "DONE")
  6977. (buffer-string))))))
  6978. ;;; Timestamps API
  6979. (ert-deftest test-org/at-timestamp-p ()
  6980. "Test `org-at-timestamp-p' specifications."
  6981. (should
  6982. (org-test-with-temp-text "<2012-03-29 Thu>"
  6983. (org-at-timestamp-p)))
  6984. (should-not
  6985. (org-test-with-temp-text "2012-03-29 Thu"
  6986. (org-at-timestamp-p)))
  6987. ;; Test return values.
  6988. (should
  6989. (eq 'bracket
  6990. (org-test-with-temp-text "<2012-03-29 Thu>"
  6991. (org-at-timestamp-p))))
  6992. (should
  6993. (eq 'year
  6994. (org-test-with-temp-text "<<point>2012-03-29 Thu>"
  6995. (org-at-timestamp-p))))
  6996. (should
  6997. (eq 'month
  6998. (org-test-with-temp-text "<2012-<point>03-29 Thu>"
  6999. (org-at-timestamp-p))))
  7000. (should
  7001. (eq 'day
  7002. (org-test-with-temp-text "<2012-03-<point>29 Thu>"
  7003. (org-at-timestamp-p))))
  7004. (should
  7005. (eq 'day
  7006. (org-test-with-temp-text "<2012-03-29 T<point>hu>"
  7007. (org-at-timestamp-p))))
  7008. (should
  7009. (wholenump
  7010. (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
  7011. (org-at-timestamp-p))))
  7012. (should
  7013. (eq 'bracket
  7014. (org-test-with-temp-text "<2012-03-29 Thu<point>>"
  7015. (org-at-timestamp-p))))
  7016. (should
  7017. (eq 'after
  7018. (org-test-with-temp-text "<2012-03-29 Thu><point>»"
  7019. (org-at-timestamp-p))))
  7020. ;; Test `inactive' optional argument.
  7021. (should
  7022. (org-test-with-temp-text "[2012-03-29 Thu]"
  7023. (org-at-timestamp-p 'inactive)))
  7024. (should-not
  7025. (org-test-with-temp-text "[2012-03-29 Thu]"
  7026. (org-at-timestamp-p)))
  7027. ;; When optional argument is `agenda', recognize time-stamps in
  7028. ;; planning info line, property drawers and clocks.
  7029. (should
  7030. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7031. (org-at-timestamp-p 'agenda)))
  7032. (should-not
  7033. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7034. (org-at-timestamp-p)))
  7035. (should
  7036. (org-test-with-temp-text
  7037. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7038. (org-at-timestamp-p 'agenda)))
  7039. (should-not
  7040. (org-test-with-temp-text
  7041. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7042. (org-at-timestamp-p)))
  7043. (should
  7044. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7045. (let ((org-agenda-include-inactive-timestamps t))
  7046. (org-at-timestamp-p 'agenda))))
  7047. (should-not
  7048. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7049. (let ((org-agenda-include-inactive-timestamps t))
  7050. (org-at-timestamp-p))))
  7051. (should-not
  7052. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7053. (let ((org-agenda-include-inactive-timestamps t))
  7054. (org-at-timestamp-p 'inactive))))
  7055. ;; When optional argument is `lax', match any part of the document
  7056. ;; with Org timestamp syntax.
  7057. (should
  7058. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7059. (org-at-timestamp-p 'lax)))
  7060. (should-not
  7061. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7062. (org-at-timestamp-p)))
  7063. (should
  7064. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7065. (org-at-timestamp-p 'lax)))
  7066. (should-not
  7067. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7068. (org-at-timestamp-p)))
  7069. (should
  7070. (org-test-with-temp-text
  7071. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7072. (org-at-timestamp-p 'lax)))
  7073. (should-not
  7074. (org-test-with-temp-text
  7075. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7076. (org-at-timestamp-p)))
  7077. ;; Optional argument `lax' also matches inactive timestamps.
  7078. (should
  7079. (org-test-with-temp-text "# [2012-03-29 Thu]<point>"
  7080. (org-at-timestamp-p 'lax))))
  7081. (ert-deftest test-org/time-stamp ()
  7082. "Test `org-time-stamp' specifications."
  7083. ;; Insert chosen time stamp at point.
  7084. (should
  7085. (string-match
  7086. "Te<2014-03-04 .*?>xt"
  7087. (org-test-with-temp-text "Te<point>xt"
  7088. (cl-letf (((symbol-function 'org-read-date)
  7089. (lambda (&rest args)
  7090. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7091. (org-time-stamp nil)
  7092. (buffer-string)))))
  7093. ;; With a prefix argument, also insert time.
  7094. (should
  7095. (string-match
  7096. "Te<2014-03-04 .*? 00:41>xt"
  7097. (org-test-with-temp-text "Te<point>xt"
  7098. (cl-letf (((symbol-function 'org-read-date)
  7099. (lambda (&rest args)
  7100. (apply #'encode-time
  7101. (org-parse-time-string "2014-03-04 00:41")))))
  7102. (org-time-stamp '(4))
  7103. (buffer-string)))))
  7104. ;; With two universal prefix arguments, insert an active timestamp
  7105. ;; with the current time without prompting the user.
  7106. (should
  7107. (string-match
  7108. "Te<2014-03-04 .*? 00:41>xt"
  7109. (org-test-with-temp-text "Te<point>xt"
  7110. (org-test-at-time "2014-03-04 00:41"
  7111. (org-time-stamp '(16))
  7112. (buffer-string)))))
  7113. ;; When optional argument is non-nil, insert an inactive timestamp.
  7114. (should
  7115. (string-match
  7116. "Te\\[2014-03-04 .*?\\]xt"
  7117. (org-test-with-temp-text "Te<point>xt"
  7118. (cl-letf (((symbol-function 'org-read-date)
  7119. (lambda (&rest args)
  7120. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7121. (org-time-stamp nil t)
  7122. (buffer-string)))))
  7123. ;; When called from a timestamp, replace existing one.
  7124. (should
  7125. (string-match
  7126. "<2014-03-04 .*?>"
  7127. (org-test-with-temp-text "<2012-03-29<point> thu.>"
  7128. (cl-letf (((symbol-function 'org-read-date)
  7129. (lambda (&rest args)
  7130. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7131. (org-time-stamp nil)
  7132. (buffer-string)))))
  7133. (should
  7134. (string-match
  7135. "<2014-03-04 .*?>--<2014-03-04 .*?>"
  7136. (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
  7137. (cl-letf (((symbol-function 'org-read-date)
  7138. (lambda (&rest args)
  7139. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7140. (org-time-stamp nil)
  7141. (buffer-string)))))
  7142. ;; When replacing a timestamp, preserve repeater, if any.
  7143. (should
  7144. (string-match
  7145. "<2014-03-04 .*? \\+2y>"
  7146. (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
  7147. (cl-letf (((symbol-function 'org-read-date)
  7148. (lambda (&rest args)
  7149. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7150. (org-time-stamp nil)
  7151. (buffer-string)))))
  7152. ;; When called twice in a raw, build a date range.
  7153. (should
  7154. (string-match
  7155. "<2012-03-29 .*?>--<2014-03-04 .*?>"
  7156. (org-test-with-temp-text "<2012-03-29 thu.><point>"
  7157. (cl-letf (((symbol-function 'org-read-date)
  7158. (lambda (&rest args)
  7159. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7160. (let ((last-command 'org-time-stamp)
  7161. (this-command 'org-time-stamp))
  7162. (org-time-stamp nil))
  7163. (buffer-string))))))
  7164. (ert-deftest test-org/timestamp-has-time-p ()
  7165. "Test `org-timestamp-has-time-p' specifications."
  7166. ;; With time.
  7167. (should
  7168. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7169. (org-timestamp-has-time-p (org-element-context))))
  7170. ;; Without time.
  7171. (should-not
  7172. (org-test-with-temp-text "<2012-03-29 Thu>"
  7173. (org-timestamp-has-time-p (org-element-context)))))
  7174. (ert-deftest test-org/get-repeat ()
  7175. "Test `org-get-repeat' specifications."
  7176. (should
  7177. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
  7178. (org-get-repeat)))
  7179. (should-not
  7180. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
  7181. (org-get-repeat)))
  7182. ;; Return proper repeat string.
  7183. (should
  7184. (equal "+2y"
  7185. (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
  7186. (org-get-repeat))))
  7187. ;; Prevent false positive (commented or verbatim time stamps)
  7188. (should-not
  7189. (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
  7190. (org-get-repeat)))
  7191. (should-not
  7192. (org-test-with-temp-text
  7193. "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
  7194. (org-get-repeat)))
  7195. ;; Return nil when called before first heading.
  7196. (should-not
  7197. (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
  7198. (org-get-repeat)))
  7199. ;; When called with an optional argument, extract repeater from that
  7200. ;; string instead.
  7201. (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
  7202. (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
  7203. (ert-deftest test-org/timestamp-format ()
  7204. "Test `org-timestamp-format' specifications."
  7205. ;; Regular test.
  7206. (should
  7207. (equal
  7208. "2012-03-29 16:40"
  7209. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7210. (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
  7211. ;; Range end.
  7212. (should
  7213. (equal
  7214. "2012-03-29"
  7215. (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
  7216. (org-timestamp-format (org-element-context) "%Y-%m-%d" t)))))
  7217. (ert-deftest test-org/timestamp-split-range ()
  7218. "Test `org-timestamp-split-range' specifications."
  7219. ;; Extract range start (active).
  7220. (should
  7221. (equal '(2012 3 29)
  7222. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7223. (let ((ts (org-timestamp-split-range (org-element-context))))
  7224. (mapcar (lambda (p) (org-element-property p ts))
  7225. '(:year-end :month-end :day-end))))))
  7226. ;; Extract range start (inactive)
  7227. (should
  7228. (equal '(2012 3 29)
  7229. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7230. (let ((ts (org-timestamp-split-range (org-element-context))))
  7231. (mapcar (lambda (p) (org-element-property p ts))
  7232. '(:year-end :month-end :day-end))))))
  7233. ;; Extract range end (active).
  7234. (should
  7235. (equal '(2012 3 30)
  7236. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7237. (let ((ts (org-timestamp-split-range
  7238. (org-element-context) t)))
  7239. (mapcar (lambda (p) (org-element-property p ts))
  7240. '(:year-end :month-end :day-end))))))
  7241. ;; Extract range end (inactive)
  7242. (should
  7243. (equal '(2012 3 30)
  7244. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7245. (let ((ts (org-timestamp-split-range
  7246. (org-element-context) t)))
  7247. (mapcar (lambda (p) (org-element-property p ts))
  7248. '(:year-end :month-end :day-end))))))
  7249. ;; Return the timestamp if not a range.
  7250. (should
  7251. (org-test-with-temp-text "[2012-03-29 Thu]"
  7252. (let* ((ts-orig (org-element-context))
  7253. (ts-copy (org-timestamp-split-range ts-orig)))
  7254. (eq ts-orig ts-copy))))
  7255. (should
  7256. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7257. (let* ((ts-orig (org-element-context))
  7258. (ts-copy (org-timestamp-split-range ts-orig)))
  7259. (eq ts-orig ts-copy)))))
  7260. (ert-deftest test-org/timestamp-translate ()
  7261. "Test `org-timestamp-translate' specifications."
  7262. ;; Translate whole date range.
  7263. (should
  7264. (equal "<29>--<30>"
  7265. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7266. (let ((org-display-custom-times t)
  7267. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7268. (org-timestamp-translate (org-element-context))))))
  7269. ;; Translate date range start.
  7270. (should
  7271. (equal "<29>"
  7272. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7273. (let ((org-display-custom-times t)
  7274. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7275. (org-timestamp-translate (org-element-context) 'start)))))
  7276. ;; Translate date range end.
  7277. (should
  7278. (equal "<30>"
  7279. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7280. (let ((org-display-custom-times t)
  7281. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7282. (org-timestamp-translate (org-element-context) 'end)))))
  7283. ;; Translate time range.
  7284. (should
  7285. (equal "<08>--<16>"
  7286. (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
  7287. (let ((org-display-custom-times t)
  7288. (org-time-stamp-custom-formats '("<%d>" . "<%H>")))
  7289. (org-timestamp-translate (org-element-context))))))
  7290. ;; Translate non-range timestamp.
  7291. (should
  7292. (equal "<29>"
  7293. (org-test-with-temp-text "<2012-03-29 Thu>"
  7294. (let ((org-display-custom-times t)
  7295. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7296. (org-timestamp-translate (org-element-context))))))
  7297. ;; Do not change `diary' timestamps.
  7298. (should
  7299. (equal "<%%(org-float t 4 2)>"
  7300. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7301. (let ((org-display-custom-times t)
  7302. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7303. (org-timestamp-translate (org-element-context)))))))
  7304. (ert-deftest test-org/timestamp-from-string ()
  7305. "Test `org-timestamp-from-string' specifications."
  7306. ;; Return nil if argument is not a valid Org timestamp.
  7307. (should-not (org-timestamp-from-string ""))
  7308. (should-not (org-timestamp-from-string nil))
  7309. (should-not (org-timestamp-from-string "<2012-03-29"))
  7310. ;; Otherwise, return a valid Org timestamp object.
  7311. (should
  7312. (string-match-p "<2012-03-29 .+>"
  7313. (org-element-interpret-data
  7314. (org-timestamp-from-string "<2012-03-29 Thu>"))))
  7315. (should
  7316. (string-match-p "[2014-03-04 .+]"
  7317. (org-element-interpret-data
  7318. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  7319. (ert-deftest test-org/timestamp-from-time ()
  7320. "Test `org-timestamp-from-time' specifications."
  7321. ;; Standard test.
  7322. (should
  7323. (string-match-p
  7324. "<2012-03-29 .+>"
  7325. (org-element-interpret-data
  7326. (org-timestamp-from-time
  7327. (apply #'encode-time
  7328. (org-parse-time-string "<2012-03-29 Thu 16:40>"))))))
  7329. ;; When optional argument WITH-TIME is non-nil, provide time
  7330. ;; information.
  7331. (should
  7332. (string-match-p
  7333. "<2012-03-29 .+ 16:40>"
  7334. (org-element-interpret-data
  7335. (org-timestamp-from-time
  7336. (apply #'encode-time
  7337. (org-parse-time-string "<2012-03-29 Thu 16:40>"))
  7338. t))))
  7339. ;; When optional argument INACTIVE is non-nil, return an inactive
  7340. ;; timestamp.
  7341. (should
  7342. (string-match-p
  7343. "[2012-03-29 .+]"
  7344. (org-element-interpret-data
  7345. (org-timestamp-from-time
  7346. (apply #'encode-time
  7347. (org-parse-time-string "<2012-03-29 Thu 16:40>"))
  7348. nil t)))))
  7349. (ert-deftest test-org/timestamp-to-time ()
  7350. "Test `org-timestamp-to-time' specifications."
  7351. (should
  7352. (equal "2014-03-04"
  7353. (format-time-string
  7354. "%Y-%m-%d"
  7355. (org-timestamp-to-time
  7356. (org-timestamp-from-string "<2014-03-04 Tue>")))))
  7357. (should
  7358. (equal "2014-03-04"
  7359. (format-time-string
  7360. "%Y-%m-%d"
  7361. (org-timestamp-to-time
  7362. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  7363. (should
  7364. (equal "2012-03-29 08:30"
  7365. (format-time-string
  7366. "%Y-%m-%d %H:%M"
  7367. (org-timestamp-to-time
  7368. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")))))
  7369. (should
  7370. (equal "2012-03-29"
  7371. (format-time-string
  7372. "%Y-%m-%d"
  7373. (org-timestamp-to-time
  7374. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")))))
  7375. (should
  7376. (equal "2012-03-29"
  7377. (format-time-string
  7378. "%Y-%m-%d"
  7379. (org-timestamp-to-time
  7380. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")))))
  7381. ;; When optional argument END is non-nil, use end of date range or
  7382. ;; time range.
  7383. (should
  7384. (equal "2012-03-29 16:40"
  7385. (format-time-string
  7386. "%Y-%m-%d %H:%M"
  7387. (org-timestamp-to-time
  7388. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")
  7389. t))))
  7390. (should
  7391. (equal "2014-03-04"
  7392. (format-time-string
  7393. "%Y-%m-%d"
  7394. (org-timestamp-to-time
  7395. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")
  7396. t))))
  7397. (should
  7398. (equal "2014-03-04"
  7399. (format-time-string
  7400. "%Y-%m-%d"
  7401. (org-timestamp-to-time
  7402. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")
  7403. t)))))
  7404. ;;; Visibility
  7405. (ert-deftest test-org/hide-drawer-toggle ()
  7406. "Test `org-hide-drawer-toggle' specifications."
  7407. ;; Error when not at a drawer.
  7408. (should-error
  7409. (org-test-with-temp-text ":fake-drawer:\ncontents"
  7410. (org-hide-drawer-toggle 'off)
  7411. (get-char-property (line-end-position) 'invisible)))
  7412. (should-error
  7413. (org-test-with-temp-text
  7414. "#+begin_example\n<point>:D:\nc\n:END:\n#+end_example"
  7415. (org-hide-drawer-toggle t)))
  7416. ;; Hide drawer.
  7417. (should
  7418. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7419. (org-hide-drawer-toggle)
  7420. (get-char-property (line-end-position) 'invisible)))
  7421. ;; Show drawer unconditionally when optional argument is `off'.
  7422. (should-not
  7423. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7424. (org-hide-drawer-toggle)
  7425. (org-hide-drawer-toggle 'off)
  7426. (get-char-property (line-end-position) 'invisible)))
  7427. ;; Hide drawer unconditionally when optional argument is non-nil.
  7428. (should
  7429. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7430. (org-hide-drawer-toggle t)
  7431. (get-char-property (line-end-position) 'invisible)))
  7432. ;; Do not hide drawer when called from final blank lines.
  7433. (should-not
  7434. (org-test-with-temp-text ":drawer:\ncontents\n:end:\n\n<point>"
  7435. (org-hide-drawer-toggle)
  7436. (goto-char (point-min))
  7437. (get-char-property (line-end-position) 'invisible)))
  7438. ;; Don't leave point in an invisible part of the buffer when hiding
  7439. ;; a drawer away.
  7440. (should-not
  7441. (org-test-with-temp-text ":drawer:\ncontents\n<point>:end:"
  7442. (org-hide-drawer-toggle)
  7443. (get-char-property (point) 'invisible))))
  7444. (ert-deftest test-org/hide-block-toggle ()
  7445. "Test `org-hide-block-toggle' specifications."
  7446. ;; Error when not at a block.
  7447. (should-error
  7448. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
  7449. (org-hide-block-toggle 'off)
  7450. (get-char-property (line-end-position) 'invisible)))
  7451. ;; Hide block.
  7452. (should
  7453. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  7454. (org-hide-block-toggle)
  7455. (get-char-property (line-end-position) 'invisible)))
  7456. (should
  7457. (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
  7458. (org-hide-block-toggle)
  7459. (get-char-property (line-end-position) 'invisible)))
  7460. ;; Show block unconditionally when optional argument is `off'.
  7461. (should-not
  7462. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7463. (org-hide-block-toggle)
  7464. (org-hide-block-toggle 'off)
  7465. (get-char-property (line-end-position) 'invisible)))
  7466. (should-not
  7467. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7468. (org-hide-block-toggle 'off)
  7469. (get-char-property (line-end-position) 'invisible)))
  7470. ;; Hide block unconditionally when optional argument is non-nil.
  7471. (should
  7472. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7473. (org-hide-block-toggle t)
  7474. (get-char-property (line-end-position) 'invisible)))
  7475. (should
  7476. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7477. (org-hide-block-toggle)
  7478. (org-hide-block-toggle t)
  7479. (get-char-property (line-end-position) 'invisible)))
  7480. ;; Do not hide block when called from final blank lines.
  7481. (should-not
  7482. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
  7483. (org-hide-block-toggle)
  7484. (goto-char (point-min))
  7485. (get-char-property (line-end-position) 'invisible)))
  7486. ;; Don't leave point in an invisible part of the buffer when hiding
  7487. ;; a block away.
  7488. (should-not
  7489. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
  7490. (org-hide-block-toggle)
  7491. (get-char-property (point) 'invisible))))
  7492. (ert-deftest test-org/hide-block-toggle-maybe ()
  7493. "Test `org-hide-block-toggle-maybe' specifications."
  7494. (should
  7495. (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
  7496. (org-hide-block-toggle-maybe)))
  7497. (should-not
  7498. (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
  7499. (ert-deftest test-org/show-set-visibility ()
  7500. "Test `org-show-set-visibility' specifications."
  7501. ;; Do not throw an error before first heading.
  7502. (should
  7503. (org-test-with-temp-text "Preamble\n* Headline"
  7504. (org-show-set-visibility 'tree)
  7505. t))
  7506. ;; Test all visibility spans, both on headline and in entry.
  7507. (let ((list-visible-lines
  7508. (lambda (state headerp)
  7509. (org-test-with-temp-text "* Grandmother (0)
  7510. ** Uncle (1)
  7511. *** Heir (2)
  7512. ** Father (3)
  7513. Ancestor text (4)
  7514. *** Sister (5)
  7515. Sibling text (6)
  7516. *** Self (7)
  7517. Match (8)
  7518. **** First born (9)
  7519. Child text (10)
  7520. **** The other child (11)
  7521. *** Brother (12)
  7522. ** Aunt (13)
  7523. "
  7524. (org-cycle t)
  7525. (search-forward (if headerp "Self" "Match"))
  7526. (org-show-set-visibility state)
  7527. (goto-char (point-min))
  7528. (let (result (line 0))
  7529. (while (not (eobp))
  7530. (unless (org-invisible-p2) (push line result))
  7531. (cl-incf line)
  7532. (forward-line))
  7533. (nreverse result))))))
  7534. (should (equal '(0 7) (funcall list-visible-lines 'minimal t)))
  7535. (should (equal '(0 7 8) (funcall list-visible-lines 'minimal nil)))
  7536. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local t)))
  7537. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local nil)))
  7538. (should (equal '(0 3 7) (funcall list-visible-lines 'ancestors t)))
  7539. (should (equal '(0 3 7 8) (funcall list-visible-lines 'ancestors nil)))
  7540. (should (equal '(0 3 5 7 12) (funcall list-visible-lines 'lineage t)))
  7541. (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines 'lineage nil)))
  7542. (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines 'tree t)))
  7543. (should (equal '(0 1 3 5 7 8 9 11 12 13)
  7544. (funcall list-visible-lines 'tree nil)))
  7545. (should (equal '(0 1 3 4 5 7 12 13)
  7546. (funcall list-visible-lines 'canonical t)))
  7547. (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
  7548. (funcall list-visible-lines 'canonical nil))))
  7549. ;; When point is hidden in a drawer or a block, make sure to make it
  7550. ;; visible.
  7551. (should-not
  7552. (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
  7553. (org-hide-block-toggle)
  7554. (search-forward "Text")
  7555. (org-show-set-visibility 'minimal)
  7556. (org-invisible-p2)))
  7557. (should-not
  7558. (org-test-with-temp-text ":DRAWER:\nText\n:END:"
  7559. (org-hide-drawer-toggle)
  7560. (search-forward "Text")
  7561. (org-show-set-visibility 'minimal)
  7562. (org-invisible-p2)))
  7563. (should-not
  7564. (org-test-with-temp-text
  7565. "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
  7566. (org-hide-drawer-toggle)
  7567. (forward-line -1)
  7568. (org-hide-block-toggle)
  7569. (search-forward "Text")
  7570. (org-show-set-visibility 'minimal)
  7571. (org-invisible-p2))))
  7572. (defun test-org/copy-visible ()
  7573. "Test `org-copy-visible' specifications."
  7574. (should
  7575. (equal "Foo"
  7576. (org-test-with-temp-text "Foo"
  7577. (let ((kill-ring nil))
  7578. (org-copy-visible (point-min) (point-max))
  7579. (current-kill 0 t)))))
  7580. ;; Skip invisible characters by text property.
  7581. (should
  7582. (equal "Foo"
  7583. (org-test-with-temp-text #("F<hidden>oo" 1 7 (invisible t))
  7584. (let ((kill-ring nil))
  7585. (org-copy-visible (point-min) (point-max))
  7586. (current-kill 0 t)))))
  7587. ;; Skip invisible characters by overlay.
  7588. (should
  7589. (equal "Foo"
  7590. (org-test-with-temp-text "F<hidden>oo"
  7591. (let ((o (make-overlay 2 10)))
  7592. (overlay-put o 'invisible t))
  7593. (let ((kill-ring nil))
  7594. (org-copy-visible (point-min) (point-max))
  7595. (current-kill 0 t)))))
  7596. ;; Handle invisible characters at the beginning and the end of the
  7597. ;; buffer.
  7598. (should
  7599. (equal "Foo"
  7600. (org-test-with-temp-text #("<hidden>Foo" 0 8 (invisible t))
  7601. (let ((kill-ring nil))
  7602. (org-copy-visible (point-min) (point-max))
  7603. (current-kill 0 t)))))
  7604. (should
  7605. (equal "Foo"
  7606. (org-test-with-temp-text #("Foo<hidden>" 3 11 (invisible t))
  7607. (let ((kill-ring nil))
  7608. (org-copy-visible (point-min) (point-max))
  7609. (current-kill 0 t)))))
  7610. ;; Handle multiple visible parts.
  7611. (should
  7612. (equal "abc"
  7613. (org-test-with-temp-text
  7614. #("aXbXc" 1 2 (invisible t) 3 4 (invisible t))
  7615. (let ((kill-ring nil))
  7616. (org-copy-visible (point-min) (point-max))
  7617. (current-kill 0 t))))))
  7618. (ert-deftest test-org/set-visibility-according-to-property ()
  7619. "Test `org-set-visibility-according-to-property' specifications."
  7620. ;; "folded" state.
  7621. (should
  7622. (org-test-with-temp-text
  7623. "
  7624. * a
  7625. :PROPERTIES:
  7626. :VISIBILITY: folded
  7627. :END:
  7628. ** <point>b"
  7629. (org-set-visibility-according-to-property)
  7630. (invisible-p (point))))
  7631. ;; "children" state.
  7632. (should
  7633. (org-test-with-temp-text
  7634. "
  7635. * a
  7636. :PROPERTIES:
  7637. :VISIBILITY: children
  7638. :END:
  7639. ** b
  7640. <point>Contents
  7641. ** c"
  7642. (org-set-visibility-according-to-property)
  7643. (invisible-p (point))))
  7644. (should
  7645. (org-test-with-temp-text
  7646. "
  7647. * a
  7648. :PROPERTIES:
  7649. :VISIBILITY: children
  7650. :END:
  7651. ** b
  7652. Contents
  7653. *** <point>c"
  7654. (org-set-visibility-according-to-property)
  7655. (invisible-p (point))))
  7656. ;; "content" state.
  7657. (should
  7658. (org-test-with-temp-text
  7659. "
  7660. * a
  7661. :PROPERTIES:
  7662. :VISIBILITY: content
  7663. :END:
  7664. ** b
  7665. <point>Contents
  7666. *** c"
  7667. (org-set-visibility-according-to-property)
  7668. (invisible-p (point))))
  7669. (should
  7670. (org-test-with-temp-text
  7671. "
  7672. * a
  7673. :PROPERTIES:
  7674. :VISIBILITY: content
  7675. :END:
  7676. ** b
  7677. Contents
  7678. *** <point>c"
  7679. (org-set-visibility-according-to-property)
  7680. (not (invisible-p (point)))))
  7681. ;; "showall" state.
  7682. (should
  7683. (org-test-with-temp-text
  7684. "
  7685. * a
  7686. :PROPERTIES:
  7687. :VISIBILITY: showall
  7688. :END:
  7689. ** b
  7690. <point>Contents
  7691. *** c"
  7692. (org-set-visibility-according-to-property)
  7693. (not (invisible-p (point)))))
  7694. (should
  7695. (org-test-with-temp-text
  7696. "
  7697. * a
  7698. :PROPERTIES:
  7699. :VISIBILITY: showall
  7700. :END:
  7701. ** b
  7702. Contents
  7703. *** <point>c"
  7704. (org-set-visibility-according-to-property)
  7705. (not (invisible-p (point)))))
  7706. ;; When VISIBILITY properties are nested, ignore inner ones.
  7707. (should
  7708. (org-test-with-temp-text
  7709. "
  7710. * A
  7711. :PROPERTIES:
  7712. :VISIBILITY: folded
  7713. :END:
  7714. ** <point>B
  7715. :PROPERTIES:
  7716. :VISIBILITY: folded
  7717. :END:"
  7718. (org-set-visibility-according-to-property)
  7719. (invisible-p (point)))))
  7720. (ert-deftest test-org/visibility-show-branches ()
  7721. "Test visibility of inline archived subtrees."
  7722. (org-test-with-temp-text
  7723. "* Foo<point>
  7724. ** Bar :ARCHIVE:
  7725. *** Baz
  7726. "
  7727. (org-kill-note-or-show-branches)
  7728. (should (org-invisible-p (- (point-max) 2)))))
  7729. ;;; Yank and Kill
  7730. (ert-deftest test-org/paste-subtree ()
  7731. "Test `org-paste-subtree' specifications."
  7732. ;; Return an error if text to yank is not a set of subtrees.
  7733. (should-error (org-paste-subtree nil "Text"))
  7734. ;; Adjust level according to current one.
  7735. (should
  7736. (equal "* H\n* Text\n"
  7737. (org-test-with-temp-text "* H\n<point>"
  7738. (org-paste-subtree nil "* Text")
  7739. (buffer-string))))
  7740. (should
  7741. (equal "* H1\n** H2\n** Text\n"
  7742. (org-test-with-temp-text "* H1\n** H2\n<point>"
  7743. (org-paste-subtree nil "* Text")
  7744. (buffer-string))))
  7745. ;; When not on a heading, move to next heading before yanking.
  7746. (should
  7747. (equal "* H1\nParagraph\n* Text\n* H2"
  7748. (org-test-with-temp-text "* H1\n<point>Paragraph\n* H2"
  7749. (org-paste-subtree nil "* Text")
  7750. (buffer-string))))
  7751. ;; If point is between two headings, use the deepest level.
  7752. (should
  7753. (equal "* H1\n\n* Text\n* H2"
  7754. (org-test-with-temp-text "* H1\n<point>\n* H2"
  7755. (org-paste-subtree nil "* Text")
  7756. (buffer-string))))
  7757. (should
  7758. (equal "** H1\n\n** Text\n* H2"
  7759. (org-test-with-temp-text "** H1\n<point>\n* H2"
  7760. (org-paste-subtree nil "* Text")
  7761. (buffer-string))))
  7762. (should
  7763. (equal "* H1\n\n** Text\n** H2"
  7764. (org-test-with-temp-text "* H1\n<point>\n** H2"
  7765. (org-paste-subtree nil "* Text")
  7766. (buffer-string))))
  7767. ;; When on an empty heading, after the stars, deduce the new level
  7768. ;; from the number of stars.
  7769. (should
  7770. (equal "*** Text\n"
  7771. (org-test-with-temp-text "*** <point>"
  7772. (org-paste-subtree nil "* Text")
  7773. (buffer-string))))
  7774. ;; Optional argument LEVEL forces a level for the subtree.
  7775. (should
  7776. (equal "* H\n*** Text\n"
  7777. (org-test-with-temp-text "* H<point>"
  7778. (org-paste-subtree 3 "* Text")
  7779. (buffer-string)))))
  7780. (ert-deftest test-org/cut-and-paste-subtree ()
  7781. "Test `org-cut-subtree' and `org-paste-subtree'."
  7782. (should
  7783. (equal
  7784. "* Two
  7785. two
  7786. * One
  7787. "
  7788. (org-test-with-temp-text
  7789. "* One
  7790. <point>* Two
  7791. two
  7792. "
  7793. (call-interactively #'org-cut-subtree)
  7794. (goto-char (point-min))
  7795. (call-interactively #'org-paste-subtree)
  7796. (buffer-string))))
  7797. (should
  7798. (equal
  7799. "* One
  7800. * Two
  7801. "
  7802. (org-test-with-temp-text
  7803. "* One
  7804. <point>* Two
  7805. "
  7806. (call-interactively #'org-cut-subtree)
  7807. (backward-char)
  7808. (call-interactively #'org-paste-subtree)
  7809. (buffer-string)))))
  7810. (provide 'test-org)
  7811. ;;; test-org.el ends here