test-org.el 139 KB

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