test-org.el 263 KB

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