test-org.el 260 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047
  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/shiftright-heading ()
  3239. "Test `org-shiftright' on headings."
  3240. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  3241. (should
  3242. (equal "* TODO a1\n** a2\n* DONE b1\n"
  3243. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3244. (org-shiftright)
  3245. (buffer-string))))
  3246. (should
  3247. (equal "* TODO a1\n** TODO a2\n* b1\n"
  3248. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3249. (let ((org-loop-over-headlines-in-active-region t))
  3250. (transient-mark-mode 1)
  3251. (push-mark (point) t t)
  3252. (search-forward "* DONE b1")
  3253. (org-shiftright))
  3254. (buffer-string))))
  3255. (should
  3256. (equal "* TODO a1\n** a2\n* b1\n"
  3257. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3258. (let ((org-loop-over-headlines-in-active-region 'start-level))
  3259. (transient-mark-mode 1)
  3260. (push-mark (point) t t)
  3261. (search-forward "* DONE b1")
  3262. (org-shiftright))
  3263. (buffer-string))))))
  3264. (ert-deftest test-org/beginning-of-line ()
  3265. "Test `org-beginning-of-line' specifications."
  3266. ;; Move to beginning of line. If current line in invisible, move to
  3267. ;; beginning of visible line instead.
  3268. (should
  3269. (org-test-with-temp-text "Some text\nSome other text<point>"
  3270. (org-beginning-of-line)
  3271. (bolp)))
  3272. (should
  3273. (org-test-with-temp-text "* H1\n** H2<point>"
  3274. (org-overview)
  3275. (org-beginning-of-line)
  3276. (= (line-beginning-position) 1)))
  3277. ;; With `visual-line-mode' active, move to beginning of visual line.
  3278. (should-not
  3279. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3280. (visual-line-mode)
  3281. (dotimes (i 1000) (insert "very "))
  3282. (org-beginning-of-line)
  3283. (bolp)))
  3284. ;; In a wide headline, with `visual-line-mode', prefer going to the
  3285. ;; beginning of a visual line than to the logical beginning of line,
  3286. ;; even if special movement is active.
  3287. (should-not
  3288. (org-test-with-temp-text "* A <point>long headline"
  3289. (visual-line-mode)
  3290. (dotimes (i 1000) (insert "very "))
  3291. (goto-char (point-max))
  3292. (org-beginning-of-line)
  3293. (bobp)))
  3294. (should-not
  3295. (org-test-with-temp-text "* A <point>long headline"
  3296. (visual-line-mode)
  3297. (dotimes (i 1000) (insert "very "))
  3298. (goto-char (point-max))
  3299. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line))
  3300. (bobp)))
  3301. ;; At an headline with special movement, first move at beginning of
  3302. ;; title, then at the beginning of line, rinse, repeat.
  3303. (should
  3304. (org-test-with-temp-text "* TODO Headline<point>"
  3305. (let ((org-special-ctrl-a/e t))
  3306. (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
  3307. (progn (org-beginning-of-line) (bolp))
  3308. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3309. (should
  3310. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3311. (let ((org-special-ctrl-a/e t))
  3312. (org-beginning-of-line)
  3313. (looking-at "Headline"))))
  3314. (should
  3315. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3316. (let ((org-special-ctrl-a/e '(t . nil)))
  3317. (org-beginning-of-line)
  3318. (looking-at "Headline"))))
  3319. (should-not
  3320. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3321. (let ((org-special-ctrl-a/e '(nil . nil)))
  3322. (org-beginning-of-line)
  3323. (looking-at "Headline"))))
  3324. ;; At an headline with reversed movement, first move to beginning of
  3325. ;; line, then to the beginning of title.
  3326. (should
  3327. (org-test-with-temp-text "* TODO Headline<point>"
  3328. (let ((org-special-ctrl-a/e 'reversed)
  3329. (this-command last-command))
  3330. (and (progn (org-beginning-of-line) (bolp))
  3331. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3332. (should
  3333. (org-test-with-temp-text "* TODO Headline<point>"
  3334. (let ((org-special-ctrl-a/e '(reversed . nil))
  3335. (this-command last-command))
  3336. (and (progn (org-beginning-of-line) (bolp))
  3337. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3338. (should-not
  3339. (org-test-with-temp-text "* TODO Headline<point>"
  3340. (let ((org-special-ctrl-a/e '(t . nil))
  3341. (this-command last-command))
  3342. (and (progn (org-beginning-of-line) (bolp))
  3343. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3344. ;; At an item with special movement, first move after to beginning
  3345. ;; of title, then to the beginning of line, rinse, repeat.
  3346. (should
  3347. (org-test-with-temp-text "- [ ] Item<point>"
  3348. (let ((org-special-ctrl-a/e t))
  3349. (and (progn (org-beginning-of-line) (looking-at-p "Item"))
  3350. (progn (org-beginning-of-line) (bolp))
  3351. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3352. ;; At an item with reversed movement, first move to beginning of
  3353. ;; line, then to the beginning of title.
  3354. (should
  3355. (org-test-with-temp-text "- [X] Item<point>"
  3356. (let ((org-special-ctrl-a/e 'reversed)
  3357. (this-command last-command))
  3358. (and (progn (org-beginning-of-line) (bolp))
  3359. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3360. ;; Leave point before invisible characters at column 0.
  3361. (should
  3362. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3363. (let ((org-special-ctrl-a/e nil))
  3364. (org-beginning-of-line)
  3365. (bolp))))
  3366. (should
  3367. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3368. (let ((org-special-ctrl-a/e t))
  3369. (org-beginning-of-line)
  3370. (bolp))))
  3371. (should
  3372. (org-test-with-temp-text "[[http<point>://orgmode.org]]"
  3373. (visual-line-mode)
  3374. (org-beginning-of-line)
  3375. (bolp)))
  3376. ;; Special case: Do not error when the buffer contains only a single
  3377. ;; asterisk.
  3378. (should
  3379. (org-test-with-temp-text "*<point>"
  3380. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line) t)))
  3381. (should
  3382. (org-test-with-temp-text "*<point>"
  3383. (let ((org-special-ctrl-a/e nil)) (org-beginning-of-line) t))))
  3384. (ert-deftest test-org/end-of-line ()
  3385. "Test `org-end-of-line' specifications."
  3386. ;; Standard test.
  3387. (should
  3388. (org-test-with-temp-text "Some text\nSome other text"
  3389. (org-end-of-line)
  3390. (eolp)))
  3391. ;; With `visual-line-mode' active, move to end of visible line.
  3392. ;; However, never go past ellipsis.
  3393. (should-not
  3394. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3395. (visual-line-mode)
  3396. (dotimes (i 1000) (insert "very "))
  3397. (goto-char (point-min))
  3398. (org-end-of-line)
  3399. (eolp)))
  3400. (should-not
  3401. (org-test-with-temp-text "* A short headline\nSome contents"
  3402. (visual-line-mode)
  3403. (org-overview)
  3404. (org-end-of-line)
  3405. (eobp)))
  3406. ;; In a wide headline, with `visual-line-mode', prefer going to end
  3407. ;; of visible line if tags, or end of line, are farther.
  3408. (should-not
  3409. (org-test-with-temp-text "* A <point>long headline"
  3410. (visual-line-mode)
  3411. (dotimes (i 1000) (insert "very "))
  3412. (goto-char (point-min))
  3413. (org-end-of-line)
  3414. (eolp)))
  3415. (should-not
  3416. (org-test-with-temp-text "* A <point>long headline :tag:"
  3417. (visual-line-mode)
  3418. (dotimes (i 1000) (insert "very "))
  3419. (goto-char (point-min))
  3420. (org-end-of-line)
  3421. (eolp)))
  3422. ;; At an headline without special movement, go to end of line.
  3423. ;; However, never go past ellipsis.
  3424. (should
  3425. (org-test-with-temp-text "* Headline2b :tag:\n"
  3426. (let ((org-special-ctrl-a/e nil))
  3427. (and (progn (org-end-of-line) (eolp))
  3428. (progn (org-end-of-line) (eolp))))))
  3429. (should
  3430. (org-test-with-temp-text "* Headline2b :tag:\n"
  3431. (let ((org-special-ctrl-a/e '(t . nil)))
  3432. (and (progn (org-end-of-line) (eolp))
  3433. (progn (org-end-of-line) (eolp))))))
  3434. (should
  3435. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3436. (org-overview)
  3437. (let ((org-special-ctrl-a/e nil))
  3438. (org-end-of-line)
  3439. (= 1 (line-beginning-position)))))
  3440. ;; At an headline with special movement, first move before tags,
  3441. ;; then at the end of line, rinse, repeat. However, never go past
  3442. ;; ellipsis.
  3443. (should
  3444. (org-test-with-temp-text "* Headline1 :tag:\n"
  3445. (let ((org-special-ctrl-a/e t))
  3446. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3447. (progn (org-end-of-line) (eolp))
  3448. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3449. (should
  3450. (org-test-with-temp-text "* Headline1 :tag:\n"
  3451. (let ((org-special-ctrl-a/e '(nil . t)))
  3452. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3453. (progn (org-end-of-line) (eolp))
  3454. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3455. (should-not
  3456. (org-test-with-temp-text "* Headline1 :tag:\n"
  3457. (let ((org-special-ctrl-a/e '(nil . nil)))
  3458. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3459. (progn (org-end-of-line) (eolp))
  3460. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3461. (should
  3462. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3463. (org-overview)
  3464. (let ((org-special-ctrl-a/e t))
  3465. (org-end-of-line)
  3466. (org-end-of-line)
  3467. (= 1 (line-beginning-position)))))
  3468. ;; At an headline, with reversed movement, first go to end of line,
  3469. ;; then before tags. However, never go past ellipsis.
  3470. (should
  3471. (org-test-with-temp-text "* Headline3 :tag:\n"
  3472. (let ((org-special-ctrl-a/e 'reversed)
  3473. (this-command last-command))
  3474. (and (progn (org-end-of-line) (eolp))
  3475. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3476. (should
  3477. (org-test-with-temp-text "* Headline3 :tag:\n"
  3478. (let ((org-special-ctrl-a/e '(nil . reversed))
  3479. (this-command last-command))
  3480. (and (progn (org-end-of-line) (eolp))
  3481. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3482. (should-not
  3483. (org-test-with-temp-text "* Headline3 :tag:\n"
  3484. (let ((org-special-ctrl-a/e '(nil . t))
  3485. (this-command last-command))
  3486. (and (progn (org-end-of-line) (eolp))
  3487. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3488. (should
  3489. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3490. (org-overview)
  3491. (let ((org-special-ctrl-a/e 'reversed))
  3492. (org-end-of-line)
  3493. (= 1 (line-beginning-position)))))
  3494. ;; At a block without hidden contents.
  3495. (should
  3496. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3497. (progn (org-end-of-line) (eolp))))
  3498. ;; At a block with hidden contents.
  3499. (should-not
  3500. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3501. (let ((org-special-ctrl-a/e t))
  3502. (org-hide-block-toggle)
  3503. (org-end-of-line)
  3504. (eobp))))
  3505. ;; Get past invisible characters at the end of line.
  3506. (should
  3507. (org-test-with-temp-text "[[https://orgmode.org]]"
  3508. (org-end-of-line)
  3509. (eolp))))
  3510. (ert-deftest test-org/open-line ()
  3511. "Test `org-open-line' specifications."
  3512. ;; Call `open-line' outside of tables.
  3513. (should
  3514. (equal "\nText"
  3515. (org-test-with-temp-text "Text"
  3516. (org-open-line 1)
  3517. (buffer-string))))
  3518. ;; At a table, create a row above.
  3519. (should
  3520. (equal "\n| |\n| a |"
  3521. (org-test-with-temp-text "\n<point>| a |"
  3522. (org-open-line 1)
  3523. (buffer-string))))
  3524. ;; At the very first character of the buffer, also call `open-line'.
  3525. (should
  3526. (equal "\n| a |"
  3527. (org-test-with-temp-text "| a |"
  3528. (org-open-line 1)
  3529. (buffer-string))))
  3530. ;; Narrowing does not count.
  3531. (should
  3532. (equal "Text\n| |\n| a |"
  3533. (org-test-with-temp-text "Text\n<point>| a |"
  3534. (narrow-to-region (point) (point-max))
  3535. (org-open-line 1)
  3536. (widen)
  3537. (buffer-string)))))
  3538. (ert-deftest test-org/forward-sentence ()
  3539. "Test `org-forward-sentence' specifications."
  3540. ;; At the end of a table cell, move to the end of the next one.
  3541. (should
  3542. (org-test-with-temp-text "| a<point> | b |"
  3543. (org-forward-sentence)
  3544. (looking-at " |$")))
  3545. ;; Elsewhere in a cell, move to its end.
  3546. (should
  3547. (org-test-with-temp-text "| a<point>c | b |"
  3548. (org-forward-sentence)
  3549. (looking-at " | b |$")))
  3550. ;; Otherwise, simply call `forward-sentence'.
  3551. (should
  3552. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3553. (org-forward-sentence)
  3554. (looking-at " Sentence 2.")))
  3555. (should
  3556. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3557. (org-forward-sentence)
  3558. (org-forward-sentence)
  3559. (eobp)))
  3560. ;; At the end of an element, jump to the next one, without stopping
  3561. ;; on blank lines in-between.
  3562. (should
  3563. (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
  3564. (org-forward-sentence)
  3565. (eobp)))
  3566. ;; Headlines are considered to be sentences by themselves, even if
  3567. ;; they do not end with a full stop.
  3568. (should
  3569. (equal
  3570. "* Headline"
  3571. (org-test-with-temp-text "* <point>Headline\nSentence."
  3572. (org-forward-sentence)
  3573. (buffer-substring-no-properties (line-beginning-position) (point)))))
  3574. (should
  3575. (org-test-with-temp-text "* Headline<point>\nSentence."
  3576. (org-forward-sentence)
  3577. (eobp)))
  3578. (should
  3579. (org-test-with-temp-text "Sentence.<point>\n\n* Headline\n\nSentence 2."
  3580. (org-forward-sentence)
  3581. (and (org-at-heading-p) (eolp)))))
  3582. (ert-deftest test-org/backward-sentence ()
  3583. "Test `org-backward-sentence' specifications."
  3584. ;; At the beginning of a table cell, move to the beginning of the
  3585. ;; previous one.
  3586. (should
  3587. (org-test-with-temp-text "| a | <point>b |"
  3588. (org-backward-sentence)
  3589. (looking-at "a | b |$")))
  3590. ;; Elsewhere in a cell, move to its beginning.
  3591. (should
  3592. (org-test-with-temp-text "| a | b<point>c |"
  3593. (org-backward-sentence)
  3594. (looking-at "bc |$")))
  3595. ;; Otherwise, simply call `backward-sentence'.
  3596. (should
  3597. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3598. (org-backward-sentence)
  3599. (looking-at "Sentence 2.")))
  3600. (should
  3601. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3602. (org-backward-sentence)
  3603. (org-backward-sentence)
  3604. (bobp)))
  3605. ;; Make sure to hit the beginning of a sentence on the same line as
  3606. ;; an item.
  3607. (should
  3608. (org-test-with-temp-text "- Line 1\n line <point>2."
  3609. (org-backward-sentence)
  3610. (looking-at "Line 1"))))
  3611. (ert-deftest test-org/forward-paragraph ()
  3612. "Test `org-forward-paragraph' specifications."
  3613. ;; At end of buffer, do not return an error.
  3614. (should
  3615. (org-test-with-temp-text "Paragraph"
  3616. (goto-char (point-max))
  3617. (org-forward-paragraph)
  3618. t))
  3619. ;; Standard test.
  3620. (should
  3621. (= 2
  3622. (org-test-with-temp-text "P1\n\nP2"
  3623. (org-forward-paragraph)
  3624. (org-current-line))))
  3625. (should
  3626. (= 2
  3627. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  3628. (org-forward-paragraph)
  3629. (org-current-line))))
  3630. ;; Enter greater elements.
  3631. (should
  3632. (= 2
  3633. (org-test-with-temp-text "#+begin_center\nP1\n#+end_center\nP2"
  3634. (org-forward-paragraph)
  3635. (org-current-line))))
  3636. ;; Do not enter elements with invisible contents.
  3637. (should
  3638. (= 4
  3639. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  3640. (org-cycle)
  3641. (org-forward-paragraph)
  3642. (org-current-line))))
  3643. (should
  3644. (= 6
  3645. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\nP3"
  3646. (org-hide-block-toggle)
  3647. (org-forward-paragraph)
  3648. (org-current-line))))
  3649. ;; On an item or a footnote definition, move past the first element
  3650. ;; inside, if any.
  3651. (should
  3652. (= 2
  3653. (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
  3654. (org-forward-paragraph)
  3655. (org-current-line))))
  3656. (should
  3657. (= 2
  3658. (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
  3659. (org-forward-paragraph)
  3660. (org-current-line))))
  3661. ;; On a table (resp. a property drawer) do not move through table
  3662. ;; rows (resp. node properties).
  3663. (should
  3664. (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
  3665. (org-forward-paragraph)
  3666. (looking-at "Paragraph")))
  3667. (should
  3668. (org-test-with-temp-text
  3669. "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
  3670. (org-forward-paragraph)
  3671. (looking-at "Paragraph")))
  3672. ;; Skip consecutive keywords, clocks and diary S-exps.
  3673. (should
  3674. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n"
  3675. (org-forward-paragraph)
  3676. (eobp)))
  3677. (should
  3678. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n"
  3679. (org-forward-paragraph)
  3680. (eobp)))
  3681. (should
  3682. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n"
  3683. (org-forward-paragraph)
  3684. (eobp)))
  3685. (should-not
  3686. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n"
  3687. (org-forward-paragraph)
  3688. (eobp)))
  3689. (should-not
  3690. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n"
  3691. (org-forward-paragraph)
  3692. (eobp)))
  3693. ;; In a plain list with one item every line, skip the whole list,
  3694. ;; even with point in the middle of the list.
  3695. (should
  3696. (org-test-with-temp-text "- A\n - B\n- C\n"
  3697. (org-forward-paragraph)
  3698. (eobp)))
  3699. (should
  3700. (org-test-with-temp-text "- A\n - <point>B\n- C\n"
  3701. (org-forward-paragraph)
  3702. (eobp)))
  3703. ;; On a comment, verse or source block, stop at "contents"
  3704. ;; boundaries and blank lines.
  3705. (should
  3706. (= 2
  3707. (org-test-with-temp-text "#+begin_src emacs-lisp\nL1\n\nL2\n#+end_src"
  3708. (org-forward-paragraph)
  3709. (org-current-line))))
  3710. (should
  3711. (= 3
  3712. (org-test-with-temp-text "#+begin_verse\n<point>L1\n\nL2\n#+end_verse"
  3713. (org-forward-paragraph)
  3714. (org-current-line))))
  3715. (should
  3716. (= 5
  3717. (org-test-with-temp-text "#+begin_comment\nL1\n\n<point>L2\n#+end_comment"
  3718. (org-forward-paragraph)
  3719. (org-current-line))))
  3720. ;; Being on an affiliated keyword shouldn't make any difference.
  3721. (should
  3722. (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
  3723. (org-forward-paragraph)
  3724. (eobp))))
  3725. (ert-deftest test-org/backward-paragraph ()
  3726. "Test `org-backward-paragraph' specifications."
  3727. ;; Do not error at beginning of buffer.
  3728. (should
  3729. (org-test-with-temp-text "Paragraph"
  3730. (org-backward-paragraph)
  3731. t))
  3732. ;; At blank lines at the very beginning of a buffer, move to
  3733. ;; point-min.
  3734. (should
  3735. (org-test-with-temp-text "\n\n<point>\n\nParagraph"
  3736. (org-backward-paragraph)
  3737. (bobp)))
  3738. ;; Regular test.
  3739. (should
  3740. (= 2
  3741. (org-test-with-temp-text "P1\n\nP2<point>"
  3742. (org-backward-paragraph)
  3743. (org-current-line))))
  3744. (should
  3745. (= 4
  3746. (org-test-with-temp-text "P1\n\nP2\n\nP3<point>"
  3747. (org-backward-paragraph)
  3748. (org-current-line))))
  3749. ;; Try to move on the line above current element.
  3750. (should
  3751. (= 2
  3752. (org-test-with-temp-text "\n\n<point>Paragraph"
  3753. (org-backward-paragraph)
  3754. (org-current-line))))
  3755. ;; Do not leave point in an invisible area.
  3756. (should
  3757. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  3758. (org-cycle)
  3759. (goto-char (point-max))
  3760. (beginning-of-line)
  3761. (org-backward-paragraph)
  3762. (bobp)))
  3763. (should
  3764. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\n"
  3765. (org-hide-block-toggle)
  3766. (goto-char (point-max))
  3767. (org-backward-paragraph)
  3768. (bobp)))
  3769. ;; On the first element in an item or a footnote definition, jump
  3770. ;; before the footnote or the item.
  3771. (should
  3772. (org-test-with-temp-text "- line1<point>"
  3773. (org-backward-paragraph)
  3774. (bobp)))
  3775. (should
  3776. (org-test-with-temp-text "[fn:1] line1n<point>"
  3777. (org-backward-paragraph)
  3778. (bobp)))
  3779. ;; On the second element in an item or a footnote definition, jump
  3780. ;; to item or the definition.
  3781. (should
  3782. (= 2
  3783. (org-test-with-temp-text "- line1\n\n<point> line2"
  3784. (org-backward-paragraph)
  3785. (org-current-line))))
  3786. (should
  3787. (= 2
  3788. (org-test-with-temp-text "[fn:1] line1\n\n<point> line2"
  3789. (org-backward-paragraph)
  3790. (org-current-line))))
  3791. ;; On a table (resp. a property drawer), ignore table rows
  3792. ;; (resp. node properties).
  3793. (should
  3794. (org-test-with-temp-text "| a | b |\n| c | d |\n<point>P1"
  3795. (org-backward-paragraph)
  3796. (bobp)))
  3797. (should
  3798. (= 2
  3799. (org-test-with-temp-text
  3800. "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
  3801. (org-backward-paragraph)
  3802. (org-current-line))))
  3803. ;; In a plain list with one item every line, skip the whole list,
  3804. ;; even with point in the middle of the list.
  3805. (should
  3806. (org-test-with-temp-text "- A\n - B\n- C\n<point>"
  3807. (org-backward-paragraph)
  3808. (bobp)))
  3809. (should
  3810. (org-test-with-temp-text "- A\n - B\n- <point>C\n"
  3811. (org-backward-paragraph)
  3812. (bobp)))
  3813. ;; Skip consecutive keywords, clocks and diary S-exps.
  3814. (should
  3815. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n<point>"
  3816. (org-backward-paragraph)
  3817. (bobp)))
  3818. (should
  3819. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n<point>"
  3820. (org-backward-paragraph)
  3821. (bobp)))
  3822. (should
  3823. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n<point>"
  3824. (org-backward-paragraph)
  3825. (bobp)))
  3826. (should-not
  3827. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n<point>"
  3828. (org-backward-paragraph)
  3829. (bobp)))
  3830. (should-not
  3831. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n<point>"
  3832. (org-backward-paragraph)
  3833. (bobp)))
  3834. ;; On a comment, example, source and verse blocks, stop at blank
  3835. ;; lines.
  3836. (should
  3837. (= 1
  3838. (org-test-with-temp-text
  3839. "#+begin_comment\n<point>L1\n\nL2\n\nL3\n#+end_comment"
  3840. (org-backward-paragraph)
  3841. (org-current-line))))
  3842. (should
  3843. (= 2
  3844. (org-test-with-temp-text
  3845. "#+begin_verse\nL1\n\n<point>L2\n\nL3\n#+end_verse"
  3846. (org-backward-paragraph)
  3847. (org-current-line))))
  3848. (should
  3849. (= 3
  3850. (org-test-with-temp-text
  3851. "#+begin_src emacs-lisp\nL1\n\nL2\n\n<point>L3\n#+end_src"
  3852. (org-backward-paragraph)
  3853. (org-current-line))))
  3854. ;; When called from the opening line itself, however, move to
  3855. ;; beginning of block.
  3856. (should
  3857. (org-test-with-temp-text "#+begin_<point>example\nL1\n#+end_example"
  3858. (org-backward-paragraph)
  3859. (bobp)))
  3860. ;; On an empty heading, move above it.
  3861. (should
  3862. (org-test-with-temp-text "\n* <point>"
  3863. (org-backward-paragraph)
  3864. (bobp)))
  3865. (should
  3866. (org-test-with-temp-text "\n* \n<point>"
  3867. (org-backward-paragraph)
  3868. (bobp))))
  3869. (ert-deftest test-org/forward-element ()
  3870. "Test `org-forward-element' specifications."
  3871. ;; 1. At EOB: should error.
  3872. (org-test-with-temp-text "Some text\n"
  3873. (goto-char (point-max))
  3874. (should-error (org-forward-element)))
  3875. ;; 2. Standard move: expected to ignore blank lines.
  3876. (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
  3877. (org-forward-element)
  3878. (should (looking-at (regexp-quote "Second paragraph."))))
  3879. ;; 3. Headline tests.
  3880. (org-test-with-temp-text "
  3881. * Head 1
  3882. ** Head 1.1
  3883. *** Head 1.1.1
  3884. ** Head 1.2"
  3885. ;; 3.1. At an headline beginning: move to next headline at the
  3886. ;; same level.
  3887. (goto-line 3)
  3888. (org-forward-element)
  3889. (should (looking-at (regexp-quote "** Head 1.2")))
  3890. ;; 3.2. At an headline beginning: move to parent headline if no
  3891. ;; headline at the same level.
  3892. (goto-line 3)
  3893. (org-forward-element)
  3894. (should (looking-at (regexp-quote "** Head 1.2"))))
  3895. ;; 4. Greater element tests.
  3896. (org-test-with-temp-text
  3897. "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
  3898. ;; 4.1. At a greater element: expected to skip contents.
  3899. (org-forward-element)
  3900. (should (looking-at (regexp-quote "Outside.")))
  3901. ;; 4.2. At the end of greater element contents: expected to skip
  3902. ;; to the end of the greater element.
  3903. (goto-line 2)
  3904. (org-forward-element)
  3905. (should (looking-at (regexp-quote "Outside."))))
  3906. ;; 5. List tests.
  3907. (org-test-with-temp-text "
  3908. - item1
  3909. - sub1
  3910. - sub2
  3911. - sub3
  3912. Inner paragraph.
  3913. - item2
  3914. Outside."
  3915. ;; 5.1. At list top point: expected to move to the element after
  3916. ;; the list.
  3917. (goto-line 2)
  3918. (org-forward-element)
  3919. (should (looking-at (regexp-quote "Outside.")))
  3920. ;; 5.2. Special case: at the first line of a sub-list, but not at
  3921. ;; beginning of line, move to next item.
  3922. (goto-line 2)
  3923. (forward-char)
  3924. (org-forward-element)
  3925. (should (looking-at "- item2"))
  3926. (goto-line 4)
  3927. (forward-char)
  3928. (org-forward-element)
  3929. (should (looking-at " - sub2"))
  3930. ;; 5.3 At sub-list beginning: expected to move after the sub-list.
  3931. (goto-line 4)
  3932. (org-forward-element)
  3933. (should (looking-at (regexp-quote " Inner paragraph.")))
  3934. ;; 5.4. At sub-list end: expected to move outside the sub-list.
  3935. (goto-line 8)
  3936. (org-forward-element)
  3937. (should (looking-at (regexp-quote " Inner paragraph.")))
  3938. ;; 5.5. At an item: expected to move to next item, if any.
  3939. (goto-line 6)
  3940. (org-forward-element)
  3941. (should (looking-at " - sub3"))))
  3942. (ert-deftest test-org/backward-element ()
  3943. "Test `org-backward-element' specifications."
  3944. ;; 1. Should error at BOB.
  3945. (org-test-with-temp-text " \nParagraph."
  3946. (should-error (org-backward-element)))
  3947. ;; 2. Should move at BOB when called on the first element in buffer.
  3948. (should
  3949. (org-test-with-temp-text "\n#+TITLE: test"
  3950. (progn (forward-line)
  3951. (org-backward-element)
  3952. (bobp))))
  3953. ;; 3. Not at the beginning of an element: move at its beginning.
  3954. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  3955. (goto-line 3)
  3956. (end-of-line)
  3957. (org-backward-element)
  3958. (should (looking-at (regexp-quote "Paragraph2."))))
  3959. ;; 4. Headline tests.
  3960. (org-test-with-temp-text "
  3961. * Head 1
  3962. ** Head 1.1
  3963. *** Head 1.1.1
  3964. ** Head 1.2"
  3965. ;; 4.1. At an headline beginning: move to previous headline at the
  3966. ;; same level.
  3967. (goto-line 5)
  3968. (org-backward-element)
  3969. (should (looking-at (regexp-quote "** Head 1.1")))
  3970. ;; 4.2. At an headline beginning: move to parent headline if no
  3971. ;; headline at the same level.
  3972. (goto-line 3)
  3973. (org-backward-element)
  3974. (should (looking-at (regexp-quote "* Head 1")))
  3975. ;; 4.3. At the first top-level headline: should error.
  3976. (goto-line 2)
  3977. (should-error (org-backward-element)))
  3978. ;; 5. At beginning of first element inside a greater element:
  3979. ;; expected to move to greater element's beginning.
  3980. (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
  3981. (goto-line 3)
  3982. (org-backward-element)
  3983. (should (looking-at "#\\+BEGIN_CENTER")))
  3984. ;; 6. At the beginning of the first element in a section: should
  3985. ;; move back to headline, if any.
  3986. (should
  3987. (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
  3988. (progn (goto-char (point-max))
  3989. (beginning-of-line)
  3990. (org-backward-element)
  3991. (org-at-heading-p))))
  3992. ;; 7. List tests.
  3993. (org-test-with-temp-text "
  3994. - item1
  3995. - sub1
  3996. - sub2
  3997. - sub3
  3998. Inner paragraph.
  3999. - item2
  4000. Outside."
  4001. ;; 7.1. At beginning of sub-list: expected to move to the
  4002. ;; paragraph before it.
  4003. (goto-line 4)
  4004. (org-backward-element)
  4005. (should (looking-at "item1"))
  4006. ;; 7.2. At an item in a list: expected to move at previous item.
  4007. (goto-line 8)
  4008. (org-backward-element)
  4009. (should (looking-at " - sub2"))
  4010. (goto-line 12)
  4011. (org-backward-element)
  4012. (should (looking-at "- item1"))
  4013. ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
  4014. ;; beginning.
  4015. (goto-line 10)
  4016. (org-backward-element)
  4017. (should (looking-at " - sub1"))
  4018. (goto-line 15)
  4019. (org-backward-element)
  4020. (should (looking-at "- item1"))
  4021. ;; 7.4. At blank-lines before list end: expected to move to top
  4022. ;; item.
  4023. (goto-line 14)
  4024. (org-backward-element)
  4025. (should (looking-at "- item1"))))
  4026. (ert-deftest test-org/up-element ()
  4027. "Test `org-up-element' specifications."
  4028. ;; 1. At BOB or with no surrounding element: should error.
  4029. (org-test-with-temp-text "Paragraph."
  4030. (should-error (org-up-element)))
  4031. (org-test-with-temp-text "* Head1\n* Head2"
  4032. (goto-line 2)
  4033. (should-error (org-up-element)))
  4034. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  4035. (goto-line 3)
  4036. (should-error (org-up-element)))
  4037. ;; 2. At an headline: move to parent headline.
  4038. (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
  4039. (goto-line 3)
  4040. (org-up-element)
  4041. (should (looking-at "\\* Head1")))
  4042. ;; 3. Inside a greater element: move to greater element beginning.
  4043. (org-test-with-temp-text
  4044. "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
  4045. (goto-line 3)
  4046. (org-up-element)
  4047. (should (looking-at "#\\+BEGIN_CENTER")))
  4048. ;; 4. List tests.
  4049. (org-test-with-temp-text "* Top
  4050. - item1
  4051. - sub1
  4052. - sub2
  4053. Paragraph within sub2.
  4054. - item2"
  4055. ;; 4.1. Within an item: move to the item beginning.
  4056. (goto-line 8)
  4057. (org-up-element)
  4058. (should (looking-at " - sub2"))
  4059. ;; 4.2. At an item in a sub-list: move to parent item.
  4060. (goto-line 4)
  4061. (org-up-element)
  4062. (should (looking-at "- item1"))
  4063. ;; 4.3. At an item in top list: move to beginning of whole list.
  4064. (goto-line 10)
  4065. (org-up-element)
  4066. (should (looking-at "- item1"))
  4067. ;; 4.4. Special case. At very top point: should move to parent of
  4068. ;; list.
  4069. (goto-line 2)
  4070. (org-up-element)
  4071. (should (looking-at "\\* Top"))))
  4072. (ert-deftest test-org/down-element ()
  4073. "Test `org-down-element' specifications."
  4074. ;; Error when the element hasn't got a recursive type.
  4075. (org-test-with-temp-text "Paragraph."
  4076. (should-error (org-down-element)))
  4077. ;; Error when the element has no contents
  4078. (org-test-with-temp-text "* Headline"
  4079. (should-error (org-down-element)))
  4080. ;; When at a plain-list, move to first item.
  4081. (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
  4082. (goto-line 2)
  4083. (org-down-element)
  4084. (should (looking-at " - Item 1.1")))
  4085. (org-test-with-temp-text "#+NAME: list\n- Item 1"
  4086. (org-down-element)
  4087. (should (looking-at " Item 1")))
  4088. ;; When at a table, move to first row
  4089. (org-test-with-temp-text "#+NAME: table\n| a | b |"
  4090. (org-down-element)
  4091. (should (looking-at " a | b |")))
  4092. ;; Otherwise, move inside the greater element.
  4093. (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
  4094. (org-down-element)
  4095. (should (looking-at "Paragraph"))))
  4096. (ert-deftest test-org/drag-element-backward ()
  4097. "Test `org-drag-element-backward' specifications."
  4098. ;; Standard test.
  4099. (should
  4100. (equal
  4101. "#+key2: val2\n#+key1: val1\n#+key3: val3"
  4102. (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
  4103. (org-drag-element-backward)
  4104. (buffer-string))))
  4105. (should
  4106. (equal
  4107. "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
  4108. (org-test-with-temp-text
  4109. "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
  4110. (org-drag-element-backward)
  4111. (buffer-string))))
  4112. ;; Preserve blank lines.
  4113. (should
  4114. (equal "Paragraph 2\n\n\nPara1\n\nPara3"
  4115. (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
  4116. (org-drag-element-backward)
  4117. (buffer-string))))
  4118. ;; Preserve column.
  4119. (should
  4120. (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
  4121. (org-drag-element-backward)
  4122. (looking-at-p "2")))
  4123. ;; Error when trying to move first element of buffer.
  4124. (should-error
  4125. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4126. (org-drag-element-backward))
  4127. :type 'user-error)
  4128. ;; Error when trying to swap nested elements.
  4129. (should-error
  4130. (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
  4131. (org-drag-element-backward))
  4132. :type 'user-error)
  4133. ;; Error when trying to swap an headline element and a non-headline
  4134. ;; element.
  4135. (should-error
  4136. (org-test-with-temp-text "Test.\n<point>* Head 1"
  4137. (org-drag-element-backward))
  4138. :type 'error)
  4139. ;; Error when called before first element.
  4140. (should-error
  4141. (org-test-with-temp-text "\n<point>"
  4142. (org-drag-element-backward))
  4143. :type 'user-error)
  4144. ;; Preserve visibility of elements and their contents.
  4145. (should
  4146. (equal '((63 . 82) (26 . 48))
  4147. (org-test-with-temp-text "
  4148. #+BEGIN_CENTER
  4149. Text.
  4150. #+END_CENTER
  4151. - item 1
  4152. #+BEGIN_QUOTE
  4153. Text.
  4154. #+END_QUOTE"
  4155. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4156. (search-backward "- item 1")
  4157. (org-drag-element-backward)
  4158. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4159. (overlays-in (point-min) (point-max))))))
  4160. ;; Pathological case: handle call with point in blank lines right
  4161. ;; after a headline.
  4162. (should
  4163. (equal "* H2\n\n* H1\nText\n"
  4164. (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
  4165. (org-drag-element-backward)
  4166. (buffer-string)))))
  4167. (ert-deftest test-org/drag-element-forward ()
  4168. "Test `org-drag-element-forward' specifications."
  4169. ;; 1. Error when trying to move first element of buffer.
  4170. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4171. (goto-line 3)
  4172. (should-error (org-drag-element-forward)))
  4173. ;; 2. Error when trying to swap nested elements.
  4174. (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
  4175. (forward-line)
  4176. (should-error (org-drag-element-forward)))
  4177. ;; 3. Error when trying to swap a non-headline element and an
  4178. ;; headline.
  4179. (org-test-with-temp-text "Test.\n* Head 1"
  4180. (should-error (org-drag-element-forward)))
  4181. ;; 4. Error when called before first element.
  4182. (should-error
  4183. (org-test-with-temp-text "\n"
  4184. (forward-line)
  4185. (org-drag-element-backward))
  4186. :type 'user-error)
  4187. ;; 5. Otherwise, swap elements, preserving column and blank lines
  4188. ;; between elements.
  4189. (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
  4190. (search-forward "graph")
  4191. (org-drag-element-forward)
  4192. (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
  4193. (should (looking-at " 1")))
  4194. ;; 5. Preserve visibility of elements and their contents.
  4195. (org-test-with-temp-text "
  4196. #+BEGIN_CENTER
  4197. Text.
  4198. #+END_CENTER
  4199. - item 1
  4200. #+BEGIN_QUOTE
  4201. Text.
  4202. #+END_QUOTE"
  4203. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4204. (search-backward "#+BEGIN_CENTER")
  4205. (org-drag-element-forward)
  4206. (should
  4207. (equal
  4208. '((63 . 82) (26 . 48))
  4209. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4210. (overlays-in (point-min) (point-max)))))))
  4211. (ert-deftest test-org/next-block ()
  4212. "Test `org-next-block' specifications."
  4213. ;; Regular test.
  4214. (should
  4215. (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  4216. (org-next-block 1)
  4217. (looking-at "#\\+BEGIN_CENTER")))
  4218. ;; Ignore case.
  4219. (should
  4220. (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
  4221. (let ((case-fold-search nil))
  4222. (org-next-block 1)
  4223. (looking-at "#\\+begin_center"))))
  4224. ;; Ignore current line.
  4225. (should
  4226. (org-test-with-temp-text
  4227. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
  4228. (org-next-block 1)
  4229. (looking-at "#\\+BEGIN_CENTER")))
  4230. ;; Throw an error when no block is found.
  4231. (should-error
  4232. (org-test-with-temp-text "Paragraph"
  4233. (org-next-block 1)))
  4234. ;; With an argument, skip many blocks at once.
  4235. (should
  4236. (org-test-with-temp-text
  4237. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4238. (org-next-block 2)
  4239. (looking-at "#\\+BEGIN_QUOTE")))
  4240. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4241. (should
  4242. (org-test-with-temp-text
  4243. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4244. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4245. (looking-at "#\\+BEGIN_QUOTE")))
  4246. ;; Optional argument is also case-insensitive.
  4247. (should
  4248. (org-test-with-temp-text
  4249. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
  4250. (let ((case-fold-search nil))
  4251. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4252. (looking-at "#\\+begin_quote")))))
  4253. (ert-deftest test-org/insert-structure-template ()
  4254. "Test `org-insert-structure-template'."
  4255. ;; Test in empty buffer.
  4256. (should
  4257. (string= "#+begin_foo\n#+end_foo\n"
  4258. (org-test-with-temp-text ""
  4259. (org-insert-structure-template "foo")
  4260. (buffer-string))))
  4261. ;; Test with multiple lines in buffer.
  4262. (should
  4263. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4264. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4265. (transient-mark-mode 1)
  4266. (org-mark-element)
  4267. (org-insert-structure-template "foo")
  4268. (buffer-string))))
  4269. ;; Mark only the current line.
  4270. (should
  4271. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4272. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4273. (transient-mark-mode 1)
  4274. (set-mark (point-min))
  4275. (end-of-line)
  4276. (org-insert-structure-template "foo")
  4277. (buffer-string))))
  4278. ;; Middle of paragraph.
  4279. (should
  4280. (string= "p1\n#+begin_foo\np2\n#+end_foo\np3"
  4281. (org-test-with-temp-text "p1\n<point>p2\np3"
  4282. (set-mark (line-beginning-position))
  4283. (end-of-line)
  4284. (activate-mark)
  4285. (org-insert-structure-template "foo")
  4286. (buffer-string))))
  4287. ;; Test with text in buffer, no region, no final newline.
  4288. (should
  4289. (string= "#+begin_foo\nI'm a paragraph.\n#+end_foo\n"
  4290. (org-test-with-temp-text "I'm a paragraph."
  4291. (org-mark-element)
  4292. (org-insert-structure-template "foo")
  4293. (buffer-string))))
  4294. ;; Test with text in buffer and region set.
  4295. (should
  4296. (string= "#+begin_foo\nI'm a paragraph\n\nI'm a second paragrah\n#+end_foo\n"
  4297. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragrah"
  4298. (set-mark (point))
  4299. (goto-char (point-max))
  4300. (org-insert-structure-template "foo")
  4301. (buffer-string))))
  4302. ;; Test with example escaping.
  4303. (should
  4304. (string= "#+begin_example\n,* Heading\n#+end_example\n"
  4305. (org-test-with-temp-text "* Heading"
  4306. (org-mark-element)
  4307. (org-insert-structure-template "example")
  4308. (buffer-string))))
  4309. ;; Test with indentation.
  4310. (should
  4311. (string= " #+begin_foo\n This is a paragraph\n #+end_foo\n"
  4312. (org-test-with-temp-text " This is a paragraph"
  4313. (org-mark-element)
  4314. (org-insert-structure-template "foo")
  4315. (buffer-string))))
  4316. (should
  4317. (string= " #+begin_foo\n Line 1\n Line2\n #+end_foo\n"
  4318. (org-test-with-temp-text " Line 1\n Line2"
  4319. (org-mark-element)
  4320. (org-insert-structure-template "foo")
  4321. (buffer-string))))
  4322. ;; Test point location.
  4323. (should
  4324. (string= "#+begin_foo\n"
  4325. (org-test-with-temp-text ""
  4326. (org-insert-structure-template "foo")
  4327. (buffer-substring (point-min) (point)))))
  4328. (should
  4329. (string= "#+begin_src "
  4330. (org-test-with-temp-text ""
  4331. (org-insert-structure-template "src")
  4332. (buffer-substring (point-min) (point))))))
  4333. (ert-deftest test-org/previous-block ()
  4334. "Test `org-previous-block' specifications."
  4335. ;; Regular test.
  4336. (should
  4337. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
  4338. (org-previous-block 1)
  4339. (looking-at "#\\+BEGIN_CENTER")))
  4340. ;; Ignore case.
  4341. (should
  4342. (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
  4343. (let ((case-fold-search nil))
  4344. (org-previous-block 1)
  4345. (looking-at "#\\+begin_center"))))
  4346. ;; Ignore current line.
  4347. (should
  4348. (org-test-with-temp-text
  4349. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
  4350. (org-previous-block 1)
  4351. (looking-at "#\\+BEGIN_QUOTE")))
  4352. ;; Throw an error when no block is found.
  4353. (should-error
  4354. (org-test-with-temp-text "Paragraph<point>"
  4355. (org-previous-block 1)))
  4356. ;; With an argument, skip many blocks at once.
  4357. (should
  4358. (org-test-with-temp-text
  4359. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4360. (org-previous-block 2)
  4361. (looking-at "#\\+BEGIN_CENTER")))
  4362. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4363. (should
  4364. (org-test-with-temp-text
  4365. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4366. (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4367. (looking-at "#\\+BEGIN_QUOTE")))
  4368. ;; Optional argument is also case-insensitive.
  4369. (should
  4370. (org-test-with-temp-text
  4371. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
  4372. (let ((case-fold-search nil))
  4373. (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4374. (looking-at "#\\+begin_quote")))))
  4375. ;;; Outline structure
  4376. (ert-deftest test-org/demote ()
  4377. "Test `org-demote' specifications."
  4378. ;; Add correct number of stars according to `org-odd-levels-only'.
  4379. (should
  4380. (= 2
  4381. (org-test-with-temp-text "* H"
  4382. (let ((org-odd-levels-only nil)) (org-demote))
  4383. (org-current-level))))
  4384. (should
  4385. (= 3
  4386. (org-test-with-temp-text "* H"
  4387. (let ((org-odd-levels-only t)) (org-demote))
  4388. (org-current-level))))
  4389. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4390. (should
  4391. (org-test-with-temp-text "* H :tag:"
  4392. (let ((org-tags-column 10)
  4393. (org-auto-align-tags t)
  4394. (org-odd-levels-only nil))
  4395. (org-demote))
  4396. (org-move-to-column 10)
  4397. (looking-at-p ":tag:$")))
  4398. (should-not
  4399. (org-test-with-temp-text "* H :tag:"
  4400. (let ((org-tags-column 10)
  4401. (org-auto-align-tags nil)
  4402. (org-odd-levels-only nil))
  4403. (org-demote))
  4404. (org-move-to-column 10)
  4405. (looking-at-p ":tag:$")))
  4406. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4407. ;; info and property drawers accordingly.
  4408. (should
  4409. (= 3
  4410. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4411. (let ((org-odd-levels-only nil)
  4412. (org-adapt-indentation t))
  4413. (org-demote))
  4414. (forward-line)
  4415. (org-get-indentation))))
  4416. (should
  4417. (= 3
  4418. (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4419. (let ((org-odd-levels-only nil)
  4420. (org-adapt-indentation t))
  4421. (org-demote))
  4422. (forward-line)
  4423. (org-get-indentation))))
  4424. (should-not
  4425. (= 3
  4426. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4427. (let ((org-odd-levels-only nil)
  4428. (org-adapt-indentation nil))
  4429. (org-demote))
  4430. (forward-line)
  4431. (org-get-indentation))))
  4432. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4433. ;; section accordingly. Ignore, however, footnote definitions and
  4434. ;; inlinetasks boundaries.
  4435. (should
  4436. (= 3
  4437. (org-test-with-temp-text "* H\n Paragraph"
  4438. (let ((org-odd-levels-only nil)
  4439. (org-adapt-indentation t))
  4440. (org-demote))
  4441. (forward-line)
  4442. (org-get-indentation))))
  4443. (should
  4444. (= 2
  4445. (org-test-with-temp-text "* H\n Paragraph"
  4446. (let ((org-odd-levels-only nil)
  4447. (org-adapt-indentation nil))
  4448. (org-demote))
  4449. (forward-line)
  4450. (org-get-indentation))))
  4451. (should
  4452. (zerop
  4453. (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
  4454. (let ((org-odd-levels-only nil)
  4455. (org-adapt-indentation t))
  4456. (org-demote))
  4457. (goto-char (point-max))
  4458. (org-get-indentation))))
  4459. (should
  4460. (= 3
  4461. (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
  4462. (let ((org-odd-levels-only nil)
  4463. (org-adapt-indentation t))
  4464. (org-demote))
  4465. (goto-char (point-max))
  4466. (org-get-indentation))))
  4467. (when (featurep 'org-inlinetask)
  4468. (should
  4469. (zerop
  4470. (let ((org-inlinetask-min-level 5)
  4471. (org-adapt-indentation t))
  4472. (org-test-with-temp-text "* H\n***** I\n***** END"
  4473. (org-demote)
  4474. (forward-line)
  4475. (org-get-indentation))))))
  4476. (when (featurep 'org-inlinetask)
  4477. (should
  4478. (= 3
  4479. (let ((org-inlinetask-min-level 5)
  4480. (org-adapt-indentation t))
  4481. (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
  4482. (org-demote)
  4483. (forward-line 2)
  4484. (org-get-indentation))))))
  4485. ;; Ignore contents of source blocks or example blocks when
  4486. ;; indentation should be preserved (through
  4487. ;; `org-src-preserve-indentation' or "-i" flag).
  4488. (should-not
  4489. (zerop
  4490. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4491. (let ((org-adapt-indentation t)
  4492. (org-src-preserve-indentation nil))
  4493. (org-demote))
  4494. (forward-line 2)
  4495. (org-get-indentation))))
  4496. (should
  4497. (zerop
  4498. (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
  4499. (let ((org-adapt-indentation t)
  4500. (org-src-preserve-indentation t))
  4501. (org-demote))
  4502. (forward-line 2)
  4503. (org-get-indentation))))
  4504. (should
  4505. (zerop
  4506. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4507. (let ((org-adapt-indentation t)
  4508. (org-src-preserve-indentation t))
  4509. (org-demote))
  4510. (forward-line 2)
  4511. (org-get-indentation))))
  4512. (should
  4513. (zerop
  4514. (org-test-with-temp-text
  4515. "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
  4516. (let ((org-adapt-indentation t)
  4517. (org-src-preserve-indentation nil))
  4518. (org-demote))
  4519. (forward-line 2)
  4520. (org-get-indentation)))))
  4521. (ert-deftest test-org/promote ()
  4522. "Test `org-promote' specifications."
  4523. ;; Return an error if headline is to be promoted to level 0, unless
  4524. ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
  4525. ;; headline becomes a comment.
  4526. (should-error
  4527. (org-test-with-temp-text "* H"
  4528. (let ((org-allow-promoting-top-level-subtree nil)) (org-promote))))
  4529. (should
  4530. (equal "# H"
  4531. (org-test-with-temp-text "* H"
  4532. (let ((org-allow-promoting-top-level-subtree t)) (org-promote))
  4533. (buffer-string))))
  4534. ;; Remove correct number of stars according to
  4535. ;; `org-odd-levels-only'.
  4536. (should
  4537. (= 2
  4538. (org-test-with-temp-text "*** H"
  4539. (let ((org-odd-levels-only nil)) (org-promote))
  4540. (org-current-level))))
  4541. (should
  4542. (= 1
  4543. (org-test-with-temp-text "*** H"
  4544. (let ((org-odd-levels-only t)) (org-promote))
  4545. (org-current-level))))
  4546. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4547. (should
  4548. (org-test-with-temp-text "** H :tag:"
  4549. (let ((org-tags-column 10)
  4550. (org-auto-align-tags t)
  4551. (org-odd-levels-only nil))
  4552. (org-promote))
  4553. (org-move-to-column 10)
  4554. (looking-at-p ":tag:$")))
  4555. (should-not
  4556. (org-test-with-temp-text "** H :tag:"
  4557. (let ((org-tags-column 10)
  4558. (org-auto-align-tags nil)
  4559. (org-odd-levels-only nil))
  4560. (org-promote))
  4561. (org-move-to-column 10)
  4562. (looking-at-p ":tag:$")))
  4563. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4564. ;; info and property drawers.
  4565. (should
  4566. (= 2
  4567. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4568. (let ((org-odd-levels-only nil)
  4569. (org-adapt-indentation t))
  4570. (org-promote))
  4571. (forward-line)
  4572. (org-get-indentation))))
  4573. (should
  4574. (= 2
  4575. (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4576. (let ((org-odd-levels-only nil)
  4577. (org-adapt-indentation t))
  4578. (org-promote))
  4579. (forward-line)
  4580. (org-get-indentation))))
  4581. (should-not
  4582. (= 2
  4583. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4584. (let ((org-odd-levels-only nil)
  4585. (org-adapt-indentation nil))
  4586. (org-promote))
  4587. (forward-line)
  4588. (org-get-indentation))))
  4589. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4590. ;; section accordingly. Ignore, however, footnote definitions and
  4591. ;; inlinetasks boundaries.
  4592. (should
  4593. (= 2
  4594. (org-test-with-temp-text "** H\n Paragraph"
  4595. (let ((org-odd-levels-only nil)
  4596. (org-adapt-indentation t))
  4597. (org-promote))
  4598. (forward-line)
  4599. (org-get-indentation))))
  4600. (should-not
  4601. (= 2
  4602. (org-test-with-temp-text "** H\n Paragraph"
  4603. (let ((org-odd-levels-only nil)
  4604. (org-adapt-indentation nil))
  4605. (org-promote))
  4606. (forward-line)
  4607. (org-get-indentation))))
  4608. (should
  4609. (= 2
  4610. (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
  4611. (let ((org-odd-levels-only nil)
  4612. (org-adapt-indentation t))
  4613. (org-promote))
  4614. (forward-line)
  4615. (org-get-indentation))))
  4616. (when (featurep 'org-inlinetask)
  4617. (should
  4618. (zerop
  4619. (let ((org-inlinetask-min-level 5)
  4620. (org-adapt-indentation t))
  4621. (org-test-with-temp-text "** H\n***** I\n***** END"
  4622. (org-promote)
  4623. (forward-line)
  4624. (org-get-indentation))))))
  4625. (when (featurep 'org-inlinetask)
  4626. (should
  4627. (= 2
  4628. (let ((org-inlinetask-min-level 5)
  4629. (org-adapt-indentation t))
  4630. (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
  4631. (org-promote)
  4632. (forward-line 2)
  4633. (org-get-indentation))))))
  4634. ;; Give up shifting if it would break document's structure
  4635. ;; otherwise.
  4636. (should
  4637. (= 3
  4638. (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
  4639. (let ((org-odd-levels-only nil)
  4640. (org-adapt-indentation t))
  4641. (org-promote))
  4642. (forward-line)
  4643. (org-get-indentation))))
  4644. (should
  4645. (= 3
  4646. (org-test-with-temp-text "** H\n Paragraph\n * list."
  4647. (let ((org-odd-levels-only nil)
  4648. (org-adapt-indentation t))
  4649. (org-promote))
  4650. (forward-line)
  4651. (org-get-indentation))))
  4652. ;; Ignore contents of source blocks or example blocks when
  4653. ;; indentation should be preserved (through
  4654. ;; `org-src-preserve-indentation' or "-i" flag).
  4655. (should-not
  4656. (zerop
  4657. (org-test-with-temp-text
  4658. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  4659. (let ((org-adapt-indentation t)
  4660. (org-src-preserve-indentation nil)
  4661. (org-odd-levels-only nil))
  4662. (org-promote))
  4663. (forward-line)
  4664. (org-get-indentation))))
  4665. (should
  4666. (zerop
  4667. (org-test-with-temp-text
  4668. "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
  4669. (let ((org-adapt-indentation t)
  4670. (org-src-preserve-indentation t)
  4671. (org-odd-levels-only nil))
  4672. (org-promote))
  4673. (forward-line)
  4674. (org-get-indentation))))
  4675. (should
  4676. (zerop
  4677. (org-test-with-temp-text
  4678. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  4679. (let ((org-adapt-indentation t)
  4680. (org-src-preserve-indentation t)
  4681. (org-odd-levels-only nil))
  4682. (org-promote))
  4683. (forward-line)
  4684. (org-get-indentation))))
  4685. (should
  4686. (zerop
  4687. (org-test-with-temp-text
  4688. "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
  4689. (let ((org-adapt-indentation t)
  4690. (org-src-preserve-indentation nil)
  4691. (org-odd-levels-only nil))
  4692. (org-promote))
  4693. (forward-line)
  4694. (org-get-indentation)))))
  4695. (ert-deftest test-org/org-get-valid-level ()
  4696. "Test function `org-get-valid-level' specifications."
  4697. (let ((org-odd-levels-only nil))
  4698. (should (equal 1 (org-get-valid-level 0 0)))
  4699. (should (equal 1 (org-get-valid-level 0 1)))
  4700. (should (equal 2 (org-get-valid-level 0 2)))
  4701. (should (equal 3 (org-get-valid-level 0 3)))
  4702. (should (equal 1 (org-get-valid-level 1 0)))
  4703. (should (equal 2 (org-get-valid-level 1 1)))
  4704. (should (equal 23 (org-get-valid-level 1 22)))
  4705. (should (equal 1 (org-get-valid-level 1 -1)))
  4706. (should (equal 1 (org-get-valid-level 2 -1))))
  4707. (let ((org-odd-levels-only t))
  4708. (should (equal 1 (org-get-valid-level 0 0)))
  4709. (should (equal 1 (org-get-valid-level 0 1)))
  4710. (should (equal 3 (org-get-valid-level 0 2)))
  4711. (should (equal 5 (org-get-valid-level 0 3)))
  4712. (should (equal 1 (org-get-valid-level 1 0)))
  4713. (should (equal 3 (org-get-valid-level 1 1)))
  4714. (should (equal 3 (org-get-valid-level 2 1)))
  4715. (should (equal 5 (org-get-valid-level 3 1)))
  4716. (should (equal 5 (org-get-valid-level 4 1)))
  4717. (should (equal 43 (org-get-valid-level 1 21)))
  4718. (should (equal 1 (org-get-valid-level 1 -1)))
  4719. (should (equal 1 (org-get-valid-level 2 -1)))
  4720. (should (equal 1 (org-get-valid-level 3 -1)))
  4721. (should (equal 3 (org-get-valid-level 4 -1)))
  4722. (should (equal 3 (org-get-valid-level 5 -1)))))
  4723. ;;; Planning
  4724. (ert-deftest test-org/at-planning-p ()
  4725. "Test `org-at-planning-p' specifications."
  4726. ;; Regular test.
  4727. (should
  4728. (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
  4729. (org-at-planning-p)))
  4730. (should-not
  4731. (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
  4732. (org-at-planning-p)))
  4733. ;; Correctly find planning attached to inlinetasks.
  4734. (when (featurep 'org-inlinetask)
  4735. (should
  4736. (org-test-with-temp-text
  4737. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
  4738. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4739. (should-not
  4740. (org-test-with-temp-text
  4741. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  4742. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4743. (should-not
  4744. (org-test-with-temp-text
  4745. "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  4746. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4747. (should-not
  4748. (org-test-with-temp-text
  4749. "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
  4750. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
  4751. (ert-deftest test-org/add-planning-info ()
  4752. "Test `org-add-planning-info'."
  4753. ;; Create deadline when `org-adapt-indentation' is non-nil.
  4754. (should
  4755. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4756. (org-test-with-temp-text "* H\nParagraph<point>"
  4757. (let ((org-adapt-indentation t))
  4758. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4759. (replace-regexp-in-string
  4760. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4761. nil nil 1))))
  4762. ;; Create deadline when `org-adapt-indentation' is nil.
  4763. (should
  4764. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  4765. (org-test-with-temp-text "* H\nParagraph<point>"
  4766. (let ((org-adapt-indentation nil))
  4767. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4768. (replace-regexp-in-string
  4769. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4770. nil nil 1))))
  4771. ;; Update deadline when `org-adapt-indentation' is non-nil.
  4772. (should
  4773. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4774. (org-test-with-temp-text "\
  4775. * H
  4776. DEADLINE: <2015-06-24 Wed>
  4777. Paragraph<point>"
  4778. (let ((org-adapt-indentation t))
  4779. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4780. (replace-regexp-in-string
  4781. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4782. nil nil 1))))
  4783. ;; Update deadline when `org-adapt-indentation' is nil.
  4784. (should
  4785. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  4786. (org-test-with-temp-text "\
  4787. * H
  4788. DEADLINE: <2015-06-24 Wed>
  4789. Paragraph<point>"
  4790. (let ((org-adapt-indentation nil))
  4791. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4792. (replace-regexp-in-string
  4793. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4794. nil nil 1))))
  4795. ;; Schedule when `org-adapt-indentation' is non-nil.
  4796. (should
  4797. (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
  4798. (org-test-with-temp-text "* H\nParagraph<point>"
  4799. (let ((org-adapt-indentation t))
  4800. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  4801. (replace-regexp-in-string
  4802. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4803. nil nil 1))))
  4804. ;; Schedule when `org-adapt-indentation' is nil.
  4805. (should
  4806. (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
  4807. (org-test-with-temp-text "* H\nParagraph<point>"
  4808. (let ((org-adapt-indentation nil))
  4809. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  4810. (replace-regexp-in-string
  4811. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4812. nil nil 1))))
  4813. ;; Add deadline when scheduled.
  4814. (should
  4815. (equal "\
  4816. * H
  4817. DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
  4818. Paragraph"
  4819. (org-test-with-temp-text "\
  4820. * H
  4821. SCHEDULED: <2015-06-24 Wed>
  4822. Paragraph<point>"
  4823. (let ((org-adapt-indentation t))
  4824. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4825. (replace-regexp-in-string
  4826. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4827. nil nil 1))))
  4828. ;; Remove middle entry.
  4829. (should
  4830. (equal "\
  4831. * H
  4832. CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
  4833. Paragraph"
  4834. (org-test-with-temp-text "\
  4835. * H
  4836. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  4837. Paragraph<point>"
  4838. (let ((org-adapt-indentation t))
  4839. (org-add-planning-info nil nil 'deadline))
  4840. (replace-regexp-in-string
  4841. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  4842. nil nil 1))))
  4843. ;; Remove last entry and then middle entry (order should not
  4844. ;; matter).
  4845. (should
  4846. (equal "\
  4847. * H
  4848. CLOSED: [2015-06-24]
  4849. Paragraph"
  4850. (org-test-with-temp-text "\
  4851. * H
  4852. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  4853. Paragraph<point>"
  4854. (let ((org-adapt-indentation t))
  4855. (org-add-planning-info nil nil 'scheduled 'deadline))
  4856. (replace-regexp-in-string
  4857. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  4858. nil nil 1))))
  4859. ;; Remove closed when `org-adapt-indentation' is non-nil.
  4860. (should
  4861. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4862. (org-test-with-temp-text "\
  4863. * H
  4864. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  4865. Paragraph<point>"
  4866. (let ((org-adapt-indentation t))
  4867. (org-add-planning-info nil nil 'closed))
  4868. (replace-regexp-in-string
  4869. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4870. nil nil 1))))
  4871. (should
  4872. (equal "* H\n Paragraph"
  4873. (org-test-with-temp-text "\
  4874. * H
  4875. CLOSED: [2015-06-25 Thu]
  4876. Paragraph<point>"
  4877. (let ((org-adapt-indentation t))
  4878. (org-add-planning-info nil nil 'closed))
  4879. (replace-regexp-in-string
  4880. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4881. nil nil 1))))
  4882. ;; Remove closed when `org-adapt-indentation' is nil.
  4883. (should
  4884. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  4885. (org-test-with-temp-text "\
  4886. * H
  4887. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  4888. Paragraph<point>"
  4889. (let ((org-adapt-indentation nil))
  4890. (org-add-planning-info nil nil 'closed))
  4891. (replace-regexp-in-string
  4892. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4893. nil nil 1))))
  4894. (should
  4895. (equal "* H\nParagraph"
  4896. (org-test-with-temp-text "\
  4897. * H
  4898. CLOSED: [2015-06-25 Thu]
  4899. Paragraph<point>"
  4900. (let ((org-adapt-indentation nil))
  4901. (org-add-planning-info nil nil 'closed))
  4902. (replace-regexp-in-string
  4903. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4904. nil nil 1))))
  4905. ;; Remove closed entry and delete empty line.
  4906. (should
  4907. (equal "\
  4908. * H
  4909. Paragraph"
  4910. (org-test-with-temp-text "\
  4911. * H
  4912. CLOSED: [2015-06-24 Wed]
  4913. Paragraph<point>"
  4914. (let ((org-adapt-indentation t))
  4915. (org-add-planning-info nil nil 'closed))
  4916. (replace-regexp-in-string
  4917. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4918. nil nil 1))))
  4919. ;; Remove one entry and update another.
  4920. (should
  4921. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4922. (org-test-with-temp-text "\
  4923. * H
  4924. SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
  4925. Paragraph<point>"
  4926. (let ((org-adapt-indentation t))
  4927. (org-add-planning-info 'deadline "<2015-06-25 Thu>" 'scheduled))
  4928. (replace-regexp-in-string
  4929. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4930. nil nil 1)))))
  4931. (ert-deftest test-org/deadline ()
  4932. "Test `org-deadline' specifications."
  4933. ;; Insert a new value or replace existing one.
  4934. (should
  4935. (equal "* H\nDEADLINE: <2012-03-29>"
  4936. (org-test-with-temp-text "* H"
  4937. (let ((org-adapt-indentation nil)
  4938. (org-last-inserted-timestamp nil))
  4939. (org-deadline nil "<2012-03-29 Tue>"))
  4940. (replace-regexp-in-string
  4941. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4942. nil nil 1))))
  4943. (should
  4944. (equal "* H\nDEADLINE: <2014-03-04>"
  4945. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  4946. (let ((org-adapt-indentation nil)
  4947. (org-last-inserted-timestamp nil))
  4948. (org-deadline nil "<2014-03-04 Thu>"))
  4949. (replace-regexp-in-string
  4950. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4951. nil nil 1))))
  4952. ;; Accept delta time, e.g., "+2d".
  4953. (should
  4954. (equal "* H\nDEADLINE: <2015-03-04>"
  4955. (org-test-at-time "2014-03-04"
  4956. (org-test-with-temp-text "* H"
  4957. (let ((org-adapt-indentation nil)
  4958. (org-last-inserted-timestamp nil))
  4959. (org-deadline nil "+1y"))
  4960. (replace-regexp-in-string
  4961. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  4962. ;; Preserve repeater.
  4963. (should
  4964. (equal "* H\nDEADLINE: <2012-03-29 +2y>"
  4965. (org-test-with-temp-text "* H"
  4966. (let ((org-adapt-indentation nil)
  4967. (org-last-inserted-timestamp nil))
  4968. (org-deadline nil "<2012-03-29 Tue +2y>"))
  4969. (replace-regexp-in-string
  4970. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  4971. ;; Remove CLOSED keyword, if any.
  4972. (should
  4973. (equal "* H\nDEADLINE: <2012-03-29>"
  4974. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  4975. (let ((org-adapt-indentation nil)
  4976. (org-last-inserted-timestamp nil))
  4977. (org-deadline nil "<2012-03-29 Tue>"))
  4978. (replace-regexp-in-string
  4979. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  4980. ;; With C-u argument, remove DEADLINE keyword.
  4981. (should
  4982. (equal "* H\n"
  4983. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  4984. (let ((org-adapt-indentation nil)
  4985. (org-last-inserted-timestamp nil))
  4986. (org-deadline '(4)))
  4987. (buffer-string))))
  4988. (should
  4989. (equal "* H"
  4990. (org-test-with-temp-text "* H"
  4991. (let ((org-adapt-indentation nil)
  4992. (org-last-inserted-timestamp nil))
  4993. (org-deadline '(4)))
  4994. (buffer-string))))
  4995. ;; With C-u C-u argument, prompt for a delay cookie.
  4996. (should
  4997. (equal "* H\nDEADLINE: <2012-03-29 -705d>"
  4998. (cl-letf (((symbol-function 'org-read-date)
  4999. (lambda (&rest args)
  5000. (apply #'encode-time
  5001. (org-parse-time-string "2014-03-04")))))
  5002. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5003. (let ((org-adapt-indentation nil)
  5004. (org-last-inserted-timestamp nil))
  5005. (org-deadline '(16)))
  5006. (buffer-string)))))
  5007. (should-error
  5008. (cl-letf (((symbol-function 'org-read-date)
  5009. (lambda (&rest args)
  5010. (apply #'encode-time
  5011. (org-parse-time-string "2014-03-04")))))
  5012. (org-test-with-temp-text "* H"
  5013. (let ((org-adapt-indentation nil)
  5014. (org-last-inserted-timestamp nil))
  5015. (org-deadline '(16)))
  5016. (buffer-string))))
  5017. ;; When a region is active and
  5018. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5019. ;; same value in all headlines in region.
  5020. (should
  5021. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5022. (org-test-with-temp-text "* H1\n* H2"
  5023. (let ((org-adapt-indentation nil)
  5024. (org-last-inserted-timestamp nil)
  5025. (org-loop-over-headlines-in-active-region t))
  5026. (transient-mark-mode 1)
  5027. (push-mark (point) t t)
  5028. (goto-char (point-max))
  5029. (org-deadline nil "2012-03-29"))
  5030. (replace-regexp-in-string
  5031. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5032. (should-not
  5033. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5034. (org-test-with-temp-text "* H1\n* H2"
  5035. (let ((org-adapt-indentation nil)
  5036. (org-last-inserted-timestamp nil)
  5037. (org-loop-over-headlines-in-active-region nil))
  5038. (transient-mark-mode 1)
  5039. (push-mark (point) t t)
  5040. (goto-char (point-max))
  5041. (org-deadline nil "2012-03-29"))
  5042. (replace-regexp-in-string
  5043. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5044. (ert-deftest test-org/schedule ()
  5045. "Test `org-schedule' specifications."
  5046. ;; Insert a new value or replace existing one.
  5047. (should
  5048. (equal "* H\nSCHEDULED: <2012-03-29>"
  5049. (org-test-with-temp-text "* H"
  5050. (let ((org-adapt-indentation nil)
  5051. (org-last-inserted-timestamp nil))
  5052. (org-schedule nil "<2012-03-29 Tue>"))
  5053. (replace-regexp-in-string
  5054. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5055. nil nil 1))))
  5056. (should
  5057. (equal "* H\nSCHEDULED: <2014-03-04>"
  5058. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5059. (let ((org-adapt-indentation nil)
  5060. (org-last-inserted-timestamp nil))
  5061. (org-schedule nil "<2014-03-04 Thu>"))
  5062. (replace-regexp-in-string
  5063. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5064. nil nil 1))))
  5065. ;; Accept delta time, e.g., "+2d".
  5066. (should
  5067. (equal "* H\nSCHEDULED: <2015-03-04>"
  5068. (org-test-at-time "2014-03-04"
  5069. (org-test-with-temp-text "* H"
  5070. (let ((org-adapt-indentation nil)
  5071. (org-last-inserted-timestamp nil))
  5072. (org-schedule nil "+1y"))
  5073. (replace-regexp-in-string
  5074. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5075. ;; Preserve repeater.
  5076. (should
  5077. (equal "* H\nSCHEDULED: <2012-03-29 +2y>"
  5078. (org-test-with-temp-text "* H"
  5079. (let ((org-adapt-indentation nil)
  5080. (org-last-inserted-timestamp nil))
  5081. (org-schedule nil "<2012-03-29 Tue +2y>"))
  5082. (replace-regexp-in-string
  5083. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5084. ;; Remove CLOSED keyword, if any.
  5085. (should
  5086. (equal "* H\nSCHEDULED: <2012-03-29>"
  5087. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  5088. (let ((org-adapt-indentation nil)
  5089. (org-last-inserted-timestamp nil))
  5090. (org-schedule nil "<2012-03-29 Tue>"))
  5091. (replace-regexp-in-string
  5092. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5093. ;; With C-u argument, remove SCHEDULED keyword.
  5094. (should
  5095. (equal "* H\n"
  5096. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5097. (let ((org-adapt-indentation nil)
  5098. (org-last-inserted-timestamp nil))
  5099. (org-schedule '(4)))
  5100. (buffer-string))))
  5101. (should
  5102. (equal "* H"
  5103. (org-test-with-temp-text "* H"
  5104. (let ((org-adapt-indentation nil)
  5105. (org-last-inserted-timestamp nil))
  5106. (org-schedule '(4)))
  5107. (buffer-string))))
  5108. ;; With C-u C-u argument, prompt for a delay cookie.
  5109. (should
  5110. (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
  5111. (cl-letf (((symbol-function 'org-read-date)
  5112. (lambda (&rest args)
  5113. (apply #'encode-time
  5114. (org-parse-time-string "2014-03-04")))))
  5115. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5116. (let ((org-adapt-indentation nil)
  5117. (org-last-inserted-timestamp nil))
  5118. (org-schedule '(16)))
  5119. (buffer-string)))))
  5120. (should-error
  5121. (cl-letf (((symbol-function 'org-read-date)
  5122. (lambda (&rest args)
  5123. (apply #'encode-time
  5124. (org-parse-time-string "2014-03-04")))))
  5125. (org-test-with-temp-text "* H"
  5126. (let ((org-adapt-indentation nil)
  5127. (org-last-inserted-timestamp nil))
  5128. (org-schedule '(16)))
  5129. (buffer-string))))
  5130. ;; When a region is active and
  5131. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5132. ;; same value in all headlines in region.
  5133. (should
  5134. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5135. (org-test-with-temp-text "* H1\n* H2"
  5136. (let ((org-adapt-indentation nil)
  5137. (org-last-inserted-timestamp nil)
  5138. (org-loop-over-headlines-in-active-region t))
  5139. (transient-mark-mode 1)
  5140. (push-mark (point) t t)
  5141. (goto-char (point-max))
  5142. (org-schedule nil "2012-03-29"))
  5143. (replace-regexp-in-string
  5144. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5145. (should-not
  5146. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5147. (org-test-with-temp-text "* H1\n* H2"
  5148. (let ((org-adapt-indentation nil)
  5149. (org-last-inserted-timestamp nil)
  5150. (org-loop-over-headlines-in-active-region nil))
  5151. (transient-mark-mode 1)
  5152. (push-mark (point) t t)
  5153. (goto-char (point-max))
  5154. (org-schedule nil "2012-03-29"))
  5155. (replace-regexp-in-string
  5156. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5157. (should
  5158. ;; check if a repeater survives re-scheduling.
  5159. (string-match-p
  5160. "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
  5161. (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
  5162. (let ((org-adapt-indentation nil)
  5163. (org-last-inserted-timestamp nil))
  5164. (org-schedule nil "2017-02-01"))
  5165. (buffer-string)))))
  5166. ;;; Property API
  5167. (ert-deftest test-org/buffer-property-keys ()
  5168. "Test `org-buffer-property-keys' specifications."
  5169. ;; Retrieve properties across siblings.
  5170. (should
  5171. (equal '("A" "B")
  5172. (org-test-with-temp-text "
  5173. * H1
  5174. :PROPERTIES:
  5175. :A: 1
  5176. :END:
  5177. * H2
  5178. :PROPERTIES:
  5179. :B: 1
  5180. :END:"
  5181. (org-buffer-property-keys))))
  5182. ;; Retrieve properties across children.
  5183. (should
  5184. (equal '("A" "B")
  5185. (org-test-with-temp-text "
  5186. * H1
  5187. :PROPERTIES:
  5188. :A: 1
  5189. :END:
  5190. ** H2
  5191. :PROPERTIES:
  5192. :B: 1
  5193. :END:"
  5194. (org-buffer-property-keys))))
  5195. ;; Retrieve muliple properties in the same drawer.
  5196. (should
  5197. (equal '("A" "B")
  5198. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5199. (org-buffer-property-keys))))
  5200. ;; Ignore extension symbol in property name.
  5201. (should
  5202. (equal '("A")
  5203. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5204. (org-buffer-property-keys))))
  5205. ;; With non-nil COLUMNS, extract property names from columns.
  5206. (should
  5207. (equal '("A" "B")
  5208. (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
  5209. (org-buffer-property-keys nil nil t))))
  5210. (should
  5211. (equal '("A" "B" "COLUMNS")
  5212. (org-test-with-temp-text
  5213. "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
  5214. (org-buffer-property-keys nil nil t))))
  5215. ;; In COLUMNS, ignore title and summary-type.
  5216. (should
  5217. (equal '("A")
  5218. (org-test-with-temp-text "#+COLUMNS: %A(Foo)"
  5219. (org-buffer-property-keys nil nil t))))
  5220. (should
  5221. (equal '("A")
  5222. (org-test-with-temp-text "#+COLUMNS: %A{Foo}"
  5223. (org-buffer-property-keys nil nil t))))
  5224. (should
  5225. (equal '("A")
  5226. (org-test-with-temp-text "#+COLUMNS: %A(Foo){Bar}"
  5227. (org-buffer-property-keys nil nil t)))))
  5228. (ert-deftest test-org/property-values ()
  5229. "Test `org-property-values' specifications."
  5230. ;; Regular test.
  5231. (should
  5232. (equal '("2" "1")
  5233. (org-test-with-temp-text
  5234. "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
  5235. (org-property-values "A"))))
  5236. ;; Ignore empty values.
  5237. (should-not
  5238. (org-test-with-temp-text
  5239. "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
  5240. (org-property-values "A")))
  5241. ;; Take into consideration extended values.
  5242. (should
  5243. (equal '("1 2")
  5244. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5245. (org-property-values "A")))))
  5246. (ert-deftest test-org/set-property ()
  5247. "Test `org-set-property' specifications."
  5248. (should
  5249. (equal
  5250. ":PROPERTIES:\n:TEST: t\n:END:\n"
  5251. (org-test-with-temp-text ""
  5252. (let ((org-property-format "%s %s"))
  5253. (org-set-property "TEST" "t"))
  5254. (buffer-string))))
  5255. (should
  5256. (equal
  5257. "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5258. (org-test-with-temp-text "* H"
  5259. (let ((org-adapt-indentation nil)
  5260. (org-property-format "%s %s"))
  5261. (org-set-property "TEST" "t"))
  5262. (buffer-string)))))
  5263. (ert-deftest test-org/delete-property ()
  5264. "Test `org-delete-property' specifications."
  5265. (should
  5266. (equal
  5267. ""
  5268. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5269. (org-delete-property "TEST")
  5270. (buffer-string))))
  5271. (should
  5272. (equal
  5273. ":PROPERTIES:\n:TEST1: t\n:END:\n"
  5274. (org-test-with-temp-text ":PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5275. (org-delete-property "TEST2")
  5276. (buffer-string))))
  5277. (should
  5278. (equal
  5279. "* H\n"
  5280. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5281. (org-delete-property "TEST")
  5282. (buffer-string))))
  5283. (should
  5284. (equal
  5285. "* H\n:PROPERTIES:\n:TEST1: t\n:END:\n"
  5286. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5287. (org-delete-property "TEST2")
  5288. (buffer-string)))))
  5289. (ert-deftest test-org/delete-property-globally ()
  5290. "Test `org-delete-property-global' specifications."
  5291. (should
  5292. (equal
  5293. ""
  5294. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5295. (org-delete-property-globally "TEST")
  5296. (buffer-string))))
  5297. (should
  5298. (equal
  5299. "* H\n"
  5300. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n* H\n:PROPERTIES:\n:TEST: nil\n:END:"
  5301. (org-delete-property-globally "TEST")
  5302. (buffer-string)))))
  5303. (ert-deftest test-org/find-property ()
  5304. "Test `org-find-property' specifications."
  5305. ;; Regular test.
  5306. (should
  5307. (= 1
  5308. (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
  5309. (org-find-property "prop"))))
  5310. ;; Find properties in top-level property drawer.
  5311. (should
  5312. (= 1
  5313. (org-test-with-temp-text ":PROPERTIES:\n:PROP: value\n:END:"
  5314. (org-find-property "prop"))))
  5315. ;; Ignore false positives.
  5316. (should
  5317. (= 27
  5318. (org-test-with-temp-text
  5319. "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
  5320. (org-find-property "A"))))
  5321. ;; Return first entry found in buffer.
  5322. (should
  5323. (= 1
  5324. (org-test-with-temp-text
  5325. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5326. (org-find-property "A"))))
  5327. ;; Only search visible part of the buffer.
  5328. (should
  5329. (= 31
  5330. (org-test-with-temp-text
  5331. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5332. (org-narrow-to-subtree)
  5333. (org-find-property "A"))))
  5334. ;; With optional argument, only find entries with a specific value.
  5335. (should-not
  5336. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5337. (org-find-property "A" "2")))
  5338. (should
  5339. (= 31
  5340. (org-test-with-temp-text
  5341. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
  5342. (org-find-property "A" "2"))))
  5343. ;; Use "nil" for explicit nil values.
  5344. (should
  5345. (= 31
  5346. (org-test-with-temp-text
  5347. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
  5348. (org-find-property "A" "nil")))))
  5349. (ert-deftest test-org/entry-delete ()
  5350. "Test `org-entry-delete' specifications."
  5351. ;; Regular test.
  5352. (should
  5353. (string-match
  5354. " *:PROPERTIES:\n *:B: +2\n *:END:"
  5355. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5356. (org-entry-delete (point) "A")
  5357. (buffer-string))))
  5358. ;; Also remove accumulated properties.
  5359. (should-not
  5360. (string-match
  5361. ":A"
  5362. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
  5363. (org-entry-delete (point) "A")
  5364. (buffer-string))))
  5365. ;; When last property is removed, remove the property drawer.
  5366. (should-not
  5367. (string-match
  5368. ":PROPERTIES:"
  5369. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
  5370. (org-entry-delete (point) "A")
  5371. (buffer-string))))
  5372. ;; Return a non-nil value when some property was removed.
  5373. (should
  5374. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5375. (org-entry-delete (point) "A")))
  5376. (should-not
  5377. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5378. (org-entry-delete (point) "C")))
  5379. ;; Special properties cannot be located in a drawer. Allow to
  5380. ;; remove them anyway, in case of user error.
  5381. (should
  5382. (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
  5383. (org-entry-delete (point) "SCHEDULED"))))
  5384. (ert-deftest test-org/entry-get ()
  5385. "Test `org-entry-get' specifications."
  5386. ;; Regular test.
  5387. (should
  5388. (equal "1"
  5389. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:"
  5390. (org-entry-get (point) "A"))))
  5391. (should
  5392. (equal "1"
  5393. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5394. (org-entry-get (point) "A"))))
  5395. ;; Ignore case.
  5396. (should
  5397. (equal "1"
  5398. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5399. (org-entry-get (point) "a"))))
  5400. ;; Handle extended values, both before and after base value.
  5401. (should
  5402. (equal "1 2 3"
  5403. (org-test-with-temp-text
  5404. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5405. (org-entry-get (point) "A"))))
  5406. ;; Empty values are returned as the empty string.
  5407. (should
  5408. (equal ""
  5409. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
  5410. (org-entry-get (point) "A"))))
  5411. ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
  5412. ;; otherwise, return nil.
  5413. (should-not
  5414. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5415. (org-entry-get (point) "A")))
  5416. (should
  5417. (equal "nil"
  5418. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5419. (org-entry-get (point) "A" nil t))))
  5420. ;; Return nil when no property is found, independently on the
  5421. ;; LITERAL-NIL argument.
  5422. (should-not
  5423. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5424. (org-entry-get (point) "B")))
  5425. (should-not
  5426. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5427. (org-entry-get (point) "B" nil t)))
  5428. ;; Handle inheritance, when allowed. Include extended values and
  5429. ;; possibly global values.
  5430. (should
  5431. (equal
  5432. "1"
  5433. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:\n* H"
  5434. (org-entry-get (point-max) "A" t))))
  5435. (should
  5436. (equal
  5437. "1"
  5438. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5439. (org-entry-get (point-max) "A" t))))
  5440. (should
  5441. (equal
  5442. "1"
  5443. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5444. (let ((org-use-property-inheritance t))
  5445. (org-entry-get (point-max) "A" 'selective)))))
  5446. (should-not
  5447. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5448. (let ((org-use-property-inheritance nil))
  5449. (org-entry-get (point-max) "A" 'selective))))
  5450. (should
  5451. (equal
  5452. "1 2"
  5453. (org-test-with-temp-text
  5454. ":PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5455. (org-entry-get (point-max) "A" t))))
  5456. (should
  5457. (equal
  5458. "1 2"
  5459. (org-test-with-temp-text
  5460. "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5461. (org-entry-get (point-max) "A" t))))
  5462. (should
  5463. (equal
  5464. "1 2"
  5465. (org-test-with-temp-text
  5466. ":PROPERTIES:\n:A: 1\n:END:\n* H1\n* H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5467. (org-entry-get (point-max) "A" t))))
  5468. (should
  5469. (equal
  5470. "1 2"
  5471. (org-test-with-temp-text
  5472. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2.1\n* H2.2\n:PROPERTIES:\n:A+: 2\n:END:"
  5473. (org-entry-get (point-max) "A" t))))
  5474. (should
  5475. (equal "1"
  5476. (org-test-with-temp-text
  5477. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
  5478. (org-mode-restart)
  5479. (org-entry-get (point-max) "A" t))))
  5480. (should
  5481. (equal "0 1"
  5482. (org-test-with-temp-text
  5483. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
  5484. (org-mode-restart)
  5485. (org-entry-get (point-max) "A" t))))
  5486. ;; document level property-drawer has precedance over
  5487. ;; global-property by PROPERTY-keyword.
  5488. (should
  5489. (equal "0 2"
  5490. (org-test-with-temp-text
  5491. ":PROPERTIES:\n:A: 0\n:END:\n#+PROPERTY: A 1\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5492. (org-mode-restart)
  5493. (org-entry-get (point-max) "A" t)))))
  5494. (ert-deftest test-org/entry-properties ()
  5495. "Test `org-entry-properties' specifications."
  5496. ;; Get "ITEM" property.
  5497. (should
  5498. (equal "H"
  5499. (org-test-with-temp-text "* TODO H"
  5500. (cdr (assoc "ITEM" (org-entry-properties nil "ITEM"))))))
  5501. (should
  5502. (equal "H"
  5503. (org-test-with-temp-text "* TODO H"
  5504. (cdr (assoc "ITEM" (org-entry-properties))))))
  5505. ;; Get "TODO" property. TODO keywords are case sensitive.
  5506. (should
  5507. (equal "TODO"
  5508. (org-test-with-temp-text "* TODO H"
  5509. (cdr (assoc "TODO" (org-entry-properties nil "TODO"))))))
  5510. (should
  5511. (equal "TODO"
  5512. (org-test-with-temp-text "* TODO H"
  5513. (cdr (assoc "TODO" (org-entry-properties))))))
  5514. (should-not
  5515. (org-test-with-temp-text "* H"
  5516. (assoc "TODO" (org-entry-properties nil "TODO"))))
  5517. (should-not
  5518. (org-test-with-temp-text "* todo H"
  5519. (assoc "TODO" (org-entry-properties nil "TODO"))))
  5520. ;; Get "PRIORITY" property.
  5521. (should
  5522. (equal "A"
  5523. (org-test-with-temp-text "* [#A] H"
  5524. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  5525. (should
  5526. (equal "A"
  5527. (org-test-with-temp-text "* [#A] H"
  5528. (cdr (assoc "PRIORITY" (org-entry-properties))))))
  5529. (should
  5530. (equal (char-to-string org-priority-default)
  5531. (org-test-with-temp-text "* H"
  5532. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  5533. ;; Get "FILE" property.
  5534. (should
  5535. (org-test-with-temp-text-in-file "* H\nParagraph"
  5536. (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil "FILE")))
  5537. (buffer-file-name))))
  5538. (should
  5539. (org-test-with-temp-text-in-file "* H\nParagraph"
  5540. (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
  5541. (buffer-file-name))))
  5542. (should-not
  5543. (org-test-with-temp-text "* H\nParagraph"
  5544. (cdr (assoc "FILE" (org-entry-properties nil "FILE")))))
  5545. ;; Get "TAGS" property.
  5546. (should
  5547. (equal ":tag1:tag2:"
  5548. (org-test-with-temp-text "* H :tag1:tag2:"
  5549. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS"))))))
  5550. (should
  5551. (equal ":tag1:tag2:"
  5552. (org-test-with-temp-text "* H :tag1:tag2:"
  5553. (cdr (assoc "TAGS" (org-entry-properties))))))
  5554. (should-not
  5555. (org-test-with-temp-text "* H"
  5556. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS")))))
  5557. ;; Get "ALLTAGS" property.
  5558. (should
  5559. (equal ":tag1:tag2:"
  5560. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  5561. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS"))))))
  5562. (should
  5563. (equal ":tag1:tag2:"
  5564. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  5565. (cdr (assoc "ALLTAGS" (org-entry-properties))))))
  5566. (should-not
  5567. (org-test-with-temp-text "* H"
  5568. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS")))))
  5569. ;; Get "BLOCKED" property.
  5570. (should
  5571. (equal "t"
  5572. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  5573. (let ((org-enforce-todo-dependencies t)
  5574. (org-blocker-hook
  5575. '(org-block-todo-from-children-or-siblings-or-parent)))
  5576. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  5577. (should
  5578. (equal ""
  5579. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  5580. (let ((org-enforce-todo-dependencies t)
  5581. (org-blocker-hook
  5582. '(org-block-todo-from-children-or-siblings-or-parent)))
  5583. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  5584. ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
  5585. (should
  5586. (equal
  5587. "[2012-03-29 thu.]"
  5588. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  5589. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED"))))))
  5590. (should
  5591. (equal
  5592. "[2012-03-29 thu.]"
  5593. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  5594. (cdr (assoc "CLOSED" (org-entry-properties))))))
  5595. (should-not
  5596. (org-test-with-temp-text "* H"
  5597. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED")))))
  5598. (should
  5599. (equal
  5600. "<2014-03-04 tue.>"
  5601. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5602. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE"))))))
  5603. (should
  5604. (equal
  5605. "<2014-03-04 tue.>"
  5606. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5607. (cdr (assoc "DEADLINE" (org-entry-properties))))))
  5608. (should-not
  5609. (org-test-with-temp-text "* H"
  5610. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE")))))
  5611. (should
  5612. (equal
  5613. "<2014-03-04 tue.>"
  5614. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5615. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED"))))))
  5616. (should
  5617. (equal
  5618. "<2014-03-04 tue.>"
  5619. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5620. (cdr (assoc "SCHEDULED" (org-entry-properties))))))
  5621. (should-not
  5622. (org-test-with-temp-text "* H"
  5623. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED")))))
  5624. ;; Get "CATEGORY"
  5625. (should
  5626. (equal "cat"
  5627. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  5628. (cdr (assoc "CATEGORY" (org-entry-properties))))))
  5629. (should
  5630. (equal "cat"
  5631. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  5632. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5633. (should
  5634. (equal "cat"
  5635. (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
  5636. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5637. (should
  5638. (equal "cat2"
  5639. (org-test-with-temp-text
  5640. (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  5641. "\n"
  5642. "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
  5643. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5644. ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
  5645. (should
  5646. (equal "<2012-03-29 thu.>"
  5647. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
  5648. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  5649. (should
  5650. (equal "[2012-03-29 thu.]"
  5651. (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
  5652. (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
  5653. (should
  5654. (equal "<2012-03-29 thu.>"
  5655. (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
  5656. (cdr (assoc "TIMESTAMP" (org-entry-properties nil "TIMESTAMP"))))))
  5657. (should
  5658. (equal "[2014-03-04 tue.]"
  5659. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
  5660. (cdr (assoc "TIMESTAMP_IA"
  5661. (org-entry-properties nil "TIMESTAMP_IA"))))))
  5662. (should-not
  5663. (equal "<2012-03-29 thu.>"
  5664. (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
  5665. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  5666. ;; Get standard properties.
  5667. (should
  5668. (equal "1"
  5669. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5670. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5671. ;; Handle extended properties.
  5672. (should
  5673. (equal "1 2 3"
  5674. (org-test-with-temp-text
  5675. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5676. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5677. (should
  5678. (equal "1 2 3"
  5679. (org-test-with-temp-text
  5680. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
  5681. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5682. ;; Ignore forbidden (special) properties.
  5683. (should-not
  5684. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
  5685. (cdr (assoc "TODO" (org-entry-properties nil 'standard))))))
  5686. (ert-deftest test-org/entry-put ()
  5687. "Test `org-entry-put' specifications."
  5688. ;; Error when not a string or nil.
  5689. (should-error
  5690. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5691. (org-entry-put 1 "test" 2)))
  5692. ;; Error when property name is invalid.
  5693. (should-error
  5694. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5695. (org-entry-put 1 "no space" "value")))
  5696. (should-error
  5697. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5698. (org-entry-put 1 "" "value")))
  5699. ;; Set "TODO" property.
  5700. (should
  5701. (string-match (regexp-quote " TODO H")
  5702. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  5703. (org-entry-put (point) "TODO" "TODO")
  5704. (buffer-string))))
  5705. (should
  5706. (string-match (regexp-quote "* H")
  5707. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  5708. (org-entry-put (point) "TODO" nil)
  5709. (buffer-string))))
  5710. ;; Set "PRIORITY" property.
  5711. (should
  5712. (equal "* [#A] H"
  5713. (org-test-with-temp-text "* [#B] H"
  5714. (org-entry-put (point) "PRIORITY" "A")
  5715. (buffer-string))))
  5716. (should
  5717. (equal "* H"
  5718. (org-test-with-temp-text "* [#B] H"
  5719. (org-entry-put (point) "PRIORITY" nil)
  5720. (buffer-string))))
  5721. ;; Set "SCHEDULED" property.
  5722. (should
  5723. (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
  5724. (org-test-with-temp-text "* H"
  5725. (org-entry-put (point) "SCHEDULED" "2014-03-04")
  5726. (buffer-string))))
  5727. (should
  5728. (string= "* H\n"
  5729. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5730. (org-entry-put (point) "SCHEDULED" nil)
  5731. (buffer-string))))
  5732. (should
  5733. (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
  5734. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5735. (org-entry-put (point) "SCHEDULED" "earlier")
  5736. (buffer-string))))
  5737. (should
  5738. (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
  5739. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5740. (org-entry-put (point) "SCHEDULED" "later")
  5741. (buffer-string))))
  5742. ;; Set "DEADLINE" property.
  5743. (should
  5744. (string-match "^ *DEADLINE: <2014-03-04 .*?>"
  5745. (org-test-with-temp-text "* H"
  5746. (org-entry-put (point) "DEADLINE" "2014-03-04")
  5747. (buffer-string))))
  5748. (should
  5749. (string= "* H\n"
  5750. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5751. (org-entry-put (point) "DEADLINE" nil)
  5752. (buffer-string))))
  5753. (should
  5754. (string-match "^ *DEADLINE: <2014-03-03 .*?>"
  5755. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5756. (org-entry-put (point) "DEADLINE" "earlier")
  5757. (buffer-string))))
  5758. (should
  5759. (string-match "^ *DEADLINE: <2014-03-05 .*?>"
  5760. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5761. (org-entry-put (point) "DEADLINE" "later")
  5762. (buffer-string))))
  5763. ;; Set "CATEGORY" property
  5764. (should
  5765. (string-match "^ *:CATEGORY: cat"
  5766. (org-test-with-temp-text "* H"
  5767. (org-entry-put (point) "CATEGORY" "cat")
  5768. (buffer-string))))
  5769. ;; Regular properties, with or without pre-existing drawer.
  5770. (should
  5771. (string-match "^ *:A: +2$"
  5772. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5773. (org-entry-put (point) "A" "2")
  5774. (buffer-string))))
  5775. (should
  5776. (string-match "^ *:A: +1$"
  5777. (org-test-with-temp-text "* H"
  5778. (org-entry-put (point) "A" "1")
  5779. (buffer-string))))
  5780. ;; Special case: two consecutive headlines.
  5781. (should
  5782. (string-match "\\* A\n *:PROPERTIES:"
  5783. (org-test-with-temp-text "* A\n** B"
  5784. (org-entry-put (point) "A" "1")
  5785. (buffer-string)))))
  5786. (ert-deftest test-org/refresh-properties ()
  5787. "Test `org-refresh-properties' specifications."
  5788. (should
  5789. (equal "1"
  5790. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5791. (org-refresh-properties "A" 'org-test)
  5792. (get-text-property (point) 'org-test))))
  5793. (should-not
  5794. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5795. (org-refresh-properties "B" 'org-test)
  5796. (get-text-property (point) 'org-test)))
  5797. ;; Handle properties only defined with extension syntax, i.e.,
  5798. ;; "PROPERTY+".
  5799. (should
  5800. (equal "1"
  5801. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
  5802. (org-refresh-properties "A" 'org-test)
  5803. (get-text-property (point) 'org-test))))
  5804. ;; When property is inherited, add text property to the whole
  5805. ;; sub-tree.
  5806. (should
  5807. (equal "1"
  5808. (org-test-with-temp-text
  5809. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
  5810. (let ((org-use-property-inheritance t))
  5811. (org-refresh-properties "A" 'org-test))
  5812. (get-text-property (point) 'org-test))))
  5813. ;; When a document level property-drawer is used, those properties
  5814. ;; should work exactly like headline-properties as if at a
  5815. ;; headline-level 0.
  5816. (should
  5817. (equal "1"
  5818. (org-test-with-temp-text
  5819. ":PROPERTIES:\n:A: 1\n:END:\n"
  5820. (org-mode-restart)
  5821. (let ((org-use-property-inheritance t))
  5822. (org-refresh-properties "A" 'org-test))
  5823. (get-text-property (point) 'org-test))))
  5824. (should-not
  5825. (equal "1"
  5826. (org-test-with-temp-text
  5827. ":PROPERTIES:\n:A: 1\n:END:\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
  5835. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  5836. (org-mode-restart)
  5837. (let ((org-use-property-inheritance t))
  5838. (org-refresh-properties "A" 'org-test))
  5839. (get-text-property (point) 'org-test))))
  5840. (should
  5841. (equal "2"
  5842. (org-test-with-temp-text
  5843. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1\n:PROPERTIES:\n:A: 2\n:END:"
  5844. (org-mode-restart)
  5845. (let ((org-use-property-inheritance t))
  5846. (org-refresh-properties "A" 'org-test))
  5847. (get-text-property (point) 'org-test))))
  5848. ;; When property is inherited, use global value across the whole
  5849. ;; buffer. However local values have precedence, as well as the
  5850. ;; document level property-drawer.
  5851. (should-not
  5852. (equal "1"
  5853. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  5854. (org-mode-restart)
  5855. (let ((org-use-property-inheritance nil))
  5856. (org-refresh-properties "A" 'org-test))
  5857. (get-text-property (point) 'org-test))))
  5858. (should
  5859. (equal "1"
  5860. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  5861. (org-mode-restart)
  5862. (let ((org-use-property-inheritance t))
  5863. (org-refresh-properties "A" 'org-test))
  5864. (get-text-property (point) 'org-test))))
  5865. (should
  5866. (equal "2"
  5867. (org-test-with-temp-text
  5868. "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
  5869. (org-mode-restart)
  5870. (let ((org-use-property-inheritance t))
  5871. (org-refresh-properties "A" 'org-test))
  5872. (get-text-property (point) 'org-test))))
  5873. ;; When both keyword-property and document-level property-block is
  5874. ;; defined, the property-block has precedance.
  5875. (should
  5876. (equal "1"
  5877. (org-test-with-temp-text
  5878. ":PROPERTIES:\n:A: 1\n:END:\n#+PROPERTY: A 2\n<point>* H1"
  5879. (org-mode-restart)
  5880. (let ((org-use-property-inheritance t))
  5881. (org-refresh-properties "A" 'org-test))
  5882. (get-text-property (point) 'org-test)))))
  5883. (ert-deftest test-org/refresh-category-properties ()
  5884. "Test `org-refresh-category-properties' specifications"
  5885. (should
  5886. (equal "cat1"
  5887. (org-test-with-temp-text
  5888. ":PROPERTIES:\n:CATEGORY: cat1\n:END:"
  5889. (org-refresh-category-properties)
  5890. (get-text-property (point) 'org-category))))
  5891. (should
  5892. (equal "cat1"
  5893. (org-test-with-temp-text
  5894. "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  5895. (org-refresh-category-properties)
  5896. (get-text-property (point) 'org-category))))
  5897. ;; Even though property-inheritance is deactivated, category
  5898. ;; property should be inherited. As described in
  5899. ;; `org-use-property-inheritance'.
  5900. (should
  5901. (equal "cat1"
  5902. (org-test-with-temp-text
  5903. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  5904. (org-mode-restart)
  5905. (let ((org-use-property-inheritance nil))
  5906. (org-refresh-category-properties))
  5907. (get-text-property (point) 'org-category))))
  5908. (should
  5909. (equal "cat1"
  5910. (org-test-with-temp-text
  5911. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  5912. (org-mode-restart)
  5913. (let ((org-use-property-inheritance t))
  5914. (org-refresh-category-properties))
  5915. (get-text-property (point) 'org-category))))
  5916. (should
  5917. (equal "cat2"
  5918. (org-test-with-temp-text
  5919. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H\n:PROPERTIES:\n:CATEGORY: cat2\n:END:\n"
  5920. (org-mode-restart)
  5921. (let ((org-use-property-inheritance t))
  5922. (org-refresh-category-properties))
  5923. (get-text-property (point) 'org-category)))))
  5924. ;;; Refile
  5925. (ert-deftest test-org/refile-get-targets ()
  5926. "Test `org-refile-get-targets' specifications."
  5927. ;; :maxlevel includes all headings above specified value.
  5928. (should
  5929. (equal '("H1" "H2" "H3")
  5930. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  5931. (let ((org-refile-use-outline-path nil)
  5932. (org-refile-targets `((nil :maxlevel . 3))))
  5933. (mapcar #'car (org-refile-get-targets))))))
  5934. (should
  5935. (equal '("H1" "H2")
  5936. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  5937. (let ((org-refile-use-outline-path nil)
  5938. (org-refile-targets `((nil :maxlevel . 2))))
  5939. (mapcar #'car (org-refile-get-targets))))))
  5940. ;; :level limits targets to headlines with the specified level.
  5941. (should
  5942. (equal '("H2")
  5943. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  5944. (let ((org-refile-use-outline-path nil)
  5945. (org-refile-targets `((nil :level . 2))))
  5946. (mapcar #'car (org-refile-get-targets))))))
  5947. ;; :tag limits targets to headlines with specified tag.
  5948. (should
  5949. (equal '("H1")
  5950. (org-test-with-temp-text "* H1 :foo:\n** H2\n*** H3 :bar:"
  5951. (let ((org-refile-use-outline-path nil)
  5952. (org-refile-targets `((nil :tag . "foo"))))
  5953. (mapcar #'car (org-refile-get-targets))))))
  5954. ;; :todo limits targets to headlines with specified TODO keyword.
  5955. (should
  5956. (equal '("H2")
  5957. (org-test-with-temp-text "* H1\n** TODO H2\n*** DONE H3"
  5958. (let ((org-refile-use-outline-path nil)
  5959. (org-refile-targets `((nil :todo . "TODO"))))
  5960. (mapcar #'car (org-refile-get-targets))))))
  5961. ;; :regexp filters targets matching provided regexp.
  5962. (should
  5963. (equal '("F2" "F3")
  5964. (org-test-with-temp-text "* H1\n** F2\n*** F3"
  5965. (let ((org-refile-use-outline-path nil)
  5966. (org-refile-targets `((nil :regexp . "F"))))
  5967. (mapcar #'car (org-refile-get-targets))))))
  5968. ;; A nil `org-refile-targets' includes only top level headlines in
  5969. ;; current buffer.
  5970. (should
  5971. (equal '("H1" "H2")
  5972. (org-test-with-temp-text "* H1\n** S1\n* H2"
  5973. (let ((org-refile-use-outline-path nil)
  5974. (org-refile-targets nil))
  5975. (mapcar #'car (org-refile-get-targets))))))
  5976. ;; Return value is the union of the targets according to all the
  5977. ;; defined rules. However, prevent duplicates.
  5978. (should
  5979. (equal '("F2" "F3" "H1")
  5980. (org-test-with-temp-text "* TODO H1\n** F2\n*** F3"
  5981. (let ((org-refile-use-outline-path nil)
  5982. (org-refile-targets `((nil :regexp . "F")
  5983. (nil :todo . "TODO"))))
  5984. (mapcar #'car (org-refile-get-targets))))))
  5985. (should
  5986. (equal '("F2" "F3" "H1")
  5987. (org-test-with-temp-text "* TODO H1\n** TODO F2\n*** F3"
  5988. (let ((org-refile-use-outline-path nil)
  5989. (org-refile-targets `((nil :regexp . "F")
  5990. (nil :todo . "TODO"))))
  5991. (mapcar #'car (org-refile-get-targets))))))
  5992. ;; When `org-refile-use-outline-path' is non-nil, provide targets as
  5993. ;; paths.
  5994. (should
  5995. (equal '("H1" "H1/H2" "H1/H2/H3")
  5996. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  5997. (let ((org-refile-use-outline-path t)
  5998. (org-refile-targets `((nil :maxlevel . 3))))
  5999. (mapcar #'car (org-refile-get-targets))))))
  6000. ;; When providing targets as paths, escape forward slashes in
  6001. ;; headings with backslashes.
  6002. (should
  6003. (equal '("H1\\/foo")
  6004. (org-test-with-temp-text "* H1/foo"
  6005. (let ((org-refile-use-outline-path t)
  6006. (org-refile-targets `((nil :maxlevel . 1))))
  6007. (mapcar #'car (org-refile-get-targets))))))
  6008. ;; When `org-refile-use-outline-path' is `file', include file name
  6009. ;; without directory in targets.
  6010. (should
  6011. (org-test-with-temp-text-in-file "* H1"
  6012. (let* ((filename (buffer-file-name))
  6013. (org-refile-use-outline-path 'file)
  6014. (org-refile-targets `(((,filename) :level . 1))))
  6015. (member (file-name-nondirectory filename)
  6016. (mapcar #'car (org-refile-get-targets))))))
  6017. ;; When `org-refile-use-outline-path' is `full-file-path', include
  6018. ;; full file name.
  6019. (should
  6020. (org-test-with-temp-text-in-file "* H1"
  6021. (let* ((filename (file-truename (buffer-file-name)))
  6022. (org-refile-use-outline-path 'full-file-path)
  6023. (org-refile-targets `(((,filename) :level . 1))))
  6024. (member filename (mapcar #'car (org-refile-get-targets))))))
  6025. ;; When `org-refile-use-outline-path' is `buffer-name', include
  6026. ;; buffer name.
  6027. (should
  6028. (org-test-with-temp-text "* H1"
  6029. (let* ((org-refile-use-outline-path 'buffer-name)
  6030. (org-refile-targets `((nil :level . 1))))
  6031. (member (buffer-name) (mapcar #'car (org-refile-get-targets)))))))
  6032. ;;; Sparse trees
  6033. (ert-deftest test-org/match-sparse-tree ()
  6034. "Test `org-match-sparse-tree' specifications."
  6035. ;; Match tags.
  6036. (should-not
  6037. (org-test-with-temp-text "* H\n** H1 :tag:"
  6038. (org-match-sparse-tree nil "tag")
  6039. (search-forward "H1")
  6040. (org-invisible-p2)))
  6041. (should
  6042. (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
  6043. (org-match-sparse-tree nil "tag")
  6044. (search-forward "H2")
  6045. (org-invisible-p2)))
  6046. ;; "-" operator for tags.
  6047. (should-not
  6048. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6049. (org-match-sparse-tree nil "tag1-tag2")
  6050. (search-forward "H1")
  6051. (org-invisible-p2)))
  6052. (should
  6053. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6054. (org-match-sparse-tree nil "tag1-tag2")
  6055. (search-forward "H2")
  6056. (org-invisible-p2)))
  6057. ;; "&" operator for tags.
  6058. (should
  6059. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6060. (org-match-sparse-tree nil "tag1&tag2")
  6061. (search-forward "H1")
  6062. (org-invisible-p2)))
  6063. (should-not
  6064. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6065. (org-match-sparse-tree nil "tag1&tag2")
  6066. (search-forward "H2")
  6067. (org-invisible-p2)))
  6068. ;; "|" operator for tags.
  6069. (should-not
  6070. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6071. (org-match-sparse-tree nil "tag1|tag2")
  6072. (search-forward "H1")
  6073. (org-invisible-p2)))
  6074. (should-not
  6075. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6076. (org-match-sparse-tree nil "tag1|tag2")
  6077. (search-forward "H2")
  6078. (org-invisible-p2)))
  6079. ;; Regexp match on tags.
  6080. (should-not
  6081. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6082. (org-match-sparse-tree nil "{^tag.*}")
  6083. (search-forward "H1")
  6084. (org-invisible-p2)))
  6085. (should
  6086. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6087. (org-match-sparse-tree nil "{^tag.*}")
  6088. (search-forward "H2")
  6089. (org-invisible-p2)))
  6090. ;; Match group tags.
  6091. (should-not
  6092. (org-test-with-temp-text
  6093. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6094. (org-match-sparse-tree nil "work")
  6095. (search-forward "H1")
  6096. (org-invisible-p2)))
  6097. (should-not
  6098. (org-test-with-temp-text
  6099. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6100. (org-match-sparse-tree nil "work")
  6101. (search-forward "H2")
  6102. (org-invisible-p2)))
  6103. ;; Match group tags with hard brackets.
  6104. (should-not
  6105. (org-test-with-temp-text
  6106. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6107. (org-match-sparse-tree nil "work")
  6108. (search-forward "H1")
  6109. (org-invisible-p2)))
  6110. (should-not
  6111. (org-test-with-temp-text
  6112. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6113. (org-match-sparse-tree nil "work")
  6114. (search-forward "H2")
  6115. (org-invisible-p2)))
  6116. ;; Match tags in hierarchies
  6117. (should-not
  6118. (org-test-with-temp-text
  6119. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6120. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6121. #+TAGS: { Lev_3 : Lev_4 }\n
  6122. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6123. (org-match-sparse-tree nil "Lev_1")
  6124. (search-forward "H4")
  6125. (org-invisible-p2)))
  6126. (should-not
  6127. (org-test-with-temp-text
  6128. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6129. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6130. #+TAGS: { Lev_3 : Lev_4 }\n
  6131. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6132. (org-match-sparse-tree nil "Lev_1+Lev_3")
  6133. (search-forward "H4")
  6134. (org-invisible-p2)))
  6135. ;; Match regular expressions in tags
  6136. (should-not
  6137. (org-test-with-temp-text
  6138. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
  6139. (org-match-sparse-tree nil "Lev")
  6140. (search-forward "H1")
  6141. (org-invisible-p2)))
  6142. (should
  6143. (org-test-with-temp-text
  6144. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
  6145. (org-match-sparse-tree nil "Lev")
  6146. (search-forward "H1")
  6147. (org-invisible-p2)))
  6148. ;; Match properties.
  6149. (should
  6150. (org-test-with-temp-text
  6151. "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
  6152. (org-match-sparse-tree nil "A=\"1\"")
  6153. (search-forward "H2")
  6154. (org-invisible-p2)))
  6155. (should-not
  6156. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6157. (org-match-sparse-tree nil "A=\"1\"")
  6158. (search-forward "H2")
  6159. (org-invisible-p2)))
  6160. ;; Case is not significant when matching properties.
  6161. (should-not
  6162. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6163. (org-match-sparse-tree nil "a=\"1\"")
  6164. (search-forward "H2")
  6165. (org-invisible-p2)))
  6166. (should-not
  6167. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
  6168. (org-match-sparse-tree nil "A=\"1\"")
  6169. (search-forward "H2")
  6170. (org-invisible-p2)))
  6171. ;; Match special LEVEL property.
  6172. (should-not
  6173. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6174. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6175. (search-forward "H1")
  6176. (org-invisible-p2)))
  6177. (should
  6178. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6179. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6180. (search-forward "H2")
  6181. (org-invisible-p2)))
  6182. ;; Comparison operators when matching properties.
  6183. (should
  6184. (org-test-with-temp-text
  6185. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6186. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6187. (search-forward "H1")
  6188. (org-invisible-p2)))
  6189. (should-not
  6190. (org-test-with-temp-text
  6191. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6192. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6193. (search-forward "H2")
  6194. (org-invisible-p2)))
  6195. ;; Regexp match on properties values.
  6196. (should-not
  6197. (org-test-with-temp-text
  6198. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6199. (org-match-sparse-tree nil "A={f.*}")
  6200. (search-forward "H1")
  6201. (org-invisible-p2)))
  6202. (should
  6203. (org-test-with-temp-text
  6204. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6205. (org-match-sparse-tree nil "A={f.*}")
  6206. (search-forward "H2")
  6207. (org-invisible-p2)))
  6208. ;; With an optional argument, limit match to TODO entries.
  6209. (should-not
  6210. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6211. (org-match-sparse-tree t "tag")
  6212. (search-forward "H1")
  6213. (org-invisible-p2)))
  6214. (should
  6215. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6216. (org-match-sparse-tree t "tag")
  6217. (search-forward "H2")
  6218. (org-invisible-p2))))
  6219. (ert-deftest test-org/occur ()
  6220. "Test `org-occur' specifications."
  6221. ;; Count number of matches.
  6222. (should
  6223. (= 1
  6224. (org-test-with-temp-text "* H\nA\n* H2"
  6225. (org-occur "A"))))
  6226. (should
  6227. (= 2
  6228. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6229. (org-occur "A"))))
  6230. ;; Test CALLBACK optional argument.
  6231. (should
  6232. (= 0
  6233. (org-test-with-temp-text "* H\nA\n* H2"
  6234. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6235. (should
  6236. (= 1
  6237. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6238. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6239. ;; Case-fold searches according to `org-occur-case-fold-search'.
  6240. (should
  6241. (= 2
  6242. (org-test-with-temp-text "Aa"
  6243. (let ((org-occur-case-fold-search t)) (org-occur "A")))))
  6244. (should
  6245. (= 2
  6246. (org-test-with-temp-text "Aa"
  6247. (let ((org-occur-case-fold-search t)) (org-occur "a")))))
  6248. (should
  6249. (= 1
  6250. (org-test-with-temp-text "Aa"
  6251. (let ((org-occur-case-fold-search nil)) (org-occur "A")))))
  6252. (should
  6253. (= 1
  6254. (org-test-with-temp-text "Aa"
  6255. (let ((org-occur-case-fold-search nil)) (org-occur "a")))))
  6256. (should
  6257. (= 1
  6258. (org-test-with-temp-text "Aa"
  6259. (let ((org-occur-case-fold-search 'smart)) (org-occur "A")))))
  6260. (should
  6261. (= 2
  6262. (org-test-with-temp-text "Aa"
  6263. (let ((org-occur-case-fold-search 'smart)) (org-occur "a"))))))
  6264. ;;; Tags
  6265. (ert-deftest test-org/tag-string-to-alist ()
  6266. "Test `org-tag-string-to-alist' specifications."
  6267. ;; Tag without selection key.
  6268. (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
  6269. ;; Tag with selection key.
  6270. (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t))))
  6271. ;; Tag group.
  6272. (should
  6273. (equal
  6274. (org-tag-string-to-alist "[ group : t1 t2 ]")
  6275. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag))))
  6276. ;; Mutually exclusive tags.
  6277. (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
  6278. '((:startgroup) ("tag1") ("tag2") (:endgroup))))
  6279. (should
  6280. (equal
  6281. (org-tag-string-to-alist "{ group : tag1 tag2 }")
  6282. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))))
  6283. (ert-deftest test-org/tag-alist-to-string ()
  6284. "Test `org-tag-alist-to-string' specifications."
  6285. (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
  6286. (should (equal (org-tag-alist-to-string '(("tag1" . ?t))) "tag1(t)"))
  6287. (should
  6288. (equal
  6289. (org-tag-alist-to-string
  6290. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6291. "[ group : t1 t2 ]"))
  6292. (should
  6293. (equal (org-tag-alist-to-string
  6294. '((:startgroup) ("tag1") ("tag2") (:endgroup)))
  6295. "{ tag1 tag2 }"))
  6296. (should
  6297. (equal
  6298. (org-tag-alist-to-string
  6299. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))
  6300. "{ group : tag1 tag2 }")))
  6301. (ert-deftest test-org/tag-alist-to-groups ()
  6302. "Test `org-tag-alist-to-groups' specifications."
  6303. (should
  6304. (equal (org-tag-alist-to-groups
  6305. '((:startgroup) ("group") (:grouptags) ("t1") ("t2") (:endgroup)))
  6306. '(("group" "t1" "t2"))))
  6307. (should
  6308. (equal
  6309. (org-tag-alist-to-groups
  6310. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6311. '(("group" "t1" "t2"))))
  6312. (should-not
  6313. (org-tag-alist-to-groups
  6314. '((:startgroup) ("group") ("t1") ("t2") (:endgroup)))))
  6315. (ert-deftest test-org/tag-align ()
  6316. "Test tags alignment."
  6317. ;; Test aligning tags with different display width.
  6318. (should
  6319. ;; 12345678901234567890
  6320. (equal "* Test :abc:"
  6321. (org-test-with-temp-text "* Test :abc:"
  6322. (let ((org-tags-column -20)
  6323. (indent-tabs-mode nil))
  6324. (org-fix-tags-on-the-fly))
  6325. (buffer-string))))
  6326. (should
  6327. ;; 12345678901234567890
  6328. (equal "* Test :日本語:"
  6329. (org-test-with-temp-text "* Test :日本語:"
  6330. (let ((org-tags-column -20)
  6331. (indent-tabs-mode nil))
  6332. (org-fix-tags-on-the-fly))
  6333. (buffer-string))))
  6334. ;; Make sure aligning tags do not skip invisible text.
  6335. (should
  6336. (equal "* [[linkx]] :tag:"
  6337. (org-test-with-temp-text "* [[link<point>]] :tag:"
  6338. (let ((org-tags-column 0))
  6339. (org-fix-tags-on-the-fly)
  6340. (insert "x")
  6341. (buffer-string)))))
  6342. ;; Aligning tags preserve position.
  6343. (should
  6344. (= 6 (org-test-with-temp-text "* 345 <point> :tag:"
  6345. (let ((org-tags-column 78)
  6346. (indent-tabs-mode nil))
  6347. (org-fix-tags-on-the-fly))
  6348. (current-column))))
  6349. ;; Aligning all tags in visible buffer.
  6350. (should
  6351. ;; 12345678901234567890
  6352. (equal (concat "* Level 1 :abc:\n"
  6353. "** Level 2 :def:")
  6354. (org-test-with-temp-text (concat "* Level 1 :abc:\n"
  6355. "** Level 2 :def:")
  6356. (let ((org-tags-column -20)
  6357. (indent-tabs-mode nil))
  6358. ;; (org-align-tags :all) must work even when the point
  6359. ;; is at the end of the buffer.
  6360. (goto-char (point-max))
  6361. (org-align-tags :all))
  6362. (buffer-string)))))
  6363. (ert-deftest test-org/get-tags ()
  6364. "Test `org-get-tags' specifications."
  6365. ;; Standard test.
  6366. (should
  6367. (equal '("foo")
  6368. (org-test-with-temp-text "* Test :foo:" (org-get-tags))))
  6369. (should
  6370. (equal '("foo" "bar")
  6371. (org-test-with-temp-text "* Test :foo:bar:" (org-get-tags))))
  6372. ;; Return nil when there is no tag.
  6373. (should-not
  6374. (org-test-with-temp-text "* Test" (org-get-tags)))
  6375. ;; Tags are inherited from parent headlines.
  6376. (should
  6377. (equal '("tag")
  6378. (let ((org-use-tag-inheritance t))
  6379. (org-test-with-temp-text "* H0 :foo:\n* H1 :tag:\n<point>** H2"
  6380. (org-get-tags)))))
  6381. ;; Tags are inherited from `org-file-tags'.
  6382. (should
  6383. (equal '("tag")
  6384. (org-test-with-temp-text "* H1"
  6385. (let ((org-file-tags '("tag"))
  6386. (org-use-tag-inheritance t))
  6387. (org-get-tags)))))
  6388. ;; Only inherited tags have the `inherited' text property.
  6389. (should
  6390. (get-text-property 0 'inherited
  6391. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6392. (let ((org-use-tag-inheritance t))
  6393. (assoc-string "foo" (org-get-tags))))))
  6394. (should-not
  6395. (get-text-property 0 'inherited
  6396. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6397. (let ((org-use-tag-inheritance t))
  6398. (assoc-string "bar" (org-get-tags))))))
  6399. ;; Obey to `org-use-tag-inheritance'.
  6400. (should-not
  6401. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6402. (let ((org-use-tag-inheritance nil))
  6403. (assoc-string "foo" (org-get-tags)))))
  6404. (should-not
  6405. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6406. (let ((org-use-tag-inheritance nil)
  6407. (org-file-tags '("foo")))
  6408. (assoc-string "foo" (org-get-tags)))))
  6409. (should-not
  6410. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6411. (let ((org-use-tag-inheritance '("bar")))
  6412. (assoc-string "foo" (org-get-tags)))))
  6413. (should
  6414. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6415. (let ((org-use-tag-inheritance '("bar")))
  6416. (assoc-string "bar" (org-get-tags)))))
  6417. (should-not
  6418. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6419. (let ((org-use-tag-inheritance "b.*"))
  6420. (assoc-string "foo" (org-get-tags)))))
  6421. (should
  6422. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6423. (let ((org-use-tag-inheritance "b.*"))
  6424. (assoc-string "bar" (org-get-tags)))))
  6425. ;; When optional argument LOCAL is non-nil, ignore tag inheritance.
  6426. (should
  6427. (equal '("baz")
  6428. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6429. (let ((org-use-tag-inheritance t))
  6430. (org-get-tags nil t)))))
  6431. ;; When optional argument POS is non-nil, get tags there instead.
  6432. (should
  6433. (equal '("foo")
  6434. (org-test-with-temp-text "* H1 :foo:\n* <point>H2 :bar:"
  6435. (org-get-tags 1))))
  6436. ;; Make sure tags excluded from inheritance are returned if local
  6437. (should
  6438. (equal '("foo")
  6439. (org-test-with-temp-text "* Test :foo:"
  6440. (let ((org-use-tag-inheritance t)
  6441. (org-tags-exclude-from-inheritance '("foo")))
  6442. (org-get-tags)))))
  6443. ;; Test the collection of tags from #+filetags and parent tags.
  6444. (should
  6445. (equal '("a" "b" "c" "d")
  6446. (org-test-with-temp-text (concat "#+filetags: a\n"
  6447. "* Level 1 :b:\n"
  6448. "** Level 2 :c:\n"
  6449. "*** Level 3 :d:\n"
  6450. "<point>")
  6451. (let ((org-use-tag-inheritance t))
  6452. (org-mode-restart) ;So that `org-file-tags' get populated from #+filetags
  6453. (org-get-tags)))))
  6454. ;; Pathological case: tagged headline with an empty body.
  6455. (should (org-test-with-temp-text "* :tag:" (org-get-tags))))
  6456. (ert-deftest test-org/set-tags ()
  6457. "Test `org-set-tags' specifications."
  6458. ;; Throw an error on invalid data.
  6459. (should-error
  6460. (org-test-with-temp-text "* H"
  6461. (org-set-tags 'foo)))
  6462. ;; `nil', an empty, and a blank string remove all tags.
  6463. (should
  6464. (equal "* H"
  6465. (org-test-with-temp-text "* H :tag1:tag2:"
  6466. (org-set-tags nil)
  6467. (buffer-string))))
  6468. (should
  6469. (equal "* H"
  6470. (org-test-with-temp-text "* H :tag1:tag2:"
  6471. (org-set-tags "")
  6472. (buffer-string))))
  6473. (should
  6474. (equal "* H"
  6475. (org-test-with-temp-text "* H :tag1:tag2:"
  6476. (org-set-tags " ")
  6477. (buffer-string))))
  6478. ;; If there's nothing to remove, just bail out.
  6479. (should
  6480. (equal "* H"
  6481. (org-test-with-temp-text "* H"
  6482. (org-set-tags nil)
  6483. (buffer-string))))
  6484. (should
  6485. (equal "* "
  6486. (org-test-with-temp-text "* "
  6487. (org-set-tags nil)
  6488. (buffer-string))))
  6489. ;; If DATA is a tag string, set current tags to it, even if it means
  6490. ;; replacing old tags.
  6491. (should
  6492. (equal "* H :tag0:"
  6493. (org-test-with-temp-text "* H :tag1:tag2:"
  6494. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  6495. (buffer-string))))
  6496. (should
  6497. (equal "* H :tag0:"
  6498. (org-test-with-temp-text "* H"
  6499. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  6500. (buffer-string))))
  6501. ;; If DATA is a list, set tags to this list, even if it means
  6502. ;; replacing old tags.
  6503. (should
  6504. (equal "* H :tag0:"
  6505. (org-test-with-temp-text "* H :tag1:tag2:"
  6506. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6507. (buffer-string))))
  6508. (should
  6509. (equal "* H :tag0:"
  6510. (org-test-with-temp-text "* H"
  6511. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6512. (buffer-string))))
  6513. ;; When set, apply `org-tags-sort-function'.
  6514. (should
  6515. (equal "* H :a:b:"
  6516. (org-test-with-temp-text "* H"
  6517. (let ((org-tags-column 1)
  6518. (org-tags-sort-function #'string<))
  6519. (org-set-tags '("b" "a"))
  6520. (buffer-string)))))
  6521. ;; When new tags are identical to the previous ones, still align.
  6522. (should
  6523. (equal "* H :foo:"
  6524. (org-test-with-temp-text "* H :foo:"
  6525. (let ((org-tags-column 1))
  6526. (org-set-tags '("foo"))
  6527. (buffer-string)))))
  6528. ;; When tags have been changed, run `org-after-tags-change-hook'.
  6529. (should
  6530. (catch :return
  6531. (org-test-with-temp-text "* H :foo:"
  6532. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  6533. (org-set-tags '("bar"))
  6534. nil))))
  6535. (should-not
  6536. (catch :return
  6537. (org-test-with-temp-text "* H :foo:"
  6538. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  6539. (org-set-tags '("foo"))
  6540. nil))))
  6541. ;; Special case: handle empty headlines.
  6542. (should
  6543. (equal "* :tag0:"
  6544. (org-test-with-temp-text "* "
  6545. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6546. (buffer-string))))
  6547. ;; Modify buffer only when a tag change happens or alignment is
  6548. ;; done.
  6549. (should-not
  6550. (org-test-with-temp-text "* H :foo:"
  6551. (set-buffer-modified-p nil)
  6552. (let ((org-tags-column 1)) (org-set-tags '("foo")))
  6553. (buffer-modified-p)))
  6554. (should
  6555. (org-test-with-temp-text "* H :foo:"
  6556. (set-buffer-modified-p nil)
  6557. (let ((org-tags-column 10)) (org-set-tags '("foo")))
  6558. (buffer-modified-p)))
  6559. (should
  6560. (org-test-with-temp-text "* H :foo:"
  6561. (set-buffer-modified-p nil)
  6562. (let ((org-tags-column 10)) (org-set-tags '("bar")))
  6563. (buffer-modified-p)))
  6564. ;; Pathological case: when setting tags of a folded headline, do not
  6565. ;; let new tags being sucked into invisibility.
  6566. (should-not
  6567. (org-test-with-temp-text "* H1\nContent\n* H2\n\n Other Content"
  6568. ;; Show only headlines
  6569. (org-content)
  6570. ;; Set NEXT tag on current entry
  6571. (org-set-tags ":NEXT:")
  6572. ;; Move point to that NEXT tag
  6573. (search-forward "NEXT") (backward-word)
  6574. ;; And it should be visible (i.e. no overlays)
  6575. (overlays-at (point)))))
  6576. (ert-deftest test-org/set-tags-command ()
  6577. "Test `org-set-tags-command' specifications"
  6578. ;; Set tags at current headline.
  6579. (should
  6580. (equal "* H1 :foo:"
  6581. (org-test-with-temp-text "* H1"
  6582. (cl-letf (((symbol-function 'completing-read)
  6583. (lambda (&rest args) ":foo:")))
  6584. (let ((org-use-fast-tag-selection nil)
  6585. (org-tags-column 1))
  6586. (org-set-tags-command)))
  6587. (buffer-string))))
  6588. ;; Preserve position when called from the section below.
  6589. (should
  6590. (equal "* H1 :foo:\nContents"
  6591. (org-test-with-temp-text "* H1\n<point>Contents"
  6592. (cl-letf (((symbol-function 'completing-read)
  6593. (lambda (&rest args) ":foo:")))
  6594. (let ((org-use-fast-tag-selection nil)
  6595. (org-tags-column 1))
  6596. (org-set-tags-command)))
  6597. (buffer-string))))
  6598. (should-not
  6599. (equal "* H1 :foo:\nContents2"
  6600. (org-test-with-temp-text "* H1\n<point>Contents2"
  6601. (cl-letf (((symbol-function 'completing-read)
  6602. (lambda (&rest args) ":foo:")))
  6603. (let ((org-use-fast-tag-selection nil)
  6604. (org-tags-column 1))
  6605. (org-set-tags-command)))
  6606. (org-at-heading-p))))
  6607. ;; Strip all forbidden characters from user-entered tags.
  6608. (should
  6609. (equal "* H1 :foo:"
  6610. (org-test-with-temp-text "* H1"
  6611. (cl-letf (((symbol-function 'completing-read)
  6612. (lambda (&rest args) ": foo *:")))
  6613. (let ((org-use-fast-tag-selection nil)
  6614. (org-tags-column 1))
  6615. (org-set-tags-command)))
  6616. (buffer-string))))
  6617. ;; When a region is active and
  6618. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  6619. ;; same value in all headlines in region.
  6620. (should
  6621. (equal "* H1 :foo:\nContents\n* H2 :foo:"
  6622. (org-test-with-temp-text "* H1\nContents\n* H2"
  6623. (cl-letf (((symbol-function 'completing-read)
  6624. (lambda (&rest args) ":foo:")))
  6625. (let ((org-use-fast-tag-selection nil)
  6626. (org-loop-over-headlines-in-active-region t)
  6627. (org-tags-column 1))
  6628. (transient-mark-mode 1)
  6629. (push-mark (point) t t)
  6630. (goto-char (point-max))
  6631. (org-set-tags-command)))
  6632. (buffer-string))))
  6633. (should
  6634. (equal "* H1\nContents\n* H2 :foo:"
  6635. (org-test-with-temp-text "* H1\nContents\n* H2"
  6636. (cl-letf (((symbol-function 'completing-read)
  6637. (lambda (&rest args) ":foo:")))
  6638. (let ((org-use-fast-tag-selection nil)
  6639. (org-loop-over-headlines-in-active-region nil)
  6640. (org-tags-column 1))
  6641. (transient-mark-mode 1)
  6642. (push-mark (point) t t)
  6643. (goto-char (point-max))
  6644. (org-set-tags-command)))
  6645. (buffer-string))))
  6646. ;; With a C-u prefix argument, align all tags in the buffer.
  6647. (should
  6648. (equal "* H1 :foo:\n* H2 :bar:"
  6649. (org-test-with-temp-text "* H1 :foo:\n* H2 :bar:"
  6650. (let ((org-tags-column 1)) (org-set-tags-command '(4)))
  6651. (buffer-string))))
  6652. ;; Point does not move with empty headline.
  6653. (should
  6654. (equal ":foo:"
  6655. (org-test-with-temp-text "* <point>"
  6656. (cl-letf (((symbol-function 'completing-read)
  6657. (lambda (&rest args) ":foo:")))
  6658. (let ((org-use-fast-tag-selection nil)
  6659. (org-tags-column 1))
  6660. (org-set-tags-command)))
  6661. (buffer-substring (point) (line-end-position)))))
  6662. ;; Point does not move at start of line.
  6663. (should
  6664. (equal "* H1 :foo:"
  6665. (org-test-with-temp-text "* H1"
  6666. (cl-letf (((symbol-function 'completing-read)
  6667. (lambda (&rest args) ":foo:")))
  6668. (let ((org-use-fast-tag-selection nil)
  6669. (org-tags-column 1))
  6670. (org-set-tags-command)))
  6671. (buffer-substring (point) (line-end-position)))))
  6672. ;; Point does not move when within *'s.
  6673. (should
  6674. (equal "* H1 :foo:"
  6675. (org-test-with-temp-text "*<point>* H1"
  6676. (cl-letf (((symbol-function 'completing-read)
  6677. (lambda (&rest args) ":foo:")))
  6678. (let ((org-use-fast-tag-selection nil)
  6679. (org-tags-column 1))
  6680. (org-set-tags-command)))
  6681. (buffer-substring (point) (line-end-position)))))
  6682. ;; Point workaround does not get fooled when looking at a space.
  6683. (should
  6684. (equal " b :foo:"
  6685. (org-test-with-temp-text "* a<point> b"
  6686. (cl-letf (((symbol-function 'completing-read)
  6687. (lambda (&rest args) ":foo:")))
  6688. (let ((org-use-fast-tag-selection nil)
  6689. (org-tags-column 1))
  6690. (org-set-tags-command)))
  6691. (buffer-substring (point) (line-end-position))))))
  6692. (ert-deftest test-org/toggle-tag ()
  6693. "Test `org-toggle-tag' specifications."
  6694. ;; Insert missing tag.
  6695. (should
  6696. (equal "* H :tag:"
  6697. (org-test-with-temp-text "* H"
  6698. (let ((org-tags-column 1)) (org-toggle-tag "tag"))
  6699. (buffer-string))))
  6700. (should
  6701. (equal "* H :tag1:tag2:"
  6702. (org-test-with-temp-text "* H :tag1:"
  6703. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  6704. (buffer-string))))
  6705. ;; Remove existing tag.
  6706. (should
  6707. (equal "* H"
  6708. (org-test-with-temp-text "* H :tag:"
  6709. (org-toggle-tag "tag")
  6710. (buffer-string))))
  6711. (should
  6712. (equal "* H :tag1:"
  6713. (org-test-with-temp-text "* H :tag1:tag2:"
  6714. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  6715. (buffer-string))))
  6716. (should
  6717. (equal "* H :tag2:"
  6718. (org-test-with-temp-text "* H :tag1:tag2:"
  6719. (let ((org-tags-column 1)) (org-toggle-tag "tag1"))
  6720. (buffer-string))))
  6721. ;; With optional argument ONOFF set to `on', try to insert the tag,
  6722. ;; even if its already there.
  6723. (should
  6724. (equal "* H :tag:"
  6725. (org-test-with-temp-text "* H"
  6726. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  6727. (buffer-string))))
  6728. (should
  6729. (equal "* H :tag:"
  6730. (org-test-with-temp-text "* H :tag:"
  6731. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  6732. (buffer-string))))
  6733. ;; With optional argument ONOFF set to `off', try to remove the tag,
  6734. ;; even if its not there.
  6735. (should
  6736. (equal "* H"
  6737. (org-test-with-temp-text "* H :tag:"
  6738. (org-toggle-tag "tag" 'off)
  6739. (buffer-string))))
  6740. (should
  6741. (equal "* H :tag:"
  6742. (org-test-with-temp-text "* H :tag:"
  6743. (let ((org-tags-column 1)) (org-toggle-tag "foo" 'off))
  6744. (buffer-string))))
  6745. ;; Special case: Handle properly tag inheritance. In particular, do
  6746. ;; not set inherited tags.
  6747. (should
  6748. (equal "* H1 :tag:\n** H2 :tag2:tag:"
  6749. (org-test-with-temp-text "* H1 :tag:\n** <point>H2 :tag2:"
  6750. (let ((org-use-tag-inheritance t)
  6751. (org-tags-column 1))
  6752. (org-toggle-tag "tag"))
  6753. (buffer-string))))
  6754. (should
  6755. (equal "* H1 :tag1:tag2:\n** H2 :foo:"
  6756. (org-test-with-temp-text "* H1 :tag1:tag2:\n** <point>H2"
  6757. (let ((org-use-tag-inheritance t)
  6758. (org-tags-column 1))
  6759. (org-toggle-tag "foo"))
  6760. (buffer-string)))))
  6761. (ert-deftest test-org/tags-expand ()
  6762. "Test `org-tags-expand' specifications."
  6763. ;; Expand tag groups as a regexp enclosed within curly brackets.
  6764. (should
  6765. (equal "{\\<[ABC]\\>}"
  6766. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6767. (org-mode-restart)
  6768. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  6769. (should
  6770. (equal "{\\<\\(?:Aa\\|Bb\\|Cc\\)\\>}"
  6771. (org-test-with-temp-text "#+TAGS: [ Aa : Bb Cc ]"
  6772. (org-mode-restart)
  6773. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "Aa")))))
  6774. ;; Preserve operator before the regexp.
  6775. (should
  6776. (equal "+{\\<[ABC]\\>}"
  6777. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6778. (org-mode-restart)
  6779. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "+A")))))
  6780. (should
  6781. (equal "-{\\<[ABC]\\>}"
  6782. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6783. (org-mode-restart)
  6784. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "-A")))))
  6785. ;; Handle "|" syntax.
  6786. (should
  6787. (equal "{\\<[ABC]\\>}|D"
  6788. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6789. (org-mode-restart)
  6790. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|D")))))
  6791. ;; Handle nested groups.
  6792. (should
  6793. (equal "{\\<[A-D]\\>}"
  6794. (org-test-with-temp-text "#+TAGS: [ A : B C ]\n#+TAGS: [ B : D ]"
  6795. (org-mode-restart)
  6796. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  6797. ;; Expand multiple occurrences of the same group.
  6798. (should
  6799. (equal "{\\<[ABC]\\>}|{\\<[ABC]\\>}"
  6800. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6801. (org-mode-restart)
  6802. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|A")))))
  6803. ;; Preserve regexp matches.
  6804. (should
  6805. (equal "{A+}"
  6806. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6807. (org-mode-restart)
  6808. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "{A+}"))))))
  6809. ;;; TODO keywords
  6810. (ert-deftest test-org/auto-repeat-maybe ()
  6811. "Test `org-auto-repeat-maybe' specifications."
  6812. ;; Do not auto repeat when there is no valid time stamp with
  6813. ;; a repeater in the entry.
  6814. (should-not
  6815. (string-prefix-p
  6816. "* TODO H"
  6817. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6818. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
  6819. (org-todo "DONE")
  6820. (buffer-string)))))
  6821. (should-not
  6822. (string-prefix-p
  6823. "* TODO H"
  6824. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6825. (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
  6826. (org-todo "DONE")
  6827. (buffer-string)))))
  6828. ;; When switching to DONE state, switch back to first TODO keyword
  6829. ;; in sequence, or the same keyword if they have different types.
  6830. (should
  6831. (string-prefix-p
  6832. "* TODO H"
  6833. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6834. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  6835. (org-todo "DONE")
  6836. (buffer-string)))))
  6837. (should
  6838. (string-prefix-p
  6839. "* KWD1 H"
  6840. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  6841. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  6842. (org-todo "DONE")
  6843. (buffer-string)))))
  6844. (should
  6845. (string-prefix-p
  6846. "* KWD2 H"
  6847. (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
  6848. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  6849. (org-todo "DONE")
  6850. (buffer-string)))))
  6851. ;; If there was no TODO keyword in the first place, do not insert
  6852. ;; any either.
  6853. (should
  6854. (string-prefix-p
  6855. "* H"
  6856. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6857. (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
  6858. (org-todo "DONE")
  6859. (buffer-string)))))
  6860. ;; Revert to REPEAT_TO_STATE, if set.
  6861. (should
  6862. (string-prefix-p
  6863. "* KWD2 H"
  6864. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  6865. (org-test-with-temp-text
  6866. "* KWD2 H
  6867. :PROPERTIES:
  6868. :REPEAT_TO_STATE: KWD2
  6869. :END:
  6870. <2012-03-29 Thu +2y>"
  6871. (org-todo "DONE")
  6872. (buffer-string)))))
  6873. ;; When switching to DONE state, update base date. If there are
  6874. ;; multiple repeated time stamps, update them all.
  6875. (should
  6876. (string-match-p
  6877. "<2014-03-29 .* \\+2y>"
  6878. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6879. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  6880. (org-todo "DONE")
  6881. (buffer-string)))))
  6882. (should
  6883. (string-match-p
  6884. "<2015-03-04 .* \\+1y>"
  6885. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6886. (org-test-with-temp-text
  6887. "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
  6888. (org-todo "DONE")
  6889. (buffer-string)))))
  6890. ;; Throw an error if repeater unit is the hour and no time is
  6891. ;; provided in the time-stamp.
  6892. (should-error
  6893. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6894. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
  6895. (org-todo "DONE")
  6896. (buffer-string))))
  6897. ;; Handle every repeater type using hours step.
  6898. (should
  6899. (string-match-p
  6900. "2014-03-04 .* 02:00"
  6901. (org-test-at-time "<2014-03-04 02:35>"
  6902. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 +8h>"
  6903. (org-todo "DONE")
  6904. (buffer-string)))))
  6905. (should
  6906. (string-match-p
  6907. "2014-03-04 .* 10:00"
  6908. (org-test-at-time "<2014-03-04 02:35>"
  6909. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 ++8h>"
  6910. (org-todo "DONE")
  6911. (buffer-string)))))
  6912. (should
  6913. (string-match-p
  6914. "2014-03-04 .* 10:35"
  6915. (org-test-at-time "<2014-03-04 02:35>"
  6916. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 .+8h>"
  6917. (org-todo "DONE")
  6918. (buffer-string)))))
  6919. ;; Do not repeat inactive time stamps with a repeater.
  6920. (should-not
  6921. (string-match-p
  6922. "\\[2014-03-29 .* \\+2y\\]"
  6923. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6924. (org-test-with-temp-text
  6925. "* TODO H\n[2012-03-29 Thu. +2y]"
  6926. (org-todo "DONE")
  6927. (buffer-string)))))
  6928. ;; Do not repeat commented time stamps.
  6929. (should-not
  6930. (string-prefix-p
  6931. "<2015-03-04 .* \\+1y>"
  6932. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6933. (org-test-with-temp-text
  6934. "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
  6935. (org-todo "DONE")
  6936. (buffer-string)))))
  6937. (should-not
  6938. (string-prefix-p
  6939. "<2015-03-04 .* \\+1y>"
  6940. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6941. (org-test-with-temp-text
  6942. "* TODO H
  6943. <2012-03-29 Thu. +2y>
  6944. #+BEGIN_EXAMPLE
  6945. <2014-03-04 Tue +1y>
  6946. #+END_EXAMPLE"
  6947. (org-todo "DONE")
  6948. (buffer-string)))))
  6949. ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
  6950. ;; entry, record time of last repeat.
  6951. (should-not
  6952. (string-match-p
  6953. ":LAST_REPEAT:"
  6954. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  6955. (org-log-repeat nil))
  6956. (cl-letf (((symbol-function 'org-add-log-setup)
  6957. (lambda (&rest args) nil)))
  6958. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  6959. (org-todo "DONE")
  6960. (buffer-string))))))
  6961. (should
  6962. (string-match-p
  6963. ":LAST_REPEAT:"
  6964. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  6965. (org-log-repeat t))
  6966. (cl-letf (((symbol-function 'org-add-log-setup)
  6967. (lambda (&rest args) nil)))
  6968. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  6969. (org-todo "DONE")
  6970. (buffer-string))))))
  6971. (should
  6972. (string-match-p
  6973. ":LAST_REPEAT:"
  6974. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6975. (cl-letf (((symbol-function 'org-add-log-setup)
  6976. (lambda (&rest args) nil)))
  6977. (org-test-with-temp-text
  6978. "* TODO H\n<2012-03-29 Thu +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
  6979. (org-todo "DONE")
  6980. (buffer-string))))))
  6981. ;; When a SCHEDULED entry has no repeater, remove it upon repeating
  6982. ;; the entry as it is no longer relevant.
  6983. (should-not
  6984. (string-match-p
  6985. "^SCHEDULED:"
  6986. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6987. (org-test-with-temp-text
  6988. "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
  6989. (org-todo "DONE")
  6990. (buffer-string)))))
  6991. ;; Properly advance repeater even when a clock entry is specified
  6992. ;; and `org-log-repeat' is nil.
  6993. (should
  6994. (string-match-p
  6995. "SCHEDULED: <2014-03-29"
  6996. (let ((org-log-repeat nil)
  6997. (org-todo-keywords '((sequence "TODO" "DONE"))))
  6998. (org-test-with-temp-text
  6999. "* TODO H
  7000. SCHEDULED: <2012-03-29 Thu +2y>
  7001. CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] => 6:40"
  7002. (org-todo "DONE")
  7003. (buffer-string))))))
  7004. ;;; Timestamps API
  7005. (ert-deftest test-org/at-timestamp-p ()
  7006. "Test `org-at-timestamp-p' specifications."
  7007. (should
  7008. (org-test-with-temp-text "<2012-03-29 Thu>"
  7009. (org-at-timestamp-p)))
  7010. (should-not
  7011. (org-test-with-temp-text "2012-03-29 Thu"
  7012. (org-at-timestamp-p)))
  7013. ;; Test return values.
  7014. (should
  7015. (eq 'bracket
  7016. (org-test-with-temp-text "<2012-03-29 Thu>"
  7017. (org-at-timestamp-p))))
  7018. (should
  7019. (eq 'year
  7020. (org-test-with-temp-text "<<point>2012-03-29 Thu>"
  7021. (org-at-timestamp-p))))
  7022. (should
  7023. (eq 'month
  7024. (org-test-with-temp-text "<2012-<point>03-29 Thu>"
  7025. (org-at-timestamp-p))))
  7026. (should
  7027. (eq 'day
  7028. (org-test-with-temp-text "<2012-03-<point>29 Thu>"
  7029. (org-at-timestamp-p))))
  7030. (should
  7031. (eq 'day
  7032. (org-test-with-temp-text "<2012-03-29 T<point>hu>"
  7033. (org-at-timestamp-p))))
  7034. (should
  7035. (wholenump
  7036. (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
  7037. (org-at-timestamp-p))))
  7038. (should
  7039. (eq 'bracket
  7040. (org-test-with-temp-text "<2012-03-29 Thu<point>>"
  7041. (org-at-timestamp-p))))
  7042. (should
  7043. (eq 'after
  7044. (org-test-with-temp-text "<2012-03-29 Thu><point>»"
  7045. (org-at-timestamp-p))))
  7046. ;; Test `inactive' optional argument.
  7047. (should
  7048. (org-test-with-temp-text "[2012-03-29 Thu]"
  7049. (org-at-timestamp-p 'inactive)))
  7050. (should-not
  7051. (org-test-with-temp-text "[2012-03-29 Thu]"
  7052. (org-at-timestamp-p)))
  7053. ;; When optional argument is `agenda', recognize time-stamps in
  7054. ;; planning info line, property drawers and clocks.
  7055. (should
  7056. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7057. (org-at-timestamp-p 'agenda)))
  7058. (should-not
  7059. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7060. (org-at-timestamp-p)))
  7061. (should
  7062. (org-test-with-temp-text
  7063. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7064. (org-at-timestamp-p 'agenda)))
  7065. (should-not
  7066. (org-test-with-temp-text
  7067. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7068. (org-at-timestamp-p)))
  7069. (should
  7070. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7071. (let ((org-agenda-include-inactive-timestamps t))
  7072. (org-at-timestamp-p 'agenda))))
  7073. (should-not
  7074. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7075. (let ((org-agenda-include-inactive-timestamps t))
  7076. (org-at-timestamp-p))))
  7077. (should-not
  7078. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7079. (let ((org-agenda-include-inactive-timestamps t))
  7080. (org-at-timestamp-p 'inactive))))
  7081. ;; When optional argument is `lax', match any part of the document
  7082. ;; with Org timestamp syntax.
  7083. (should
  7084. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7085. (org-at-timestamp-p 'lax)))
  7086. (should-not
  7087. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7088. (org-at-timestamp-p)))
  7089. (should
  7090. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7091. (org-at-timestamp-p 'lax)))
  7092. (should-not
  7093. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7094. (org-at-timestamp-p)))
  7095. (should
  7096. (org-test-with-temp-text
  7097. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7098. (org-at-timestamp-p 'lax)))
  7099. (should-not
  7100. (org-test-with-temp-text
  7101. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7102. (org-at-timestamp-p)))
  7103. ;; Optional argument `lax' also matches inactive timestamps.
  7104. (should
  7105. (org-test-with-temp-text "# [2012-03-29 Thu]<point>"
  7106. (org-at-timestamp-p 'lax))))
  7107. (ert-deftest test-org/time-stamp ()
  7108. "Test `org-time-stamp' specifications."
  7109. ;; Insert chosen time stamp at point.
  7110. (should
  7111. (string-match
  7112. "Te<2014-03-04 .*?>xt"
  7113. (org-test-with-temp-text "Te<point>xt"
  7114. (cl-letf (((symbol-function 'org-read-date)
  7115. (lambda (&rest args)
  7116. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7117. (org-time-stamp nil)
  7118. (buffer-string)))))
  7119. ;; With a prefix argument, also insert time.
  7120. (should
  7121. (string-match
  7122. "Te<2014-03-04 .*? 00:41>xt"
  7123. (org-test-with-temp-text "Te<point>xt"
  7124. (cl-letf (((symbol-function 'org-read-date)
  7125. (lambda (&rest args)
  7126. (apply #'encode-time
  7127. (org-parse-time-string "2014-03-04 00:41")))))
  7128. (org-time-stamp '(4))
  7129. (buffer-string)))))
  7130. ;; With two universal prefix arguments, insert an active timestamp
  7131. ;; with the current time without prompting the user.
  7132. (should
  7133. (string-match
  7134. "Te<2014-03-04 .*? 00:41>xt"
  7135. (org-test-with-temp-text "Te<point>xt"
  7136. (org-test-at-time "2014-03-04 00:41"
  7137. (org-time-stamp '(16))
  7138. (buffer-string)))))
  7139. ;; When optional argument is non-nil, insert an inactive timestamp.
  7140. (should
  7141. (string-match
  7142. "Te\\[2014-03-04 .*?\\]xt"
  7143. (org-test-with-temp-text "Te<point>xt"
  7144. (cl-letf (((symbol-function 'org-read-date)
  7145. (lambda (&rest args)
  7146. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7147. (org-time-stamp nil t)
  7148. (buffer-string)))))
  7149. ;; When called from a timestamp, replace existing one.
  7150. (should
  7151. (string-match
  7152. "<2014-03-04 .*?>"
  7153. (org-test-with-temp-text "<2012-03-29<point> thu.>"
  7154. (cl-letf (((symbol-function 'org-read-date)
  7155. (lambda (&rest args)
  7156. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7157. (org-time-stamp nil)
  7158. (buffer-string)))))
  7159. (should
  7160. (string-match
  7161. "<2014-03-04 .*?>--<2014-03-04 .*?>"
  7162. (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
  7163. (cl-letf (((symbol-function 'org-read-date)
  7164. (lambda (&rest args)
  7165. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7166. (org-time-stamp nil)
  7167. (buffer-string)))))
  7168. ;; When replacing a timestamp, preserve repeater, if any.
  7169. (should
  7170. (string-match
  7171. "<2014-03-04 .*? \\+2y>"
  7172. (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
  7173. (cl-letf (((symbol-function 'org-read-date)
  7174. (lambda (&rest args)
  7175. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7176. (org-time-stamp nil)
  7177. (buffer-string)))))
  7178. ;; When called twice in a raw, build a date range.
  7179. (should
  7180. (string-match
  7181. "<2012-03-29 .*?>--<2014-03-04 .*?>"
  7182. (org-test-with-temp-text "<2012-03-29 thu.><point>"
  7183. (cl-letf (((symbol-function 'org-read-date)
  7184. (lambda (&rest args)
  7185. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7186. (let ((last-command 'org-time-stamp)
  7187. (this-command 'org-time-stamp))
  7188. (org-time-stamp nil))
  7189. (buffer-string))))))
  7190. (ert-deftest test-org/timestamp-has-time-p ()
  7191. "Test `org-timestamp-has-time-p' specifications."
  7192. ;; With time.
  7193. (should
  7194. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7195. (org-timestamp-has-time-p (org-element-context))))
  7196. ;; Without time.
  7197. (should-not
  7198. (org-test-with-temp-text "<2012-03-29 Thu>"
  7199. (org-timestamp-has-time-p (org-element-context)))))
  7200. (ert-deftest test-org/get-repeat ()
  7201. "Test `org-get-repeat' specifications."
  7202. (should
  7203. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
  7204. (org-get-repeat)))
  7205. (should-not
  7206. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
  7207. (org-get-repeat)))
  7208. ;; Return proper repeat string.
  7209. (should
  7210. (equal "+2y"
  7211. (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
  7212. (org-get-repeat))))
  7213. ;; Prevent false positive (commented or verbatim time stamps)
  7214. (should-not
  7215. (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
  7216. (org-get-repeat)))
  7217. (should-not
  7218. (org-test-with-temp-text
  7219. "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
  7220. (org-get-repeat)))
  7221. ;; Return nil when called before first heading.
  7222. (should-not
  7223. (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
  7224. (org-get-repeat)))
  7225. ;; When called with an optional argument, extract repeater from that
  7226. ;; string instead.
  7227. (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
  7228. (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
  7229. (ert-deftest test-org/timestamp-format ()
  7230. "Test `org-timestamp-format' specifications."
  7231. ;; Regular test.
  7232. (should
  7233. (equal
  7234. "2012-03-29 16:40"
  7235. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7236. (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
  7237. ;; Range end.
  7238. (should
  7239. (equal
  7240. "2012-03-29"
  7241. (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
  7242. (org-timestamp-format (org-element-context) "%Y-%m-%d" t)))))
  7243. (ert-deftest test-org/timestamp-split-range ()
  7244. "Test `org-timestamp-split-range' specifications."
  7245. ;; Extract range start (active).
  7246. (should
  7247. (equal '(2012 3 29)
  7248. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7249. (let ((ts (org-timestamp-split-range (org-element-context))))
  7250. (mapcar (lambda (p) (org-element-property p ts))
  7251. '(:year-end :month-end :day-end))))))
  7252. ;; Extract range start (inactive)
  7253. (should
  7254. (equal '(2012 3 29)
  7255. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7256. (let ((ts (org-timestamp-split-range (org-element-context))))
  7257. (mapcar (lambda (p) (org-element-property p ts))
  7258. '(:year-end :month-end :day-end))))))
  7259. ;; Extract range end (active).
  7260. (should
  7261. (equal '(2012 3 30)
  7262. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7263. (let ((ts (org-timestamp-split-range
  7264. (org-element-context) t)))
  7265. (mapcar (lambda (p) (org-element-property p ts))
  7266. '(:year-end :month-end :day-end))))))
  7267. ;; Extract range end (inactive)
  7268. (should
  7269. (equal '(2012 3 30)
  7270. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7271. (let ((ts (org-timestamp-split-range
  7272. (org-element-context) t)))
  7273. (mapcar (lambda (p) (org-element-property p ts))
  7274. '(:year-end :month-end :day-end))))))
  7275. ;; Return the timestamp if not a range.
  7276. (should
  7277. (org-test-with-temp-text "[2012-03-29 Thu]"
  7278. (let* ((ts-orig (org-element-context))
  7279. (ts-copy (org-timestamp-split-range ts-orig)))
  7280. (eq ts-orig ts-copy))))
  7281. (should
  7282. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7283. (let* ((ts-orig (org-element-context))
  7284. (ts-copy (org-timestamp-split-range ts-orig)))
  7285. (eq ts-orig ts-copy)))))
  7286. (ert-deftest test-org/timestamp-translate ()
  7287. "Test `org-timestamp-translate' specifications."
  7288. ;; Translate whole date range.
  7289. (should
  7290. (equal "<29>--<30>"
  7291. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7292. (let ((org-display-custom-times t)
  7293. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7294. (org-timestamp-translate (org-element-context))))))
  7295. ;; Translate date range start.
  7296. (should
  7297. (equal "<29>"
  7298. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7299. (let ((org-display-custom-times t)
  7300. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7301. (org-timestamp-translate (org-element-context) 'start)))))
  7302. ;; Translate date range end.
  7303. (should
  7304. (equal "<30>"
  7305. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7306. (let ((org-display-custom-times t)
  7307. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7308. (org-timestamp-translate (org-element-context) 'end)))))
  7309. ;; Translate time range.
  7310. (should
  7311. (equal "<08>--<16>"
  7312. (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
  7313. (let ((org-display-custom-times t)
  7314. (org-time-stamp-custom-formats '("<%d>" . "<%H>")))
  7315. (org-timestamp-translate (org-element-context))))))
  7316. ;; Translate non-range timestamp.
  7317. (should
  7318. (equal "<29>"
  7319. (org-test-with-temp-text "<2012-03-29 Thu>"
  7320. (let ((org-display-custom-times t)
  7321. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7322. (org-timestamp-translate (org-element-context))))))
  7323. ;; Do not change `diary' timestamps.
  7324. (should
  7325. (equal "<%%(org-float t 4 2)>"
  7326. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7327. (let ((org-display-custom-times t)
  7328. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7329. (org-timestamp-translate (org-element-context)))))))
  7330. (ert-deftest test-org/timestamp-from-string ()
  7331. "Test `org-timestamp-from-string' specifications."
  7332. ;; Return nil if argument is not a valid Org timestamp.
  7333. (should-not (org-timestamp-from-string ""))
  7334. (should-not (org-timestamp-from-string nil))
  7335. (should-not (org-timestamp-from-string "<2012-03-29"))
  7336. ;; Otherwise, return a valid Org timestamp object.
  7337. (should
  7338. (string-match-p "<2012-03-29 .+>"
  7339. (org-element-interpret-data
  7340. (org-timestamp-from-string "<2012-03-29 Thu>"))))
  7341. (should
  7342. (string-match-p "[2014-03-04 .+]"
  7343. (org-element-interpret-data
  7344. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  7345. (ert-deftest test-org/timestamp-from-time ()
  7346. "Test `org-timestamp-from-time' specifications."
  7347. ;; Standard test.
  7348. (should
  7349. (string-match-p
  7350. "<2012-03-29 .+>"
  7351. (org-element-interpret-data
  7352. (org-timestamp-from-time
  7353. (apply #'encode-time
  7354. (org-parse-time-string "<2012-03-29 Thu 16:40>"))))))
  7355. ;; When optional argument WITH-TIME is non-nil, provide time
  7356. ;; information.
  7357. (should
  7358. (string-match-p
  7359. "<2012-03-29 .+ 16:40>"
  7360. (org-element-interpret-data
  7361. (org-timestamp-from-time
  7362. (apply #'encode-time
  7363. (org-parse-time-string "<2012-03-29 Thu 16:40>"))
  7364. t))))
  7365. ;; When optional argument INACTIVE is non-nil, return an inactive
  7366. ;; timestamp.
  7367. (should
  7368. (string-match-p
  7369. "[2012-03-29 .+]"
  7370. (org-element-interpret-data
  7371. (org-timestamp-from-time
  7372. (apply #'encode-time
  7373. (org-parse-time-string "<2012-03-29 Thu 16:40>"))
  7374. nil t)))))
  7375. (ert-deftest test-org/timestamp-to-time ()
  7376. "Test `org-timestamp-to-time' specifications."
  7377. (should
  7378. (equal "2014-03-04"
  7379. (format-time-string
  7380. "%Y-%m-%d"
  7381. (org-timestamp-to-time
  7382. (org-timestamp-from-string "<2014-03-04 Tue>")))))
  7383. (should
  7384. (equal "2014-03-04"
  7385. (format-time-string
  7386. "%Y-%m-%d"
  7387. (org-timestamp-to-time
  7388. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  7389. (should
  7390. (equal "2012-03-29 08:30"
  7391. (format-time-string
  7392. "%Y-%m-%d %H:%M"
  7393. (org-timestamp-to-time
  7394. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")))))
  7395. (should
  7396. (equal "2012-03-29"
  7397. (format-time-string
  7398. "%Y-%m-%d"
  7399. (org-timestamp-to-time
  7400. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")))))
  7401. (should
  7402. (equal "2012-03-29"
  7403. (format-time-string
  7404. "%Y-%m-%d"
  7405. (org-timestamp-to-time
  7406. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")))))
  7407. ;; When optional argument END is non-nil, use end of date range or
  7408. ;; time range.
  7409. (should
  7410. (equal "2012-03-29 16:40"
  7411. (format-time-string
  7412. "%Y-%m-%d %H:%M"
  7413. (org-timestamp-to-time
  7414. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")
  7415. t))))
  7416. (should
  7417. (equal "2014-03-04"
  7418. (format-time-string
  7419. "%Y-%m-%d"
  7420. (org-timestamp-to-time
  7421. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")
  7422. t))))
  7423. (should
  7424. (equal "2014-03-04"
  7425. (format-time-string
  7426. "%Y-%m-%d"
  7427. (org-timestamp-to-time
  7428. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")
  7429. t)))))
  7430. ;;; Visibility
  7431. (ert-deftest test-org/hide-drawer-toggle ()
  7432. "Test `org-hide-drawer-toggle' specifications."
  7433. ;; Error when not at a drawer.
  7434. (should-error
  7435. (org-test-with-temp-text ":fake-drawer:\ncontents"
  7436. (org-hide-drawer-toggle 'off)
  7437. (get-char-property (line-end-position) 'invisible)))
  7438. (should-error
  7439. (org-test-with-temp-text
  7440. "#+begin_example\n<point>:D:\nc\n:END:\n#+end_example"
  7441. (org-hide-drawer-toggle t)))
  7442. ;; Hide drawer.
  7443. (should
  7444. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7445. (org-hide-drawer-toggle)
  7446. (get-char-property (line-end-position) 'invisible)))
  7447. ;; Show drawer unconditionally when optional argument is `off'.
  7448. (should-not
  7449. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7450. (org-hide-drawer-toggle)
  7451. (org-hide-drawer-toggle 'off)
  7452. (get-char-property (line-end-position) 'invisible)))
  7453. ;; Hide drawer unconditionally when optional argument is non-nil.
  7454. (should
  7455. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7456. (org-hide-drawer-toggle t)
  7457. (get-char-property (line-end-position) 'invisible)))
  7458. ;; Do not hide drawer when called from final blank lines.
  7459. (should-not
  7460. (org-test-with-temp-text ":drawer:\ncontents\n:end:\n\n<point>"
  7461. (org-hide-drawer-toggle)
  7462. (goto-char (point-min))
  7463. (get-char-property (line-end-position) 'invisible)))
  7464. ;; Don't leave point in an invisible part of the buffer when hiding
  7465. ;; a drawer away.
  7466. (should-not
  7467. (org-test-with-temp-text ":drawer:\ncontents\n<point>:end:"
  7468. (org-hide-drawer-toggle)
  7469. (get-char-property (point) 'invisible))))
  7470. (ert-deftest test-org/hide-block-toggle ()
  7471. "Test `org-hide-block-toggle' specifications."
  7472. ;; Error when not at a block.
  7473. (should-error
  7474. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
  7475. (org-hide-block-toggle 'off)
  7476. (get-char-property (line-end-position) 'invisible)))
  7477. ;; Hide block.
  7478. (should
  7479. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  7480. (org-hide-block-toggle)
  7481. (get-char-property (line-end-position) 'invisible)))
  7482. (should
  7483. (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
  7484. (org-hide-block-toggle)
  7485. (get-char-property (line-end-position) 'invisible)))
  7486. ;; Show block unconditionally when optional argument is `off'.
  7487. (should-not
  7488. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7489. (org-hide-block-toggle)
  7490. (org-hide-block-toggle 'off)
  7491. (get-char-property (line-end-position) 'invisible)))
  7492. (should-not
  7493. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7494. (org-hide-block-toggle 'off)
  7495. (get-char-property (line-end-position) 'invisible)))
  7496. ;; Hide block unconditionally when optional argument is non-nil.
  7497. (should
  7498. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7499. (org-hide-block-toggle t)
  7500. (get-char-property (line-end-position) 'invisible)))
  7501. (should
  7502. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7503. (org-hide-block-toggle)
  7504. (org-hide-block-toggle t)
  7505. (get-char-property (line-end-position) 'invisible)))
  7506. ;; Do not hide block when called from final blank lines.
  7507. (should-not
  7508. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
  7509. (org-hide-block-toggle)
  7510. (goto-char (point-min))
  7511. (get-char-property (line-end-position) 'invisible)))
  7512. ;; Don't leave point in an invisible part of the buffer when hiding
  7513. ;; a block away.
  7514. (should-not
  7515. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
  7516. (org-hide-block-toggle)
  7517. (get-char-property (point) 'invisible))))
  7518. (ert-deftest test-org/hide-block-toggle-maybe ()
  7519. "Test `org-hide-block-toggle-maybe' specifications."
  7520. (should
  7521. (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
  7522. (org-hide-block-toggle-maybe)))
  7523. (should-not
  7524. (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
  7525. (ert-deftest test-org/show-set-visibility ()
  7526. "Test `org-show-set-visibility' specifications."
  7527. ;; Do not throw an error before first heading.
  7528. (should
  7529. (org-test-with-temp-text "Preamble\n* Headline"
  7530. (org-show-set-visibility 'tree)
  7531. t))
  7532. ;; Test all visibility spans, both on headline and in entry.
  7533. (let ((list-visible-lines
  7534. (lambda (state headerp)
  7535. (org-test-with-temp-text "* Grandmother (0)
  7536. ** Uncle (1)
  7537. *** Heir (2)
  7538. ** Father (3)
  7539. Ancestor text (4)
  7540. *** Sister (5)
  7541. Sibling text (6)
  7542. *** Self (7)
  7543. Match (8)
  7544. **** First born (9)
  7545. Child text (10)
  7546. **** The other child (11)
  7547. *** Brother (12)
  7548. ** Aunt (13)
  7549. "
  7550. (org-cycle t)
  7551. (search-forward (if headerp "Self" "Match"))
  7552. (org-show-set-visibility state)
  7553. (goto-char (point-min))
  7554. (let (result (line 0))
  7555. (while (not (eobp))
  7556. (unless (org-invisible-p2) (push line result))
  7557. (cl-incf line)
  7558. (forward-line))
  7559. (nreverse result))))))
  7560. (should (equal '(0 7) (funcall list-visible-lines 'minimal t)))
  7561. (should (equal '(0 7 8) (funcall list-visible-lines 'minimal nil)))
  7562. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local t)))
  7563. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local nil)))
  7564. (should (equal '(0 3 7) (funcall list-visible-lines 'ancestors t)))
  7565. (should (equal '(0 3 7 8) (funcall list-visible-lines 'ancestors nil)))
  7566. (should (equal '(0 3 5 7 12) (funcall list-visible-lines 'lineage t)))
  7567. (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines 'lineage nil)))
  7568. (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines 'tree t)))
  7569. (should (equal '(0 1 3 5 7 8 9 11 12 13)
  7570. (funcall list-visible-lines 'tree nil)))
  7571. (should (equal '(0 1 3 4 5 7 12 13)
  7572. (funcall list-visible-lines 'canonical t)))
  7573. (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
  7574. (funcall list-visible-lines 'canonical nil))))
  7575. ;; When point is hidden in a drawer or a block, make sure to make it
  7576. ;; visible.
  7577. (should-not
  7578. (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
  7579. (org-hide-block-toggle)
  7580. (search-forward "Text")
  7581. (org-show-set-visibility 'minimal)
  7582. (org-invisible-p2)))
  7583. (should-not
  7584. (org-test-with-temp-text ":DRAWER:\nText\n:END:"
  7585. (org-hide-drawer-toggle)
  7586. (search-forward "Text")
  7587. (org-show-set-visibility 'minimal)
  7588. (org-invisible-p2)))
  7589. (should-not
  7590. (org-test-with-temp-text
  7591. "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
  7592. (org-hide-drawer-toggle)
  7593. (forward-line -1)
  7594. (org-hide-block-toggle)
  7595. (search-forward "Text")
  7596. (org-show-set-visibility 'minimal)
  7597. (org-invisible-p2))))
  7598. (defun test-org/copy-visible ()
  7599. "Test `org-copy-visible' specifications."
  7600. (should
  7601. (equal "Foo"
  7602. (org-test-with-temp-text "Foo"
  7603. (let ((kill-ring nil))
  7604. (org-copy-visible (point-min) (point-max))
  7605. (current-kill 0 t)))))
  7606. ;; Skip invisible characters by text property.
  7607. (should
  7608. (equal "Foo"
  7609. (org-test-with-temp-text #("F<hidden>oo" 1 7 (invisible t))
  7610. (let ((kill-ring nil))
  7611. (org-copy-visible (point-min) (point-max))
  7612. (current-kill 0 t)))))
  7613. ;; Skip invisible characters by overlay.
  7614. (should
  7615. (equal "Foo"
  7616. (org-test-with-temp-text "F<hidden>oo"
  7617. (let ((o (make-overlay 2 10)))
  7618. (overlay-put o 'invisible t))
  7619. (let ((kill-ring nil))
  7620. (org-copy-visible (point-min) (point-max))
  7621. (current-kill 0 t)))))
  7622. ;; Handle invisible characters at the beginning and the end of the
  7623. ;; buffer.
  7624. (should
  7625. (equal "Foo"
  7626. (org-test-with-temp-text #("<hidden>Foo" 0 8 (invisible t))
  7627. (let ((kill-ring nil))
  7628. (org-copy-visible (point-min) (point-max))
  7629. (current-kill 0 t)))))
  7630. (should
  7631. (equal "Foo"
  7632. (org-test-with-temp-text #("Foo<hidden>" 3 11 (invisible t))
  7633. (let ((kill-ring nil))
  7634. (org-copy-visible (point-min) (point-max))
  7635. (current-kill 0 t)))))
  7636. ;; Handle multiple visible parts.
  7637. (should
  7638. (equal "abc"
  7639. (org-test-with-temp-text
  7640. #("aXbXc" 1 2 (invisible t) 3 4 (invisible t))
  7641. (let ((kill-ring nil))
  7642. (org-copy-visible (point-min) (point-max))
  7643. (current-kill 0 t))))))
  7644. (ert-deftest test-org/set-visibility-according-to-property ()
  7645. "Test `org-set-visibility-according-to-property' specifications."
  7646. ;; "folded" state.
  7647. (should
  7648. (org-test-with-temp-text
  7649. "
  7650. * a
  7651. :PROPERTIES:
  7652. :VISIBILITY: folded
  7653. :END:
  7654. ** <point>b"
  7655. (org-set-visibility-according-to-property)
  7656. (invisible-p (point))))
  7657. ;; "children" state.
  7658. (should
  7659. (org-test-with-temp-text
  7660. "
  7661. * a
  7662. :PROPERTIES:
  7663. :VISIBILITY: children
  7664. :END:
  7665. ** b
  7666. <point>Contents
  7667. ** c"
  7668. (org-set-visibility-according-to-property)
  7669. (invisible-p (point))))
  7670. (should
  7671. (org-test-with-temp-text
  7672. "
  7673. * a
  7674. :PROPERTIES:
  7675. :VISIBILITY: children
  7676. :END:
  7677. ** b
  7678. Contents
  7679. *** <point>c"
  7680. (org-set-visibility-according-to-property)
  7681. (invisible-p (point))))
  7682. ;; "content" state.
  7683. (should
  7684. (org-test-with-temp-text
  7685. "
  7686. * a
  7687. :PROPERTIES:
  7688. :VISIBILITY: content
  7689. :END:
  7690. ** b
  7691. <point>Contents
  7692. *** c"
  7693. (org-set-visibility-according-to-property)
  7694. (invisible-p (point))))
  7695. (should
  7696. (org-test-with-temp-text
  7697. "
  7698. * a
  7699. :PROPERTIES:
  7700. :VISIBILITY: content
  7701. :END:
  7702. ** b
  7703. Contents
  7704. *** <point>c"
  7705. (org-set-visibility-according-to-property)
  7706. (not (invisible-p (point)))))
  7707. ;; "showall" state.
  7708. (should
  7709. (org-test-with-temp-text
  7710. "
  7711. * a
  7712. :PROPERTIES:
  7713. :VISIBILITY: showall
  7714. :END:
  7715. ** b
  7716. <point>Contents
  7717. *** c"
  7718. (org-set-visibility-according-to-property)
  7719. (not (invisible-p (point)))))
  7720. (should
  7721. (org-test-with-temp-text
  7722. "
  7723. * a
  7724. :PROPERTIES:
  7725. :VISIBILITY: showall
  7726. :END:
  7727. ** b
  7728. Contents
  7729. *** <point>c"
  7730. (org-set-visibility-according-to-property)
  7731. (not (invisible-p (point)))))
  7732. ;; When VISIBILITY properties are nested, ignore inner ones.
  7733. (should
  7734. (org-test-with-temp-text
  7735. "
  7736. * A
  7737. :PROPERTIES:
  7738. :VISIBILITY: folded
  7739. :END:
  7740. ** <point>B
  7741. :PROPERTIES:
  7742. :VISIBILITY: folded
  7743. :END:"
  7744. (org-set-visibility-according-to-property)
  7745. (invisible-p (point)))))
  7746. (ert-deftest test-org/visibility-show-branches ()
  7747. "Test visibility of inline archived subtrees."
  7748. (org-test-with-temp-text
  7749. "* Foo<point>
  7750. ** Bar :ARCHIVE:
  7751. *** Baz
  7752. "
  7753. (org-kill-note-or-show-branches)
  7754. (should (org-invisible-p (- (point-max) 2)))))
  7755. ;;; Yank and Kill
  7756. (ert-deftest test-org/paste-subtree ()
  7757. "Test `org-paste-subtree' specifications."
  7758. ;; Return an error if text to yank is not a set of subtrees.
  7759. (should-error (org-paste-subtree nil "Text"))
  7760. ;; Adjust level according to current one.
  7761. (should
  7762. (equal "* H\n* Text\n"
  7763. (org-test-with-temp-text "* H\n<point>"
  7764. (org-paste-subtree nil "* Text")
  7765. (buffer-string))))
  7766. (should
  7767. (equal "* H1\n** H2\n** Text\n"
  7768. (org-test-with-temp-text "* H1\n** H2\n<point>"
  7769. (org-paste-subtree nil "* Text")
  7770. (buffer-string))))
  7771. ;; When not on a heading, move to next heading before yanking.
  7772. (should
  7773. (equal "* H1\nParagraph\n* Text\n* H2"
  7774. (org-test-with-temp-text "* H1\n<point>Paragraph\n* H2"
  7775. (org-paste-subtree nil "* Text")
  7776. (buffer-string))))
  7777. ;; If point is between two headings, use the deepest level.
  7778. (should
  7779. (equal "* H1\n\n* Text\n* H2"
  7780. (org-test-with-temp-text "* H1\n<point>\n* H2"
  7781. (org-paste-subtree nil "* Text")
  7782. (buffer-string))))
  7783. (should
  7784. (equal "** H1\n\n** Text\n* H2"
  7785. (org-test-with-temp-text "** H1\n<point>\n* H2"
  7786. (org-paste-subtree nil "* Text")
  7787. (buffer-string))))
  7788. (should
  7789. (equal "* H1\n\n** Text\n** H2"
  7790. (org-test-with-temp-text "* H1\n<point>\n** H2"
  7791. (org-paste-subtree nil "* Text")
  7792. (buffer-string))))
  7793. ;; When on an empty heading, after the stars, deduce the new level
  7794. ;; from the number of stars.
  7795. (should
  7796. (equal "*** Text\n"
  7797. (org-test-with-temp-text "*** <point>"
  7798. (org-paste-subtree nil "* Text")
  7799. (buffer-string))))
  7800. ;; Optional argument LEVEL forces a level for the subtree.
  7801. (should
  7802. (equal "* H\n*** Text\n"
  7803. (org-test-with-temp-text "* H<point>"
  7804. (org-paste-subtree 3 "* Text")
  7805. (buffer-string)))))
  7806. (ert-deftest test-org/cut-and-paste-subtree ()
  7807. "Test `org-cut-subtree' and `org-paste-subtree'."
  7808. (should
  7809. (equal
  7810. "* Two
  7811. two
  7812. * One
  7813. "
  7814. (org-test-with-temp-text
  7815. "* One
  7816. <point>* Two
  7817. two
  7818. "
  7819. (call-interactively #'org-cut-subtree)
  7820. (goto-char (point-min))
  7821. (call-interactively #'org-paste-subtree)
  7822. (buffer-string))))
  7823. (should
  7824. (equal
  7825. "* One
  7826. * Two
  7827. "
  7828. (org-test-with-temp-text
  7829. "* One
  7830. <point>* Two
  7831. "
  7832. (call-interactively #'org-cut-subtree)
  7833. (backward-char)
  7834. (call-interactively #'org-paste-subtree)
  7835. (buffer-string)))))
  7836. (provide 'test-org)
  7837. ;;; test-org.el ends here