test-org.el 138 KB

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