test-org.el 280 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656
  1. ;;; test-org.el --- tests for org.el
  2. ;; Copyright (c) David Maus
  3. ;; Authors: David Maus
  4. ;; This file is not part of GNU Emacs.
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. ;; Template test file for Org tests
  16. ;;; Code:
  17. (eval-and-compile (require 'cl-lib))
  18. ;;; Comments
  19. (ert-deftest test-org/toggle-comment ()
  20. "Test `org-toggle-comment' specifications."
  21. ;; Simple headline.
  22. (should
  23. (equal "* Test"
  24. (org-test-with-temp-text "* COMMENT Test"
  25. (org-toggle-comment)
  26. (buffer-string))))
  27. (should
  28. (equal "* COMMENT Test"
  29. (org-test-with-temp-text "* Test"
  30. (org-toggle-comment)
  31. (buffer-string))))
  32. ;; Headline with a regular keyword.
  33. (should
  34. (equal "* TODO Test"
  35. (org-test-with-temp-text "* TODO COMMENT Test"
  36. (org-toggle-comment)
  37. (buffer-string))))
  38. (should
  39. (equal "* TODO COMMENT Test"
  40. (org-test-with-temp-text "* TODO Test"
  41. (org-toggle-comment)
  42. (buffer-string))))
  43. ;; Empty headline.
  44. (should
  45. (equal "* "
  46. (org-test-with-temp-text "* COMMENT"
  47. (org-toggle-comment)
  48. (buffer-string))))
  49. (should
  50. (equal "* COMMENT"
  51. (org-test-with-temp-text "* "
  52. (org-toggle-comment)
  53. (buffer-string))))
  54. ;; Headline with a single keyword.
  55. (should
  56. (equal "* TODO "
  57. (org-test-with-temp-text "* TODO COMMENT"
  58. (org-toggle-comment)
  59. (buffer-string))))
  60. (should
  61. (equal "* TODO COMMENT"
  62. (org-test-with-temp-text "* TODO"
  63. (org-toggle-comment)
  64. (buffer-string))))
  65. ;; Headline with a keyword, a priority cookie and contents.
  66. (should
  67. (equal "* TODO [#A] Headline"
  68. (org-test-with-temp-text "* TODO [#A] COMMENT Headline"
  69. (org-toggle-comment)
  70. (buffer-string))))
  71. (should
  72. (equal "* TODO [#A] COMMENT Headline"
  73. (org-test-with-temp-text "* TODO [#A] Headline"
  74. (org-toggle-comment)
  75. (buffer-string)))))
  76. (ert-deftest test-org/comment-dwim ()
  77. "Test `comment-dwim' behaviour in an Org buffer."
  78. ;; No region selected, no comment on current line and line not
  79. ;; empty: insert comment on line above.
  80. (should
  81. (equal "# \nComment"
  82. (org-test-with-temp-text "Comment"
  83. (call-interactively #'org-comment-dwim)
  84. (buffer-string))))
  85. ;; No region selected, no comment on current line and line empty:
  86. ;; insert comment on this line.
  87. (should
  88. (equal "# \nParagraph"
  89. (org-test-with-temp-text "\nParagraph"
  90. (call-interactively #'org-comment-dwim)
  91. (buffer-string))))
  92. ;; No region selected, and a comment on this line: indent it.
  93. (should
  94. (equal "* Headline\n # Comment"
  95. (org-test-with-temp-text "* Headline\n# <point>Comment"
  96. (let ((org-adapt-indentation t))
  97. (call-interactively #'org-comment-dwim))
  98. (buffer-string))))
  99. ;; Also recognize single # at column 0 as comments.
  100. (should
  101. (equal "# Comment"
  102. (org-test-with-temp-text "# Comment"
  103. (call-interactively #'org-comment-dwim)
  104. (buffer-string))))
  105. ;; Region selected and only comments and blank lines within it:
  106. ;; un-comment all commented lines.
  107. (should
  108. (equal "Comment 1\n\nComment 2"
  109. (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
  110. (transient-mark-mode 1)
  111. (push-mark (point) t t)
  112. (goto-char (point-max))
  113. (call-interactively #'org-comment-dwim)
  114. (buffer-string))))
  115. ;; Region selected without comments: comment all lines if
  116. ;; `comment-empty-lines' is non-nil, only non-blank lines otherwise.
  117. (should
  118. (equal "# Comment 1\n\n# Comment 2"
  119. (org-test-with-temp-text "Comment 1\n\nComment 2"
  120. (transient-mark-mode 1)
  121. (push-mark (point) t t)
  122. (goto-char (point-max))
  123. (let ((comment-empty-lines nil))
  124. (call-interactively #'org-comment-dwim))
  125. (buffer-string))))
  126. (should
  127. (equal "# Comment 1\n# \n# Comment 2"
  128. (org-test-with-temp-text "Comment 1\n\nComment 2"
  129. (transient-mark-mode 1)
  130. (push-mark (point) t t)
  131. (goto-char (point-max))
  132. (let ((comment-empty-lines t))
  133. (call-interactively #'org-comment-dwim))
  134. (buffer-string))))
  135. ;; In front of a keyword without region, insert a new comment.
  136. (should
  137. (equal "# \n#+KEYWORD: value"
  138. (org-test-with-temp-text "#+KEYWORD: value"
  139. (call-interactively #'org-comment-dwim)
  140. (buffer-string))))
  141. ;; Comment a heading
  142. (should
  143. (equal "* COMMENT Test"
  144. (org-test-with-temp-text "* Test"
  145. (call-interactively #'org-comment-dwim)
  146. (buffer-string))))
  147. ;; In a source block, use appropriate syntax.
  148. (should
  149. (equal " ;; "
  150. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n<point>\n#+END_SRC"
  151. (let ((org-edit-src-content-indentation 2))
  152. (call-interactively #'org-comment-dwim))
  153. (buffer-substring-no-properties (line-beginning-position)
  154. (point)))))
  155. (should
  156. (equal "#+BEGIN_SRC emacs-lisp\n ;; a\n ;; b\n#+END_SRC"
  157. (org-test-with-temp-text
  158. "#+BEGIN_SRC emacs-lisp\n<point>a\nb\n#+END_SRC"
  159. (transient-mark-mode 1)
  160. (push-mark (point) t t)
  161. (forward-line 2)
  162. (let ((org-edit-src-content-indentation 2))
  163. (call-interactively #'org-comment-dwim))
  164. (buffer-string)))))
  165. ;;; Date and time analysis
  166. (ert-deftest test-org/org-read-date ()
  167. "Test `org-read-date' specifications."
  168. ;; Parse ISO date with abbreviated year and month.
  169. (should (equal "2012-03-29 16:40"
  170. (let ((org-time-was-given t))
  171. (org-read-date t nil "12-3-29 16:40"))))
  172. ;; Parse Europeans dates.
  173. (should (equal "2012-03-29 16:40"
  174. (let ((org-time-was-given t))
  175. (org-read-date t nil "29.03.2012 16:40"))))
  176. ;; Parse Europeans dates without year.
  177. (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
  178. (let ((org-time-was-given t))
  179. (org-read-date t nil "29.03. 16:40"))))
  180. ;; Relative date applied to current time if there is single
  181. ;; plus/minus, or to default date when there are two of them.
  182. (should
  183. (equal
  184. "2015-03-04"
  185. (org-test-at-time "2014-03-04"
  186. (org-read-date
  187. t nil "+1y" nil
  188. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))
  189. (should
  190. (equal
  191. "2013-03-29"
  192. (org-test-at-time "2014-03-04"
  193. (org-read-date
  194. t nil "++1y" nil
  195. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))
  196. ;; When `org-read-date-prefer-future' is non-nil, prefer future
  197. ;; dates (relatively to now) when incomplete. Otherwise, use
  198. ;; default date.
  199. (should
  200. (equal
  201. "2014-04-01"
  202. (org-test-at-time "2014-03-04"
  203. (let ((org-read-date-prefer-future t))
  204. (org-read-date t nil "1")))))
  205. (should
  206. (equal
  207. "2013-03-04"
  208. (org-test-at-time "2012-03-29"
  209. (let ((org-read-date-prefer-future t))
  210. (org-read-date t nil "3-4")))))
  211. (should
  212. (equal
  213. "2012-03-04"
  214. (org-test-at-time "2012-03-29"
  215. (let ((org-read-date-prefer-future nil))
  216. (org-read-date t nil "3-4")))))
  217. ;; When set to `org-read-date-prefer-future' is set to `time', read
  218. ;; day is moved to tomorrow if specified hour is before current
  219. ;; time. However, it only happens in no other part of the date is
  220. ;; specified.
  221. (should
  222. (equal
  223. "2012-03-30"
  224. (org-test-at-time "2012-03-29 16:40"
  225. (let ((org-read-date-prefer-future 'time))
  226. (org-read-date t nil "00:40" nil)))))
  227. (should-not
  228. (equal
  229. "2012-03-30"
  230. (org-test-at-time "2012-03-29 16:40"
  231. (let ((org-read-date-prefer-future 'time))
  232. (org-read-date t nil "29 00:40" nil)))))
  233. ;; Caveat: `org-read-date-prefer-future' always refers to current
  234. ;; time, not default time, when they differ.
  235. (should
  236. (equal
  237. "2014-04-01"
  238. (org-test-at-time "2014-03-04"
  239. (let ((org-read-date-prefer-future t))
  240. (org-read-date
  241. t nil "1" nil
  242. (apply #'encode-time (org-parse-time-string "2012-03-29")))))))
  243. (should
  244. (equal
  245. "2014-03-25"
  246. (org-test-at-time "2014-03-04"
  247. (let ((org-read-date-prefer-future t))
  248. (org-read-date
  249. t nil "25" nil
  250. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))))
  251. (ert-deftest test-org/org-parse-time-string ()
  252. "Test `org-parse-time-string'."
  253. (should (equal (org-parse-time-string "2012-03-29 16:40")
  254. '(0 40 16 29 3 2012 nil nil nil)))
  255. (should (equal (org-parse-time-string "[2012-03-29 16:40]")
  256. '(0 40 16 29 3 2012 nil nil nil)))
  257. (should (equal (org-parse-time-string "<2012-03-29 16:40>")
  258. '(0 40 16 29 3 2012 nil nil nil)))
  259. (should (equal (org-parse-time-string "<2012-03-29>")
  260. '(0 0 0 29 3 2012 nil nil nil)))
  261. (should (equal (org-parse-time-string "<2012-03-29>" t)
  262. '(0 nil nil 29 3 2012 nil nil nil))))
  263. (ert-deftest test-org/closest-date ()
  264. "Test `org-closest-date' specifications."
  265. (require 'calendar)
  266. ;; Time stamps without a repeater are returned unchanged.
  267. (should
  268. (equal
  269. '(3 29 2012)
  270. (calendar-gregorian-from-absolute
  271. (org-closest-date "<2012-03-29>" "<2014-03-04>" nil))))
  272. ;; Time stamps with a null repeater are returned unchanged.
  273. (should
  274. (equal
  275. '(3 29 2012)
  276. (calendar-gregorian-from-absolute
  277. (org-closest-date "<2012-03-29 +0d>" "<2014-03-04>" nil))))
  278. ;; if PREFER is set to `past' always return a date before, or equal
  279. ;; to CURRENT.
  280. (should
  281. (equal
  282. '(3 1 2014)
  283. (calendar-gregorian-from-absolute
  284. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'past))))
  285. (should
  286. (equal
  287. '(3 4 2014)
  288. (calendar-gregorian-from-absolute
  289. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'past))))
  290. ;; if PREFER is set to `future' always return a date before, or equal
  291. ;; to CURRENT.
  292. (should
  293. (equal
  294. '(3 29 2014)
  295. (calendar-gregorian-from-absolute
  296. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'future))))
  297. (should
  298. (equal
  299. '(3 4 2014)
  300. (calendar-gregorian-from-absolute
  301. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'future))))
  302. ;; If PREFER is neither `past' nor `future', select closest date.
  303. (should
  304. (equal
  305. '(3 1 2014)
  306. (calendar-gregorian-from-absolute
  307. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" nil))))
  308. (should
  309. (equal
  310. '(5 4 2014)
  311. (calendar-gregorian-from-absolute
  312. (org-closest-date "<2012-03-04 +1m>" "<2014-04-28>" nil))))
  313. ;; Test "day" repeater.
  314. (should
  315. (equal '(3 8 2014)
  316. (calendar-gregorian-from-absolute
  317. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'past))))
  318. (should
  319. (equal '(3 10 2014)
  320. (calendar-gregorian-from-absolute
  321. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'future))))
  322. ;; Test "month" repeater.
  323. (should
  324. (equal '(1 5 2015)
  325. (calendar-gregorian-from-absolute
  326. (org-closest-date "<2014-03-05 +2m>" "<2015-02-04>" 'past))))
  327. (should
  328. (equal '(3 29 2014)
  329. (calendar-gregorian-from-absolute
  330. (org-closest-date "<2012-03-29 +2m>" "<2014-03-04>" 'future))))
  331. ;; Test "year" repeater.
  332. (should
  333. (equal '(3 5 2014)
  334. (calendar-gregorian-from-absolute
  335. (org-closest-date "<2014-03-05 +2y>" "<2015-02-04>" 'past))))
  336. (should
  337. (equal '(3 29 2014)
  338. (calendar-gregorian-from-absolute
  339. (org-closest-date "<2012-03-29 +2y>" "<2014-03-04>" 'future)))))
  340. (ert-deftest test-org/deadline-close-p ()
  341. "Test `org-deadline-close-p' specifications."
  342. (org-test-at-time "2016-06-03 Fri 01:43"
  343. ;; Timestamps are close if they are within `ndays' of lead time.
  344. (org-test-with-temp-text "* Heading"
  345. (should (org-deadline-close-p "2016-06-03 Fri" 0))
  346. (should (org-deadline-close-p "2016-06-02 Thu" 0))
  347. (should-not (org-deadline-close-p "2016-06-04 Sat" 0))
  348. (should (org-deadline-close-p "2016-06-04 Sat" 1))
  349. (should (org-deadline-close-p "2016-06-03 Fri 12:00" 0)))
  350. ;; Read `ndays' from timestamp if argument not given.
  351. (org-test-with-temp-text "* H"
  352. (should (org-deadline-close-p "2016-06-04 Sat -1d"))
  353. (should-not (org-deadline-close-p "2016-06-04 Sat -0d"))
  354. (should (org-deadline-close-p "2016-06-10 Fri -1w"))
  355. (should-not (org-deadline-close-p "2016-06-11 Sat -1w")))
  356. ;; Prefer `ndays' argument over lead time in timestamp.
  357. (org-test-with-temp-text "* H"
  358. (should (org-deadline-close-p "2016-06-04 Sat -0d" 1))
  359. (should-not (org-deadline-close-p "2016-06-04 Sat -0d" 0)))
  360. ;; Completed tasks are never close.
  361. (let ((org-todo-keywords '(("TODO" "|" "DONE"))))
  362. (org-test-with-temp-text "* TODO Heading"
  363. (should (org-deadline-close-p "2016-06-03")))
  364. (org-test-with-temp-text "* DONE Heading"
  365. (should-not (org-deadline-close-p "2016-06-03"))))))
  366. ;;; Drawers
  367. (ert-deftest test-org/at-property-p ()
  368. "Test `org-at-property-p' specifications."
  369. (should
  370. (equal 't
  371. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:PROP: t\n:END:\n"
  372. (org-at-property-p))))
  373. (should
  374. (equal 't
  375. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n:END:\n"
  376. (org-at-property-p)))))
  377. (ert-deftest test-org/at-property-drawer-p ()
  378. "Test `org-at-property-drawer-p' specifications."
  379. (should
  380. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:PROP: t\n:END:\n"
  381. (org-at-property-drawer-p)))
  382. (should
  383. (org-test-with-temp-text ":PROPERTIES:\n:PROP: t\n:END:\n"
  384. (org-at-property-drawer-p)))
  385. ;; The function only returns t if point is at the first line of
  386. ;; a property block.
  387. (should-not
  388. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n:END:\n"
  389. (org-at-property-drawer-p)))
  390. ;; The function ignores incomplete drawers.
  391. (should-not
  392. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n"
  393. (org-at-property-drawer-p)))
  394. ;; tab separating the value.
  395. (should
  396. (org-test-with-temp-text ":PROPERTIES:\n:PROP: t\n:END:\n"
  397. (org-at-property-drawer-p))))
  398. (ert-deftest test-org/get-property-block ()
  399. "Test `org-get-property-block' specifications."
  400. (should
  401. (equal '(14 . 14)
  402. (org-test-with-temp-text ":PROPERTIES:\n:END:\n* H\n"
  403. (org-get-property-block))))
  404. (should
  405. (equal '(14 . 14)
  406. (org-test-with-temp-text ":PROPERTIES:\n:END:\n"
  407. (org-get-property-block))))
  408. ;; Comments above a document property block is ok.
  409. (should
  410. (equal '(18 . 18)
  411. (org-test-with-temp-text "# C\n:PROPERTIES:\n:END:\n"
  412. (org-get-property-block))))
  413. ;; Keywords above a document property block is ok.
  414. (should
  415. (equal '(22 . 22)
  416. (org-test-with-temp-text "# C\n# C\n:PROPERTIES:\n:END:\n"
  417. (org-get-property-block))))
  418. ;; Comments and keywords are allowed before a document property block.
  419. (should
  420. (equal '(18 . 27)
  421. (org-test-with-temp-text "# C\n:PROPERTIES:\n:KEY: V:\n:END:\n"
  422. (org-get-property-block))))
  423. ;; A document property block will not be valid if there are lines
  424. ;; with whitespace above it
  425. (should-not
  426. (org-test-with-temp-text "\n:PROPERTIES:\n:END:\n"
  427. (org-get-property-block)))
  428. (should
  429. (equal '(18 . 18)
  430. (org-test-with-temp-text "* H\n:PROPERTIES:\n:END:\n<point>"
  431. (org-get-property-block))))
  432. (should
  433. (equal "* H\n:PROPERTIES:\n:END:\n"
  434. (org-test-with-temp-text "* H"
  435. (let ((org-adapt-indentation nil))
  436. (org-get-property-block nil 'force))
  437. (buffer-string))))
  438. (should
  439. (equal ":PROPERTIES:\n:END:\n"
  440. (org-test-with-temp-text ""
  441. (org-get-property-block nil 'force)
  442. (buffer-string))))
  443. (should
  444. (equal "* H1\n :PROPERTIES:\n :END:\n* H2"
  445. (org-test-with-temp-text "* H1\n* H2"
  446. (let ((org-adapt-indentation t))
  447. (org-get-property-block nil 'force))
  448. (buffer-string)))))
  449. (ert-deftest test-org/insert-property-drawer ()
  450. "Test `org-insert-property-drawer' specifications."
  451. ;; Insert drawer in empty buffer
  452. (should
  453. (equal ":PROPERTIES:\n:END:\n"
  454. (org-test-with-temp-text ""
  455. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  456. (buffer-string))))
  457. ;; Insert drawer in document header with existing comment and
  458. ;; keyword.
  459. (should
  460. (equal "# C\n:PROPERTIES:\n:END:\n#+TITLE: T"
  461. (org-test-with-temp-text "# C\n#+TITLE: T"
  462. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  463. (buffer-string))))
  464. ;; Insert drawer in document header with existing keyword.
  465. (should
  466. (equal ":PROPERTIES:\n:END:\n#+TITLE: T"
  467. (org-test-with-temp-text "#+TITLE: T"
  468. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  469. (buffer-string))))
  470. (should
  471. (equal ":PROPERTIES:\n:END:"
  472. (org-test-with-temp-text ":PROPERTIES:\n:END:"
  473. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  474. (buffer-string))))
  475. ;; Insert drawer in document header with one existing heading in buffer.
  476. (should
  477. (equal ":PROPERTIES:\n:END:\n\n* T\n"
  478. (org-test-with-temp-text "\n* T\n"
  479. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  480. (buffer-string))))
  481. ;; Insert drawer right after headline if there is no planning line,
  482. ;; or after it otherwise.
  483. (should
  484. (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
  485. (org-test-with-temp-text "* H\nParagraph<point>"
  486. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  487. (buffer-string))))
  488. (should
  489. (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
  490. (org-test-with-temp-text
  491. "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
  492. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  493. (buffer-string))))
  494. ;; Indent inserted drawer.
  495. (should
  496. (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
  497. (org-test-with-temp-text "* H\nParagraph<point>"
  498. (let ((org-adapt-indentation t)) (org-insert-property-drawer))
  499. (buffer-string))))
  500. ;; Handle insertion at eob.
  501. (should
  502. (equal "* H\n:PROPERTIES:\n:END:\n"
  503. (org-test-with-temp-text "* H"
  504. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  505. (buffer-string))))
  506. ;; Skip inlinetasks before point.
  507. (when (featurep 'org-inlinetask)
  508. (should
  509. (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
  510. (org-test-with-temp-text
  511. "* H\n*************** I\n*************** END\nP<point>"
  512. (let ((org-adapt-indentation nil)
  513. (org-inlinetask-min-level 15))
  514. (org-insert-property-drawer))
  515. (buffer-string)))))
  516. ;; Correctly set drawer in an inlinetask.
  517. (when (featurep 'org-inlinetask)
  518. (should
  519. (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
  520. (org-test-with-temp-text
  521. "* H\n*************** I\nP<point>\n*************** END"
  522. (let ((org-adapt-indentation nil)
  523. (org-inlinetask-min-level 15))
  524. (org-insert-property-drawer))
  525. (buffer-string))))))
  526. ;;; Filling
  527. (ert-deftest test-org/fill-element ()
  528. "Test `org-fill-element' specifications."
  529. ;; At an Org table, align it.
  530. (should
  531. (equal "| a |\n"
  532. (org-test-with-temp-text "|a|"
  533. (org-fill-element)
  534. (buffer-string))))
  535. (should
  536. (equal "#+name: table\n| a |\n"
  537. (org-test-with-temp-text "#+name: table\n| a |\n"
  538. (org-fill-element)
  539. (buffer-string))))
  540. ;; At a paragraph, preserve line breaks.
  541. (org-test-with-temp-text "some \\\\\nlong\ntext"
  542. (let ((fill-column 20))
  543. (org-fill-element)
  544. (should (equal (buffer-string) "some \\\\\nlong text"))))
  545. ;; Correctly fill a paragraph when point is at its very end.
  546. (should
  547. (equal "A B"
  548. (org-test-with-temp-text "A\nB"
  549. (let ((fill-column 20))
  550. (goto-char (point-max))
  551. (org-fill-element)
  552. (buffer-string)))))
  553. ;; Correctly fill the last paragraph of a greater element.
  554. (should
  555. (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
  556. (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
  557. (let ((fill-column 8))
  558. (forward-line)
  559. (end-of-line)
  560. (org-fill-element)
  561. (buffer-string)))))
  562. ;; Correctly fill an element in a narrowed buffer.
  563. (should
  564. (equal "01234\n6"
  565. (org-test-with-temp-text "01234 6789"
  566. (let ((fill-column 5))
  567. (narrow-to-region 1 8)
  568. (org-fill-element)
  569. (buffer-string)))))
  570. ;; Handle `adaptive-fill-regexp' in paragraphs.
  571. (should
  572. (equal "> a b"
  573. (org-test-with-temp-text "> a\n> b"
  574. (let ((fill-column 5)
  575. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  576. (org-fill-element)
  577. (buffer-string)))))
  578. ;; Special case: Fill first paragraph when point is at an item or
  579. ;; a plain-list or a footnote reference.
  580. (should
  581. (equal "- A B"
  582. (org-test-with-temp-text "- A\n B"
  583. (let ((fill-column 20))
  584. (org-fill-element)
  585. (buffer-string)))))
  586. (should
  587. (equal "[fn:1] A B"
  588. (org-test-with-temp-text "[fn:1] A\nB"
  589. (let ((fill-column 20))
  590. (org-fill-element)
  591. (buffer-string)))))
  592. (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
  593. (let ((fill-column 20))
  594. (org-fill-element)
  595. (should (equal (buffer-string)
  596. "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
  597. ;; Fill contents of `comment-block' elements.
  598. (should
  599. (equal
  600. (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
  601. (let ((fill-column 20))
  602. (forward-line)
  603. (org-fill-element)
  604. (buffer-string)))
  605. "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
  606. ;; Fill `comment' elements.
  607. (should
  608. (equal " # A B"
  609. (org-test-with-temp-text " # A\n # B"
  610. (let ((fill-column 20))
  611. (org-fill-element)
  612. (buffer-string)))))
  613. ;; Do not mix consecutive comments when filling one of them.
  614. (should
  615. (equal "# A B\n\n# C"
  616. (org-test-with-temp-text "# A\n# B\n\n# C"
  617. (let ((fill-column 20))
  618. (org-fill-element)
  619. (buffer-string)))))
  620. ;; Use commented empty lines as separators when filling comments.
  621. (should
  622. (equal "# A B\n#\n# C"
  623. (org-test-with-temp-text "# A\n# B\n#\n# C"
  624. (let ((fill-column 20))
  625. (org-fill-element)
  626. (buffer-string)))))
  627. ;; Handle `adaptive-fill-regexp' in comments.
  628. (should
  629. (equal "# > a b"
  630. (org-test-with-temp-text "# > a\n# > b"
  631. (let ((fill-column 20)
  632. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  633. (org-fill-element)
  634. (buffer-string)))))
  635. ;; Do nothing at affiliated keywords.
  636. (should
  637. (equal "#+NAME: para\nSome\ntext."
  638. (org-test-with-temp-text "#+NAME: para\nSome\ntext."
  639. (let ((fill-column 20))
  640. (org-fill-element)
  641. (buffer-string)))))
  642. ;; Do not move point after table when filling a table.
  643. (should-not
  644. (org-test-with-temp-text "| a | b |\n| c | d |\n"
  645. (forward-char)
  646. (org-fill-element)
  647. (eobp)))
  648. ;; Do not fill "n" macro, with or without arguments, followed by
  649. ;; a dot or a closing parenthesis since it could be confused with
  650. ;; a numbered bullet.
  651. (should-not
  652. (equal "123456789\n{{{n}}}."
  653. (org-test-with-temp-text "123456789 {{{n}}}."
  654. (let ((fill-column 10))
  655. (org-fill-element)
  656. (buffer-string)))))
  657. (should-not
  658. (equal "123456789\n{{{n}}}\)"
  659. (org-test-with-temp-text "123456789 {{{n}}}\)"
  660. (let ((fill-column 10))
  661. (org-fill-element)
  662. (buffer-string)))))
  663. (should-not
  664. (equal "123456789\n{{{n()}}}."
  665. (org-test-with-temp-text "123456789 {{{n()}}}."
  666. (let ((fill-column 10))
  667. (org-fill-element)
  668. (buffer-string)))))
  669. (should-not
  670. (equal "123456789\n{{{n(counter)}}}."
  671. (org-test-with-temp-text "123456789 {{{n(counter)}}}."
  672. (let ((fill-column 10))
  673. (org-fill-element)
  674. (buffer-string))))))
  675. (ert-deftest test-org/fill-paragraph ()
  676. "Test `org-fill-paragraph' specifications."
  677. ;; Regular test.
  678. (should
  679. (equal "012345678\n9"
  680. (org-test-with-temp-text "012345678 9"
  681. (let ((fill-column 10))
  682. (org-fill-paragraph)
  683. (buffer-string)))))
  684. ;; Fill paragraph even at end of buffer.
  685. (should
  686. (equal "012345678\n9\n"
  687. (org-test-with-temp-text "012345678 9\n<point>"
  688. (let ((fill-column 10))
  689. (org-fill-paragraph)
  690. (buffer-string)))))
  691. ;; Between two paragraphs, fill the next one.
  692. (should
  693. (equal "012345678 9\n\n012345678\n9"
  694. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  695. (let ((fill-column 10))
  696. (org-fill-paragraph)
  697. (buffer-string)))))
  698. (should
  699. (equal "012345678\n9\n\n012345678 9"
  700. (org-test-with-temp-text "012345678 9<point>\n\n012345678 9"
  701. (let ((fill-column 10))
  702. (org-fill-paragraph)
  703. (buffer-string)))))
  704. ;; Fill paragraph in a comment block.
  705. (should
  706. (equal "#+begin_comment\n012345678\n9\n#+end_comment"
  707. (org-test-with-temp-text
  708. "#+begin_comment\n<point>012345678 9\n#+end_comment"
  709. (let ((fill-column 10))
  710. (org-fill-paragraph)
  711. (buffer-string)))))
  712. ;; When a region is selected, fill every paragraph in the region.
  713. (should
  714. (equal "012345678\n9\n\n012345678\n9"
  715. (org-test-with-temp-text "012345678 9\n\n012345678 9"
  716. (let ((fill-column 10))
  717. (transient-mark-mode 1)
  718. (push-mark (point-min) t t)
  719. (goto-char (point-max))
  720. (call-interactively #'org-fill-paragraph)
  721. (buffer-string)))))
  722. (should
  723. (equal "012345678\n9\n\n012345678 9"
  724. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  725. (let ((fill-column 10))
  726. (transient-mark-mode 1)
  727. (push-mark (point) t t)
  728. (goto-char (point-min))
  729. (call-interactively #'org-fill-paragraph)
  730. (buffer-string)))))
  731. (should
  732. (equal "012345678 9\n\n012345678\n9"
  733. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  734. (let ((fill-column 10))
  735. (transient-mark-mode 1)
  736. (push-mark (point) t t)
  737. (goto-char (point-max))
  738. (call-interactively #'org-fill-paragraph)
  739. (buffer-string))))))
  740. (ert-deftest test-org/auto-fill-function ()
  741. "Test auto-filling features."
  742. ;; Auto fill paragraph.
  743. (should
  744. (equal "12345\n7890"
  745. (org-test-with-temp-text "12345 7890"
  746. (let ((fill-column 5))
  747. (end-of-line)
  748. (org-auto-fill-function)
  749. (buffer-string)))))
  750. ;; Auto fill first paragraph in an item.
  751. (should
  752. (equal "- 12345\n 7890"
  753. (org-test-with-temp-text "- 12345 7890"
  754. (let ((fill-column 7))
  755. (end-of-line)
  756. (org-auto-fill-function)
  757. (buffer-string)))))
  758. ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
  759. (should
  760. (equal "> 12345\n 7890"
  761. (org-test-with-temp-text "> 12345 7890"
  762. (let ((fill-column 10)
  763. (adaptive-fill-regexp "[ \t]*>+[ \t]*")
  764. (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
  765. (end-of-line)
  766. (org-auto-fill-function)
  767. (buffer-string)))))
  768. (should
  769. (equal "> 12345\n> 12345\n> 7890"
  770. (org-test-with-temp-text "> 12345\n> 12345 7890"
  771. (let ((fill-column 10)
  772. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  773. (goto-char (point-max))
  774. (org-auto-fill-function)
  775. (buffer-string)))))
  776. (should-not
  777. (equal " 12345\n *12345\n *12345"
  778. (org-test-with-temp-text " 12345\n *12345 12345"
  779. (let ((fill-column 10)
  780. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  781. (goto-char (point-max))
  782. (org-auto-fill-function)
  783. (buffer-string)))))
  784. ;; Auto fill comments.
  785. (should
  786. (equal " # 12345\n # 7890"
  787. (org-test-with-temp-text " # 12345 7890"
  788. (let ((fill-column 10))
  789. (end-of-line)
  790. (org-auto-fill-function)
  791. (buffer-string)))))
  792. ;; A hash within a line isn't a comment.
  793. (should-not
  794. (equal "12345 # 7890\n# 1"
  795. (org-test-with-temp-text "12345 # 7890 1"
  796. (let ((fill-column 12))
  797. (end-of-line)
  798. (org-auto-fill-function)
  799. (buffer-string)))))
  800. ;; Correctly interpret empty prefix.
  801. (should-not
  802. (equal "# a\n# b\nRegular\n# paragraph"
  803. (org-test-with-temp-text "# a\n# b\nRegular paragraph"
  804. (let ((fill-column 12))
  805. (end-of-line 3)
  806. (org-auto-fill-function)
  807. (buffer-string)))))
  808. ;; Comment block: auto fill contents.
  809. (should
  810. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  811. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  812. (let ((fill-column 5))
  813. (forward-line)
  814. (end-of-line)
  815. (org-auto-fill-function)
  816. (buffer-string)))))
  817. (should
  818. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  819. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  820. (let ((fill-column 5))
  821. (forward-line)
  822. (end-of-line)
  823. (org-auto-fill-function)
  824. (buffer-string)))))
  825. ;; Do not fill if a new item could be created.
  826. (should-not
  827. (equal "12345\n- 90"
  828. (org-test-with-temp-text "12345 - 90"
  829. (let ((fill-column 5))
  830. (end-of-line)
  831. (org-auto-fill-function)
  832. (buffer-string)))))
  833. ;; Do not fill if a line break could be introduced.
  834. (should-not
  835. (equal "123\\\\\n7890"
  836. (org-test-with-temp-text "123\\\\ 7890"
  837. (let ((fill-column 6))
  838. (end-of-line)
  839. (org-auto-fill-function)
  840. (buffer-string)))))
  841. ;; Do not fill affiliated keywords.
  842. (should-not
  843. (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
  844. (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
  845. (let ((fill-column 20))
  846. (end-of-line)
  847. (org-auto-fill-function)
  848. (buffer-string))))))
  849. ;;; Indentation
  850. (ert-deftest test-org/indent-line ()
  851. "Test `org-indent-line' specifications."
  852. ;; Do not indent diary sexps, footnote definitions or headlines.
  853. (should
  854. (zerop
  855. (org-test-with-temp-text "%%(org-calendar-holiday)"
  856. (org-indent-line)
  857. (org-get-indentation))))
  858. (should
  859. (zerop
  860. (org-test-with-temp-text "[fn:1] fn"
  861. (let ((org-adapt-indentation t)) (org-indent-line))
  862. (org-get-indentation))))
  863. (should
  864. (zerop
  865. (org-test-with-temp-text "* H"
  866. (org-indent-line)
  867. (org-get-indentation))))
  868. ;; Do not indent before first headline.
  869. (should
  870. (zerop
  871. (org-test-with-temp-text ""
  872. (org-indent-line)
  873. (org-get-indentation))))
  874. ;; Indent according to headline level otherwise, unless
  875. ;; `org-adapt-indentation' is nil.
  876. (should
  877. (= 2
  878. (org-test-with-temp-text "* H\n<point>A"
  879. (let ((org-adapt-indentation t)) (org-indent-line))
  880. (org-get-indentation))))
  881. (should
  882. (= 2
  883. (org-test-with-temp-text "* H\n<point>\nA"
  884. (let ((org-adapt-indentation t)) (org-indent-line))
  885. (org-get-indentation))))
  886. (should
  887. (zerop
  888. (org-test-with-temp-text "* H\n<point>A"
  889. (let ((org-adapt-indentation nil)) (org-indent-line))
  890. (org-get-indentation))))
  891. ;; Indenting preserves point position.
  892. (should
  893. (org-test-with-temp-text "* H\nA<point>B"
  894. (let ((org-adapt-indentation t)) (org-indent-line))
  895. (looking-at "B")))
  896. ;; Do not change indentation at an item or a LaTeX environment.
  897. (should
  898. (= 1
  899. (org-test-with-temp-text "* H\n<point> - A"
  900. (let ((org-adapt-indentation t)) (org-indent-line))
  901. (org-get-indentation))))
  902. (should
  903. (= 1
  904. (org-test-with-temp-text
  905. "\\begin{equation}\n <point>1+1=2\n\\end{equation}"
  906. (org-indent-line)
  907. (org-get-indentation))))
  908. ;; On blank lines at the end of a list, indent like last element
  909. ;; within it if the line is still in the list. If the last element
  910. ;; is an item, indent like its contents. Otherwise, indent like the
  911. ;; whole list.
  912. (should
  913. (= 4
  914. (org-test-with-temp-text "* H\n- A\n - AA\n<point>"
  915. (let ((org-adapt-indentation t)) (org-indent-line))
  916. (org-get-indentation))))
  917. (should
  918. (= 4
  919. (org-test-with-temp-text "* H\n- A\n -\n\n<point>"
  920. (let ((org-adapt-indentation t)) (org-indent-line))
  921. (org-get-indentation))))
  922. (should
  923. (zerop
  924. (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n<point>"
  925. (let ((org-adapt-indentation t)) (org-indent-line))
  926. (org-get-indentation))))
  927. (should
  928. (= 4
  929. (org-test-with-temp-text "* H\n- A\n - \n<point>"
  930. (let ((org-adapt-indentation t)) (org-indent-line))
  931. (org-get-indentation))))
  932. (should
  933. (= 4
  934. (org-test-with-temp-text
  935. "* H\n - \n #+BEGIN_SRC emacs-lisp\n t\n #+END_SRC\n<point>"
  936. (let ((org-adapt-indentation t)) (org-indent-line))
  937. (org-get-indentation))))
  938. (should
  939. (= 2
  940. (org-test-with-temp-text "- A\n B\n\n<point>"
  941. (let ((org-adapt-indentation nil)) (org-indent-line))
  942. (org-get-indentation))))
  943. (should
  944. (= 2
  945. (org-test-with-temp-text
  946. "- A\n \begin{cases} 1 + 1\n \end{cases}\n\n<point>"
  947. (let ((org-adapt-indentation nil)) (org-indent-line))
  948. (org-get-indentation))))
  949. ;; Likewise, on a blank line at the end of a footnote definition,
  950. ;; indent at column 0 if line belongs to the definition. Otherwise,
  951. ;; indent like the definition itself.
  952. (should
  953. (zerop
  954. (org-test-with-temp-text "* H\n[fn:1] Definition\n<point>"
  955. (let ((org-adapt-indentation t)) (org-indent-line))
  956. (org-get-indentation))))
  957. (should
  958. (zerop
  959. (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n<point>"
  960. (let ((org-adapt-indentation t)) (org-indent-line))
  961. (org-get-indentation))))
  962. ;; After the end of the contents of a greater element, indent like
  963. ;; the beginning of the element.
  964. (should
  965. (= 1
  966. (org-test-with-temp-text
  967. " #+BEGIN_CENTER\n Contents\n<point>#+END_CENTER"
  968. (org-indent-line)
  969. (org-get-indentation))))
  970. ;; On blank lines after a paragraph, indent like its last non-empty
  971. ;; line.
  972. (should
  973. (= 1
  974. (org-test-with-temp-text " Paragraph\n\n<point>"
  975. (org-indent-line)
  976. (org-get-indentation))))
  977. ;; At the first line of an element, indent like previous element's
  978. ;; first line, ignoring footnotes definitions and inline tasks, or
  979. ;; according to parent.
  980. (let ((org-adapt-indentation t))
  981. (should
  982. (= 2
  983. (org-test-with-temp-text "A\n\n B\n\nC<point>"
  984. (org-indent-line)
  985. (org-get-indentation))))
  986. (should
  987. (= 1
  988. (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC<point>"
  989. (org-indent-line)
  990. (org-get-indentation))))
  991. (should
  992. (= 1
  993. (org-test-with-temp-text
  994. " #+BEGIN_CENTER\n<point> Contents\n#+END_CENTER"
  995. (org-indent-line)
  996. (org-get-indentation)))))
  997. ;; Within code part of a source block, use language major mode if
  998. ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
  999. ;; according to line above.
  1000. (should
  1001. (= 6
  1002. (org-test-with-temp-text
  1003. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  1004. (let ((org-src-tab-acts-natively t)
  1005. (org-edit-src-content-indentation 0))
  1006. (org-indent-line))
  1007. (org-get-indentation))))
  1008. (should
  1009. (= 1
  1010. (org-test-with-temp-text
  1011. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  1012. (let ((org-src-tab-acts-natively nil)
  1013. (org-edit-src-content-indentation 0))
  1014. (org-indent-line))
  1015. (org-get-indentation))))
  1016. ;; Otherwise, indent like the first non-blank line above.
  1017. (should
  1018. (zerop
  1019. (org-test-with-temp-text
  1020. "#+BEGIN_CENTER\nline1\n\n<point> line2\n#+END_CENTER"
  1021. (org-indent-line)
  1022. (org-get-indentation))))
  1023. ;; Align node properties according to `org-property-format'. Handle
  1024. ;; nicely empty values.
  1025. (should
  1026. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1027. (org-test-with-temp-text
  1028. "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
  1029. (let ((org-property-format "%-10s %s")) (org-indent-line))
  1030. (buffer-string))))
  1031. (should
  1032. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1033. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
  1034. (let ((org-property-format "%-10s %s")) (org-indent-line))
  1035. (buffer-string)))))
  1036. (ert-deftest test-org/indent-region ()
  1037. "Test `org-indent-region' specifications."
  1038. ;; Indent paragraph.
  1039. (let ((org-adapt-indentation t))
  1040. (should
  1041. (equal "A\nB\nC"
  1042. (org-test-with-temp-text " A\nB\n C"
  1043. (org-indent-region (point-min) (point-max))
  1044. (buffer-string)))))
  1045. ;; Indent greater elements along with their contents.
  1046. (should
  1047. (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
  1048. (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
  1049. (org-indent-region (point-min) (point-max))
  1050. (buffer-string))))
  1051. ;; Ignore contents of verse blocks. Only indent block delimiters.
  1052. (should
  1053. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1054. (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1055. (org-indent-region (point-min) (point-max))
  1056. (buffer-string))))
  1057. (let ((org-adapt-indentation t))
  1058. (should
  1059. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1060. (org-test-with-temp-text " #+BEGIN_VERSE\n A\n B\n #+END_VERSE"
  1061. (org-indent-region (point-min) (point-max))
  1062. (buffer-string)))))
  1063. ;; Indent example blocks as a single block, unless indentation
  1064. ;; should be preserved. In this case only indent the block markers.
  1065. (should
  1066. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1067. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1068. (org-indent-region (point-min) (point-max))
  1069. (buffer-string))))
  1070. (let ((org-adapt-indentation t))
  1071. (should
  1072. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1073. (org-test-with-temp-text " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1074. (org-indent-region (point-min) (point-max))
  1075. (buffer-string))))
  1076. (should
  1077. (equal "#+BEGIN_EXAMPLE -i\n A\n B\n#+END_EXAMPLE"
  1078. (org-test-with-temp-text
  1079. " #+BEGIN_EXAMPLE -i\n A\n B\n #+END_EXAMPLE"
  1080. (org-indent-region (point-min) (point-max))
  1081. (buffer-string))))
  1082. (should
  1083. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1084. (org-test-with-temp-text
  1085. " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1086. (let ((org-src-preserve-indentation t))
  1087. (org-indent-region (point-min) (point-max)))
  1088. (buffer-string)))))
  1089. ;; Treat export blocks as a whole.
  1090. (should
  1091. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1092. (org-test-with-temp-text "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1093. (org-indent-region (point-min) (point-max))
  1094. (buffer-string))))
  1095. (let ((org-adapt-indentation t))
  1096. (should
  1097. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1098. (org-test-with-temp-text
  1099. " #+BEGIN_EXPORT latex\n A\n B\n #+END_EXPORT"
  1100. (org-indent-region (point-min) (point-max))
  1101. (buffer-string)))))
  1102. ;; Indent according to mode if `org-src-tab-acts-natively' is
  1103. ;; non-nil. Otherwise, do not indent code at all.
  1104. (should
  1105. (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
  1106. (org-test-with-temp-text
  1107. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1108. (let ((org-src-tab-acts-natively t)
  1109. (org-edit-src-content-indentation 0))
  1110. (org-indent-region (point-min) (point-max)))
  1111. (buffer-string))))
  1112. (should
  1113. (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1114. (org-test-with-temp-text
  1115. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1116. (let ((org-src-tab-acts-natively nil)
  1117. (org-edit-src-content-indentation 0))
  1118. (org-indent-region (point-min) (point-max)))
  1119. (buffer-string))))
  1120. ;; Align node properties according to `org-property-format'. Handle
  1121. ;; nicely empty values.
  1122. (should
  1123. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1124. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
  1125. (let ((org-property-format "%-10s %s")
  1126. (org-adapt-indentation nil))
  1127. (org-indent-region (point) (point-max)))
  1128. (buffer-string))))
  1129. (should
  1130. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1131. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
  1132. (let ((org-property-format "%-10s %s")
  1133. (org-adapt-indentation nil))
  1134. (org-indent-region (point) (point-max)))
  1135. (buffer-string))))
  1136. ;; Indent property drawers according to `org-adapt-indentation'.
  1137. (let ((org-adapt-indentation 'headline-data))
  1138. (should
  1139. (equal "* H\n :PROPERTIES:\n :key:\n :END:"
  1140. (org-test-with-temp-text "* H\n:PROPERTIES:\n:key:\n:END:"
  1141. (org-indent-region (point-min) (point-max))
  1142. (buffer-string)))))
  1143. ;; Indent plain lists.
  1144. (let ((org-adapt-indentation t))
  1145. (should
  1146. (equal "- A\n B\n - C\n\n D"
  1147. (org-test-with-temp-text "- A\n B\n - C\n\n D"
  1148. (org-indent-region (point-min) (point-max))
  1149. (buffer-string))))
  1150. (should
  1151. (equal "- A\n\n- B"
  1152. (org-test-with-temp-text " - A\n\n - B"
  1153. (org-indent-region (point-min) (point-max))
  1154. (buffer-string)))))
  1155. ;; Indent footnote definitions.
  1156. (should
  1157. (equal "[fn:1] Definition\n\nDefinition"
  1158. (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
  1159. (org-indent-region (point-min) (point-max))
  1160. (buffer-string))))
  1161. ;; Special case: Start indenting on a blank line.
  1162. (should
  1163. (equal "\nParagraph"
  1164. (org-test-with-temp-text "\n Paragraph"
  1165. (org-indent-region (point-min) (point-max))
  1166. (buffer-string)))))
  1167. ;;; Editing
  1168. (ert-deftest test-org/delete-indentation ()
  1169. "Test `org-delete-indentation' specifications."
  1170. ;; Regular test.
  1171. (should (equal "foo bar"
  1172. (org-test-with-temp-text
  1173. "foo \n bar<point>"
  1174. (org-delete-indentation)
  1175. (buffer-string))))
  1176. ;; With optional argument.
  1177. (should (equal "foo bar"
  1178. (org-test-with-temp-text
  1179. "foo<point> \n bar"
  1180. (org-delete-indentation t)
  1181. (buffer-string))))
  1182. ;; At headline text should be appended to the headline text.
  1183. (should
  1184. (equal"* foo bar :tag:"
  1185. (let (org-auto-align-tags)
  1186. (org-test-with-temp-text
  1187. "* foo :tag:\n bar<point>"
  1188. (org-delete-indentation)
  1189. (buffer-string)))))
  1190. (should
  1191. (equal "* foo bar :tag:"
  1192. (let (org-auto-align-tags)
  1193. (org-test-with-temp-text
  1194. "* foo <point>:tag:\n bar"
  1195. (org-delete-indentation t)
  1196. (buffer-string))))))
  1197. (ert-deftest test-org/return ()
  1198. "Test `org-return' specifications."
  1199. ;; Regular test.
  1200. (should
  1201. (equal "Para\ngraph"
  1202. (org-test-with-temp-text "Para<point>graph"
  1203. (org-return)
  1204. (buffer-string))))
  1205. ;; With optional argument, indent line.
  1206. (should
  1207. (equal " Para\n graph"
  1208. (org-test-with-temp-text " Para<point>graph"
  1209. (org-return t)
  1210. (buffer-string))))
  1211. ;; On a table, call `org-table-next-row'.
  1212. (should
  1213. (org-test-with-temp-text "| <point>a |\n| b |"
  1214. (org-return)
  1215. (looking-at-p "b")))
  1216. ;; Open link or timestamp under point when `org-return-follows-link'
  1217. ;; is non-nil.
  1218. (should
  1219. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1220. (let ((org-return-follows-link t)
  1221. (org-link-search-must-match-exact-headline nil))
  1222. (org-return))
  1223. (looking-at-p "<<target>>")))
  1224. (should-not
  1225. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1226. (let ((org-return-follows-link nil)) (org-return))
  1227. (looking-at-p "<<target>>")))
  1228. (should
  1229. (org-test-with-temp-text "* [[b][a<point>]]\n* b"
  1230. (let ((org-return-follows-link t)) (org-return))
  1231. (looking-at-p "* b")))
  1232. (should
  1233. (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
  1234. (let ((org-return-follows-link t)
  1235. (org-link-search-must-match-exact-headline nil))
  1236. (org-return))
  1237. (looking-at-p "<<target>>")))
  1238. (should-not
  1239. (org-test-with-temp-text "Link [[target]]<point> <<target>>"
  1240. (let ((org-return-follows-link t)
  1241. (org-link-search-must-match-exact-headline nil))
  1242. (org-return))
  1243. (looking-at-p "<<target>>")))
  1244. ;; When `org-return-follows-link' is non-nil, tolerate links and
  1245. ;; timestamps in comments, node properties, etc.
  1246. (should
  1247. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1248. (let ((org-return-follows-link t)
  1249. (org-link-search-must-match-exact-headline nil))
  1250. (org-return))
  1251. (looking-at-p "<<target>>")))
  1252. (should-not
  1253. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1254. (let ((org-return-follows-link nil)) (org-return))
  1255. (looking-at-p "<<target>>")))
  1256. (should-not
  1257. (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
  1258. (let ((org-return-follows-link t)
  1259. (org-link-search-must-match-exact-headline nil))
  1260. (org-return))
  1261. (looking-at-p "<<target>>")))
  1262. ;; Non-nil `org-return-follows-link' ignores read-only state of
  1263. ;; a buffer.
  1264. (should
  1265. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1266. (let ((org-return-follows-link t)
  1267. (org-link-search-must-match-exact-headline nil))
  1268. (setq buffer-read-only t)
  1269. (call-interactively #'org-return))
  1270. (looking-at-p "<<target>>")))
  1271. ;; `org-return-follows-link' handle multi-line lines.
  1272. (should
  1273. (org-test-with-temp-text
  1274. "[[target][This is a very\n long description<point>]]\n <<target>>"
  1275. (let ((org-return-follows-link t)
  1276. (org-link-search-must-match-exact-headline nil))
  1277. (org-return))
  1278. (looking-at-p "<<target>>")))
  1279. (should-not
  1280. (org-test-with-temp-text
  1281. "[[target][This is a very\n long description]]<point>\n <<target>>"
  1282. (let ((org-return-follows-link t)
  1283. (org-link-search-must-match-exact-headline nil))
  1284. (org-return))
  1285. (looking-at-p "<<target>>")))
  1286. ;; However, do not open link when point is in a table.
  1287. (should
  1288. (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
  1289. (let ((org-return-follows-link t)) (org-return))
  1290. (looking-at-p "between")))
  1291. ;; Special case: in a list, when indenting, do not break structure.
  1292. (should
  1293. (equal "- A\n B"
  1294. (org-test-with-temp-text "- A <point>B"
  1295. (org-return t)
  1296. (buffer-string))))
  1297. (should
  1298. (equal "- A\n\n- B"
  1299. (org-test-with-temp-text "- A\n<point>- B"
  1300. (org-return t)
  1301. (buffer-string))))
  1302. ;; On tags part of a headline, add a newline below it instead of
  1303. ;; breaking it.
  1304. (should
  1305. (equal "* H :tag:\n"
  1306. (org-test-with-temp-text "* H :<point>tag:"
  1307. (org-return)
  1308. (buffer-string))))
  1309. ;; Before headline text, add a newline below it instead of breaking
  1310. ;; it.
  1311. (should
  1312. (equal "* TODO H :tag:\n"
  1313. (org-test-with-temp-text "* <point>TODO H :tag:"
  1314. (org-return)
  1315. (buffer-string))))
  1316. (should
  1317. (equal "* TODO [#B] H :tag:\n"
  1318. (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
  1319. (org-return)
  1320. (buffer-string))))
  1321. (should ;TODO are case-sensitive
  1322. (equal "* \nTodo"
  1323. (org-test-with-temp-text "* <point>Todo"
  1324. (org-return)
  1325. (buffer-string))))
  1326. ;; At headline text, break headline text but preserve tags.
  1327. (should
  1328. (equal "* TODO [#B] foo :tag:\nbar"
  1329. (let (org-auto-align-tags)
  1330. (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
  1331. (org-return)
  1332. (buffer-string)))))
  1333. ;; At bol of headline insert newline.
  1334. (should
  1335. (equal "\n* h"
  1336. (org-test-with-temp-text "<point>* h"
  1337. (org-return)
  1338. (buffer-string))))
  1339. ;; Refuse to leave invalid headline in buffer.
  1340. (should
  1341. (equal "* h\n"
  1342. (org-test-with-temp-text "*<point> h"
  1343. (org-return)
  1344. (buffer-string))))
  1345. ;; Before first column or after last one in a table, split the
  1346. ;; table.
  1347. (should
  1348. (equal "| a |\n\n| b |"
  1349. (org-test-with-temp-text "| a |\n<point>| b |"
  1350. (org-return)
  1351. (buffer-string))))
  1352. (should
  1353. (equal "| a |\n\n| b |"
  1354. (org-test-with-temp-text "| a |<point>\n| b |"
  1355. (org-return)
  1356. (buffer-string))))
  1357. ;; Do not auto-fill on hitting <RET> inside a property drawer.
  1358. (should
  1359. (equal "* Heading\n:PROPERTIES:\n:SOME_PROP: This is a very long property value that goes beyond the fill-column. But this is inside a property drawer, so the auto-filling should be disabled.\n\n:END:"
  1360. (org-test-with-temp-text "* Heading\n:PROPERTIES:\n:SOME_PROP: This is a very long property value that goes beyond the fill-column. But this is inside a property drawer, so the auto-filling should be disabled.<point>\n:END:"
  1361. (setq-local fill-column 10)
  1362. (auto-fill-mode 1)
  1363. (org-return)
  1364. (buffer-string)))))
  1365. (ert-deftest test-org/with-electric-indent ()
  1366. "Test RET and C-j specifications with `electric-indent-mode' on."
  1367. ;; Call commands interactively, since this is how `newline' knows it
  1368. ;; must run `post-self-insert-hook'.
  1369. ;;
  1370. ;; RET, like `newline', should indent.
  1371. (should
  1372. (equal " Para\n graph"
  1373. (org-test-with-temp-text " Para<point>graph"
  1374. (electric-indent-local-mode 1)
  1375. (call-interactively 'org-return)
  1376. (buffer-string))))
  1377. (should
  1378. (equal "- item1\n item2"
  1379. (org-test-with-temp-text "- item1<point>item2"
  1380. (electric-indent-local-mode 1)
  1381. (call-interactively 'org-return)
  1382. (buffer-string))))
  1383. ;; TODO: test more values of `org-adapt-indentation'.
  1384. (let ((org-adapt-indentation t))
  1385. (should
  1386. (equal "* heading\n body"
  1387. (org-test-with-temp-text "* heading<point>body"
  1388. (electric-indent-local-mode 1)
  1389. (call-interactively 'org-return)
  1390. (buffer-string)))))
  1391. ;; C-j, like `electric-newline-and-maybe-indent', should not indent.
  1392. (should
  1393. (equal " Para\ngraph"
  1394. (org-test-with-temp-text " Para<point>graph"
  1395. (electric-indent-local-mode 1)
  1396. (call-interactively 'org-return-and-maybe-indent)
  1397. (buffer-string))))
  1398. (should
  1399. (equal "- item1\nitem2"
  1400. (org-test-with-temp-text "- item1<point>item2"
  1401. (electric-indent-local-mode 1)
  1402. (call-interactively 'org-return-and-maybe-indent)
  1403. (buffer-string))))
  1404. ;; TODO: test more values of `org-adapt-indentation'.
  1405. (let ((org-adapt-indentation t))
  1406. (should
  1407. (equal "* heading\nbody"
  1408. (org-test-with-temp-text "* heading<point>body"
  1409. (electric-indent-local-mode 1)
  1410. (call-interactively 'org-return-and-maybe-indent)
  1411. (buffer-string))))))
  1412. (ert-deftest test-org/without-electric-indent ()
  1413. "Test RET and C-j specifications with `electric-indent-mode' off."
  1414. ;; Call commands interactively, since this is how `newline' knows it
  1415. ;; must run `post-self-insert-hook'.
  1416. ;;
  1417. ;; RET, like `newline', should not indent.
  1418. (should
  1419. (equal " Para\ngraph"
  1420. (org-test-with-temp-text " Para<point>graph"
  1421. (electric-indent-local-mode 0)
  1422. (call-interactively 'org-return)
  1423. (buffer-string))))
  1424. (should
  1425. (equal "- item1\nitem2"
  1426. (org-test-with-temp-text "- item1<point>item2"
  1427. (electric-indent-local-mode 0)
  1428. (call-interactively 'org-return)
  1429. (buffer-string))))
  1430. (should
  1431. (equal "* heading\nbody"
  1432. (org-test-with-temp-text "* heading<point>body"
  1433. (electric-indent-local-mode 0)
  1434. (call-interactively 'org-return)
  1435. (buffer-string))))
  1436. ;; C-j, like `electric-newline-and-maybe-indent', should indent.
  1437. (should
  1438. (equal " Para\n graph"
  1439. (org-test-with-temp-text " Para<point>graph"
  1440. (electric-indent-local-mode 0)
  1441. (call-interactively 'org-return-and-maybe-indent)
  1442. (buffer-string))))
  1443. (should
  1444. (equal "- item1\n item2"
  1445. (org-test-with-temp-text "- item1<point>item2"
  1446. (electric-indent-local-mode 0)
  1447. (call-interactively 'org-return-and-maybe-indent)
  1448. (buffer-string))))
  1449. ;; TODO: test more values of `org-adapt-indentation'.
  1450. (let ((org-adapt-indentation t))
  1451. (should
  1452. (equal "* heading\n body"
  1453. (org-test-with-temp-text "* heading<point>body"
  1454. (electric-indent-local-mode 0)
  1455. (call-interactively 'org-return-and-maybe-indent)
  1456. (buffer-string))))))
  1457. (ert-deftest test-org/meta-return ()
  1458. "Test M-RET (`org-meta-return') specifications."
  1459. ;; In a table field insert a row above.
  1460. (should
  1461. (org-test-with-temp-text "| a |"
  1462. (forward-char)
  1463. (org-meta-return)
  1464. (forward-line -1)
  1465. (looking-at "| |$")))
  1466. ;; In a paragraph change current line into a header.
  1467. (should
  1468. (org-test-with-temp-text "a"
  1469. (org-meta-return)
  1470. (beginning-of-line)
  1471. (looking-at "\* a$")))
  1472. ;; In an item insert an item, in this case above.
  1473. (should
  1474. (org-test-with-temp-text "- a"
  1475. (org-meta-return)
  1476. (beginning-of-line)
  1477. (looking-at "- $")))
  1478. ;; In a drawer and item insert an item, in this case above.
  1479. (should
  1480. (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
  1481. (forward-line)
  1482. (org-fold-reveal)
  1483. (org-meta-return)
  1484. (beginning-of-line)
  1485. (looking-at "- $"))))
  1486. (ert-deftest test-org/insert-heading ()
  1487. "Test `org-insert-heading' specifications."
  1488. ;; In an empty buffer, insert a new headline.
  1489. (should
  1490. (equal "* "
  1491. (org-test-with-temp-text ""
  1492. (org-insert-heading)
  1493. (buffer-string))))
  1494. ;; At the beginning of a line, turn it into a headline.
  1495. (should
  1496. (equal "* P"
  1497. (org-test-with-temp-text "<point>P"
  1498. (org-insert-heading)
  1499. (buffer-string))))
  1500. ;; In the middle of a line, split the line if allowed, otherwise,
  1501. ;; insert the headline at its end.
  1502. (should
  1503. (equal "Para\n* graph"
  1504. (org-test-with-temp-text "Para<point>graph"
  1505. (let ((org-M-RET-may-split-line '((default . t))))
  1506. (org-insert-heading))
  1507. (buffer-string))))
  1508. (should
  1509. (equal "Paragraph\n* "
  1510. (org-test-with-temp-text "Para<point>graph"
  1511. (let ((org-M-RET-may-split-line '((default . nil))))
  1512. (org-insert-heading))
  1513. (buffer-string))))
  1514. ;; At the beginning of a headline, create one above.
  1515. (should
  1516. (equal "* \n* H"
  1517. (org-test-with-temp-text "* H"
  1518. (org-insert-heading)
  1519. (buffer-string))))
  1520. ;; In the middle of a headline, split it if allowed.
  1521. (should
  1522. (equal "* H\n* 1"
  1523. (org-test-with-temp-text "* H<point>1"
  1524. (let ((org-M-RET-may-split-line '((headline . t))))
  1525. (org-insert-heading))
  1526. (buffer-string))))
  1527. (should
  1528. (equal "* H1\n* "
  1529. (org-test-with-temp-text "* H<point>1"
  1530. (let ((org-M-RET-may-split-line '((headline . nil))))
  1531. (org-insert-heading))
  1532. (buffer-string))))
  1533. ;; However, splitting cannot happen on TODO keywords, priorities or
  1534. ;; tags.
  1535. (should
  1536. (equal "* TODO H1\n* "
  1537. (org-test-with-temp-text "* TO<point>DO H1"
  1538. (let ((org-M-RET-may-split-line '((headline . t))))
  1539. (org-insert-heading))
  1540. (buffer-string))))
  1541. (should
  1542. (equal "* [#A] H1\n* "
  1543. (org-test-with-temp-text "* [#<point>A] H1"
  1544. (let ((org-M-RET-may-split-line '((headline . t))))
  1545. (org-insert-heading))
  1546. (buffer-string))))
  1547. (should
  1548. (equal "* H1 :tag:\n* "
  1549. (org-test-with-temp-text "* H1 :ta<point>g:"
  1550. (let ((org-M-RET-may-split-line '((headline . t))))
  1551. (org-insert-heading))
  1552. (buffer-string))))
  1553. ;; New headline level depends on the level of the headline above.
  1554. (should
  1555. (equal "** H\n** P"
  1556. (org-test-with-temp-text "** H\n<point>P"
  1557. (org-insert-heading)
  1558. (buffer-string))))
  1559. (should
  1560. (equal "** H\nPara\n** graph"
  1561. (org-test-with-temp-text "** H\nPara<point>graph"
  1562. (let ((org-M-RET-may-split-line '((default . t))))
  1563. (org-insert-heading))
  1564. (buffer-string))))
  1565. (should
  1566. (equal "** \n** H"
  1567. (org-test-with-temp-text "** H"
  1568. (org-insert-heading)
  1569. (buffer-string))))
  1570. ;; When called with one universal argument, insert a new headline at
  1571. ;; the end of the current subtree, independently on the position of
  1572. ;; point.
  1573. (should
  1574. (equal
  1575. "* "
  1576. (org-test-with-temp-text ""
  1577. (let ((org-insert-heading-respect-content nil))
  1578. (org-insert-heading '(4)))
  1579. (buffer-string))))
  1580. (should
  1581. (equal
  1582. "entry
  1583. * "
  1584. (org-test-with-temp-text "entry"
  1585. (let ((org-insert-heading-respect-content nil))
  1586. (org-insert-heading '(4)))
  1587. (buffer-string))))
  1588. (should
  1589. (equal
  1590. "* H1\n** H2\n* "
  1591. (org-test-with-temp-text "* H1\n** H2"
  1592. (let ((org-insert-heading-respect-content nil))
  1593. (org-insert-heading '(4)))
  1594. (buffer-string))))
  1595. (should
  1596. (equal
  1597. "* H1\n** H2\n* "
  1598. (org-test-with-temp-text "* H<point>1\n** H2"
  1599. (let ((org-insert-heading-respect-content nil))
  1600. (org-insert-heading '(4)))
  1601. (buffer-string))))
  1602. ;; When called with two universal arguments, insert a new headline
  1603. ;; at the end of the grandparent subtree.
  1604. (should
  1605. (equal "* H1\n** H3\n- item\n** H2\n** "
  1606. (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
  1607. (let ((org-insert-heading-respect-content nil))
  1608. (org-insert-heading '(16)))
  1609. (buffer-string))))
  1610. ;; When optional TOP-LEVEL argument is non-nil, always insert
  1611. ;; a level 1 heading.
  1612. (should
  1613. (equal "* H1\n** H2\n* "
  1614. (org-test-with-temp-text "* H1\n** H2<point>"
  1615. (org-insert-heading nil nil t)
  1616. (buffer-string))))
  1617. (should
  1618. (equal "* H1\n- item\n* "
  1619. (org-test-with-temp-text "* H1\n- item<point>"
  1620. (org-insert-heading nil nil t)
  1621. (buffer-string))))
  1622. ;; Obey `org-blank-before-new-entry'.
  1623. (should
  1624. (equal "* H1\n\n* "
  1625. (org-test-with-temp-text "* H1<point>"
  1626. (let ((org-blank-before-new-entry '((heading . t))))
  1627. (org-insert-heading))
  1628. (buffer-string))))
  1629. (should
  1630. (equal "* H1\n* "
  1631. (org-test-with-temp-text "* H1<point>"
  1632. (let ((org-blank-before-new-entry '((heading . nil))))
  1633. (org-insert-heading))
  1634. (buffer-string))))
  1635. (should
  1636. (equal "* H1\n* H2\n* "
  1637. (org-test-with-temp-text "* H1\n* H2<point>"
  1638. (let ((org-blank-before-new-entry '((heading . auto))))
  1639. (org-insert-heading))
  1640. (buffer-string))))
  1641. (should
  1642. (equal "* H1\n\n* H2\n\n* "
  1643. (org-test-with-temp-text "* H1\n\n* H2<point>"
  1644. (let ((org-blank-before-new-entry '((heading . auto))))
  1645. (org-insert-heading))
  1646. (buffer-string))))
  1647. ;; Corner case: correctly insert a headline after an empty one.
  1648. (should
  1649. (equal "* \n* "
  1650. (org-test-with-temp-text "* <point>"
  1651. (org-insert-heading)
  1652. (buffer-string))))
  1653. (should
  1654. (org-test-with-temp-text "* <point>\n"
  1655. (org-insert-heading)
  1656. (looking-at-p "\n\\'")))
  1657. ;; Do not insert spurious headlines when inserting a new headline.
  1658. (should
  1659. (equal "* H1\n* H2\n* \n"
  1660. (org-test-with-temp-text "* H1\n* H2<point>\n"
  1661. (org-insert-heading)
  1662. (buffer-string))))
  1663. ;; Preserve visibility at beginning of line. In particular, when
  1664. ;; removing spurious blank lines, do not visually merge heading with
  1665. ;; the line visible above.
  1666. (should-not
  1667. (org-test-with-temp-text "* H1<point>\nContents\n\n* H2\n"
  1668. (org-overview)
  1669. (let ((org-blank-before-new-entry '((heading . nil))))
  1670. (org-insert-heading '(4)))
  1671. (invisible-p (line-end-position 0))))
  1672. ;; Properly handle empty lines when forcing a headline below current
  1673. ;; one.
  1674. (should
  1675. (equal "* H1\n\n* H\n\n* "
  1676. (org-test-with-temp-text "* H1\n\n* H<point>"
  1677. (let ((org-blank-before-new-entry '((heading . t))))
  1678. (org-insert-heading '(4))
  1679. (buffer-string))))))
  1680. (ert-deftest test-org/insert-todo-heading-respect-content ()
  1681. "Test `org-insert-todo-heading-respect-content' specifications."
  1682. ;; Create a TODO heading.
  1683. (should
  1684. (org-test-with-temp-text "* H1\n Body"
  1685. (org-insert-todo-heading-respect-content)
  1686. (nth 2 (org-heading-components))))
  1687. ;; Add headline at the end of the first subtree
  1688. (should
  1689. (equal
  1690. "* TODO "
  1691. (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
  1692. (org-insert-todo-heading-respect-content)
  1693. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1694. ;; In a list, do not create a new item.
  1695. (should
  1696. (equal
  1697. "* TODO "
  1698. (org-test-with-temp-text "* H\n- an item\n- another one"
  1699. (search-forward "an ")
  1700. (org-insert-todo-heading-respect-content)
  1701. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1702. ;; Use the same TODO keyword as current heading.
  1703. (should
  1704. (equal
  1705. "* TODO \n"
  1706. (org-test-with-temp-text "* TODO\n** WAITING\n"
  1707. (org-insert-todo-heading-respect-content)
  1708. (buffer-substring-no-properties (line-beginning-position) (point-max))))))
  1709. (ert-deftest test-org/clone-with-time-shift ()
  1710. "Test `org-clone-subtree-with-time-shift'."
  1711. ;; Raise an error before first heading.
  1712. (should-error
  1713. (org-test-with-temp-text ""
  1714. (org-clone-subtree-with-time-shift 1)))
  1715. ;; Raise an error on invalid number of clones.
  1716. (should-error
  1717. (org-test-with-temp-text "* Clone me"
  1718. (org-clone-subtree-with-time-shift -1)))
  1719. ;; Clone non-repeating once.
  1720. (should
  1721. (equal "\
  1722. * H1\n<2015-06-21>
  1723. * H1\n<2015-06-23>
  1724. "
  1725. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1726. (org-clone-subtree-with-time-shift 1 "+2d")
  1727. (replace-regexp-in-string
  1728. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1729. nil nil 1))))
  1730. ;; Clone repeating once.
  1731. (should
  1732. (equal "\
  1733. * H1\n<2015-06-21>
  1734. * H1\n<2015-06-23>
  1735. * H1\n<2015-06-25 +1w>
  1736. "
  1737. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1738. (org-clone-subtree-with-time-shift 1 "+2d")
  1739. (replace-regexp-in-string
  1740. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1741. nil nil 1))))
  1742. ;; Clone repeating once in backward.
  1743. (should
  1744. (equal "\
  1745. * H1\n<2015-06-21>
  1746. * H1\n<2015-06-19>
  1747. * H1\n<2015-06-17 +1w>
  1748. "
  1749. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1750. (org-clone-subtree-with-time-shift 1 "-2d")
  1751. (replace-regexp-in-string
  1752. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1753. nil nil 1))))
  1754. ;; Clone non-repeating zero times.
  1755. (should
  1756. (equal "\
  1757. * H1\n<2015-06-21>
  1758. "
  1759. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1760. (org-clone-subtree-with-time-shift 0 "+2d")
  1761. (replace-regexp-in-string
  1762. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1763. nil nil 1))))
  1764. ;; Clone repeating "zero" times.
  1765. (should
  1766. (equal "\
  1767. * H1\n<2015-06-21>
  1768. * H1\n<2015-06-23 +1w>
  1769. "
  1770. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1771. (org-clone-subtree-with-time-shift 0 "+2d")
  1772. (replace-regexp-in-string
  1773. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1774. nil nil 1))))
  1775. ;; Clone with blank SHIFT argument.
  1776. (should
  1777. (string-prefix-p
  1778. "* H <2012-03-29"
  1779. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1780. (org-clone-subtree-with-time-shift 1 "")
  1781. (buffer-substring-no-properties (line-beginning-position 2)
  1782. (line-end-position 2)))))
  1783. ;; Find time stamps before point. If SHIFT is not specified, ask
  1784. ;; for a time shift.
  1785. (should
  1786. (string-prefix-p
  1787. "* H <2012-03-30"
  1788. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1789. (org-clone-subtree-with-time-shift 1 "+1d")
  1790. (buffer-substring-no-properties (line-beginning-position 2)
  1791. (line-end-position 2)))))
  1792. (should
  1793. (string-prefix-p
  1794. "* H <2014-03-05"
  1795. (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
  1796. (cl-letf (((symbol-function 'read-from-minibuffer)
  1797. (lambda (&rest args) "+1d")))
  1798. (org-clone-subtree-with-time-shift 1))
  1799. (buffer-substring-no-properties (line-beginning-position 2)
  1800. (line-end-position 2)))))
  1801. ;; Hour shift.
  1802. (should
  1803. (equal "\
  1804. * H1\n<2015-06-21 20:00>
  1805. * H1\n<2015-06-21 23:00>
  1806. * H1\n<2015-06-22 02:00>
  1807. "
  1808. (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>"
  1809. (org-clone-subtree-with-time-shift 2 "+3h")
  1810. (replace-regexp-in-string
  1811. "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" ""
  1812. (buffer-substring-no-properties (point-min) (point-max))
  1813. nil nil 1))))
  1814. (should
  1815. (equal "\
  1816. * H1\n<2015-06-21 20:00>
  1817. * H1\n<2015-06-21 18:00>
  1818. "
  1819. (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>"
  1820. (org-clone-subtree-with-time-shift 1 "-2h")
  1821. (replace-regexp-in-string
  1822. "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" ""
  1823. (buffer-substring-no-properties (point-min) (point-max))
  1824. nil nil 1)))))
  1825. ;;; Fixed-Width Areas
  1826. (ert-deftest test-org/toggle-fixed-width ()
  1827. "Test `org-toggle-fixed-width' specifications."
  1828. ;; No region: Toggle on fixed-width marker in paragraphs.
  1829. (should
  1830. (equal ": A"
  1831. (org-test-with-temp-text "A"
  1832. (org-toggle-fixed-width)
  1833. (buffer-string))))
  1834. ;; No region: Toggle off fixed-width markers in fixed-width areas.
  1835. (should
  1836. (equal "A"
  1837. (org-test-with-temp-text ": A"
  1838. (org-toggle-fixed-width)
  1839. (buffer-string))))
  1840. ;; No region: Toggle on marker in blank lines after elements or just
  1841. ;; after a headline.
  1842. (should
  1843. (equal "* H\n: "
  1844. (org-test-with-temp-text "* H\n"
  1845. (forward-line)
  1846. (org-toggle-fixed-width)
  1847. (buffer-string))))
  1848. (should
  1849. (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
  1850. (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
  1851. (goto-char (point-max))
  1852. (org-toggle-fixed-width)
  1853. (buffer-string))))
  1854. ;; No region: Toggle on marker in front of one line elements (e.g.,
  1855. ;; headlines, clocks)
  1856. (should
  1857. (equal ": * Headline"
  1858. (org-test-with-temp-text "* Headline"
  1859. (org-toggle-fixed-width)
  1860. (buffer-string))))
  1861. (should
  1862. (equal ": #+KEYWORD: value"
  1863. (org-test-with-temp-text "#+KEYWORD: value"
  1864. (org-toggle-fixed-width)
  1865. (buffer-string))))
  1866. ;; No region: error in other situations.
  1867. (should-error
  1868. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
  1869. (forward-line)
  1870. (org-toggle-fixed-width)
  1871. (buffer-string)))
  1872. ;; No region: Indentation is preserved.
  1873. (should
  1874. (equal "- A\n : B"
  1875. (org-test-with-temp-text "- A\n B"
  1876. (forward-line)
  1877. (org-toggle-fixed-width)
  1878. (buffer-string))))
  1879. ;; Region: If it contains only fixed-width elements and blank lines,
  1880. ;; toggle off fixed-width markup.
  1881. (should
  1882. (equal "A\n\nB"
  1883. (org-test-with-temp-text ": A\n\n: B"
  1884. (transient-mark-mode 1)
  1885. (push-mark (point) t t)
  1886. (goto-char (point-max))
  1887. (org-toggle-fixed-width)
  1888. (buffer-string))))
  1889. ;; Region: If it contains anything else, toggle on fixed-width but
  1890. ;; not on fixed-width areas.
  1891. (should
  1892. (equal ": A\n: \n: B\n: \n: C"
  1893. (org-test-with-temp-text "A\n\n: B\n\nC"
  1894. (transient-mark-mode 1)
  1895. (push-mark (point) t t)
  1896. (goto-char (point-max))
  1897. (org-toggle-fixed-width)
  1898. (buffer-string))))
  1899. ;; Region: Ignore blank lines at its end, unless it contains only
  1900. ;; such lines.
  1901. (should
  1902. (equal ": A\n\n"
  1903. (org-test-with-temp-text "A\n\n"
  1904. (transient-mark-mode 1)
  1905. (push-mark (point) t t)
  1906. (goto-char (point-max))
  1907. (org-toggle-fixed-width)
  1908. (buffer-string))))
  1909. (should
  1910. (equal ": \n: \n"
  1911. (org-test-with-temp-text "\n\n"
  1912. (transient-mark-mode 1)
  1913. (push-mark (point) t t)
  1914. (goto-char (point-max))
  1915. (org-toggle-fixed-width)
  1916. (buffer-string)))))
  1917. (ert-deftest test-org/kill-line ()
  1918. "Test `org-kill-line' specifications."
  1919. ;; At the beginning of a line, kill whole line.
  1920. (should
  1921. (equal ""
  1922. (org-test-with-temp-text "abc"
  1923. (org-kill-line)
  1924. (buffer-string))))
  1925. ;; In the middle of a line, kill line until its end.
  1926. (should
  1927. (equal "a"
  1928. (org-test-with-temp-text "a<point>bc"
  1929. (org-kill-line)
  1930. (buffer-string))))
  1931. ;; Do not kill newline character.
  1932. (should
  1933. (equal "\n123"
  1934. (org-test-with-temp-text "abc\n123"
  1935. (org-kill-line)
  1936. (buffer-string))))
  1937. (should
  1938. (equal "a\n123"
  1939. (org-test-with-temp-text "a<point>bc\n123"
  1940. (org-kill-line)
  1941. (buffer-string))))
  1942. ;; When `org-special-ctrl-k' is non-nil and point is at a headline,
  1943. ;; kill until tags.
  1944. (should
  1945. (equal "* A :tag:"
  1946. (org-test-with-temp-text "* A<point>B :tag:"
  1947. (let ((org-special-ctrl-k t)
  1948. (org-tags-column 0))
  1949. (org-kill-line))
  1950. (buffer-string))))
  1951. ;; If point is on tags, only kill part left until the end of line.
  1952. (should
  1953. (equal "* A :tag:"
  1954. (org-test-with-temp-text "* A :tag:<point>tag2:"
  1955. (let ((org-special-ctrl-k t)
  1956. (org-tags-column 0))
  1957. (org-kill-line))
  1958. (buffer-string))))
  1959. ;; However, if point is at the beginning of the line, kill whole
  1960. ;; headline.
  1961. (should
  1962. (equal ""
  1963. (org-test-with-temp-text "* AB :tag:"
  1964. (let ((org-special-ctrl-k t)
  1965. (org-tags-column 0))
  1966. (org-kill-line))
  1967. (buffer-string))))
  1968. ;; When `org-ctrl-k-protect-subtree' is non-nil, and point is in
  1969. ;; invisible text, ask before removing it. When set to `error',
  1970. ;; throw an error.
  1971. (should-error
  1972. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  1973. (org-overview)
  1974. (let ((org-special-ctrl-k nil)
  1975. (org-ctrl-k-protect-subtree t))
  1976. (cl-letf (((symbol-function 'y-or-n-p) 'ignore))
  1977. (org-kill-line)))))
  1978. (should-error
  1979. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  1980. (org-overview)
  1981. (let ((org-special-ctrl-k nil)
  1982. (org-ctrl-k-protect-subtree 'error))
  1983. (org-kill-line)))))
  1984. ;;; Headline
  1985. (ert-deftest test-org/get-heading ()
  1986. "Test `org-get-heading' specifications."
  1987. ;; Return current heading, even if point is not on it.
  1988. (should
  1989. (equal "H"
  1990. (org-test-with-temp-text "* H"
  1991. (org-get-heading))))
  1992. (should
  1993. (equal "H"
  1994. (org-test-with-temp-text "* H\nText<point>"
  1995. (org-get-heading))))
  1996. ;; Without any optional argument, return TODO keyword, priority
  1997. ;; cookie, COMMENT keyword and tags.
  1998. (should
  1999. (equal "TODO H"
  2000. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2001. (org-get-heading))))
  2002. (should
  2003. (equal "[#A] H"
  2004. (org-test-with-temp-text "* [#A] H"
  2005. (org-get-heading))))
  2006. (should
  2007. (equal "COMMENT H"
  2008. (org-test-with-temp-text "* COMMENT H"
  2009. (org-get-heading))))
  2010. (should
  2011. (equal "H :tag:"
  2012. (org-test-with-temp-text "* H :tag:"
  2013. (org-get-heading))))
  2014. ;; With NO-TAGS argument, ignore tags.
  2015. (should
  2016. (equal "TODO H"
  2017. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2018. (org-get-heading t))))
  2019. (should
  2020. (equal "H"
  2021. (org-test-with-temp-text "* H :tag:"
  2022. (org-get-heading t))))
  2023. ;; With NO-TODO, ignore TODO keyword.
  2024. (should
  2025. (equal "H"
  2026. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2027. (org-get-heading nil t))))
  2028. (should
  2029. (equal "H :tag:"
  2030. (org-test-with-temp-text "* H :tag:"
  2031. (org-get-heading nil t))))
  2032. ;; TODO keywords are case-sensitive.
  2033. (should
  2034. (equal "Todo H"
  2035. (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
  2036. (org-get-heading nil t))))
  2037. ;; With NO-PRIORITY, ignore priority.
  2038. (should
  2039. (equal "H"
  2040. (org-test-with-temp-text "* [#A] H"
  2041. (org-get-heading nil nil t))))
  2042. (should
  2043. (equal "H"
  2044. (org-test-with-temp-text "* H"
  2045. (org-get-heading nil nil t))))
  2046. (should
  2047. (equal "TODO H"
  2048. (org-test-with-temp-text "* TODO [#A] H"
  2049. (org-get-heading nil nil t))))
  2050. ;; With NO-COMMENT, ignore COMMENT keyword.
  2051. (should
  2052. (equal "H"
  2053. (org-test-with-temp-text "* COMMENT H"
  2054. (org-get-heading nil nil nil t))))
  2055. (should
  2056. (equal "H"
  2057. (org-test-with-temp-text "* H"
  2058. (org-get-heading nil nil nil t))))
  2059. (should
  2060. (equal "TODO [#A] H"
  2061. (org-test-with-temp-text "* TODO [#A] COMMENT H"
  2062. (org-get-heading nil nil nil t))))
  2063. ;; On an empty headline, return value is consistent.
  2064. (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
  2065. (should (equal "" (org-test-with-temp-text "* " (org-get-heading t))))
  2066. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t))))
  2067. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t))))
  2068. (should
  2069. (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t)))))
  2070. (ert-deftest test-org/in-commented-heading-p ()
  2071. "Test `org-in-commented-heading-p' specifications."
  2072. ;; Commented headline.
  2073. (should
  2074. (org-test-with-temp-text "* COMMENT Headline\nBody"
  2075. (goto-char (point-max))
  2076. (org-in-commented-heading-p)))
  2077. ;; Commented ancestor.
  2078. (should
  2079. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  2080. (goto-char (point-max))
  2081. (org-in-commented-heading-p)))
  2082. ;; Comment keyword is case-sensitive.
  2083. (should-not
  2084. (org-test-with-temp-text "* Comment Headline\nBody"
  2085. (goto-char (point-max))
  2086. (org-in-commented-heading-p)))
  2087. ;; Keyword is standalone.
  2088. (should-not
  2089. (org-test-with-temp-text "* COMMENTHeadline\nBody"
  2090. (goto-char (point-max))
  2091. (org-in-commented-heading-p)))
  2092. ;; Optional argument.
  2093. (should-not
  2094. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  2095. (goto-char (point-max))
  2096. (org-in-commented-heading-p t))))
  2097. (ert-deftest test-org/in-archived-heading-p ()
  2098. "Test `org-in-archived-heading-p' specifications."
  2099. ;; Archived headline.
  2100. (should
  2101. (org-test-with-temp-text "* Headline :ARCHIVE:\nBody"
  2102. (goto-char (point-max))
  2103. (org-in-archived-heading-p)))
  2104. ;; Archived ancestor.
  2105. (should
  2106. (org-test-with-temp-text "* Headline :ARCHIVE:\n** Level 2\nBody"
  2107. (goto-char (point-max))
  2108. (org-in-archived-heading-p)))
  2109. ;; Optional argument.
  2110. (should-not
  2111. (org-test-with-temp-text "* Headline :ARCHIVE:\n** Level 2\nBody"
  2112. (goto-char (point-max))
  2113. (org-in-archived-heading-p t)))
  2114. ;; Archive tag containing ARCHIVE as substring
  2115. (should-not
  2116. (org-test-with-temp-text "* Headline :NOARCHIVE:\n** Level 2\nBody"
  2117. (goto-char (point-max))
  2118. (org-in-archived-heading-p))))
  2119. (ert-deftest test-org/entry-blocked-p ()
  2120. ;; Check other dependencies.
  2121. (should
  2122. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  2123. (let ((org-enforce-todo-dependencies t)
  2124. (org-blocker-hook
  2125. '(org-block-todo-from-children-or-siblings-or-parent)))
  2126. (org-entry-blocked-p))))
  2127. (should-not
  2128. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  2129. (let ((org-enforce-todo-dependencies t)
  2130. (org-blocker-hook
  2131. '(org-block-todo-from-children-or-siblings-or-parent)))
  2132. (org-entry-blocked-p))))
  2133. ;; Entry without a TODO keyword or with a DONE keyword cannot be
  2134. ;; blocked.
  2135. (should-not
  2136. (org-test-with-temp-text "* Blocked\n** TODO one"
  2137. (let ((org-enforce-todo-dependencies t)
  2138. (org-blocker-hook
  2139. '(org-block-todo-from-children-or-siblings-or-parent)))
  2140. (org-entry-blocked-p))))
  2141. (should-not
  2142. (org-test-with-temp-text "* DONE Blocked\n** TODO one"
  2143. (let ((org-enforce-todo-dependencies t)
  2144. (org-blocker-hook
  2145. '(org-block-todo-from-children-or-siblings-or-parent)))
  2146. (org-entry-blocked-p))))
  2147. ;; Follow :ORDERED: specifications.
  2148. (should
  2149. (org-test-with-temp-text
  2150. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
  2151. (let ((org-enforce-todo-dependencies t)
  2152. (org-blocker-hook
  2153. '(org-block-todo-from-children-or-siblings-or-parent)))
  2154. (org-entry-blocked-p))))
  2155. (should-not
  2156. (org-test-with-temp-text
  2157. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
  2158. (let ((org-enforce-todo-dependencies t)
  2159. (org-blocker-hook
  2160. '(org-block-todo-from-children-or-siblings-or-parent)))
  2161. (org-entry-blocked-p)))))
  2162. (ert-deftest test-org/get-outline-path ()
  2163. "Test `org-get-outline-path' specifications."
  2164. ;; Top-level headlines have no outline path.
  2165. (should-not
  2166. (org-test-with-temp-text "* H"
  2167. (org-get-outline-path)))
  2168. ;; Otherwise, outline path is the path leading to the headline.
  2169. (should
  2170. (equal '("H")
  2171. (org-test-with-temp-text "* H\n** S<point>"
  2172. (org-get-outline-path))))
  2173. ;; Find path even when point is not on a headline.
  2174. (should
  2175. (equal '("H")
  2176. (org-test-with-temp-text "* H\n** S\nText<point>"
  2177. (org-get-outline-path))))
  2178. ;; TODO keywords, tags and statistics cookies are ignored.
  2179. (should
  2180. (equal '("H")
  2181. (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
  2182. (org-get-outline-path))))
  2183. ;; Links are replaced with their description or their path.
  2184. (should
  2185. (equal '("Org")
  2186. (org-test-with-temp-text
  2187. "* [[https://orgmode.org][Org]]\n** S<point>"
  2188. (org-get-outline-path))))
  2189. (should
  2190. (equal '("https://orgmode.org")
  2191. (org-test-with-temp-text
  2192. "* [[https://orgmode.org]]\n** S<point>"
  2193. (org-get-outline-path))))
  2194. ;; When WITH-SELF is non-nil, include current heading.
  2195. (should
  2196. (equal '("H")
  2197. (org-test-with-temp-text "* H"
  2198. (org-get-outline-path t))))
  2199. (should
  2200. (equal '("H" "S")
  2201. (org-test-with-temp-text "* H\n** S\nText<point>"
  2202. (org-get-outline-path t))))
  2203. ;; Using cache is transparent to the user.
  2204. (should
  2205. (equal '("H")
  2206. (org-test-with-temp-text "* H\n** S<point>"
  2207. (setq org-outline-path-cache nil)
  2208. (org-get-outline-path nil t))))
  2209. ;; Do not corrupt cache when finding outline path in distant part of
  2210. ;; the buffer.
  2211. (should
  2212. (equal '("H2")
  2213. (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
  2214. (setq org-outline-path-cache nil)
  2215. (org-get-outline-path nil t)
  2216. (search-forward "S2")
  2217. (org-get-outline-path nil t))))
  2218. ;; Do not choke on empty headlines.
  2219. (should
  2220. (org-test-with-temp-text "* H\n** <point>"
  2221. (org-get-outline-path)))
  2222. (should
  2223. (org-test-with-temp-text "* \n** H<point>"
  2224. (org-get-outline-path))))
  2225. (ert-deftest test-org/format-outline-path ()
  2226. "Test `org-format-outline-path' specifications."
  2227. (should
  2228. (string= (org-format-outline-path (list "one" "two" "three"))
  2229. "one/two/three"))
  2230. ;; Empty path.
  2231. (should
  2232. (string= (org-format-outline-path '())
  2233. ""))
  2234. (should
  2235. (string= (org-format-outline-path '(nil))
  2236. ""))
  2237. ;; Empty path and prefix.
  2238. (should
  2239. (string= (org-format-outline-path '() nil ">>")
  2240. ">>"))
  2241. ;; Trailing whitespace in headings.
  2242. (should
  2243. (string= (org-format-outline-path (list "one\t" "tw o " "three "))
  2244. "one/tw o/three"))
  2245. ;; Non-default prefix and separators.
  2246. (should
  2247. (string= (org-format-outline-path (list "one" "two" "three") nil ">>" "|")
  2248. ">>|one|two|three"))
  2249. ;; Truncate.
  2250. (should
  2251. (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
  2252. "one/two/.."))
  2253. ;; Give a very narrow width.
  2254. (should
  2255. (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
  2256. "on"))
  2257. ;; Give a prefix that extends beyond the width.
  2258. (should
  2259. (string= (org-format-outline-path (list "one" "two" "three" "four") 10
  2260. ">>>>>>>>>>")
  2261. ">>>>>>>>..")))
  2262. (ert-deftest test-org/map-entries ()
  2263. "Test `org-map-entries' specifications."
  2264. ;; Full match.
  2265. (should
  2266. (equal '(1 11)
  2267. (org-test-with-temp-text "* Level 1\n** Level 2"
  2268. (org-map-entries #'point))))
  2269. ;; Level match.
  2270. (should
  2271. (equal '(1)
  2272. (org-test-with-temp-text "* Level 1\n** Level 2"
  2273. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL=1")))))
  2274. (should
  2275. (equal '(11)
  2276. (org-test-with-temp-text "* Level 1\n** Level 2"
  2277. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL>1")))))
  2278. ;; Tag match.
  2279. (should
  2280. (equal '(11)
  2281. (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
  2282. (org-map-entries #'point "yes"))))
  2283. (should
  2284. (equal '(14)
  2285. (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
  2286. (org-map-entries #'point "+yes-a"))))
  2287. (should
  2288. (equal '(11 23)
  2289. (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
  2290. (org-map-entries #'point "{yes?}"))))
  2291. ;; Priority match.
  2292. (should
  2293. (equal '(1)
  2294. (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
  2295. (org-map-entries #'point "PRIORITY=\"A\""))))
  2296. ;; Date match.
  2297. (should
  2298. (equal '(36)
  2299. (org-test-with-temp-text "
  2300. * H1
  2301. SCHEDULED: <2012-03-29 thu.>
  2302. * H2
  2303. SCHEDULED: <2014-03-04 tue.>"
  2304. (org-map-entries #'point "SCHEDULED=\"<2014-03-04 tue.>\""))))
  2305. (should
  2306. (equal '(2)
  2307. (org-test-with-temp-text "
  2308. * H1
  2309. SCHEDULED: <2012-03-29 thu.>
  2310. * H2
  2311. SCHEDULED: <2014-03-04 tue.>"
  2312. (org-map-entries #'point "SCHEDULED<\"<2013-01-01>\""))))
  2313. ;; Regular property match.
  2314. (should
  2315. (equal '(2)
  2316. (org-test-with-temp-text "
  2317. * H1
  2318. :PROPERTIES:
  2319. :TEST: 1
  2320. :END:
  2321. * H2
  2322. :PROPERTIES:
  2323. :TEST: 2
  2324. :END:"
  2325. (org-map-entries #'point "TEST=1"))))
  2326. ;; Multiple criteria.
  2327. (should
  2328. (equal '(23)
  2329. (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
  2330. (let (org-odd-levels-only
  2331. (org-use-tag-inheritance nil))
  2332. (org-map-entries #'point "yes+LEVEL=1")))))
  2333. ;; "or" criteria.
  2334. (should
  2335. (equal '(12 24)
  2336. (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
  2337. (let (org-odd-levels-only)
  2338. (org-map-entries #'point "LEVEL=2|no")))))
  2339. (should
  2340. (equal '(1 12)
  2341. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
  2342. (let (org-odd-levels-only)
  2343. (org-map-entries #'point "yes|no")))))
  2344. ;; "and" criteria.
  2345. (should
  2346. (equal '(22)
  2347. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
  2348. (let (org-odd-levels-only)
  2349. (org-map-entries #'point "yes&no")))))
  2350. ;; Setting `org-map-continue-from'
  2351. (should
  2352. (string= ""
  2353. (org-test-with-temp-text "* H1\n* H2\n* H3n* H4"
  2354. (org-map-entries
  2355. (lambda ()
  2356. (org-cut-subtree)
  2357. (setq org-map-continue-from (point))))
  2358. (buffer-string))))
  2359. (should
  2360. (string= "* H1\n* H2\n* H3\n"
  2361. (org-test-with-temp-text "* H1\n* H2\n* H3\n* H4"
  2362. (org-map-entries
  2363. (lambda ()
  2364. (when (string= "H4"
  2365. (org-element-property
  2366. :raw-value (org-element-at-point)))
  2367. (org-cut-subtree)
  2368. (setq org-map-continue-from
  2369. (org-element-property
  2370. :begin (org-element-at-point))))))
  2371. (buffer-string)))))
  2372. (ert-deftest test-org/edit-headline ()
  2373. "Test `org-edit-headline' specifications."
  2374. (should
  2375. (equal "* B"
  2376. (org-test-with-temp-text "* A"
  2377. (org-edit-headline "B")
  2378. (buffer-string))))
  2379. ;; Handle empty headings.
  2380. (should
  2381. (equal "* "
  2382. (org-test-with-temp-text "* A"
  2383. (org-edit-headline "")
  2384. (buffer-string))))
  2385. (should
  2386. (equal "* A"
  2387. (org-test-with-temp-text "* "
  2388. (org-edit-headline "A")
  2389. (buffer-string))))
  2390. ;; Handle TODO keywords and priority cookies.
  2391. (should
  2392. (equal "* TODO B"
  2393. (org-test-with-temp-text "* TODO A"
  2394. (org-edit-headline "B")
  2395. (buffer-string))))
  2396. (should
  2397. (equal "* [#A] B"
  2398. (org-test-with-temp-text "* [#A] A"
  2399. (org-edit-headline "B")
  2400. (buffer-string))))
  2401. (should
  2402. (equal "* TODO [#A] B"
  2403. (org-test-with-temp-text "* TODO [#A] A"
  2404. (org-edit-headline "B")
  2405. (buffer-string))))
  2406. ;; Handle tags.
  2407. (equal "* B :tag:"
  2408. (org-test-with-temp-text "* A :tag:"
  2409. (let ((org-tags-column 4)) (org-edit-headline "B"))
  2410. (buffer-string))))
  2411. ;;; Keywords
  2412. (ert-deftest test-org/set-regexps-and-options ()
  2413. "Test `org-set-regexps-and-options' specifications."
  2414. ;; TAGS keyword.
  2415. (should
  2416. (equal '(("A"))
  2417. (let ((org-tag-alist '(("A")))
  2418. (org-tag-persistent-alist nil))
  2419. (org-test-with-temp-text ""
  2420. (org-mode-restart)
  2421. org-current-tag-alist))))
  2422. (should
  2423. (equal '(("B"))
  2424. (let ((org-tag-alist '(("A")))
  2425. (org-tag-persistent-alist nil))
  2426. (org-test-with-temp-text "#+TAGS: B"
  2427. (org-mode-restart)
  2428. org-current-tag-alist))))
  2429. (should
  2430. (equal '(("C") ("B"))
  2431. (let ((org-tag-alist '(("A")))
  2432. (org-tag-persistent-alist '(("C"))))
  2433. (org-test-with-temp-text "#+TAGS: B"
  2434. (org-mode-restart)
  2435. org-current-tag-alist))))
  2436. (should
  2437. (equal '(("B"))
  2438. (let ((org-tag-alist '(("A")))
  2439. (org-tag-persistent-alist '(("C"))))
  2440. (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
  2441. (org-mode-restart)
  2442. org-current-tag-alist))))
  2443. (should
  2444. (equal '(("A" . ?a) ("B") ("C"))
  2445. (let ((org-tag-persistant-alist nil))
  2446. (org-test-with-temp-text "#+TAGS: A(a) B C"
  2447. (org-mode-restart)
  2448. org-current-tag-alist))))
  2449. (should
  2450. (equal '(("A") (:newline) ("B"))
  2451. (let ((org-tag-persistent-alist nil))
  2452. (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
  2453. (org-mode-restart)
  2454. org-current-tag-alist))))
  2455. (should
  2456. (equal '((:startgroup) ("A") ("B") (:endgroup) ("C"))
  2457. (let ((org-tag-persistent-alist nil))
  2458. (org-test-with-temp-text "#+TAGS: { A B } C"
  2459. (org-mode-restart)
  2460. org-current-tag-alist))))
  2461. (should
  2462. (equal '((:startgroup) ("A") (:grouptags) ("B") ("C") (:endgroup))
  2463. (let ((org-tag-persistent-alist nil))
  2464. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2465. (org-mode-restart)
  2466. org-current-tag-alist))))
  2467. (should
  2468. (equal '(("A" "B" "C"))
  2469. (let ((org-tag-persistent-alist nil))
  2470. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2471. (org-mode-restart)
  2472. org-tag-groups-alist))))
  2473. (should
  2474. (equal '((:startgrouptag) ("A") (:grouptags) ("B") ("C") (:endgrouptag))
  2475. (let ((org-tag-persistent-alist nil))
  2476. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2477. (org-mode-restart)
  2478. org-current-tag-alist))))
  2479. (should
  2480. (equal '(("A" "B" "C"))
  2481. (let ((org-tag-persistent-alist nil))
  2482. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2483. (org-mode-restart)
  2484. org-tag-groups-alist))))
  2485. (should-not
  2486. (let ((org-tag-alist '(("A"))))
  2487. (org-test-with-temp-text "#+TAGS:"
  2488. (org-mode-restart)
  2489. org-current-tag-alist)))
  2490. ;; FILETAGS keyword.
  2491. (should
  2492. (equal '("A" "B" "C")
  2493. (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
  2494. (org-mode-restart)
  2495. org-file-tags)))
  2496. ;; PROPERTY keyword. Property names are case-insensitive.
  2497. (should
  2498. (equal "foo=1"
  2499. (org-test-with-temp-text "#+PROPERTY: var foo=1"
  2500. (org-mode-restart)
  2501. (cdr (assoc "var" org-keyword-properties)))))
  2502. (should
  2503. (equal
  2504. "foo=1 bar=2"
  2505. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
  2506. (org-mode-restart)
  2507. (cdr (assoc "var" org-keyword-properties)))))
  2508. (should
  2509. (equal
  2510. "foo=1 bar=2"
  2511. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
  2512. (org-mode-restart)
  2513. (cdr (assoc "var" org-keyword-properties)))))
  2514. ;; ARCHIVE keyword.
  2515. (should
  2516. (equal "%s_done::"
  2517. (org-test-with-temp-text "#+ARCHIVE: %s_done::"
  2518. (org-mode-restart)
  2519. org-archive-location)))
  2520. ;; CATEGORY keyword.
  2521. (should
  2522. (eq 'test
  2523. (org-test-with-temp-text "#+CATEGORY: test"
  2524. (org-mode-restart)
  2525. org-category)))
  2526. (should
  2527. (equal "test"
  2528. (org-test-with-temp-text "#+CATEGORY: test"
  2529. (org-mode-restart)
  2530. (cdr (assoc "CATEGORY" org-keyword-properties)))))
  2531. ;; COLUMNS keyword.
  2532. (should
  2533. (equal "%25ITEM %TAGS %PRIORITY %TODO"
  2534. (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
  2535. (org-mode-restart)
  2536. org-columns-default-format)))
  2537. ;; CONSTANTS keyword. Constants names are case sensitive.
  2538. (should
  2539. (equal '("299792458." "3.14")
  2540. (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
  2541. (org-mode-restart)
  2542. (mapcar
  2543. (lambda (n) (cdr (assoc n org-table-formula-constants-local)))
  2544. '("c" "pi")))))
  2545. (should
  2546. (equal "3.14"
  2547. (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
  2548. (org-mode-restart)
  2549. (cdr (assoc "pi" org-table-formula-constants-local)))))
  2550. (should
  2551. (equal "22/7"
  2552. (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
  2553. (org-mode-restart)
  2554. (cdr (assoc "PI" org-table-formula-constants-local)))))
  2555. ;; LINK keyword.
  2556. (should
  2557. (equal
  2558. '("url1" "url2")
  2559. (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
  2560. (org-mode-restart)
  2561. (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local)))
  2562. '("a" "b")))))
  2563. ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
  2564. (should
  2565. (equal
  2566. '(?X ?Z ?Y)
  2567. (org-test-with-temp-text "#+PRIORITIES: X Z Y"
  2568. (org-mode-restart)
  2569. (list org-priority-highest org-priority-lowest org-priority-default))))
  2570. (should
  2571. (equal
  2572. '(?A ?C ?B)
  2573. (org-test-with-temp-text "#+PRIORITIES: X Z"
  2574. (org-mode-restart)
  2575. (list org-priority-highest org-priority-lowest org-priority-default))))
  2576. ;; STARTUP keyword.
  2577. (should
  2578. (equal '(t t)
  2579. (org-test-with-temp-text "#+STARTUP: fold odd"
  2580. (org-mode-restart)
  2581. (list org-startup-folded org-odd-levels-only))))
  2582. ;; TODO keywords.
  2583. (should
  2584. (equal '(("A" "B") ("C"))
  2585. (org-test-with-temp-text "#+TODO: A B | C"
  2586. (org-mode-restart)
  2587. (list org-not-done-keywords org-done-keywords))))
  2588. (should
  2589. (equal '(("A" "C") ("B" "D"))
  2590. (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
  2591. (org-mode-restart)
  2592. (list org-not-done-keywords org-done-keywords))))
  2593. (should
  2594. (equal '(("A" "B") ("C"))
  2595. (org-test-with-temp-text "#+TYP_TODO: A B | C"
  2596. (org-mode-restart)
  2597. (list org-not-done-keywords org-done-keywords))))
  2598. (should
  2599. (equal '((:startgroup) ("A" . ?a) (:endgroup))
  2600. (org-test-with-temp-text "#+TODO: A(a)"
  2601. (org-mode-restart)
  2602. org-todo-key-alist)))
  2603. (should
  2604. (equal '(("D" note nil) ("C" time nil) ("B" note time))
  2605. (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
  2606. (org-mode-restart)
  2607. org-todo-log-states)))
  2608. ;; Enter SETUPFILE keyword.
  2609. (should
  2610. (equal "1"
  2611. (org-test-with-temp-text
  2612. (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
  2613. (org-mode-restart)
  2614. (cdr (assoc "a" org-keyword-properties))))))
  2615. (ert-deftest test-org/collect-keywords ()
  2616. "Test `org-collect-keywords'."
  2617. (should-not
  2618. (org-test-with-temp-text "#+begin_example\n#+foo: bar\n#+end_example"
  2619. (org-collect-keywords '("FOO")))))
  2620. ;;; Links
  2621. ;;;; Coderefs
  2622. (ert-deftest test-org/coderef ()
  2623. "Test coderef links specifications."
  2624. (should
  2625. (org-test-with-temp-text "
  2626. #+BEGIN_SRC emacs-lisp
  2627. \(+ 1 1) (ref:sc)
  2628. #+END_SRC
  2629. \[[(sc)<point>]]"
  2630. (org-open-at-point)
  2631. (looking-at "(ref:sc)")))
  2632. ;; Find coderef even with alternate label format.
  2633. (should
  2634. (org-test-with-temp-text "
  2635. #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
  2636. \(+ 1 1) {ref:sc}
  2637. #+END_SRC
  2638. \[[(sc)<point>]]"
  2639. (org-open-at-point)
  2640. (looking-at "{ref:sc}"))))
  2641. ;;;; Custom ID
  2642. (ert-deftest test-org/custom-id ()
  2643. "Test custom ID links specifications."
  2644. (should
  2645. (org-test-with-temp-text
  2646. "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2647. (org-open-at-point)
  2648. (looking-at-p "\\* H1")))
  2649. ;; Handle escape characters.
  2650. (should
  2651. (org-test-with-temp-text
  2652. "* H1\n:PROPERTIES:\n:CUSTOM_ID: [%]\n:END:\n* H2\n[[#\\[%\\]<point>]]"
  2653. (org-open-at-point)
  2654. (looking-at-p "\\* H1")))
  2655. ;; Throw an error on false positives.
  2656. (should-error
  2657. (org-test-with-temp-text
  2658. "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2659. (org-open-at-point)
  2660. (looking-at-p "\\* H1"))))
  2661. ;;;; Fuzzy Links
  2662. ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
  2663. ;; a named element (#+name: text) and to headlines (* Text).
  2664. (ert-deftest test-org/fuzzy-links ()
  2665. "Test fuzzy links specifications."
  2666. ;; Fuzzy link goes in priority to a matching target.
  2667. (should
  2668. (org-test-with-temp-text
  2669. "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
  2670. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2671. (looking-at "<<Test>>")))
  2672. ;; Then fuzzy link points to an element with a given name.
  2673. (should
  2674. (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
  2675. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2676. (looking-at "#\\+NAME: Test")))
  2677. ;; A target still lead to a matching headline otherwise.
  2678. (should
  2679. (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
  2680. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2681. (looking-at "\\* Head2")))
  2682. ;; With a leading star in link, enforce heading match.
  2683. (should
  2684. (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
  2685. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2686. (looking-at "\\* Test")))
  2687. ;; With a leading star in link, enforce exact heading match, even
  2688. ;; with `org-link-search-must-match-exact-headline' set to nil.
  2689. (should-error
  2690. (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
  2691. (let ((org-link-search-must-match-exact-headline nil))
  2692. (org-open-at-point))))
  2693. ;; Handle non-nil `org-link-search-must-match-exact-headline'.
  2694. (should
  2695. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
  2696. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2697. (looking-at "\\* Test")))
  2698. (should
  2699. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
  2700. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2701. (looking-at "\\* Test")))
  2702. ;; Heading match should not care about spaces, cookies, TODO
  2703. ;; keywords, priorities, and tags. However, TODO keywords are
  2704. ;; case-sensitive.
  2705. (should
  2706. (let ((first-line
  2707. "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
  2708. (org-test-with-temp-text
  2709. (concat first-line "\nFoo Bar\n<point>[[*Test 1 2]]")
  2710. (let ((org-link-search-must-match-exact-headline nil)
  2711. (org-todo-regexp "TODO"))
  2712. (org-open-at-point))
  2713. (looking-at (regexp-quote first-line)))))
  2714. (should-error
  2715. (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
  2716. (let ((org-link-search-must-match-exact-headline nil)
  2717. (org-todo-regexp "TODO"))
  2718. (org-open-at-point))))
  2719. ;; Heading match should still be exact.
  2720. (should-error
  2721. (org-test-with-temp-text "
  2722. ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
  2723. Foo Bar
  2724. <point>[[*Test 1]]"
  2725. (let ((org-link-search-must-match-exact-headline nil)
  2726. (org-todo-regexp "TODO"))
  2727. (org-open-at-point))))
  2728. (should
  2729. (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
  2730. (let ((org-link-search-must-match-exact-headline nil)
  2731. (org-todo-regexp "TODO"))
  2732. (org-open-at-point))
  2733. (looking-at-p (regexp-quote "** Test 1 2"))))
  2734. ;; Heading match ignores COMMENT keyword.
  2735. (should
  2736. (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
  2737. (org-open-at-point)
  2738. (looking-at "\\* COMMENT Test")))
  2739. (should
  2740. (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
  2741. (org-open-at-point)
  2742. (looking-at "\\* TODO COMMENT Test")))
  2743. ;; Correctly un-escape fuzzy links.
  2744. (should
  2745. (org-test-with-temp-text "* [foo]\n[[*\\[foo\\]][With escaped characters]]"
  2746. (org-open-at-point)
  2747. (bobp)))
  2748. ;; Match search strings containing newline characters, including
  2749. ;; blank lines.
  2750. (should
  2751. (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
  2752. (let ((file (buffer-file-name)))
  2753. (goto-char (point-max))
  2754. (insert (format "[[file:%s::line1 line2]]" file))
  2755. (beginning-of-line)
  2756. (let ((org-link-search-must-match-exact-headline nil))
  2757. (org-open-at-point 0))
  2758. (looking-at-p "line1"))))
  2759. (should
  2760. (org-test-with-temp-text-in-file "Paragraph\n\nline1\n\nline2\n\n"
  2761. (let ((file (buffer-file-name)))
  2762. (goto-char (point-max))
  2763. (insert (format "[[file:%s::line1 line2]]" file))
  2764. (beginning-of-line)
  2765. (let ((org-link-search-must-match-exact-headline nil))
  2766. (org-open-at-point 0))
  2767. (looking-at-p "line1")))))
  2768. ;;;; Open at point
  2769. (ert-deftest test-org/open-at-point/keyword ()
  2770. "Does `org-open-at-point' open link in a keyword line?"
  2771. (should
  2772. (org-test-with-temp-text
  2773. "<<top>>\n#+KEYWORD: <point>[[top]]"
  2774. (org-open-at-point) t))
  2775. (should
  2776. (org-test-with-temp-text
  2777. "* H\n<<top>>\n#+KEYWORD: <point>[[top]]"
  2778. (org-open-at-point) t)))
  2779. (ert-deftest test-org/open-at-point/property ()
  2780. "Does `org-open-at-point' open link in property drawer?"
  2781. (should
  2782. (org-test-with-temp-text
  2783. "* Headline
  2784. :PROPERTIES:
  2785. :URL: <point>[[*Headline]]
  2786. :END:"
  2787. (org-open-at-point) t)))
  2788. (ert-deftest test-org/open-at-point/comment ()
  2789. "Does `org-open-at-point' open link in a commented line?"
  2790. (should
  2791. (org-test-with-temp-text
  2792. "<<top>>\n# <point>[[top]]"
  2793. (org-open-at-point) t))
  2794. (should
  2795. (org-test-with-temp-text
  2796. "* H\n<<top>>\n# <point>[[top]]"
  2797. (org-open-at-point) t)))
  2798. (ert-deftest test-org/open-at-point/inline-image ()
  2799. "Test `org-open-at-point' on nested links."
  2800. (should
  2801. (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
  2802. (org-open-at-point)
  2803. (bobp))))
  2804. (ert-deftest test-org/open-at-point/radio-target ()
  2805. "Test `org-open-at-point' on radio targets."
  2806. (should
  2807. (org-test-with-temp-text "<<<target>>> <point>target"
  2808. (org-update-radio-target-regexp)
  2809. (org-open-at-point)
  2810. (eq (org-element-type (org-element-context)) 'radio-target))))
  2811. (ert-deftest test-org/open-at-point/tag ()
  2812. "Test `org-open-at-point' on tags."
  2813. (should
  2814. (org-test-with-temp-text "* H :<point>tag:"
  2815. (catch :result
  2816. (cl-letf (((symbol-function 'org-tags-view)
  2817. (lambda (&rest args) (throw :result t))))
  2818. (org-open-at-point)
  2819. nil))))
  2820. (should-not
  2821. (org-test-with-temp-text-in-file "* H<point> :tag:"
  2822. (catch :result
  2823. (cl-letf (((symbol-function 'org-tags-view)
  2824. (lambda (&rest args) (throw :result t))))
  2825. ;; When point isn't on a tag it's going to try other things,
  2826. ;; possibly trying to open attachments which will return an
  2827. ;; error if there isn't an attachment. Suppress that error.
  2828. (ignore-errors
  2829. (org-open-at-point))
  2830. nil)))))
  2831. ;;; Node Properties
  2832. (ert-deftest test-org/accumulated-properties-in-drawers ()
  2833. "Ensure properties accumulate in subtree drawers."
  2834. (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
  2835. (org-babel-next-src-block)
  2836. (should (equal '(2 1) (org-babel-execute-src-block)))))
  2837. (ert-deftest test-org/custom-properties ()
  2838. "Test custom properties specifications."
  2839. ;; Standard test.
  2840. (should
  2841. (let ((org-custom-properties '("FOO")))
  2842. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2843. (org-toggle-custom-properties-visibility)
  2844. (org-invisible-p2))))
  2845. ;; Properties are case-insensitive.
  2846. (should
  2847. (let ((org-custom-properties '("FOO")))
  2848. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
  2849. (org-toggle-custom-properties-visibility)
  2850. (org-invisible-p2))))
  2851. (should
  2852. (let ((org-custom-properties '("foo")))
  2853. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2854. (org-toggle-custom-properties-visibility)
  2855. (org-invisible-p2))))
  2856. ;; Multiple custom properties in the same drawer.
  2857. (should
  2858. (let ((org-custom-properties '("FOO" "BAR")))
  2859. (org-test-with-temp-text
  2860. "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
  2861. (org-fold-reveal)
  2862. (org-toggle-custom-properties-visibility)
  2863. (and (org-invisible-p2)
  2864. (not (progn (forward-line) (org-invisible-p2)))
  2865. (progn (forward-line) (org-invisible-p2))))))
  2866. ;; Hide custom properties with an empty value.
  2867. (should
  2868. (let ((org-custom-properties '("FOO")))
  2869. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
  2870. (org-toggle-custom-properties-visibility)
  2871. (org-invisible-p2))))
  2872. ;; Do not hide fake properties.
  2873. (should-not
  2874. (let ((org-custom-properties '("FOO")))
  2875. (org-test-with-temp-text ":FOO: val\n"
  2876. (org-toggle-custom-properties-visibility)
  2877. (org-invisible-p2))))
  2878. (should-not
  2879. (let ((org-custom-properties '("A")))
  2880. (org-test-with-temp-text
  2881. "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
  2882. (org-fold-reveal)
  2883. (org-toggle-custom-properties-visibility)
  2884. (org-invisible-p2)))))
  2885. ;;; Mark Region
  2886. (ert-deftest test-org/mark-element ()
  2887. "Test `org-mark-element' specifications."
  2888. ;; Mark beginning and end of element.
  2889. (should
  2890. (equal '(t t)
  2891. (org-test-with-temp-text "Para<point>graph"
  2892. (org-mark-element)
  2893. (list (bobp) (= (mark) (point-max))))))
  2894. (should
  2895. (equal '(t t)
  2896. (org-test-with-temp-text "P1\n\nPara<point>graph\n\nP2"
  2897. (org-mark-element)
  2898. (list (looking-at "Paragraph")
  2899. (org-with-point-at (mark) (looking-at "P2"))))))
  2900. ;; Do not set mark past (point-max).
  2901. (should
  2902. (org-test-with-temp-text "Para<point>graph"
  2903. (narrow-to-region 2 6)
  2904. (org-mark-element)
  2905. (= 6 (mark)))))
  2906. (ert-deftest test-org/mark-subtree ()
  2907. "Test `org-mark-subtree' specifications."
  2908. ;; Error when point is before first headline.
  2909. (should-error
  2910. (org-test-with-temp-text "Paragraph\n* Headline\nBody"
  2911. (progn (transient-mark-mode 1)
  2912. (org-mark-subtree))))
  2913. ;; Without argument, mark current subtree.
  2914. (should
  2915. (equal
  2916. '(12 32)
  2917. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  2918. (progn (transient-mark-mode 1)
  2919. (forward-line 2)
  2920. (org-mark-subtree)
  2921. (list (region-beginning) (region-end))))))
  2922. ;; With an argument, move ARG up.
  2923. (should
  2924. (equal
  2925. '(1 32)
  2926. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  2927. (progn (transient-mark-mode 1)
  2928. (forward-line 2)
  2929. (org-mark-subtree 1)
  2930. (list (region-beginning) (region-end))))))
  2931. ;; Do not get fooled by inlinetasks.
  2932. (when (featurep 'org-inlinetask)
  2933. (should
  2934. (= 1
  2935. (org-test-with-temp-text "* Headline\n*************** Task\nContents"
  2936. (progn (transient-mark-mode 1)
  2937. (forward-line 1)
  2938. (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
  2939. (region-beginning)))))))
  2940. ;;; Miscellaneous
  2941. (ert-deftest test-org/sort-entries ()
  2942. "Test `org-sort-entries'."
  2943. ;; Sort alphabetically.
  2944. (should
  2945. (equal "\n* abc\n* def\n* xyz\n"
  2946. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  2947. (org-sort-entries nil ?a)
  2948. (buffer-string))))
  2949. (should
  2950. (equal "\n* xyz\n* def\n* abc\n"
  2951. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  2952. (org-sort-entries nil ?A)
  2953. (buffer-string))))
  2954. (should
  2955. (equal "\n* \n* klm\n* xyz\n"
  2956. (org-test-with-temp-text "\n* xyz\n* \n* klm\n"
  2957. (org-sort-entries nil ?a)
  2958. (buffer-string))))
  2959. ;; Sort numerically.
  2960. (should
  2961. (equal "\n* 1\n* 2\n* 10\n"
  2962. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  2963. (org-sort-entries nil ?n)
  2964. (buffer-string))))
  2965. (should
  2966. (equal "\n* 10\n* 2\n* 1\n"
  2967. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  2968. (org-sort-entries nil ?N)
  2969. (buffer-string))))
  2970. (should
  2971. (equal "\n* \n* 1\n* 2\n"
  2972. (org-test-with-temp-text "\n* 1\n* \n* 2\n"
  2973. (org-sort-entries nil ?n)
  2974. (buffer-string))))
  2975. ;; Sort by custom function.
  2976. (should
  2977. (equal "\n* b\n* aa\n* ccc\n"
  2978. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  2979. (org-sort-entries nil ?f
  2980. (lambda ()
  2981. (length (buffer-substring (point-at-bol)
  2982. (point-at-eol))))
  2983. #'<)
  2984. (buffer-string))))
  2985. (should
  2986. (equal "\n* ccc\n* aa\n* b\n"
  2987. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  2988. (org-sort-entries nil ?F
  2989. (lambda ()
  2990. (length (buffer-substring (point-at-bol)
  2991. (point-at-eol))))
  2992. #'<)
  2993. (buffer-string))))
  2994. ;; Sort by TODO keyword.
  2995. (should
  2996. (equal "\n* TODO h1\n* TODO h3\n* DONE h2\n"
  2997. (org-test-with-temp-text
  2998. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  2999. (org-sort-entries nil ?o)
  3000. (buffer-string))))
  3001. (should
  3002. (equal "\n* DONE h2\n* TODO h1\n* TODO h3\n"
  3003. (org-test-with-temp-text
  3004. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  3005. (org-sort-entries nil ?O)
  3006. (buffer-string))))
  3007. ;; Sort by priority.
  3008. (should
  3009. (equal "\n* [#A] h2\n* [#B] h3\n* [#C] h1\n"
  3010. (org-test-with-temp-text
  3011. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  3012. (org-sort-entries nil ?p)
  3013. (buffer-string))))
  3014. (should
  3015. (equal "\n* [#C] h1\n* [#B] h3\n* [#A] h2\n"
  3016. (org-test-with-temp-text
  3017. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  3018. (org-sort-entries nil ?P)
  3019. (buffer-string))))
  3020. ;; Sort by creation time.
  3021. (should
  3022. (equal "
  3023. * h3
  3024. [2017-05-08 Mon]
  3025. * h2
  3026. [2017-05-09 Tue]
  3027. * h1
  3028. [2018-05-09 Wed]
  3029. "
  3030. (org-test-with-temp-text
  3031. "
  3032. * h1
  3033. [2018-05-09 Wed]
  3034. * h2
  3035. [2017-05-09 Tue]
  3036. * h3
  3037. [2017-05-08 Mon]
  3038. "
  3039. (org-sort-entries nil ?c)
  3040. (buffer-string))))
  3041. ;; Sort by scheduled date.
  3042. (should
  3043. (equal "
  3044. * TODO h4
  3045. SCHEDULED: <2017-05-06 Sat>
  3046. * TODO h3
  3047. SCHEDULED: <2017-05-08 Mon>
  3048. * TODO h2
  3049. DEADLINE: <2017-05-09 Tue>
  3050. * TODO h1
  3051. DEADLINE: <2017-05-07 Sun>
  3052. "
  3053. (org-test-with-temp-text
  3054. "
  3055. * TODO h2
  3056. DEADLINE: <2017-05-09 Tue>
  3057. * TODO h1
  3058. DEADLINE: <2017-05-07 Sun>
  3059. * TODO h3
  3060. SCHEDULED: <2017-05-08 Mon>
  3061. * TODO h4
  3062. SCHEDULED: <2017-05-06 Sat>
  3063. "
  3064. (org-sort-entries nil ?s)
  3065. (buffer-string))))
  3066. ;; Sort by deadline date.
  3067. (should
  3068. (equal "
  3069. * TODO h1
  3070. DEADLINE: <2017-05-07 Sun>
  3071. * TODO h2
  3072. DEADLINE: <2017-05-09 Tue>
  3073. * TODO h3
  3074. SCHEDULED: <2017-05-08 Mon>
  3075. * TODO h4
  3076. SCHEDULED: <2017-05-06 Sat>
  3077. "
  3078. (org-test-with-temp-text
  3079. "
  3080. * TODO h2
  3081. DEADLINE: <2017-05-09 Tue>
  3082. * TODO h1
  3083. DEADLINE: <2017-05-07 Sun>
  3084. * TODO h3
  3085. SCHEDULED: <2017-05-08 Mon>
  3086. * TODO h4
  3087. SCHEDULED: <2017-05-06 Sat>
  3088. "
  3089. (org-sort-entries nil ?d)
  3090. (buffer-string))))
  3091. ;; Sort by any date/time
  3092. (should
  3093. (equal "
  3094. * TODO h4
  3095. SCHEDULED: <2017-05-06 Sat>
  3096. * TODO h1
  3097. DEADLINE: <2017-05-07 Sun>
  3098. * TODO h3
  3099. SCHEDULED: <2017-05-08 Mon>
  3100. * TODO h2
  3101. DEADLINE: <2017-05-09 Tue>
  3102. "
  3103. (org-test-with-temp-text
  3104. "
  3105. * TODO h2
  3106. DEADLINE: <2017-05-09 Tue>
  3107. * TODO h1
  3108. DEADLINE: <2017-05-07 Sun>
  3109. * TODO h3
  3110. SCHEDULED: <2017-05-08 Mon>
  3111. * TODO h4
  3112. SCHEDULED: <2017-05-06 Sat>
  3113. "
  3114. (org-sort-entries nil ?t)
  3115. (buffer-string))))
  3116. ;; Sort by clocking time.
  3117. (should
  3118. (equal "
  3119. * clocked h2
  3120. :LOGBOOK:
  3121. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3122. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  3123. :END:
  3124. * clocked h1
  3125. :LOGBOOK:
  3126. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3127. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  3128. :END:
  3129. "
  3130. (org-test-with-temp-text
  3131. "
  3132. * clocked h1
  3133. :LOGBOOK:
  3134. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3135. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  3136. :END:
  3137. * clocked h2
  3138. :LOGBOOK:
  3139. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3140. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  3141. :END:
  3142. "
  3143. (org-sort-entries nil ?k)
  3144. (buffer-string))))
  3145. ;; Preserve file local variables when sorting.
  3146. (should
  3147. (equal "\n* A\n* B\n# Local Variables:\n# foo: t\n# End:\n"
  3148. (org-test-with-temp-text
  3149. "\n* B\n* A\n# Local Variables:\n# foo: t\n# End:"
  3150. (org-sort-entries nil ?a)
  3151. (buffer-string)))))
  3152. (ert-deftest test-org/string-collate-greaterp ()
  3153. "Test `org-string-collate-greaterp' specifications."
  3154. (should (org-string-collate-greaterp "def" "abc"))
  3155. (should-not (org-string-collate-greaterp "abc" "def")))
  3156. (ert-deftest test-org/file-contents ()
  3157. "Test `org-file-contents' specifications."
  3158. ;; Open files.
  3159. (should
  3160. (string= "#+BIND: variable value
  3161. #+DESCRIPTION: l2
  3162. #+LANGUAGE: en
  3163. #+SELECT_TAGS: b
  3164. #+TITLE: b
  3165. #+PROPERTY: a 1
  3166. " (org-file-contents (expand-file-name "setupfile3.org"
  3167. (concat org-test-dir "examples/")))))
  3168. ;; Throw error when trying to access an invalid file.
  3169. (should-error (org-file-contents "this-file-must-not-exist"))
  3170. ;; Try to access an invalid file, but do not throw an error.
  3171. (should
  3172. (progn (org-file-contents "this-file-must-not-exist" :noerror) t))
  3173. ;; Open URL.
  3174. (should
  3175. (string= "foo"
  3176. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3177. (unwind-protect
  3178. ;; Simulate successful retrieval of a URL.
  3179. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3180. (lambda (&rest_)
  3181. (with-current-buffer buffer
  3182. (insert "HTTP/1.1 200 OK\n\nfoo"))
  3183. buffer)))
  3184. (org-file-contents "http://some-valid-url"))
  3185. (kill-buffer buffer)))))
  3186. ;; Throw error when trying to access an invalid URL.
  3187. (should-error
  3188. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3189. (unwind-protect
  3190. ;; Simulate unsuccessful retrieval of a URL.
  3191. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3192. (lambda (&rest_)
  3193. (with-current-buffer buffer
  3194. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3195. buffer)))
  3196. (org-file-contents "http://this-url-must-not-exist"))
  3197. (kill-buffer buffer))))
  3198. ;; Try to access an invalid URL, but do not throw an error.
  3199. (should-error
  3200. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3201. (unwind-protect
  3202. ;; Simulate unsuccessful retrieval of a URL.
  3203. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3204. (lambda (&rest_)
  3205. (with-current-buffer buffer
  3206. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3207. buffer)))
  3208. (org-file-contents "http://this-url-must-not-exist"))
  3209. (kill-buffer buffer))))
  3210. (should
  3211. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3212. (unwind-protect
  3213. ;; Simulate unsuccessful retrieval of a URL.
  3214. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3215. (lambda (&rest_)
  3216. (with-current-buffer buffer
  3217. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3218. buffer)))
  3219. (org-file-contents "http://this-url-must-not-exist" :noerror))
  3220. (kill-buffer buffer))
  3221. t)))
  3222. ;;; Navigation
  3223. (ert-deftest test-org/next-visible-heading ()
  3224. "Test `org-next-visible-heading' specifications."
  3225. ;; Move to the beginning of the next headline, taking into
  3226. ;; consideration ARG.
  3227. (should
  3228. (org-test-with-temp-text "* H1\n* H2"
  3229. (org-next-visible-heading 1)
  3230. (looking-at "\\* H2")))
  3231. (should
  3232. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3233. (org-next-visible-heading 2)
  3234. (looking-at "\\* H3")))
  3235. ;; Ignore invisible headlines.
  3236. (should
  3237. (org-test-with-temp-text "* H1\n** H2\n* H3"
  3238. (org-cycle)
  3239. (org-next-visible-heading 1)
  3240. (looking-at "\\* H3")))
  3241. ;; Move point between headlines, not on blank lines between.
  3242. (should
  3243. (org-test-with-temp-text "* H1\n** H2\n\n\n\n* H3"
  3244. (let ((org-cycle-separator-lines 1))
  3245. (org-cycle)
  3246. (org-next-visible-heading 1))
  3247. (looking-at "\\* H3")))
  3248. ;; Move at end of buffer when there is no more headline.
  3249. (should
  3250. (org-test-with-temp-text "* H1"
  3251. (org-next-visible-heading 1)
  3252. (eobp)))
  3253. (should
  3254. (org-test-with-temp-text "* H1\n* H2"
  3255. (org-next-visible-heading 2)
  3256. (eobp)))
  3257. ;; With a negative argument, move backwards.
  3258. (should
  3259. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3260. (org-next-visible-heading -1)
  3261. (looking-at "\\* H2")))
  3262. (should
  3263. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3264. (org-next-visible-heading -2)
  3265. (looking-at "\\* H1"))))
  3266. (ert-deftest test-org/previous-visible-heading ()
  3267. "Test `org-previous-visible-heading' specifications."
  3268. ;; Move to the beginning of the next headline, taking into
  3269. ;; consideration ARG.
  3270. (should
  3271. (org-test-with-temp-text "* H1\n<point>* H2"
  3272. (org-previous-visible-heading 1)
  3273. (looking-at "\\* H1")))
  3274. (should
  3275. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3276. (org-previous-visible-heading 2)
  3277. (looking-at "\\* H1")))
  3278. ;; Ignore invisible headlines.
  3279. (should
  3280. (org-test-with-temp-text "* H1\n** H2\n<point>* H3"
  3281. (org-overview)
  3282. (org-previous-visible-heading 1)
  3283. (looking-at "\\* H1")))
  3284. ;; Move point between headlines, not on blank lines between.
  3285. (should
  3286. (org-test-with-temp-text "* H1\n\n\n\n** H2\n<point>* H3"
  3287. (let ((org-cycle-separator-lines 1))
  3288. (org-overview)
  3289. (org-previous-visible-heading 1))
  3290. (looking-at "\\* H1")))
  3291. ;; Move at end of buffer when there is no more headline.
  3292. (should
  3293. (org-test-with-temp-text "* H1"
  3294. (org-previous-visible-heading 1)
  3295. (bobp)))
  3296. (should
  3297. (org-test-with-temp-text "* H1\n* <point>H2"
  3298. (org-previous-visible-heading 2)
  3299. (bobp)))
  3300. ;; Invisible parts may not start at a headline, i.e., when revealing
  3301. ;; parts of the buffer. Handle this.
  3302. (should
  3303. (org-test-with-temp-text "* Main\n** H1\nFoo\n** H2\nBar\n** H3\nBaz"
  3304. (org-overview)
  3305. (search-forward "H1")
  3306. (org-show-context 'minimal)
  3307. (org-cycle)
  3308. (search-forward "H3")
  3309. (org-show-context 'minimal)
  3310. ;; At this point, buffer displays, with point at "|",
  3311. ;;
  3312. ;; * Main
  3313. ;; ** H1
  3314. ;; Foo
  3315. ;; ** H3|
  3316. (org-previous-visible-heading 1)
  3317. (looking-at "\\*+ H1"))))
  3318. (ert-deftest test-org/forward-heading-same-level ()
  3319. "Test `org-forward-heading-same-level' specifications."
  3320. ;; Test navigation at top level, forward and backward.
  3321. (should
  3322. (equal "* H2"
  3323. (org-test-with-temp-text "* H1\n* H2"
  3324. (org-forward-heading-same-level 1)
  3325. (buffer-substring-no-properties (point) (line-end-position)))))
  3326. (should
  3327. (equal "* H1"
  3328. (org-test-with-temp-text "* H1\n<point>* H2"
  3329. (org-forward-heading-same-level -1)
  3330. (buffer-substring-no-properties (point) (line-end-position)))))
  3331. ;; Test navigation in a sub-tree, forward and backward.
  3332. (should
  3333. (equal "* H2"
  3334. (org-test-with-temp-text "* H1\n** H11\n** H12\n* H2"
  3335. (org-forward-heading-same-level 1)
  3336. (buffer-substring-no-properties (point) (line-end-position)))))
  3337. (should
  3338. (equal "* H1"
  3339. (org-test-with-temp-text "* H1\n** H11\n** H12\n<point>* H2"
  3340. (org-forward-heading-same-level -1)
  3341. (buffer-substring-no-properties (point) (line-end-position)))))
  3342. ;; Stop at first or last sub-heading.
  3343. (should-not
  3344. (equal "* H2"
  3345. (org-test-with-temp-text "* H1\n** H11\n<point>** H12\n* H2"
  3346. (org-forward-heading-same-level 1)
  3347. (buffer-substring-no-properties (point) (line-end-position)))))
  3348. (should-not
  3349. (equal "* H2"
  3350. (org-test-with-temp-text "* H1\n<point>** H11\n** H12\n* H2"
  3351. (org-forward-heading-same-level -1)
  3352. (buffer-substring-no-properties (point) (line-end-position)))))
  3353. ;; Allow multiple moves.
  3354. (should
  3355. (equal "* H3"
  3356. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3357. (org-forward-heading-same-level 2)
  3358. (buffer-substring-no-properties (point) (line-end-position)))))
  3359. (should
  3360. (equal "* H1"
  3361. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3362. (org-forward-heading-same-level -2)
  3363. (buffer-substring-no-properties (point) (line-end-position)))))
  3364. ;; Ignore spurious moves when first (or last) sibling is reached.
  3365. (should
  3366. (equal "** H3"
  3367. (org-test-with-temp-text "* First\n<point>** H1\n** H2\n** H3\n* Last"
  3368. (org-forward-heading-same-level 100)
  3369. (buffer-substring-no-properties (point) (line-end-position)))))
  3370. (should
  3371. (equal "** H1"
  3372. (org-test-with-temp-text "* First\n** H1\n** H2\n<point>** H3\n* Last"
  3373. (org-forward-heading-same-level -100)
  3374. (buffer-substring-no-properties (point) (line-end-position))))))
  3375. (ert-deftest test-org/end-of-meta-data ()
  3376. "Test `org-end-of-meta-data' specifications."
  3377. ;; Skip planning line.
  3378. (should
  3379. (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
  3380. (org-end-of-meta-data)
  3381. (eobp)))
  3382. ;; Skip properties drawer.
  3383. (should
  3384. (org-test-with-temp-text
  3385. "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
  3386. (org-end-of-meta-data)
  3387. (eobp)))
  3388. ;; Skip both.
  3389. (should
  3390. (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
  3391. (org-end-of-meta-data)
  3392. (eobp)))
  3393. ;; Nothing to skip, go to first line.
  3394. (should
  3395. (org-test-with-temp-text "* Headline\nContents"
  3396. (org-end-of-meta-data)
  3397. (looking-at "Contents")))
  3398. ;; With option argument, skip empty lines, regular drawers and
  3399. ;; clocking lines.
  3400. (should
  3401. (org-test-with-temp-text "* Headline\n\nContents"
  3402. (org-end-of-meta-data t)
  3403. (looking-at "Contents")))
  3404. (should
  3405. (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
  3406. (org-end-of-meta-data t)
  3407. (looking-at "Contents")))
  3408. (should
  3409. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
  3410. (org-end-of-meta-data t)
  3411. (looking-at "Contents")))
  3412. ;; Special case: do not skip incomplete drawers.
  3413. (should
  3414. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
  3415. (org-end-of-meta-data t)
  3416. (looking-at ":LOGBOOK:")))
  3417. ;; Special case: Be careful about consecutive headlines.
  3418. (should-not
  3419. (org-test-with-temp-text "* H1\n*H2\nContents"
  3420. (org-end-of-meta-data t)
  3421. (looking-at "Contents"))))
  3422. (ert-deftest test-org/shiftright-heading ()
  3423. "Test `org-shiftright' on headings."
  3424. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  3425. (should
  3426. (equal "* TODO a1\n** a2\n* DONE b1\n"
  3427. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3428. (org-shiftright)
  3429. (buffer-string))))
  3430. (should
  3431. (equal "* TODO a1\n** TODO a2\n* b1\n"
  3432. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3433. (let ((org-loop-over-headlines-in-active-region t))
  3434. (transient-mark-mode 1)
  3435. (push-mark (point) t t)
  3436. (search-forward "* DONE b1")
  3437. (org-shiftright))
  3438. (buffer-string))))
  3439. (should
  3440. (equal "* TODO a1\n** a2\n* b1\n"
  3441. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3442. (let ((org-loop-over-headlines-in-active-region 'start-level))
  3443. (transient-mark-mode 1)
  3444. (push-mark (point) t t)
  3445. (search-forward "* DONE b1")
  3446. (org-shiftright))
  3447. (buffer-string))))))
  3448. (ert-deftest test-org/beginning-of-line ()
  3449. "Test `org-beginning-of-line' specifications."
  3450. ;; Move to beginning of line. If current line in invisible, move to
  3451. ;; beginning of visible line instead.
  3452. (should
  3453. (org-test-with-temp-text "Some text\nSome other text<point>"
  3454. (org-beginning-of-line)
  3455. (bolp)))
  3456. (should
  3457. (org-test-with-temp-text "* H1\n** H2<point>"
  3458. (org-overview)
  3459. (org-beginning-of-line)
  3460. (= (line-beginning-position) 1)))
  3461. ;; With `visual-line-mode' active, move to beginning of visual line.
  3462. (should-not
  3463. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3464. (visual-line-mode)
  3465. (dotimes (i 1000) (insert "very "))
  3466. (org-beginning-of-line)
  3467. (bolp)))
  3468. ;; In a wide headline, with `visual-line-mode', prefer going to the
  3469. ;; beginning of a visual line than to the logical beginning of line,
  3470. ;; even if special movement is active.
  3471. (should-not
  3472. (org-test-with-temp-text "* A <point>long headline"
  3473. (visual-line-mode)
  3474. (dotimes (i 1000) (insert "very "))
  3475. (goto-char (point-max))
  3476. (org-beginning-of-line)
  3477. (bobp)))
  3478. (should-not
  3479. (org-test-with-temp-text "* A <point>long headline"
  3480. (visual-line-mode)
  3481. (dotimes (i 1000) (insert "very "))
  3482. (goto-char (point-max))
  3483. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line))
  3484. (bobp)))
  3485. ;; At an headline with special movement, first move at beginning of
  3486. ;; title, then at the beginning of line, rinse, repeat.
  3487. (should
  3488. (org-test-with-temp-text "* TODO Headline<point>"
  3489. (let ((org-special-ctrl-a/e t))
  3490. (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
  3491. (progn (org-beginning-of-line) (bolp))
  3492. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3493. (should
  3494. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3495. (let ((org-special-ctrl-a/e t))
  3496. (org-beginning-of-line)
  3497. (looking-at "Headline"))))
  3498. (should
  3499. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3500. (let ((org-special-ctrl-a/e '(t . nil)))
  3501. (org-beginning-of-line)
  3502. (looking-at "Headline"))))
  3503. (should-not
  3504. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3505. (let ((org-special-ctrl-a/e '(nil . nil)))
  3506. (org-beginning-of-line)
  3507. (looking-at "Headline"))))
  3508. ;; At an headline with reversed movement, first move to beginning of
  3509. ;; line, then to the beginning of title.
  3510. (should
  3511. (org-test-with-temp-text "* TODO Headline<point>"
  3512. (let ((org-special-ctrl-a/e 'reversed)
  3513. (this-command last-command))
  3514. (and (progn (org-beginning-of-line) (bolp))
  3515. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3516. (should
  3517. (org-test-with-temp-text "* TODO Headline<point>"
  3518. (let ((org-special-ctrl-a/e '(reversed . nil))
  3519. (this-command last-command))
  3520. (and (progn (org-beginning-of-line) (bolp))
  3521. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3522. (should-not
  3523. (org-test-with-temp-text "* TODO Headline<point>"
  3524. (let ((org-special-ctrl-a/e '(t . nil))
  3525. (this-command last-command))
  3526. (and (progn (org-beginning-of-line) (bolp))
  3527. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3528. ;; At an item with special movement, first move after to beginning
  3529. ;; of title, then to the beginning of line, rinse, repeat.
  3530. (should
  3531. (org-test-with-temp-text "- [ ] Item<point>"
  3532. (let ((org-special-ctrl-a/e t))
  3533. (and (progn (org-beginning-of-line) (looking-at-p "Item"))
  3534. (progn (org-beginning-of-line) (bolp))
  3535. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3536. ;; At an item with reversed movement, first move to beginning of
  3537. ;; line, then to the beginning of title.
  3538. (should
  3539. (org-test-with-temp-text "- [X] Item<point>"
  3540. (let ((org-special-ctrl-a/e 'reversed)
  3541. (this-command last-command))
  3542. (and (progn (org-beginning-of-line) (bolp))
  3543. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3544. ;; Leave point before invisible characters at column 0.
  3545. (should
  3546. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3547. (let ((org-special-ctrl-a/e nil))
  3548. (org-beginning-of-line)
  3549. (bolp))))
  3550. (should
  3551. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3552. (let ((org-special-ctrl-a/e t))
  3553. (org-beginning-of-line)
  3554. (bolp))))
  3555. (should
  3556. (org-test-with-temp-text "[[http<point>://orgmode.org]]"
  3557. (visual-line-mode)
  3558. (org-beginning-of-line)
  3559. (bolp)))
  3560. ;; Special case: Do not error when the buffer contains only a single
  3561. ;; asterisk.
  3562. (should
  3563. (org-test-with-temp-text "*<point>"
  3564. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line) t)))
  3565. (should
  3566. (org-test-with-temp-text "*<point>"
  3567. (let ((org-special-ctrl-a/e nil)) (org-beginning-of-line) t))))
  3568. (ert-deftest test-org/end-of-line ()
  3569. "Test `org-end-of-line' specifications."
  3570. ;; Standard test.
  3571. (should
  3572. (org-test-with-temp-text "Some text\nSome other text"
  3573. (org-end-of-line)
  3574. (eolp)))
  3575. ;; With `visual-line-mode' active, move to end of visible line.
  3576. ;; However, never go past ellipsis.
  3577. (should-not
  3578. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3579. (visual-line-mode)
  3580. (dotimes (i 1000) (insert "very "))
  3581. (goto-char (point-min))
  3582. (org-end-of-line)
  3583. (eolp)))
  3584. (should-not
  3585. (org-test-with-temp-text "* A short headline\nSome contents"
  3586. (visual-line-mode)
  3587. (org-overview)
  3588. (org-end-of-line)
  3589. (eobp)))
  3590. ;; In a wide headline, with `visual-line-mode', prefer going to end
  3591. ;; of visible line if tags, or end of line, are farther.
  3592. (should-not
  3593. (org-test-with-temp-text "* A <point>long headline"
  3594. (visual-line-mode)
  3595. (dotimes (i 1000) (insert "very "))
  3596. (goto-char (point-min))
  3597. (org-end-of-line)
  3598. (eolp)))
  3599. (should-not
  3600. (org-test-with-temp-text "* A <point>long headline :tag:"
  3601. (visual-line-mode)
  3602. (dotimes (i 1000) (insert "very "))
  3603. (goto-char (point-min))
  3604. (org-end-of-line)
  3605. (eolp)))
  3606. ;; At an headline without special movement, go to end of line.
  3607. ;; However, never go past ellipsis.
  3608. (should
  3609. (org-test-with-temp-text "* Headline2b :tag:\n"
  3610. (let ((org-special-ctrl-a/e nil))
  3611. (and (progn (org-end-of-line) (eolp))
  3612. (progn (org-end-of-line) (eolp))))))
  3613. (should
  3614. (org-test-with-temp-text "* Headline2b :tag:\n"
  3615. (let ((org-special-ctrl-a/e '(t . nil)))
  3616. (and (progn (org-end-of-line) (eolp))
  3617. (progn (org-end-of-line) (eolp))))))
  3618. (should
  3619. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3620. (org-overview)
  3621. (let ((org-special-ctrl-a/e nil))
  3622. (org-end-of-line)
  3623. (= 1 (line-beginning-position)))))
  3624. ;; At an headline with special movement, first move before tags,
  3625. ;; then at the end of line, rinse, repeat. However, never go past
  3626. ;; ellipsis.
  3627. (should
  3628. (org-test-with-temp-text "* Headline1 :tag:\n"
  3629. (let ((org-special-ctrl-a/e t))
  3630. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3631. (progn (org-end-of-line) (eolp))
  3632. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3633. (should
  3634. (org-test-with-temp-text "* Headline1 :tag:\n"
  3635. (let ((org-special-ctrl-a/e '(nil . t)))
  3636. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3637. (progn (org-end-of-line) (eolp))
  3638. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3639. (should-not
  3640. (org-test-with-temp-text "* Headline1 :tag:\n"
  3641. (let ((org-special-ctrl-a/e '(nil . nil)))
  3642. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3643. (progn (org-end-of-line) (eolp))
  3644. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3645. (should
  3646. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3647. (org-overview)
  3648. (let ((org-special-ctrl-a/e t))
  3649. (org-end-of-line)
  3650. (org-end-of-line)
  3651. (= 1 (line-beginning-position)))))
  3652. ;; At an headline, with reversed movement, first go to end of line,
  3653. ;; then before tags. However, never go past ellipsis.
  3654. (should
  3655. (org-test-with-temp-text "* Headline3 :tag:\n"
  3656. (let ((org-special-ctrl-a/e 'reversed)
  3657. (this-command last-command))
  3658. (and (progn (org-end-of-line) (eolp))
  3659. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3660. (should
  3661. (org-test-with-temp-text "* Headline3 :tag:\n"
  3662. (let ((org-special-ctrl-a/e '(nil . reversed))
  3663. (this-command last-command))
  3664. (and (progn (org-end-of-line) (eolp))
  3665. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3666. (should-not
  3667. (org-test-with-temp-text "* Headline3 :tag:\n"
  3668. (let ((org-special-ctrl-a/e '(nil . t))
  3669. (this-command last-command))
  3670. (and (progn (org-end-of-line) (eolp))
  3671. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3672. (should
  3673. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3674. (org-overview)
  3675. (let ((org-special-ctrl-a/e 'reversed))
  3676. (org-end-of-line)
  3677. (= 1 (line-beginning-position)))))
  3678. ;; At a block without hidden contents.
  3679. (should
  3680. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3681. (progn (org-end-of-line) (eolp))))
  3682. ;; At a block with hidden contents.
  3683. (should-not
  3684. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3685. (let ((org-special-ctrl-a/e t))
  3686. (org-fold-hide-block-toggle)
  3687. (org-end-of-line)
  3688. (eobp))))
  3689. ;; Get past invisible characters at the end of line.
  3690. (should
  3691. (org-test-with-temp-text "[[https://orgmode.org]]"
  3692. (org-end-of-line)
  3693. (eolp))))
  3694. (ert-deftest test-org/open-line ()
  3695. "Test `org-open-line' specifications."
  3696. ;; Call `open-line' outside of tables.
  3697. (should
  3698. (equal "\nText"
  3699. (org-test-with-temp-text "Text"
  3700. (org-open-line 1)
  3701. (buffer-string))))
  3702. ;; At a table, create a row above.
  3703. (should
  3704. (equal "\n| |\n| a |"
  3705. (org-test-with-temp-text "\n<point>| a |"
  3706. (org-open-line 1)
  3707. (buffer-string))))
  3708. ;; At the very first character of the buffer, also call `open-line'.
  3709. (should
  3710. (equal "\n| a |"
  3711. (org-test-with-temp-text "| a |"
  3712. (org-open-line 1)
  3713. (buffer-string))))
  3714. ;; Narrowing does not count.
  3715. (should
  3716. (equal "Text\n| |\n| a |"
  3717. (org-test-with-temp-text "Text\n<point>| a |"
  3718. (narrow-to-region (point) (point-max))
  3719. (org-open-line 1)
  3720. (widen)
  3721. (buffer-string)))))
  3722. (ert-deftest test-org/forward-sentence ()
  3723. "Test `org-forward-sentence' specifications."
  3724. ;; At the end of a table cell, move to the end of the next one.
  3725. (should
  3726. (org-test-with-temp-text "| a<point> | b |"
  3727. (org-forward-sentence)
  3728. (looking-at " |$")))
  3729. ;; Elsewhere in a cell, move to its end.
  3730. (should
  3731. (org-test-with-temp-text "| a<point>c | b |"
  3732. (org-forward-sentence)
  3733. (looking-at " | b |$")))
  3734. ;; Otherwise, simply call `forward-sentence'.
  3735. (should
  3736. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3737. (org-forward-sentence)
  3738. (looking-at " Sentence 2.")))
  3739. (should
  3740. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3741. (org-forward-sentence)
  3742. (org-forward-sentence)
  3743. (eobp)))
  3744. ;; At the end of an element, jump to the next one, without stopping
  3745. ;; on blank lines in-between.
  3746. (should
  3747. (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
  3748. (org-forward-sentence)
  3749. (eobp)))
  3750. ;; Headlines are considered to be sentences by themselves, even if
  3751. ;; they do not end with a full stop.
  3752. (should
  3753. (equal
  3754. "* Headline"
  3755. (org-test-with-temp-text "* <point>Headline\nSentence."
  3756. (org-forward-sentence)
  3757. (buffer-substring-no-properties (line-beginning-position) (point)))))
  3758. (should
  3759. (org-test-with-temp-text "* Headline<point>\nSentence."
  3760. (org-forward-sentence)
  3761. (eobp)))
  3762. (should
  3763. (org-test-with-temp-text "Sentence.<point>\n\n* Headline\n\nSentence 2."
  3764. (org-forward-sentence)
  3765. (and (org-at-heading-p) (eolp)))))
  3766. (ert-deftest test-org/backward-sentence ()
  3767. "Test `org-backward-sentence' specifications."
  3768. ;; At the beginning of a table cell, move to the beginning of the
  3769. ;; previous one.
  3770. (should
  3771. (org-test-with-temp-text "| a | <point>b |"
  3772. (org-backward-sentence)
  3773. (looking-at "a | b |$")))
  3774. ;; Elsewhere in a cell, move to its beginning.
  3775. (should
  3776. (org-test-with-temp-text "| a | b<point>c |"
  3777. (org-backward-sentence)
  3778. (looking-at "bc |$")))
  3779. ;; Otherwise, simply call `backward-sentence'.
  3780. (should
  3781. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3782. (org-backward-sentence)
  3783. (looking-at "Sentence 2.")))
  3784. (should
  3785. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3786. (org-backward-sentence)
  3787. (org-backward-sentence)
  3788. (bobp)))
  3789. ;; Make sure to hit the beginning of a sentence on the same line as
  3790. ;; an item.
  3791. (should
  3792. (org-test-with-temp-text "- Line 1\n line <point>2."
  3793. (org-backward-sentence)
  3794. (looking-at "Line 1"))))
  3795. (ert-deftest test-org/forward-paragraph ()
  3796. "Test `org-forward-paragraph' specifications."
  3797. ;; At end of buffer, do not return an error.
  3798. (should
  3799. (org-test-with-temp-text "Paragraph"
  3800. (goto-char (point-max))
  3801. (org-forward-paragraph)
  3802. t))
  3803. ;; Standard test.
  3804. (should
  3805. (= 2
  3806. (org-test-with-temp-text "P1\n\nP2"
  3807. (org-forward-paragraph)
  3808. (org-current-line))))
  3809. (should
  3810. (= 2
  3811. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  3812. (org-forward-paragraph)
  3813. (org-current-line))))
  3814. ;; Enter greater elements.
  3815. (should
  3816. (= 2
  3817. (org-test-with-temp-text "#+begin_center\nP1\n#+end_center\nP2"
  3818. (org-forward-paragraph)
  3819. (org-current-line))))
  3820. ;; Do not enter elements with invisible contents.
  3821. (should
  3822. (= 4
  3823. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  3824. (org-cycle)
  3825. (org-forward-paragraph)
  3826. (org-current-line))))
  3827. (should
  3828. (= 6
  3829. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\nP3"
  3830. (org-fold-hide-block-toggle)
  3831. (org-forward-paragraph)
  3832. (org-current-line))))
  3833. ;; On an item or a footnote definition, move past the first element
  3834. ;; inside, if any.
  3835. (should
  3836. (= 2
  3837. (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
  3838. (org-forward-paragraph)
  3839. (org-current-line))))
  3840. (should
  3841. (= 2
  3842. (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
  3843. (org-forward-paragraph)
  3844. (org-current-line))))
  3845. ;; On a table (resp. a property drawer) do not move through table
  3846. ;; rows (resp. node properties).
  3847. (should
  3848. (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
  3849. (org-forward-paragraph)
  3850. (looking-at "Paragraph")))
  3851. (should
  3852. (org-test-with-temp-text
  3853. "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
  3854. (org-forward-paragraph)
  3855. (looking-at "Paragraph")))
  3856. ;; Skip consecutive keywords, clocks and diary S-exps.
  3857. (should
  3858. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n"
  3859. (org-forward-paragraph)
  3860. (eobp)))
  3861. (should
  3862. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n"
  3863. (org-forward-paragraph)
  3864. (eobp)))
  3865. (should
  3866. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n"
  3867. (org-forward-paragraph)
  3868. (eobp)))
  3869. (should-not
  3870. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n"
  3871. (org-forward-paragraph)
  3872. (eobp)))
  3873. (should-not
  3874. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n"
  3875. (org-forward-paragraph)
  3876. (eobp)))
  3877. ;; In a plain list with one item every line, skip the whole list,
  3878. ;; even with point in the middle of the list.
  3879. (should
  3880. (org-test-with-temp-text "- A\n - B\n- C\n"
  3881. (org-forward-paragraph)
  3882. (eobp)))
  3883. (should
  3884. (org-test-with-temp-text "- A\n - <point>B\n- C\n"
  3885. (org-forward-paragraph)
  3886. (eobp)))
  3887. ;; On a comment, verse or source block, stop at "contents"
  3888. ;; boundaries and blank lines.
  3889. (should
  3890. (= 2
  3891. (org-test-with-temp-text "#+begin_src emacs-lisp\nL1\n\nL2\n#+end_src"
  3892. (org-forward-paragraph)
  3893. (org-current-line))))
  3894. (should
  3895. (= 3
  3896. (org-test-with-temp-text "#+begin_verse\n<point>L1\n\nL2\n#+end_verse"
  3897. (org-forward-paragraph)
  3898. (org-current-line))))
  3899. (should
  3900. (= 5
  3901. (org-test-with-temp-text "#+begin_comment\nL1\n\n<point>L2\n#+end_comment"
  3902. (org-forward-paragraph)
  3903. (org-current-line))))
  3904. ;; Being on an affiliated keyword shouldn't make any difference.
  3905. (should
  3906. (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
  3907. (org-forward-paragraph)
  3908. (eobp))))
  3909. (ert-deftest test-org/backward-paragraph ()
  3910. "Test `org-backward-paragraph' specifications."
  3911. ;; Do not error at beginning of buffer.
  3912. (should
  3913. (org-test-with-temp-text "Paragraph"
  3914. (org-backward-paragraph)
  3915. t))
  3916. ;; At blank lines at the very beginning of a buffer, move to
  3917. ;; point-min.
  3918. (should
  3919. (org-test-with-temp-text "\n\n<point>\n\nParagraph"
  3920. (org-backward-paragraph)
  3921. (bobp)))
  3922. ;; Regular test.
  3923. (should
  3924. (= 2
  3925. (org-test-with-temp-text "P1\n\nP2<point>"
  3926. (org-backward-paragraph)
  3927. (org-current-line))))
  3928. (should
  3929. (= 4
  3930. (org-test-with-temp-text "P1\n\nP2\n\nP3<point>"
  3931. (org-backward-paragraph)
  3932. (org-current-line))))
  3933. ;; Try to move on the line above current element.
  3934. (should
  3935. (= 2
  3936. (org-test-with-temp-text "\n\n<point>Paragraph"
  3937. (org-backward-paragraph)
  3938. (org-current-line))))
  3939. ;; Do not leave point in an invisible area.
  3940. (should
  3941. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  3942. (org-cycle)
  3943. (goto-char (point-max))
  3944. (beginning-of-line)
  3945. (org-backward-paragraph)
  3946. (bobp)))
  3947. (should
  3948. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\n"
  3949. (org-fold-hide-block-toggle)
  3950. (goto-char (point-max))
  3951. (org-backward-paragraph)
  3952. (bobp)))
  3953. ;; On the first element in an item or a footnote definition, jump
  3954. ;; before the footnote or the item.
  3955. (should
  3956. (org-test-with-temp-text "- line1<point>"
  3957. (org-backward-paragraph)
  3958. (bobp)))
  3959. (should
  3960. (org-test-with-temp-text "[fn:1] line1n<point>"
  3961. (org-backward-paragraph)
  3962. (bobp)))
  3963. ;; On the second element in an item or a footnote definition, jump
  3964. ;; to item or the definition.
  3965. (should
  3966. (= 2
  3967. (org-test-with-temp-text "- line1\n\n<point> line2"
  3968. (org-backward-paragraph)
  3969. (org-current-line))))
  3970. (should
  3971. (= 2
  3972. (org-test-with-temp-text "[fn:1] line1\n\n<point> line2"
  3973. (org-backward-paragraph)
  3974. (org-current-line))))
  3975. ;; On a table (resp. a property drawer), ignore table rows
  3976. ;; (resp. node properties).
  3977. (should
  3978. (org-test-with-temp-text "| a | b |\n| c | d |\n<point>P1"
  3979. (org-backward-paragraph)
  3980. (bobp)))
  3981. (should
  3982. (= 2
  3983. (org-test-with-temp-text
  3984. "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
  3985. (org-backward-paragraph)
  3986. (org-current-line))))
  3987. ;; In a plain list with one item every line, skip the whole list,
  3988. ;; even with point in the middle of the list.
  3989. (should
  3990. (org-test-with-temp-text "- A\n - B\n- C\n<point>"
  3991. (org-backward-paragraph)
  3992. (bobp)))
  3993. (should
  3994. (org-test-with-temp-text "- A\n - B\n- <point>C\n"
  3995. (org-backward-paragraph)
  3996. (bobp)))
  3997. ;; Skip consecutive keywords, clocks and diary S-exps.
  3998. (should
  3999. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n<point>"
  4000. (org-backward-paragraph)
  4001. (bobp)))
  4002. (should
  4003. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n<point>"
  4004. (org-backward-paragraph)
  4005. (bobp)))
  4006. (should
  4007. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n<point>"
  4008. (org-backward-paragraph)
  4009. (bobp)))
  4010. (should-not
  4011. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n<point>"
  4012. (org-backward-paragraph)
  4013. (bobp)))
  4014. (should-not
  4015. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n<point>"
  4016. (org-backward-paragraph)
  4017. (bobp)))
  4018. ;; On a comment, example, source and verse blocks, stop at blank
  4019. ;; lines.
  4020. (should
  4021. (= 1
  4022. (org-test-with-temp-text
  4023. "#+begin_comment\n<point>L1\n\nL2\n\nL3\n#+end_comment"
  4024. (org-backward-paragraph)
  4025. (org-current-line))))
  4026. (should
  4027. (= 2
  4028. (org-test-with-temp-text
  4029. "#+begin_verse\nL1\n\n<point>L2\n\nL3\n#+end_verse"
  4030. (org-backward-paragraph)
  4031. (org-current-line))))
  4032. (should
  4033. (= 3
  4034. (org-test-with-temp-text
  4035. "#+begin_src emacs-lisp\nL1\n\nL2\n\n<point>L3\n#+end_src"
  4036. (org-backward-paragraph)
  4037. (org-current-line))))
  4038. ;; When called from the opening line itself, however, move to
  4039. ;; beginning of block.
  4040. (should
  4041. (org-test-with-temp-text "#+begin_<point>example\nL1\n#+end_example"
  4042. (org-backward-paragraph)
  4043. (bobp)))
  4044. ;; On an empty heading, move above it.
  4045. (should
  4046. (org-test-with-temp-text "\n* <point>"
  4047. (org-backward-paragraph)
  4048. (bobp)))
  4049. (should
  4050. (org-test-with-temp-text "\n* \n<point>"
  4051. (org-backward-paragraph)
  4052. (bobp))))
  4053. (ert-deftest test-org/forward-element ()
  4054. "Test `org-forward-element' specifications."
  4055. ;; 1. At EOB: should error.
  4056. (org-test-with-temp-text "Some text\n"
  4057. (goto-char (point-max))
  4058. (should-error (org-forward-element)))
  4059. ;; 2. Standard move: expected to ignore blank lines.
  4060. (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
  4061. (org-forward-element)
  4062. (should (looking-at (regexp-quote "Second paragraph."))))
  4063. ;; 3. Headline tests.
  4064. (org-test-with-temp-text "
  4065. * Head 1
  4066. ** Head 1.1
  4067. *** Head 1.1.1
  4068. ** Head 1.2"
  4069. ;; 3.1. At an headline beginning: move to next headline at the
  4070. ;; same level.
  4071. (goto-line 3)
  4072. (org-forward-element)
  4073. (should (looking-at (regexp-quote "** Head 1.2")))
  4074. ;; 3.2. At an headline beginning: move to parent headline if no
  4075. ;; headline at the same level.
  4076. (goto-line 3)
  4077. (org-forward-element)
  4078. (should (looking-at (regexp-quote "** Head 1.2"))))
  4079. ;; 4. Greater element tests.
  4080. (org-test-with-temp-text
  4081. "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
  4082. ;; 4.1. At a greater element: expected to skip contents.
  4083. (org-forward-element)
  4084. (should (looking-at (regexp-quote "Outside.")))
  4085. ;; 4.2. At the end of greater element contents: expected to skip
  4086. ;; to the end of the greater element.
  4087. (goto-line 2)
  4088. (org-forward-element)
  4089. (should (looking-at (regexp-quote "Outside."))))
  4090. ;; 5. List tests.
  4091. (org-test-with-temp-text "
  4092. - item1
  4093. - sub1
  4094. - sub2
  4095. - sub3
  4096. Inner paragraph.
  4097. - item2
  4098. Outside."
  4099. ;; 5.1. At list top point: expected to move to the element after
  4100. ;; the list.
  4101. (goto-line 2)
  4102. (org-forward-element)
  4103. (should (looking-at (regexp-quote "Outside.")))
  4104. ;; 5.2. Special case: at the first line of a sub-list, but not at
  4105. ;; beginning of line, move to next item.
  4106. (goto-line 2)
  4107. (forward-char)
  4108. (org-forward-element)
  4109. (should (looking-at "- item2"))
  4110. (goto-line 4)
  4111. (forward-char)
  4112. (org-forward-element)
  4113. (should (looking-at " - sub2"))
  4114. ;; 5.3 At sub-list beginning: expected to move after the sub-list.
  4115. (goto-line 4)
  4116. (org-forward-element)
  4117. (should (looking-at (regexp-quote " Inner paragraph.")))
  4118. ;; 5.4. At sub-list end: expected to move outside the sub-list.
  4119. (goto-line 8)
  4120. (org-forward-element)
  4121. (should (looking-at (regexp-quote " Inner paragraph.")))
  4122. ;; 5.5. At an item: expected to move to next item, if any.
  4123. (goto-line 6)
  4124. (org-forward-element)
  4125. (should (looking-at " - sub3"))))
  4126. (ert-deftest test-org/backward-element ()
  4127. "Test `org-backward-element' specifications."
  4128. ;; 1. Should error at BOB.
  4129. (org-test-with-temp-text " \nParagraph."
  4130. (should-error (org-backward-element)))
  4131. ;; 2. Should move at BOB when called on the first element in buffer.
  4132. (should
  4133. (org-test-with-temp-text "\n#+TITLE: test"
  4134. (progn (forward-line)
  4135. (org-backward-element)
  4136. (bobp))))
  4137. ;; 3. Not at the beginning of an element: move at its beginning.
  4138. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  4139. (goto-line 3)
  4140. (end-of-line)
  4141. (org-backward-element)
  4142. (should (looking-at (regexp-quote "Paragraph2."))))
  4143. ;; 4. Headline tests.
  4144. (org-test-with-temp-text "
  4145. * Head 1
  4146. ** Head 1.1
  4147. *** Head 1.1.1
  4148. ** Head 1.2"
  4149. ;; 4.1. At an headline beginning: move to previous headline at the
  4150. ;; same level.
  4151. (goto-line 5)
  4152. (org-backward-element)
  4153. (should (looking-at (regexp-quote "** Head 1.1")))
  4154. ;; 4.2. At an headline beginning: move to parent headline if no
  4155. ;; headline at the same level.
  4156. (goto-line 3)
  4157. (org-backward-element)
  4158. (should (looking-at (regexp-quote "* Head 1")))
  4159. ;; 4.3. At the first top-level headline: should error.
  4160. (goto-line 2)
  4161. (should-error (org-backward-element)))
  4162. ;; 5. At beginning of first element inside a greater element:
  4163. ;; expected to move to greater element's beginning.
  4164. (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
  4165. (goto-line 3)
  4166. (org-backward-element)
  4167. (should (looking-at "#\\+BEGIN_CENTER")))
  4168. ;; 6. At the beginning of the first element in a section: should
  4169. ;; move back to headline, if any.
  4170. (should
  4171. (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
  4172. (progn (goto-char (point-max))
  4173. (beginning-of-line)
  4174. (org-backward-element)
  4175. (org-at-heading-p))))
  4176. ;; 7. List tests.
  4177. (org-test-with-temp-text "
  4178. - item1
  4179. - sub1
  4180. - sub2
  4181. - sub3
  4182. Inner paragraph.
  4183. - item2
  4184. Outside."
  4185. ;; 7.1. At beginning of sub-list: expected to move to the
  4186. ;; paragraph before it.
  4187. (goto-line 4)
  4188. (org-backward-element)
  4189. (should (looking-at "item1"))
  4190. ;; 7.2. At an item in a list: expected to move at previous item.
  4191. (goto-line 8)
  4192. (org-backward-element)
  4193. (should (looking-at " - sub2"))
  4194. (goto-line 12)
  4195. (org-backward-element)
  4196. (should (looking-at "- item1"))
  4197. ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
  4198. ;; beginning.
  4199. (goto-line 10)
  4200. (org-backward-element)
  4201. (should (looking-at " - sub1"))
  4202. (goto-line 15)
  4203. (org-backward-element)
  4204. (should (looking-at "- item1"))
  4205. ;; 7.4. At blank-lines before list end: expected to move to top
  4206. ;; item.
  4207. (goto-line 14)
  4208. (org-backward-element)
  4209. (should (looking-at "- item1"))))
  4210. (ert-deftest test-org/up-element ()
  4211. "Test `org-up-element' specifications."
  4212. ;; 1. At BOB or with no surrounding element: should error.
  4213. (org-test-with-temp-text "Paragraph."
  4214. (should-error (org-up-element)))
  4215. (org-test-with-temp-text "* Head1\n* Head2"
  4216. (goto-line 2)
  4217. (should-error (org-up-element)))
  4218. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  4219. (goto-line 3)
  4220. (should-error (org-up-element)))
  4221. ;; 2. At an headline: move to parent headline.
  4222. (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
  4223. (goto-line 3)
  4224. (org-up-element)
  4225. (should (looking-at "\\* Head1")))
  4226. ;; 3. Inside a greater element: move to greater element beginning.
  4227. (org-test-with-temp-text
  4228. "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
  4229. (goto-line 3)
  4230. (org-up-element)
  4231. (should (looking-at "#\\+BEGIN_CENTER")))
  4232. ;; 4. List tests.
  4233. (org-test-with-temp-text "* Top
  4234. - item1
  4235. - sub1
  4236. - sub2
  4237. Paragraph within sub2.
  4238. - item2"
  4239. ;; 4.1. Within an item: move to the item beginning.
  4240. (goto-line 8)
  4241. (org-up-element)
  4242. (should (looking-at " - sub2"))
  4243. ;; 4.2. At an item in a sub-list: move to parent item.
  4244. (goto-line 4)
  4245. (org-up-element)
  4246. (should (looking-at "- item1"))
  4247. ;; 4.3. At an item in top list: move to beginning of whole list.
  4248. (goto-line 10)
  4249. (org-up-element)
  4250. (should (looking-at "- item1"))
  4251. ;; 4.4. Special case. At very top point: should move to parent of
  4252. ;; list.
  4253. (goto-line 2)
  4254. (org-up-element)
  4255. (should (looking-at "\\* Top"))))
  4256. (ert-deftest test-org/down-element ()
  4257. "Test `org-down-element' specifications."
  4258. ;; Error when the element hasn't got a recursive type.
  4259. (org-test-with-temp-text "Paragraph."
  4260. (should-error (org-down-element)))
  4261. ;; Error when the element has no contents
  4262. (org-test-with-temp-text "* Headline"
  4263. (should-error (org-down-element)))
  4264. ;; When at a plain-list, move to first item.
  4265. (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
  4266. (goto-line 2)
  4267. (org-down-element)
  4268. (should (looking-at " - Item 1.1")))
  4269. (org-test-with-temp-text "#+NAME: list\n- Item 1"
  4270. (org-down-element)
  4271. (should (looking-at " Item 1")))
  4272. ;; When at a table, move to first row
  4273. (org-test-with-temp-text "#+NAME: table\n| a | b |"
  4274. (org-down-element)
  4275. (should (looking-at " a | b |")))
  4276. ;; Otherwise, move inside the greater element.
  4277. (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
  4278. (org-down-element)
  4279. (should (looking-at "Paragraph"))))
  4280. (ert-deftest test-org/drag-element-backward ()
  4281. "Test `org-drag-element-backward' specifications."
  4282. ;; Standard test.
  4283. (should
  4284. (equal
  4285. "#+key2: val2\n#+key1: val1\n#+key3: val3"
  4286. (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
  4287. (org-drag-element-backward)
  4288. (buffer-string))))
  4289. (should
  4290. (equal
  4291. "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
  4292. (org-test-with-temp-text
  4293. "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
  4294. (org-drag-element-backward)
  4295. (buffer-string))))
  4296. ;; Preserve blank lines.
  4297. (should
  4298. (equal "Paragraph 2\n\n\nPara1\n\nPara3"
  4299. (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
  4300. (org-drag-element-backward)
  4301. (buffer-string))))
  4302. ;; Preserve column.
  4303. (should
  4304. (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
  4305. (org-drag-element-backward)
  4306. (looking-at-p "2")))
  4307. ;; Error when trying to move first element of buffer.
  4308. (should-error
  4309. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4310. (org-drag-element-backward))
  4311. :type 'user-error)
  4312. ;; Error when trying to swap nested elements.
  4313. (should-error
  4314. (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
  4315. (org-drag-element-backward))
  4316. :type 'user-error)
  4317. ;; Error when trying to swap an headline element and a non-headline
  4318. ;; element.
  4319. (should-error
  4320. (org-test-with-temp-text "Test.\n<point>* Head 1"
  4321. (org-drag-element-backward))
  4322. :type 'error)
  4323. ;; Error when called before first element.
  4324. (should-error
  4325. (org-test-with-temp-text "\n<point>"
  4326. (org-drag-element-backward))
  4327. :type 'user-error)
  4328. ;; Preserve visibility of elements and their contents.
  4329. (should
  4330. (equal '((63 . 82) (26 . 48))
  4331. (let ((org-fold-core-style 'text-properties))
  4332. (org-test-with-temp-text
  4333. "
  4334. #+BEGIN_CENTER
  4335. Text.
  4336. #+END_CENTER
  4337. - item 1
  4338. #+BEGIN_QUOTE
  4339. Text.
  4340. #+END_QUOTE"
  4341. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4342. (search-backward "- item 1")
  4343. (org-drag-element-backward)
  4344. (let (regions)
  4345. (goto-char (point-min))
  4346. (while (< (point) (point-max))
  4347. (let ((region (org-fold-get-region-at-point)))
  4348. (if (not region)
  4349. (goto-char (org-fold-next-folding-state-change))
  4350. (goto-char (cdr region))
  4351. (push region regions))))
  4352. regions)))))
  4353. (should
  4354. (equal '((63 . 82) (26 . 48))
  4355. (let ((org-fold-core-style 'overlays))
  4356. (org-test-with-temp-text
  4357. "
  4358. #+BEGIN_CENTER
  4359. Text.
  4360. #+END_CENTER
  4361. - item 1
  4362. #+BEGIN_QUOTE
  4363. Text.
  4364. #+END_QUOTE"
  4365. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4366. (search-backward "- item 1")
  4367. (org-drag-element-backward)
  4368. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4369. (overlays-in (point-min) (point-max)))))))
  4370. ;; Pathological case: handle call with point in blank lines right
  4371. ;; after a headline.
  4372. (should
  4373. (equal "* H2\n\n* H1\nText\n"
  4374. (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
  4375. (org-drag-element-backward)
  4376. (buffer-string)))))
  4377. (ert-deftest test-org/drag-element-forward ()
  4378. "Test `org-drag-element-forward' specifications."
  4379. ;; 1. Error when trying to move first element of buffer.
  4380. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4381. (goto-line 3)
  4382. (should-error (org-drag-element-forward)))
  4383. ;; 2. Error when trying to swap nested elements.
  4384. (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
  4385. (forward-line)
  4386. (should-error (org-drag-element-forward)))
  4387. ;; 3. Error when trying to swap a non-headline element and an
  4388. ;; headline.
  4389. (org-test-with-temp-text "Test.\n* Head 1"
  4390. (should-error (org-drag-element-forward)))
  4391. ;; 4. Error when called before first element.
  4392. (should-error
  4393. (org-test-with-temp-text "\n"
  4394. (forward-line)
  4395. (org-drag-element-backward))
  4396. :type 'user-error)
  4397. ;; 5. Otherwise, swap elements, preserving column and blank lines
  4398. ;; between elements.
  4399. (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
  4400. (search-forward "graph")
  4401. (org-drag-element-forward)
  4402. (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
  4403. (should (looking-at " 1")))
  4404. ;; 5. Preserve visibility of elements and their contents.
  4405. (let ((org-fold-core-style 'text-properties))
  4406. (org-test-with-temp-text
  4407. "
  4408. #+BEGIN_CENTER
  4409. Text.
  4410. #+END_CENTER
  4411. - item 1
  4412. #+BEGIN_QUOTE
  4413. Text.
  4414. #+END_QUOTE"
  4415. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4416. (search-backward "#+BEGIN_CENTER")
  4417. (org-drag-element-forward)
  4418. (should
  4419. (equal
  4420. '((63 . 82) (26 . 48))
  4421. (let (regions)
  4422. (goto-char (point-min))
  4423. (while (< (point) (point-max))
  4424. (let ((region (org-fold-get-region-at-point)))
  4425. (if (not region)
  4426. (goto-char (org-fold-next-folding-state-change))
  4427. (goto-char (cdr region))
  4428. (push region regions))))
  4429. regions)))))
  4430. (let ((org-fold-core-style 'overlays))
  4431. (org-test-with-temp-text
  4432. "
  4433. #+BEGIN_CENTER
  4434. Text.
  4435. #+END_CENTER
  4436. - item 1
  4437. #+BEGIN_QUOTE
  4438. Text.
  4439. #+END_QUOTE"
  4440. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4441. (search-backward "#+BEGIN_CENTER")
  4442. (org-drag-element-forward)
  4443. (should
  4444. (equal
  4445. '((63 . 82) (26 . 48))
  4446. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4447. (overlays-in (point-min) (point-max))))))))
  4448. (ert-deftest test-org/next-block ()
  4449. "Test `org-next-block' specifications."
  4450. ;; Regular test.
  4451. (should
  4452. (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  4453. (org-next-block 1)
  4454. (looking-at "#\\+BEGIN_CENTER")))
  4455. ;; Ignore case.
  4456. (should
  4457. (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
  4458. (let ((case-fold-search nil))
  4459. (org-next-block 1)
  4460. (looking-at "#\\+begin_center"))))
  4461. ;; Ignore current line.
  4462. (should
  4463. (org-test-with-temp-text
  4464. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
  4465. (org-next-block 1)
  4466. (looking-at "#\\+BEGIN_CENTER")))
  4467. ;; Throw an error when no block is found.
  4468. (should-error
  4469. (org-test-with-temp-text "Paragraph"
  4470. (org-next-block 1)))
  4471. ;; With an argument, skip many blocks at once.
  4472. (should
  4473. (org-test-with-temp-text
  4474. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4475. (org-next-block 2)
  4476. (looking-at "#\\+BEGIN_QUOTE")))
  4477. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4478. (should
  4479. (org-test-with-temp-text
  4480. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4481. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4482. (looking-at "#\\+BEGIN_QUOTE")))
  4483. ;; Optional argument is also case-insensitive.
  4484. (should
  4485. (org-test-with-temp-text
  4486. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
  4487. (let ((case-fold-search nil))
  4488. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4489. (looking-at "#\\+begin_quote")))))
  4490. (ert-deftest test-org/insert-structure-template ()
  4491. "Test `org-insert-structure-template'."
  4492. ;; Test in empty buffer.
  4493. (should
  4494. (string= "#+begin_foo\n#+end_foo\n"
  4495. (org-test-with-temp-text ""
  4496. (org-insert-structure-template "foo")
  4497. (buffer-string))))
  4498. ;; Test with multiple lines in buffer.
  4499. (should
  4500. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4501. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4502. (transient-mark-mode 1)
  4503. (org-mark-element)
  4504. (org-insert-structure-template "foo")
  4505. (buffer-string))))
  4506. ;; Mark only the current line.
  4507. (should
  4508. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4509. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4510. (transient-mark-mode 1)
  4511. (set-mark (point-min))
  4512. (end-of-line)
  4513. (org-insert-structure-template "foo")
  4514. (buffer-string))))
  4515. ;; Middle of paragraph.
  4516. (should
  4517. (string= "p1\n#+begin_foo\np2\n#+end_foo\np3"
  4518. (org-test-with-temp-text "p1\n<point>p2\np3"
  4519. (set-mark (line-beginning-position))
  4520. (end-of-line)
  4521. (activate-mark)
  4522. (org-insert-structure-template "foo")
  4523. (buffer-string))))
  4524. ;; Test with text in buffer, no region, no final newline.
  4525. (should
  4526. (string= "#+begin_foo\nI'm a paragraph.\n#+end_foo\n"
  4527. (org-test-with-temp-text "I'm a paragraph."
  4528. (org-mark-element)
  4529. (org-insert-structure-template "foo")
  4530. (buffer-string))))
  4531. ;; Test with text in buffer and region set.
  4532. (should
  4533. (string= "#+begin_foo\nI'm a paragraph\n\nI'm a second paragrah\n#+end_foo\n"
  4534. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragrah"
  4535. (set-mark (point))
  4536. (goto-char (point-max))
  4537. (org-insert-structure-template "foo")
  4538. (buffer-string))))
  4539. ;; Test with example escaping.
  4540. (should
  4541. (string= "#+begin_example\n,* Heading\n#+end_example\n"
  4542. (org-test-with-temp-text "* Heading"
  4543. (org-mark-element)
  4544. (org-insert-structure-template "example")
  4545. (buffer-string))))
  4546. ;; Test with indentation.
  4547. (should
  4548. (string= " #+begin_foo\n This is a paragraph\n #+end_foo\n"
  4549. (org-test-with-temp-text " This is a paragraph"
  4550. (org-mark-element)
  4551. (org-insert-structure-template "foo")
  4552. (buffer-string))))
  4553. (should
  4554. (string= " #+begin_foo\n Line 1\n Line2\n #+end_foo\n"
  4555. (org-test-with-temp-text " Line 1\n Line2"
  4556. (org-mark-element)
  4557. (org-insert-structure-template "foo")
  4558. (buffer-string))))
  4559. ;; Test point location.
  4560. (should
  4561. (string= "#+begin_foo\n"
  4562. (org-test-with-temp-text ""
  4563. (org-insert-structure-template "foo")
  4564. (buffer-substring (point-min) (point)))))
  4565. (should
  4566. (string= "#+begin_src "
  4567. (org-test-with-temp-text ""
  4568. (org-insert-structure-template "src")
  4569. (buffer-substring (point-min) (point))))))
  4570. (ert-deftest test-org/previous-block ()
  4571. "Test `org-previous-block' specifications."
  4572. ;; Regular test.
  4573. (should
  4574. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
  4575. (org-previous-block 1)
  4576. (looking-at "#\\+BEGIN_CENTER")))
  4577. ;; Ignore case.
  4578. (should
  4579. (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
  4580. (let ((case-fold-search nil))
  4581. (org-previous-block 1)
  4582. (looking-at "#\\+begin_center"))))
  4583. ;; Ignore current line.
  4584. (should
  4585. (org-test-with-temp-text
  4586. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
  4587. (org-previous-block 1)
  4588. (looking-at "#\\+BEGIN_QUOTE")))
  4589. ;; Throw an error when no block is found.
  4590. (should-error
  4591. (org-test-with-temp-text "Paragraph<point>"
  4592. (org-previous-block 1)))
  4593. ;; With an argument, skip many blocks at once.
  4594. (should
  4595. (org-test-with-temp-text
  4596. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4597. (org-previous-block 2)
  4598. (looking-at "#\\+BEGIN_CENTER")))
  4599. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4600. (should
  4601. (org-test-with-temp-text
  4602. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4603. (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4604. (looking-at "#\\+BEGIN_QUOTE")))
  4605. ;; Optional argument is also case-insensitive.
  4606. (should
  4607. (org-test-with-temp-text
  4608. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
  4609. (let ((case-fold-search nil))
  4610. (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4611. (looking-at "#\\+begin_quote")))))
  4612. ;;; Outline structure
  4613. (ert-deftest test-org/demote ()
  4614. "Test `org-demote' specifications."
  4615. ;; Add correct number of stars according to `org-odd-levels-only'.
  4616. (should
  4617. (= 2
  4618. (org-test-with-temp-text "* H"
  4619. (let ((org-odd-levels-only nil)) (org-demote))
  4620. (org-current-level))))
  4621. (should
  4622. (= 3
  4623. (org-test-with-temp-text "* H"
  4624. (let ((org-odd-levels-only t)) (org-demote))
  4625. (org-current-level))))
  4626. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4627. (should
  4628. (org-test-with-temp-text "* H :tag:"
  4629. (let ((org-tags-column 10)
  4630. (org-auto-align-tags t)
  4631. (org-odd-levels-only nil))
  4632. (org-demote))
  4633. (org-move-to-column 10)
  4634. (looking-at-p ":tag:$")))
  4635. (should-not
  4636. (org-test-with-temp-text "* H :tag:"
  4637. (let ((org-tags-column 10)
  4638. (org-auto-align-tags nil)
  4639. (org-odd-levels-only nil))
  4640. (org-demote))
  4641. (org-move-to-column 10)
  4642. (looking-at-p ":tag:$")))
  4643. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4644. ;; info and property drawers accordingly.
  4645. (should
  4646. (= 3
  4647. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4648. (let ((org-odd-levels-only nil)
  4649. (org-adapt-indentation t))
  4650. (org-demote))
  4651. (forward-line)
  4652. (org-get-indentation))))
  4653. (should
  4654. (= 3
  4655. (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4656. (let ((org-odd-levels-only nil)
  4657. (org-adapt-indentation t))
  4658. (org-demote))
  4659. (forward-line)
  4660. (org-get-indentation))))
  4661. (should-not
  4662. (= 3
  4663. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4664. (let ((org-odd-levels-only nil)
  4665. (org-adapt-indentation nil))
  4666. (org-demote))
  4667. (forward-line)
  4668. (org-get-indentation))))
  4669. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4670. ;; section accordingly. Ignore, however, footnote definitions and
  4671. ;; inlinetasks boundaries.
  4672. (should
  4673. (= 3
  4674. (org-test-with-temp-text "* H\n Paragraph"
  4675. (let ((org-odd-levels-only nil)
  4676. (org-adapt-indentation t))
  4677. (org-demote))
  4678. (forward-line)
  4679. (org-get-indentation))))
  4680. (should
  4681. (= 2
  4682. (org-test-with-temp-text "* H\n Paragraph"
  4683. (let ((org-odd-levels-only nil)
  4684. (org-adapt-indentation nil))
  4685. (org-demote))
  4686. (forward-line)
  4687. (org-get-indentation))))
  4688. (should
  4689. (zerop
  4690. (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
  4691. (let ((org-odd-levels-only nil)
  4692. (org-adapt-indentation t))
  4693. (org-demote))
  4694. (goto-char (point-max))
  4695. (org-get-indentation))))
  4696. (should
  4697. (= 3
  4698. (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
  4699. (let ((org-odd-levels-only nil)
  4700. (org-adapt-indentation t))
  4701. (org-demote))
  4702. (goto-char (point-max))
  4703. (org-get-indentation))))
  4704. (when (featurep 'org-inlinetask)
  4705. (should
  4706. (zerop
  4707. (let ((org-inlinetask-min-level 5)
  4708. (org-adapt-indentation t))
  4709. (org-test-with-temp-text "* H\n***** I\n***** END"
  4710. (org-demote)
  4711. (forward-line)
  4712. (org-get-indentation))))))
  4713. (when (featurep 'org-inlinetask)
  4714. (should
  4715. (= 3
  4716. (let ((org-inlinetask-min-level 5)
  4717. (org-adapt-indentation t))
  4718. (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
  4719. (org-demote)
  4720. (forward-line 2)
  4721. (org-get-indentation))))))
  4722. ;; When `org-adapt-indentation' is non-nil, log drawers are
  4723. ;; adjusted.
  4724. (should
  4725. (equal
  4726. "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4727. (org-test-with-temp-text "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4728. (let ((org-odd-levels-only nil)
  4729. (org-adapt-indentation t))
  4730. (org-demote))
  4731. (buffer-string))))
  4732. (should
  4733. (equal
  4734. "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4735. (org-test-with-temp-text "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4736. (let ((org-odd-levels-only nil)
  4737. (org-adapt-indentation 'headline-data))
  4738. (org-demote))
  4739. (buffer-string))))
  4740. (should
  4741. (equal
  4742. "** H\n :LOGBOOK:\n - a\n :END:"
  4743. (org-test-with-temp-text "* H\n:LOGBOOK:\n- a\n:END:"
  4744. (let ((org-odd-levels-only nil)
  4745. (org-adapt-indentation t))
  4746. (org-demote))
  4747. (buffer-string))))
  4748. ;; Ignore contents of source blocks or example blocks when
  4749. ;; indentation should be preserved (through
  4750. ;; `org-src-preserve-indentation' or "-i" flag).
  4751. (should-not
  4752. (zerop
  4753. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4754. (let ((org-adapt-indentation t)
  4755. (org-src-preserve-indentation nil))
  4756. (org-demote))
  4757. (forward-line 2)
  4758. (org-get-indentation))))
  4759. (should
  4760. (zerop
  4761. (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
  4762. (let ((org-adapt-indentation t)
  4763. (org-src-preserve-indentation t))
  4764. (org-demote))
  4765. (forward-line 2)
  4766. (org-get-indentation))))
  4767. (should
  4768. (zerop
  4769. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4770. (let ((org-adapt-indentation t)
  4771. (org-src-preserve-indentation t))
  4772. (org-demote))
  4773. (forward-line 2)
  4774. (org-get-indentation))))
  4775. (should
  4776. (zerop
  4777. (org-test-with-temp-text
  4778. "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
  4779. (let ((org-adapt-indentation t)
  4780. (org-src-preserve-indentation nil))
  4781. (org-demote))
  4782. (forward-line 2)
  4783. (org-get-indentation)))))
  4784. (ert-deftest test-org/promote ()
  4785. "Test `org-promote' specifications."
  4786. ;; Return an error if headline is to be promoted to level 0, unless
  4787. ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
  4788. ;; headline becomes a comment.
  4789. (should-error
  4790. (org-test-with-temp-text "* H"
  4791. (let ((org-allow-promoting-top-level-subtree nil)) (org-promote))))
  4792. (should
  4793. (equal "# H"
  4794. (org-test-with-temp-text "* H"
  4795. (let ((org-allow-promoting-top-level-subtree t)) (org-promote))
  4796. (buffer-string))))
  4797. ;; Remove correct number of stars according to
  4798. ;; `org-odd-levels-only'.
  4799. (should
  4800. (= 2
  4801. (org-test-with-temp-text "*** H"
  4802. (let ((org-odd-levels-only nil)) (org-promote))
  4803. (org-current-level))))
  4804. (should
  4805. (= 1
  4806. (org-test-with-temp-text "*** H"
  4807. (let ((org-odd-levels-only t)) (org-promote))
  4808. (org-current-level))))
  4809. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4810. (should
  4811. (org-test-with-temp-text "** H :tag:"
  4812. (let ((org-tags-column 10)
  4813. (org-auto-align-tags t)
  4814. (org-odd-levels-only nil))
  4815. (org-promote))
  4816. (org-move-to-column 10)
  4817. (looking-at-p ":tag:$")))
  4818. (should-not
  4819. (org-test-with-temp-text "** H :tag:"
  4820. (let ((org-tags-column 10)
  4821. (org-auto-align-tags nil)
  4822. (org-odd-levels-only nil))
  4823. (org-promote))
  4824. (org-move-to-column 10)
  4825. (looking-at-p ":tag:$")))
  4826. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4827. ;; info and property drawers.
  4828. (should
  4829. (= 2
  4830. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4831. (let ((org-odd-levels-only nil)
  4832. (org-adapt-indentation t))
  4833. (org-promote))
  4834. (forward-line)
  4835. (org-get-indentation))))
  4836. (should
  4837. (= 2
  4838. (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4839. (let ((org-odd-levels-only nil)
  4840. (org-adapt-indentation t))
  4841. (org-promote))
  4842. (forward-line)
  4843. (org-get-indentation))))
  4844. (should-not
  4845. (= 2
  4846. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4847. (let ((org-odd-levels-only nil)
  4848. (org-adapt-indentation nil))
  4849. (org-promote))
  4850. (forward-line)
  4851. (org-get-indentation))))
  4852. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4853. ;; section accordingly. Ignore, however, footnote definitions and
  4854. ;; inlinetasks boundaries.
  4855. (should
  4856. (= 2
  4857. (org-test-with-temp-text "** H\n Paragraph"
  4858. (let ((org-odd-levels-only nil)
  4859. (org-adapt-indentation t))
  4860. (org-promote))
  4861. (forward-line)
  4862. (org-get-indentation))))
  4863. (should-not
  4864. (= 2
  4865. (org-test-with-temp-text "** H\n Paragraph"
  4866. (let ((org-odd-levels-only nil)
  4867. (org-adapt-indentation nil))
  4868. (org-promote))
  4869. (forward-line)
  4870. (org-get-indentation))))
  4871. (should
  4872. (= 2
  4873. (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
  4874. (let ((org-odd-levels-only nil)
  4875. (org-adapt-indentation t))
  4876. (org-promote))
  4877. (forward-line)
  4878. (org-get-indentation))))
  4879. (when (featurep 'org-inlinetask)
  4880. (should
  4881. (zerop
  4882. (let ((org-inlinetask-min-level 5)
  4883. (org-adapt-indentation t))
  4884. (org-test-with-temp-text "** H\n***** I\n***** END"
  4885. (org-promote)
  4886. (forward-line)
  4887. (org-get-indentation))))))
  4888. (when (featurep 'org-inlinetask)
  4889. (should
  4890. (= 2
  4891. (let ((org-inlinetask-min-level 5)
  4892. (org-adapt-indentation t))
  4893. (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
  4894. (org-promote)
  4895. (forward-line 2)
  4896. (org-get-indentation))))))
  4897. ;; Give up shifting if it would break document's structure
  4898. ;; otherwise.
  4899. (should
  4900. (= 3
  4901. (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
  4902. (let ((org-odd-levels-only nil)
  4903. (org-adapt-indentation t))
  4904. (org-promote))
  4905. (forward-line)
  4906. (org-get-indentation))))
  4907. (should
  4908. (= 3
  4909. (org-test-with-temp-text "** H\n Paragraph\n * list."
  4910. (let ((org-odd-levels-only nil)
  4911. (org-adapt-indentation t))
  4912. (org-promote))
  4913. (forward-line)
  4914. (org-get-indentation))))
  4915. ;; When `org-adapt-indentation' is non-nil, log drawers are
  4916. ;; adjusted.
  4917. (should
  4918. (equal
  4919. "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4920. (org-test-with-temp-text "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4921. (let ((org-odd-levels-only nil)
  4922. (org-adapt-indentation t))
  4923. (org-promote))
  4924. (buffer-string))))
  4925. (should
  4926. (equal
  4927. "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4928. (org-test-with-temp-text "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4929. (let ((org-odd-levels-only nil)
  4930. (org-adapt-indentation 'headline-data))
  4931. (org-promote))
  4932. (buffer-string))))
  4933. (should
  4934. (equal
  4935. "* H\n:LOGBOOK:\n- a\n:END:"
  4936. (org-test-with-temp-text "** H\n:LOGBOOK:\n- a\n:END:"
  4937. (let ((org-odd-levels-only nil)
  4938. (org-adapt-indentation t))
  4939. (org-promote))
  4940. (buffer-string))))
  4941. (should
  4942. (equal
  4943. "# H\n:LOGBOOK:\n- a\n:END:"
  4944. (org-test-with-temp-text "* H\n:LOGBOOK:\n- a\n:END:"
  4945. (let ((org-odd-levels-only nil)
  4946. (org-allow-promoting-top-level-subtree t)
  4947. (org-adapt-indentation t))
  4948. (org-promote))
  4949. (buffer-string))))
  4950. ;; Ignore contents of source blocks or example blocks when
  4951. ;; indentation should be preserved (through
  4952. ;; `org-src-preserve-indentation' or "-i" flag).
  4953. (should-not
  4954. (zerop
  4955. (org-test-with-temp-text
  4956. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  4957. (let ((org-adapt-indentation t)
  4958. (org-src-preserve-indentation nil)
  4959. (org-odd-levels-only nil))
  4960. (org-promote))
  4961. (forward-line)
  4962. (org-get-indentation))))
  4963. (should
  4964. (zerop
  4965. (org-test-with-temp-text
  4966. "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
  4967. (let ((org-adapt-indentation t)
  4968. (org-src-preserve-indentation t)
  4969. (org-odd-levels-only nil))
  4970. (org-promote))
  4971. (forward-line)
  4972. (org-get-indentation))))
  4973. (should
  4974. (zerop
  4975. (org-test-with-temp-text
  4976. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  4977. (let ((org-adapt-indentation t)
  4978. (org-src-preserve-indentation t)
  4979. (org-odd-levels-only nil))
  4980. (org-promote))
  4981. (forward-line)
  4982. (org-get-indentation))))
  4983. (should
  4984. (zerop
  4985. (org-test-with-temp-text
  4986. "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
  4987. (let ((org-adapt-indentation t)
  4988. (org-src-preserve-indentation nil)
  4989. (org-odd-levels-only nil))
  4990. (org-promote))
  4991. (forward-line)
  4992. (org-get-indentation)))))
  4993. (ert-deftest test-org/org-get-valid-level ()
  4994. "Test function `org-get-valid-level' specifications."
  4995. (let ((org-odd-levels-only nil))
  4996. (should (equal 1 (org-get-valid-level 0 0)))
  4997. (should (equal 1 (org-get-valid-level 0 1)))
  4998. (should (equal 2 (org-get-valid-level 0 2)))
  4999. (should (equal 3 (org-get-valid-level 0 3)))
  5000. (should (equal 1 (org-get-valid-level 1 0)))
  5001. (should (equal 2 (org-get-valid-level 1 1)))
  5002. (should (equal 23 (org-get-valid-level 1 22)))
  5003. (should (equal 1 (org-get-valid-level 1 -1)))
  5004. (should (equal 1 (org-get-valid-level 2 -1))))
  5005. (let ((org-odd-levels-only t))
  5006. (should (equal 1 (org-get-valid-level 0 0)))
  5007. (should (equal 1 (org-get-valid-level 0 1)))
  5008. (should (equal 3 (org-get-valid-level 0 2)))
  5009. (should (equal 5 (org-get-valid-level 0 3)))
  5010. (should (equal 1 (org-get-valid-level 1 0)))
  5011. (should (equal 3 (org-get-valid-level 1 1)))
  5012. (should (equal 3 (org-get-valid-level 2 1)))
  5013. (should (equal 5 (org-get-valid-level 3 1)))
  5014. (should (equal 5 (org-get-valid-level 4 1)))
  5015. (should (equal 43 (org-get-valid-level 1 21)))
  5016. (should (equal 1 (org-get-valid-level 1 -1)))
  5017. (should (equal 1 (org-get-valid-level 2 -1)))
  5018. (should (equal 1 (org-get-valid-level 3 -1)))
  5019. (should (equal 3 (org-get-valid-level 4 -1)))
  5020. (should (equal 3 (org-get-valid-level 5 -1)))))
  5021. ;;; Planning
  5022. (ert-deftest test-org/at-planning-p ()
  5023. "Test `org-at-planning-p' specifications."
  5024. ;; Regular test.
  5025. (should
  5026. (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
  5027. (org-at-planning-p)))
  5028. (should-not
  5029. (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
  5030. (org-at-planning-p)))
  5031. ;; Correctly find planning attached to inlinetasks.
  5032. (when (featurep 'org-inlinetask)
  5033. (should
  5034. (org-test-with-temp-text
  5035. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
  5036. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  5037. (should-not
  5038. (org-test-with-temp-text
  5039. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  5040. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  5041. (should-not
  5042. (org-test-with-temp-text
  5043. "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  5044. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  5045. (should-not
  5046. (org-test-with-temp-text
  5047. "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
  5048. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
  5049. (ert-deftest test-org/add-planning-info ()
  5050. "Test `org-add-planning-info'."
  5051. ;; Create deadline when `org-adapt-indentation' is non-nil.
  5052. (should
  5053. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5054. (org-test-with-temp-text "* H\nParagraph<point>"
  5055. (let ((org-adapt-indentation t))
  5056. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5057. (replace-regexp-in-string
  5058. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5059. nil nil 1))))
  5060. ;; Create deadline when `org-adapt-indentation' is nil.
  5061. (should
  5062. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  5063. (org-test-with-temp-text "* H\nParagraph<point>"
  5064. (let ((org-adapt-indentation nil))
  5065. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5066. (replace-regexp-in-string
  5067. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5068. nil nil 1))))
  5069. ;; Update deadline when `org-adapt-indentation' is non-nil.
  5070. (should
  5071. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5072. (org-test-with-temp-text "\
  5073. * H
  5074. DEADLINE: <2015-06-24 Wed>
  5075. Paragraph<point>"
  5076. (let ((org-adapt-indentation t))
  5077. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5078. (replace-regexp-in-string
  5079. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5080. nil nil 1))))
  5081. ;; Update deadline when `org-adapt-indentation' is nil.
  5082. (should
  5083. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  5084. (org-test-with-temp-text "\
  5085. * H
  5086. DEADLINE: <2015-06-24 Wed>
  5087. Paragraph<point>"
  5088. (let ((org-adapt-indentation nil))
  5089. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5090. (replace-regexp-in-string
  5091. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5092. nil nil 1))))
  5093. ;; Schedule when `org-adapt-indentation' is non-nil.
  5094. (should
  5095. (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
  5096. (org-test-with-temp-text "* H\nParagraph<point>"
  5097. (let ((org-adapt-indentation t))
  5098. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  5099. (replace-regexp-in-string
  5100. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5101. nil nil 1))))
  5102. ;; Schedule when `org-adapt-indentation' is nil.
  5103. (should
  5104. (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
  5105. (org-test-with-temp-text "* H\nParagraph<point>"
  5106. (let ((org-adapt-indentation nil))
  5107. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  5108. (replace-regexp-in-string
  5109. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5110. nil nil 1))))
  5111. ;; Add deadline when scheduled.
  5112. (should
  5113. (equal "\
  5114. * H
  5115. DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
  5116. Paragraph"
  5117. (org-test-with-temp-text "\
  5118. * H
  5119. SCHEDULED: <2015-06-24 Wed>
  5120. Paragraph<point>"
  5121. (let ((org-adapt-indentation t))
  5122. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5123. (replace-regexp-in-string
  5124. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5125. nil nil 1))))
  5126. ;; Remove middle entry.
  5127. (should
  5128. (equal "\
  5129. * H
  5130. CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
  5131. Paragraph"
  5132. (org-test-with-temp-text "\
  5133. * H
  5134. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  5135. Paragraph<point>"
  5136. (let ((org-adapt-indentation t))
  5137. (org-add-planning-info nil nil 'deadline))
  5138. (replace-regexp-in-string
  5139. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  5140. nil nil 1))))
  5141. ;; Remove last entry and then middle entry (order should not
  5142. ;; matter).
  5143. (should
  5144. (equal "\
  5145. * H
  5146. CLOSED: [2015-06-24]
  5147. Paragraph"
  5148. (org-test-with-temp-text "\
  5149. * H
  5150. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  5151. Paragraph<point>"
  5152. (let ((org-adapt-indentation t))
  5153. (org-add-planning-info nil nil 'scheduled 'deadline))
  5154. (replace-regexp-in-string
  5155. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  5156. nil nil 1))))
  5157. ;; Remove closed when `org-adapt-indentation' is non-nil.
  5158. (should
  5159. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5160. (org-test-with-temp-text "\
  5161. * H
  5162. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  5163. Paragraph<point>"
  5164. (let ((org-adapt-indentation t))
  5165. (org-add-planning-info nil nil 'closed))
  5166. (replace-regexp-in-string
  5167. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5168. nil nil 1))))
  5169. (should
  5170. (equal "* H\n Paragraph"
  5171. (org-test-with-temp-text "\
  5172. * H
  5173. CLOSED: [2015-06-25 Thu]
  5174. Paragraph<point>"
  5175. (let ((org-adapt-indentation t))
  5176. (org-add-planning-info nil nil 'closed))
  5177. (replace-regexp-in-string
  5178. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5179. nil nil 1))))
  5180. ;; Remove closed when `org-adapt-indentation' is nil.
  5181. (should
  5182. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  5183. (org-test-with-temp-text "\
  5184. * H
  5185. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  5186. Paragraph<point>"
  5187. (let ((org-adapt-indentation nil))
  5188. (org-add-planning-info nil nil 'closed))
  5189. (replace-regexp-in-string
  5190. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5191. nil nil 1))))
  5192. (should
  5193. (equal "* H\nParagraph"
  5194. (org-test-with-temp-text "\
  5195. * H
  5196. CLOSED: [2015-06-25 Thu]
  5197. Paragraph<point>"
  5198. (let ((org-adapt-indentation nil))
  5199. (org-add-planning-info nil nil 'closed))
  5200. (replace-regexp-in-string
  5201. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5202. nil nil 1))))
  5203. ;; Remove closed entry and delete empty line.
  5204. (should
  5205. (equal "\
  5206. * H
  5207. Paragraph"
  5208. (org-test-with-temp-text "\
  5209. * H
  5210. CLOSED: [2015-06-24 Wed]
  5211. Paragraph<point>"
  5212. (let ((org-adapt-indentation t))
  5213. (org-add-planning-info nil nil 'closed))
  5214. (replace-regexp-in-string
  5215. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5216. nil nil 1))))
  5217. ;; Remove one entry and update another.
  5218. (should
  5219. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5220. (org-test-with-temp-text "\
  5221. * H
  5222. SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
  5223. Paragraph<point>"
  5224. (let ((org-adapt-indentation t))
  5225. (org-add-planning-info 'deadline "<2015-06-25 Thu>" 'scheduled))
  5226. (replace-regexp-in-string
  5227. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5228. nil nil 1)))))
  5229. (ert-deftest test-org/deadline ()
  5230. "Test `org-deadline' specifications."
  5231. ;; Insert a new value or replace existing one.
  5232. (should
  5233. (equal "* H\nDEADLINE: <2012-03-29>"
  5234. (org-test-with-temp-text "* H"
  5235. (let ((org-adapt-indentation nil)
  5236. (org-last-inserted-timestamp nil))
  5237. (org-deadline nil "<2012-03-29 Tue>"))
  5238. (replace-regexp-in-string
  5239. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5240. nil nil 1))))
  5241. (should
  5242. (equal "* H\nDEADLINE: <2014-03-04>"
  5243. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5244. (let ((org-adapt-indentation nil)
  5245. (org-last-inserted-timestamp nil))
  5246. (org-deadline nil "<2014-03-04 Thu>"))
  5247. (replace-regexp-in-string
  5248. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5249. nil nil 1))))
  5250. ;; Accept delta time, e.g., "+2d".
  5251. (should
  5252. (equal "* H\nDEADLINE: <2015-03-04>"
  5253. (org-test-at-time "2014-03-04"
  5254. (org-test-with-temp-text "* H"
  5255. (let ((org-adapt-indentation nil)
  5256. (org-last-inserted-timestamp nil))
  5257. (org-deadline nil "+1y"))
  5258. (replace-regexp-in-string
  5259. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5260. ;; Preserve repeater.
  5261. (should
  5262. (equal "* H\nDEADLINE: <2012-03-29 +2y>"
  5263. (org-test-with-temp-text "* H"
  5264. (let ((org-adapt-indentation nil)
  5265. (org-last-inserted-timestamp nil))
  5266. (org-deadline nil "<2012-03-29 Tue +2y>"))
  5267. (replace-regexp-in-string
  5268. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5269. ;; Remove CLOSED keyword, if any.
  5270. (should
  5271. (equal "* H\nDEADLINE: <2012-03-29>"
  5272. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  5273. (let ((org-adapt-indentation nil)
  5274. (org-last-inserted-timestamp nil))
  5275. (org-deadline nil "<2012-03-29 Tue>"))
  5276. (replace-regexp-in-string
  5277. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5278. ;; With C-u argument, remove DEADLINE keyword.
  5279. (should
  5280. (equal "* H\n"
  5281. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5282. (let ((org-adapt-indentation nil)
  5283. (org-last-inserted-timestamp nil))
  5284. (org-deadline '(4)))
  5285. (buffer-string))))
  5286. (should
  5287. (equal "* H"
  5288. (org-test-with-temp-text "* H"
  5289. (let ((org-adapt-indentation nil)
  5290. (org-last-inserted-timestamp nil))
  5291. (org-deadline '(4)))
  5292. (buffer-string))))
  5293. ;; With C-u C-u argument, prompt for a delay cookie.
  5294. (should
  5295. (equal "* H\nDEADLINE: <2012-03-29 -705d>"
  5296. (cl-letf (((symbol-function 'org-read-date)
  5297. (lambda (&rest args)
  5298. (apply #'encode-time
  5299. (org-parse-time-string "2014-03-04")))))
  5300. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5301. (let ((org-adapt-indentation nil)
  5302. (org-last-inserted-timestamp nil))
  5303. (org-deadline '(16)))
  5304. (buffer-string)))))
  5305. (should-error
  5306. (cl-letf (((symbol-function 'org-read-date)
  5307. (lambda (&rest args)
  5308. (apply #'encode-time
  5309. (org-parse-time-string "2014-03-04")))))
  5310. (org-test-with-temp-text "* H"
  5311. (let ((org-adapt-indentation nil)
  5312. (org-last-inserted-timestamp nil))
  5313. (org-deadline '(16)))
  5314. (buffer-string))))
  5315. ;; When a region is active and
  5316. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5317. ;; same value in all headlines in region.
  5318. (should
  5319. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5320. (org-test-with-temp-text "* H1\n* H2"
  5321. (let ((org-adapt-indentation nil)
  5322. (org-last-inserted-timestamp nil)
  5323. (org-loop-over-headlines-in-active-region t))
  5324. (transient-mark-mode 1)
  5325. (push-mark (point) t t)
  5326. (goto-char (point-max))
  5327. (org-deadline nil "2012-03-29"))
  5328. (replace-regexp-in-string
  5329. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5330. (should-not
  5331. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5332. (org-test-with-temp-text "* H1\n* H2"
  5333. (let ((org-adapt-indentation nil)
  5334. (org-last-inserted-timestamp nil)
  5335. (org-loop-over-headlines-in-active-region nil))
  5336. (transient-mark-mode 1)
  5337. (push-mark (point) t t)
  5338. (goto-char (point-max))
  5339. (org-deadline nil "2012-03-29"))
  5340. (replace-regexp-in-string
  5341. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5342. (ert-deftest test-org/schedule ()
  5343. "Test `org-schedule' specifications."
  5344. ;; Insert a new value or replace existing one.
  5345. (should
  5346. (equal "* H\nSCHEDULED: <2012-03-29>"
  5347. (org-test-with-temp-text "* H"
  5348. (let ((org-adapt-indentation nil)
  5349. (org-last-inserted-timestamp nil))
  5350. (org-schedule nil "<2012-03-29 Tue>"))
  5351. (replace-regexp-in-string
  5352. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5353. nil nil 1))))
  5354. (should
  5355. (equal "* H\nSCHEDULED: <2014-03-04>"
  5356. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5357. (let ((org-adapt-indentation nil)
  5358. (org-last-inserted-timestamp nil))
  5359. (org-schedule nil "<2014-03-04 Thu>"))
  5360. (replace-regexp-in-string
  5361. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5362. nil nil 1))))
  5363. ;; Accept delta time, e.g., "+2d".
  5364. (should
  5365. (equal "* H\nSCHEDULED: <2015-03-04>"
  5366. (org-test-at-time "2014-03-04"
  5367. (org-test-with-temp-text "* H"
  5368. (let ((org-adapt-indentation nil)
  5369. (org-last-inserted-timestamp nil))
  5370. (org-schedule nil "+1y"))
  5371. (replace-regexp-in-string
  5372. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5373. ;; Preserve repeater.
  5374. (should
  5375. (equal "* H\nSCHEDULED: <2012-03-29 +2y>"
  5376. (org-test-with-temp-text "* H"
  5377. (let ((org-adapt-indentation nil)
  5378. (org-last-inserted-timestamp nil))
  5379. (org-schedule nil "<2012-03-29 Tue +2y>"))
  5380. (replace-regexp-in-string
  5381. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5382. ;; Remove CLOSED keyword, if any.
  5383. (should
  5384. (equal "* H\nSCHEDULED: <2012-03-29>"
  5385. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  5386. (let ((org-adapt-indentation nil)
  5387. (org-last-inserted-timestamp nil))
  5388. (org-schedule nil "<2012-03-29 Tue>"))
  5389. (replace-regexp-in-string
  5390. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5391. ;; With C-u argument, remove SCHEDULED keyword.
  5392. (should
  5393. (equal "* H\n"
  5394. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5395. (let ((org-adapt-indentation nil)
  5396. (org-last-inserted-timestamp nil))
  5397. (org-schedule '(4)))
  5398. (buffer-string))))
  5399. (should
  5400. (equal "* H"
  5401. (org-test-with-temp-text "* H"
  5402. (let ((org-adapt-indentation nil)
  5403. (org-last-inserted-timestamp nil))
  5404. (org-schedule '(4)))
  5405. (buffer-string))))
  5406. ;; With C-u C-u argument, prompt for a delay cookie.
  5407. (should
  5408. (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
  5409. (cl-letf (((symbol-function 'org-read-date)
  5410. (lambda (&rest args)
  5411. (apply #'encode-time
  5412. (org-parse-time-string "2014-03-04")))))
  5413. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5414. (let ((org-adapt-indentation nil)
  5415. (org-last-inserted-timestamp nil))
  5416. (org-schedule '(16)))
  5417. (buffer-string)))))
  5418. (should-error
  5419. (cl-letf (((symbol-function 'org-read-date)
  5420. (lambda (&rest args)
  5421. (apply #'encode-time
  5422. (org-parse-time-string "2014-03-04")))))
  5423. (org-test-with-temp-text "* H"
  5424. (let ((org-adapt-indentation nil)
  5425. (org-last-inserted-timestamp nil))
  5426. (org-schedule '(16)))
  5427. (buffer-string))))
  5428. ;; When a region is active and
  5429. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5430. ;; same value in all headlines in region.
  5431. (should
  5432. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5433. (org-test-with-temp-text "* H1\n* H2"
  5434. (let ((org-adapt-indentation nil)
  5435. (org-last-inserted-timestamp nil)
  5436. (org-loop-over-headlines-in-active-region t))
  5437. (transient-mark-mode 1)
  5438. (push-mark (point) t t)
  5439. (goto-char (point-max))
  5440. (org-schedule nil "2012-03-29"))
  5441. (replace-regexp-in-string
  5442. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5443. (should-not
  5444. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5445. (org-test-with-temp-text "* H1\n* H2"
  5446. (let ((org-adapt-indentation nil)
  5447. (org-last-inserted-timestamp nil)
  5448. (org-loop-over-headlines-in-active-region nil))
  5449. (transient-mark-mode 1)
  5450. (push-mark (point) t t)
  5451. (goto-char (point-max))
  5452. (org-schedule nil "2012-03-29"))
  5453. (replace-regexp-in-string
  5454. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5455. (should
  5456. ;; check if a repeater survives re-scheduling.
  5457. (string-match-p
  5458. "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
  5459. (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
  5460. (let ((org-adapt-indentation nil)
  5461. (org-last-inserted-timestamp nil))
  5462. (org-schedule nil "2017-02-01"))
  5463. (buffer-string)))))
  5464. ;;; Property API
  5465. (ert-deftest test-org/buffer-property-keys ()
  5466. "Test `org-buffer-property-keys' specifications."
  5467. ;; Retrieve properties across siblings.
  5468. (should
  5469. (equal '("A" "B")
  5470. (org-test-with-temp-text "
  5471. * H1
  5472. :PROPERTIES:
  5473. :A: 1
  5474. :END:
  5475. * H2
  5476. :PROPERTIES:
  5477. :B: 1
  5478. :END:"
  5479. (org-buffer-property-keys))))
  5480. ;; Retrieve properties across children.
  5481. (should
  5482. (equal '("A" "B")
  5483. (org-test-with-temp-text "
  5484. * H1
  5485. :PROPERTIES:
  5486. :A: 1
  5487. :END:
  5488. ** H2
  5489. :PROPERTIES:
  5490. :B: 1
  5491. :END:"
  5492. (org-buffer-property-keys))))
  5493. ;; Retrieve muliple properties in the same drawer.
  5494. (should
  5495. (equal '("A" "B")
  5496. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5497. (org-buffer-property-keys))))
  5498. ;; Ignore extension symbol in property name.
  5499. (should
  5500. (equal '("A")
  5501. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5502. (org-buffer-property-keys))))
  5503. ;; Add bare property if xxx_ALL property is there
  5504. (should
  5505. (equal '("A" "B" "B_ALL")
  5506. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B_ALL: foo bar\n:END:"
  5507. (org-buffer-property-keys))))
  5508. ;; Add bare property if xxx_ALL property is there - check dupes
  5509. (should
  5510. (equal '("A" "B" "B_ALL")
  5511. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:B_ALL: foo bar\n:END:"
  5512. (org-buffer-property-keys))))
  5513. ;; Retrieve properties from #+PROPERTY keyword lines
  5514. (should
  5515. (equal '("A" "C")
  5516. (org-test-with-temp-text "#+PROPERTY: C foo\n* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5517. (org-buffer-property-keys))))
  5518. ;; Retrieve properties from #+PROPERTY keyword lines - make sure an _ALL property also
  5519. ;; adds the bare property
  5520. (should
  5521. (equal '("A" "C" "C_ALL")
  5522. (org-test-with-temp-text "#+PROPERTY: C_ALL foo bar\n* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5523. (org-buffer-property-keys))))
  5524. ;; With non-nil COLUMNS, extract property names from columns.
  5525. (should
  5526. (equal '("A" "B")
  5527. (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
  5528. (org-buffer-property-keys nil nil t))))
  5529. (should
  5530. (equal '("A" "B" "COLUMNS")
  5531. (org-test-with-temp-text
  5532. "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
  5533. (org-buffer-property-keys nil nil t))))
  5534. ;; In COLUMNS, ignore title and summary-type.
  5535. (should
  5536. (equal '("A")
  5537. (org-test-with-temp-text "#+COLUMNS: %A(Foo)"
  5538. (org-buffer-property-keys nil nil t))))
  5539. (should
  5540. (equal '("A")
  5541. (org-test-with-temp-text "#+COLUMNS: %A{Foo}"
  5542. (org-buffer-property-keys nil nil t))))
  5543. (should
  5544. (equal '("A")
  5545. (org-test-with-temp-text "#+COLUMNS: %A(Foo){Bar}"
  5546. (org-buffer-property-keys nil nil t)))))
  5547. (ert-deftest test-org/property-values ()
  5548. "Test `org-property-values' specifications."
  5549. ;; Regular test.
  5550. (should
  5551. (equal '("2" "1")
  5552. (org-test-with-temp-text
  5553. "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
  5554. (org-property-values "A"))))
  5555. ;; Ignore empty values.
  5556. (should-not
  5557. (org-test-with-temp-text
  5558. "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
  5559. (org-property-values "A")))
  5560. ;; Take into consideration extended values.
  5561. (should
  5562. (equal '("1 2")
  5563. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5564. (org-property-values "A")))))
  5565. (ert-deftest test-org/set-property ()
  5566. "Test `org-set-property' specifications."
  5567. (should
  5568. (equal
  5569. ":PROPERTIES:\n:TEST: t\n:END:\n"
  5570. (org-test-with-temp-text ""
  5571. (let ((org-property-format "%s %s"))
  5572. (org-set-property "TEST" "t"))
  5573. (buffer-string))))
  5574. (should
  5575. (equal
  5576. "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5577. (org-test-with-temp-text "* H"
  5578. (let ((org-adapt-indentation nil)
  5579. (org-property-format "%s %s"))
  5580. (org-set-property "TEST" "t"))
  5581. (buffer-string)))))
  5582. (ert-deftest test-org/delete-property ()
  5583. "Test `org-delete-property' specifications."
  5584. (should
  5585. (equal
  5586. ""
  5587. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5588. (org-delete-property "TEST")
  5589. (buffer-string))))
  5590. (should
  5591. (equal
  5592. ":PROPERTIES:\n:TEST1: t\n:END:\n"
  5593. (org-test-with-temp-text ":PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5594. (org-delete-property "TEST2")
  5595. (buffer-string))))
  5596. (should
  5597. (equal
  5598. "* H\n"
  5599. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5600. (org-delete-property "TEST")
  5601. (buffer-string))))
  5602. (should
  5603. (equal
  5604. "* H\n:PROPERTIES:\n:TEST1: t\n:END:\n"
  5605. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5606. (org-delete-property "TEST2")
  5607. (buffer-string)))))
  5608. (ert-deftest test-org/delete-property-globally ()
  5609. "Test `org-delete-property-global' specifications."
  5610. (should
  5611. (equal
  5612. ""
  5613. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5614. (org-delete-property-globally "TEST")
  5615. (buffer-string))))
  5616. (should
  5617. (equal
  5618. "* H\n"
  5619. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n* H\n:PROPERTIES:\n:TEST: nil\n:END:"
  5620. (org-delete-property-globally "TEST")
  5621. (buffer-string)))))
  5622. (ert-deftest test-org/find-property ()
  5623. "Test `org-find-property' specifications."
  5624. ;; Regular test.
  5625. (should
  5626. (= 1
  5627. (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
  5628. (org-find-property "prop"))))
  5629. ;; Find properties in top-level property drawer.
  5630. (should
  5631. (= 1
  5632. (org-test-with-temp-text ":PROPERTIES:\n:PROP: value\n:END:"
  5633. (org-find-property "prop"))))
  5634. ;; Ignore false positives.
  5635. (should
  5636. (= 27
  5637. (org-test-with-temp-text
  5638. "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
  5639. (org-find-property "A"))))
  5640. ;; Return first entry found in buffer.
  5641. (should
  5642. (= 1
  5643. (org-test-with-temp-text
  5644. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5645. (org-find-property "A"))))
  5646. ;; Only search visible part of the buffer.
  5647. (should
  5648. (= 31
  5649. (org-test-with-temp-text
  5650. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5651. (org-narrow-to-subtree)
  5652. (org-find-property "A"))))
  5653. ;; With optional argument, only find entries with a specific value.
  5654. (should-not
  5655. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5656. (org-find-property "A" "2")))
  5657. (should
  5658. (= 31
  5659. (org-test-with-temp-text
  5660. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
  5661. (org-find-property "A" "2"))))
  5662. ;; Use "nil" for explicit nil values.
  5663. (should
  5664. (= 31
  5665. (org-test-with-temp-text
  5666. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
  5667. (org-find-property "A" "nil")))))
  5668. (ert-deftest test-org/entry-delete ()
  5669. "Test `org-entry-delete' specifications."
  5670. ;; Regular test.
  5671. (should
  5672. (string-match
  5673. " *:PROPERTIES:\n *:B: +2\n *:END:"
  5674. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5675. (org-entry-delete (point) "A")
  5676. (buffer-string))))
  5677. ;; Also remove accumulated properties.
  5678. (should-not
  5679. (string-match
  5680. ":A"
  5681. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
  5682. (org-entry-delete (point) "A")
  5683. (buffer-string))))
  5684. ;; When last property is removed, remove the property drawer.
  5685. (should-not
  5686. (string-match
  5687. ":PROPERTIES:"
  5688. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
  5689. (org-entry-delete (point) "A")
  5690. (buffer-string))))
  5691. ;; Return a non-nil value when some property was removed.
  5692. (should
  5693. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5694. (org-entry-delete (point) "A")))
  5695. (should-not
  5696. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5697. (org-entry-delete (point) "C")))
  5698. ;; Special properties cannot be located in a drawer. Allow to
  5699. ;; remove them anyway, in case of user error.
  5700. (should
  5701. (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
  5702. (org-entry-delete (point) "SCHEDULED"))))
  5703. (ert-deftest test-org/entry-get ()
  5704. "Test `org-entry-get' specifications."
  5705. ;; Regular test.
  5706. (should
  5707. (equal "1"
  5708. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:"
  5709. (org-entry-get (point) "A"))))
  5710. (should
  5711. (equal "1"
  5712. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5713. (org-entry-get (point) "A"))))
  5714. ;; Ignore case.
  5715. (should
  5716. (equal "1"
  5717. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5718. (org-entry-get (point) "a"))))
  5719. ;; Handle extended values, both before and after base value.
  5720. (should
  5721. (equal "1 2 3"
  5722. (org-test-with-temp-text
  5723. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5724. (org-entry-get (point) "A"))))
  5725. ;; Empty values are returned as the empty string.
  5726. (should
  5727. (equal ""
  5728. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
  5729. (org-entry-get (point) "A"))))
  5730. ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
  5731. ;; otherwise, return nil.
  5732. (should-not
  5733. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5734. (org-entry-get (point) "A")))
  5735. (should
  5736. (equal "nil"
  5737. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5738. (org-entry-get (point) "A" nil t))))
  5739. ;; Return nil when no property is found, independently on the
  5740. ;; LITERAL-NIL argument.
  5741. (should-not
  5742. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5743. (org-entry-get (point) "B")))
  5744. (should-not
  5745. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5746. (org-entry-get (point) "B" nil t)))
  5747. ;; Handle inheritance, when allowed. Include extended values and
  5748. ;; possibly global values.
  5749. (should
  5750. (equal
  5751. "1"
  5752. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:\n* H"
  5753. (org-entry-get (point-max) "A" t))))
  5754. (should
  5755. (equal
  5756. "1"
  5757. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5758. (org-entry-get (point-max) "A" t))))
  5759. (should
  5760. (equal
  5761. "1"
  5762. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5763. (let ((org-use-property-inheritance t))
  5764. (org-entry-get (point-max) "A" 'selective)))))
  5765. (should-not
  5766. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5767. (let ((org-use-property-inheritance nil))
  5768. (org-entry-get (point-max) "A" 'selective))))
  5769. (should-not
  5770. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H2"
  5771. (let ((org-use-property-inheritance t))
  5772. (org-entry-get (point-max) "A" t))))
  5773. (should
  5774. (equal
  5775. "1 2"
  5776. (org-test-with-temp-text
  5777. ":PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5778. (org-entry-get (point-max) "A" t))))
  5779. (should
  5780. (equal
  5781. "1 2"
  5782. (org-test-with-temp-text
  5783. "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5784. (org-entry-get (point-max) "A" t))))
  5785. (should
  5786. (equal
  5787. "1 2"
  5788. (org-test-with-temp-text
  5789. ":PROPERTIES:\n:A: 1\n:END:\n* H1\n* H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5790. (org-entry-get (point-max) "A" t))))
  5791. (should
  5792. (equal
  5793. "1 2"
  5794. (org-test-with-temp-text
  5795. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2.1\n** H2.2\n:PROPERTIES:\n:A+: 2\n:END:"
  5796. (org-entry-get (point-max) "A" t))))
  5797. (should
  5798. (equal "1"
  5799. (org-test-with-temp-text
  5800. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
  5801. (org-mode-restart)
  5802. (org-entry-get (point-max) "A" t))))
  5803. (should
  5804. (equal "0 1"
  5805. (org-test-with-temp-text
  5806. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
  5807. (org-mode-restart)
  5808. (org-entry-get (point-max) "A" t))))
  5809. ;; document level property-drawer has precedance over
  5810. ;; global-property by PROPERTY-keyword.
  5811. (should
  5812. (equal "0 2"
  5813. (org-test-with-temp-text
  5814. ":PROPERTIES:\n:A: 0\n:END:\n#+PROPERTY: A 1\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5815. (org-mode-restart)
  5816. (org-entry-get (point-max) "A" t)))))
  5817. (ert-deftest test-org/entry-properties ()
  5818. "Test `org-entry-properties' specifications."
  5819. ;; Get "ITEM" property.
  5820. (should
  5821. (equal "H"
  5822. (org-test-with-temp-text "* TODO H"
  5823. (cdr (assoc "ITEM" (org-entry-properties nil "ITEM"))))))
  5824. (should
  5825. (equal "H"
  5826. (org-test-with-temp-text "* TODO H"
  5827. (cdr (assoc "ITEM" (org-entry-properties))))))
  5828. ;; Get "TODO" property. TODO keywords are case sensitive.
  5829. (should
  5830. (equal "TODO"
  5831. (org-test-with-temp-text "* TODO H"
  5832. (cdr (assoc "TODO" (org-entry-properties nil "TODO"))))))
  5833. (should
  5834. (equal "TODO"
  5835. (org-test-with-temp-text "* TODO H"
  5836. (cdr (assoc "TODO" (org-entry-properties))))))
  5837. (should-not
  5838. (org-test-with-temp-text "* H"
  5839. (assoc "TODO" (org-entry-properties nil "TODO"))))
  5840. (should-not
  5841. (org-test-with-temp-text "* todo H"
  5842. (assoc "TODO" (org-entry-properties nil "TODO"))))
  5843. ;; Get "PRIORITY" property.
  5844. (should
  5845. (equal "A"
  5846. (org-test-with-temp-text "* [#A] H"
  5847. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  5848. (should
  5849. (equal "A"
  5850. (org-test-with-temp-text "* [#A] H"
  5851. (cdr (assoc "PRIORITY" (org-entry-properties))))))
  5852. (should
  5853. (equal (char-to-string org-priority-default)
  5854. (org-test-with-temp-text "* H"
  5855. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  5856. ;; Get "FILE" property.
  5857. (should
  5858. (org-test-with-temp-text-in-file "* H\nParagraph"
  5859. (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil "FILE")))
  5860. (buffer-file-name))))
  5861. (should
  5862. (org-test-with-temp-text-in-file "* H\nParagraph"
  5863. (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
  5864. (buffer-file-name))))
  5865. (should-not
  5866. (org-test-with-temp-text "* H\nParagraph"
  5867. (cdr (assoc "FILE" (org-entry-properties nil "FILE")))))
  5868. ;; Get "TAGS" property.
  5869. (should
  5870. (equal ":tag1:tag2:"
  5871. (org-test-with-temp-text "* H :tag1:tag2:"
  5872. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS"))))))
  5873. (should
  5874. (equal ":tag1:tag2:"
  5875. (org-test-with-temp-text "* H :tag1:tag2:"
  5876. (cdr (assoc "TAGS" (org-entry-properties))))))
  5877. (should-not
  5878. (org-test-with-temp-text "* H"
  5879. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS")))))
  5880. ;; Get "ALLTAGS" property.
  5881. (should
  5882. (equal ":tag1:tag2:"
  5883. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  5884. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS"))))))
  5885. (should
  5886. (equal ":tag1:tag2:"
  5887. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  5888. (cdr (assoc "ALLTAGS" (org-entry-properties))))))
  5889. (should-not
  5890. (org-test-with-temp-text "* H"
  5891. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS")))))
  5892. ;; Get "BLOCKED" property.
  5893. (should
  5894. (equal "t"
  5895. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  5896. (let ((org-enforce-todo-dependencies t)
  5897. (org-blocker-hook
  5898. '(org-block-todo-from-children-or-siblings-or-parent)))
  5899. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  5900. (should
  5901. (equal ""
  5902. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  5903. (let ((org-enforce-todo-dependencies t)
  5904. (org-blocker-hook
  5905. '(org-block-todo-from-children-or-siblings-or-parent)))
  5906. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  5907. ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
  5908. (should
  5909. (equal
  5910. "[2012-03-29 thu.]"
  5911. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  5912. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED"))))))
  5913. (should
  5914. (equal
  5915. "[2012-03-29 thu.]"
  5916. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  5917. (cdr (assoc "CLOSED" (org-entry-properties))))))
  5918. (should-not
  5919. (org-test-with-temp-text "* H"
  5920. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED")))))
  5921. (should
  5922. (equal
  5923. "<2014-03-04 tue.>"
  5924. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5925. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE"))))))
  5926. (should
  5927. (equal
  5928. "<2014-03-04 tue.>"
  5929. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5930. (cdr (assoc "DEADLINE" (org-entry-properties))))))
  5931. (should-not
  5932. (org-test-with-temp-text "* H"
  5933. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE")))))
  5934. (should
  5935. (equal
  5936. "<2014-03-04 tue.>"
  5937. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5938. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED"))))))
  5939. (should
  5940. (equal
  5941. "<2014-03-04 tue.>"
  5942. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5943. (cdr (assoc "SCHEDULED" (org-entry-properties))))))
  5944. (should-not
  5945. (org-test-with-temp-text "* H"
  5946. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED")))))
  5947. ;; Get "CATEGORY"
  5948. (should
  5949. (equal "cat"
  5950. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  5951. (cdr (assoc "CATEGORY" (org-entry-properties))))))
  5952. (should
  5953. (equal "cat"
  5954. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  5955. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5956. (should
  5957. (equal "cat"
  5958. (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
  5959. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5960. (should
  5961. (equal "cat2"
  5962. (org-test-with-temp-text
  5963. (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  5964. "\n"
  5965. "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
  5966. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5967. ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
  5968. (should
  5969. (equal "<2012-03-29 thu.>"
  5970. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
  5971. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  5972. (should
  5973. (equal "[2012-03-29 thu.]"
  5974. (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
  5975. (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
  5976. (should
  5977. (equal "<2012-03-29 thu.>"
  5978. (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
  5979. (cdr (assoc "TIMESTAMP" (org-entry-properties nil "TIMESTAMP"))))))
  5980. (should
  5981. (equal "[2014-03-04 tue.]"
  5982. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
  5983. (cdr (assoc "TIMESTAMP_IA"
  5984. (org-entry-properties nil "TIMESTAMP_IA"))))))
  5985. (should-not
  5986. (equal "<2012-03-29 thu.>"
  5987. (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
  5988. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  5989. ;; Get standard properties.
  5990. (should
  5991. (equal "1"
  5992. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5993. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5994. ;; Handle extended properties.
  5995. (should
  5996. (equal "1 2 3"
  5997. (org-test-with-temp-text
  5998. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5999. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  6000. (should
  6001. (equal "1 2 3"
  6002. (org-test-with-temp-text
  6003. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
  6004. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  6005. ;; Ignore forbidden (special) properties.
  6006. (should-not
  6007. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
  6008. (cdr (assoc "TODO" (org-entry-properties nil 'standard))))))
  6009. (ert-deftest test-org/entry-put ()
  6010. "Test `org-entry-put' specifications."
  6011. ;; Error when not a string or nil.
  6012. (should-error
  6013. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  6014. (org-entry-put 1 "test" 2)))
  6015. ;; Error when property name is invalid.
  6016. (should-error
  6017. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  6018. (org-entry-put 1 "no space" "value")))
  6019. (should-error
  6020. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  6021. (org-entry-put 1 "" "value")))
  6022. ;; Set "TODO" property.
  6023. (should
  6024. (string-match (regexp-quote " TODO H")
  6025. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  6026. (org-entry-put (point) "TODO" "TODO")
  6027. (buffer-string))))
  6028. (should
  6029. (string-match (regexp-quote "* H")
  6030. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  6031. (org-entry-put (point) "TODO" nil)
  6032. (buffer-string))))
  6033. ;; Set "PRIORITY" property.
  6034. (should
  6035. (equal "* [#A] H"
  6036. (org-test-with-temp-text "* [#B] H"
  6037. (org-entry-put (point) "PRIORITY" "A")
  6038. (buffer-string))))
  6039. (should
  6040. (equal "* H"
  6041. (org-test-with-temp-text "* [#B] H"
  6042. (org-entry-put (point) "PRIORITY" nil)
  6043. (buffer-string))))
  6044. ;; Set "SCHEDULED" property.
  6045. (should
  6046. (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
  6047. (org-test-with-temp-text "* H"
  6048. (org-entry-put (point) "SCHEDULED" "2014-03-04")
  6049. (buffer-string))))
  6050. (should
  6051. (string= "* H\n"
  6052. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6053. (org-entry-put (point) "SCHEDULED" nil)
  6054. (buffer-string))))
  6055. (should
  6056. (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
  6057. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6058. (org-entry-put (point) "SCHEDULED" "earlier")
  6059. (buffer-string))))
  6060. (should
  6061. (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
  6062. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6063. (org-entry-put (point) "SCHEDULED" "later")
  6064. (buffer-string))))
  6065. ;; Set "DEADLINE" property.
  6066. (should
  6067. (string-match "^ *DEADLINE: <2014-03-04 .*?>"
  6068. (org-test-with-temp-text "* H"
  6069. (org-entry-put (point) "DEADLINE" "2014-03-04")
  6070. (buffer-string))))
  6071. (should
  6072. (string= "* H\n"
  6073. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6074. (org-entry-put (point) "DEADLINE" nil)
  6075. (buffer-string))))
  6076. (should
  6077. (string-match "^ *DEADLINE: <2014-03-03 .*?>"
  6078. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6079. (org-entry-put (point) "DEADLINE" "earlier")
  6080. (buffer-string))))
  6081. (should
  6082. (string-match "^ *DEADLINE: <2014-03-05 .*?>"
  6083. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6084. (org-entry-put (point) "DEADLINE" "later")
  6085. (buffer-string))))
  6086. ;; Set "CATEGORY" property
  6087. (should
  6088. (string-match "^ *:CATEGORY: cat"
  6089. (org-test-with-temp-text "* H"
  6090. (org-entry-put (point) "CATEGORY" "cat")
  6091. (buffer-string))))
  6092. ;; Regular properties, with or without pre-existing drawer.
  6093. (should
  6094. (string-match "^ *:A: +2$"
  6095. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6096. (org-entry-put (point) "A" "2")
  6097. (buffer-string))))
  6098. (should
  6099. (string-match "^ *:A: +1$"
  6100. (org-test-with-temp-text "* H"
  6101. (org-entry-put (point) "A" "1")
  6102. (buffer-string))))
  6103. ;; Special case: two consecutive headlines.
  6104. (should
  6105. (string-match "\\* A\n *:PROPERTIES:"
  6106. (org-test-with-temp-text "* A\n** B"
  6107. (org-entry-put (point) "A" "1")
  6108. (buffer-string)))))
  6109. (ert-deftest test-org/refresh-properties ()
  6110. "Test `org-refresh-properties' specifications."
  6111. (should
  6112. (equal "1"
  6113. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6114. (org-refresh-properties "A" 'org-test)
  6115. (get-text-property (point) 'org-test))))
  6116. (should-not
  6117. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6118. (org-refresh-properties "B" 'org-test)
  6119. (get-text-property (point) 'org-test)))
  6120. ;; Handle properties only defined with extension syntax, i.e.,
  6121. ;; "PROPERTY+".
  6122. (should
  6123. (equal "1"
  6124. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
  6125. (org-refresh-properties "A" 'org-test)
  6126. (get-text-property (point) 'org-test))))
  6127. ;; When property is inherited, add text property to the whole
  6128. ;; sub-tree.
  6129. (should
  6130. (equal "1"
  6131. (org-test-with-temp-text
  6132. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
  6133. (let ((org-use-property-inheritance t))
  6134. (org-refresh-properties "A" 'org-test))
  6135. (get-text-property (point) 'org-test))))
  6136. ;; When a document level property-drawer is used, those properties
  6137. ;; should work exactly like headline-properties as if at a
  6138. ;; headline-level 0.
  6139. (should
  6140. (equal "1"
  6141. (org-test-with-temp-text
  6142. ":PROPERTIES:\n:A: 1\n:END:\n"
  6143. (org-mode-restart)
  6144. (let ((org-use-property-inheritance t))
  6145. (org-refresh-properties "A" 'org-test))
  6146. (get-text-property (point) 'org-test))))
  6147. (should-not
  6148. (equal "1"
  6149. (org-test-with-temp-text
  6150. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  6151. (org-mode-restart)
  6152. (let ((org-use-property-inheritance nil))
  6153. (org-refresh-properties "A" 'org-test))
  6154. (get-text-property (point) 'org-test))))
  6155. (should
  6156. (equal "1"
  6157. (org-test-with-temp-text
  6158. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  6159. (org-mode-restart)
  6160. (let ((org-use-property-inheritance t))
  6161. (org-refresh-properties "A" 'org-test))
  6162. (get-text-property (point) 'org-test))))
  6163. (should
  6164. (equal "2"
  6165. (org-test-with-temp-text
  6166. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1\n:PROPERTIES:\n:A: 2\n:END:"
  6167. (org-mode-restart)
  6168. (let ((org-use-property-inheritance t))
  6169. (org-refresh-properties "A" 'org-test))
  6170. (get-text-property (point) 'org-test))))
  6171. ;; When property is inherited, use global value across the whole
  6172. ;; buffer. However local values have precedence, as well as the
  6173. ;; document level property-drawer.
  6174. (should-not
  6175. (equal "1"
  6176. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  6177. (org-mode-restart)
  6178. (let ((org-use-property-inheritance nil))
  6179. (org-refresh-properties "A" 'org-test))
  6180. (get-text-property (point) 'org-test))))
  6181. (should
  6182. (equal "1"
  6183. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  6184. (org-mode-restart)
  6185. (let ((org-use-property-inheritance t))
  6186. (org-refresh-properties "A" 'org-test))
  6187. (get-text-property (point) 'org-test))))
  6188. (should
  6189. (equal "2"
  6190. (org-test-with-temp-text
  6191. "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
  6192. (org-mode-restart)
  6193. (let ((org-use-property-inheritance t))
  6194. (org-refresh-properties "A" 'org-test))
  6195. (get-text-property (point) 'org-test))))
  6196. ;; When both keyword-property and document-level property-block is
  6197. ;; defined, the property-block has precedance.
  6198. (should
  6199. (equal "1"
  6200. (org-test-with-temp-text
  6201. ":PROPERTIES:\n:A: 1\n:END:\n#+PROPERTY: A 2\n<point>* H1"
  6202. (org-mode-restart)
  6203. (let ((org-use-property-inheritance t))
  6204. (org-refresh-properties "A" 'org-test))
  6205. (get-text-property (point) 'org-test)))))
  6206. (ert-deftest test-org/refresh-category-properties ()
  6207. "Test `org-refresh-category-properties' specifications"
  6208. (should
  6209. (equal "cat1"
  6210. (org-test-with-temp-text
  6211. ":PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6212. (org-refresh-category-properties)
  6213. (org-get-category))))
  6214. (should
  6215. (equal "cat1"
  6216. (org-test-with-temp-text
  6217. "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6218. (org-refresh-category-properties)
  6219. (org-get-category))))
  6220. ;; Even though property-inheritance is deactivated, category
  6221. ;; property should be inherited. As described in
  6222. ;; `org-use-property-inheritance'.
  6223. (should
  6224. (equal "cat1"
  6225. (org-test-with-temp-text
  6226. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  6227. (org-mode-restart)
  6228. (let ((org-use-property-inheritance nil))
  6229. (org-refresh-category-properties))
  6230. (org-get-category))))
  6231. (should
  6232. (equal "cat1"
  6233. (org-test-with-temp-text
  6234. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  6235. (org-mode-restart)
  6236. (let ((org-use-property-inheritance t))
  6237. (org-refresh-category-properties))
  6238. (org-get-category))))
  6239. (should
  6240. (equal "cat2"
  6241. (org-test-with-temp-text
  6242. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H\n:PROPERTIES:\n:CATEGORY: cat2\n:END:\n"
  6243. (org-mode-restart)
  6244. (let ((org-use-property-inheritance t))
  6245. (org-refresh-category-properties))
  6246. (org-get-category)))))
  6247. ;;; Refile
  6248. (ert-deftest test-org/refile-get-targets ()
  6249. "Test `org-refile-get-targets' specifications."
  6250. ;; :maxlevel includes all headings above specified value.
  6251. (should
  6252. (equal '("H1" "H2" "H3")
  6253. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6254. (let ((org-refile-use-outline-path nil)
  6255. (org-refile-targets `((nil :maxlevel . 3))))
  6256. (mapcar #'car (org-refile-get-targets))))))
  6257. (should
  6258. (equal '("H1" "H2")
  6259. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6260. (let ((org-refile-use-outline-path nil)
  6261. (org-refile-targets `((nil :maxlevel . 2))))
  6262. (mapcar #'car (org-refile-get-targets))))))
  6263. ;; :level limits targets to headlines with the specified level.
  6264. (should
  6265. (equal '("H2")
  6266. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6267. (let ((org-refile-use-outline-path nil)
  6268. (org-refile-targets `((nil :level . 2))))
  6269. (mapcar #'car (org-refile-get-targets))))))
  6270. ;; :tag limits targets to headlines with specified tag.
  6271. (should
  6272. (equal '("H1")
  6273. (org-test-with-temp-text "* H1 :foo:\n** H2\n*** H3 :bar:"
  6274. (let ((org-refile-use-outline-path nil)
  6275. (org-refile-targets `((nil :tag . "foo"))))
  6276. (mapcar #'car (org-refile-get-targets))))))
  6277. ;; :todo limits targets to headlines with specified TODO keyword.
  6278. (should
  6279. (equal '("H2")
  6280. (org-test-with-temp-text "* H1\n** TODO H2\n*** DONE H3"
  6281. (let ((org-refile-use-outline-path nil)
  6282. (org-refile-targets `((nil :todo . "TODO"))))
  6283. (mapcar #'car (org-refile-get-targets))))))
  6284. ;; :regexp filters targets matching provided regexp.
  6285. (should
  6286. (equal '("F2" "F3")
  6287. (org-test-with-temp-text "* H1\n** F2\n*** F3"
  6288. (let ((org-refile-use-outline-path nil)
  6289. (org-refile-targets `((nil :regexp . "F"))))
  6290. (mapcar #'car (org-refile-get-targets))))))
  6291. ;; A nil `org-refile-targets' includes only top level headlines in
  6292. ;; current buffer.
  6293. (should
  6294. (equal '("H1" "H2")
  6295. (org-test-with-temp-text "* H1\n** S1\n* H2"
  6296. (let ((org-refile-use-outline-path nil)
  6297. (org-refile-targets nil))
  6298. (mapcar #'car (org-refile-get-targets))))))
  6299. ;; Return value is the union of the targets according to all the
  6300. ;; defined rules. However, prevent duplicates.
  6301. (should
  6302. (equal '("F2" "F3" "H1")
  6303. (org-test-with-temp-text "* TODO H1\n** F2\n*** F3"
  6304. (let ((org-refile-use-outline-path nil)
  6305. (org-refile-targets `((nil :regexp . "F")
  6306. (nil :todo . "TODO"))))
  6307. (mapcar #'car (org-refile-get-targets))))))
  6308. (should
  6309. (equal '("F2" "F3" "H1")
  6310. (org-test-with-temp-text "* TODO H1\n** TODO F2\n*** F3"
  6311. (let ((org-refile-use-outline-path nil)
  6312. (org-refile-targets `((nil :regexp . "F")
  6313. (nil :todo . "TODO"))))
  6314. (mapcar #'car (org-refile-get-targets))))))
  6315. ;; When `org-refile-use-outline-path' is non-nil, provide targets as
  6316. ;; paths.
  6317. (should
  6318. (equal '("H1" "H1/H2" "H1/H2/H3")
  6319. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6320. (let ((org-refile-use-outline-path t)
  6321. (org-refile-targets `((nil :maxlevel . 3))))
  6322. (mapcar #'car (org-refile-get-targets))))))
  6323. ;; When providing targets as paths, escape forward slashes in
  6324. ;; headings with backslashes.
  6325. (should
  6326. (equal '("H1\\/foo")
  6327. (org-test-with-temp-text "* H1/foo"
  6328. (let ((org-refile-use-outline-path t)
  6329. (org-refile-targets `((nil :maxlevel . 1))))
  6330. (mapcar #'car (org-refile-get-targets))))))
  6331. ;; When `org-refile-use-outline-path' is `file', include file name
  6332. ;; without directory in targets.
  6333. (should
  6334. (org-test-with-temp-text-in-file "* H1"
  6335. (let* ((filename (buffer-file-name))
  6336. (org-refile-use-outline-path 'file)
  6337. (org-refile-targets `(((,filename) :level . 1))))
  6338. (member (file-name-nondirectory filename)
  6339. (mapcar #'car (org-refile-get-targets))))))
  6340. ;; When `org-refile-use-outline-path' is `full-file-path', include
  6341. ;; full file name.
  6342. (should
  6343. (org-test-with-temp-text-in-file "* H1"
  6344. (let* ((filename (file-truename (buffer-file-name)))
  6345. (org-refile-use-outline-path 'full-file-path)
  6346. (org-refile-targets `(((,filename) :level . 1))))
  6347. (member filename (mapcar #'car (org-refile-get-targets))))))
  6348. ;; When `org-refile-use-outline-path' is `buffer-name', include
  6349. ;; buffer name.
  6350. (should
  6351. (org-test-with-temp-text "* H1"
  6352. (let* ((org-refile-use-outline-path 'buffer-name)
  6353. (org-refile-targets `((nil :level . 1))))
  6354. (member (buffer-name) (mapcar #'car (org-refile-get-targets)))))))
  6355. ;;; Sparse trees
  6356. (ert-deftest test-org/match-sparse-tree ()
  6357. "Test `org-match-sparse-tree' specifications."
  6358. ;; Match tags.
  6359. (should-not
  6360. (org-test-with-temp-text "* H\n** H1 :tag:"
  6361. (org-match-sparse-tree nil "tag")
  6362. (search-forward "H1")
  6363. (org-invisible-p2)))
  6364. (should
  6365. (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
  6366. (org-match-sparse-tree nil "tag")
  6367. (search-forward "H2")
  6368. (org-invisible-p2)))
  6369. ;; "-" operator for tags.
  6370. (should-not
  6371. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6372. (org-match-sparse-tree nil "tag1-tag2")
  6373. (search-forward "H1")
  6374. (org-invisible-p2)))
  6375. (should
  6376. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6377. (org-match-sparse-tree nil "tag1-tag2")
  6378. (search-forward "H2")
  6379. (org-invisible-p2)))
  6380. ;; "&" operator for tags.
  6381. (should
  6382. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6383. (org-match-sparse-tree nil "tag1&tag2")
  6384. (search-forward "H1")
  6385. (org-invisible-p2)))
  6386. (should-not
  6387. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6388. (org-match-sparse-tree nil "tag1&tag2")
  6389. (search-forward "H2")
  6390. (org-invisible-p2)))
  6391. ;; "|" operator for tags.
  6392. (should-not
  6393. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6394. (org-match-sparse-tree nil "tag1|tag2")
  6395. (search-forward "H1")
  6396. (org-invisible-p2)))
  6397. (should-not
  6398. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6399. (org-match-sparse-tree nil "tag1|tag2")
  6400. (search-forward "H2")
  6401. (org-invisible-p2)))
  6402. ;; Regexp match on tags.
  6403. (should-not
  6404. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6405. (org-match-sparse-tree nil "{^tag.*}")
  6406. (search-forward "H1")
  6407. (org-invisible-p2)))
  6408. (should
  6409. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6410. (org-match-sparse-tree nil "{^tag.*}")
  6411. (search-forward "H2")
  6412. (org-invisible-p2)))
  6413. ;; Match group tags.
  6414. (should-not
  6415. (org-test-with-temp-text
  6416. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6417. (org-match-sparse-tree nil "work")
  6418. (search-forward "H1")
  6419. (org-invisible-p2)))
  6420. (should-not
  6421. (org-test-with-temp-text
  6422. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6423. (org-match-sparse-tree nil "work")
  6424. (search-forward "H2")
  6425. (org-invisible-p2)))
  6426. ;; Match group tags with hard brackets.
  6427. (should-not
  6428. (org-test-with-temp-text
  6429. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6430. (org-match-sparse-tree nil "work")
  6431. (search-forward "H1")
  6432. (org-invisible-p2)))
  6433. (should-not
  6434. (org-test-with-temp-text
  6435. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6436. (org-match-sparse-tree nil "work")
  6437. (search-forward "H2")
  6438. (org-invisible-p2)))
  6439. ;; Match tags in hierarchies
  6440. (should-not
  6441. (org-test-with-temp-text
  6442. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6443. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6444. #+TAGS: { Lev_3 : Lev_4 }\n
  6445. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6446. (org-match-sparse-tree nil "Lev_1")
  6447. (search-forward "H4")
  6448. (org-invisible-p2)))
  6449. (should-not
  6450. (org-test-with-temp-text
  6451. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6452. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6453. #+TAGS: { Lev_3 : Lev_4 }\n
  6454. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6455. (org-match-sparse-tree nil "Lev_1+Lev_3")
  6456. (search-forward "H4")
  6457. (org-invisible-p2)))
  6458. ;; Match regular expressions in tags
  6459. (should-not
  6460. (org-test-with-temp-text
  6461. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
  6462. (org-match-sparse-tree nil "Lev")
  6463. (search-forward "H1")
  6464. (org-invisible-p2)))
  6465. (should
  6466. (org-test-with-temp-text
  6467. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
  6468. (org-match-sparse-tree nil "Lev")
  6469. (search-forward "H1")
  6470. (org-invisible-p2)))
  6471. ;; Match properties.
  6472. (should
  6473. (org-test-with-temp-text
  6474. "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
  6475. (org-match-sparse-tree nil "A=\"1\"")
  6476. (search-forward "H2")
  6477. (org-invisible-p2)))
  6478. (should-not
  6479. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6480. (org-match-sparse-tree nil "A=\"1\"")
  6481. (search-forward "H2")
  6482. (org-invisible-p2)))
  6483. ;; Case is not significant when matching properties.
  6484. (should-not
  6485. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6486. (org-match-sparse-tree nil "a=\"1\"")
  6487. (search-forward "H2")
  6488. (org-invisible-p2)))
  6489. (should-not
  6490. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
  6491. (org-match-sparse-tree nil "A=\"1\"")
  6492. (search-forward "H2")
  6493. (org-invisible-p2)))
  6494. ;; Match special LEVEL property.
  6495. (should-not
  6496. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6497. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6498. (search-forward "H1")
  6499. (org-invisible-p2)))
  6500. (should
  6501. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6502. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6503. (search-forward "H2")
  6504. (org-invisible-p2)))
  6505. ;; Comparison operators when matching properties.
  6506. (should
  6507. (org-test-with-temp-text
  6508. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6509. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6510. (search-forward "H1")
  6511. (org-invisible-p2)))
  6512. (should-not
  6513. (org-test-with-temp-text
  6514. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6515. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6516. (search-forward "H2")
  6517. (org-invisible-p2)))
  6518. ;; Regexp match on properties values.
  6519. (should-not
  6520. (org-test-with-temp-text
  6521. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6522. (org-match-sparse-tree nil "A={f.*}")
  6523. (search-forward "H1")
  6524. (org-invisible-p2)))
  6525. (should
  6526. (org-test-with-temp-text
  6527. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6528. (org-match-sparse-tree nil "A={f.*}")
  6529. (search-forward "H2")
  6530. (org-invisible-p2)))
  6531. ;; With an optional argument, limit match to TODO entries.
  6532. (should-not
  6533. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6534. (org-match-sparse-tree t "tag")
  6535. (search-forward "H1")
  6536. (org-invisible-p2)))
  6537. (should
  6538. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6539. (org-match-sparse-tree t "tag")
  6540. (search-forward "H2")
  6541. (org-invisible-p2))))
  6542. (ert-deftest test-org/occur ()
  6543. "Test `org-occur' specifications."
  6544. ;; Count number of matches.
  6545. (should
  6546. (= 1
  6547. (org-test-with-temp-text "* H\nA\n* H2"
  6548. (org-occur "A"))))
  6549. (should
  6550. (= 2
  6551. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6552. (org-occur "A"))))
  6553. ;; Test CALLBACK optional argument.
  6554. (should
  6555. (= 0
  6556. (org-test-with-temp-text "* H\nA\n* H2"
  6557. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6558. (should
  6559. (= 1
  6560. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6561. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6562. ;; Case-fold searches according to `org-occur-case-fold-search'.
  6563. (should
  6564. (= 2
  6565. (org-test-with-temp-text "Aa"
  6566. (let ((org-occur-case-fold-search t)) (org-occur "A")))))
  6567. (should
  6568. (= 2
  6569. (org-test-with-temp-text "Aa"
  6570. (let ((org-occur-case-fold-search t)) (org-occur "a")))))
  6571. (should
  6572. (= 1
  6573. (org-test-with-temp-text "Aa"
  6574. (let ((org-occur-case-fold-search nil)) (org-occur "A")))))
  6575. (should
  6576. (= 1
  6577. (org-test-with-temp-text "Aa"
  6578. (let ((org-occur-case-fold-search nil)) (org-occur "a")))))
  6579. (should
  6580. (= 1
  6581. (org-test-with-temp-text "Aa"
  6582. (let ((org-occur-case-fold-search 'smart)) (org-occur "A")))))
  6583. (should
  6584. (= 2
  6585. (org-test-with-temp-text "Aa"
  6586. (let ((org-occur-case-fold-search 'smart)) (org-occur "a"))))))
  6587. ;;; Tags
  6588. (ert-deftest test-org/tag-string-to-alist ()
  6589. "Test `org-tag-string-to-alist' specifications."
  6590. ;; Tag without selection key.
  6591. (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
  6592. ;; Tag with selection key.
  6593. (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t))))
  6594. ;; Tag group.
  6595. (should
  6596. (equal
  6597. (org-tag-string-to-alist "[ group : t1 t2 ]")
  6598. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag))))
  6599. ;; Mutually exclusive tags.
  6600. (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
  6601. '((:startgroup) ("tag1") ("tag2") (:endgroup))))
  6602. (should
  6603. (equal
  6604. (org-tag-string-to-alist "{ group : tag1 tag2 }")
  6605. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))))
  6606. (ert-deftest test-org/tag-alist-to-string ()
  6607. "Test `org-tag-alist-to-string' specifications."
  6608. (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
  6609. (should (equal (org-tag-alist-to-string '(("tag1" . ?t))) "tag1(t)"))
  6610. (should
  6611. (equal
  6612. (org-tag-alist-to-string
  6613. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6614. "[ group : t1 t2 ]"))
  6615. (should
  6616. (equal (org-tag-alist-to-string
  6617. '((:startgroup) ("tag1") ("tag2") (:endgroup)))
  6618. "{ tag1 tag2 }"))
  6619. (should
  6620. (equal
  6621. (org-tag-alist-to-string
  6622. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))
  6623. "{ group : tag1 tag2 }")))
  6624. (ert-deftest test-org/tag-alist-to-groups ()
  6625. "Test `org-tag-alist-to-groups' specifications."
  6626. (should
  6627. (equal (org-tag-alist-to-groups
  6628. '((:startgroup) ("group") (:grouptags) ("t1") ("t2") (:endgroup)))
  6629. '(("group" "t1" "t2"))))
  6630. (should
  6631. (equal
  6632. (org-tag-alist-to-groups
  6633. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6634. '(("group" "t1" "t2"))))
  6635. (should-not
  6636. (org-tag-alist-to-groups
  6637. '((:startgroup) ("group") ("t1") ("t2") (:endgroup)))))
  6638. (ert-deftest test-org/tag-align ()
  6639. "Test tags alignment."
  6640. ;; Test aligning tags with different display width.
  6641. (should
  6642. ;; 12345678901234567890
  6643. (equal "* Test :abc:"
  6644. (org-test-with-temp-text "* Test :abc:"
  6645. (let ((org-tags-column -20)
  6646. (indent-tabs-mode nil))
  6647. (org-fix-tags-on-the-fly))
  6648. (buffer-string))))
  6649. (should
  6650. ;; 12345678901234567890
  6651. (equal "* Test :日本語:"
  6652. (org-test-with-temp-text "* Test :日本語:"
  6653. (let ((org-tags-column -20)
  6654. (indent-tabs-mode nil))
  6655. (org-fix-tags-on-the-fly))
  6656. (buffer-string))))
  6657. ;; Make sure aligning tags do not skip invisible text.
  6658. (should
  6659. (equal "* [[linkx]] :tag:"
  6660. (org-test-with-temp-text "* [[link<point>]] :tag:"
  6661. (let ((org-tags-column 0))
  6662. (org-fix-tags-on-the-fly)
  6663. (insert "x")
  6664. (buffer-string)))))
  6665. ;; Aligning tags preserve position.
  6666. (should
  6667. (= 6 (org-test-with-temp-text "* 345 <point> :tag:"
  6668. (let ((org-tags-column 78)
  6669. (indent-tabs-mode nil))
  6670. (org-fix-tags-on-the-fly))
  6671. (current-column))))
  6672. ;; Aligning all tags in visible buffer.
  6673. (should
  6674. ;; 12345678901234567890
  6675. (equal (concat "* Level 1 :abc:\n"
  6676. "** Level 2 :def:")
  6677. (org-test-with-temp-text (concat "* Level 1 :abc:\n"
  6678. "** Level 2 :def:")
  6679. (let ((org-tags-column -20)
  6680. (indent-tabs-mode nil))
  6681. ;; (org-align-tags :all) must work even when the point
  6682. ;; is at the end of the buffer.
  6683. (goto-char (point-max))
  6684. (org-align-tags :all))
  6685. (buffer-string)))))
  6686. (ert-deftest test-org/get-tags ()
  6687. "Test `org-get-tags' specifications."
  6688. ;; Standard test.
  6689. (should
  6690. (equal '("foo")
  6691. (org-test-with-temp-text "* Test :foo:" (org-get-tags))))
  6692. (should
  6693. (equal '("foo" "bar")
  6694. (org-test-with-temp-text "* Test :foo:bar:" (org-get-tags))))
  6695. ;; Tags for inlinetasks.
  6696. (should
  6697. (equal '("foo" "bar")
  6698. (progn
  6699. (require 'org-inlinetask)
  6700. (org-test-with-temp-text (concat (make-string org-inlinetask-min-level ?*) " Test :foo:bar:")
  6701. (org-get-tags (org-element-at-point))))))
  6702. (should
  6703. (equal '("foo" "bar")
  6704. (progn
  6705. (require 'org-inlinetask)
  6706. (org-test-with-temp-text (concat (make-string org-inlinetask-min-level ?*) " Test :foo:bar:")
  6707. (org-get-tags nil)))))
  6708. ;; Return nil when there is no tag.
  6709. (should-not
  6710. (org-test-with-temp-text "* Test" (org-get-tags)))
  6711. ;; Tags are inherited from parent headlines.
  6712. (should
  6713. (equal '("tag")
  6714. (let ((org-use-tag-inheritance t))
  6715. (org-test-with-temp-text "* H0 :foo:\n* H1 :tag:\n<point>** H2"
  6716. (org-get-tags)))))
  6717. ;; Tags are inherited from `org-file-tags'.
  6718. (should
  6719. (equal '("tag")
  6720. (org-test-with-temp-text "* H1"
  6721. (let ((org-file-tags '("tag"))
  6722. (org-use-tag-inheritance t))
  6723. (org-get-tags)))))
  6724. ;; Only inherited tags have the `inherited' text property.
  6725. (should
  6726. (get-text-property 0 'inherited
  6727. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6728. (let ((org-use-tag-inheritance t))
  6729. (assoc-string "foo" (org-get-tags))))))
  6730. (should-not
  6731. (get-text-property 0 'inherited
  6732. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6733. (let ((org-use-tag-inheritance t))
  6734. (assoc-string "bar" (org-get-tags))))))
  6735. ;; Obey to `org-use-tag-inheritance'.
  6736. (should-not
  6737. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6738. (let ((org-use-tag-inheritance nil))
  6739. (assoc-string "foo" (org-get-tags)))))
  6740. (should-not
  6741. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6742. (let ((org-use-tag-inheritance nil)
  6743. (org-file-tags '("foo")))
  6744. (assoc-string "foo" (org-get-tags)))))
  6745. (should-not
  6746. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6747. (let ((org-use-tag-inheritance '("bar")))
  6748. (assoc-string "foo" (org-get-tags)))))
  6749. (should
  6750. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6751. (let ((org-use-tag-inheritance '("bar")))
  6752. (assoc-string "bar" (org-get-tags)))))
  6753. (should-not
  6754. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6755. (let ((org-use-tag-inheritance "b.*"))
  6756. (assoc-string "foo" (org-get-tags)))))
  6757. (should
  6758. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6759. (let ((org-use-tag-inheritance "b.*"))
  6760. (assoc-string "bar" (org-get-tags)))))
  6761. ;; When optional argument LOCAL is non-nil, ignore tag inheritance.
  6762. (should
  6763. (equal '("baz")
  6764. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6765. (let ((org-use-tag-inheritance t))
  6766. (org-get-tags nil t)))))
  6767. ;; When optional argument POS is non-nil, get tags there instead.
  6768. (should
  6769. (equal '("foo")
  6770. (org-test-with-temp-text "* H1 :foo:\n* <point>H2 :bar:"
  6771. (org-get-tags 1))))
  6772. ;; Make sure tags excluded from inheritance are returned if local
  6773. (should
  6774. (equal '("foo")
  6775. (org-test-with-temp-text "* Test :foo:"
  6776. (let ((org-use-tag-inheritance t)
  6777. (org-tags-exclude-from-inheritance '("foo")))
  6778. (org-get-tags)))))
  6779. ;; Test the collection of tags from #+filetags and parent tags.
  6780. (should
  6781. (equal '("a" "b" "c" "d")
  6782. (org-test-with-temp-text (concat "#+filetags: a\n"
  6783. "* Level 1 :b:\n"
  6784. "** Level 2 :c:\n"
  6785. "*** Level 3 :d:\n"
  6786. "<point>")
  6787. (let ((org-use-tag-inheritance t))
  6788. (org-mode-restart) ;So that `org-file-tags' get populated from #+filetags
  6789. (org-get-tags)))))
  6790. ;; Pathological case: tagged headline with an empty body.
  6791. (should (org-test-with-temp-text "* :tag:" (org-get-tags))))
  6792. (ert-deftest test-org/set-tags ()
  6793. "Test `org-set-tags' specifications."
  6794. ;; Throw an error on invalid data.
  6795. (should-error
  6796. (org-test-with-temp-text "* H"
  6797. (org-set-tags 'foo)))
  6798. ;; `nil', an empty, and a blank string remove all tags.
  6799. (should
  6800. (equal "* H"
  6801. (org-test-with-temp-text "* H :tag1:tag2:"
  6802. (org-set-tags nil)
  6803. (buffer-string))))
  6804. (should
  6805. (equal "* H"
  6806. (org-test-with-temp-text "* H :tag1:tag2:"
  6807. (org-set-tags "")
  6808. (buffer-string))))
  6809. (should
  6810. (equal "* H"
  6811. (org-test-with-temp-text "* H :tag1:tag2:"
  6812. (org-set-tags " ")
  6813. (buffer-string))))
  6814. ;; If there's nothing to remove, just bail out.
  6815. (should
  6816. (equal "* H"
  6817. (org-test-with-temp-text "* H"
  6818. (org-set-tags nil)
  6819. (buffer-string))))
  6820. (should
  6821. (equal "* "
  6822. (org-test-with-temp-text "* "
  6823. (org-set-tags nil)
  6824. (buffer-string))))
  6825. ;; If DATA is a tag string, set current tags to it, even if it means
  6826. ;; replacing old tags.
  6827. (should
  6828. (equal "* H :tag0:"
  6829. (org-test-with-temp-text "* H :tag1:tag2:"
  6830. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  6831. (buffer-string))))
  6832. (should
  6833. (equal "* H :tag0:"
  6834. (org-test-with-temp-text "* H"
  6835. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  6836. (buffer-string))))
  6837. ;; If DATA is a list, set tags to this list, even if it means
  6838. ;; replacing old tags.
  6839. (should
  6840. (equal "* H :tag0:"
  6841. (org-test-with-temp-text "* H :tag1:tag2:"
  6842. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6843. (buffer-string))))
  6844. (should
  6845. (equal "* H :tag0:"
  6846. (org-test-with-temp-text "* H"
  6847. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6848. (buffer-string))))
  6849. ;; When set, apply `org-tags-sort-function'.
  6850. (should
  6851. (equal "* H :a:b:"
  6852. (org-test-with-temp-text "* H"
  6853. (let ((org-tags-column 1)
  6854. (org-tags-sort-function #'string<))
  6855. (org-set-tags '("b" "a"))
  6856. (buffer-string)))))
  6857. ;; When new tags are identical to the previous ones, still align.
  6858. (should
  6859. (equal "* H :foo:"
  6860. (org-test-with-temp-text "* H :foo:"
  6861. (let ((org-tags-column 1))
  6862. (org-set-tags '("foo"))
  6863. (buffer-string)))))
  6864. ;; When tags have been changed, run `org-after-tags-change-hook'.
  6865. (should
  6866. (catch :return
  6867. (org-test-with-temp-text "* H :foo:"
  6868. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  6869. (org-set-tags '("bar"))
  6870. nil))))
  6871. (should-not
  6872. (catch :return
  6873. (org-test-with-temp-text "* H :foo:"
  6874. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  6875. (org-set-tags '("foo"))
  6876. nil))))
  6877. ;; Special case: handle empty headlines.
  6878. (should
  6879. (equal "* :tag0:"
  6880. (org-test-with-temp-text "* "
  6881. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6882. (buffer-string))))
  6883. ;; Modify buffer only when a tag change happens or alignment is
  6884. ;; done.
  6885. (should-not
  6886. (org-test-with-temp-text "* H :foo:"
  6887. (set-buffer-modified-p nil)
  6888. (let ((org-tags-column 1)) (org-set-tags '("foo")))
  6889. (buffer-modified-p)))
  6890. (should
  6891. (org-test-with-temp-text "* H :foo:"
  6892. (set-buffer-modified-p nil)
  6893. (let ((org-tags-column 10)) (org-set-tags '("foo")))
  6894. (buffer-modified-p)))
  6895. (should
  6896. (org-test-with-temp-text "* H :foo:"
  6897. (set-buffer-modified-p nil)
  6898. (let ((org-tags-column 10)) (org-set-tags '("bar")))
  6899. (buffer-modified-p)))
  6900. ;; Pathological case: when setting tags of a folded headline, do not
  6901. ;; let new tags being sucked into invisibility.
  6902. (should-not
  6903. (org-test-with-temp-text "* H1\nContent\n* H2\n\n Other Content"
  6904. ;; Show only headlines
  6905. (org-content)
  6906. ;; Set NEXT tag on current entry
  6907. (org-set-tags ":NEXT:")
  6908. ;; Move point to that NEXT tag
  6909. (search-forward "NEXT") (backward-word)
  6910. ;; And it should be visible (i.e. no overlays)
  6911. (overlays-at (point)))))
  6912. (ert-deftest test-org/set-tags-command ()
  6913. "Test `org-set-tags-command' specifications"
  6914. ;; Set tags at current headline.
  6915. (should
  6916. (equal "* H1 :foo:"
  6917. (org-test-with-temp-text "* H1"
  6918. (cl-letf (((symbol-function 'completing-read-multiple)
  6919. (lambda (&rest args) '("foo"))))
  6920. (let ((org-use-fast-tag-selection nil)
  6921. (org-tags-column 1))
  6922. (org-set-tags-command)))
  6923. (buffer-string))))
  6924. ;; Preserve position when called from the section below.
  6925. (should
  6926. (equal "* H1 :foo:\nContents"
  6927. (org-test-with-temp-text "* H1\n<point>Contents"
  6928. (cl-letf (((symbol-function 'completing-read-multiple)
  6929. (lambda (&rest args) '("foo"))))
  6930. (let ((org-use-fast-tag-selection nil)
  6931. (org-tags-column 1))
  6932. (org-set-tags-command)))
  6933. (buffer-string))))
  6934. (should-not
  6935. (equal "* H1 :foo:\nContents2"
  6936. (org-test-with-temp-text "* H1\n<point>Contents2"
  6937. (cl-letf (((symbol-function 'completing-read-multiple)
  6938. (lambda (&rest args) '("foo"))))
  6939. (let ((org-use-fast-tag-selection nil)
  6940. (org-tags-column 1))
  6941. (org-set-tags-command)))
  6942. (org-at-heading-p))))
  6943. ;; When a region is active and
  6944. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  6945. ;; same value in all headlines in region.
  6946. (should
  6947. (equal "* H1 :foo:\nContents\n* H2 :foo:"
  6948. (org-test-with-temp-text "* H1\nContents\n* H2"
  6949. (cl-letf (((symbol-function 'completing-read-multiple)
  6950. (lambda (&rest args) '("foo"))))
  6951. (let ((org-use-fast-tag-selection nil)
  6952. (org-loop-over-headlines-in-active-region t)
  6953. (org-tags-column 1))
  6954. (transient-mark-mode 1)
  6955. (push-mark (point) t t)
  6956. (goto-char (point-max))
  6957. (org-set-tags-command)))
  6958. (buffer-string))))
  6959. (should
  6960. (equal "* H1\nContents\n* H2 :foo:"
  6961. (org-test-with-temp-text "* H1\nContents\n* H2"
  6962. (cl-letf (((symbol-function 'completing-read-multiple)
  6963. (lambda (&rest args) '("foo"))))
  6964. (let ((org-use-fast-tag-selection nil)
  6965. (org-loop-over-headlines-in-active-region nil)
  6966. (org-tags-column 1))
  6967. (transient-mark-mode 1)
  6968. (push-mark (point) t t)
  6969. (goto-char (point-max))
  6970. (org-set-tags-command)))
  6971. (buffer-string))))
  6972. ;; With a C-u prefix argument, align all tags in the buffer.
  6973. (should
  6974. (equal "* H1 :foo:\n* H2 :bar:"
  6975. (org-test-with-temp-text "* H1 :foo:\n* H2 :bar:"
  6976. (let ((org-tags-column 1)) (org-set-tags-command '(4)))
  6977. (buffer-string))))
  6978. ;; Point does not move with empty headline.
  6979. (should
  6980. (equal ":foo:"
  6981. (org-test-with-temp-text "* <point>"
  6982. (cl-letf (((symbol-function 'completing-read-multiple)
  6983. (lambda (&rest args) '("foo"))))
  6984. (let ((org-use-fast-tag-selection nil)
  6985. (org-tags-column 1))
  6986. (org-set-tags-command)))
  6987. (buffer-substring (point) (line-end-position)))))
  6988. ;; Point does not move at start of line.
  6989. (should
  6990. (equal "* H1 :foo:"
  6991. (org-test-with-temp-text "* H1"
  6992. (cl-letf (((symbol-function 'completing-read-multiple)
  6993. (lambda (&rest args) '("foo"))))
  6994. (let ((org-use-fast-tag-selection nil)
  6995. (org-tags-column 1))
  6996. (org-set-tags-command)))
  6997. (buffer-substring (point) (line-end-position)))))
  6998. ;; Point does not move when within *'s.
  6999. (should
  7000. (equal "* H1 :foo:"
  7001. (org-test-with-temp-text "*<point>* H1"
  7002. (cl-letf (((symbol-function 'completing-read-multiple)
  7003. (lambda (&rest args) '("foo"))))
  7004. (let ((org-use-fast-tag-selection nil)
  7005. (org-tags-column 1))
  7006. (org-set-tags-command)))
  7007. (buffer-substring (point) (line-end-position)))))
  7008. ;; Point workaround does not get fooled when looking at a space.
  7009. (should
  7010. (equal " b :foo:"
  7011. (org-test-with-temp-text "* a<point> b"
  7012. (cl-letf (((symbol-function 'completing-read-multiple)
  7013. (lambda (&rest args) '("foo"))))
  7014. (let ((org-use-fast-tag-selection nil)
  7015. (org-tags-column 1))
  7016. (org-set-tags-command)))
  7017. (buffer-substring (point) (line-end-position)))))
  7018. ;; Handle tags both set locally and inherited.
  7019. (should
  7020. (equal "b :foo:"
  7021. (org-test-with-temp-text "* a :foo:\n** <point>b :foo:"
  7022. (cl-letf (((symbol-function 'completing-read-multiple)
  7023. (lambda (prompt coll &optional pred req initial &rest args)
  7024. (list initial))))
  7025. (let ((org-use-fast-tag-selection nil)
  7026. (org-tags-column 1))
  7027. (org-set-tags-command)))
  7028. (buffer-substring (point) (line-end-position))))))
  7029. (ert-deftest test-org/toggle-tag ()
  7030. "Test `org-toggle-tag' specifications."
  7031. ;; Insert missing tag.
  7032. (should
  7033. (equal "* H :tag:"
  7034. (org-test-with-temp-text "* H"
  7035. (let ((org-tags-column 1)) (org-toggle-tag "tag"))
  7036. (buffer-string))))
  7037. (should
  7038. (equal "* H :tag1:tag2:"
  7039. (org-test-with-temp-text "* H :tag1:"
  7040. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  7041. (buffer-string))))
  7042. ;; Remove existing tag.
  7043. (should
  7044. (equal "* H"
  7045. (org-test-with-temp-text "* H :tag:"
  7046. (org-toggle-tag "tag")
  7047. (buffer-string))))
  7048. (should
  7049. (equal "* H :tag1:"
  7050. (org-test-with-temp-text "* H :tag1:tag2:"
  7051. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  7052. (buffer-string))))
  7053. (should
  7054. (equal "* H :tag2:"
  7055. (org-test-with-temp-text "* H :tag1:tag2:"
  7056. (let ((org-tags-column 1)) (org-toggle-tag "tag1"))
  7057. (buffer-string))))
  7058. ;; With optional argument ONOFF set to `on', try to insert the tag,
  7059. ;; even if its already there.
  7060. (should
  7061. (equal "* H :tag:"
  7062. (org-test-with-temp-text "* H"
  7063. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  7064. (buffer-string))))
  7065. (should
  7066. (equal "* H :tag:"
  7067. (org-test-with-temp-text "* H :tag:"
  7068. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  7069. (buffer-string))))
  7070. ;; With optional argument ONOFF set to `off', try to remove the tag,
  7071. ;; even if its not there.
  7072. (should
  7073. (equal "* H"
  7074. (org-test-with-temp-text "* H :tag:"
  7075. (org-toggle-tag "tag" 'off)
  7076. (buffer-string))))
  7077. (should
  7078. (equal "* H :tag:"
  7079. (org-test-with-temp-text "* H :tag:"
  7080. (let ((org-tags-column 1)) (org-toggle-tag "foo" 'off))
  7081. (buffer-string))))
  7082. ;; Special case: Handle properly tag inheritance. In particular, do
  7083. ;; not set inherited tags.
  7084. (should
  7085. (equal "* H1 :tag:\n** H2 :tag2:tag:"
  7086. (org-test-with-temp-text "* H1 :tag:\n** <point>H2 :tag2:"
  7087. (let ((org-use-tag-inheritance t)
  7088. (org-tags-column 1))
  7089. (org-toggle-tag "tag"))
  7090. (buffer-string))))
  7091. (should
  7092. (equal "* H1 :tag1:tag2:\n** H2 :foo:"
  7093. (org-test-with-temp-text "* H1 :tag1:tag2:\n** <point>H2"
  7094. (let ((org-use-tag-inheritance t)
  7095. (org-tags-column 1))
  7096. (org-toggle-tag "foo"))
  7097. (buffer-string)))))
  7098. (ert-deftest test-org/tags-expand ()
  7099. "Test `org-tags-expand' specifications."
  7100. ;; Expand tag groups as a regexp enclosed within curly brackets.
  7101. (should
  7102. (equal "{\\<[ABC]\\>}"
  7103. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7104. (org-mode-restart)
  7105. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  7106. (should
  7107. (equal "{\\<\\(?:Aa\\|Bb\\|Cc\\)\\>}"
  7108. (org-test-with-temp-text "#+TAGS: [ Aa : Bb Cc ]"
  7109. (org-mode-restart)
  7110. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "Aa")))))
  7111. ;; Preserve operator before the regexp.
  7112. (should
  7113. (equal "+{\\<[ABC]\\>}"
  7114. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7115. (org-mode-restart)
  7116. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "+A")))))
  7117. (should
  7118. (equal "-{\\<[ABC]\\>}"
  7119. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7120. (org-mode-restart)
  7121. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "-A")))))
  7122. ;; Handle "|" syntax.
  7123. (should
  7124. (equal "{\\<[ABC]\\>}|D"
  7125. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7126. (org-mode-restart)
  7127. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|D")))))
  7128. ;; Handle nested groups.
  7129. (should
  7130. (equal "{\\<[A-D]\\>}"
  7131. (org-test-with-temp-text "#+TAGS: [ A : B C ]\n#+TAGS: [ B : D ]"
  7132. (org-mode-restart)
  7133. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  7134. ;; Expand multiple occurrences of the same group.
  7135. (should
  7136. (equal "{\\<[ABC]\\>}|{\\<[ABC]\\>}"
  7137. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7138. (org-mode-restart)
  7139. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|A")))))
  7140. ;; Preserve regexp matches.
  7141. (should
  7142. (equal "{A+}"
  7143. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7144. (org-mode-restart)
  7145. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "{A+}"))))))
  7146. ;;; TODO keywords
  7147. (ert-deftest test-org/auto-repeat-maybe ()
  7148. "Test `org-auto-repeat-maybe' specifications."
  7149. ;; Do not auto repeat when there is no valid time stamp with
  7150. ;; a repeater in the entry.
  7151. (should-not
  7152. (string-prefix-p
  7153. "* TODO H"
  7154. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7155. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
  7156. (org-todo "DONE")
  7157. (buffer-string)))))
  7158. (should-not
  7159. (string-prefix-p
  7160. "* TODO H"
  7161. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7162. (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
  7163. (org-todo "DONE")
  7164. (buffer-string)))))
  7165. ;; When switching to DONE state, switch back to first TODO keyword
  7166. ;; in sequence, or the same keyword if they have different types.
  7167. (should
  7168. (string-prefix-p
  7169. "* TODO H"
  7170. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7171. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7172. (org-todo "DONE")
  7173. (buffer-string)))))
  7174. (should
  7175. (string-prefix-p
  7176. "* KWD1 H"
  7177. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  7178. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  7179. (org-todo "DONE")
  7180. (buffer-string)))))
  7181. (should
  7182. (string-prefix-p
  7183. "* KWD2 H"
  7184. (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
  7185. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  7186. (org-todo "DONE")
  7187. (buffer-string)))))
  7188. ;; If there was no TODO keyword in the first place, do not insert
  7189. ;; any either.
  7190. (should
  7191. (string-prefix-p
  7192. "* H"
  7193. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7194. (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
  7195. (org-todo "DONE")
  7196. (buffer-string)))))
  7197. ;; Revert to REPEAT_TO_STATE, if set.
  7198. (should
  7199. (string-prefix-p
  7200. "* KWD2 H"
  7201. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  7202. (org-test-with-temp-text
  7203. "* KWD2 H
  7204. :PROPERTIES:
  7205. :REPEAT_TO_STATE: KWD2
  7206. :END:
  7207. <2012-03-29 Thu +2y>"
  7208. (org-todo "DONE")
  7209. (buffer-string)))))
  7210. ;; When switching to DONE state, update base date. If there are
  7211. ;; multiple repeated time stamps, update them all.
  7212. (should
  7213. (string-match-p
  7214. "<2014-03-29 .* \\+2y>"
  7215. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7216. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7217. (org-todo "DONE")
  7218. (buffer-string)))))
  7219. (should
  7220. (string-match-p
  7221. "<2015-03-04 .* \\+1y>"
  7222. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7223. (org-test-with-temp-text
  7224. "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
  7225. (org-todo "DONE")
  7226. (buffer-string)))))
  7227. ;; Throw an error if repeater unit is the hour and no time is
  7228. ;; provided in the time-stamp.
  7229. (should-error
  7230. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7231. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
  7232. (org-todo "DONE")
  7233. (buffer-string))))
  7234. ;; Handle every repeater type using hours step.
  7235. (should
  7236. (string-match-p
  7237. "2014-03-04 .* 02:00"
  7238. (org-test-at-time "<2014-03-04 02:35>"
  7239. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 +8h>"
  7240. (org-todo "DONE")
  7241. (buffer-string)))))
  7242. (should
  7243. (string-match-p
  7244. "2014-03-04 .* 10:00"
  7245. (org-test-at-time "<2014-03-04 02:35>"
  7246. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 ++8h>"
  7247. (org-todo "DONE")
  7248. (buffer-string)))))
  7249. (should
  7250. (string-match-p
  7251. "2014-03-04 .* 10:35"
  7252. (org-test-at-time "<2014-03-04 02:35>"
  7253. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 .+8h>"
  7254. (org-todo "DONE")
  7255. (buffer-string)))))
  7256. ;; Do not repeat inactive time stamps with a repeater.
  7257. (should-not
  7258. (string-match-p
  7259. "\\[2014-03-29 .* \\+2y\\]"
  7260. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7261. (org-test-with-temp-text
  7262. "* TODO H\n[2012-03-29 Thu. +2y]"
  7263. (org-todo "DONE")
  7264. (buffer-string)))))
  7265. ;; Do not repeat commented time stamps.
  7266. (should-not
  7267. (string-prefix-p
  7268. "<2015-03-04 .* \\+1y>"
  7269. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7270. (org-test-with-temp-text
  7271. "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
  7272. (org-todo "DONE")
  7273. (buffer-string)))))
  7274. (should-not
  7275. (string-prefix-p
  7276. "<2015-03-04 .* \\+1y>"
  7277. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7278. (org-test-with-temp-text
  7279. "* TODO H
  7280. <2012-03-29 Thu. +2y>
  7281. #+BEGIN_EXAMPLE
  7282. <2014-03-04 Tue +1y>
  7283. #+END_EXAMPLE"
  7284. (org-todo "DONE")
  7285. (buffer-string)))))
  7286. ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
  7287. ;; entry, record time of last repeat.
  7288. (should-not
  7289. (string-match-p
  7290. ":LAST_REPEAT:"
  7291. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  7292. (org-log-repeat nil))
  7293. (cl-letf (((symbol-function 'org-add-log-setup)
  7294. (lambda (&rest args) nil)))
  7295. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  7296. (org-todo "DONE")
  7297. (buffer-string))))))
  7298. (should
  7299. (string-match-p
  7300. ":LAST_REPEAT:"
  7301. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  7302. (org-log-repeat t))
  7303. (cl-letf (((symbol-function 'org-add-log-setup)
  7304. (lambda (&rest args) nil)))
  7305. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  7306. (org-todo "DONE")
  7307. (buffer-string))))))
  7308. (should
  7309. (string-match-p
  7310. ":LAST_REPEAT:"
  7311. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7312. (cl-letf (((symbol-function 'org-add-log-setup)
  7313. (lambda (&rest args) nil)))
  7314. (org-test-with-temp-text
  7315. "* TODO H\n<2012-03-29 Thu +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
  7316. (org-todo "DONE")
  7317. (buffer-string))))))
  7318. ;; When a SCHEDULED entry has no repeater, remove it upon repeating
  7319. ;; the entry as it is no longer relevant.
  7320. (should-not
  7321. (string-match-p
  7322. "^SCHEDULED:"
  7323. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7324. (org-test-with-temp-text
  7325. "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
  7326. (org-todo "DONE")
  7327. (buffer-string)))))
  7328. ;; Properly advance repeater even when a clock entry is specified
  7329. ;; and `org-log-repeat' is nil.
  7330. (should
  7331. (string-match-p
  7332. "SCHEDULED: <2014-03-29"
  7333. (let ((org-log-repeat nil)
  7334. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7335. (org-test-with-temp-text
  7336. "* TODO H
  7337. SCHEDULED: <2012-03-29 Thu +2y>
  7338. CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] => 6:40"
  7339. (org-todo "DONE")
  7340. (buffer-string)))))
  7341. ;; Make sure that logbook state change record does not get
  7342. ;; duplicated when `org-log-repeat' `org-log-done' are non-nil.
  7343. (should
  7344. (string-match-p
  7345. (rx "* TODO Read book
  7346. SCHEDULED: <2021-06-16 " (1+ (not space)) " +1d>
  7347. :PROPERTIES:
  7348. :LAST_REPEAT:" (1+ nonl) "
  7349. :END:
  7350. - State \"DONE\" from \"TODO\"" (1+ nonl) buffer-end)
  7351. (let ((org-log-repeat 'time)
  7352. (org-todo-keywords '((sequence "TODO" "|" "DONE(d!)")))
  7353. (org-log-into-drawer nil))
  7354. (org-test-with-temp-text
  7355. "* TODO Read book
  7356. SCHEDULED: <2021-06-15 Tue +1d>"
  7357. (org-todo "DONE")
  7358. (when (memq 'org-add-log-note post-command-hook)
  7359. (org-add-log-note))
  7360. (buffer-string))))))
  7361. (ert-deftest test-org/org-log-done ()
  7362. "Test `org-log-done' specifications."
  7363. ;; nil value.
  7364. (should
  7365. (string=
  7366. "* DONE task"
  7367. (let ((org-log-done nil)
  7368. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7369. (org-test-with-temp-text
  7370. "* TODO task"
  7371. (org-todo "DONE")
  7372. (when (memq 'org-add-log-note post-command-hook)
  7373. (org-add-log-note))
  7374. (buffer-string)))))
  7375. ;; `time' value.
  7376. (should
  7377. (string=
  7378. (format
  7379. "* DONE task
  7380. CLOSED: %s"
  7381. (org-test-with-temp-text ""
  7382. (org-insert-time-stamp (current-time) t t)
  7383. (buffer-string)))
  7384. (let ((org-log-done 'time)
  7385. (org-log-done-with-time t)
  7386. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7387. (org-test-with-temp-text
  7388. "* TODO task"
  7389. (org-todo "DONE")
  7390. (when (memq 'org-add-log-note post-command-hook)
  7391. (org-add-log-note))
  7392. (buffer-string)))))
  7393. (should
  7394. (string=
  7395. (format
  7396. "* DONE task
  7397. CLOSED: %s"
  7398. (org-test-with-temp-text ""
  7399. (org-insert-time-stamp (current-time) nil t)
  7400. (buffer-string)))
  7401. (let ((org-log-done 'time)
  7402. (org-log-done-with-time nil)
  7403. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7404. (org-test-with-temp-text
  7405. "* TODO task"
  7406. (org-todo "DONE")
  7407. (when (memq 'org-add-log-note post-command-hook)
  7408. (org-add-log-note))
  7409. (buffer-string)))))
  7410. ;; TODO: Test `note' value.
  7411. ;; Test startup overrides.
  7412. (should
  7413. (string=
  7414. "#+STARTUP: nologdone
  7415. * DONE task"
  7416. (let ((org-log-done 'time)
  7417. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7418. (org-test-with-temp-text
  7419. "#+STARTUP: nologdone
  7420. <point>* TODO task"
  7421. (org-set-regexps-and-options)
  7422. (org-todo "DONE")
  7423. (when (memq 'org-add-log-note post-command-hook)
  7424. (org-add-log-note))
  7425. (buffer-string)))))
  7426. (should
  7427. (string=
  7428. (format
  7429. "#+STARTUP: logdone
  7430. * DONE task
  7431. CLOSED: %s"
  7432. (org-test-with-temp-text ""
  7433. (org-insert-time-stamp (current-time) t t)
  7434. (buffer-string)))
  7435. (let ((org-log-done nil)
  7436. (org-log-done-with-time t)
  7437. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7438. (org-test-with-temp-text
  7439. "#+STARTUP: logdone
  7440. <point>* TODO task"
  7441. (org-set-regexps-and-options)
  7442. (org-todo "DONE")
  7443. (when (memq 'org-add-log-note post-command-hook)
  7444. (org-add-log-note))
  7445. (buffer-string)))))
  7446. ;; Test local property overrides.
  7447. (should
  7448. (string=
  7449. "* DONE task
  7450. :PROPERTIES:
  7451. :LOGGING: nil
  7452. :END:"
  7453. (let ((org-log-done 'time)
  7454. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7455. (org-test-with-temp-text
  7456. "* TODO task
  7457. :PROPERTIES:
  7458. :LOGGING: nil
  7459. :END:"
  7460. (org-todo "DONE")
  7461. (when (memq 'org-add-log-note post-command-hook)
  7462. (org-add-log-note))
  7463. (buffer-string)))))
  7464. (should
  7465. (string=
  7466. (format
  7467. "* DONE task
  7468. CLOSED: %s
  7469. :PROPERTIES:
  7470. :LOGGING: logdone
  7471. :END:"
  7472. (org-test-with-temp-text ""
  7473. (org-insert-time-stamp (current-time) t t)
  7474. (buffer-string)))
  7475. (let ((org-log-done nil)
  7476. (org-log-done-with-time t)
  7477. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7478. (org-test-with-temp-text
  7479. "* TODO task
  7480. :PROPERTIES:
  7481. :LOGGING: logdone
  7482. :END:"
  7483. (org-todo "DONE")
  7484. (when (memq 'org-add-log-note post-command-hook)
  7485. (org-add-log-note))
  7486. (buffer-string))))))
  7487. ;;; Timestamps API
  7488. (ert-deftest test-org/at-timestamp-p ()
  7489. "Test `org-at-timestamp-p' specifications."
  7490. (should
  7491. (org-test-with-temp-text "<2012-03-29 Thu>"
  7492. (org-at-timestamp-p)))
  7493. (should-not
  7494. (org-test-with-temp-text "2012-03-29 Thu"
  7495. (org-at-timestamp-p)))
  7496. ;; Test return values.
  7497. (should
  7498. (eq 'bracket
  7499. (org-test-with-temp-text "<2012-03-29 Thu>"
  7500. (org-at-timestamp-p))))
  7501. (should
  7502. (eq 'year
  7503. (org-test-with-temp-text "<<point>2012-03-29 Thu>"
  7504. (org-at-timestamp-p))))
  7505. (should
  7506. (eq 'month
  7507. (org-test-with-temp-text "<2012-<point>03-29 Thu>"
  7508. (org-at-timestamp-p))))
  7509. (should
  7510. (eq 'day
  7511. (org-test-with-temp-text "<2012-03-<point>29 Thu>"
  7512. (org-at-timestamp-p))))
  7513. (should
  7514. (eq 'day
  7515. (org-test-with-temp-text "<2012-03-29 T<point>hu>"
  7516. (org-at-timestamp-p))))
  7517. (should
  7518. (wholenump
  7519. (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
  7520. (org-at-timestamp-p))))
  7521. (should
  7522. (eq 'bracket
  7523. (org-test-with-temp-text "<2012-03-29 Thu<point>>"
  7524. (org-at-timestamp-p))))
  7525. (should
  7526. (eq 'after
  7527. (org-test-with-temp-text "<2012-03-29 Thu><point>»"
  7528. (org-at-timestamp-p))))
  7529. ;; Test `inactive' optional argument.
  7530. (should
  7531. (org-test-with-temp-text "[2012-03-29 Thu]"
  7532. (org-at-timestamp-p 'inactive)))
  7533. (should-not
  7534. (org-test-with-temp-text "[2012-03-29 Thu]"
  7535. (org-at-timestamp-p)))
  7536. ;; When optional argument is `agenda', recognize time-stamps in
  7537. ;; planning info line, property drawers and clocks.
  7538. (should
  7539. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7540. (org-at-timestamp-p 'agenda)))
  7541. (should-not
  7542. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7543. (org-at-timestamp-p)))
  7544. (should
  7545. (org-test-with-temp-text
  7546. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7547. (org-at-timestamp-p 'agenda)))
  7548. (should-not
  7549. (org-test-with-temp-text
  7550. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7551. (org-at-timestamp-p)))
  7552. (should
  7553. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7554. (let ((org-agenda-include-inactive-timestamps t))
  7555. (org-at-timestamp-p 'agenda))))
  7556. (should-not
  7557. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7558. (let ((org-agenda-include-inactive-timestamps t))
  7559. (org-at-timestamp-p))))
  7560. (should-not
  7561. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7562. (let ((org-agenda-include-inactive-timestamps t))
  7563. (org-at-timestamp-p 'inactive))))
  7564. ;; When optional argument is `lax', match any part of the document
  7565. ;; with Org timestamp syntax.
  7566. (should
  7567. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7568. (org-at-timestamp-p 'lax)))
  7569. (should-not
  7570. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7571. (org-at-timestamp-p)))
  7572. (should
  7573. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7574. (org-at-timestamp-p 'lax)))
  7575. (should-not
  7576. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7577. (org-at-timestamp-p)))
  7578. (should
  7579. (org-test-with-temp-text
  7580. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7581. (org-at-timestamp-p 'lax)))
  7582. (should-not
  7583. (org-test-with-temp-text
  7584. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7585. (org-at-timestamp-p)))
  7586. ;; Optional argument `lax' also matches inactive timestamps.
  7587. (should
  7588. (org-test-with-temp-text "# [2012-03-29 Thu]<point>"
  7589. (org-at-timestamp-p 'lax))))
  7590. (ert-deftest test-org/time-stamp ()
  7591. "Test `org-time-stamp' specifications."
  7592. ;; Insert chosen time stamp at point.
  7593. (should
  7594. (string-match
  7595. "Te<2014-03-04 .*?>xt"
  7596. (org-test-with-temp-text "Te<point>xt"
  7597. (cl-letf (((symbol-function 'org-read-date)
  7598. (lambda (&rest args)
  7599. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7600. (org-time-stamp nil)
  7601. (buffer-string)))))
  7602. ;; With a prefix argument, also insert time.
  7603. (should
  7604. (string-match
  7605. "Te<2014-03-04 .*? 00:41>xt"
  7606. (org-test-with-temp-text "Te<point>xt"
  7607. (cl-letf (((symbol-function 'org-read-date)
  7608. (lambda (&rest args)
  7609. (apply #'encode-time
  7610. (org-parse-time-string "2014-03-04 00:41")))))
  7611. (org-time-stamp '(4))
  7612. (buffer-string)))))
  7613. ;; With two universal prefix arguments, insert an active timestamp
  7614. ;; with the current time without prompting the user.
  7615. (should
  7616. (string-match
  7617. "Te<2014-03-04 .*? 00:41>xt"
  7618. (org-test-with-temp-text "Te<point>xt"
  7619. (org-test-at-time "2014-03-04 00:41"
  7620. (org-time-stamp '(16))
  7621. (buffer-string)))))
  7622. ;; When optional argument is non-nil, insert an inactive timestamp.
  7623. (should
  7624. (string-match
  7625. "Te\\[2014-03-04 .*?\\]xt"
  7626. (org-test-with-temp-text "Te<point>xt"
  7627. (cl-letf (((symbol-function 'org-read-date)
  7628. (lambda (&rest args)
  7629. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7630. (org-time-stamp nil t)
  7631. (buffer-string)))))
  7632. ;; When called from a timestamp, replace existing one.
  7633. (should
  7634. (string-match
  7635. "<2014-03-04 .*?>"
  7636. (org-test-with-temp-text "<2012-03-29<point> thu.>"
  7637. (cl-letf (((symbol-function 'org-read-date)
  7638. (lambda (&rest args)
  7639. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7640. (org-time-stamp nil)
  7641. (buffer-string)))))
  7642. (should
  7643. (string-match
  7644. "<2014-03-04 .*?>--<2014-03-04 .*?>"
  7645. (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
  7646. (cl-letf (((symbol-function 'org-read-date)
  7647. (lambda (&rest args)
  7648. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7649. (org-time-stamp nil)
  7650. (buffer-string)))))
  7651. ;; When replacing a timestamp, preserve repeater, if any.
  7652. (should
  7653. (string-match
  7654. "<2014-03-04 .*? \\+2y>"
  7655. (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
  7656. (cl-letf (((symbol-function 'org-read-date)
  7657. (lambda (&rest args)
  7658. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7659. (org-time-stamp nil)
  7660. (buffer-string)))))
  7661. ;; When called twice in a raw, build a date range.
  7662. (should
  7663. (string-match
  7664. "<2012-03-29 .*?>--<2014-03-04 .*?>"
  7665. (org-test-with-temp-text "<2012-03-29 thu.><point>"
  7666. (cl-letf (((symbol-function 'org-read-date)
  7667. (lambda (&rest args)
  7668. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7669. (let ((last-command 'org-time-stamp)
  7670. (this-command 'org-time-stamp))
  7671. (org-time-stamp nil))
  7672. (buffer-string))))))
  7673. (ert-deftest test-org/timestamp-has-time-p ()
  7674. "Test `org-timestamp-has-time-p' specifications."
  7675. ;; With time.
  7676. (should
  7677. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7678. (org-timestamp-has-time-p (org-element-context))))
  7679. ;; Without time.
  7680. (should-not
  7681. (org-test-with-temp-text "<2012-03-29 Thu>"
  7682. (org-timestamp-has-time-p (org-element-context)))))
  7683. (ert-deftest test-org/get-repeat ()
  7684. "Test `org-get-repeat' specifications."
  7685. (should
  7686. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
  7687. (org-get-repeat)))
  7688. (should-not
  7689. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
  7690. (org-get-repeat)))
  7691. ;; Return proper repeat string.
  7692. (should
  7693. (equal "+2y"
  7694. (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
  7695. (org-get-repeat))))
  7696. ;; Prevent false positive (commented or verbatim time stamps)
  7697. (should-not
  7698. (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
  7699. (org-get-repeat)))
  7700. (should-not
  7701. (org-test-with-temp-text
  7702. "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
  7703. (org-get-repeat)))
  7704. ;; Return nil when called before first heading.
  7705. (should-not
  7706. (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
  7707. (org-get-repeat)))
  7708. ;; When called with an optional argument, extract repeater from that
  7709. ;; string instead.
  7710. (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
  7711. (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
  7712. (ert-deftest test-org/timestamp-format ()
  7713. "Test `org-timestamp-format' specifications."
  7714. ;; Regular test.
  7715. (should
  7716. (equal
  7717. "2012-03-29 16:40"
  7718. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7719. (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
  7720. ;; Range end.
  7721. (should
  7722. (equal
  7723. "2012-03-29"
  7724. (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
  7725. (org-timestamp-format (org-element-context) "%Y-%m-%d" t)))))
  7726. (ert-deftest test-org/timestamp-split-range ()
  7727. "Test `org-timestamp-split-range' specifications."
  7728. ;; Extract range start (active).
  7729. (should
  7730. (equal '(2012 3 29)
  7731. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7732. (let ((ts (org-timestamp-split-range (org-element-context))))
  7733. (mapcar (lambda (p) (org-element-property p ts))
  7734. '(:year-end :month-end :day-end))))))
  7735. ;; Extract range start (inactive)
  7736. (should
  7737. (equal '(2012 3 29)
  7738. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7739. (let ((ts (org-timestamp-split-range (org-element-context))))
  7740. (mapcar (lambda (p) (org-element-property p ts))
  7741. '(:year-end :month-end :day-end))))))
  7742. ;; Extract range end (active).
  7743. (should
  7744. (equal '(2012 3 30)
  7745. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7746. (let ((ts (org-timestamp-split-range
  7747. (org-element-context) t)))
  7748. (mapcar (lambda (p) (org-element-property p ts))
  7749. '(:year-end :month-end :day-end))))))
  7750. ;; Extract range end (inactive)
  7751. (should
  7752. (equal '(2012 3 30)
  7753. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7754. (let ((ts (org-timestamp-split-range
  7755. (org-element-context) t)))
  7756. (mapcar (lambda (p) (org-element-property p ts))
  7757. '(:year-end :month-end :day-end))))))
  7758. ;; Return the timestamp if not a range.
  7759. (should
  7760. (org-test-with-temp-text "[2012-03-29 Thu]"
  7761. (let* ((ts-orig (org-element-context))
  7762. (ts-copy (org-timestamp-split-range ts-orig)))
  7763. (eq ts-orig ts-copy))))
  7764. (should
  7765. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7766. (let* ((ts-orig (org-element-context))
  7767. (ts-copy (org-timestamp-split-range ts-orig)))
  7768. (eq ts-orig ts-copy)))))
  7769. (ert-deftest test-org/timestamp-translate ()
  7770. "Test `org-timestamp-translate' specifications."
  7771. ;; Translate whole date range.
  7772. (should
  7773. (equal "<29>--<30>"
  7774. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7775. (let ((org-display-custom-times t)
  7776. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7777. (org-timestamp-translate (org-element-context))))))
  7778. ;; Translate date range start.
  7779. (should
  7780. (equal "<29>"
  7781. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7782. (let ((org-display-custom-times t)
  7783. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7784. (org-timestamp-translate (org-element-context) 'start)))))
  7785. ;; Translate date range end.
  7786. (should
  7787. (equal "<30>"
  7788. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7789. (let ((org-display-custom-times t)
  7790. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7791. (org-timestamp-translate (org-element-context) 'end)))))
  7792. ;; Translate time range.
  7793. (should
  7794. (equal "<08>--<16>"
  7795. (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
  7796. (let ((org-display-custom-times t)
  7797. (org-time-stamp-custom-formats '("<%d>" . "<%H>")))
  7798. (org-timestamp-translate (org-element-context))))))
  7799. ;; Translate non-range timestamp.
  7800. (should
  7801. (equal "<29>"
  7802. (org-test-with-temp-text "<2012-03-29 Thu>"
  7803. (let ((org-display-custom-times t)
  7804. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7805. (org-timestamp-translate (org-element-context))))))
  7806. ;; Do not change `diary' timestamps.
  7807. (should
  7808. (equal "<%%(org-float t 4 2)>"
  7809. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7810. (let ((org-display-custom-times t)
  7811. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7812. (org-timestamp-translate (org-element-context)))))))
  7813. (ert-deftest test-org/timestamp-from-string ()
  7814. "Test `org-timestamp-from-string' specifications."
  7815. ;; Return nil if argument is not a valid Org timestamp.
  7816. (should-not (org-timestamp-from-string ""))
  7817. (should-not (org-timestamp-from-string nil))
  7818. (should-not (org-timestamp-from-string "<2012-03-29"))
  7819. ;; Otherwise, return a valid Org timestamp object.
  7820. (should
  7821. (string-match-p "<2012-03-29 .+>"
  7822. (org-element-interpret-data
  7823. (org-timestamp-from-string "<2012-03-29 Thu>"))))
  7824. (should
  7825. (string-match-p "[2014-03-04 .+]"
  7826. (org-element-interpret-data
  7827. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  7828. (ert-deftest test-org/timestamp-from-time ()
  7829. "Test `org-timestamp-from-time' specifications."
  7830. ;; Standard test.
  7831. (should
  7832. (string-match-p
  7833. "<2012-03-29 .+>"
  7834. (org-element-interpret-data
  7835. (org-timestamp-from-time
  7836. (apply #'encode-time
  7837. (org-parse-time-string "<2012-03-29 Thu 16:40>"))))))
  7838. ;; When optional argument WITH-TIME is non-nil, provide time
  7839. ;; information.
  7840. (should
  7841. (string-match-p
  7842. "<2012-03-29 .+ 16:40>"
  7843. (org-element-interpret-data
  7844. (org-timestamp-from-time
  7845. (apply #'encode-time
  7846. (org-parse-time-string "<2012-03-29 Thu 16:40>"))
  7847. t))))
  7848. ;; When optional argument INACTIVE is non-nil, return an inactive
  7849. ;; timestamp.
  7850. (should
  7851. (string-match-p
  7852. "[2012-03-29 .+]"
  7853. (org-element-interpret-data
  7854. (org-timestamp-from-time
  7855. (apply #'encode-time
  7856. (org-parse-time-string "<2012-03-29 Thu 16:40>"))
  7857. nil t)))))
  7858. (ert-deftest test-org/timestamp-to-time ()
  7859. "Test `org-timestamp-to-time' specifications."
  7860. (should
  7861. (equal "2014-03-04"
  7862. (format-time-string
  7863. "%Y-%m-%d"
  7864. (org-timestamp-to-time
  7865. (org-timestamp-from-string "<2014-03-04 Tue>")))))
  7866. (should
  7867. (equal "2014-03-04"
  7868. (format-time-string
  7869. "%Y-%m-%d"
  7870. (org-timestamp-to-time
  7871. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  7872. (should
  7873. (equal "2012-03-29 08:30"
  7874. (format-time-string
  7875. "%Y-%m-%d %H:%M"
  7876. (org-timestamp-to-time
  7877. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")))))
  7878. (should
  7879. (equal "2012-03-29"
  7880. (format-time-string
  7881. "%Y-%m-%d"
  7882. (org-timestamp-to-time
  7883. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")))))
  7884. (should
  7885. (equal "2012-03-29"
  7886. (format-time-string
  7887. "%Y-%m-%d"
  7888. (org-timestamp-to-time
  7889. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")))))
  7890. ;; When optional argument END is non-nil, use end of date range or
  7891. ;; time range.
  7892. (should
  7893. (equal "2012-03-29 16:40"
  7894. (format-time-string
  7895. "%Y-%m-%d %H:%M"
  7896. (org-timestamp-to-time
  7897. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")
  7898. t))))
  7899. (should
  7900. (equal "2014-03-04"
  7901. (format-time-string
  7902. "%Y-%m-%d"
  7903. (org-timestamp-to-time
  7904. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")
  7905. t))))
  7906. (should
  7907. (equal "2014-03-04"
  7908. (format-time-string
  7909. "%Y-%m-%d"
  7910. (org-timestamp-to-time
  7911. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")
  7912. t)))))
  7913. ;;; Visibility
  7914. (ert-deftest test-org/hide-drawer-toggle ()
  7915. "Test `org-fold-hide-drawer-toggle' specifications."
  7916. ;; Error when not at a drawer.
  7917. (should-error
  7918. (org-test-with-temp-text ":fake-drawer:\ncontents"
  7919. (org-fold-hide-drawer-toggle 'off)
  7920. (get-char-property (line-end-position) 'invisible)))
  7921. (should-error
  7922. (org-test-with-temp-text
  7923. "#+begin_example\n<point>:D:\nc\n:END:\n#+end_example"
  7924. (org-fold-hide-drawer-toggle t)))
  7925. ;; Hide drawer.
  7926. (should
  7927. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7928. (org-fold-show-all)
  7929. (org-fold-hide-drawer-toggle)
  7930. (get-char-property (line-end-position) 'invisible)))
  7931. ;; Show drawer unconditionally when optional argument is `off'.
  7932. (should-not
  7933. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7934. (org-fold-hide-drawer-toggle)
  7935. (org-fold-hide-drawer-toggle 'off)
  7936. (get-char-property (line-end-position) 'invisible)))
  7937. ;; Hide drawer unconditionally when optional argument is non-nil.
  7938. (should
  7939. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7940. (org-fold-hide-drawer-toggle t)
  7941. (get-char-property (line-end-position) 'invisible)))
  7942. ;; Do not hide drawer when called from final blank lines.
  7943. (should-not
  7944. (org-test-with-temp-text ":drawer:\ncontents\n:end:\n\n<point>"
  7945. (org-fold-show-all)
  7946. (org-fold-hide-drawer-toggle)
  7947. (goto-char (point-min))
  7948. (get-char-property (line-end-position) 'invisible)))
  7949. ;; Don't leave point in an invisible part of the buffer when hiding
  7950. ;; a drawer away.
  7951. (should-not
  7952. (org-test-with-temp-text ":drawer:\ncontents\n<point>:end:"
  7953. (org-fold-hide-drawer-toggle)
  7954. (get-char-property (point) 'invisible))))
  7955. (ert-deftest test-org/hide-block-toggle ()
  7956. "Test `org-fold-hide-block-toggle' specifications."
  7957. ;; Error when not at a block.
  7958. (should-error
  7959. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
  7960. (org-fold-hide-block-toggle 'off)
  7961. (get-char-property (line-end-position) 'invisible)))
  7962. ;; Hide block.
  7963. (should
  7964. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  7965. (org-fold-hide-block-toggle)
  7966. (get-char-property (line-end-position) 'invisible)))
  7967. (should
  7968. (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
  7969. (org-fold-hide-block-toggle)
  7970. (get-char-property (line-end-position) 'invisible)))
  7971. ;; Show block unconditionally when optional argument is `off'.
  7972. (should-not
  7973. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7974. (org-fold-hide-block-toggle)
  7975. (org-fold-hide-block-toggle 'off)
  7976. (get-char-property (line-end-position) 'invisible)))
  7977. (should-not
  7978. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7979. (org-fold-hide-block-toggle 'off)
  7980. (get-char-property (line-end-position) 'invisible)))
  7981. ;; Hide block unconditionally when optional argument is non-nil.
  7982. (should
  7983. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7984. (org-fold-hide-block-toggle t)
  7985. (get-char-property (line-end-position) 'invisible)))
  7986. (should
  7987. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7988. (org-fold-hide-block-toggle)
  7989. (org-fold-hide-block-toggle t)
  7990. (get-char-property (line-end-position) 'invisible)))
  7991. ;; Do not hide block when called from final blank lines.
  7992. (should-not
  7993. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
  7994. (org-fold-hide-block-toggle)
  7995. (goto-char (point-min))
  7996. (get-char-property (line-end-position) 'invisible)))
  7997. ;; Don't leave point in an invisible part of the buffer when hiding
  7998. ;; a block away.
  7999. (should-not
  8000. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
  8001. (org-fold-hide-block-toggle)
  8002. (get-char-property (point) 'invisible))))
  8003. (ert-deftest test-org/hide-block-toggle-maybe ()
  8004. "Test `org-fold-hide-block-toggle' specifications."
  8005. (should
  8006. (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
  8007. (org-hide-block-toggle)))
  8008. (should-error
  8009. (org-test-with-temp-text "Paragraph" (org-hide-block-toggle))))
  8010. (ert-deftest test-org/show-set-visibility ()
  8011. "Test `org-fold-show-set-visibility' specifications."
  8012. ;; Do not throw an error before first heading.
  8013. (should
  8014. (org-test-with-temp-text "Preamble\n* Headline"
  8015. (org-fold-show-set-visibility 'tree)
  8016. t))
  8017. ;; Test all visibility spans, both on headline and in entry.
  8018. (let ((list-visible-lines
  8019. (lambda (state headerp)
  8020. (org-test-with-temp-text "* Grandmother (0)
  8021. ** Uncle (1)
  8022. *** Heir (2)
  8023. ** Father (3)
  8024. Ancestor text (4)
  8025. *** Sister (5)
  8026. Sibling text (6)
  8027. *** Self (7)
  8028. Match (8)
  8029. **** First born (9)
  8030. Child text (10)
  8031. **** The other child (11)
  8032. *** Brother (12)
  8033. ** Aunt (13)
  8034. "
  8035. (org-cycle t)
  8036. (search-forward (if headerp "Self" "Match"))
  8037. (org-fold-show-set-visibility state)
  8038. (goto-char (point-min))
  8039. (let (result (line 0))
  8040. (while (not (eobp))
  8041. (unless (org-invisible-p2) (push line result))
  8042. (cl-incf line)
  8043. (forward-line))
  8044. (nreverse result))))))
  8045. (should (equal '(0 7) (funcall list-visible-lines 'minimal t)))
  8046. (should (equal '(0 7 8) (funcall list-visible-lines 'minimal nil)))
  8047. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local t)))
  8048. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local nil)))
  8049. (should (equal '(0 3 7) (funcall list-visible-lines 'ancestors t)))
  8050. (should (equal '(0 3 7 8) (funcall list-visible-lines 'ancestors nil)))
  8051. (should (equal '(0 3 7 8 9 10 11)
  8052. (funcall list-visible-lines 'ancestors-full t)))
  8053. (should (equal '(0 3 7 8 9 10 11)
  8054. (funcall list-visible-lines 'ancestors-full nil)))
  8055. (should (equal '(0 3 5 7 12) (funcall list-visible-lines 'lineage t)))
  8056. (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines 'lineage nil)))
  8057. (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines 'tree t)))
  8058. (should (equal '(0 1 3 5 7 8 9 11 12 13)
  8059. (funcall list-visible-lines 'tree nil)))
  8060. (should (equal '(0 1 3 4 5 7 12 13)
  8061. (funcall list-visible-lines 'canonical t)))
  8062. (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
  8063. (funcall list-visible-lines 'canonical nil))))
  8064. ;; When point is hidden in a drawer or a block, make sure to make it
  8065. ;; visible.
  8066. (should-not
  8067. (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
  8068. (org-fold-hide-block-toggle)
  8069. (search-forward "Text")
  8070. (org-fold-show-set-visibility 'minimal)
  8071. (org-invisible-p2)))
  8072. (should-not
  8073. (org-test-with-temp-text ":DRAWER:\nText\n:END:"
  8074. (org-fold-hide-drawer-toggle)
  8075. (search-forward "Text")
  8076. (org-fold-show-set-visibility 'minimal)
  8077. (org-invisible-p2)))
  8078. (should-not
  8079. (org-test-with-temp-text
  8080. "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
  8081. (org-fold-hide-drawer-toggle)
  8082. (forward-line -1)
  8083. (org-fold-hide-block-toggle)
  8084. (search-forward "Text")
  8085. (org-fold-show-set-visibility 'minimal)
  8086. (org-invisible-p2))))
  8087. (ert-deftest test-org/copy-visible ()
  8088. "Test `org-copy-visible' specifications."
  8089. ;;`org-unfontify-region', which is wired up to
  8090. ;; `font-lock-unfontify-region-function', removes the invisible text
  8091. ;; property, among other things.
  8092. (cl-letf (((symbol-function 'org-unfontify-region) #'ignore))
  8093. (should
  8094. (equal "Foo"
  8095. (org-test-with-temp-text "Foo"
  8096. (let ((kill-ring nil))
  8097. (org-copy-visible (point-min) (point-max))
  8098. (current-kill 0 t)))))
  8099. ;; Skip invisible characters by text property.
  8100. (should
  8101. (equal "Foo"
  8102. (org-test-with-temp-text #("F<hidden>oo" 1 9 (invisible t))
  8103. (let ((kill-ring nil))
  8104. (org-copy-visible (point-min) (point-max))
  8105. (current-kill 0 t)))))
  8106. ;; Skip invisible characters by overlay.
  8107. (should
  8108. (equal "Foo"
  8109. (org-test-with-temp-text "F<hidden>oo"
  8110. (let ((o (make-overlay 2 10)))
  8111. (overlay-put o 'invisible t))
  8112. (let ((kill-ring nil))
  8113. (org-copy-visible (point-min) (point-max))
  8114. (current-kill 0 t)))))
  8115. ;; Handle invisible characters at the beginning and the end of the
  8116. ;; buffer.
  8117. (should
  8118. (equal "Foo"
  8119. (org-test-with-temp-text #("<hidden>Foo" 0 8 (invisible t))
  8120. (let ((kill-ring nil))
  8121. (org-copy-visible (point-min) (point-max))
  8122. (current-kill 0 t)))))
  8123. (should
  8124. (equal "Foo"
  8125. (org-test-with-temp-text #("Foo<hidden>" 3 11 (invisible t))
  8126. (let ((kill-ring nil))
  8127. (org-copy-visible (point-min) (point-max))
  8128. (current-kill 0 t)))))
  8129. ;; Handle multiple visible parts.
  8130. (should
  8131. (equal "abc"
  8132. (org-test-with-temp-text
  8133. #("aXbXc" 1 2 (invisible t) 3 4 (invisible t))
  8134. (let ((kill-ring nil))
  8135. (org-copy-visible (point-min) (point-max))
  8136. (current-kill 0 t)))))
  8137. ;; Handle adjacent invisible parts.
  8138. (should
  8139. (equal "ab"
  8140. (org-test-with-temp-text
  8141. #("aXXb" 1 2 (invisible t) 2 3 (invisible org-link))
  8142. (let ((kill-ring nil))
  8143. (org-copy-visible (point-min) (point-max))
  8144. (current-kill 0 t)))))
  8145. ;; Copies text based on what's actually visible, as defined by
  8146. ;; `buffer-invisibility-spec'.
  8147. (should
  8148. (equal "aYb"
  8149. (org-test-with-temp-text
  8150. #("aXYb"
  8151. 1 2 (invisible t)
  8152. 2 3 (invisible org-test-copy-visible))
  8153. (let ((kill-ring nil))
  8154. (org-copy-visible (point-min) (point-max))
  8155. (current-kill 0 t)))))))
  8156. (ert-deftest test-org/set-visibility-according-to-property ()
  8157. "Test `org-set-visibility-according-to-property' specifications."
  8158. ;; "folded" state.
  8159. (should
  8160. (org-test-with-temp-text
  8161. "
  8162. * a
  8163. :PROPERTIES:
  8164. :VISIBILITY: folded
  8165. :END:
  8166. ** <point>b"
  8167. (org-set-visibility-according-to-property)
  8168. (invisible-p (point))))
  8169. ;; "children" state.
  8170. (should
  8171. (org-test-with-temp-text
  8172. "
  8173. * a
  8174. :PROPERTIES:
  8175. :VISIBILITY: children
  8176. :END:
  8177. ** b
  8178. <point>Contents
  8179. ** c"
  8180. (org-set-visibility-according-to-property)
  8181. (invisible-p (point))))
  8182. (should
  8183. (org-test-with-temp-text
  8184. "
  8185. * a
  8186. :PROPERTIES:
  8187. :VISIBILITY: children
  8188. :END:
  8189. ** b
  8190. Contents
  8191. *** <point>c"
  8192. (org-set-visibility-according-to-property)
  8193. (invisible-p (point))))
  8194. ;; "content" state.
  8195. (should
  8196. (org-test-with-temp-text
  8197. "
  8198. * a
  8199. :PROPERTIES:
  8200. :VISIBILITY: content
  8201. :END:
  8202. ** b
  8203. <point>Contents
  8204. *** c"
  8205. (org-set-visibility-according-to-property)
  8206. (invisible-p (point))))
  8207. (should
  8208. (org-test-with-temp-text
  8209. "
  8210. * a
  8211. :PROPERTIES:
  8212. :VISIBILITY: content
  8213. :END:
  8214. ** b
  8215. Contents
  8216. *** <point>c"
  8217. (org-set-visibility-according-to-property)
  8218. (not (invisible-p (point)))))
  8219. ;; "showall" state.
  8220. (should
  8221. (org-test-with-temp-text
  8222. "
  8223. * a
  8224. :PROPERTIES:
  8225. :VISIBILITY: showall
  8226. :END:
  8227. ** b
  8228. <point>Contents
  8229. *** c"
  8230. (org-set-visibility-according-to-property)
  8231. (not (invisible-p (point)))))
  8232. (should
  8233. (org-test-with-temp-text
  8234. "
  8235. * a
  8236. :PROPERTIES:
  8237. :VISIBILITY: showall
  8238. :END:
  8239. ** b
  8240. Contents
  8241. *** <point>c"
  8242. (org-set-visibility-according-to-property)
  8243. (not (invisible-p (point)))))
  8244. ;; When VISIBILITY properties are nested, ignore inner ones.
  8245. (should
  8246. (org-test-with-temp-text
  8247. "
  8248. * A
  8249. :PROPERTIES:
  8250. :VISIBILITY: folded
  8251. :END:
  8252. ** <point>B
  8253. :PROPERTIES:
  8254. :VISIBILITY: folded
  8255. :END:"
  8256. (org-set-visibility-according-to-property)
  8257. (invisible-p (point)))))
  8258. (ert-deftest test-org/visibility-show-branches ()
  8259. "Test visibility of inline archived subtrees."
  8260. (org-test-with-temp-text
  8261. "* Foo<point>
  8262. ** Bar :ARCHIVE:
  8263. *** Baz
  8264. "
  8265. (org-kill-note-or-show-branches)
  8266. (should (org-invisible-p (- (point-max) 2)))))
  8267. (ert-deftest test-org/org-cycle-narrowed-subtree ()
  8268. "Test cycling in narrowed buffer."
  8269. (org-test-with-temp-text
  8270. "* Heading 1<point>
  8271. ** Child 1.1
  8272. ** Child 1.2
  8273. some text
  8274. *** Sub-child 1.2.1
  8275. * Heading 2"
  8276. (org-overview)
  8277. (org-narrow-to-subtree)
  8278. (org-cycle)
  8279. (re-search-forward "Sub-child")
  8280. (should (org-invisible-p))))
  8281. (ert-deftest test-org/org-fold-reveal-broken-structure ()
  8282. "Test unfolding broken elements."
  8283. (let ((org-fold-core-style 'text-properties))
  8284. (org-test-with-temp-text
  8285. "<point>* Heading 1
  8286. Text here"
  8287. (org-overview)
  8288. (re-search-forward "Text")
  8289. (should (org-invisible-p))
  8290. (goto-char 1)
  8291. (delete-char 1)
  8292. (re-search-forward "Text")
  8293. (should-not (org-invisible-p)))
  8294. (org-test-with-temp-text
  8295. "* Heading 1
  8296. <point>:PROPERTIES:
  8297. :ID: something
  8298. :END:
  8299. Text here"
  8300. (org-cycle)
  8301. (org-fold-hide-drawer-all)
  8302. (re-search-forward "ID")
  8303. (should (org-invisible-p))
  8304. (re-search-backward ":PROPERTIES:")
  8305. (delete-char 1)
  8306. (re-search-forward "ID")
  8307. (should-not (org-invisible-p)))
  8308. (org-test-with-temp-text
  8309. "* Heading 1
  8310. <point>:PROPERTIES:
  8311. :ID: something
  8312. :END:
  8313. Text here"
  8314. (org-cycle)
  8315. (org-fold-hide-drawer-all)
  8316. (re-search-forward "ID")
  8317. (should (org-invisible-p))
  8318. (re-search-forward ":END:")
  8319. (delete-char -1)
  8320. (re-search-backward "ID")
  8321. (should-not (org-invisible-p)))
  8322. (org-test-with-temp-text
  8323. "* Heading 1
  8324. <point>#+begin_src emacs-lisp
  8325. (+ 1 2)
  8326. #+end_src
  8327. Text here"
  8328. (org-cycle)
  8329. (org-fold-hide-drawer-all)
  8330. (re-search-forward "end")
  8331. (should (org-invisible-p))
  8332. (delete-char -1)
  8333. (re-search-backward "2")
  8334. (should-not (org-invisible-p)))))
  8335. (ert-deftest test-org/re-hide-edits-inside-fold ()
  8336. "Test edits inside folded regions."
  8337. (org-test-with-temp-text
  8338. "<point>* Heading 1
  8339. Text here"
  8340. (org-overview)
  8341. (org-set-property "TEST" "1")
  8342. (re-search-forward "TEST")
  8343. (should (org-invisible-p)))
  8344. (org-test-with-temp-text
  8345. "* Heading 1<point>
  8346. Text here"
  8347. (org-overview)
  8348. (insert " and extra heading text")
  8349. (re-search-backward "heading")
  8350. (should-not (org-invisible-p)))
  8351. (org-test-with-temp-text
  8352. "* Heading 1
  8353. Text<point> here"
  8354. (org-overview)
  8355. (insert " and extra text")
  8356. (re-search-backward "extra")
  8357. (should (org-invisible-p))))
  8358. ;;; Yank and Kill
  8359. (ert-deftest test-org/paste-subtree ()
  8360. "Test `org-paste-subtree' specifications."
  8361. ;; Return an error if text to yank is not a set of subtrees.
  8362. (should-error (org-paste-subtree nil "Text"))
  8363. ;; Adjust level according to current one.
  8364. (should
  8365. (equal "* H\n* Text\n"
  8366. (org-test-with-temp-text "* H\n<point>"
  8367. (org-paste-subtree nil "* Text")
  8368. (buffer-string))))
  8369. (should
  8370. (equal "* H1\n** H2\n** Text\n"
  8371. (org-test-with-temp-text "* H1\n** H2\n<point>"
  8372. (org-paste-subtree nil "* Text")
  8373. (buffer-string))))
  8374. ;; When not on a heading, move to next heading before yanking.
  8375. (should
  8376. (equal "* H1\nParagraph\n* Text\n* H2"
  8377. (org-test-with-temp-text "* H1\n<point>Paragraph\n* H2"
  8378. (org-paste-subtree nil "* Text")
  8379. (buffer-string))))
  8380. ;; If point is between two headings, use the deepest level.
  8381. (should
  8382. (equal "* H1\n\n* Text\n* H2"
  8383. (org-test-with-temp-text "* H1\n<point>\n* H2"
  8384. (org-paste-subtree nil "* Text")
  8385. (buffer-string))))
  8386. (should
  8387. (equal "** H1\n\n** Text\n* H2"
  8388. (org-test-with-temp-text "** H1\n<point>\n* H2"
  8389. (org-paste-subtree nil "* Text")
  8390. (buffer-string))))
  8391. (should
  8392. (equal "* H1\n\n** Text\n** H2"
  8393. (org-test-with-temp-text "* H1\n<point>\n** H2"
  8394. (org-paste-subtree nil "* Text")
  8395. (buffer-string))))
  8396. ;; When on an empty heading, after the stars, deduce the new level
  8397. ;; from the number of stars.
  8398. (should
  8399. (equal "*** Text\n"
  8400. (org-test-with-temp-text "*** <point>"
  8401. (org-paste-subtree nil "* Text")
  8402. (buffer-string))))
  8403. ;; Optional argument LEVEL forces a level for the subtree.
  8404. (should
  8405. (equal "* H\n*** Text\n"
  8406. (org-test-with-temp-text "* H<point>"
  8407. (org-paste-subtree 3 "* Text")
  8408. (buffer-string)))))
  8409. (ert-deftest test-org/cut-and-paste-subtree ()
  8410. "Test `org-cut-subtree' and `org-paste-subtree'."
  8411. (should
  8412. (equal
  8413. "* Two
  8414. two
  8415. * One
  8416. "
  8417. (org-test-with-temp-text
  8418. "* One
  8419. <point>* Two
  8420. two
  8421. "
  8422. (call-interactively #'org-cut-subtree)
  8423. (goto-char (point-min))
  8424. (call-interactively #'org-paste-subtree)
  8425. (buffer-string))))
  8426. (should
  8427. (equal
  8428. "* One
  8429. * Two
  8430. "
  8431. (org-test-with-temp-text
  8432. "* One
  8433. <point>* Two
  8434. "
  8435. (call-interactively #'org-cut-subtree)
  8436. (backward-char)
  8437. (call-interactively #'org-paste-subtree)
  8438. (buffer-string)))))
  8439. (provide 'test-org)
  8440. ;;; test-org.el ends here