test-org.el 148 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610
  1. ;;; test-org.el --- tests for org.el
  2. ;; Copyright (c) David Maus
  3. ;; Authors: David Maus
  4. ;; This file is not part of GNU Emacs.
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Comments:
  16. ;; Template test file for Org-mode tests
  17. ;;; Code:
  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. (progn (call-interactively '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. (progn (call-interactively '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# Comment"
  96. (progn (forward-line)
  97. (let ((org-adapt-indentation t))
  98. (call-interactively 'comment-dwim))
  99. (buffer-string)))))
  100. ;; Also recognize single # at column 0 as comments.
  101. (should
  102. (equal "# Comment"
  103. (org-test-with-temp-text "# Comment"
  104. (progn (forward-line)
  105. (call-interactively 'comment-dwim)
  106. (buffer-string)))))
  107. ;; Region selected and only comments and blank lines within it:
  108. ;; un-comment all commented lines.
  109. (should
  110. (equal "Comment 1\n\nComment 2"
  111. (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
  112. (progn
  113. (transient-mark-mode 1)
  114. (push-mark (point) t t)
  115. (goto-char (point-max))
  116. (call-interactively 'comment-dwim)
  117. (buffer-string)))))
  118. ;; Region selected without comments: comment all lines if
  119. ;; `comment-empty-lines' is non-nil, only non-blank lines otherwise.
  120. (should
  121. (equal "# Comment 1\n\n# Comment 2"
  122. (org-test-with-temp-text "Comment 1\n\nComment 2"
  123. (progn
  124. (transient-mark-mode 1)
  125. (push-mark (point) t t)
  126. (goto-char (point-max))
  127. (let ((comment-empty-lines nil))
  128. (call-interactively 'comment-dwim))
  129. (buffer-string)))))
  130. (should
  131. (equal "# Comment 1\n# \n# Comment 2"
  132. (org-test-with-temp-text "Comment 1\n\nComment 2"
  133. (progn
  134. (transient-mark-mode 1)
  135. (push-mark (point) t t)
  136. (goto-char (point-max))
  137. (let ((comment-empty-lines t))
  138. (call-interactively 'comment-dwim))
  139. (buffer-string)))))
  140. ;; In front of a keyword without region, insert a new comment.
  141. (should
  142. (equal "# \n#+KEYWORD: value"
  143. (org-test-with-temp-text "#+KEYWORD: value"
  144. (progn (call-interactively 'comment-dwim)
  145. (buffer-string)))))
  146. ;; In a source block, use appropriate syntax.
  147. (should
  148. (equal " ;; "
  149. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n\n#+END_SRC"
  150. (forward-line)
  151. (let ((org-edit-src-content-indentation 2))
  152. (call-interactively 'comment-dwim))
  153. (buffer-substring-no-properties (line-beginning-position) (point)))))
  154. (should
  155. (equal "#+BEGIN_SRC emacs-lisp\n ;; a\n ;; b\n#+END_SRC"
  156. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\na\nb\n#+END_SRC"
  157. (forward-line)
  158. (transient-mark-mode 1)
  159. (push-mark (point) t t)
  160. (forward-line 2)
  161. (let ((org-edit-src-content-indentation 2))
  162. (call-interactively 'comment-dwim))
  163. (buffer-string)))))
  164. ;;; Date and time analysis
  165. (ert-deftest test-org/org-read-date ()
  166. "Test `org-read-date' specifications."
  167. ;; Parse ISO date with abbreviated year and month.
  168. (should (equal "2012-03-29 16:40"
  169. (let ((org-time-was-given t))
  170. (org-read-date t nil "12-3-29 16:40"))))
  171. ;; Parse Europeans dates.
  172. (should (equal "2012-03-29 16:40"
  173. (let ((org-time-was-given t))
  174. (org-read-date t nil "29.03.2012 16:40"))))
  175. ;; Parse Europeans dates without year.
  176. (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
  177. (let ((org-time-was-given t))
  178. (org-read-date t nil "29.03. 16:40"))))
  179. ;; Relative date applied to current time if there is single
  180. ;; plus/minus, or to default date when there are two of them.
  181. (should
  182. (equal
  183. "2015-03-04"
  184. (flet ((current-time () (apply #'encode-time
  185. (org-parse-time-string "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. (flet ((current-time () (apply #'encode-time
  193. (org-parse-time-string "2014-03-04"))))
  194. (org-read-date
  195. t nil "++1y" nil
  196. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))
  197. ;; When `org-read-date-prefer-future' is non-nil, prefer future
  198. ;; dates (relatively to now) when incomplete. Otherwise, use
  199. ;; default date.
  200. (should
  201. (equal
  202. "2014-04-01"
  203. (flet ((current-time () (apply #'encode-time
  204. (org-parse-time-string "2014-03-04"))))
  205. (let ((org-read-date-prefer-future t))
  206. (org-read-date t nil "1")))))
  207. (should
  208. (equal
  209. "2013-03-04"
  210. (flet ((current-time () (apply #'encode-time
  211. (org-parse-time-string "2012-03-29"))))
  212. (let ((org-read-date-prefer-future t))
  213. (org-read-date t nil "3-4")))))
  214. (should
  215. (equal
  216. "2012-03-04"
  217. (flet ((current-time () (apply #'encode-time
  218. (org-parse-time-string "2012-03-29"))))
  219. (let ((org-read-date-prefer-future nil))
  220. (org-read-date t nil "3-4")))))
  221. ;; When set to `org-read-date-prefer-future' is set to `time', read
  222. ;; day is moved to tomorrow if specified hour is before current
  223. ;; time. However, it only happens in no other part of the date is
  224. ;; specified.
  225. (should
  226. (equal
  227. "2012-03-30"
  228. (flet ((current-time () (apply #'encode-time
  229. (org-parse-time-string "2012-03-29 16:40"))))
  230. (let ((org-read-date-prefer-future 'time))
  231. (org-read-date t nil "00:40" nil)))))
  232. (should-not
  233. (equal
  234. "2012-03-30"
  235. (flet ((current-time () (apply #'encode-time
  236. (org-parse-time-string "2012-03-29 16:40"))))
  237. (let ((org-read-date-prefer-future 'time))
  238. (org-read-date t nil "29 00:40" nil)))))
  239. ;; Caveat: `org-read-date-prefer-future' always refers to current
  240. ;; time, not default time, when they differ.
  241. (should
  242. (equal
  243. "2014-04-01"
  244. (flet ((current-time
  245. () (apply #'encode-time (org-parse-time-string "2014-03-04"))))
  246. (let ((org-read-date-prefer-future t))
  247. (org-read-date
  248. t nil "1" nil
  249. (apply #'encode-time (org-parse-time-string "2012-03-29")))))))
  250. (should
  251. (equal
  252. "2014-03-25"
  253. (flet ((current-time
  254. () (apply #'encode-time (org-parse-time-string "2014-03-04"))))
  255. (let ((org-read-date-prefer-future t))
  256. (org-read-date
  257. t nil "25" nil
  258. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))))
  259. (ert-deftest test-org/org-parse-time-string ()
  260. "Test `org-parse-time-string'."
  261. (should (equal (org-parse-time-string "2012-03-29 16:40")
  262. '(0 40 16 29 3 2012 nil nil nil)))
  263. (should (equal (org-parse-time-string "[2012-03-29 16:40]")
  264. '(0 40 16 29 3 2012 nil nil nil)))
  265. (should (equal (org-parse-time-string "<2012-03-29 16:40>")
  266. '(0 40 16 29 3 2012 nil nil nil)))
  267. (should (equal (org-parse-time-string "<2012-03-29>")
  268. '(0 0 0 29 3 2012 nil nil nil)))
  269. (should (equal (org-parse-time-string "<2012-03-29>" t)
  270. '(0 nil nil 29 3 2012 nil nil nil))))
  271. (ert-deftest test-org/closest-date ()
  272. "Test `org-closest-date' specifications."
  273. (require 'calendar)
  274. ;; Time stamps without a repeater are returned unchanged.
  275. (should
  276. (equal
  277. '(3 29 2012)
  278. (calendar-gregorian-from-absolute
  279. (org-closest-date "<2012-03-29>" "<2014-03-04>" nil))))
  280. ;; Time stamps with a null repeater are returned unchanged.
  281. (should
  282. (equal
  283. '(3 29 2012)
  284. (calendar-gregorian-from-absolute
  285. (org-closest-date "<2012-03-29 +0d>" "<2014-03-04>" nil))))
  286. ;; if PREFER is set to `past' always return a date before, or equal
  287. ;; to CURRENT.
  288. (should
  289. (equal
  290. '(3 1 2014)
  291. (calendar-gregorian-from-absolute
  292. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'past))))
  293. (should
  294. (equal
  295. '(3 4 2014)
  296. (calendar-gregorian-from-absolute
  297. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'past))))
  298. ;; if PREFER is set to `future' always return a date before, or equal
  299. ;; to CURRENT.
  300. (should
  301. (equal
  302. '(3 29 2014)
  303. (calendar-gregorian-from-absolute
  304. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'future))))
  305. (should
  306. (equal
  307. '(3 4 2014)
  308. (calendar-gregorian-from-absolute
  309. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'future))))
  310. ;; If PREFER is neither `past' nor `future', select closest date.
  311. (should
  312. (equal
  313. '(3 1 2014)
  314. (calendar-gregorian-from-absolute
  315. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" nil))))
  316. (should
  317. (equal
  318. '(5 4 2014)
  319. (calendar-gregorian-from-absolute
  320. (org-closest-date "<2012-03-04 +1m>" "<2014-04-28>" nil))))
  321. ;; Test "day" repeater.
  322. (should
  323. (equal '(3 8 2014)
  324. (calendar-gregorian-from-absolute
  325. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'past))))
  326. (should
  327. (equal '(3 10 2014)
  328. (calendar-gregorian-from-absolute
  329. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'future))))
  330. ;; Test "month" repeater.
  331. (should
  332. (equal '(1 5 2015)
  333. (calendar-gregorian-from-absolute
  334. (org-closest-date "<2014-03-05 +2m>" "<2015-02-04>" 'past))))
  335. (should
  336. (equal '(3 29 2014)
  337. (calendar-gregorian-from-absolute
  338. (org-closest-date "<2012-03-29 +2m>" "<2014-03-04>" 'future))))
  339. ;; Test "year" repeater.
  340. (should
  341. (equal '(3 5 2014)
  342. (calendar-gregorian-from-absolute
  343. (org-closest-date "<2014-03-05 +2y>" "<2015-02-04>" 'past))))
  344. (should
  345. (equal '(3 29 2014)
  346. (calendar-gregorian-from-absolute
  347. (org-closest-date "<2012-03-29 +2y>" "<2014-03-04>" 'future)))))
  348. ;;; Drawers
  349. (ert-deftest test-org/insert-property-drawer ()
  350. "Test `org-insert-property-drawer' specifications."
  351. ;; Error before first headline.
  352. (should-error (org-test-with-temp-text "" (org-insert-property-drawer)))
  353. ;; Insert drawer right after headline if there is no planning line,
  354. ;; or after it otherwise.
  355. (should
  356. (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
  357. (org-test-with-temp-text "* H\nParagraph<point>"
  358. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  359. (buffer-string))))
  360. (should
  361. (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
  362. (org-test-with-temp-text
  363. "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
  364. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  365. (buffer-string))))
  366. ;; Indent inserted drawer.
  367. (should
  368. (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
  369. (org-test-with-temp-text "* H\nParagraph<point>"
  370. (let ((org-adapt-indentation t)) (org-insert-property-drawer))
  371. (buffer-string))))
  372. ;; Handle insertion at eob.
  373. (should
  374. (equal "* H\n:PROPERTIES:\n:END:\n"
  375. (org-test-with-temp-text "* H"
  376. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  377. (buffer-string))))
  378. ;; Skip inlinetasks before point.
  379. (when (featurep 'org-inlinetask)
  380. (should
  381. (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
  382. (org-test-with-temp-text
  383. "* H\n*************** I\n*************** END\nP<point>"
  384. (let ((org-adapt-indentation nil)
  385. (org-inlinetask-min-level 15))
  386. (org-insert-property-drawer))
  387. (buffer-string)))))
  388. ;; Correctly set drawer in an inlinetask.
  389. (when (featurep 'org-inlinetask)
  390. (should
  391. (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
  392. (org-test-with-temp-text
  393. "* H\n*************** I\nP<point>\n*************** END"
  394. (let ((org-adapt-indentation nil)
  395. (org-inlinetask-min-level 15))
  396. (org-insert-property-drawer))
  397. (buffer-string))))))
  398. ;;; Filling
  399. (ert-deftest test-org/fill-paragraph ()
  400. "Test `org-fill-paragraph' specifications."
  401. ;; At an Org table, align it.
  402. (should
  403. (equal "| a |\n"
  404. (org-test-with-temp-text "|a|"
  405. (org-fill-paragraph)
  406. (buffer-string))))
  407. (should
  408. (equal "#+name: table\n| a |\n"
  409. (org-test-with-temp-text "#+name: table\n| a |\n"
  410. (org-fill-paragraph)
  411. (buffer-string))))
  412. ;; At a paragraph, preserve line breaks.
  413. (org-test-with-temp-text "some \\\\\nlong\ntext"
  414. (let ((fill-column 20))
  415. (org-fill-paragraph)
  416. (should (equal (buffer-string) "some \\\\\nlong text"))))
  417. ;; Correctly fill a paragraph when point is at its very end.
  418. (should
  419. (equal "A B"
  420. (org-test-with-temp-text "A\nB"
  421. (let ((fill-column 20))
  422. (goto-char (point-max))
  423. (org-fill-paragraph)
  424. (buffer-string)))))
  425. ;; Correctly fill the last paragraph of a greater element.
  426. (should
  427. (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
  428. (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
  429. (let ((fill-column 8))
  430. (forward-line)
  431. (end-of-line)
  432. (org-fill-paragraph)
  433. (buffer-string)))))
  434. ;; Correctly fill an element in a narrowed buffer.
  435. (should
  436. (equal "01234\n6"
  437. (org-test-with-temp-text "01234 6789"
  438. (let ((fill-column 5))
  439. (narrow-to-region 1 8)
  440. (org-fill-paragraph)
  441. (buffer-string)))))
  442. ;; Handle `adaptive-fill-regexp' in paragraphs.
  443. (should
  444. (equal "> a b"
  445. (org-test-with-temp-text "> a\n> b"
  446. (let ((fill-column 5)
  447. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  448. (org-fill-paragraph)
  449. (buffer-string)))))
  450. ;; Special case: Fill first paragraph when point is at an item or
  451. ;; a plain-list or a footnote reference.
  452. (should
  453. (equal "- A B"
  454. (org-test-with-temp-text "- A\n B"
  455. (let ((fill-column 20))
  456. (org-fill-paragraph)
  457. (buffer-string)))))
  458. (should
  459. (equal "[fn:1] A B"
  460. (org-test-with-temp-text "[fn:1] A\nB"
  461. (let ((fill-column 20))
  462. (org-fill-paragraph)
  463. (buffer-string)))))
  464. (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
  465. (let ((fill-column 20))
  466. (org-fill-paragraph)
  467. (should (equal (buffer-string)
  468. "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
  469. ;; Fill contents of `comment-block' elements.
  470. (should
  471. (equal
  472. (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
  473. (let ((fill-column 20))
  474. (forward-line)
  475. (org-fill-paragraph)
  476. (buffer-string)))
  477. "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
  478. ;; Fill `comment' elements.
  479. (should
  480. (equal " # A B"
  481. (org-test-with-temp-text " # A\n # B"
  482. (let ((fill-column 20))
  483. (org-fill-paragraph)
  484. (buffer-string)))))
  485. ;; Do not mix consecutive comments when filling one of them.
  486. (should
  487. (equal "# A B\n\n# C"
  488. (org-test-with-temp-text "# A\n# B\n\n# C"
  489. (let ((fill-column 20))
  490. (org-fill-paragraph)
  491. (buffer-string)))))
  492. ;; Use commented empty lines as separators when filling comments.
  493. (should
  494. (equal "# A B\n#\n# C"
  495. (org-test-with-temp-text "# A\n# B\n#\n# C"
  496. (let ((fill-column 20))
  497. (org-fill-paragraph)
  498. (buffer-string)))))
  499. ;; Handle `adaptive-fill-regexp' in comments.
  500. (should
  501. (equal "# > a b"
  502. (org-test-with-temp-text "# > a\n# > b"
  503. (let ((fill-column 20)
  504. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  505. (org-fill-paragraph)
  506. (buffer-string)))))
  507. ;; Do nothing at affiliated keywords.
  508. (org-test-with-temp-text "#+NAME: para\nSome\ntext."
  509. (let ((fill-column 20))
  510. (org-fill-paragraph)
  511. (should (equal (buffer-string) "#+NAME: para\nSome\ntext."))))
  512. ;; Do not move point after table when filling a table.
  513. (should-not
  514. (org-test-with-temp-text "| a | b |\n| c | d |\n"
  515. (forward-char)
  516. (org-fill-paragraph)
  517. (eobp))))
  518. (ert-deftest test-org/auto-fill-function ()
  519. "Test auto-filling features."
  520. ;; Auto fill paragraph.
  521. (should
  522. (equal "12345\n7890"
  523. (org-test-with-temp-text "12345 7890"
  524. (let ((fill-column 5))
  525. (end-of-line)
  526. (org-auto-fill-function)
  527. (buffer-string)))))
  528. ;; Auto fill first paragraph in an item.
  529. (should
  530. (equal "- 12345\n 7890"
  531. (org-test-with-temp-text "- 12345 7890"
  532. (let ((fill-column 7))
  533. (end-of-line)
  534. (org-auto-fill-function)
  535. (buffer-string)))))
  536. ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
  537. (should
  538. (equal "> 12345\n 7890"
  539. (org-test-with-temp-text "> 12345 7890"
  540. (let ((fill-column 10)
  541. (adaptive-fill-regexp "[ \t]*>+[ \t]*")
  542. (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
  543. (end-of-line)
  544. (org-auto-fill-function)
  545. (buffer-string)))))
  546. (should
  547. (equal "> 12345\n> 12345\n> 7890"
  548. (org-test-with-temp-text "> 12345\n> 12345 7890"
  549. (let ((fill-column 10)
  550. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  551. (goto-char (point-max))
  552. (org-auto-fill-function)
  553. (buffer-string)))))
  554. (should-not
  555. (equal " 12345\n *12345\n *12345"
  556. (org-test-with-temp-text " 12345\n *12345 12345"
  557. (let ((fill-column 10)
  558. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  559. (goto-char (point-max))
  560. (org-auto-fill-function)
  561. (buffer-string)))))
  562. ;; Auto fill comments.
  563. (should
  564. (equal " # 12345\n # 7890"
  565. (org-test-with-temp-text " # 12345 7890"
  566. (let ((fill-column 10))
  567. (end-of-line)
  568. (org-auto-fill-function)
  569. (buffer-string)))))
  570. ;; A hash within a line isn't a comment.
  571. (should-not
  572. (equal "12345 # 7890\n# 1"
  573. (org-test-with-temp-text "12345 # 7890 1"
  574. (let ((fill-column 12))
  575. (end-of-line)
  576. (org-auto-fill-function)
  577. (buffer-string)))))
  578. ;; Correctly interpret empty prefix.
  579. (should-not
  580. (equal "# a\n# b\nRegular\n# paragraph"
  581. (org-test-with-temp-text "# a\n# b\nRegular paragraph"
  582. (let ((fill-column 12))
  583. (end-of-line 3)
  584. (org-auto-fill-function)
  585. (buffer-string)))))
  586. ;; Comment block: auto fill contents.
  587. (should
  588. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  589. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  590. (let ((fill-column 5))
  591. (forward-line)
  592. (end-of-line)
  593. (org-auto-fill-function)
  594. (buffer-string)))))
  595. (should
  596. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  597. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  598. (let ((fill-column 5))
  599. (forward-line)
  600. (end-of-line)
  601. (org-auto-fill-function)
  602. (buffer-string)))))
  603. ;; Do not fill if a new item could be created.
  604. (should-not
  605. (equal "12345\n- 90"
  606. (org-test-with-temp-text "12345 - 90"
  607. (let ((fill-column 5))
  608. (end-of-line)
  609. (org-auto-fill-function)
  610. (buffer-string)))))
  611. ;; Do not fill if a line break could be introduced.
  612. (should-not
  613. (equal "123\\\\\n7890"
  614. (org-test-with-temp-text "123\\\\ 7890"
  615. (let ((fill-column 6))
  616. (end-of-line)
  617. (org-auto-fill-function)
  618. (buffer-string)))))
  619. ;; Do not fill affiliated keywords.
  620. (should-not
  621. (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
  622. (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
  623. (let ((fill-column 20))
  624. (end-of-line)
  625. (org-auto-fill-function)
  626. (buffer-string))))))
  627. ;;; Indentation
  628. (ert-deftest test-org/indent-line ()
  629. "Test `org-indent-line' specifications."
  630. ;; Do not indent diary sexps, footnote definitions or headlines.
  631. (should
  632. (zerop
  633. (org-test-with-temp-text "%%(org-calendar-holiday)"
  634. (org-indent-line)
  635. (org-get-indentation))))
  636. (should
  637. (zerop
  638. (org-test-with-temp-text "[fn:1] fn"
  639. (let ((org-adapt-indentation t)) (org-indent-line))
  640. (org-get-indentation))))
  641. (should
  642. (zerop
  643. (org-test-with-temp-text "* H"
  644. (org-indent-line)
  645. (org-get-indentation))))
  646. ;; Do not indent before first headline.
  647. (should
  648. (zerop
  649. (org-test-with-temp-text ""
  650. (org-indent-line)
  651. (org-get-indentation))))
  652. ;; Indent according to headline level otherwise, unless
  653. ;; `org-adapt-indentation' is nil.
  654. (should
  655. (= 2
  656. (org-test-with-temp-text "* H\nA"
  657. (forward-line)
  658. (let ((org-adapt-indentation t)) (org-indent-line))
  659. (org-get-indentation))))
  660. (should
  661. (= 2
  662. (org-test-with-temp-text "* H\n\nA"
  663. (forward-line)
  664. (let ((org-adapt-indentation t)) (org-indent-line))
  665. (org-get-indentation))))
  666. (should
  667. (zerop
  668. (org-test-with-temp-text "* H\nA"
  669. (forward-line)
  670. (let ((org-adapt-indentation nil)) (org-indent-line))
  671. (org-get-indentation))))
  672. ;; Indenting preserves point position.
  673. (should
  674. (org-test-with-temp-text "* H\nAB"
  675. (forward-line)
  676. (forward-char)
  677. (let ((org-adapt-indentation t)) (org-indent-line))
  678. (looking-at "B")))
  679. ;; Do not change indentation at an item.
  680. (should
  681. (= 1
  682. (org-test-with-temp-text "* H\n - A"
  683. (forward-line)
  684. (let ((org-adapt-indentation t)) (org-indent-line))
  685. (org-get-indentation))))
  686. ;; On blank lines at the end of a list, indent like last element
  687. ;; within it if the line is still in the list. If the last element
  688. ;; is an item, indent like its contents. Otherwise, indent like the
  689. ;; whole list.
  690. (should
  691. (= 4
  692. (org-test-with-temp-text "* H\n- A\n - AA\n<point>"
  693. (let ((org-adapt-indentation t)) (org-indent-line))
  694. (org-get-indentation))))
  695. (should
  696. (zerop
  697. (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n<point>"
  698. (let ((org-adapt-indentation t)) (org-indent-line))
  699. (org-get-indentation))))
  700. (should
  701. (= 4
  702. (org-test-with-temp-text "* H\n- A\n - \n<point>"
  703. (let ((org-adapt-indentation t)) (org-indent-line))
  704. (org-get-indentation))))
  705. (should
  706. (= 4
  707. (org-test-with-temp-text
  708. "* H\n - \n #+BEGIN_SRC emacs-lisp\n t\n #+END_SRC\n<point>"
  709. (let ((org-adapt-indentation t)) (org-indent-line))
  710. (org-get-indentation))))
  711. (should
  712. (= 2
  713. (org-test-with-temp-text "- A\n B\n\n<point>"
  714. (let ((org-adapt-indentation nil)) (org-indent-line))
  715. (org-get-indentation))))
  716. ;; Likewise, on a blank line at the end of a footnote definition,
  717. ;; indent at column 0 if line belongs to the definition. Otherwise,
  718. ;; indent like the definition itself.
  719. (should
  720. (zerop
  721. (org-test-with-temp-text "* H\n[fn:1] Definition\n"
  722. (goto-char (point-max))
  723. (let ((org-adapt-indentation t)) (org-indent-line))
  724. (org-get-indentation))))
  725. (should
  726. (zerop
  727. (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n"
  728. (goto-char (point-max))
  729. (let ((org-adapt-indentation t)) (org-indent-line))
  730. (org-get-indentation))))
  731. ;; After the end of the contents of a greater element, indent like
  732. ;; the beginning of the element.
  733. (should
  734. (= 1
  735. (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
  736. (forward-line 2)
  737. (org-indent-line)
  738. (org-get-indentation))))
  739. ;; On blank lines after a paragraph, indent like its last non-empty
  740. ;; line.
  741. (should
  742. (= 1
  743. (org-test-with-temp-text " Paragraph\n\n<point>"
  744. (org-indent-line)
  745. (org-get-indentation))))
  746. ;; At the first line of an element, indent like previous element's
  747. ;; first line, ignoring footnotes definitions and inline tasks, or
  748. ;; according to parent.
  749. (should
  750. (= 2
  751. (org-test-with-temp-text "A\n\n B\n\nC"
  752. (goto-char (point-max))
  753. (org-indent-line)
  754. (org-get-indentation))))
  755. (should
  756. (= 1
  757. (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC"
  758. (goto-char (point-max))
  759. (org-indent-line)
  760. (org-get-indentation))))
  761. (should
  762. (= 1
  763. (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
  764. (forward-line 1)
  765. (org-indent-line)
  766. (org-get-indentation))))
  767. ;; Within code part of a source block, use language major mode if
  768. ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
  769. ;; according to line above.
  770. (should
  771. (= 6
  772. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  773. (forward-line 2)
  774. (let ((org-src-tab-acts-natively t)
  775. (org-edit-src-content-indentation 0))
  776. (org-indent-line))
  777. (org-get-indentation))))
  778. (should
  779. (= 1
  780. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  781. (forward-line 2)
  782. (let ((org-src-tab-acts-natively nil)
  783. (org-edit-src-content-indentation 0))
  784. (org-indent-line))
  785. (org-get-indentation))))
  786. ;; Otherwise, indent like the first non-blank line above.
  787. (should
  788. (zerop
  789. (org-test-with-temp-text "#+BEGIN_CENTER\nline1\n\n line2\n#+END_CENTER"
  790. (forward-line 3)
  791. (org-indent-line)
  792. (org-get-indentation))))
  793. ;; Align node properties according to `org-property-format'. Handle
  794. ;; nicely empty values.
  795. (should
  796. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  797. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
  798. (let ((org-property-format "%-10s %s")) (org-indent-line))
  799. (buffer-string))))
  800. (should
  801. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  802. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
  803. (let ((org-property-format "%-10s %s")) (org-indent-line))
  804. (buffer-string)))))
  805. (ert-deftest test-org/indent-region ()
  806. "Test `org-indent-region' specifications."
  807. ;; Indent paragraph.
  808. (should
  809. (equal "A\nB\nC"
  810. (org-test-with-temp-text " A\nB\n C"
  811. (org-indent-region (point-min) (point-max))
  812. (buffer-string))))
  813. ;; Indent greater elements along with their contents.
  814. (should
  815. (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
  816. (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
  817. (org-indent-region (point-min) (point-max))
  818. (buffer-string))))
  819. ;; Ignore contents of verse blocks and example blocks.
  820. (should
  821. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  822. (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  823. (org-indent-region (point-min) (point-max))
  824. (buffer-string))))
  825. (should
  826. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  827. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  828. (org-indent-region (point-min) (point-max))
  829. (buffer-string))))
  830. ;; Indent according to mode if `org-src-tab-acts-natively' is
  831. ;; non-nil. Otherwise, do not indent code at all.
  832. (should
  833. (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
  834. (org-test-with-temp-text
  835. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  836. (let ((org-src-tab-acts-natively t)
  837. (org-edit-src-content-indentation 0))
  838. (org-indent-region (point-min) (point-max)))
  839. (buffer-string))))
  840. (should
  841. (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  842. (org-test-with-temp-text
  843. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  844. (let ((org-src-tab-acts-natively nil)
  845. (org-edit-src-content-indentation 0))
  846. (org-indent-region (point-min) (point-max)))
  847. (buffer-string))))
  848. ;; Align node properties according to `org-property-format'. Handle
  849. ;; nicely empty values.
  850. (should
  851. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  852. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
  853. (let ((org-property-format "%-10s %s")
  854. (org-adapt-indentation nil))
  855. (org-indent-region (point) (point-max)))
  856. (buffer-string))))
  857. (should
  858. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  859. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
  860. (let ((org-property-format "%-10s %s")
  861. (org-adapt-indentation nil))
  862. (org-indent-region (point) (point-max)))
  863. (buffer-string))))
  864. ;; Indent plain lists.
  865. (should
  866. (equal "- A\n B\n - C\n\n D"
  867. (org-test-with-temp-text "- A\n B\n - C\n\n D"
  868. (org-indent-region (point-min) (point-max))
  869. (buffer-string))))
  870. (should
  871. (equal "- A\n\n- B"
  872. (org-test-with-temp-text " - A\n\n - B"
  873. (org-indent-region (point-min) (point-max))
  874. (buffer-string))))
  875. ;; Indent footnote definitions.
  876. (should
  877. (equal "[fn:1] Definition\n\nDefinition"
  878. (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
  879. (org-indent-region (point-min) (point-max))
  880. (buffer-string))))
  881. ;; Special case: Start indenting on a blank line.
  882. (should
  883. (equal "\nParagraph"
  884. (org-test-with-temp-text "\n Paragraph"
  885. (org-indent-region (point-min) (point-max))
  886. (buffer-string)))))
  887. ;;; Editing
  888. (ert-deftest test-org/delete-indentation ()
  889. "Test `org-delete-indentation' specifications."
  890. ;; Regular test.
  891. (should (equal "foo bar"
  892. (org-test-with-temp-text
  893. "foo \n bar<point>"
  894. (org-delete-indentation)
  895. (buffer-string))))
  896. ;; With optional argument.
  897. (should (equal "foo bar"
  898. (org-test-with-temp-text
  899. "foo<point> \n bar"
  900. (org-delete-indentation t)
  901. (buffer-string))))
  902. ;; At headline text should be appended to the headline text.
  903. (should
  904. (equal"* foo bar :tag:"
  905. (let (org-auto-align-tags)
  906. (org-test-with-temp-text
  907. "* foo :tag:\n bar<point>"
  908. (org-delete-indentation)
  909. (buffer-string)))))
  910. (should
  911. (equal "* foo bar :tag:"
  912. (let (org-auto-align-tags)
  913. (org-test-with-temp-text
  914. "* foo <point>:tag:\n bar"
  915. (org-delete-indentation t)
  916. (buffer-string))))))
  917. (ert-deftest test-org/return ()
  918. "Test `org-return' specifications."
  919. ;; Regular test.
  920. (should
  921. (equal "Para\ngraph"
  922. (org-test-with-temp-text "Para<point>graph"
  923. (org-return)
  924. (buffer-string))))
  925. ;; With optional argument, indent line.
  926. (should
  927. (equal " Para\n graph"
  928. (org-test-with-temp-text " Para<point>graph"
  929. (org-return t)
  930. (buffer-string))))
  931. ;; On a table, call `org-table-next-row'.
  932. (should
  933. (org-test-with-temp-text "| <point>a |\n| b |"
  934. (org-return)
  935. (org-looking-at-p "b")))
  936. ;; Open link or timestamp under point when `org-return-follows-link'
  937. ;; is non-nil.
  938. (should
  939. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  940. (let ((org-return-follows-link t)
  941. (org-link-search-must-match-exact-headline nil))
  942. (org-return))
  943. (org-looking-at-p "<<target>>")))
  944. (should-not
  945. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  946. (let ((org-return-follows-link nil)) (org-return))
  947. (org-looking-at-p "<<target>>")))
  948. (should
  949. (org-test-with-temp-text "* [[b][a<point>]]\n* b"
  950. (let ((org-return-follows-link t)) (org-return))
  951. (org-looking-at-p "* b")))
  952. (should
  953. (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
  954. (let ((org-return-follows-link t)
  955. (org-link-search-must-match-exact-headline nil))
  956. (org-return))
  957. (org-looking-at-p "<<target>>")))
  958. (should-not
  959. (org-test-with-temp-text "Link [[target]]<point> <<target>>"
  960. (let ((org-return-follows-link t)
  961. (org-link-search-must-match-exact-headline nil))
  962. (org-return))
  963. (org-looking-at-p "<<target>>")))
  964. ;; When `org-return-follows-link' is non-nil, tolerate links and
  965. ;; timestamps in comments, node properties, etc.
  966. (should
  967. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  968. (let ((org-return-follows-link t)
  969. (org-link-search-must-match-exact-headline nil))
  970. (org-return))
  971. (org-looking-at-p "<<target>>")))
  972. (should-not
  973. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  974. (let ((org-return-follows-link nil)) (org-return))
  975. (org-looking-at-p "<<target>>")))
  976. (should-not
  977. (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
  978. (let ((org-return-follows-link t)
  979. (org-link-search-must-match-exact-headline nil))
  980. (org-return))
  981. (org-looking-at-p "<<target>>")))
  982. ;; However, do not open link when point is in a table.
  983. (should
  984. (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
  985. (let ((org-return-follows-link t)) (org-return))
  986. (org-looking-at-p "between")))
  987. ;; Special case: in a list, when indenting, do not break structure.
  988. (should
  989. (equal "- A\n B"
  990. (org-test-with-temp-text "- A <point>B"
  991. (org-return t)
  992. (buffer-string))))
  993. (should
  994. (equal "- A\n\n- B"
  995. (org-test-with-temp-text "- A\n<point>- B"
  996. (org-return t)
  997. (buffer-string))))
  998. ;; On tags part of a headline, add a newline below it instead of
  999. ;; breaking it.
  1000. (should
  1001. (equal "* H :tag:\n"
  1002. (org-test-with-temp-text "* H :<point>tag:"
  1003. (org-return)
  1004. (buffer-string))))
  1005. ;; Before headline text, add a newline below it instead of breaking
  1006. ;; it.
  1007. (should
  1008. (equal "* TODO H :tag:\n"
  1009. (org-test-with-temp-text "* <point>TODO H :tag:"
  1010. (org-return)
  1011. (buffer-string))))
  1012. (should
  1013. (equal "* TODO [#B] H :tag:\n"
  1014. (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
  1015. (org-return)
  1016. (buffer-string))))
  1017. ;; At headline text, break headline text but preserve tags.
  1018. (should
  1019. (equal "* TODO [#B] foo :tag:\nbar"
  1020. (let (org-auto-align-tags)
  1021. (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
  1022. (org-return)
  1023. (buffer-string)))))
  1024. ;; At bol of headline insert newline.
  1025. (should
  1026. (equal "\n* h"
  1027. (org-test-with-temp-text "<point>* h"
  1028. (org-return)
  1029. (buffer-string))))
  1030. ;; Refuse to leave invalid headline in buffer.
  1031. (should
  1032. (equal "* h\n"
  1033. (org-test-with-temp-text "*<point> h"
  1034. (org-return)
  1035. (buffer-string)))))
  1036. (ert-deftest test-org/meta-return ()
  1037. "Test M-RET (`org-meta-return') specifications."
  1038. ;; In a table field insert a row above.
  1039. (should
  1040. (org-test-with-temp-text "| a |"
  1041. (forward-char)
  1042. (org-meta-return)
  1043. (forward-line -1)
  1044. (looking-at "| |$")))
  1045. ;; In a paragraph change current line into a header.
  1046. (should
  1047. (org-test-with-temp-text "a"
  1048. (org-meta-return)
  1049. (beginning-of-line)
  1050. (looking-at "\* a$")))
  1051. ;; In an item insert an item, in this case above.
  1052. (should
  1053. (org-test-with-temp-text "- a"
  1054. (org-meta-return)
  1055. (beginning-of-line)
  1056. (looking-at "- $")))
  1057. ;; In a drawer and item insert an item, in this case above.
  1058. (should
  1059. (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
  1060. (forward-line)
  1061. (org-meta-return)
  1062. (beginning-of-line)
  1063. (looking-at "- $"))))
  1064. (ert-deftest test-org/insert-heading ()
  1065. "Test `org-insert-heading' specifications."
  1066. ;; In an empty buffer, insert a new headline.
  1067. (should
  1068. (equal "* "
  1069. (org-test-with-temp-text ""
  1070. (org-insert-heading)
  1071. (buffer-string))))
  1072. ;; At the beginning of a line, turn it into a headline
  1073. (should
  1074. (equal "* P"
  1075. (org-test-with-temp-text "<point>P"
  1076. (org-insert-heading)
  1077. (buffer-string))))
  1078. ;; In the middle of a line, split the line if allowed, otherwise,
  1079. ;; insert the headline at its end.
  1080. (should
  1081. (equal "Para\n* graph"
  1082. (org-test-with-temp-text "Para<point>graph"
  1083. (let ((org-M-RET-may-split-line '((default . t))))
  1084. (org-insert-heading))
  1085. (buffer-string))))
  1086. (should
  1087. (equal "Paragraph\n* "
  1088. (org-test-with-temp-text "Para<point>graph"
  1089. (let ((org-M-RET-may-split-line '((default . nil))))
  1090. (org-insert-heading))
  1091. (buffer-string))))
  1092. ;; When on a list, insert an item instead, unless called with an
  1093. ;; universal argument or if list is invisible. In this case, create
  1094. ;; a new headline after contents.
  1095. (should
  1096. (equal "* H\n- item\n- "
  1097. (org-test-with-temp-text "* H\n- item<point>"
  1098. (let ((org-insert-heading-respect-content nil))
  1099. (org-insert-heading))
  1100. (buffer-string))))
  1101. (should
  1102. (equal "* H\n- item\n- item 2\n* "
  1103. (org-test-with-temp-text "* H\n- item<point>\n- item 2"
  1104. (let ((org-insert-heading-respect-content nil))
  1105. (org-insert-heading '(4)))
  1106. (buffer-string))))
  1107. (should
  1108. (equal "* H\n- item\n* "
  1109. (org-test-with-temp-text "* H\n- item"
  1110. (org-cycle)
  1111. (goto-char (point-max))
  1112. (let ((org-insert-heading-respect-content nil)) (org-insert-heading))
  1113. (buffer-string))))
  1114. ;; When called with two universal arguments, insert a new headline
  1115. ;; at the end of the grandparent subtree.
  1116. (should
  1117. (equal "* H1\n** H3\n- item\n** H2\n** "
  1118. (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
  1119. (let ((org-insert-heading-respect-content nil))
  1120. (org-insert-heading '(16)))
  1121. (buffer-string))))
  1122. ;; When optional TOP-LEVEL argument is non-nil, always insert
  1123. ;; a level 1 heading.
  1124. (should
  1125. (equal "* H1\n** H2\n* "
  1126. (org-test-with-temp-text "* H1\n** H2<point>"
  1127. (org-insert-heading nil nil t)
  1128. (buffer-string))))
  1129. (should
  1130. (equal "* H1\n- item\n* "
  1131. (org-test-with-temp-text "* H1\n- item<point>"
  1132. (org-insert-heading nil nil t)
  1133. (buffer-string))))
  1134. ;; Corner case: correctly insert a headline after an empty one.
  1135. (should
  1136. (equal "* \n* "
  1137. (org-test-with-temp-text "* <point>"
  1138. (org-insert-heading)
  1139. (buffer-string)))))
  1140. (ert-deftest test-org/insert-todo-heading-respect-content ()
  1141. "Test `org-insert-todo-heading-respect-content' specifications."
  1142. ;; Create a TODO heading.
  1143. (should
  1144. (org-test-with-temp-text "* H1\n Body"
  1145. (org-insert-todo-heading-respect-content)
  1146. (nth 2 (org-heading-components))))
  1147. ;; Add headline at the end of the first subtree
  1148. (should
  1149. (org-test-with-temp-text "* H1\nH1Body\n** H2\nH2Body"
  1150. (search-forward "H1Body")
  1151. (org-insert-todo-heading-respect-content)
  1152. (and (eobp) (org-at-heading-p))))
  1153. ;; In a list, do not create a new item.
  1154. (should
  1155. (org-test-with-temp-text "* H\n- an item\n- another one"
  1156. (search-forward "an ")
  1157. (org-insert-todo-heading-respect-content)
  1158. (and (eobp) (org-at-heading-p)))))
  1159. (ert-deftest test-org/clone-with-time-shift ()
  1160. "Test `org-clone-subtree-with-time-shift'."
  1161. ;; Clone non-repeating once.
  1162. (should
  1163. (equal "\
  1164. * H1\n<2015-06-21>
  1165. * H1\n<2015-06-23>
  1166. "
  1167. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1168. (org-clone-subtree-with-time-shift 1 "+2d")
  1169. (replace-regexp-in-string
  1170. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1171. nil nil 1))))
  1172. ;; Clone repeating once.
  1173. (should
  1174. (equal "\
  1175. * H1\n<2015-06-21>
  1176. * H1\n<2015-06-23>
  1177. * H1\n<2015-06-25 +1w>
  1178. "
  1179. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1180. (org-clone-subtree-with-time-shift 1 "+2d")
  1181. (replace-regexp-in-string
  1182. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1183. nil nil 1))))
  1184. ;; Clone non-repeating zero times.
  1185. (should
  1186. (equal "\
  1187. * H1\n<2015-06-21>
  1188. "
  1189. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1190. (org-clone-subtree-with-time-shift 0 "+2d")
  1191. (replace-regexp-in-string
  1192. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1193. nil nil 1))))
  1194. ;; Clone repeating "zero" times.
  1195. (should
  1196. (equal "\
  1197. * H1\n<2015-06-21>
  1198. * H1\n<2015-06-23 +1w>
  1199. "
  1200. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1201. (org-clone-subtree-with-time-shift 0 "+2d")
  1202. (replace-regexp-in-string
  1203. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1204. nil nil 1)))))
  1205. ;;; Fixed-Width Areas
  1206. (ert-deftest test-org/toggle-fixed-width ()
  1207. "Test `org-toggle-fixed-width' specifications."
  1208. ;; No region: Toggle on fixed-width marker in paragraphs.
  1209. (should
  1210. (equal ": A"
  1211. (org-test-with-temp-text "A"
  1212. (org-toggle-fixed-width)
  1213. (buffer-string))))
  1214. ;; No region: Toggle off fixed-width markers in fixed-width areas.
  1215. (should
  1216. (equal "A"
  1217. (org-test-with-temp-text ": A"
  1218. (org-toggle-fixed-width)
  1219. (buffer-string))))
  1220. ;; No region: Toggle on marker in blank lines after elements or just
  1221. ;; after a headline.
  1222. (should
  1223. (equal "* H\n: "
  1224. (org-test-with-temp-text "* H\n"
  1225. (forward-line)
  1226. (org-toggle-fixed-width)
  1227. (buffer-string))))
  1228. (should
  1229. (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
  1230. (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
  1231. (goto-char (point-max))
  1232. (org-toggle-fixed-width)
  1233. (buffer-string))))
  1234. ;; No region: Toggle on marker in front of one line elements (e.g.,
  1235. ;; headlines, clocks)
  1236. (should
  1237. (equal ": * Headline"
  1238. (org-test-with-temp-text "* Headline"
  1239. (org-toggle-fixed-width)
  1240. (buffer-string))))
  1241. (should
  1242. (equal ": #+KEYWORD: value"
  1243. (org-test-with-temp-text "#+KEYWORD: value"
  1244. (org-toggle-fixed-width)
  1245. (buffer-string))))
  1246. ;; No region: error in other situations.
  1247. (should-error
  1248. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
  1249. (forward-line)
  1250. (org-toggle-fixed-width)
  1251. (buffer-string)))
  1252. ;; No region: Indentation is preserved.
  1253. (should
  1254. (equal "- A\n : B"
  1255. (org-test-with-temp-text "- A\n B"
  1256. (forward-line)
  1257. (org-toggle-fixed-width)
  1258. (buffer-string))))
  1259. ;; Region: If it contains only fixed-width elements and blank lines,
  1260. ;; toggle off fixed-width markup.
  1261. (should
  1262. (equal "A\n\nB"
  1263. (org-test-with-temp-text ": A\n\n: B"
  1264. (transient-mark-mode 1)
  1265. (push-mark (point) t t)
  1266. (goto-char (point-max))
  1267. (org-toggle-fixed-width)
  1268. (buffer-string))))
  1269. ;; Region: If it contains anything else, toggle on fixed-width but
  1270. ;; not on fixed-width areas.
  1271. (should
  1272. (equal ": A\n: \n: B\n: \n: C"
  1273. (org-test-with-temp-text "A\n\n: B\n\nC"
  1274. (transient-mark-mode 1)
  1275. (push-mark (point) t t)
  1276. (goto-char (point-max))
  1277. (org-toggle-fixed-width)
  1278. (buffer-string))))
  1279. ;; Region: Ignore blank lines at its end, unless it contains only
  1280. ;; such lines.
  1281. (should
  1282. (equal ": A\n\n"
  1283. (org-test-with-temp-text "A\n\n"
  1284. (transient-mark-mode 1)
  1285. (push-mark (point) t t)
  1286. (goto-char (point-max))
  1287. (org-toggle-fixed-width)
  1288. (buffer-string))))
  1289. (should
  1290. (equal ": \n: \n"
  1291. (org-test-with-temp-text "\n\n"
  1292. (transient-mark-mode 1)
  1293. (push-mark (point) t t)
  1294. (goto-char (point-max))
  1295. (org-toggle-fixed-width)
  1296. (buffer-string)))))
  1297. ;;; Headline
  1298. (ert-deftest test-org/in-commented-heading-p ()
  1299. "Test `org-in-commented-heading-p' specifications."
  1300. ;; Commented headline.
  1301. (should
  1302. (org-test-with-temp-text "* COMMENT Headline\nBody"
  1303. (goto-char (point-max))
  1304. (org-in-commented-heading-p)))
  1305. ;; Commented ancestor.
  1306. (should
  1307. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  1308. (goto-char (point-max))
  1309. (org-in-commented-heading-p)))
  1310. ;; Comment keyword is case-sensitive.
  1311. (should-not
  1312. (org-test-with-temp-text "* Comment Headline\nBody"
  1313. (goto-char (point-max))
  1314. (org-in-commented-heading-p)))
  1315. ;; Keyword is standalone.
  1316. (should-not
  1317. (org-test-with-temp-text "* COMMENTHeadline\nBody"
  1318. (goto-char (point-max))
  1319. (org-in-commented-heading-p)))
  1320. ;; Optional argument.
  1321. (should-not
  1322. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  1323. (goto-char (point-max))
  1324. (org-in-commented-heading-p t))))
  1325. (ert-deftest test-org/entry-blocked-p ()
  1326. ;; Check other dependencies.
  1327. (should
  1328. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  1329. (let ((org-enforce-todo-dependencies t)
  1330. (org-blocker-hook
  1331. '(org-block-todo-from-children-or-siblings-or-parent)))
  1332. (org-entry-blocked-p))))
  1333. (should-not
  1334. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  1335. (let ((org-enforce-todo-dependencies t)
  1336. (org-blocker-hook
  1337. '(org-block-todo-from-children-or-siblings-or-parent)))
  1338. (org-entry-blocked-p))))
  1339. ;; Entry without a TODO keyword or with a DONE keyword cannot be
  1340. ;; blocked.
  1341. (should-not
  1342. (org-test-with-temp-text "* Blocked\n** TODO one"
  1343. (let ((org-enforce-todo-dependencies t)
  1344. (org-blocker-hook
  1345. '(org-block-todo-from-children-or-siblings-or-parent)))
  1346. (org-entry-blocked-p))))
  1347. (should-not
  1348. (org-test-with-temp-text "* DONE Blocked\n** TODO one"
  1349. (let ((org-enforce-todo-dependencies t)
  1350. (org-blocker-hook
  1351. '(org-block-todo-from-children-or-siblings-or-parent)))
  1352. (org-entry-blocked-p))))
  1353. ;; Follow :ORDERED: specifications.
  1354. (should
  1355. (org-test-with-temp-text
  1356. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
  1357. (let ((org-enforce-todo-dependencies t)
  1358. (org-blocker-hook
  1359. '(org-block-todo-from-children-or-siblings-or-parent)))
  1360. (org-entry-blocked-p))))
  1361. (should-not
  1362. (org-test-with-temp-text
  1363. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
  1364. (let ((org-enforce-todo-dependencies t)
  1365. (org-blocker-hook
  1366. '(org-block-todo-from-children-or-siblings-or-parent)))
  1367. (org-entry-blocked-p)))))
  1368. (ert-deftest test-org/get-outline-path ()
  1369. "Test `org-get-outline-path' specifications."
  1370. ;; Top-level headlines have no outline path.
  1371. (should-not
  1372. (org-test-with-temp-text "* H"
  1373. (org-get-outline-path)))
  1374. ;; Otherwise, outline path is the path leading to the headline.
  1375. (should
  1376. (equal '("H")
  1377. (org-test-with-temp-text "* H\n** S<point>"
  1378. (org-get-outline-path))))
  1379. ;; Find path even when point is not on a headline.
  1380. (should
  1381. (equal '("H")
  1382. (org-test-with-temp-text "* H\n** S\nText<point>"
  1383. (org-get-outline-path))))
  1384. ;; TODO keywords, tags and statistics cookies are ignored.
  1385. (should
  1386. (equal '("H")
  1387. (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
  1388. (org-get-outline-path))))
  1389. ;; Links are replaced with their description or their path.
  1390. (should
  1391. (equal '("Org")
  1392. (org-test-with-temp-text
  1393. "* [[http://orgmode.org][Org]]\n** S<point>"
  1394. (org-get-outline-path))))
  1395. (should
  1396. (equal '("http://orgmode.org")
  1397. (org-test-with-temp-text
  1398. "* [[http://orgmode.org]]\n** S<point>"
  1399. (org-get-outline-path))))
  1400. ;; When WITH-SELF is non-nil, include current heading.
  1401. (should
  1402. (equal '("H")
  1403. (org-test-with-temp-text "* H"
  1404. (org-get-outline-path t))))
  1405. (should
  1406. (equal '("H" "S")
  1407. (org-test-with-temp-text "* H\n** S\nText<point>"
  1408. (org-get-outline-path t))))
  1409. ;; Using cache is transparent to the user.
  1410. (should
  1411. (equal '("H")
  1412. (org-test-with-temp-text "* H\n** S<point>"
  1413. (setq org-outline-path-cache nil)
  1414. (org-get-outline-path nil t))))
  1415. ;; Do not corrupt cache when finding outline path in distant part of
  1416. ;; the buffer.
  1417. (should
  1418. (equal '("H2")
  1419. (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
  1420. (setq org-outline-path-cache nil)
  1421. (org-get-outline-path nil t)
  1422. (search-forward "S2")
  1423. (org-get-outline-path nil t))))
  1424. ;; Do not choke on empty headlines.
  1425. (should
  1426. (org-test-with-temp-text "* H\n** <point>"
  1427. (org-get-outline-path)))
  1428. (should
  1429. (org-test-with-temp-text "* \n** H<point>"
  1430. (org-get-outline-path))))
  1431. (ert-deftest test-org/format-outline-path ()
  1432. "Test `org-format-outline-path' specifications."
  1433. (should
  1434. (string= (org-format-outline-path (list "one" "two" "three"))
  1435. "one/two/three"))
  1436. ;; Empty path.
  1437. (should
  1438. (string= (org-format-outline-path '())
  1439. ""))
  1440. (should
  1441. (string= (org-format-outline-path '(nil))
  1442. ""))
  1443. ;; Empty path and prefix.
  1444. (should
  1445. (string= (org-format-outline-path '() nil ">>")
  1446. ">>"))
  1447. ;; Trailing whitespace in headings.
  1448. (should
  1449. (string= (org-format-outline-path (list "one\t" "tw o " "three "))
  1450. "one/tw o/three"))
  1451. ;; Non-default prefix and separators.
  1452. (should
  1453. (string= (org-format-outline-path (list "one" "two" "three") nil ">>" "|")
  1454. ">>|one|two|three"))
  1455. ;; Truncate.
  1456. (should
  1457. (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
  1458. "one/two/.."))
  1459. ;; Give a very narrow width.
  1460. (should
  1461. (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
  1462. "on"))
  1463. ;; Give a prefix that extends beyond the width.
  1464. (should
  1465. (string= (org-format-outline-path (list "one" "two" "three" "four") 10
  1466. ">>>>>>>>>>")
  1467. ">>>>>>>>..")))
  1468. (ert-deftest test-org/map-entries ()
  1469. "Test `org-map-entries' specifications."
  1470. ;; Full match.
  1471. (should
  1472. (equal '(1 11)
  1473. (org-test-with-temp-text "* Level 1\n** Level 2"
  1474. (org-map-entries #'point))))
  1475. ;; Level match.
  1476. (should
  1477. (equal '(1)
  1478. (org-test-with-temp-text "* Level 1\n** Level 2"
  1479. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL=1")))))
  1480. (should
  1481. (equal '(11)
  1482. (org-test-with-temp-text "* Level 1\n** Level 2"
  1483. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL>1")))))
  1484. ;; Tag match.
  1485. (should
  1486. (equal '(11)
  1487. (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
  1488. (org-map-entries #'point "yes"))))
  1489. (should
  1490. (equal '(14)
  1491. (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
  1492. (org-map-entries #'point "+yes-a"))))
  1493. (should
  1494. (equal '(11 23)
  1495. (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
  1496. (org-map-entries #'point "{yes?}"))))
  1497. ;; Priority match.
  1498. (should
  1499. (equal '(1)
  1500. (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
  1501. (org-map-entries #'point "PRIORITY=\"A\""))))
  1502. ;; Date match.
  1503. (should
  1504. (equal '(36)
  1505. (org-test-with-temp-text "
  1506. * H1
  1507. SCHEDULED: <2012-03-29 thu.>
  1508. * H2
  1509. SCHEDULED: <2014-03-04 tue.>"
  1510. (org-map-entries #'point "SCHEDULED=\"<2014-03-04 tue.>\""))))
  1511. (should
  1512. (equal '(2)
  1513. (org-test-with-temp-text "
  1514. * H1
  1515. SCHEDULED: <2012-03-29 thu.>
  1516. * H2
  1517. SCHEDULED: <2014-03-04 tue.>"
  1518. (org-map-entries #'point "SCHEDULED<\"<2013-01-01>\""))))
  1519. ;; Regular property match.
  1520. (should
  1521. (equal '(2)
  1522. (org-test-with-temp-text "
  1523. * H1
  1524. :PROPERTIES:
  1525. :TEST: 1
  1526. :END:
  1527. * H2
  1528. :PROPERTIES:
  1529. :TEST: 2
  1530. :END:"
  1531. (org-map-entries #'point "TEST=1"))))
  1532. ;; Multiple criteria.
  1533. (should
  1534. (equal '(23)
  1535. (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
  1536. (let (org-odd-levels-only
  1537. (org-use-tag-inheritance nil))
  1538. (org-map-entries #'point "yes+LEVEL=1")))))
  1539. ;; "or" criteria.
  1540. (should
  1541. (equal '(12 24)
  1542. (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
  1543. (let (org-odd-levels-only)
  1544. (org-map-entries #'point "LEVEL=2|no")))))
  1545. (should
  1546. (equal '(1 12)
  1547. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
  1548. (let (org-odd-levels-only)
  1549. (org-map-entries #'point "yes|no")))))
  1550. ;; "and" criteria.
  1551. (should
  1552. (equal '(22)
  1553. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
  1554. (let (org-odd-levels-only)
  1555. (org-map-entries #'point "yes&no"))))))
  1556. (ert-deftest test-org/edit-headline ()
  1557. "Test `org-edit-headline' specifications."
  1558. (should
  1559. (equal "* B"
  1560. (org-test-with-temp-text "* A"
  1561. (org-edit-headline "B")
  1562. (buffer-string))))
  1563. ;; Handle empty headings.
  1564. (should
  1565. (equal "* "
  1566. (org-test-with-temp-text "* A"
  1567. (org-edit-headline "")
  1568. (buffer-string))))
  1569. (should
  1570. (equal "* A"
  1571. (org-test-with-temp-text "* "
  1572. (org-edit-headline "A")
  1573. (buffer-string))))
  1574. ;; Handle TODO keywords and priority cookies.
  1575. (should
  1576. (equal "* TODO B"
  1577. (org-test-with-temp-text "* TODO A"
  1578. (org-edit-headline "B")
  1579. (buffer-string))))
  1580. (should
  1581. (equal "* [#A] B"
  1582. (org-test-with-temp-text "* [#A] A"
  1583. (org-edit-headline "B")
  1584. (buffer-string))))
  1585. (should
  1586. (equal "* TODO [#A] B"
  1587. (org-test-with-temp-text "* TODO [#A] A"
  1588. (org-edit-headline "B")
  1589. (buffer-string))))
  1590. ;; Handle tags.
  1591. (equal "* B :tag:"
  1592. (org-test-with-temp-text "* A :tag:"
  1593. (let ((org-tags-column 4)) (org-edit-headline "B"))
  1594. (buffer-string))))
  1595. ;;; Keywords
  1596. (ert-deftest test-org/set-regexps-and-options ()
  1597. "Test `org-set-regexps-and-options' specifications."
  1598. ;; TAGS keyword.
  1599. (should
  1600. (equal '(("A" . ?a) ("B") ("C"))
  1601. (org-test-with-temp-text "#+TAGS: A(a) B C"
  1602. (org-mode-restart)
  1603. org-tag-alist)))
  1604. (should
  1605. (equal '(("A") (:newline) ("B"))
  1606. (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
  1607. (org-mode-restart)
  1608. org-tag-alist)))
  1609. (should
  1610. (equal '((:startgroup) ("A") ("B") (:endgroup) ("C"))
  1611. (org-test-with-temp-text "#+TAGS: { A B } C"
  1612. (org-mode-restart)
  1613. org-tag-alist)))
  1614. (should
  1615. (equal '((:startgroup) ("A") (:grouptags) ("B") ("C") (:endgroup))
  1616. (org-test-with-temp-text "#+TAGS: { A : B C }"
  1617. (org-mode-restart)
  1618. org-tag-alist)))
  1619. (should
  1620. (equal '(("A" "B" "C"))
  1621. (org-test-with-temp-text "#+TAGS: { A : B C }"
  1622. (org-mode-restart)
  1623. org-tag-groups-alist)))
  1624. (should
  1625. (equal '((:startgrouptag) ("A") (:grouptags) ("B") ("C") (:endgrouptag))
  1626. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  1627. (org-mode-restart)
  1628. org-tag-alist)))
  1629. (should
  1630. (equal '(("A" "B" "C"))
  1631. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  1632. (org-mode-restart)
  1633. org-tag-groups-alist)))
  1634. ;; FILETAGS keyword.
  1635. (should
  1636. (equal '("A" "B" "C")
  1637. (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
  1638. (org-mode-restart)
  1639. org-file-tags)))
  1640. ;; PROPERTY keyword. Property names are case-insensitive.
  1641. (should
  1642. (equal "foo=1"
  1643. (org-test-with-temp-text "#+PROPERTY: var foo=1"
  1644. (org-mode-restart)
  1645. (cdr (assoc "var" org-file-properties)))))
  1646. (should
  1647. (equal
  1648. "foo=1 bar=2"
  1649. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
  1650. (org-mode-restart)
  1651. (cdr (assoc "var" org-file-properties)))))
  1652. (should
  1653. (equal
  1654. "foo=1 bar=2"
  1655. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
  1656. (org-mode-restart)
  1657. (cdr (assoc "var" org-file-properties)))))
  1658. ;; ARCHIVE keyword.
  1659. (should
  1660. (equal "%s_done::"
  1661. (org-test-with-temp-text "#+ARCHIVE: %s_done::"
  1662. (org-mode-restart)
  1663. org-archive-location)))
  1664. ;; CATEGORY keyword.
  1665. (should
  1666. (eq 'test
  1667. (org-test-with-temp-text "#+CATEGORY: test"
  1668. (org-mode-restart)
  1669. org-category)))
  1670. (should
  1671. (equal "test"
  1672. (org-test-with-temp-text "#+CATEGORY: test"
  1673. (org-mode-restart)
  1674. (cdr (assoc "CATEGORY" org-file-properties)))))
  1675. ;; COLUMNS keyword.
  1676. (should
  1677. (equal "%25ITEM %TAGS %PRIORITY %TODO"
  1678. (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
  1679. (org-mode-restart)
  1680. org-columns-default-format)))
  1681. ;; CONSTANTS keyword. Constants names are case sensitive.
  1682. (should
  1683. (equal '("299792458." "3.14")
  1684. (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
  1685. (org-mode-restart)
  1686. (mapcar
  1687. (lambda (n) (cdr (assoc n org-table-formula-constants-local)))
  1688. '("c" "pi")))))
  1689. (should
  1690. (equal "3.14"
  1691. (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
  1692. (org-mode-restart)
  1693. (cdr (assoc "pi" org-table-formula-constants-local)))))
  1694. (should
  1695. (equal "22/7"
  1696. (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
  1697. (org-mode-restart)
  1698. (cdr (assoc "PI" org-table-formula-constants-local)))))
  1699. ;; LINK keyword.
  1700. (should
  1701. (equal
  1702. '("url1" "url2")
  1703. (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
  1704. (org-mode-restart)
  1705. (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local)))
  1706. '("a" "b")))))
  1707. ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
  1708. (should
  1709. (equal
  1710. '(?X ?Z ?Y)
  1711. (org-test-with-temp-text "#+PRIORITIES: X Z Y"
  1712. (org-mode-restart)
  1713. (list org-highest-priority org-lowest-priority org-default-priority))))
  1714. (should
  1715. (equal
  1716. '(?A ?C ?B)
  1717. (org-test-with-temp-text "#+PRIORITIES: X Z"
  1718. (org-mode-restart)
  1719. (list org-highest-priority org-lowest-priority org-default-priority))))
  1720. ;; STARTUP keyword.
  1721. (should
  1722. (equal '(t t)
  1723. (org-test-with-temp-text "#+STARTUP: fold odd"
  1724. (org-mode-restart)
  1725. (list org-startup-folded org-odd-levels-only))))
  1726. ;; TODO keywords.
  1727. (should
  1728. (equal '(("A" "B") ("C"))
  1729. (org-test-with-temp-text "#+TODO: A B | C"
  1730. (org-mode-restart)
  1731. (list org-not-done-keywords org-done-keywords))))
  1732. (should
  1733. (equal '(("A" "C") ("B" "D"))
  1734. (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
  1735. (org-mode-restart)
  1736. (list org-not-done-keywords org-done-keywords))))
  1737. (should
  1738. (equal '(("A" "B") ("C"))
  1739. (org-test-with-temp-text "#+TYP_TODO: A B | C"
  1740. (org-mode-restart)
  1741. (list org-not-done-keywords org-done-keywords))))
  1742. (should
  1743. (equal '((:startgroup) ("A" . ?a) (:endgroup))
  1744. (org-test-with-temp-text "#+TODO: A(a)"
  1745. (org-mode-restart)
  1746. org-todo-key-alist)))
  1747. (should
  1748. (equal '(("D" note nil) ("C" time nil) ("B" note time))
  1749. (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
  1750. (org-mode-restart)
  1751. org-todo-log-states)))
  1752. ;; Enter SETUPFILE keyword.
  1753. (should
  1754. (equal "1"
  1755. (org-test-with-temp-text
  1756. (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
  1757. (org-mode-restart)
  1758. (cdr (assoc "a" org-file-properties))))))
  1759. ;;; Links
  1760. ;;;; Coderefs
  1761. (ert-deftest test-org/coderef ()
  1762. "Test coderef links specifications."
  1763. (should
  1764. (org-test-with-temp-text "
  1765. #+BEGIN_SRC emacs-lisp
  1766. \(+ 1 1) (ref:sc)
  1767. #+END_SRC
  1768. \[[(sc)<point>]]"
  1769. (org-open-at-point)
  1770. (looking-at "(ref:sc)")))
  1771. ;; Find coderef even with alternate label format.
  1772. (should
  1773. (org-test-with-temp-text "
  1774. #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
  1775. \(+ 1 1) {ref:sc}
  1776. #+END_SRC
  1777. \[[(sc)<point>]]"
  1778. (org-open-at-point)
  1779. (looking-at "{ref:sc}"))))
  1780. ;;;; Custom ID
  1781. (ert-deftest test-org/custom-id ()
  1782. "Test custom ID links specifications."
  1783. (should
  1784. (org-test-with-temp-text
  1785. "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  1786. (org-open-at-point)
  1787. (org-looking-at-p "\\* H1")))
  1788. ;; Throw an error on false positives.
  1789. (should-error
  1790. (org-test-with-temp-text
  1791. "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  1792. (org-open-at-point)
  1793. (org-looking-at-p "\\* H1"))))
  1794. ;;;; Fuzzy Links
  1795. ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
  1796. ;; a named element (#+name: text) and to headlines (* Text).
  1797. (ert-deftest test-org/fuzzy-links ()
  1798. "Test fuzzy links specifications."
  1799. ;; Fuzzy link goes in priority to a matching target.
  1800. (should
  1801. (org-test-with-temp-text
  1802. "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
  1803. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  1804. (looking-at "<<Test>>")))
  1805. ;; Then fuzzy link points to an element with a given name.
  1806. (should
  1807. (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
  1808. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  1809. (looking-at "#\\+NAME: Test")))
  1810. ;; A target still lead to a matching headline otherwise.
  1811. (should
  1812. (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
  1813. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  1814. (looking-at "\\* Head2")))
  1815. ;; With a leading star in link, enforce heading match.
  1816. (should
  1817. (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
  1818. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  1819. (looking-at "\\* Test")))
  1820. ;; With a leading star in link, enforce exact heading match, even
  1821. ;; with `org-link-search-must-match-exact-headline' set to nil.
  1822. (should-error
  1823. (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
  1824. (let ((org-link-search-must-match-exact-headline nil))
  1825. (org-open-at-point))))
  1826. ;; Handle non-nil `org-link-search-must-match-exact-headline'.
  1827. (should
  1828. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
  1829. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  1830. (looking-at "\\* Test")))
  1831. (should
  1832. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
  1833. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  1834. (looking-at "\\* Test")))
  1835. ;; Heading match should not care about spaces, cookies, TODO
  1836. ;; keywords, priorities, and tags.
  1837. (should
  1838. (let ((first-line
  1839. "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
  1840. (org-test-with-temp-text
  1841. (concat first-line "\nFoo Bar\n<point>[[*Test 1 2]]")
  1842. (let ((org-link-search-must-match-exact-headline nil)
  1843. (org-todo-regexp "TODO"))
  1844. (org-open-at-point))
  1845. (looking-at (regexp-quote first-line)))))
  1846. ;; Heading match should still be exact.
  1847. (should-error
  1848. (let ((first-line
  1849. "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
  1850. (org-test-with-temp-text
  1851. (concat first-line "\nFoo Bar\n<point>[[*Test 1]]")
  1852. (let ((org-link-search-must-match-exact-headline nil)
  1853. (org-todo-regexp "TODO"))
  1854. (org-open-at-point)))))
  1855. ;; Heading match ignores COMMENT keyword.
  1856. (should
  1857. (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
  1858. (org-open-at-point)
  1859. (looking-at "\\* COMMENT Test")))
  1860. ;; Correctly un-hexify fuzzy links.
  1861. (should
  1862. (org-test-with-temp-text "* With space\n[[*With%20space][With space<point>]]"
  1863. (org-open-at-point)
  1864. (bobp))))
  1865. ;;;; Link Escaping
  1866. (ert-deftest test-org/org-link-escape-ascii-character ()
  1867. "Escape an ascii character."
  1868. (should
  1869. (string=
  1870. "%5B"
  1871. (org-link-escape "["))))
  1872. (ert-deftest test-org/org-link-escape-ascii-ctrl-character ()
  1873. "Escape an ascii control character."
  1874. (should
  1875. (string=
  1876. "%09"
  1877. (org-link-escape "\t"))))
  1878. (ert-deftest test-org/org-link-escape-multibyte-character ()
  1879. "Escape an unicode multibyte character."
  1880. (should
  1881. (string=
  1882. "%E2%82%AC"
  1883. (org-link-escape "€"))))
  1884. (ert-deftest test-org/org-link-escape-custom-table ()
  1885. "Escape string with custom character table."
  1886. (should
  1887. (string=
  1888. "Foo%3A%42ar%0A"
  1889. (org-link-escape "Foo:Bar\n" '(?\: ?\B)))))
  1890. (ert-deftest test-org/org-link-escape-custom-table-merge ()
  1891. "Escape string with custom table merged with default table."
  1892. (should
  1893. (string=
  1894. "%5BF%6F%6F%3A%42ar%0A%5D"
  1895. (org-link-escape "[Foo:Bar\n]" '(?\: ?\B ?\o) t))))
  1896. (ert-deftest test-org/org-link-unescape-ascii-character ()
  1897. "Unescape an ascii character."
  1898. (should
  1899. (string=
  1900. "["
  1901. (org-link-unescape "%5B"))))
  1902. (ert-deftest test-org/org-link-unescape-ascii-ctrl-character ()
  1903. "Unescpae an ascii control character."
  1904. (should
  1905. (string=
  1906. "\n"
  1907. (org-link-unescape "%0A"))))
  1908. (ert-deftest test-org/org-link-unescape-multibyte-character ()
  1909. "Unescape unicode multibyte character."
  1910. (should
  1911. (string=
  1912. "€"
  1913. (org-link-unescape "%E2%82%AC"))))
  1914. (ert-deftest test-org/org-link-unescape-ascii-extended-char ()
  1915. "Unescape old style percent escaped character."
  1916. (should
  1917. (string=
  1918. "àâçèéêîôùû"
  1919. (decode-coding-string
  1920. (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1))))
  1921. (ert-deftest test-org/org-link-escape-url-with-escaped-char ()
  1922. "Escape and unescape a URL that includes an escaped char.
  1923. http://article.gmane.org/gmane.emacs.orgmode/21459/"
  1924. (should
  1925. (string=
  1926. "http://some.host.com/form?&id=blah%2Bblah25"
  1927. (org-link-unescape
  1928. (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
  1929. (ert-deftest test-org/org-link-escape-chars-browser ()
  1930. "Test of the constant `org-link-escape-chars-browser'.
  1931. See there why this test is a candidate to be removed once Org
  1932. drops support for Emacs 24.1 and 24.2."
  1933. (should
  1934. (string=
  1935. (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
  1936. "%22Release%208.2%22&idxname=emacs-orgmode")
  1937. (org-link-escape-browser ; Do not replace with `url-encode-url',
  1938. ; see docstring above.
  1939. (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
  1940. "\"Release 8.2\"&idxname=emacs-orgmode")))))
  1941. ;;;; Open at point
  1942. (ert-deftest test-org/open-at-point-in-keyword ()
  1943. "Does `org-open-at-point' open link in a keyword line?"
  1944. (should
  1945. (org-test-with-temp-text
  1946. "#+KEYWORD: <point>[[info:emacs#Top]]"
  1947. (org-open-at-point) t)))
  1948. (ert-deftest test-org/open-at-point-in-property ()
  1949. "Does `org-open-at-point' open link in property drawer?"
  1950. (should
  1951. (org-test-with-temp-text
  1952. "* Headline
  1953. :PROPERTIES:
  1954. :URL: <point>[[info:emacs#Top]]
  1955. :END:"
  1956. (org-open-at-point) t)))
  1957. (ert-deftest test-org/open-at-point-in-comment ()
  1958. "Does `org-open-at-point' open link in a commented line?"
  1959. (should
  1960. (org-test-with-temp-text
  1961. "# <point>[[info:emacs#Top]]"
  1962. (org-open-at-point) t)))
  1963. (ert-deftest test-org/open-at-point/info ()
  1964. "Test `org-open-at-point' on info links."
  1965. (should
  1966. (org-test-with-temp-text
  1967. "<point>[[info:emacs#Top]]"
  1968. (org-open-at-point)
  1969. (and (switch-to-buffer "*info*")
  1970. (prog1
  1971. (looking-at "\nThe Emacs Editor")
  1972. (kill-buffer))))))
  1973. (ert-deftest test-org/open-at-point/inline-image ()
  1974. "Test `org-open-at-point' on nested links."
  1975. (should
  1976. (org-test-with-temp-text "[[info:org#Top][info:<point>emacs#Top]]"
  1977. (org-open-at-point)
  1978. (prog1 (with-current-buffer "*info*" (looking-at "\nOrg Mode Manual"))
  1979. (kill-buffer "*info*")))))
  1980. (ert-deftest test-org/open-at-point/radio-target ()
  1981. "Test `org-open-at-point' on radio targets."
  1982. (should
  1983. (org-test-with-temp-text "<<<target>>> <point>target"
  1984. (org-update-radio-target-regexp)
  1985. (org-open-at-point)
  1986. (eq (org-element-type (org-element-context)) 'radio-target))))
  1987. ;;; Node Properties
  1988. (ert-deftest test-org/accumulated-properties-in-drawers ()
  1989. "Ensure properties accumulate in subtree drawers."
  1990. (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
  1991. (org-babel-next-src-block)
  1992. (should (equal '(2 1) (org-babel-execute-src-block)))))
  1993. (ert-deftest test-org/custom-properties ()
  1994. "Test custom properties specifications."
  1995. ;; Standard test.
  1996. (should
  1997. (let ((org-custom-properties '("FOO")))
  1998. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  1999. (org-toggle-custom-properties-visibility)
  2000. (org-invisible-p2))))
  2001. ;; Properties are case-insensitive.
  2002. (should
  2003. (let ((org-custom-properties '("FOO")))
  2004. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
  2005. (org-toggle-custom-properties-visibility)
  2006. (org-invisible-p2))))
  2007. (should
  2008. (let ((org-custom-properties '("foo")))
  2009. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2010. (org-toggle-custom-properties-visibility)
  2011. (org-invisible-p2))))
  2012. ;; Multiple custom properties in the same drawer.
  2013. (should
  2014. (let ((org-custom-properties '("FOO" "BAR")))
  2015. (org-test-with-temp-text
  2016. "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
  2017. (org-toggle-custom-properties-visibility)
  2018. (and (org-invisible-p2)
  2019. (not (progn (forward-line) (org-invisible-p2)))
  2020. (progn (forward-line) (org-invisible-p2))))))
  2021. ;; Hide custom properties with an empty value.
  2022. (should
  2023. (let ((org-custom-properties '("FOO")))
  2024. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
  2025. (org-toggle-custom-properties-visibility)
  2026. (org-invisible-p2))))
  2027. ;; Do not hide fake properties.
  2028. (should-not
  2029. (let ((org-custom-properties '("FOO")))
  2030. (org-test-with-temp-text ":FOO: val\n"
  2031. (org-toggle-custom-properties-visibility)
  2032. (org-invisible-p2))))
  2033. (should-not
  2034. (let ((org-custom-properties '("A")))
  2035. (org-test-with-temp-text
  2036. "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
  2037. (org-toggle-custom-properties-visibility)
  2038. (org-invisible-p2)))))
  2039. ;;; Mark Region
  2040. (ert-deftest test-org/mark-subtree ()
  2041. "Test `org-mark-subtree' specifications."
  2042. ;; Error when point is before first headline.
  2043. (should-error
  2044. (org-test-with-temp-text "Paragraph\n* Headline\nBody"
  2045. (progn (transient-mark-mode 1)
  2046. (org-mark-subtree))))
  2047. ;; Without argument, mark current subtree.
  2048. (should
  2049. (equal
  2050. '(12 32)
  2051. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  2052. (progn (transient-mark-mode 1)
  2053. (forward-line 2)
  2054. (org-mark-subtree)
  2055. (list (region-beginning) (region-end))))))
  2056. ;; With an argument, move ARG up.
  2057. (should
  2058. (equal
  2059. '(1 32)
  2060. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  2061. (progn (transient-mark-mode 1)
  2062. (forward-line 2)
  2063. (org-mark-subtree 1)
  2064. (list (region-beginning) (region-end))))))
  2065. ;; Do not get fooled by inlinetasks.
  2066. (when (featurep 'org-inlinetask)
  2067. (should
  2068. (= 1
  2069. (org-test-with-temp-text "* Headline\n*************** Task\nContents"
  2070. (progn (transient-mark-mode 1)
  2071. (forward-line 1)
  2072. (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
  2073. (region-beginning)))))))
  2074. ;;; Miscellaneous
  2075. (ert-deftest test-org/in-regexp ()
  2076. "Test `org-in-regexp' specifications."
  2077. ;; Standard tests.
  2078. (should
  2079. (org-test-with-temp-text "xx ab<point>c xx"
  2080. (org-in-regexp "abc")))
  2081. (should-not
  2082. (org-test-with-temp-text "xx abc <point>xx"
  2083. (org-in-regexp "abc")))
  2084. ;; Return non-nil even with multiple matching regexps in the same
  2085. ;; line.
  2086. (should
  2087. (org-test-with-temp-text "abc xx ab<point>c xx"
  2088. (org-in-regexp "abc")))
  2089. ;; With optional argument NLINES, check extra lines around point.
  2090. (should-not
  2091. (org-test-with-temp-text "A\nB<point>\nC"
  2092. (org-in-regexp "A\nB\nC")))
  2093. (should
  2094. (org-test-with-temp-text "A\nB<point>\nC"
  2095. (org-in-regexp "A\nB\nC" 1)))
  2096. (should-not
  2097. (org-test-with-temp-text "A\nB\nC<point>"
  2098. (org-in-regexp "A\nB\nC" 1)))
  2099. ;; When optional argument VISUALLY is non-nil, return nil if at
  2100. ;; regexp boundaries.
  2101. (should
  2102. (org-test-with-temp-text "xx abc<point> xx"
  2103. (org-in-regexp "abc")))
  2104. (should-not
  2105. (org-test-with-temp-text "xx abc<point> xx"
  2106. (org-in-regexp "abc" nil t))))
  2107. ;;; Navigation
  2108. (ert-deftest test-org/end-of-meta-data ()
  2109. "Test `org-end-of-meta-data' specifications."
  2110. ;; Skip planning line.
  2111. (should
  2112. (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
  2113. (org-end-of-meta-data)
  2114. (eobp)))
  2115. ;; Skip properties drawer.
  2116. (should
  2117. (org-test-with-temp-text
  2118. "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
  2119. (org-end-of-meta-data)
  2120. (eobp)))
  2121. ;; Skip both.
  2122. (should
  2123. (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
  2124. (org-end-of-meta-data)
  2125. (eobp)))
  2126. ;; Nothing to skip, go to first line.
  2127. (should
  2128. (org-test-with-temp-text "* Headline\nContents"
  2129. (org-end-of-meta-data)
  2130. (looking-at "Contents")))
  2131. ;; With option argument, skip empty lines, regular drawers and
  2132. ;; clocking lines.
  2133. (should
  2134. (org-test-with-temp-text "* Headline\n\nContents"
  2135. (org-end-of-meta-data t)
  2136. (looking-at "Contents")))
  2137. (should
  2138. (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
  2139. (org-end-of-meta-data t)
  2140. (looking-at "Contents")))
  2141. (should
  2142. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
  2143. (org-end-of-meta-data t)
  2144. (looking-at "Contents")))
  2145. ;; Special case: do not skip incomplete drawers.
  2146. (should
  2147. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
  2148. (org-end-of-meta-data t)
  2149. (looking-at ":LOGBOOK:")))
  2150. ;; Special case: Be careful about consecutive headlines.
  2151. (should-not
  2152. (org-test-with-temp-text "* H1\n*H2\nContents"
  2153. (org-end-of-meta-data t)
  2154. (looking-at "Contents"))))
  2155. (ert-deftest test-org/beginning-of-line ()
  2156. "Test `org-beginning-of-line' specifications."
  2157. ;; Standard test.
  2158. (should
  2159. (org-test-with-temp-text "Some text\nSome other text"
  2160. (progn (org-beginning-of-line) (bolp))))
  2161. ;; Standard test with `visual-line-mode'.
  2162. (should-not
  2163. (org-test-with-temp-text "A long line of text\nSome other text"
  2164. (progn (visual-line-mode)
  2165. (forward-char 2)
  2166. (dotimes (i 1000) (insert "very "))
  2167. (org-beginning-of-line)
  2168. (bolp))))
  2169. ;; At an headline with special movement.
  2170. (should
  2171. (org-test-with-temp-text "* TODO Headline"
  2172. (let ((org-special-ctrl-a/e t))
  2173. (org-end-of-line)
  2174. (and (progn (org-beginning-of-line) (looking-at "Headline"))
  2175. (progn (org-beginning-of-line) (bolp))
  2176. (progn (org-beginning-of-line) (looking-at "Headline"))))))
  2177. ;; Special case: Do not error when the buffer contains only a single
  2178. ;; asterisk.
  2179. (should
  2180. (org-test-with-temp-text "*<point>"
  2181. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line))))
  2182. (should
  2183. (org-test-with-temp-text "*<point>"
  2184. (let ((org-special-ctrl-a/e nil)) (org-beginning-of-line)))))
  2185. (ert-deftest test-org/end-of-line ()
  2186. "Test `org-end-of-line' specifications."
  2187. ;; Standard test.
  2188. (should
  2189. (org-test-with-temp-text "Some text\nSome other text"
  2190. (progn (org-end-of-line) (eolp))))
  2191. ;; Standard test with `visual-line-mode'.
  2192. (should-not
  2193. (org-test-with-temp-text "A long line of text\nSome other text"
  2194. (progn (visual-line-mode)
  2195. (forward-char 2)
  2196. (dotimes (i 1000) (insert "very "))
  2197. (goto-char (point-min))
  2198. (org-end-of-line)
  2199. (eolp))))
  2200. ;; At an headline with special movement.
  2201. (should
  2202. (org-test-with-temp-text "* Headline1 :tag:\n"
  2203. (let ((org-special-ctrl-a/e t))
  2204. (and (progn (org-end-of-line) (looking-at " :tag:"))
  2205. (progn (org-end-of-line) (eolp))
  2206. (progn (org-end-of-line) (looking-at " :tag:"))))))
  2207. ;; At an headline without special movement.
  2208. (should
  2209. (org-test-with-temp-text "* Headline2 :tag:\n"
  2210. (let ((org-special-ctrl-a/e nil))
  2211. (and (progn (org-end-of-line) (eolp))
  2212. (progn (org-end-of-line) (eolp))))))
  2213. ;; At an headline, with reversed movement.
  2214. (should
  2215. (org-test-with-temp-text "* Headline3 :tag:\n"
  2216. (let ((org-special-ctrl-a/e 'reversed)
  2217. (this-command last-command))
  2218. (and (progn (org-end-of-line) (eolp))
  2219. (progn (org-end-of-line) (looking-at " :tag:"))))))
  2220. ;; At a block without hidden contents.
  2221. (should
  2222. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  2223. (progn (org-end-of-line) (eolp))))
  2224. ;; At a block with hidden contents.
  2225. (should-not
  2226. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  2227. (let ((org-special-ctrl-a/e t))
  2228. (org-hide-block-toggle)
  2229. (org-end-of-line)
  2230. (eobp)))))
  2231. (ert-deftest test-org/forward-sentence ()
  2232. "Test `org-forward-sentence' specifications."
  2233. ;; At the end of a table cell, move to the end of the next one.
  2234. (should
  2235. (org-test-with-temp-text "| a<point> | b |"
  2236. (org-forward-sentence)
  2237. (looking-at " |$")))
  2238. ;; Elsewhere in a cell, move to its end.
  2239. (should
  2240. (org-test-with-temp-text "| a<point>c | b |"
  2241. (org-forward-sentence)
  2242. (looking-at " | b |$")))
  2243. ;; Otherwise, simply call `forward-sentence'.
  2244. (should
  2245. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  2246. (org-forward-sentence)
  2247. (looking-at " Sentence 2.")))
  2248. (should
  2249. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  2250. (org-forward-sentence)
  2251. (org-forward-sentence)
  2252. (eobp)))
  2253. ;; At the end of an element, jump to the next one, without stopping
  2254. ;; on blank lines in-between.
  2255. (should
  2256. (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
  2257. (org-forward-sentence)
  2258. (eobp))))
  2259. (ert-deftest test-org/backward-sentence ()
  2260. "Test `org-backward-sentence' specifications."
  2261. ;; At the beginning of a table cell, move to the beginning of the
  2262. ;; previous one.
  2263. (should
  2264. (org-test-with-temp-text "| a | <point>b |"
  2265. (org-backward-sentence)
  2266. (looking-at "a | b |$")))
  2267. ;; Elsewhere in a cell, move to its beginning.
  2268. (should
  2269. (org-test-with-temp-text "| a | b<point>c |"
  2270. (org-backward-sentence)
  2271. (looking-at "bc |$")))
  2272. ;; Otherwise, simply call `backward-sentence'.
  2273. (should
  2274. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  2275. (org-backward-sentence)
  2276. (looking-at "Sentence 2.")))
  2277. (should
  2278. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  2279. (org-backward-sentence)
  2280. (org-backward-sentence)
  2281. (bobp)))
  2282. ;; Make sure to hit the beginning of a sentence on the same line as
  2283. ;; an item.
  2284. (should
  2285. (org-test-with-temp-text "- Line 1\n line <point>2."
  2286. (org-backward-sentence)
  2287. (looking-at "Line 1"))))
  2288. (ert-deftest test-org/forward-paragraph ()
  2289. "Test `org-forward-paragraph' specifications."
  2290. ;; At end of buffer, return an error.
  2291. (should-error
  2292. (org-test-with-temp-text "Paragraph"
  2293. (goto-char (point-max))
  2294. (org-forward-paragraph)))
  2295. ;; Standard test.
  2296. (should
  2297. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  2298. (org-forward-paragraph)
  2299. (looking-at "P2")))
  2300. ;; Ignore depth.
  2301. (should
  2302. (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
  2303. (org-forward-paragraph)
  2304. (looking-at "P1")))
  2305. ;; Do not enter elements with invisible contents.
  2306. (should
  2307. (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
  2308. (org-hide-block-toggle)
  2309. (org-forward-paragraph)
  2310. (looking-at "P3")))
  2311. ;; On an affiliated keyword, jump to the beginning of the element.
  2312. (should
  2313. (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
  2314. (org-forward-paragraph)
  2315. (looking-at "Para")))
  2316. ;; On an item or a footnote definition, move to the second element
  2317. ;; inside, if any.
  2318. (should
  2319. (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
  2320. (org-forward-paragraph)
  2321. (looking-at " Paragraph")))
  2322. (should
  2323. (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
  2324. (org-forward-paragraph)
  2325. (looking-at "Paragraph")))
  2326. ;; On an item, or a footnote definition, when the first line is
  2327. ;; empty, move to the first item.
  2328. (should
  2329. (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
  2330. (org-forward-paragraph)
  2331. (looking-at " Paragraph")))
  2332. (should
  2333. (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
  2334. (org-forward-paragraph)
  2335. (looking-at "Paragraph")))
  2336. ;; On a table (resp. a property drawer) do not move through table
  2337. ;; rows (resp. node properties).
  2338. (should
  2339. (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
  2340. (org-forward-paragraph)
  2341. (looking-at "Paragraph")))
  2342. (should
  2343. (org-test-with-temp-text
  2344. "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
  2345. (org-forward-paragraph)
  2346. (looking-at "Paragraph")))
  2347. ;; On a verse or source block, stop after blank lines.
  2348. (should
  2349. (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
  2350. (org-forward-paragraph)
  2351. (looking-at "L2")))
  2352. (should
  2353. (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
  2354. (org-forward-paragraph)
  2355. (looking-at "L2"))))
  2356. (ert-deftest test-org/backward-paragraph ()
  2357. "Test `org-backward-paragraph' specifications."
  2358. ;; Error at beginning of buffer.
  2359. (should-error
  2360. (org-test-with-temp-text "Paragraph"
  2361. (org-backward-paragraph)))
  2362. ;; Regular test.
  2363. (should
  2364. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  2365. (goto-char (point-max))
  2366. (org-backward-paragraph)
  2367. (looking-at "P3")))
  2368. (should
  2369. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  2370. (goto-char (point-max))
  2371. (beginning-of-line)
  2372. (org-backward-paragraph)
  2373. (looking-at "P2")))
  2374. ;; Ignore depth.
  2375. (should
  2376. (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
  2377. (goto-char (point-max))
  2378. (beginning-of-line)
  2379. (org-backward-paragraph)
  2380. (looking-at "P2")))
  2381. ;; Ignore invisible elements.
  2382. (should
  2383. (org-test-with-temp-text "* H1\n P1\n* H2"
  2384. (org-cycle)
  2385. (goto-char (point-max))
  2386. (beginning-of-line)
  2387. (org-backward-paragraph)
  2388. (bobp)))
  2389. ;; On an affiliated keyword, jump to the first one.
  2390. (should
  2391. (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
  2392. (search-forward "c2")
  2393. (org-backward-paragraph)
  2394. (looking-at "#\\+name")))
  2395. ;; On the second element in an item or a footnote definition, jump
  2396. ;; to item or the definition.
  2397. (should
  2398. (org-test-with-temp-text "- line1\n\n line2"
  2399. (goto-char (point-max))
  2400. (beginning-of-line)
  2401. (org-backward-paragraph)
  2402. (looking-at "- line1")))
  2403. (should
  2404. (org-test-with-temp-text "[fn:1] line1\n\n line2"
  2405. (goto-char (point-max))
  2406. (beginning-of-line)
  2407. (org-backward-paragraph)
  2408. (looking-at "\\[fn:1\\] line1")))
  2409. ;; On a table (resp. a property drawer), ignore table rows
  2410. ;; (resp. node properties).
  2411. (should
  2412. (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
  2413. (goto-char (point-max))
  2414. (beginning-of-line)
  2415. (org-backward-paragraph)
  2416. (bobp)))
  2417. (should
  2418. (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
  2419. (org-backward-paragraph)
  2420. (looking-at ":PROPERTIES:")))
  2421. ;; On a source or verse block, stop before blank lines.
  2422. (should
  2423. (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
  2424. (search-forward "L3")
  2425. (beginning-of-line)
  2426. (org-backward-paragraph)
  2427. (looking-at "L2")))
  2428. (should
  2429. (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
  2430. (search-forward "L3")
  2431. (beginning-of-line)
  2432. (org-backward-paragraph)
  2433. (looking-at "L2"))))
  2434. (ert-deftest test-org/forward-element ()
  2435. "Test `org-forward-element' specifications."
  2436. ;; 1. At EOB: should error.
  2437. (org-test-with-temp-text "Some text\n"
  2438. (goto-char (point-max))
  2439. (should-error (org-forward-element)))
  2440. ;; 2. Standard move: expected to ignore blank lines.
  2441. (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
  2442. (org-forward-element)
  2443. (should (looking-at (regexp-quote "Second paragraph."))))
  2444. ;; 3. Headline tests.
  2445. (org-test-with-temp-text "
  2446. * Head 1
  2447. ** Head 1.1
  2448. *** Head 1.1.1
  2449. ** Head 1.2"
  2450. ;; 3.1. At an headline beginning: move to next headline at the
  2451. ;; same level.
  2452. (goto-line 3)
  2453. (org-forward-element)
  2454. (should (looking-at (regexp-quote "** Head 1.2")))
  2455. ;; 3.2. At an headline beginning: move to parent headline if no
  2456. ;; headline at the same level.
  2457. (goto-line 3)
  2458. (org-forward-element)
  2459. (should (looking-at (regexp-quote "** Head 1.2"))))
  2460. ;; 4. Greater element tests.
  2461. (org-test-with-temp-text
  2462. "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
  2463. ;; 4.1. At a greater element: expected to skip contents.
  2464. (org-forward-element)
  2465. (should (looking-at (regexp-quote "Outside.")))
  2466. ;; 4.2. At the end of greater element contents: expected to skip
  2467. ;; to the end of the greater element.
  2468. (goto-line 2)
  2469. (org-forward-element)
  2470. (should (looking-at (regexp-quote "Outside."))))
  2471. ;; 5. List tests.
  2472. (org-test-with-temp-text "
  2473. - item1
  2474. - sub1
  2475. - sub2
  2476. - sub3
  2477. Inner paragraph.
  2478. - item2
  2479. Outside."
  2480. ;; 5.1. At list top point: expected to move to the element after
  2481. ;; the list.
  2482. (goto-line 2)
  2483. (org-forward-element)
  2484. (should (looking-at (regexp-quote "Outside.")))
  2485. ;; 5.2. Special case: at the first line of a sub-list, but not at
  2486. ;; beginning of line, move to next item.
  2487. (goto-line 2)
  2488. (forward-char)
  2489. (org-forward-element)
  2490. (should (looking-at "- item2"))
  2491. (goto-line 4)
  2492. (forward-char)
  2493. (org-forward-element)
  2494. (should (looking-at " - sub2"))
  2495. ;; 5.3 At sub-list beginning: expected to move after the sub-list.
  2496. (goto-line 4)
  2497. (org-forward-element)
  2498. (should (looking-at (regexp-quote " Inner paragraph.")))
  2499. ;; 5.4. At sub-list end: expected to move outside the sub-list.
  2500. (goto-line 8)
  2501. (org-forward-element)
  2502. (should (looking-at (regexp-quote " Inner paragraph.")))
  2503. ;; 5.5. At an item: expected to move to next item, if any.
  2504. (goto-line 6)
  2505. (org-forward-element)
  2506. (should (looking-at " - sub3"))))
  2507. (ert-deftest test-org/backward-element ()
  2508. "Test `org-backward-element' specifications."
  2509. ;; 1. Should error at BOB.
  2510. (org-test-with-temp-text " \nParagraph."
  2511. (should-error (org-backward-element)))
  2512. ;; 2. Should move at BOB when called on the first element in buffer.
  2513. (should
  2514. (org-test-with-temp-text "\n#+TITLE: test"
  2515. (progn (forward-line)
  2516. (org-backward-element)
  2517. (bobp))))
  2518. ;; 3. Not at the beginning of an element: move at its beginning.
  2519. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  2520. (goto-line 3)
  2521. (end-of-line)
  2522. (org-backward-element)
  2523. (should (looking-at (regexp-quote "Paragraph2."))))
  2524. ;; 4. Headline tests.
  2525. (org-test-with-temp-text "
  2526. * Head 1
  2527. ** Head 1.1
  2528. *** Head 1.1.1
  2529. ** Head 1.2"
  2530. ;; 4.1. At an headline beginning: move to previous headline at the
  2531. ;; same level.
  2532. (goto-line 5)
  2533. (org-backward-element)
  2534. (should (looking-at (regexp-quote "** Head 1.1")))
  2535. ;; 4.2. At an headline beginning: move to parent headline if no
  2536. ;; headline at the same level.
  2537. (goto-line 3)
  2538. (org-backward-element)
  2539. (should (looking-at (regexp-quote "* Head 1")))
  2540. ;; 4.3. At the first top-level headline: should error.
  2541. (goto-line 2)
  2542. (should-error (org-backward-element)))
  2543. ;; 5. At beginning of first element inside a greater element:
  2544. ;; expected to move to greater element's beginning.
  2545. (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
  2546. (goto-line 3)
  2547. (org-backward-element)
  2548. (should (looking-at "#\\+BEGIN_CENTER")))
  2549. ;; 6. At the beginning of the first element in a section: should
  2550. ;; move back to headline, if any.
  2551. (should
  2552. (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
  2553. (progn (goto-char (point-max))
  2554. (beginning-of-line)
  2555. (org-backward-element)
  2556. (org-at-heading-p))))
  2557. ;; 7. List tests.
  2558. (org-test-with-temp-text "
  2559. - item1
  2560. - sub1
  2561. - sub2
  2562. - sub3
  2563. Inner paragraph.
  2564. - item2
  2565. Outside."
  2566. ;; 7.1. At beginning of sub-list: expected to move to the
  2567. ;; paragraph before it.
  2568. (goto-line 4)
  2569. (org-backward-element)
  2570. (should (looking-at "item1"))
  2571. ;; 7.2. At an item in a list: expected to move at previous item.
  2572. (goto-line 8)
  2573. (org-backward-element)
  2574. (should (looking-at " - sub2"))
  2575. (goto-line 12)
  2576. (org-backward-element)
  2577. (should (looking-at "- item1"))
  2578. ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
  2579. ;; beginning.
  2580. (goto-line 10)
  2581. (org-backward-element)
  2582. (should (looking-at " - sub1"))
  2583. (goto-line 15)
  2584. (org-backward-element)
  2585. (should (looking-at "- item1"))
  2586. ;; 7.4. At blank-lines before list end: expected to move to top
  2587. ;; item.
  2588. (goto-line 14)
  2589. (org-backward-element)
  2590. (should (looking-at "- item1"))))
  2591. (ert-deftest test-org/up-element ()
  2592. "Test `org-up-element' specifications."
  2593. ;; 1. At BOB or with no surrounding element: should error.
  2594. (org-test-with-temp-text "Paragraph."
  2595. (should-error (org-up-element)))
  2596. (org-test-with-temp-text "* Head1\n* Head2"
  2597. (goto-line 2)
  2598. (should-error (org-up-element)))
  2599. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  2600. (goto-line 3)
  2601. (should-error (org-up-element)))
  2602. ;; 2. At an headline: move to parent headline.
  2603. (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
  2604. (goto-line 3)
  2605. (org-up-element)
  2606. (should (looking-at "\\* Head1")))
  2607. ;; 3. Inside a greater element: move to greater element beginning.
  2608. (org-test-with-temp-text
  2609. "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
  2610. (goto-line 3)
  2611. (org-up-element)
  2612. (should (looking-at "#\\+BEGIN_CENTER")))
  2613. ;; 4. List tests.
  2614. (org-test-with-temp-text "* Top
  2615. - item1
  2616. - sub1
  2617. - sub2
  2618. Paragraph within sub2.
  2619. - item2"
  2620. ;; 4.1. Within an item: move to the item beginning.
  2621. (goto-line 8)
  2622. (org-up-element)
  2623. (should (looking-at " - sub2"))
  2624. ;; 4.2. At an item in a sub-list: move to parent item.
  2625. (goto-line 4)
  2626. (org-up-element)
  2627. (should (looking-at "- item1"))
  2628. ;; 4.3. At an item in top list: move to beginning of whole list.
  2629. (goto-line 10)
  2630. (org-up-element)
  2631. (should (looking-at "- item1"))
  2632. ;; 4.4. Special case. At very top point: should move to parent of
  2633. ;; list.
  2634. (goto-line 2)
  2635. (org-up-element)
  2636. (should (looking-at "\\* Top"))))
  2637. (ert-deftest test-org/down-element ()
  2638. "Test `org-down-element' specifications."
  2639. ;; Error when the element hasn't got a recursive type.
  2640. (org-test-with-temp-text "Paragraph."
  2641. (should-error (org-down-element)))
  2642. ;; Error when the element has no contents
  2643. (org-test-with-temp-text "* Headline"
  2644. (should-error (org-down-element)))
  2645. ;; When at a plain-list, move to first item.
  2646. (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
  2647. (goto-line 2)
  2648. (org-down-element)
  2649. (should (looking-at " - Item 1.1")))
  2650. (org-test-with-temp-text "#+NAME: list\n- Item 1"
  2651. (org-down-element)
  2652. (should (looking-at " Item 1")))
  2653. ;; When at a table, move to first row
  2654. (org-test-with-temp-text "#+NAME: table\n| a | b |"
  2655. (org-down-element)
  2656. (should (looking-at " a | b |")))
  2657. ;; Otherwise, move inside the greater element.
  2658. (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
  2659. (org-down-element)
  2660. (should (looking-at "Paragraph"))))
  2661. (ert-deftest test-org/drag-element-backward ()
  2662. "Test `org-drag-element-backward' specifications."
  2663. ;; Standard test.
  2664. (should
  2665. (equal
  2666. "#+key2: val2\n#+key1: val1\n#+key3: val3"
  2667. (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
  2668. (org-drag-element-backward)
  2669. (buffer-string))))
  2670. (should
  2671. (equal
  2672. "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
  2673. (org-test-with-temp-text
  2674. "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
  2675. (org-drag-element-backward)
  2676. (buffer-string))))
  2677. ;; Preserve blank lines.
  2678. (should
  2679. (equal "Paragraph 2\n\n\nPara1\n\nPara3"
  2680. (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
  2681. (org-drag-element-backward)
  2682. (buffer-string))))
  2683. ;; Preserve column.
  2684. (should
  2685. (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
  2686. (org-drag-element-backward)
  2687. (org-looking-at-p "2")))
  2688. ;; Error when trying to move first element of buffer.
  2689. (should-error
  2690. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  2691. (org-drag-element-backward)))
  2692. ;; Error when trying to swap nested elements.
  2693. (should-error
  2694. (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
  2695. (forward-line)
  2696. (org-drag-element-backward)))
  2697. ;; Error when trying to swap an headline element and a non-headline
  2698. ;; element.
  2699. (should-error
  2700. (org-test-with-temp-text "Test.\n* Head 1"
  2701. (forward-line)
  2702. (org-drag-element-backward)))
  2703. ;; Preserve visibility of elements and their contents.
  2704. (should
  2705. (equal '((63 . 82) (26 . 48))
  2706. (org-test-with-temp-text "
  2707. #+BEGIN_CENTER
  2708. Text.
  2709. #+END_CENTER
  2710. - item 1
  2711. #+BEGIN_QUOTE
  2712. Text.
  2713. #+END_QUOTE"
  2714. (while (search-forward "BEGIN_" nil t) (org-cycle))
  2715. (search-backward "- item 1")
  2716. (org-drag-element-backward)
  2717. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  2718. (overlays-in (point-min) (point-max)))))))
  2719. (ert-deftest test-org/drag-element-forward ()
  2720. "Test `org-drag-element-forward' specifications."
  2721. ;; 1. Error when trying to move first element of buffer.
  2722. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  2723. (goto-line 3)
  2724. (should-error (org-drag-element-forward)))
  2725. ;; 2. Error when trying to swap nested elements.
  2726. (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
  2727. (forward-line)
  2728. (should-error (org-drag-element-forward)))
  2729. ;; 3. Error when trying to swap a non-headline element and an
  2730. ;; headline.
  2731. (org-test-with-temp-text "Test.\n* Head 1"
  2732. (should-error (org-drag-element-forward)))
  2733. ;; 4. Otherwise, swap elements, preserving column and blank lines
  2734. ;; between elements.
  2735. (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
  2736. (search-forward "graph")
  2737. (org-drag-element-forward)
  2738. (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
  2739. (should (looking-at " 1")))
  2740. ;; 5. Preserve visibility of elements and their contents.
  2741. (org-test-with-temp-text "
  2742. #+BEGIN_CENTER
  2743. Text.
  2744. #+END_CENTER
  2745. - item 1
  2746. #+BEGIN_QUOTE
  2747. Text.
  2748. #+END_QUOTE"
  2749. (while (search-forward "BEGIN_" nil t) (org-cycle))
  2750. (search-backward "#+BEGIN_CENTER")
  2751. (org-drag-element-forward)
  2752. (should
  2753. (equal
  2754. '((63 . 82) (26 . 48))
  2755. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  2756. (overlays-in (point-min) (point-max)))))))
  2757. (ert-deftest test-org/next-block ()
  2758. "Test `org-next-block' specifications."
  2759. ;; Regular test.
  2760. (should
  2761. (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  2762. (org-next-block 1)
  2763. (looking-at "#\\+BEGIN_CENTER")))
  2764. ;; Ignore case.
  2765. (should
  2766. (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
  2767. (let ((case-fold-search nil))
  2768. (org-next-block 1)
  2769. (looking-at "#\\+begin_center"))))
  2770. ;; Ignore current line.
  2771. (should
  2772. (org-test-with-temp-text
  2773. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
  2774. (org-next-block 1)
  2775. (looking-at "#\\+BEGIN_CENTER")))
  2776. ;; Throw an error when no block is found.
  2777. (should-error
  2778. (org-test-with-temp-text "Paragraph"
  2779. (org-next-block 1)))
  2780. ;; With an argument, skip many blocks at once.
  2781. (should
  2782. (org-test-with-temp-text
  2783. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  2784. (org-next-block 2)
  2785. (looking-at "#\\+BEGIN_QUOTE")))
  2786. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  2787. (should
  2788. (org-test-with-temp-text
  2789. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  2790. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  2791. (looking-at "#\\+BEGIN_QUOTE")))
  2792. ;; Optional argument is also case-insensitive.
  2793. (should
  2794. (org-test-with-temp-text
  2795. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
  2796. (let ((case-fold-search nil))
  2797. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  2798. (looking-at "#\\+begin_quote")))))
  2799. (ert-deftest test-org/previous-block ()
  2800. "Test `org-previous-block' specifications."
  2801. ;; Regular test.
  2802. (should
  2803. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
  2804. (org-previous-block 1)
  2805. (looking-at "#\\+BEGIN_CENTER")))
  2806. ;; Ignore case.
  2807. (should
  2808. (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
  2809. (let ((case-fold-search nil))
  2810. (org-previous-block 1)
  2811. (looking-at "#\\+begin_center"))))
  2812. ;; Ignore current line.
  2813. (should
  2814. (org-test-with-temp-text
  2815. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
  2816. (org-previous-block 1)
  2817. (looking-at "#\\+BEGIN_QUOTE")))
  2818. ;; Throw an error when no block is found.
  2819. (should-error
  2820. (org-test-with-temp-text "Paragraph<point>"
  2821. (org-previous-block 1)))
  2822. ;; With an argument, skip many blocks at once.
  2823. (should
  2824. (org-test-with-temp-text
  2825. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  2826. (org-previous-block 2)
  2827. (looking-at "#\\+BEGIN_CENTER")))
  2828. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  2829. (should
  2830. (org-test-with-temp-text
  2831. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  2832. (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  2833. (looking-at "#\\+BEGIN_QUOTE")))
  2834. ;; Optional argument is also case-insensitive.
  2835. (should
  2836. (org-test-with-temp-text
  2837. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
  2838. (let ((case-fold-search nil))
  2839. (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  2840. (looking-at "#\\+begin_quote")))))
  2841. ;;; Outline structure
  2842. (ert-deftest test-org/demote ()
  2843. "Test `org-demote' specifications."
  2844. ;; Add correct number of stars according to `org-odd-levels-only'.
  2845. (should
  2846. (= 2
  2847. (org-test-with-temp-text "* H"
  2848. (let ((org-odd-levels-only nil)) (org-demote))
  2849. (org-current-level))))
  2850. (should
  2851. (= 3
  2852. (org-test-with-temp-text "* H"
  2853. (let ((org-odd-levels-only t)) (org-demote))
  2854. (org-current-level))))
  2855. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  2856. (should
  2857. (org-test-with-temp-text "* H :tag:"
  2858. (let ((org-tags-column 10)
  2859. (org-auto-align-tags t)
  2860. (org-odd-levels-only nil))
  2861. (org-demote))
  2862. (org-move-to-column 10)
  2863. (org-looking-at-p ":tag:$")))
  2864. (should-not
  2865. (org-test-with-temp-text "* H :tag:"
  2866. (let ((org-tags-column 10)
  2867. (org-auto-align-tags nil)
  2868. (org-odd-levels-only nil))
  2869. (org-demote))
  2870. (org-move-to-column 10)
  2871. (org-looking-at-p ":tag:$")))
  2872. ;; When `org-adapt-indentation' is non-nil, always indent planning
  2873. ;; info and property drawers accordingly.
  2874. (should
  2875. (= 3
  2876. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  2877. (let ((org-odd-levels-only nil)
  2878. (org-adapt-indentation t))
  2879. (org-demote))
  2880. (forward-line)
  2881. (org-get-indentation))))
  2882. (should
  2883. (= 3
  2884. (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  2885. (let ((org-odd-levels-only nil)
  2886. (org-adapt-indentation t))
  2887. (org-demote))
  2888. (forward-line)
  2889. (org-get-indentation))))
  2890. (should-not
  2891. (= 3
  2892. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  2893. (let ((org-odd-levels-only nil)
  2894. (org-adapt-indentation nil))
  2895. (org-demote))
  2896. (forward-line)
  2897. (org-get-indentation))))
  2898. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  2899. ;; section accordingly. Ignore, however, footnote definitions and
  2900. ;; inlinetasks boundaries.
  2901. (should
  2902. (= 3
  2903. (org-test-with-temp-text "* H\n Paragraph"
  2904. (let ((org-odd-levels-only nil)
  2905. (org-adapt-indentation t))
  2906. (org-demote))
  2907. (forward-line)
  2908. (org-get-indentation))))
  2909. (should
  2910. (= 2
  2911. (org-test-with-temp-text "* H\n Paragraph"
  2912. (let ((org-odd-levels-only nil)
  2913. (org-adapt-indentation nil))
  2914. (org-demote))
  2915. (forward-line)
  2916. (org-get-indentation))))
  2917. (should
  2918. (zerop
  2919. (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
  2920. (let ((org-odd-levels-only nil)
  2921. (org-adapt-indentation t))
  2922. (org-demote))
  2923. (goto-char (point-max))
  2924. (org-get-indentation))))
  2925. (should
  2926. (= 3
  2927. (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
  2928. (let ((org-odd-levels-only nil)
  2929. (org-adapt-indentation t))
  2930. (org-demote))
  2931. (goto-char (point-max))
  2932. (org-get-indentation))))
  2933. (when (featurep 'org-inlinetask)
  2934. (should
  2935. (zerop
  2936. (let ((org-inlinetask-min-level 5)
  2937. (org-adapt-indentation t))
  2938. (org-test-with-temp-text "* H\n***** I\n***** END"
  2939. (org-demote)
  2940. (forward-line)
  2941. (org-get-indentation))))))
  2942. (when (featurep 'org-inlinetask)
  2943. (should
  2944. (= 3
  2945. (let ((org-inlinetask-min-level 5)
  2946. (org-adapt-indentation t))
  2947. (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
  2948. (org-demote)
  2949. (forward-line 2)
  2950. (org-get-indentation))))))
  2951. ;; Ignore contents of source blocks or example blocks when
  2952. ;; indentation should be preserved (through
  2953. ;; `org-src-preserve-indentation' or "-i" flag).
  2954. (should-not
  2955. (zerop
  2956. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  2957. (let ((org-adapt-indentation t)
  2958. (org-src-preserve-indentation nil))
  2959. (org-demote))
  2960. (forward-line 2)
  2961. (org-get-indentation))))
  2962. (should
  2963. (zerop
  2964. (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
  2965. (let ((org-adapt-indentation t)
  2966. (org-src-preserve-indentation t))
  2967. (org-demote))
  2968. (forward-line 2)
  2969. (org-get-indentation))))
  2970. (should
  2971. (zerop
  2972. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  2973. (let ((org-adapt-indentation t)
  2974. (org-src-preserve-indentation t))
  2975. (org-demote))
  2976. (forward-line 2)
  2977. (org-get-indentation))))
  2978. (should
  2979. (zerop
  2980. (org-test-with-temp-text
  2981. "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
  2982. (let ((org-adapt-indentation t)
  2983. (org-src-preserve-indentation nil))
  2984. (org-demote))
  2985. (forward-line 2)
  2986. (org-get-indentation)))))
  2987. (ert-deftest test-org/promote ()
  2988. "Test `org-promote' specifications."
  2989. ;; Return an error if headline is to be promoted to level 0, unless
  2990. ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
  2991. ;; headline becomes a comment.
  2992. (should-error
  2993. (org-test-with-temp-text "* H"
  2994. (let ((org-allow-promoting-top-level-subtree nil)) (org-promote))))
  2995. (should
  2996. (equal "# H"
  2997. (org-test-with-temp-text "* H"
  2998. (let ((org-allow-promoting-top-level-subtree t)) (org-promote))
  2999. (buffer-string))))
  3000. ;; Remove correct number of stars according to
  3001. ;; `org-odd-levels-only'.
  3002. (should
  3003. (= 2
  3004. (org-test-with-temp-text "*** H"
  3005. (let ((org-odd-levels-only nil)) (org-promote))
  3006. (org-current-level))))
  3007. (should
  3008. (= 1
  3009. (org-test-with-temp-text "*** H"
  3010. (let ((org-odd-levels-only t)) (org-promote))
  3011. (org-current-level))))
  3012. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  3013. (should
  3014. (org-test-with-temp-text "** H :tag:"
  3015. (let ((org-tags-column 10)
  3016. (org-auto-align-tags t)
  3017. (org-odd-levels-only nil))
  3018. (org-promote))
  3019. (org-move-to-column 10)
  3020. (org-looking-at-p ":tag:$")))
  3021. (should-not
  3022. (org-test-with-temp-text "** H :tag:"
  3023. (let ((org-tags-column 10)
  3024. (org-auto-align-tags nil)
  3025. (org-odd-levels-only nil))
  3026. (org-promote))
  3027. (org-move-to-column 10)
  3028. (org-looking-at-p ":tag:$")))
  3029. ;; When `org-adapt-indentation' is non-nil, always indent planning
  3030. ;; info and property drawers.
  3031. (should
  3032. (= 2
  3033. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  3034. (let ((org-odd-levels-only nil)
  3035. (org-adapt-indentation t))
  3036. (org-promote))
  3037. (forward-line)
  3038. (org-get-indentation))))
  3039. (should
  3040. (= 2
  3041. (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  3042. (let ((org-odd-levels-only nil)
  3043. (org-adapt-indentation t))
  3044. (org-promote))
  3045. (forward-line)
  3046. (org-get-indentation))))
  3047. (should-not
  3048. (= 2
  3049. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  3050. (let ((org-odd-levels-only nil)
  3051. (org-adapt-indentation nil))
  3052. (org-promote))
  3053. (forward-line)
  3054. (org-get-indentation))))
  3055. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  3056. ;; section accordingly. Ignore, however, footnote definitions and
  3057. ;; inlinetasks boundaries.
  3058. (should
  3059. (= 2
  3060. (org-test-with-temp-text "** H\n Paragraph"
  3061. (let ((org-odd-levels-only nil)
  3062. (org-adapt-indentation t))
  3063. (org-promote))
  3064. (forward-line)
  3065. (org-get-indentation))))
  3066. (should-not
  3067. (= 2
  3068. (org-test-with-temp-text "** H\n Paragraph"
  3069. (let ((org-odd-levels-only nil)
  3070. (org-adapt-indentation nil))
  3071. (org-promote))
  3072. (forward-line)
  3073. (org-get-indentation))))
  3074. (should
  3075. (= 2
  3076. (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
  3077. (let ((org-odd-levels-only nil)
  3078. (org-adapt-indentation t))
  3079. (org-promote))
  3080. (forward-line)
  3081. (org-get-indentation))))
  3082. (when (featurep 'org-inlinetask)
  3083. (should
  3084. (zerop
  3085. (let ((org-inlinetask-min-level 5)
  3086. (org-adapt-indentation t))
  3087. (org-test-with-temp-text "** H\n***** I\n***** END"
  3088. (org-promote)
  3089. (forward-line)
  3090. (org-get-indentation))))))
  3091. (when (featurep 'org-inlinetask)
  3092. (should
  3093. (= 2
  3094. (let ((org-inlinetask-min-level 5)
  3095. (org-adapt-indentation t))
  3096. (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
  3097. (org-promote)
  3098. (forward-line 2)
  3099. (org-get-indentation))))))
  3100. ;; Give up shifting if it would break document's structure
  3101. ;; otherwise.
  3102. (should
  3103. (= 3
  3104. (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
  3105. (let ((org-odd-levels-only nil)
  3106. (org-adapt-indentation t))
  3107. (org-promote))
  3108. (forward-line)
  3109. (org-get-indentation))))
  3110. (should
  3111. (= 3
  3112. (org-test-with-temp-text "** H\n Paragraph\n * list."
  3113. (let ((org-odd-levels-only nil)
  3114. (org-adapt-indentation t))
  3115. (org-promote))
  3116. (forward-line)
  3117. (org-get-indentation))))
  3118. ;; Ignore contents of source blocks or example blocks when
  3119. ;; indentation should be preserved (through
  3120. ;; `org-src-preserve-indentation' or "-i" flag).
  3121. (should-not
  3122. (zerop
  3123. (org-test-with-temp-text
  3124. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  3125. (let ((org-adapt-indentation t)
  3126. (org-src-preserve-indentation nil)
  3127. (org-odd-levels-only nil))
  3128. (org-promote))
  3129. (forward-line)
  3130. (org-get-indentation))))
  3131. (should
  3132. (zerop
  3133. (org-test-with-temp-text
  3134. "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
  3135. (let ((org-adapt-indentation t)
  3136. (org-src-preserve-indentation t)
  3137. (org-odd-levels-only nil))
  3138. (org-promote))
  3139. (forward-line)
  3140. (org-get-indentation))))
  3141. (should
  3142. (zerop
  3143. (org-test-with-temp-text
  3144. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  3145. (let ((org-adapt-indentation t)
  3146. (org-src-preserve-indentation t)
  3147. (org-odd-levels-only nil))
  3148. (org-promote))
  3149. (forward-line)
  3150. (org-get-indentation))))
  3151. (should
  3152. (zerop
  3153. (org-test-with-temp-text
  3154. "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
  3155. (let ((org-adapt-indentation t)
  3156. (org-src-preserve-indentation nil)
  3157. (org-odd-levels-only nil))
  3158. (org-promote))
  3159. (forward-line)
  3160. (org-get-indentation)))))
  3161. ;;; Planning
  3162. (ert-deftest test-org/at-planning-p ()
  3163. "Test `org-at-planning-p' specifications."
  3164. ;; Regular test.
  3165. (should
  3166. (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
  3167. (org-at-planning-p)))
  3168. (should-not
  3169. (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
  3170. (org-at-planning-p)))
  3171. ;; Correctly find planning attached to inlinetasks.
  3172. (when (featurep 'org-inlinetask)
  3173. (should
  3174. (org-test-with-temp-text
  3175. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
  3176. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  3177. (should-not
  3178. (org-test-with-temp-text
  3179. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  3180. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  3181. (should-not
  3182. (org-test-with-temp-text
  3183. "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  3184. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  3185. (should-not
  3186. (org-test-with-temp-text
  3187. "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
  3188. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
  3189. (ert-deftest test-org/add-planning-info ()
  3190. "Test `org-add-planning-info'."
  3191. ;; Create deadline when `org-adapt-indentation' is non-nil.
  3192. (should
  3193. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  3194. (org-test-with-temp-text "* H\nParagraph<point>"
  3195. (let ((org-adapt-indentation t))
  3196. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  3197. (replace-regexp-in-string
  3198. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  3199. nil nil 1))))
  3200. ;; Create deadline when `org-adapt-indentation' is nil.
  3201. (should
  3202. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  3203. (org-test-with-temp-text "* H\nParagraph<point>"
  3204. (let ((org-adapt-indentation nil))
  3205. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  3206. (replace-regexp-in-string
  3207. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  3208. nil nil 1))))
  3209. ;; Update deadline when `org-adapt-indentation' is non-nil.
  3210. (should
  3211. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  3212. (org-test-with-temp-text "\
  3213. * H
  3214. DEADLINE: <2015-06-24 Wed>
  3215. Paragraph<point>"
  3216. (let ((org-adapt-indentation t))
  3217. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  3218. (replace-regexp-in-string
  3219. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  3220. nil nil 1))))
  3221. ;; Update deadline when `org-adapt-indentation' is nil.
  3222. (should
  3223. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  3224. (org-test-with-temp-text "\
  3225. * H
  3226. DEADLINE: <2015-06-24 Wed>
  3227. Paragraph<point>"
  3228. (let ((org-adapt-indentation nil))
  3229. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  3230. (replace-regexp-in-string
  3231. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  3232. nil nil 1))))
  3233. ;; Schedule when `org-adapt-indentation' is non-nil.
  3234. (should
  3235. (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
  3236. (org-test-with-temp-text "* H\nParagraph<point>"
  3237. (let ((org-adapt-indentation t))
  3238. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  3239. (replace-regexp-in-string
  3240. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  3241. nil nil 1))))
  3242. ;; Schedule when `org-adapt-indentation' is nil.
  3243. (should
  3244. (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
  3245. (org-test-with-temp-text "* H\nParagraph<point>"
  3246. (let ((org-adapt-indentation nil))
  3247. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  3248. (replace-regexp-in-string
  3249. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  3250. nil nil 1))))
  3251. ;; Add deadline when scheduled.
  3252. (should
  3253. (equal "\
  3254. * H
  3255. DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
  3256. Paragraph"
  3257. (org-test-with-temp-text "\
  3258. * H
  3259. SCHEDULED: <2015-06-24 Wed>
  3260. Paragraph<point>"
  3261. (let ((org-adapt-indentation t))
  3262. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  3263. (replace-regexp-in-string
  3264. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  3265. nil nil 1))))
  3266. ;; Remove middle entry.
  3267. (should
  3268. (equal "\
  3269. * H
  3270. CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
  3271. Paragraph"
  3272. (org-test-with-temp-text "\
  3273. * H
  3274. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  3275. Paragraph<point>"
  3276. (let ((org-adapt-indentation t))
  3277. (org-add-planning-info nil nil 'deadline))
  3278. (replace-regexp-in-string
  3279. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  3280. nil nil 1))))
  3281. ;; Remove last entry and then middle entry (order should not
  3282. ;; matter).
  3283. (should
  3284. (equal "\
  3285. * H
  3286. CLOSED: [2015-06-24]
  3287. Paragraph"
  3288. (org-test-with-temp-text "\
  3289. * H
  3290. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  3291. Paragraph<point>"
  3292. (let ((org-adapt-indentation t))
  3293. (org-add-planning-info nil nil 'scheduled 'deadline))
  3294. (replace-regexp-in-string
  3295. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  3296. nil nil 1))))
  3297. ;; Remove closed when `org-adapt-indentation' is non-nil.
  3298. (should
  3299. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  3300. (org-test-with-temp-text "\
  3301. * H
  3302. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  3303. Paragraph<point>"
  3304. (let ((org-adapt-indentation t))
  3305. (org-add-planning-info nil nil 'closed))
  3306. (replace-regexp-in-string
  3307. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  3308. nil nil 1))))
  3309. (should
  3310. (equal "* H\n Paragraph"
  3311. (org-test-with-temp-text "\
  3312. * H
  3313. CLOSED: [2015-06-25 Thu]
  3314. Paragraph<point>"
  3315. (let ((org-adapt-indentation t))
  3316. (org-add-planning-info nil nil 'closed))
  3317. (replace-regexp-in-string
  3318. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  3319. nil nil 1))))
  3320. ;; Remove closed when `org-adapt-indentation' is nil.
  3321. (should
  3322. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  3323. (org-test-with-temp-text "\
  3324. * H
  3325. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  3326. Paragraph<point>"
  3327. (let ((org-adapt-indentation nil))
  3328. (org-add-planning-info nil nil 'closed))
  3329. (replace-regexp-in-string
  3330. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  3331. nil nil 1))))
  3332. (should
  3333. (equal "* H\nParagraph"
  3334. (org-test-with-temp-text "\
  3335. * H
  3336. CLOSED: [2015-06-25 Thu]
  3337. Paragraph<point>"
  3338. (let ((org-adapt-indentation nil))
  3339. (org-add-planning-info nil nil 'closed))
  3340. (replace-regexp-in-string
  3341. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  3342. nil nil 1))))
  3343. ;; Remove closed entry and delete empty line.
  3344. (should
  3345. (equal "\
  3346. * H
  3347. Paragraph"
  3348. (org-test-with-temp-text "\
  3349. * H
  3350. CLOSED: [2015-06-24 Wed]
  3351. Paragraph<point>"
  3352. (let ((org-adapt-indentation t))
  3353. (org-add-planning-info nil nil 'closed))
  3354. (replace-regexp-in-string
  3355. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  3356. nil nil 1))))
  3357. ;; Remove one entry and update another.
  3358. (should
  3359. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  3360. (org-test-with-temp-text "\
  3361. * H
  3362. SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
  3363. Paragraph<point>"
  3364. (let ((org-adapt-indentation t))
  3365. (org-add-planning-info 'deadline "<2015-06-25 Thu>" 'scheduled))
  3366. (replace-regexp-in-string
  3367. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  3368. nil nil 1)))))
  3369. ;;; Property API
  3370. (ert-deftest test-org/buffer-property-keys ()
  3371. "Test `org-buffer-property-keys' specifications."
  3372. ;; Retrieve properties accross siblings.
  3373. (should
  3374. (equal '("A" "B")
  3375. (org-test-with-temp-text "
  3376. * H1
  3377. :PROPERTIES:
  3378. :A: 1
  3379. :END:
  3380. * H2
  3381. :PROPERTIES:
  3382. :B: 1
  3383. :END:"
  3384. (org-buffer-property-keys))))
  3385. ;; Retrieve properties accross children.
  3386. (should
  3387. (equal '("A" "B")
  3388. (org-test-with-temp-text "
  3389. * H1
  3390. :PROPERTIES:
  3391. :A: 1
  3392. :END:
  3393. ** H2
  3394. :PROPERTIES:
  3395. :B: 1
  3396. :END:"
  3397. (org-buffer-property-keys))))
  3398. ;; Retrieve muliple properties in the same drawer.
  3399. (should
  3400. (equal '("A" "B")
  3401. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  3402. (org-buffer-property-keys))))
  3403. ;; Ignore extension symbol in property name.
  3404. (should
  3405. (equal '("A")
  3406. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  3407. (org-buffer-property-keys))))
  3408. ;; With non-nil COLUMNS, extract property names from columns.
  3409. (should
  3410. (equal '("A" "B")
  3411. (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
  3412. (org-buffer-property-keys nil nil t))))
  3413. (should
  3414. (equal '("A" "B" "COLUMNS")
  3415. (org-test-with-temp-text
  3416. "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
  3417. (org-buffer-property-keys nil nil t))))
  3418. ;; With non-nil IGNORE-MALFORMED malformed property drawers are silently ignored.
  3419. (should
  3420. (equal '("A")
  3421. (org-test-with-temp-text
  3422. "* a\n:PROPERTIES:\n:A: 1\n:END:\n* b\n:PROPERTIES:\nsome junk here\n:END:\n"
  3423. (org-buffer-property-keys nil nil nil t)))))
  3424. (ert-deftest test-org/property-values ()
  3425. "Test `org-property-values' specifications."
  3426. ;; Regular test.
  3427. (should
  3428. (equal '("2" "1")
  3429. (org-test-with-temp-text
  3430. "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
  3431. (org-property-values "A"))))
  3432. ;; Ignore empty values.
  3433. (should-not
  3434. (org-test-with-temp-text
  3435. "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
  3436. (org-property-values "A")))
  3437. ;; Take into consideration extended values.
  3438. (should
  3439. (equal '("1 2")
  3440. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  3441. (org-property-values "A")))))
  3442. (ert-deftest test-org/find-property ()
  3443. "Test `org-find-property' specifications."
  3444. ;; Regular test.
  3445. (should
  3446. (= 1
  3447. (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
  3448. (org-find-property "prop"))))
  3449. ;; Ignore false positives.
  3450. (should
  3451. (= 27
  3452. (org-test-with-temp-text
  3453. "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
  3454. (org-find-property "A"))))
  3455. ;; Return first entry found in buffer.
  3456. (should
  3457. (= 1
  3458. (org-test-with-temp-text
  3459. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  3460. (org-find-property "A"))))
  3461. ;; Only search visible part of the buffer.
  3462. (should
  3463. (= 31
  3464. (org-test-with-temp-text
  3465. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  3466. (org-narrow-to-subtree)
  3467. (org-find-property "A"))))
  3468. ;; With optional argument, only find entries with a specific value.
  3469. (should-not
  3470. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  3471. (org-find-property "A" "2")))
  3472. (should
  3473. (= 31
  3474. (org-test-with-temp-text
  3475. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
  3476. (org-find-property "A" "2"))))
  3477. ;; Use "nil" for explicit nil values.
  3478. (should
  3479. (= 31
  3480. (org-test-with-temp-text
  3481. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
  3482. (org-find-property "A" "nil")))))
  3483. (ert-deftest test-org/entry-delete ()
  3484. "Test `org-entry-delete' specifications."
  3485. ;; Regular test.
  3486. (should
  3487. (string-match
  3488. " *:PROPERTIES:\n *:B: +2\n *:END:"
  3489. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  3490. (org-entry-delete (point) "A")
  3491. (buffer-string))))
  3492. ;; Also remove accumulated properties.
  3493. (should-not
  3494. (string-match
  3495. ":A"
  3496. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
  3497. (org-entry-delete (point) "A")
  3498. (buffer-string))))
  3499. ;; When last property is removed, remove the property drawer.
  3500. (should-not
  3501. (string-match
  3502. ":PROPERTIES:"
  3503. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
  3504. (org-entry-delete (point) "A")
  3505. (buffer-string))))
  3506. ;; Return a non-nil value when some property was removed.
  3507. (should
  3508. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  3509. (org-entry-delete (point) "A")))
  3510. (should-not
  3511. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  3512. (org-entry-delete (point) "C"))))
  3513. (ert-deftest test-org/entry-get ()
  3514. "Test `org-entry-get' specifications."
  3515. ;; Regular test.
  3516. (should
  3517. (equal "1"
  3518. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  3519. (org-entry-get (point) "A"))))
  3520. ;; Ignore case.
  3521. (should
  3522. (equal "1"
  3523. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  3524. (org-entry-get (point) "a"))))
  3525. ;; Handle extended values, both before and after base value.
  3526. (should
  3527. (equal "1 2 3"
  3528. (org-test-with-temp-text
  3529. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  3530. (org-entry-get (point) "A"))))
  3531. ;; Empty values are returned as the empty string.
  3532. (should
  3533. (equal ""
  3534. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
  3535. (org-entry-get (point) "A"))))
  3536. ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
  3537. ;; otherwise, return nil.
  3538. (should-not
  3539. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  3540. (org-entry-get (point) "A")))
  3541. (should
  3542. (equal "nil"
  3543. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  3544. (org-entry-get (point) "A" nil t))))
  3545. ;; Return nil when no property is found, independently on the
  3546. ;; LITERAL-NIL argument.
  3547. (should-not
  3548. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  3549. (org-entry-get (point) "B")))
  3550. (should-not
  3551. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  3552. (org-entry-get (point) "B" nil t)))
  3553. ;; Handle inheritance, when allowed. Include extended values and
  3554. ;; possibly global values.
  3555. (should
  3556. (equal
  3557. "1"
  3558. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
  3559. (org-entry-get (point) "A" t))))
  3560. (should
  3561. (equal
  3562. "1"
  3563. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
  3564. (let ((org-use-property-inheritance t))
  3565. (org-entry-get (point) "A" 'selective)))))
  3566. (should-not
  3567. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
  3568. (let ((org-use-property-inheritance nil))
  3569. (org-entry-get (point) "A" 'selective))))
  3570. (should
  3571. (equal
  3572. "1 2"
  3573. (org-test-with-temp-text
  3574. "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
  3575. (org-entry-get (point-max) "A" t))))
  3576. (should
  3577. (equal "1"
  3578. (org-test-with-temp-text
  3579. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
  3580. (org-mode-restart)
  3581. (org-entry-get (point-max) "A" t))))
  3582. (should
  3583. (equal "0 1"
  3584. (org-test-with-temp-text
  3585. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
  3586. (org-mode-restart)
  3587. (org-entry-get (point-max) "A" t)))))
  3588. (ert-deftest test-org/entry-properties ()
  3589. "Test `org-entry-properties' specifications."
  3590. ;; Get "ITEM" property.
  3591. (should
  3592. (equal "H"
  3593. (org-test-with-temp-text "* TODO H"
  3594. (cdr (assoc "ITEM" (org-entry-properties nil "ITEM"))))))
  3595. (should
  3596. (equal "H"
  3597. (org-test-with-temp-text "* TODO H"
  3598. (cdr (assoc "ITEM" (org-entry-properties))))))
  3599. ;; Get "TODO" property. TODO keywords are case sensitive.
  3600. (should
  3601. (equal "TODO"
  3602. (org-test-with-temp-text "* TODO H"
  3603. (cdr (assoc "TODO" (org-entry-properties nil "TODO"))))))
  3604. (should
  3605. (equal "TODO"
  3606. (org-test-with-temp-text "* TODO H"
  3607. (cdr (assoc "TODO" (org-entry-properties))))))
  3608. (should-not
  3609. (org-test-with-temp-text "* H"
  3610. (assoc "TODO" (org-entry-properties nil "TODO"))))
  3611. (should-not
  3612. (org-test-with-temp-text "* todo H"
  3613. (assoc "TODO" (org-entry-properties nil "TODO"))))
  3614. ;; Get "PRIORITY" property.
  3615. (should
  3616. (equal "A"
  3617. (org-test-with-temp-text "* [#A] H"
  3618. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  3619. (should
  3620. (equal "A"
  3621. (org-test-with-temp-text "* [#A] H"
  3622. (cdr (assoc "PRIORITY" (org-entry-properties))))))
  3623. (should
  3624. (equal (char-to-string org-default-priority)
  3625. (org-test-with-temp-text "* H"
  3626. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  3627. ;; Get "FILE" property.
  3628. (should
  3629. (org-test-with-temp-text-in-file "* H\nParagraph"
  3630. (org-file-equal-p (cdr (assoc "FILE" (org-entry-properties nil "FILE")))
  3631. (buffer-file-name))))
  3632. (should
  3633. (org-test-with-temp-text-in-file "* H\nParagraph"
  3634. (org-file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
  3635. (buffer-file-name))))
  3636. (should-not
  3637. (org-test-with-temp-text "* H\nParagraph"
  3638. (cdr (assoc "FILE" (org-entry-properties nil "FILE")))))
  3639. ;; Get "TAGS" property.
  3640. (should
  3641. (equal ":tag1:tag2:"
  3642. (org-test-with-temp-text "* H :tag1:tag2:"
  3643. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS"))))))
  3644. (should
  3645. (equal ":tag1:tag2:"
  3646. (org-test-with-temp-text "* H :tag1:tag2:"
  3647. (cdr (assoc "TAGS" (org-entry-properties))))))
  3648. (should-not
  3649. (org-test-with-temp-text "* H"
  3650. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS")))))
  3651. ;; Get "ALLTAGS" property.
  3652. (should
  3653. (equal ":tag1:tag2:"
  3654. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  3655. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS"))))))
  3656. (should
  3657. (equal ":tag1:tag2:"
  3658. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  3659. (cdr (assoc "ALLTAGS" (org-entry-properties))))))
  3660. (should-not
  3661. (org-test-with-temp-text "* H"
  3662. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS")))))
  3663. ;; Get "BLOCKED" property.
  3664. (should
  3665. (equal "t"
  3666. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  3667. (let ((org-enforce-todo-dependencies t)
  3668. (org-blocker-hook
  3669. '(org-block-todo-from-children-or-siblings-or-parent)))
  3670. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  3671. (should
  3672. (equal ""
  3673. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  3674. (let ((org-enforce-todo-dependencies t)
  3675. (org-blocker-hook
  3676. '(org-block-todo-from-children-or-siblings-or-parent)))
  3677. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  3678. ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
  3679. (should
  3680. (equal
  3681. "[2012-03-29 thu.]"
  3682. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  3683. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED"))))))
  3684. (should
  3685. (equal
  3686. "[2012-03-29 thu.]"
  3687. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  3688. (cdr (assoc "CLOSED" (org-entry-properties))))))
  3689. (should-not
  3690. (org-test-with-temp-text "* H"
  3691. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED")))))
  3692. (should
  3693. (equal
  3694. "<2014-03-04 tue.>"
  3695. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  3696. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE"))))))
  3697. (should
  3698. (equal
  3699. "<2014-03-04 tue.>"
  3700. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  3701. (cdr (assoc "DEADLINE" (org-entry-properties))))))
  3702. (should-not
  3703. (org-test-with-temp-text "* H"
  3704. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE")))))
  3705. (should
  3706. (equal
  3707. "<2014-03-04 tue.>"
  3708. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  3709. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED"))))))
  3710. (should
  3711. (equal
  3712. "<2014-03-04 tue.>"
  3713. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  3714. (cdr (assoc "SCHEDULED" (org-entry-properties))))))
  3715. (should-not
  3716. (org-test-with-temp-text "* H"
  3717. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED")))))
  3718. ;; Get "CATEGORY"
  3719. (should
  3720. (equal "cat"
  3721. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  3722. (cdr (assoc "CATEGORY" (org-entry-properties))))))
  3723. (should
  3724. (equal "cat"
  3725. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  3726. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  3727. (should
  3728. (equal "cat"
  3729. (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
  3730. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  3731. (should
  3732. (equal "cat2"
  3733. (org-test-with-temp-text
  3734. (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  3735. "\n"
  3736. "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
  3737. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  3738. ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
  3739. (should
  3740. (equal "<2012-03-29 thu.>"
  3741. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
  3742. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  3743. (should
  3744. (equal "[2012-03-29 thu.]"
  3745. (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
  3746. (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
  3747. (should
  3748. (equal "<2012-03-29 thu.>"
  3749. (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
  3750. (cdr (assoc "TIMESTAMP" (org-entry-properties nil "TIMESTAMP"))))))
  3751. (should
  3752. (equal "[2014-03-04 tue.]"
  3753. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
  3754. (cdr (assoc "TIMESTAMP_IA" (org-entry-properties nil "TIMESTAMP_IA"))))))
  3755. ;; Get standard properties.
  3756. (should
  3757. (equal "1"
  3758. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  3759. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  3760. ;; Handle extended properties.
  3761. (should
  3762. (equal "1 2 3"
  3763. (org-test-with-temp-text
  3764. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  3765. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  3766. (should
  3767. (equal "1 2 3"
  3768. (org-test-with-temp-text
  3769. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
  3770. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  3771. ;; Ignore forbidden (special) properties.
  3772. (should-not
  3773. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
  3774. (cdr (assoc "TODO" (org-entry-properties nil 'standard))))))
  3775. (ert-deftest test-org/entry-put ()
  3776. "Test `org-entry-put' specifications."
  3777. ;; Error when not a string or nil.
  3778. (should-error
  3779. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  3780. (org-entry-put 1 "test" 2)))
  3781. ;; Error when property name is invalid.
  3782. (should-error
  3783. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  3784. (org-entry-put 1 "no space" "value")))
  3785. (should-error
  3786. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  3787. (org-entry-put 1 "" "value")))
  3788. ;; Set "TODO" property.
  3789. (should
  3790. (string-match (regexp-quote " TODO H")
  3791. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  3792. (org-entry-put (point) "TODO" "TODO")
  3793. (buffer-string))))
  3794. (should
  3795. (string-match (regexp-quote "* H")
  3796. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  3797. (org-entry-put (point) "TODO" nil)
  3798. (buffer-string))))
  3799. ;; Set "PRIORITY" property.
  3800. (should
  3801. (equal "* [#A] H"
  3802. (org-test-with-temp-text "* [#B] H"
  3803. (org-entry-put (point) "PRIORITY" "A")
  3804. (buffer-string))))
  3805. (should
  3806. (equal "* H"
  3807. (org-test-with-temp-text "* [#B] H"
  3808. (org-entry-put (point) "PRIORITY" nil)
  3809. (buffer-string))))
  3810. ;; Set "SCHEDULED" property.
  3811. (should
  3812. (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
  3813. (org-test-with-temp-text "* H"
  3814. (org-entry-put (point) "SCHEDULED" "2014-03-04")
  3815. (buffer-string))))
  3816. (should
  3817. (string= "* H\n"
  3818. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  3819. (org-entry-put (point) "SCHEDULED" nil)
  3820. (buffer-string))))
  3821. (should
  3822. (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
  3823. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  3824. (org-entry-put (point) "SCHEDULED" "earlier")
  3825. (buffer-string))))
  3826. (should
  3827. (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
  3828. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  3829. (org-entry-put (point) "SCHEDULED" "later")
  3830. (buffer-string))))
  3831. ;; Set "DEADLINE" property.
  3832. (should
  3833. (string-match "^ *DEADLINE: <2014-03-04 .*?>"
  3834. (org-test-with-temp-text "* H"
  3835. (org-entry-put (point) "DEADLINE" "2014-03-04")
  3836. (buffer-string))))
  3837. (should
  3838. (string= "* H\n"
  3839. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  3840. (org-entry-put (point) "DEADLINE" nil)
  3841. (buffer-string))))
  3842. (should
  3843. (string-match "^ *DEADLINE: <2014-03-03 .*?>"
  3844. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  3845. (org-entry-put (point) "DEADLINE" "earlier")
  3846. (buffer-string))))
  3847. (should
  3848. (string-match "^ *DEADLINE: <2014-03-05 .*?>"
  3849. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  3850. (org-entry-put (point) "DEADLINE" "later")
  3851. (buffer-string))))
  3852. ;; Set "CATEGORY" property
  3853. (should
  3854. (string-match "^ *:CATEGORY: cat"
  3855. (org-test-with-temp-text "* H"
  3856. (org-entry-put (point) "CATEGORY" "cat")
  3857. (buffer-string))))
  3858. ;; Regular properties, with or without pre-existing drawer.
  3859. (should
  3860. (string-match "^ *:A: +2$"
  3861. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  3862. (org-entry-put (point) "A" "2")
  3863. (buffer-string))))
  3864. (should
  3865. (string-match "^ *:A: +1$"
  3866. (org-test-with-temp-text "* H"
  3867. (org-entry-put (point) "A" "1")
  3868. (buffer-string))))
  3869. ;; Special case: two consecutive headlines.
  3870. (should
  3871. (string-match "\\* A\n *:PROPERTIES:"
  3872. (org-test-with-temp-text "* A\n** B"
  3873. (org-entry-put (point) "A" "1")
  3874. (buffer-string)))))
  3875. ;;; Radio Targets
  3876. (ert-deftest test-org/update-radio-target-regexp ()
  3877. "Test `org-update-radio-target-regexp' specifications."
  3878. ;; Properly update cache with no previous radio target regexp.
  3879. (should
  3880. (eq 'link
  3881. (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
  3882. (save-excursion (goto-char (point-max)) (org-element-context))
  3883. (insert "<<<")
  3884. (search-forward "o")
  3885. (insert ">>>")
  3886. (org-update-radio-target-regexp)
  3887. (goto-char (point-max))
  3888. (org-element-type (org-element-context)))))
  3889. ;; Properly update cache with previous radio target regexp.
  3890. (should
  3891. (eq 'link
  3892. (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
  3893. (save-excursion (goto-char (point-max)) (org-element-context))
  3894. (insert "<<<")
  3895. (search-forward "o")
  3896. (insert ">>>")
  3897. (org-update-radio-target-regexp)
  3898. (search-backward "r")
  3899. (delete-char 5)
  3900. (insert "new")
  3901. (org-update-radio-target-regexp)
  3902. (goto-char (point-max))
  3903. (delete-region (line-beginning-position) (point))
  3904. (insert "new")
  3905. (org-element-type (org-element-context))))))
  3906. ;;; Sparse trees
  3907. (ert-deftest test-org/match-sparse-tree ()
  3908. "Test `org-match-sparse-tree' specifications."
  3909. ;; Match tags.
  3910. (should-not
  3911. (org-test-with-temp-text "* H\n** H1 :tag:"
  3912. (org-match-sparse-tree nil "tag")
  3913. (search-forward "H1")
  3914. (org-invisible-p2)))
  3915. (should
  3916. (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
  3917. (org-match-sparse-tree nil "tag")
  3918. (search-forward "H2")
  3919. (org-invisible-p2)))
  3920. ;; "-" operator for tags.
  3921. (should-not
  3922. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  3923. (org-match-sparse-tree nil "tag1-tag2")
  3924. (search-forward "H1")
  3925. (org-invisible-p2)))
  3926. (should
  3927. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  3928. (org-match-sparse-tree nil "tag1-tag2")
  3929. (search-forward "H2")
  3930. (org-invisible-p2)))
  3931. ;; "&" operator for tags.
  3932. (should
  3933. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  3934. (org-match-sparse-tree nil "tag1&tag2")
  3935. (search-forward "H1")
  3936. (org-invisible-p2)))
  3937. (should-not
  3938. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  3939. (org-match-sparse-tree nil "tag1&tag2")
  3940. (search-forward "H2")
  3941. (org-invisible-p2)))
  3942. ;; "|" operator for tags.
  3943. (should-not
  3944. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  3945. (org-match-sparse-tree nil "tag1|tag2")
  3946. (search-forward "H1")
  3947. (org-invisible-p2)))
  3948. (should-not
  3949. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  3950. (org-match-sparse-tree nil "tag1|tag2")
  3951. (search-forward "H2")
  3952. (org-invisible-p2)))
  3953. ;; Regexp match on tags.
  3954. (should-not
  3955. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  3956. (org-match-sparse-tree nil "{^tag.*}")
  3957. (search-forward "H1")
  3958. (org-invisible-p2)))
  3959. (should
  3960. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  3961. (org-match-sparse-tree nil "{^tag.*}")
  3962. (search-forward "H2")
  3963. (org-invisible-p2)))
  3964. ;; Match group tags.
  3965. (should-not
  3966. (org-test-with-temp-text
  3967. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  3968. (org-match-sparse-tree nil "work")
  3969. (search-forward "H1")
  3970. (org-invisible-p2)))
  3971. (should-not
  3972. (org-test-with-temp-text
  3973. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  3974. (org-match-sparse-tree nil "work")
  3975. (search-forward "H2")
  3976. (org-invisible-p2)))
  3977. ;; Match group tags with hard brackets.
  3978. (should-not
  3979. (org-test-with-temp-text
  3980. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  3981. (org-match-sparse-tree nil "work")
  3982. (search-forward "H1")
  3983. (org-invisible-p2)))
  3984. (should-not
  3985. (org-test-with-temp-text
  3986. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  3987. (org-match-sparse-tree nil "work")
  3988. (search-forward "H2")
  3989. (org-invisible-p2)))
  3990. ;; Match tags in hierarchies
  3991. (should-not
  3992. (org-test-with-temp-text
  3993. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  3994. #+TAGS: [ Lev_2 : Lev_3 ]\n
  3995. #+TAGS: { Lev_3 : Lev_4 }\n
  3996. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  3997. (org-match-sparse-tree nil "Lev_1")
  3998. (search-forward "H4")
  3999. (org-invisible-p2)))
  4000. ;; Match regular expressions in tags
  4001. (should-not
  4002. (org-test-with-temp-text
  4003. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
  4004. (org-match-sparse-tree nil "Lev")
  4005. (search-forward "H1")
  4006. (org-invisible-p2)))
  4007. (should
  4008. (org-test-with-temp-text
  4009. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
  4010. (org-match-sparse-tree nil "Lev")
  4011. (search-forward "H1")
  4012. (org-invisible-p2)))
  4013. ;; Match properties.
  4014. (should
  4015. (org-test-with-temp-text
  4016. "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
  4017. (org-match-sparse-tree nil "A=\"1\"")
  4018. (search-forward "H2")
  4019. (org-invisible-p2)))
  4020. (should-not
  4021. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  4022. (org-match-sparse-tree nil "A=\"1\"")
  4023. (search-forward "H2")
  4024. (org-invisible-p2)))
  4025. ;; Case is not significant when matching properties.
  4026. (should-not
  4027. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  4028. (org-match-sparse-tree nil "a=\"1\"")
  4029. (search-forward "H2")
  4030. (org-invisible-p2)))
  4031. (should-not
  4032. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
  4033. (org-match-sparse-tree nil "A=\"1\"")
  4034. (search-forward "H2")
  4035. (org-invisible-p2)))
  4036. ;; Match special LEVEL property.
  4037. (should-not
  4038. (org-test-with-temp-text "* H\n** H1\n*** H2"
  4039. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  4040. (search-forward "H1")
  4041. (org-invisible-p2)))
  4042. (should
  4043. (org-test-with-temp-text "* H\n** H1\n*** H2"
  4044. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  4045. (search-forward "H2")
  4046. (org-invisible-p2)))
  4047. ;; Comparison operators when matching properties.
  4048. (should
  4049. (org-test-with-temp-text
  4050. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  4051. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  4052. (search-forward "H1")
  4053. (org-invisible-p2)))
  4054. (should-not
  4055. (org-test-with-temp-text
  4056. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  4057. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  4058. (search-forward "H2")
  4059. (org-invisible-p2)))
  4060. ;; Regexp match on properties values.
  4061. (should-not
  4062. (org-test-with-temp-text
  4063. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  4064. (org-match-sparse-tree nil "A={f.*}")
  4065. (search-forward "H1")
  4066. (org-invisible-p2)))
  4067. (should
  4068. (org-test-with-temp-text
  4069. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  4070. (org-match-sparse-tree nil "A={f.*}")
  4071. (search-forward "H2")
  4072. (org-invisible-p2)))
  4073. ;; With an optional argument, limit match to TODO entries.
  4074. (should-not
  4075. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  4076. (org-match-sparse-tree t "tag")
  4077. (search-forward "H1")
  4078. (org-invisible-p2)))
  4079. (should
  4080. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  4081. (org-match-sparse-tree t "tag")
  4082. (search-forward "H2")
  4083. (org-invisible-p2))))
  4084. ;;; Timestamps API
  4085. (ert-deftest test-org/time-stamp ()
  4086. "Test `org-time-stamp' specifications."
  4087. ;; Insert chosen time stamp at point.
  4088. (should
  4089. (string-match
  4090. "Te<2014-03-04 .*?>xt"
  4091. (org-test-with-temp-text "Te<point>xt"
  4092. (flet ((org-read-date
  4093. (&rest args)
  4094. (apply #'encode-time (org-parse-time-string "2014-03-04"))))
  4095. (org-time-stamp nil)
  4096. (buffer-string)))))
  4097. ;; With a prefix argument, also insert time.
  4098. (should
  4099. (string-match
  4100. "Te<2014-03-04 .*? 00:41>xt"
  4101. (org-test-with-temp-text "Te<point>xt"
  4102. (flet ((org-read-date
  4103. (&rest args)
  4104. (apply #'encode-time (org-parse-time-string "2014-03-04 00:41"))))
  4105. (org-time-stamp '(4))
  4106. (buffer-string)))))
  4107. ;; With two universal prefix arguments, insert an active timestamp
  4108. ;; with the current time without prompting the user.
  4109. (should
  4110. (string-match
  4111. "Te<2014-03-04 .*? 00:41>xt"
  4112. (org-test-with-temp-text "Te<point>xt"
  4113. (flet ((current-time
  4114. ()
  4115. (apply #'encode-time (org-parse-time-string "2014-03-04 00:41"))))
  4116. (org-time-stamp '(16))
  4117. (buffer-string)))))
  4118. ;; When optional argument is non-nil, insert an inactive timestamp.
  4119. (should
  4120. (string-match
  4121. "Te\\[2014-03-04 .*?\\]xt"
  4122. (org-test-with-temp-text "Te<point>xt"
  4123. (flet ((org-read-date
  4124. (&rest args)
  4125. (apply #'encode-time (org-parse-time-string "2014-03-04"))))
  4126. (org-time-stamp nil t)
  4127. (buffer-string)))))
  4128. ;; When called from a timestamp, replace existing one.
  4129. (should
  4130. (string-match
  4131. "<2014-03-04 .*?>"
  4132. (org-test-with-temp-text "<2012-03-29<point> thu.>"
  4133. (flet ((org-read-date
  4134. (&rest args)
  4135. (apply #'encode-time (org-parse-time-string "2014-03-04"))))
  4136. (org-time-stamp nil)
  4137. (buffer-string)))))
  4138. (should
  4139. (string-match
  4140. "<2014-03-04 .*?>--<2014-03-04 .*?>"
  4141. (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
  4142. (flet ((org-read-date
  4143. (&rest args)
  4144. (apply #'encode-time (org-parse-time-string "2014-03-04"))))
  4145. (org-time-stamp nil)
  4146. (buffer-string)))))
  4147. ;; When replacing a timestamp, preserve repeater, if any.
  4148. (should
  4149. (string-match
  4150. "<2014-03-04 .*? \\+2y>"
  4151. (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
  4152. (flet ((org-read-date
  4153. (&rest args)
  4154. (apply #'encode-time (org-parse-time-string "2014-03-04"))))
  4155. (org-time-stamp nil)
  4156. (buffer-string)))))
  4157. ;; When called twice in a raw, build a date range.
  4158. (should
  4159. (string-match
  4160. "<2012-03-29 .*?>--<2014-03-04 .*?>"
  4161. (org-test-with-temp-text "<2012-03-29 thu.><point>"
  4162. (flet ((org-read-date
  4163. (&rest args)
  4164. (apply #'encode-time (org-parse-time-string "2014-03-04"))))
  4165. (let ((last-command 'org-time-stamp)
  4166. (this-command 'org-time-stamp))
  4167. (org-time-stamp nil))
  4168. (buffer-string))))))
  4169. (ert-deftest test-org/timestamp-has-time-p ()
  4170. "Test `org-timestamp-has-time-p' specifications."
  4171. ;; With time.
  4172. (should
  4173. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  4174. (org-timestamp-has-time-p (org-element-context))))
  4175. ;; Without time.
  4176. (should-not
  4177. (org-test-with-temp-text "<2012-03-29 Thu>"
  4178. (org-timestamp-has-time-p (org-element-context)))))
  4179. (ert-deftest test-org/timestamp-format ()
  4180. "Test `org-timestamp-format' specifications."
  4181. ;; Regular test.
  4182. (should
  4183. (equal
  4184. "2012-03-29 16:40"
  4185. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  4186. (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
  4187. ;; Range end.
  4188. (should
  4189. (equal
  4190. "2012-03-29"
  4191. (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
  4192. (org-timestamp-format (org-element-context) "%Y-%m-%d" t)))))
  4193. (ert-deftest test-org/timestamp-split-range ()
  4194. "Test `org-timestamp-split-range' specifications."
  4195. ;; Extract range start (active).
  4196. (should
  4197. (equal '(2012 3 29)
  4198. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  4199. (let ((ts (org-timestamp-split-range (org-element-context))))
  4200. (mapcar (lambda (p) (org-element-property p ts))
  4201. '(:year-end :month-end :day-end))))))
  4202. ;; Extract range start (inactive)
  4203. (should
  4204. (equal '(2012 3 29)
  4205. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  4206. (let ((ts (org-timestamp-split-range (org-element-context))))
  4207. (mapcar (lambda (p) (org-element-property p ts))
  4208. '(:year-end :month-end :day-end))))))
  4209. ;; Extract range end (active).
  4210. (should
  4211. (equal '(2012 3 30)
  4212. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  4213. (let ((ts (org-timestamp-split-range
  4214. (org-element-context) t)))
  4215. (mapcar (lambda (p) (org-element-property p ts))
  4216. '(:year-end :month-end :day-end))))))
  4217. ;; Extract range end (inactive)
  4218. (should
  4219. (equal '(2012 3 30)
  4220. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  4221. (let ((ts (org-timestamp-split-range
  4222. (org-element-context) t)))
  4223. (mapcar (lambda (p) (org-element-property p ts))
  4224. '(:year-end :month-end :day-end))))))
  4225. ;; Return the timestamp if not a range.
  4226. (should
  4227. (org-test-with-temp-text "[2012-03-29 Thu]"
  4228. (let* ((ts-orig (org-element-context))
  4229. (ts-copy (org-timestamp-split-range ts-orig)))
  4230. (eq ts-orig ts-copy))))
  4231. (should
  4232. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  4233. (let* ((ts-orig (org-element-context))
  4234. (ts-copy (org-timestamp-split-range ts-orig)))
  4235. (eq ts-orig ts-copy)))))
  4236. (ert-deftest test-org/timestamp-translate ()
  4237. "Test `org-timestamp-translate' specifications."
  4238. ;; Translate whole date range.
  4239. (should
  4240. (equal "<29>--<30>"
  4241. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  4242. (let ((org-display-custom-times t)
  4243. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  4244. (org-timestamp-translate (org-element-context))))))
  4245. ;; Translate date range start.
  4246. (should
  4247. (equal "<29>"
  4248. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  4249. (let ((org-display-custom-times t)
  4250. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  4251. (org-timestamp-translate (org-element-context) 'start)))))
  4252. ;; Translate date range end.
  4253. (should
  4254. (equal "<30>"
  4255. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  4256. (let ((org-display-custom-times t)
  4257. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  4258. (org-timestamp-translate (org-element-context) 'end)))))
  4259. ;; Translate time range.
  4260. (should
  4261. (equal "<08>--<16>"
  4262. (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
  4263. (let ((org-display-custom-times t)
  4264. (org-time-stamp-custom-formats '("<%d>" . "<%H>")))
  4265. (org-timestamp-translate (org-element-context))))))
  4266. ;; Translate non-range timestamp.
  4267. (should
  4268. (equal "<29>"
  4269. (org-test-with-temp-text "<2012-03-29 Thu>"
  4270. (let ((org-display-custom-times t)
  4271. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  4272. (org-timestamp-translate (org-element-context))))))
  4273. ;; Do not change `diary' timestamps.
  4274. (should
  4275. (equal "<%%(org-float t 4 2)>"
  4276. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  4277. (let ((org-display-custom-times t)
  4278. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  4279. (org-timestamp-translate (org-element-context)))))))
  4280. ;;; Visibility
  4281. (ert-deftest test-org/flag-drawer ()
  4282. "Test `org-flag-drawer' specifications."
  4283. ;; Hide drawer.
  4284. (should
  4285. (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
  4286. (org-flag-drawer t)
  4287. (get-char-property (line-end-position) 'invisible)))
  4288. ;; Show drawer.
  4289. (should-not
  4290. (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
  4291. (org-flag-drawer t)
  4292. (org-flag-drawer nil)
  4293. (get-char-property (line-end-position) 'invisible)))
  4294. ;; Test optional argument.
  4295. (should
  4296. (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
  4297. (let ((drawer (save-excursion (search-forward ":D2")
  4298. (org-element-at-point))))
  4299. (org-flag-drawer t drawer)
  4300. (get-char-property (progn (search-forward ":D2") (line-end-position))
  4301. 'invisible))))
  4302. (should-not
  4303. (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
  4304. (let ((drawer (save-excursion (search-forward ":D2")
  4305. (org-element-at-point))))
  4306. (org-flag-drawer t drawer)
  4307. (get-char-property (line-end-position) 'invisible))))
  4308. ;; Do not hide fake drawers.
  4309. (should-not
  4310. (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
  4311. (forward-line 1)
  4312. (org-flag-drawer t)
  4313. (get-char-property (line-end-position) 'invisible)))
  4314. ;; Do not hide incomplete drawers.
  4315. (should-not
  4316. (org-test-with-temp-text ":D:\nparagraph"
  4317. (forward-line 1)
  4318. (org-flag-drawer t)
  4319. (get-char-property (line-end-position) 'invisible)))
  4320. ;; Do not hide drawers when called from final blank lines.
  4321. (should-not
  4322. (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
  4323. (goto-char (point-max))
  4324. (org-flag-drawer t)
  4325. (goto-char (point-min))
  4326. (get-char-property (line-end-position) 'invisible)))
  4327. ;; Don't leave point in an invisible part of the buffer when hiding
  4328. ;; a drawer away.
  4329. (should-not
  4330. (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
  4331. (goto-char (point-max))
  4332. (org-flag-drawer t)
  4333. (get-char-property (point) 'invisible))))
  4334. (ert-deftest test-org/hide-block-toggle ()
  4335. "Test `org-hide-block-toggle' specifications."
  4336. ;; Error when not at a block.
  4337. (should-error
  4338. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
  4339. (org-hide-block-toggle 'off)
  4340. (get-char-property (line-end-position) 'invisible)))
  4341. ;; Hide block.
  4342. (should
  4343. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  4344. (org-hide-block-toggle)
  4345. (get-char-property (line-end-position) 'invisible)))
  4346. (should
  4347. (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
  4348. (org-hide-block-toggle)
  4349. (get-char-property (line-end-position) 'invisible)))
  4350. ;; Show block unconditionally when optional argument is `off'.
  4351. (should-not
  4352. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  4353. (org-hide-block-toggle)
  4354. (org-hide-block-toggle 'off)
  4355. (get-char-property (line-end-position) 'invisible)))
  4356. (should-not
  4357. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  4358. (org-hide-block-toggle 'off)
  4359. (get-char-property (line-end-position) 'invisible)))
  4360. ;; Hide block unconditionally when optional argument is non-nil.
  4361. (should
  4362. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  4363. (org-hide-block-toggle t)
  4364. (get-char-property (line-end-position) 'invisible)))
  4365. (should
  4366. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  4367. (org-hide-block-toggle)
  4368. (org-hide-block-toggle t)
  4369. (get-char-property (line-end-position) 'invisible)))
  4370. ;; Do not hide block when called from final blank lines.
  4371. (should-not
  4372. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
  4373. (org-hide-block-toggle)
  4374. (goto-char (point-min))
  4375. (get-char-property (line-end-position) 'invisible)))
  4376. ;; Don't leave point in an invisible part of the buffer when hiding
  4377. ;; a block away.
  4378. (should-not
  4379. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
  4380. (org-hide-block-toggle)
  4381. (get-char-property (point) 'invisible))))
  4382. (ert-deftest test-org/hide-block-toggle-maybe ()
  4383. "Test `org-hide-block-toggle-maybe' specifications."
  4384. (should
  4385. (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
  4386. (org-hide-block-toggle-maybe)))
  4387. (should-not
  4388. (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
  4389. (ert-deftest test-org/show-set-visibility ()
  4390. "Test `org-show-set-visibility' specifications."
  4391. ;; Do not throw an error before first heading.
  4392. (should
  4393. (org-test-with-temp-text "Preamble\n* Headline"
  4394. (org-show-set-visibility 'tree)
  4395. t))
  4396. ;; Test all visibility spans, both on headline and in entry.
  4397. (let ((list-visible-lines
  4398. (lambda (state headerp)
  4399. (org-test-with-temp-text "* Grandmother (0)
  4400. ** Uncle (1)
  4401. *** Heir (2)
  4402. ** Father (3)
  4403. Ancestor text (4)
  4404. *** Sister (5)
  4405. Sibling text (6)
  4406. *** Self (7)
  4407. Match (8)
  4408. **** First born (9)
  4409. Child text (10)
  4410. **** The other child (11)
  4411. *** Brother (12)
  4412. ** Aunt (13)
  4413. "
  4414. (org-cycle t)
  4415. (search-forward (if headerp "Self" "Match"))
  4416. (org-show-set-visibility state)
  4417. (goto-char (point-min))
  4418. (let (result (line 0))
  4419. (while (not (eobp))
  4420. (unless (org-invisible-p2) (push line result))
  4421. (incf line)
  4422. (forward-line))
  4423. (nreverse result))))))
  4424. (should (equal '(0 7) (funcall list-visible-lines 'minimal t)))
  4425. (should (equal '(0 7 8) (funcall list-visible-lines 'minimal nil)))
  4426. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local t)))
  4427. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local nil)))
  4428. (should (equal '(0 3 7) (funcall list-visible-lines 'ancestors t)))
  4429. (should (equal '(0 3 7 8) (funcall list-visible-lines 'ancestors nil)))
  4430. (should (equal '(0 3 5 7 12) (funcall list-visible-lines 'lineage t)))
  4431. (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines 'lineage nil)))
  4432. (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines 'tree t)))
  4433. (should (equal '(0 1 3 5 7 8 9 11 12 13)
  4434. (funcall list-visible-lines 'tree nil)))
  4435. (should (equal '(0 1 3 4 5 7 12 13)
  4436. (funcall list-visible-lines 'canonical t)))
  4437. (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
  4438. (funcall list-visible-lines 'canonical nil)))))
  4439. (provide 'test-org)
  4440. ;;; test-org.el ends here