test-org.el 95 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993
  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. (ert-deftest test-org/org-parse-time-string ()
  180. "Test `org-parse-time-string'."
  181. (should (equal (org-parse-time-string "2012-03-29 16:40")
  182. '(0 40 16 29 3 2012 nil nil nil)))
  183. (should (equal (org-parse-time-string "[2012-03-29 16:40]")
  184. '(0 40 16 29 3 2012 nil nil nil)))
  185. (should (equal (org-parse-time-string "<2012-03-29 16:40>")
  186. '(0 40 16 29 3 2012 nil nil nil)))
  187. (should (equal (org-parse-time-string "<2012-03-29>")
  188. '(0 0 0 29 3 2012 nil nil nil)))
  189. (should (equal (org-parse-time-string "<2012-03-29>" t)
  190. '(0 nil nil 29 3 2012 nil nil nil))))
  191. ;;; Drawers
  192. (ert-deftest test-org/insert-property-drawer ()
  193. "Test `org-insert-property-drawer' specifications."
  194. ;; Error before first headline.
  195. (should-error (org-test-with-temp-text "" (org-insert-property-drawer)))
  196. ;; Insert drawer right after headline if there is no planning line,
  197. ;; or after it otherwise.
  198. (should
  199. (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
  200. (org-test-with-temp-text "* H\nParagraph<point>"
  201. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  202. (buffer-string))))
  203. (should
  204. (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
  205. (org-test-with-temp-text
  206. "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
  207. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  208. (buffer-string))))
  209. ;; Indent inserted drawer.
  210. (should
  211. (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
  212. (org-test-with-temp-text "* H\nParagraph<point>"
  213. (let ((org-adapt-indentation t)) (org-insert-property-drawer))
  214. (buffer-string))))
  215. ;; Handle insertion at eob.
  216. (should
  217. (equal "* H\n:PROPERTIES:\n:END:\n"
  218. (org-test-with-temp-text "* H"
  219. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  220. (buffer-string))))
  221. ;; Skip inlinetasks before point.
  222. (when (featurep 'org-inlinetask)
  223. (should
  224. (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
  225. (org-test-with-temp-text
  226. "* H\n*************** I\n*************** END\nP<point>"
  227. (let ((org-adapt-indentation nil)
  228. (org-inlinetask-min-level 15))
  229. (org-insert-property-drawer))
  230. (buffer-string)))))
  231. ;; Correctly set drawer in an inlinetask.
  232. (when (featurep 'org-inlinetask)
  233. (should
  234. (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
  235. (org-test-with-temp-text
  236. "* H\n*************** I\nP<point>\n*************** END"
  237. (let ((org-adapt-indentation nil)
  238. (org-inlinetask-min-level 15))
  239. (org-insert-property-drawer))
  240. (buffer-string))))))
  241. ;;; Filling
  242. (ert-deftest test-org/fill-paragraph ()
  243. "Test `org-fill-paragraph' specifications."
  244. ;; At an Org table, align it.
  245. (should
  246. (equal "| a |\n"
  247. (org-test-with-temp-text "|a|"
  248. (org-fill-paragraph)
  249. (buffer-string))))
  250. (should
  251. (equal "#+name: table\n| a |\n"
  252. (org-test-with-temp-text "#+name: table\n| a |"
  253. (org-fill-paragraph)
  254. (buffer-string))))
  255. ;; At a paragraph, preserve line breaks.
  256. (org-test-with-temp-text "some \\\\\nlong\ntext"
  257. (let ((fill-column 20))
  258. (org-fill-paragraph)
  259. (should (equal (buffer-string) "some \\\\\nlong text"))))
  260. ;; Correctly fill a paragraph when point is at its very end.
  261. (should
  262. (equal "A B"
  263. (org-test-with-temp-text "A\nB"
  264. (let ((fill-column 20))
  265. (goto-char (point-max))
  266. (org-fill-paragraph)
  267. (buffer-string)))))
  268. ;; Correctly fill the last paragraph of a greater element.
  269. (should
  270. (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
  271. (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
  272. (let ((fill-column 8))
  273. (forward-line)
  274. (end-of-line)
  275. (org-fill-paragraph)
  276. (buffer-string)))))
  277. ;; Correctly fill an element in a narrowed buffer.
  278. (should
  279. (equal "01234\n6"
  280. (org-test-with-temp-text "01234 6789"
  281. (let ((fill-column 5))
  282. (narrow-to-region 1 8)
  283. (org-fill-paragraph)
  284. (buffer-string)))))
  285. ;; Handle `adaptive-fill-regexp' in paragraphs.
  286. (should
  287. (equal "> a b"
  288. (org-test-with-temp-text "> a\n> b"
  289. (let ((fill-column 5)
  290. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  291. (org-fill-paragraph)
  292. (buffer-string)))))
  293. ;; Special case: Fill first paragraph when point is at an item or
  294. ;; a plain-list or a footnote reference.
  295. (should
  296. (equal "- A B"
  297. (org-test-with-temp-text "- A\n B"
  298. (let ((fill-column 20))
  299. (org-fill-paragraph)
  300. (buffer-string)))))
  301. (should
  302. (equal "[fn:1] A B"
  303. (org-test-with-temp-text "[fn:1] A\nB"
  304. (let ((fill-column 20))
  305. (org-fill-paragraph)
  306. (buffer-string)))))
  307. (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
  308. (let ((fill-column 20))
  309. (org-fill-paragraph)
  310. (should (equal (buffer-string)
  311. "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
  312. ;; Fill contents of `comment-block' elements.
  313. (should
  314. (equal
  315. (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
  316. (let ((fill-column 20))
  317. (forward-line)
  318. (org-fill-paragraph)
  319. (buffer-string)))
  320. "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
  321. ;; Fill `comment' elements.
  322. (should
  323. (equal " # A B"
  324. (org-test-with-temp-text " # A\n # B"
  325. (let ((fill-column 20))
  326. (org-fill-paragraph)
  327. (buffer-string)))))
  328. ;; Do not mix consecutive comments when filling one of them.
  329. (should
  330. (equal "# A B\n\n# C"
  331. (org-test-with-temp-text "# A\n# B\n\n# C"
  332. (let ((fill-column 20))
  333. (org-fill-paragraph)
  334. (buffer-string)))))
  335. ;; Use commented empty lines as separators when filling comments.
  336. (should
  337. (equal "# A B\n#\n# C"
  338. (org-test-with-temp-text "# A\n# B\n#\n# C"
  339. (let ((fill-column 20))
  340. (org-fill-paragraph)
  341. (buffer-string)))))
  342. ;; Handle `adaptive-fill-regexp' in comments.
  343. (should
  344. (equal "# > a b"
  345. (org-test-with-temp-text "# > a\n# > b"
  346. (let ((fill-column 20)
  347. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  348. (org-fill-paragraph)
  349. (buffer-string)))))
  350. ;; Do nothing at affiliated keywords.
  351. (org-test-with-temp-text "#+NAME: para\nSome\ntext."
  352. (let ((fill-column 20))
  353. (org-fill-paragraph)
  354. (should (equal (buffer-string) "#+NAME: para\nSome\ntext."))))
  355. ;; Do not move point after table when filling a table.
  356. (should-not
  357. (org-test-with-temp-text "| a | b |\n| c | d |\n"
  358. (forward-char)
  359. (org-fill-paragraph)
  360. (eobp))))
  361. (ert-deftest test-org/auto-fill-function ()
  362. "Test auto-filling features."
  363. ;; Auto fill paragraph.
  364. (should
  365. (equal "12345\n7890"
  366. (org-test-with-temp-text "12345 7890"
  367. (let ((fill-column 5))
  368. (end-of-line)
  369. (org-auto-fill-function)
  370. (buffer-string)))))
  371. ;; Auto fill first paragraph in an item.
  372. (should
  373. (equal "- 12345\n 7890"
  374. (org-test-with-temp-text "- 12345 7890"
  375. (let ((fill-column 7))
  376. (end-of-line)
  377. (org-auto-fill-function)
  378. (buffer-string)))))
  379. ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
  380. (should
  381. (equal "> 12345\n 7890"
  382. (org-test-with-temp-text "> 12345 7890"
  383. (let ((fill-column 10)
  384. (adaptive-fill-regexp "[ \t]*>+[ \t]*")
  385. (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
  386. (end-of-line)
  387. (org-auto-fill-function)
  388. (buffer-string)))))
  389. (should
  390. (equal "> 12345\n> 12345\n> 7890"
  391. (org-test-with-temp-text "> 12345\n> 12345 7890"
  392. (let ((fill-column 10)
  393. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  394. (goto-char (point-max))
  395. (org-auto-fill-function)
  396. (buffer-string)))))
  397. (should-not
  398. (equal " 12345\n *12345\n *12345"
  399. (org-test-with-temp-text " 12345\n *12345 12345"
  400. (let ((fill-column 10)
  401. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  402. (goto-char (point-max))
  403. (org-auto-fill-function)
  404. (buffer-string)))))
  405. ;; Auto fill comments.
  406. (should
  407. (equal " # 12345\n # 7890"
  408. (org-test-with-temp-text " # 12345 7890"
  409. (let ((fill-column 10))
  410. (end-of-line)
  411. (org-auto-fill-function)
  412. (buffer-string)))))
  413. ;; A hash within a line isn't a comment.
  414. (should-not
  415. (equal "12345 # 7890\n# 1"
  416. (org-test-with-temp-text "12345 # 7890 1"
  417. (let ((fill-column 12))
  418. (end-of-line)
  419. (org-auto-fill-function)
  420. (buffer-string)))))
  421. ;; Correctly interpret empty prefix.
  422. (should-not
  423. (equal "# a\n# b\nRegular\n# paragraph"
  424. (org-test-with-temp-text "# a\n# b\nRegular paragraph"
  425. (let ((fill-column 12))
  426. (end-of-line 3)
  427. (org-auto-fill-function)
  428. (buffer-string)))))
  429. ;; Comment block: auto fill contents.
  430. (should
  431. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  432. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  433. (let ((fill-column 5))
  434. (forward-line)
  435. (end-of-line)
  436. (org-auto-fill-function)
  437. (buffer-string)))))
  438. (should
  439. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  440. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  441. (let ((fill-column 5))
  442. (forward-line)
  443. (end-of-line)
  444. (org-auto-fill-function)
  445. (buffer-string)))))
  446. ;; Do not fill if a new item could be created.
  447. (should-not
  448. (equal "12345\n- 90"
  449. (org-test-with-temp-text "12345 - 90"
  450. (let ((fill-column 5))
  451. (end-of-line)
  452. (org-auto-fill-function)
  453. (buffer-string)))))
  454. ;; Do not fill if a line break could be introduced.
  455. (should-not
  456. (equal "123\\\\\n7890"
  457. (org-test-with-temp-text "123\\\\ 7890"
  458. (let ((fill-column 6))
  459. (end-of-line)
  460. (org-auto-fill-function)
  461. (buffer-string)))))
  462. ;; Do not fill affiliated keywords.
  463. (should-not
  464. (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
  465. (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
  466. (let ((fill-column 20))
  467. (end-of-line)
  468. (org-auto-fill-function)
  469. (buffer-string))))))
  470. ;;; Indentation
  471. (ert-deftest test-org/indent-line ()
  472. "Test `org-indent-line' specifications."
  473. ;; Do not indent footnote definitions or headlines.
  474. (should
  475. (zerop
  476. (org-test-with-temp-text "* H"
  477. (org-indent-line)
  478. (org-get-indentation))))
  479. (should
  480. (zerop
  481. (org-test-with-temp-text "[fn:1] fn"
  482. (let ((org-adapt-indentation t)) (org-indent-line))
  483. (org-get-indentation))))
  484. ;; Do not indent before first headline.
  485. (should
  486. (zerop
  487. (org-test-with-temp-text ""
  488. (org-indent-line)
  489. (org-get-indentation))))
  490. ;; Indent according to headline level otherwise, unless
  491. ;; `org-adapt-indentation' is nil.
  492. (should
  493. (= 2
  494. (org-test-with-temp-text "* H\nA"
  495. (forward-line)
  496. (let ((org-adapt-indentation t)) (org-indent-line))
  497. (org-get-indentation))))
  498. (should
  499. (= 2
  500. (org-test-with-temp-text "* H\n\nA"
  501. (forward-line)
  502. (let ((org-adapt-indentation t)) (org-indent-line))
  503. (org-get-indentation))))
  504. (should
  505. (zerop
  506. (org-test-with-temp-text "* H\nA"
  507. (forward-line)
  508. (let ((org-adapt-indentation nil)) (org-indent-line))
  509. (org-get-indentation))))
  510. ;; Indenting preserves point position.
  511. (should
  512. (org-test-with-temp-text "* H\nAB"
  513. (forward-line)
  514. (forward-char)
  515. (let ((org-adapt-indentation t)) (org-indent-line))
  516. (looking-at "B")))
  517. ;; Do not change indentation at an item.
  518. (should
  519. (= 1
  520. (org-test-with-temp-text "* H\n - A"
  521. (forward-line)
  522. (let ((org-adapt-indentation t)) (org-indent-line))
  523. (org-get-indentation))))
  524. ;; On blank lines at the end of a list, indent like last element
  525. ;; within it if the line is still in the list. Otherwise, indent
  526. ;; like the whole list.
  527. (should
  528. (= 4
  529. (org-test-with-temp-text "* H\n- A\n - AA\n"
  530. (goto-char (point-max))
  531. (let ((org-adapt-indentation t)) (org-indent-line))
  532. (org-get-indentation))))
  533. (should
  534. (zerop
  535. (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n"
  536. (goto-char (point-max))
  537. (let ((org-adapt-indentation t)) (org-indent-line))
  538. (org-get-indentation))))
  539. ;; Likewise, on a blank line at the end of a footnote definition,
  540. ;; indent at column 0 if line belongs to the definition. Otherwise,
  541. ;; indent like the definition itself.
  542. (should
  543. (zerop
  544. (org-test-with-temp-text "* H\n[fn:1] Definition\n"
  545. (goto-char (point-max))
  546. (let ((org-adapt-indentation t)) (org-indent-line))
  547. (org-get-indentation))))
  548. (should
  549. (zerop
  550. (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n"
  551. (goto-char (point-max))
  552. (let ((org-adapt-indentation t)) (org-indent-line))
  553. (org-get-indentation))))
  554. ;; After the end of the contents of a greater element, indent like
  555. ;; the beginning of the element.
  556. (should
  557. (= 1
  558. (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
  559. (forward-line 2)
  560. (org-indent-line)
  561. (org-get-indentation))))
  562. ;; On blank lines after a paragraph, indent like its last non-empty
  563. ;; line.
  564. (should
  565. (= 1
  566. (org-test-with-temp-text " Paragraph\n\n<point>"
  567. (org-indent-line)
  568. (org-get-indentation))))
  569. ;; At the first line of an element, indent like previous element's
  570. ;; first line, ignoring footnotes definitions and inline tasks, or
  571. ;; according to parent.
  572. (should
  573. (= 2
  574. (org-test-with-temp-text "A\n\n B\n\nC"
  575. (goto-char (point-max))
  576. (org-indent-line)
  577. (org-get-indentation))))
  578. (should
  579. (= 1
  580. (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC"
  581. (goto-char (point-max))
  582. (org-indent-line)
  583. (org-get-indentation))))
  584. (should
  585. (= 1
  586. (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
  587. (forward-line 1)
  588. (org-indent-line)
  589. (org-get-indentation))))
  590. ;; Within code part of a source block, use language major mode if
  591. ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
  592. ;; according to line above.
  593. (should
  594. (= 6
  595. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  596. (forward-line 2)
  597. (let ((org-src-tab-acts-natively t)
  598. (org-edit-src-content-indentation 0))
  599. (org-indent-line))
  600. (org-get-indentation))))
  601. (should
  602. (= 1
  603. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  604. (forward-line 2)
  605. (let ((org-src-tab-acts-natively nil)
  606. (org-edit-src-content-indentation 0))
  607. (org-indent-line))
  608. (org-get-indentation))))
  609. ;; Otherwise, indent like the first non-blank line above.
  610. (should
  611. (zerop
  612. (org-test-with-temp-text "#+BEGIN_CENTER\nline1\n\n line2\n#+END_CENTER"
  613. (forward-line 3)
  614. (org-indent-line)
  615. (org-get-indentation))))
  616. ;; Align node properties according to `org-property-format'. Handle
  617. ;; nicely empty values.
  618. (should
  619. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  620. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
  621. (let ((org-property-format "%-10s %s")) (org-indent-line))
  622. (buffer-string))))
  623. (should
  624. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  625. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
  626. (let ((org-property-format "%-10s %s")) (org-indent-line))
  627. (buffer-string)))))
  628. (ert-deftest test-org/indent-region ()
  629. "Test `org-indent-region' specifications."
  630. ;; Indent paragraph.
  631. (should
  632. (equal "A\nB\nC"
  633. (org-test-with-temp-text " A\nB\n C"
  634. (org-indent-region (point-min) (point-max))
  635. (buffer-string))))
  636. ;; Indent greater elements along with their contents.
  637. (should
  638. (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
  639. (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
  640. (org-indent-region (point-min) (point-max))
  641. (buffer-string))))
  642. ;; Ignore contents of verse blocks and example blocks.
  643. (should
  644. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  645. (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  646. (org-indent-region (point-min) (point-max))
  647. (buffer-string))))
  648. (should
  649. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  650. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  651. (org-indent-region (point-min) (point-max))
  652. (buffer-string))))
  653. ;; Indent according to mode if `org-src-tab-acts-natively' is
  654. ;; non-nil. Otherwise, do not indent code at all.
  655. (should
  656. (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
  657. (org-test-with-temp-text
  658. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  659. (let ((org-src-tab-acts-natively t)
  660. (org-edit-src-content-indentation 0))
  661. (org-indent-region (point-min) (point-max)))
  662. (buffer-string))))
  663. (should
  664. (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  665. (org-test-with-temp-text
  666. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  667. (let ((org-src-tab-acts-natively nil)
  668. (org-edit-src-content-indentation 0))
  669. (org-indent-region (point-min) (point-max)))
  670. (buffer-string))))
  671. ;; Align node properties according to `org-property-format'. Handle
  672. ;; nicely empty values.
  673. (should
  674. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  675. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
  676. (let ((org-property-format "%-10s %s")
  677. (org-adapt-indentation nil))
  678. (org-indent-region (point) (point-max)))
  679. (buffer-string))))
  680. (should
  681. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  682. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
  683. (let ((org-property-format "%-10s %s")
  684. (org-adapt-indentation nil))
  685. (org-indent-region (point) (point-max)))
  686. (buffer-string))))
  687. ;; Indent plain lists.
  688. (should
  689. (equal "- A\n B\n - C\n\n D"
  690. (org-test-with-temp-text "- A\n B\n - C\n\n D"
  691. (org-indent-region (point-min) (point-max))
  692. (buffer-string))))
  693. (should
  694. (equal "- A\n\n- B"
  695. (org-test-with-temp-text " - A\n\n - B"
  696. (org-indent-region (point-min) (point-max))
  697. (buffer-string))))
  698. ;; Indent footnote definitions.
  699. (should
  700. (equal "[fn:1] Definition\n\nDefinition"
  701. (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
  702. (org-indent-region (point-min) (point-max))
  703. (buffer-string))))
  704. ;; Special case: Start indenting on a blank line.
  705. (should
  706. (equal "\nParagraph"
  707. (org-test-with-temp-text "\n Paragraph"
  708. (org-indent-region (point-min) (point-max))
  709. (buffer-string)))))
  710. ;;; Editing
  711. (ert-deftest test-org/return ()
  712. "Test RET (`org-return') specifications."
  713. ;; Regular test.
  714. (should
  715. (equal "Para\ngraph"
  716. (org-test-with-temp-text "Para<point>graph"
  717. (org-return)
  718. (buffer-string))))
  719. ;; With optional argument, indent line.
  720. (should
  721. (equal " Para\n graph"
  722. (org-test-with-temp-text " Para<point>graph"
  723. (org-return t)
  724. (buffer-string))))
  725. ;; On a table, call `org-table-next-row'.
  726. (should
  727. (org-test-with-temp-text "| <point>a |\n| b |"
  728. (org-return)
  729. (org-looking-at-p "b")))
  730. ;; Open link or timestamp under point when `org-return-follows-link'
  731. ;; is non-nil.
  732. (should
  733. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  734. (let ((org-return-follows-link t)) (org-return))
  735. (org-looking-at-p "<<target>>")))
  736. (should-not
  737. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  738. (let ((org-return-follows-link nil)) (org-return))
  739. (org-looking-at-p "<<target>>")))
  740. ;; However, do not open link when point is in a table.
  741. (should
  742. (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
  743. (let ((org-return-follows-link t)) (org-return))
  744. (org-looking-at-p "between")))
  745. ;; Special case: in a list, when indenting, do not break structure.
  746. (should
  747. (equal "- A\n B"
  748. (org-test-with-temp-text "- A <point>B"
  749. (org-return t)
  750. (buffer-string))))
  751. ;; Special case: on tags part of a headline, add a newline below it
  752. ;; instead of breaking it.
  753. (should
  754. (equal "* H :tag:\n"
  755. (org-test-with-temp-text "* H :<point>tag:"
  756. (org-return)
  757. (buffer-string)))))
  758. (ert-deftest test-org/meta-return ()
  759. "Test M-RET (`org-meta-return') specifications."
  760. ;; In a table field insert a row above.
  761. (should
  762. (org-test-with-temp-text "| a |"
  763. (forward-char)
  764. (org-meta-return)
  765. (forward-line -1)
  766. (looking-at "| |$")))
  767. ;; In a paragraph change current line into a header.
  768. (should
  769. (org-test-with-temp-text "a"
  770. (org-meta-return)
  771. (beginning-of-line)
  772. (looking-at "\* a$")))
  773. ;; In an item insert an item, in this case above.
  774. (should
  775. (org-test-with-temp-text "- a"
  776. (org-meta-return)
  777. (beginning-of-line)
  778. (looking-at "- $")))
  779. ;; In a drawer and item insert an item, in this case above.
  780. (should
  781. (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
  782. (forward-line)
  783. (org-meta-return)
  784. (beginning-of-line)
  785. (looking-at "- $"))))
  786. (ert-deftest test-org/insert-heading ()
  787. "Test `org-insert-heading' specifications."
  788. ;; FIXME: Test coverage is incomplete yet.
  789. ;;
  790. ;; In an empty buffer, insert a new headline.
  791. (should
  792. (equal "* "
  793. (org-test-with-temp-text ""
  794. (org-insert-heading)
  795. (buffer-string))))
  796. ;; At the beginning of a line, turn it into a headline
  797. (should
  798. (equal "* P"
  799. (org-test-with-temp-text "<point>P"
  800. (org-insert-heading)
  801. (buffer-string))))
  802. ;; In the middle of a line, split the line if allowed, otherwise,
  803. ;; insert the headline at its end.
  804. (should
  805. (equal "Para\n* graph"
  806. (org-test-with-temp-text "Para<point>graph"
  807. (let ((org-M-RET-may-split-line '((default . t))))
  808. (org-insert-heading))
  809. (buffer-string))))
  810. (should
  811. (equal "Paragraph\n* "
  812. (org-test-with-temp-text "Para<point>graph"
  813. (let ((org-M-RET-may-split-line '((default . nil))))
  814. (org-insert-heading))
  815. (buffer-string))))
  816. ;; When on a list, insert an item instead, unless called with an
  817. ;; universal argument or if list is invisible. In this case, create
  818. ;; a new headline after contents.
  819. (should
  820. (equal "* H\n- item\n- "
  821. (org-test-with-temp-text "* H\n- item<point>"
  822. (let ((org-insert-heading-respect-content nil))
  823. (org-insert-heading))
  824. (buffer-string))))
  825. (should
  826. (equal "* H\n- item\n- item 2\n* "
  827. (org-test-with-temp-text "* H\n- item<point>\n- item 2"
  828. (let ((org-insert-heading-respect-content nil))
  829. (org-insert-heading '(4)))
  830. (buffer-string))))
  831. (should
  832. (equal "* H\n- item\n* "
  833. (org-test-with-temp-text "* H\n- item"
  834. (org-cycle)
  835. (goto-char (point-max))
  836. (let ((org-insert-heading-respect-content nil)) (org-insert-heading))
  837. (buffer-string))))
  838. ;; When called with two universal arguments, insert a new headline
  839. ;; at the end of the grandparent subtree.
  840. (should
  841. (equal "* H1\n** H3\n- item\n** H2\n** "
  842. (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
  843. (let ((org-insert-heading-respect-content nil))
  844. (org-insert-heading '(16)))
  845. (buffer-string))))
  846. ;; Corner case: correctly insert a headline after an empty one.
  847. (should
  848. (equal "* \n* "
  849. (org-test-with-temp-text "* <point>"
  850. (org-insert-heading)
  851. (buffer-string)))))
  852. (ert-deftest test-org/insert-todo-heading-respect-content ()
  853. "Test `org-insert-todo-heading-respect-content' specifications."
  854. ;; Create a TODO heading.
  855. (should
  856. (org-test-with-temp-text "* H1\n Body"
  857. (org-insert-todo-heading-respect-content)
  858. (nth 2 (org-heading-components))))
  859. ;; Add headline at the end of the first subtree
  860. (should
  861. (org-test-with-temp-text "* H1\nH1Body\n** H2\nH2Body"
  862. (search-forward "H1Body")
  863. (org-insert-todo-heading-respect-content)
  864. (and (eobp) (org-at-heading-p))))
  865. ;; In a list, do not create a new item.
  866. (should
  867. (org-test-with-temp-text "* H\n- an item\n- another one"
  868. (search-forward "an ")
  869. (org-insert-todo-heading-respect-content)
  870. (and (eobp) (org-at-heading-p)))))
  871. ;;; Fixed-Width Areas
  872. (ert-deftest test-org/toggle-fixed-width ()
  873. "Test `org-toggle-fixed-width' specifications."
  874. ;; No region: Toggle on fixed-width marker in paragraphs.
  875. (should
  876. (equal ": A"
  877. (org-test-with-temp-text "A"
  878. (org-toggle-fixed-width)
  879. (buffer-string))))
  880. ;; No region: Toggle off fixed-width markers in fixed-width areas.
  881. (should
  882. (equal "A"
  883. (org-test-with-temp-text ": A"
  884. (org-toggle-fixed-width)
  885. (buffer-string))))
  886. ;; No region: Toggle on marker in blank lines after elements or just
  887. ;; after a headline.
  888. (should
  889. (equal "* H\n: "
  890. (org-test-with-temp-text "* H\n"
  891. (forward-line)
  892. (org-toggle-fixed-width)
  893. (buffer-string))))
  894. (should
  895. (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
  896. (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
  897. (goto-char (point-max))
  898. (org-toggle-fixed-width)
  899. (buffer-string))))
  900. ;; No region: Toggle on marker in front of one line elements (e.g.,
  901. ;; headlines, clocks)
  902. (should
  903. (equal ": * Headline"
  904. (org-test-with-temp-text "* Headline"
  905. (org-toggle-fixed-width)
  906. (buffer-string))))
  907. (should
  908. (equal ": #+KEYWORD: value"
  909. (org-test-with-temp-text "#+KEYWORD: value"
  910. (org-toggle-fixed-width)
  911. (buffer-string))))
  912. ;; No region: error in other situations.
  913. (should-error
  914. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
  915. (forward-line)
  916. (org-toggle-fixed-width)
  917. (buffer-string)))
  918. ;; No region: Indentation is preserved.
  919. (should
  920. (equal "- A\n : B"
  921. (org-test-with-temp-text "- A\n B"
  922. (forward-line)
  923. (org-toggle-fixed-width)
  924. (buffer-string))))
  925. ;; Region: If it contains only fixed-width elements and blank lines,
  926. ;; toggle off fixed-width markup.
  927. (should
  928. (equal "A\n\nB"
  929. (org-test-with-temp-text ": A\n\n: B"
  930. (transient-mark-mode 1)
  931. (push-mark (point) t t)
  932. (goto-char (point-max))
  933. (org-toggle-fixed-width)
  934. (buffer-string))))
  935. ;; Region: If it contains anything else, toggle on fixed-width but
  936. ;; not on fixed-width areas.
  937. (should
  938. (equal ": A\n: \n: B\n: \n: C"
  939. (org-test-with-temp-text "A\n\n: B\n\nC"
  940. (transient-mark-mode 1)
  941. (push-mark (point) t t)
  942. (goto-char (point-max))
  943. (org-toggle-fixed-width)
  944. (buffer-string))))
  945. ;; Region: Ignore blank lines at its end, unless it contains only
  946. ;; such lines.
  947. (should
  948. (equal ": A\n\n"
  949. (org-test-with-temp-text "A\n\n"
  950. (transient-mark-mode 1)
  951. (push-mark (point) t t)
  952. (goto-char (point-max))
  953. (org-toggle-fixed-width)
  954. (buffer-string))))
  955. (should
  956. (equal ": \n: \n"
  957. (org-test-with-temp-text "\n\n"
  958. (transient-mark-mode 1)
  959. (push-mark (point) t t)
  960. (goto-char (point-max))
  961. (org-toggle-fixed-width)
  962. (buffer-string)))))
  963. ;;; Headline
  964. (ert-deftest test-org/in-commented-heading-p ()
  965. "Test `org-in-commented-heading-p' specifications."
  966. ;; Commented headline.
  967. (should
  968. (org-test-with-temp-text "* COMMENT Headline\nBody"
  969. (goto-char (point-max))
  970. (org-in-commented-heading-p)))
  971. ;; Commented ancestor.
  972. (should
  973. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  974. (goto-char (point-max))
  975. (org-in-commented-heading-p)))
  976. ;; Comment keyword is case-sensitive.
  977. (should-not
  978. (org-test-with-temp-text "* Comment Headline\nBody"
  979. (goto-char (point-max))
  980. (org-in-commented-heading-p)))
  981. ;; Keyword is standalone.
  982. (should-not
  983. (org-test-with-temp-text "* COMMENTHeadline\nBody"
  984. (goto-char (point-max))
  985. (org-in-commented-heading-p)))
  986. ;; Optional argument.
  987. (should-not
  988. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  989. (goto-char (point-max))
  990. (org-in-commented-heading-p t))))
  991. ;;; Keywords
  992. (ert-deftest test-org/set-regexps-and-options ()
  993. "Test `org-set-regexps-and-options' specifications."
  994. ;; TAGS keyword.
  995. (should
  996. (equal '(("A" . ?a) ("B") ("C"))
  997. (org-test-with-temp-text "#+TAGS: A(a) B C"
  998. (org-mode-restart)
  999. org-tag-alist)))
  1000. (should
  1001. (equal '(("A") (:newline) ("B"))
  1002. (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
  1003. (org-mode-restart)
  1004. org-tag-alist)))
  1005. (should
  1006. (equal '((:startgroup) ("A") ("B") (:endgroup) ("C"))
  1007. (org-test-with-temp-text "#+TAGS: { A B } C"
  1008. (org-mode-restart)
  1009. org-tag-alist)))
  1010. (should
  1011. (equal '((:startgroup) ("A") (:grouptags) ("B") ("C") (:endgroup))
  1012. (org-test-with-temp-text "#+TAGS: { A : B C }"
  1013. (org-mode-restart)
  1014. org-tag-alist)))
  1015. (should
  1016. (equal '(("A" "B" "C"))
  1017. (org-test-with-temp-text "#+TAGS: { A : B C }"
  1018. (org-mode-restart)
  1019. org-tag-groups-alist)))
  1020. ;; FILETAGS keyword.
  1021. (should
  1022. (equal '("A" "B" "C")
  1023. (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
  1024. (org-mode-restart)
  1025. org-file-tags)))
  1026. ;; PROPERTY keyword. Property names are case-insensitive.
  1027. (should
  1028. (equal "foo=1"
  1029. (org-test-with-temp-text "#+PROPERTY: var foo=1"
  1030. (org-mode-restart)
  1031. (cdr (assoc "var" org-file-properties)))))
  1032. (should
  1033. (equal
  1034. "foo=1 bar=2"
  1035. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
  1036. (org-mode-restart)
  1037. (cdr (assoc "var" org-file-properties)))))
  1038. (should
  1039. (equal
  1040. "foo=1 bar=2"
  1041. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
  1042. (org-mode-restart)
  1043. (cdr (assoc "var" org-file-properties)))))
  1044. ;; ARCHIVE keyword.
  1045. (should
  1046. (equal "%s_done::"
  1047. (org-test-with-temp-text "#+ARCHIVE: %s_done::"
  1048. (org-mode-restart)
  1049. org-archive-location)))
  1050. ;; CATEGORY keyword.
  1051. (should
  1052. (eq 'test
  1053. (org-test-with-temp-text "#+CATEGORY: test"
  1054. (org-mode-restart)
  1055. org-category)))
  1056. (should
  1057. (equal "test"
  1058. (org-test-with-temp-text "#+CATEGORY: test"
  1059. (org-mode-restart)
  1060. (cdr (assoc "CATEGORY" org-file-properties)))))
  1061. ;; COLUMNS keyword.
  1062. (should
  1063. (equal "%25ITEM %TAGS %PRIORITY %TODO"
  1064. (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
  1065. (org-mode-restart)
  1066. org-columns-default-format)))
  1067. ;; CONSTANTS keyword. Constants names are case sensitive.
  1068. (should
  1069. (equal '("299792458." "3.14")
  1070. (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
  1071. (org-mode-restart)
  1072. (mapcar
  1073. (lambda (n) (cdr (assoc n org-table-formula-constants-local)))
  1074. '("c" "pi")))))
  1075. (should
  1076. (equal "3.14"
  1077. (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
  1078. (org-mode-restart)
  1079. (cdr (assoc "pi" org-table-formula-constants-local)))))
  1080. (should
  1081. (equal "22/7"
  1082. (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
  1083. (org-mode-restart)
  1084. (cdr (assoc "PI" org-table-formula-constants-local)))))
  1085. ;; LINK keyword.
  1086. (should
  1087. (equal
  1088. '("url1" "url2")
  1089. (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
  1090. (org-mode-restart)
  1091. (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local)))
  1092. '("a" "b")))))
  1093. ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
  1094. (should
  1095. (equal
  1096. '(?X ?Z ?Y)
  1097. (org-test-with-temp-text "#+PRIORITIES: X Z Y"
  1098. (org-mode-restart)
  1099. (list org-highest-priority org-lowest-priority org-default-priority))))
  1100. (should
  1101. (equal
  1102. '(?A ?C ?B)
  1103. (org-test-with-temp-text "#+PRIORITIES: X Z"
  1104. (org-mode-restart)
  1105. (list org-highest-priority org-lowest-priority org-default-priority))))
  1106. ;; STARTUP keyword.
  1107. (should
  1108. (equal '(t t)
  1109. (org-test-with-temp-text "#+STARTUP: fold odd"
  1110. (org-mode-restart)
  1111. (list org-startup-folded org-odd-levels-only))))
  1112. ;; TODO keywords.
  1113. (should
  1114. (equal '(("A" "B") ("C"))
  1115. (org-test-with-temp-text "#+TODO: A B | C"
  1116. (org-mode-restart)
  1117. (list org-not-done-keywords org-done-keywords))))
  1118. (should
  1119. (equal '(("A" "C") ("B" "D"))
  1120. (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
  1121. (org-mode-restart)
  1122. (list org-not-done-keywords org-done-keywords))))
  1123. (should
  1124. (equal '(("A" "B") ("C"))
  1125. (org-test-with-temp-text "#+TYP_TODO: A B | C"
  1126. (org-mode-restart)
  1127. (list org-not-done-keywords org-done-keywords))))
  1128. (should
  1129. (equal '((:startgroup) ("A" . ?a) (:endgroup))
  1130. (org-test-with-temp-text "#+TODO: A(a)"
  1131. (org-mode-restart)
  1132. org-todo-key-alist)))
  1133. (should
  1134. (equal '(("D" note nil) ("C" time nil) ("B" note time))
  1135. (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
  1136. (org-mode-restart)
  1137. org-todo-log-states)))
  1138. ;; Enter SETUPFILE keyword.
  1139. (should
  1140. (equal "1"
  1141. (org-test-with-temp-text
  1142. (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
  1143. (org-mode-restart)
  1144. (cdr (assoc "a" org-file-properties))))))
  1145. ;;; Links
  1146. ;;;; Coderefs
  1147. (ert-deftest test-org/coderef ()
  1148. "Test coderef links specifications."
  1149. (should
  1150. (org-test-with-temp-text "
  1151. #+BEGIN_SRC emacs-lisp
  1152. \(+ 1 1) (ref:sc)
  1153. #+END_SRC
  1154. \[[(sc)]]"
  1155. (goto-char (point-max))
  1156. (org-open-at-point)
  1157. (looking-at "(ref:sc)"))))
  1158. ;;;; Custom ID
  1159. (ert-deftest test-org/custom-id ()
  1160. "Test custom ID links specifications."
  1161. (should
  1162. (org-test-with-temp-text
  1163. "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom]]"
  1164. (goto-char (point-max))
  1165. (org-open-at-point)
  1166. (org-looking-at-p "\\* H1"))))
  1167. ;;;; Fuzzy Links
  1168. ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
  1169. ;; a named element (#+name: text) and to headlines (* Text).
  1170. (ert-deftest test-org/fuzzy-links ()
  1171. "Test fuzzy links specifications."
  1172. ;; Fuzzy link goes in priority to a matching target.
  1173. (should
  1174. (org-test-with-temp-text "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n[[Test]]"
  1175. (goto-line 5)
  1176. (org-open-at-point)
  1177. (looking-at "<<Test>>")))
  1178. ;; Then fuzzy link points to an element with a given name.
  1179. (should
  1180. (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n[[Test]]"
  1181. (goto-line 5)
  1182. (org-open-at-point)
  1183. (looking-at "#\\+NAME: Test")))
  1184. ;; A target still lead to a matching headline otherwise.
  1185. (should
  1186. (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n[[Head2]]"
  1187. (goto-line 4)
  1188. (org-open-at-point)
  1189. (looking-at "\\* Head2")))
  1190. ;; With a leading star in link, enforce heading match.
  1191. (should
  1192. (org-test-with-temp-text "* Test\n<<Test>>\n[[*Test]]"
  1193. (goto-line 3)
  1194. (org-open-at-point)
  1195. (looking-at "\\* Test")))
  1196. ;; Correctly un-hexify fuzzy links.
  1197. (should
  1198. (org-test-with-temp-text "* With space\n[[*With%20space][With space]]"
  1199. (goto-char (point-max))
  1200. (org-open-at-point)
  1201. (bobp))))
  1202. ;;;; Link Escaping
  1203. (ert-deftest test-org/org-link-escape-ascii-character ()
  1204. "Escape an ascii character."
  1205. (should
  1206. (string=
  1207. "%5B"
  1208. (org-link-escape "["))))
  1209. (ert-deftest test-org/org-link-escape-ascii-ctrl-character ()
  1210. "Escape an ascii control character."
  1211. (should
  1212. (string=
  1213. "%09"
  1214. (org-link-escape "\t"))))
  1215. (ert-deftest test-org/org-link-escape-multibyte-character ()
  1216. "Escape an unicode multibyte character."
  1217. (should
  1218. (string=
  1219. "%E2%82%AC"
  1220. (org-link-escape "€"))))
  1221. (ert-deftest test-org/org-link-escape-custom-table ()
  1222. "Escape string with custom character table."
  1223. (should
  1224. (string=
  1225. "Foo%3A%42ar%0A"
  1226. (org-link-escape "Foo:Bar\n" '(?\: ?\B)))))
  1227. (ert-deftest test-org/org-link-escape-custom-table-merge ()
  1228. "Escape string with custom table merged with default table."
  1229. (should
  1230. (string=
  1231. "%5BF%6F%6F%3A%42ar%0A%5D"
  1232. (org-link-escape "[Foo:Bar\n]" '(?\: ?\B ?\o) t))))
  1233. (ert-deftest test-org/org-link-unescape-ascii-character ()
  1234. "Unescape an ascii character."
  1235. (should
  1236. (string=
  1237. "["
  1238. (org-link-unescape "%5B"))))
  1239. (ert-deftest test-org/org-link-unescape-ascii-ctrl-character ()
  1240. "Unescpae an ascii control character."
  1241. (should
  1242. (string=
  1243. "\n"
  1244. (org-link-unescape "%0A"))))
  1245. (ert-deftest test-org/org-link-unescape-multibyte-character ()
  1246. "Unescape unicode multibyte character."
  1247. (should
  1248. (string=
  1249. "€"
  1250. (org-link-unescape "%E2%82%AC"))))
  1251. (ert-deftest test-org/org-link-unescape-ascii-extended-char ()
  1252. "Unescape old style percent escaped character."
  1253. (should
  1254. (string=
  1255. "àâçèéêîôùû"
  1256. (decode-coding-string
  1257. (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1))))
  1258. (ert-deftest test-org/org-link-escape-url-with-escaped-char ()
  1259. "Escape and unescape a URL that includes an escaped char.
  1260. http://article.gmane.org/gmane.emacs.orgmode/21459/"
  1261. (should
  1262. (string=
  1263. "http://some.host.com/form?&id=blah%2Bblah25"
  1264. (org-link-unescape
  1265. (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
  1266. (ert-deftest test-org/org-link-escape-chars-browser ()
  1267. "Test of the constant `org-link-escape-chars-browser'.
  1268. See there why this test is a candidate to be removed once Org
  1269. drops support for Emacs 24.1 and 24.2."
  1270. (should
  1271. (string=
  1272. (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
  1273. "%22Release%208.2%22&idxname=emacs-orgmode")
  1274. (org-link-escape-browser ; Do not replace with `url-encode-url',
  1275. ; see docstring above.
  1276. (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
  1277. "\"Release 8.2\"&idxname=emacs-orgmode")))))
  1278. ;;;; Open at point
  1279. (ert-deftest test-org/open-at-point-in-property ()
  1280. "Does `org-open-at-point' open link in property drawer?"
  1281. (should
  1282. (org-test-with-temp-text
  1283. "* Headline
  1284. :PROPERTIES:
  1285. :URL: <point>[[info:emacs#Top]]
  1286. :END:"
  1287. (org-open-at-point) t)))
  1288. (ert-deftest test-org/open-at-point-in-comment ()
  1289. "Does `org-open-at-point' open link in a commented line?"
  1290. (should
  1291. (org-test-with-temp-text
  1292. "# <point>[[info:emacs#Top]]"
  1293. (org-open-at-point) t)))
  1294. (ert-deftest test-org/open-at-point/info ()
  1295. "Test `org-open-at-point' on info links."
  1296. (should
  1297. (org-test-with-temp-text
  1298. "<point>[[info:emacs#Top]]"
  1299. (org-open-at-point)
  1300. (and (switch-to-buffer "*info*")
  1301. (prog1
  1302. (looking-at "\nThe Emacs Editor")
  1303. (kill-buffer))))))
  1304. ;;; Node Properties
  1305. (ert-deftest test-org/accumulated-properties-in-drawers ()
  1306. "Ensure properties accumulate in subtree drawers."
  1307. (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
  1308. (org-babel-next-src-block)
  1309. (should (equal '(2 1) (org-babel-execute-src-block)))))
  1310. (ert-deftest test-org/custom-properties ()
  1311. "Test custom properties specifications."
  1312. ;; Standard test.
  1313. (should
  1314. (let ((org-custom-properties '("FOO")))
  1315. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  1316. (org-toggle-custom-properties-visibility)
  1317. (org-invisible-p2))))
  1318. ;; Properties are case-insensitive.
  1319. (should
  1320. (let ((org-custom-properties '("FOO")))
  1321. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
  1322. (org-toggle-custom-properties-visibility)
  1323. (org-invisible-p2))))
  1324. (should
  1325. (let ((org-custom-properties '("foo")))
  1326. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  1327. (org-toggle-custom-properties-visibility)
  1328. (org-invisible-p2))))
  1329. ;; Multiple custom properties in the same drawer.
  1330. (should
  1331. (let ((org-custom-properties '("FOO" "BAR")))
  1332. (org-test-with-temp-text
  1333. "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
  1334. (org-toggle-custom-properties-visibility)
  1335. (and (org-invisible-p2)
  1336. (not (progn (forward-line) (org-invisible-p2)))
  1337. (progn (forward-line) (org-invisible-p2))))))
  1338. ;; Hide custom properties with an empty value.
  1339. (should
  1340. (let ((org-custom-properties '("FOO")))
  1341. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
  1342. (org-toggle-custom-properties-visibility)
  1343. (org-invisible-p2))))
  1344. ;; Do not hide fake properties.
  1345. (should-not
  1346. (let ((org-custom-properties '("FOO")))
  1347. (org-test-with-temp-text ":FOO: val\n"
  1348. (org-toggle-custom-properties-visibility)
  1349. (org-invisible-p2))))
  1350. (should-not
  1351. (let ((org-custom-properties '("A")))
  1352. (org-test-with-temp-text
  1353. "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
  1354. (org-toggle-custom-properties-visibility)
  1355. (org-invisible-p2)))))
  1356. ;;; Mark Region
  1357. (ert-deftest test-org/mark-subtree ()
  1358. "Test `org-mark-subtree' specifications."
  1359. ;; Error when point is before first headline.
  1360. (should-error
  1361. (org-test-with-temp-text "Paragraph\n* Headline\nBody"
  1362. (progn (transient-mark-mode 1)
  1363. (org-mark-subtree))))
  1364. ;; Without argument, mark current subtree.
  1365. (should
  1366. (equal
  1367. '(12 32)
  1368. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  1369. (progn (transient-mark-mode 1)
  1370. (forward-line 2)
  1371. (org-mark-subtree)
  1372. (list (region-beginning) (region-end))))))
  1373. ;; With an argument, move ARG up.
  1374. (should
  1375. (equal
  1376. '(1 32)
  1377. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  1378. (progn (transient-mark-mode 1)
  1379. (forward-line 2)
  1380. (org-mark-subtree 1)
  1381. (list (region-beginning) (region-end))))))
  1382. ;; Do not get fooled by inlinetasks.
  1383. (when (featurep 'org-inlinetask)
  1384. (should
  1385. (= 1
  1386. (org-test-with-temp-text "* Headline\n*************** Task\nContents"
  1387. (progn (transient-mark-mode 1)
  1388. (forward-line 1)
  1389. (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
  1390. (region-beginning)))))))
  1391. ;;; Navigation
  1392. (ert-deftest test-org/beginning-of-line ()
  1393. "Test `org-beginning-of-line' specifications."
  1394. ;; Standard test.
  1395. (should
  1396. (org-test-with-temp-text "Some text\nSome other text"
  1397. (progn (org-beginning-of-line) (bolp))))
  1398. ;; Standard test with `visual-line-mode'.
  1399. (should-not
  1400. (org-test-with-temp-text "A long line of text\nSome other text"
  1401. (progn (visual-line-mode)
  1402. (forward-char 2)
  1403. (dotimes (i 1000) (insert "very "))
  1404. (org-beginning-of-line)
  1405. (bolp))))
  1406. ;; At an headline with special movement.
  1407. (should
  1408. (org-test-with-temp-text "* TODO Headline"
  1409. (let ((org-special-ctrl-a/e t))
  1410. (org-end-of-line)
  1411. (and (progn (org-beginning-of-line) (looking-at "Headline"))
  1412. (progn (org-beginning-of-line) (bolp))
  1413. (progn (org-beginning-of-line) (looking-at "Headline")))))))
  1414. (ert-deftest test-org/end-of-line ()
  1415. "Test `org-end-of-line' specifications."
  1416. ;; Standard test.
  1417. (should
  1418. (org-test-with-temp-text "Some text\nSome other text"
  1419. (progn (org-end-of-line) (eolp))))
  1420. ;; Standard test with `visual-line-mode'.
  1421. (should-not
  1422. (org-test-with-temp-text "A long line of text\nSome other text"
  1423. (progn (visual-line-mode)
  1424. (forward-char 2)
  1425. (dotimes (i 1000) (insert "very "))
  1426. (goto-char (point-min))
  1427. (org-end-of-line)
  1428. (eolp))))
  1429. ;; At an headline with special movement.
  1430. (should
  1431. (org-test-with-temp-text "* Headline1 :tag:\n"
  1432. (let ((org-special-ctrl-a/e t))
  1433. (and (progn (org-end-of-line) (looking-at " :tag:"))
  1434. (progn (org-end-of-line) (eolp))
  1435. (progn (org-end-of-line) (looking-at " :tag:"))))))
  1436. ;; At an headline without special movement.
  1437. (should
  1438. (org-test-with-temp-text "* Headline2 :tag:\n"
  1439. (let ((org-special-ctrl-a/e nil))
  1440. (and (progn (org-end-of-line) (eolp))
  1441. (progn (org-end-of-line) (eolp))))))
  1442. ;; At an headline, with reversed movement.
  1443. (should
  1444. (org-test-with-temp-text "* Headline3 :tag:\n"
  1445. (let ((org-special-ctrl-a/e 'reversed)
  1446. (this-command last-command))
  1447. (and (progn (org-end-of-line) (eolp))
  1448. (progn (org-end-of-line) (looking-at " :tag:"))))))
  1449. ;; At a block without hidden contents.
  1450. (should
  1451. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  1452. (progn (org-end-of-line) (eolp))))
  1453. ;; At a block with hidden contents.
  1454. (should-not
  1455. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  1456. (let ((org-special-ctrl-a/e t))
  1457. (org-hide-block-toggle)
  1458. (org-end-of-line)
  1459. (eobp)))))
  1460. (ert-deftest test-org/forward-paragraph ()
  1461. "Test `org-forward-paragraph' specifications."
  1462. ;; At end of buffer, return an error.
  1463. (should-error
  1464. (org-test-with-temp-text "Paragraph"
  1465. (goto-char (point-max))
  1466. (org-forward-paragraph)))
  1467. ;; Standard test.
  1468. (should
  1469. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  1470. (org-forward-paragraph)
  1471. (looking-at "P2")))
  1472. ;; Ignore depth.
  1473. (should
  1474. (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
  1475. (org-forward-paragraph)
  1476. (looking-at "P1")))
  1477. ;; Do not enter elements with invisible contents.
  1478. (should
  1479. (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
  1480. (org-hide-block-toggle)
  1481. (org-forward-paragraph)
  1482. (looking-at "P3")))
  1483. ;; On an affiliated keyword, jump to the beginning of the element.
  1484. (should
  1485. (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
  1486. (org-forward-paragraph)
  1487. (looking-at "Para")))
  1488. ;; On an item or a footnote definition, move to the second element
  1489. ;; inside, if any.
  1490. (should
  1491. (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
  1492. (org-forward-paragraph)
  1493. (looking-at " Paragraph")))
  1494. (should
  1495. (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
  1496. (org-forward-paragraph)
  1497. (looking-at "Paragraph")))
  1498. ;; On an item, or a footnote definition, when the first line is
  1499. ;; empty, move to the first item.
  1500. (should
  1501. (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
  1502. (org-forward-paragraph)
  1503. (looking-at " Paragraph")))
  1504. (should
  1505. (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
  1506. (org-forward-paragraph)
  1507. (looking-at "Paragraph")))
  1508. ;; On a table (resp. a property drawer) do not move through table
  1509. ;; rows (resp. node properties).
  1510. (should
  1511. (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
  1512. (org-forward-paragraph)
  1513. (looking-at "Paragraph")))
  1514. (should
  1515. (org-test-with-temp-text
  1516. "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
  1517. (org-forward-paragraph)
  1518. (looking-at "Paragraph")))
  1519. ;; On a verse or source block, stop after blank lines.
  1520. (should
  1521. (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
  1522. (org-forward-paragraph)
  1523. (looking-at "L2")))
  1524. (should
  1525. (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
  1526. (org-forward-paragraph)
  1527. (looking-at "L2"))))
  1528. (ert-deftest test-org/backward-paragraph ()
  1529. "Test `org-backward-paragraph' specifications."
  1530. ;; Error at beginning of buffer.
  1531. (should-error
  1532. (org-test-with-temp-text "Paragraph"
  1533. (org-backward-paragraph)))
  1534. ;; Regular test.
  1535. (should
  1536. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  1537. (goto-char (point-max))
  1538. (org-backward-paragraph)
  1539. (looking-at "P3")))
  1540. (should
  1541. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  1542. (goto-char (point-max))
  1543. (beginning-of-line)
  1544. (org-backward-paragraph)
  1545. (looking-at "P2")))
  1546. ;; Ignore depth.
  1547. (should
  1548. (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
  1549. (goto-char (point-max))
  1550. (beginning-of-line)
  1551. (org-backward-paragraph)
  1552. (looking-at "P2")))
  1553. ;; Ignore invisible elements.
  1554. (should
  1555. (org-test-with-temp-text "* H1\n P1\n* H2"
  1556. (org-cycle)
  1557. (goto-char (point-max))
  1558. (beginning-of-line)
  1559. (org-backward-paragraph)
  1560. (bobp)))
  1561. ;; On an affiliated keyword, jump to the first one.
  1562. (should
  1563. (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
  1564. (search-forward "c2")
  1565. (org-backward-paragraph)
  1566. (looking-at "#\\+name")))
  1567. ;; On the second element in an item or a footnote definition, jump
  1568. ;; to item or the definition.
  1569. (should
  1570. (org-test-with-temp-text "- line1\n\n line2"
  1571. (goto-char (point-max))
  1572. (beginning-of-line)
  1573. (org-backward-paragraph)
  1574. (looking-at "- line1")))
  1575. (should
  1576. (org-test-with-temp-text "[fn:1] line1\n\n line2"
  1577. (goto-char (point-max))
  1578. (beginning-of-line)
  1579. (org-backward-paragraph)
  1580. (looking-at "\\[fn:1\\] line1")))
  1581. ;; On a table (resp. a property drawer), ignore table rows
  1582. ;; (resp. node properties).
  1583. (should
  1584. (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
  1585. (goto-char (point-max))
  1586. (beginning-of-line)
  1587. (org-backward-paragraph)
  1588. (bobp)))
  1589. (should
  1590. (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
  1591. (org-backward-paragraph)
  1592. (looking-at ":PROPERTIES:")))
  1593. ;; On a source or verse block, stop before blank lines.
  1594. (should
  1595. (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
  1596. (search-forward "L3")
  1597. (beginning-of-line)
  1598. (org-backward-paragraph)
  1599. (looking-at "L2")))
  1600. (should
  1601. (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
  1602. (search-forward "L3")
  1603. (beginning-of-line)
  1604. (org-backward-paragraph)
  1605. (looking-at "L2"))))
  1606. (ert-deftest test-org/forward-element ()
  1607. "Test `org-forward-element' specifications."
  1608. ;; 1. At EOB: should error.
  1609. (org-test-with-temp-text "Some text\n"
  1610. (goto-char (point-max))
  1611. (should-error (org-forward-element)))
  1612. ;; 2. Standard move: expected to ignore blank lines.
  1613. (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
  1614. (org-forward-element)
  1615. (should (looking-at (regexp-quote "Second paragraph."))))
  1616. ;; 3. Headline tests.
  1617. (org-test-with-temp-text "
  1618. * Head 1
  1619. ** Head 1.1
  1620. *** Head 1.1.1
  1621. ** Head 1.2"
  1622. ;; 3.1. At an headline beginning: move to next headline at the
  1623. ;; same level.
  1624. (goto-line 3)
  1625. (org-forward-element)
  1626. (should (looking-at (regexp-quote "** Head 1.2")))
  1627. ;; 3.2. At an headline beginning: move to parent headline if no
  1628. ;; headline at the same level.
  1629. (goto-line 3)
  1630. (org-forward-element)
  1631. (should (looking-at (regexp-quote "** Head 1.2"))))
  1632. ;; 4. Greater element tests.
  1633. (org-test-with-temp-text
  1634. "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
  1635. ;; 4.1. At a greater element: expected to skip contents.
  1636. (org-forward-element)
  1637. (should (looking-at (regexp-quote "Outside.")))
  1638. ;; 4.2. At the end of greater element contents: expected to skip
  1639. ;; to the end of the greater element.
  1640. (goto-line 2)
  1641. (org-forward-element)
  1642. (should (looking-at (regexp-quote "Outside."))))
  1643. ;; 5. List tests.
  1644. (org-test-with-temp-text "
  1645. - item1
  1646. - sub1
  1647. - sub2
  1648. - sub3
  1649. Inner paragraph.
  1650. - item2
  1651. Outside."
  1652. ;; 5.1. At list top point: expected to move to the element after
  1653. ;; the list.
  1654. (goto-line 2)
  1655. (org-forward-element)
  1656. (should (looking-at (regexp-quote "Outside.")))
  1657. ;; 5.2. Special case: at the first line of a sub-list, but not at
  1658. ;; beginning of line, move to next item.
  1659. (goto-line 2)
  1660. (forward-char)
  1661. (org-forward-element)
  1662. (should (looking-at "- item2"))
  1663. (goto-line 4)
  1664. (forward-char)
  1665. (org-forward-element)
  1666. (should (looking-at " - sub2"))
  1667. ;; 5.3 At sub-list beginning: expected to move after the sub-list.
  1668. (goto-line 4)
  1669. (org-forward-element)
  1670. (should (looking-at (regexp-quote " Inner paragraph.")))
  1671. ;; 5.4. At sub-list end: expected to move outside the sub-list.
  1672. (goto-line 8)
  1673. (org-forward-element)
  1674. (should (looking-at (regexp-quote " Inner paragraph.")))
  1675. ;; 5.5. At an item: expected to move to next item, if any.
  1676. (goto-line 6)
  1677. (org-forward-element)
  1678. (should (looking-at " - sub3"))))
  1679. (ert-deftest test-org/backward-element ()
  1680. "Test `org-backward-element' specifications."
  1681. ;; 1. Should error at BOB.
  1682. (org-test-with-temp-text " \nParagraph."
  1683. (should-error (org-backward-element)))
  1684. ;; 2. Should move at BOB when called on the first element in buffer.
  1685. (should
  1686. (org-test-with-temp-text "\n#+TITLE: test"
  1687. (progn (forward-line)
  1688. (org-backward-element)
  1689. (bobp))))
  1690. ;; 3. Not at the beginning of an element: move at its beginning.
  1691. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  1692. (goto-line 3)
  1693. (end-of-line)
  1694. (org-backward-element)
  1695. (should (looking-at (regexp-quote "Paragraph2."))))
  1696. ;; 4. Headline tests.
  1697. (org-test-with-temp-text "
  1698. * Head 1
  1699. ** Head 1.1
  1700. *** Head 1.1.1
  1701. ** Head 1.2"
  1702. ;; 4.1. At an headline beginning: move to previous headline at the
  1703. ;; same level.
  1704. (goto-line 5)
  1705. (org-backward-element)
  1706. (should (looking-at (regexp-quote "** Head 1.1")))
  1707. ;; 4.2. At an headline beginning: move to parent headline if no
  1708. ;; headline at the same level.
  1709. (goto-line 3)
  1710. (org-backward-element)
  1711. (should (looking-at (regexp-quote "* Head 1")))
  1712. ;; 4.3. At the first top-level headline: should error.
  1713. (goto-line 2)
  1714. (should-error (org-backward-element)))
  1715. ;; 5. At beginning of first element inside a greater element:
  1716. ;; expected to move to greater element's beginning.
  1717. (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
  1718. (goto-line 3)
  1719. (org-backward-element)
  1720. (should (looking-at "#\\+BEGIN_CENTER")))
  1721. ;; 6. At the beginning of the first element in a section: should
  1722. ;; move back to headline, if any.
  1723. (should
  1724. (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
  1725. (progn (goto-char (point-max))
  1726. (beginning-of-line)
  1727. (org-backward-element)
  1728. (org-at-heading-p))))
  1729. ;; 7. List tests.
  1730. (org-test-with-temp-text "
  1731. - item1
  1732. - sub1
  1733. - sub2
  1734. - sub3
  1735. Inner paragraph.
  1736. - item2
  1737. Outside."
  1738. ;; 7.1. At beginning of sub-list: expected to move to the
  1739. ;; paragraph before it.
  1740. (goto-line 4)
  1741. (org-backward-element)
  1742. (should (looking-at "item1"))
  1743. ;; 7.2. At an item in a list: expected to move at previous item.
  1744. (goto-line 8)
  1745. (org-backward-element)
  1746. (should (looking-at " - sub2"))
  1747. (goto-line 12)
  1748. (org-backward-element)
  1749. (should (looking-at "- item1"))
  1750. ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
  1751. ;; beginning.
  1752. (goto-line 10)
  1753. (org-backward-element)
  1754. (should (looking-at " - sub1"))
  1755. (goto-line 15)
  1756. (org-backward-element)
  1757. (should (looking-at "- item1"))
  1758. ;; 7.4. At blank-lines before list end: expected to move to top
  1759. ;; item.
  1760. (goto-line 14)
  1761. (org-backward-element)
  1762. (should (looking-at "- item1"))))
  1763. (ert-deftest test-org/up-element ()
  1764. "Test `org-up-element' specifications."
  1765. ;; 1. At BOB or with no surrounding element: should error.
  1766. (org-test-with-temp-text "Paragraph."
  1767. (should-error (org-up-element)))
  1768. (org-test-with-temp-text "* Head1\n* Head2"
  1769. (goto-line 2)
  1770. (should-error (org-up-element)))
  1771. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  1772. (goto-line 3)
  1773. (should-error (org-up-element)))
  1774. ;; 2. At an headline: move to parent headline.
  1775. (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
  1776. (goto-line 3)
  1777. (org-up-element)
  1778. (should (looking-at "\\* Head1")))
  1779. ;; 3. Inside a greater element: move to greater element beginning.
  1780. (org-test-with-temp-text
  1781. "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
  1782. (goto-line 3)
  1783. (org-up-element)
  1784. (should (looking-at "#\\+BEGIN_CENTER")))
  1785. ;; 4. List tests.
  1786. (org-test-with-temp-text "* Top
  1787. - item1
  1788. - sub1
  1789. - sub2
  1790. Paragraph within sub2.
  1791. - item2"
  1792. ;; 4.1. Within an item: move to the item beginning.
  1793. (goto-line 8)
  1794. (org-up-element)
  1795. (should (looking-at " - sub2"))
  1796. ;; 4.2. At an item in a sub-list: move to parent item.
  1797. (goto-line 4)
  1798. (org-up-element)
  1799. (should (looking-at "- item1"))
  1800. ;; 4.3. At an item in top list: move to beginning of whole list.
  1801. (goto-line 10)
  1802. (org-up-element)
  1803. (should (looking-at "- item1"))
  1804. ;; 4.4. Special case. At very top point: should move to parent of
  1805. ;; list.
  1806. (goto-line 2)
  1807. (org-up-element)
  1808. (should (looking-at "\\* Top"))))
  1809. (ert-deftest test-org/down-element ()
  1810. "Test `org-down-element' specifications."
  1811. ;; Error when the element hasn't got a recursive type.
  1812. (org-test-with-temp-text "Paragraph."
  1813. (should-error (org-down-element)))
  1814. ;; Error when the element has no contents
  1815. (org-test-with-temp-text "* Headline"
  1816. (should-error (org-down-element)))
  1817. ;; When at a plain-list, move to first item.
  1818. (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
  1819. (goto-line 2)
  1820. (org-down-element)
  1821. (should (looking-at " - Item 1.1")))
  1822. (org-test-with-temp-text "#+NAME: list\n- Item 1"
  1823. (org-down-element)
  1824. (should (looking-at " Item 1")))
  1825. ;; When at a table, move to first row
  1826. (org-test-with-temp-text "#+NAME: table\n| a | b |"
  1827. (org-down-element)
  1828. (should (looking-at " a | b |")))
  1829. ;; Otherwise, move inside the greater element.
  1830. (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
  1831. (org-down-element)
  1832. (should (looking-at "Paragraph"))))
  1833. (ert-deftest test-org/drag-element-backward ()
  1834. "Test `org-drag-element-backward' specifications."
  1835. ;; Standard test.
  1836. (should
  1837. (equal
  1838. "#+key2: val2\n#+key1: val1\n#+key3: val3"
  1839. (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
  1840. (org-drag-element-backward)
  1841. (buffer-string))))
  1842. (should
  1843. (equal
  1844. "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
  1845. (org-test-with-temp-text
  1846. "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
  1847. (org-drag-element-backward)
  1848. (buffer-string))))
  1849. ;; Preserve blank lines.
  1850. (should
  1851. (equal "Paragraph 2\n\n\nPara1\n\nPara3"
  1852. (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
  1853. (org-drag-element-backward)
  1854. (buffer-string))))
  1855. ;; Preserve column.
  1856. (should
  1857. (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
  1858. (org-drag-element-backward)
  1859. (org-looking-at-p "2")))
  1860. ;; Error when trying to move first element of buffer.
  1861. (should-error
  1862. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  1863. (org-drag-element-backward)))
  1864. ;; Error when trying to swap nested elements.
  1865. (should-error
  1866. (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
  1867. (forward-line)
  1868. (org-drag-element-backward)))
  1869. ;; Error when trying to swap an headline element and a non-headline
  1870. ;; element.
  1871. (should-error
  1872. (org-test-with-temp-text "Test.\n* Head 1"
  1873. (forward-line)
  1874. (org-drag-element-backward)))
  1875. ;; Preserve visibility of elements and their contents.
  1876. (should
  1877. (equal '((63 . 82) (26 . 48))
  1878. (org-test-with-temp-text "
  1879. #+BEGIN_CENTER
  1880. Text.
  1881. #+END_CENTER
  1882. - item 1
  1883. #+BEGIN_QUOTE
  1884. Text.
  1885. #+END_QUOTE"
  1886. (while (search-forward "BEGIN_" nil t) (org-cycle))
  1887. (search-backward "- item 1")
  1888. (org-drag-element-backward)
  1889. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  1890. (overlays-in (point-min) (point-max)))))))
  1891. (ert-deftest test-org/drag-element-forward ()
  1892. "Test `org-drag-element-forward' specifications."
  1893. ;; 1. Error when trying to move first element of buffer.
  1894. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  1895. (goto-line 3)
  1896. (should-error (org-drag-element-forward)))
  1897. ;; 2. Error when trying to swap nested elements.
  1898. (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
  1899. (forward-line)
  1900. (should-error (org-drag-element-forward)))
  1901. ;; 3. Error when trying to swap a non-headline element and an
  1902. ;; headline.
  1903. (org-test-with-temp-text "Test.\n* Head 1"
  1904. (should-error (org-drag-element-forward)))
  1905. ;; 4. Otherwise, swap elements, preserving column and blank lines
  1906. ;; between elements.
  1907. (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
  1908. (search-forward "graph")
  1909. (org-drag-element-forward)
  1910. (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
  1911. (should (looking-at " 1")))
  1912. ;; 5. Preserve visibility of elements and their contents.
  1913. (org-test-with-temp-text "
  1914. #+BEGIN_CENTER
  1915. Text.
  1916. #+END_CENTER
  1917. - item 1
  1918. #+BEGIN_QUOTE
  1919. Text.
  1920. #+END_QUOTE"
  1921. (while (search-forward "BEGIN_" nil t) (org-cycle))
  1922. (search-backward "#+BEGIN_CENTER")
  1923. (org-drag-element-forward)
  1924. (should
  1925. (equal
  1926. '((63 . 82) (26 . 48))
  1927. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  1928. (overlays-in (point-min) (point-max)))))))
  1929. ;;; Outline structure
  1930. (ert-deftest test-org/demote ()
  1931. "Test `org-demote' specifications."
  1932. ;; Add correct number of stars according to `org-odd-levels-only'.
  1933. (should
  1934. (= 2
  1935. (org-test-with-temp-text "* H"
  1936. (let ((org-odd-levels-only nil)) (org-demote))
  1937. (org-current-level))))
  1938. (should
  1939. (= 3
  1940. (org-test-with-temp-text "* H"
  1941. (let ((org-odd-levels-only t)) (org-demote))
  1942. (org-current-level))))
  1943. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  1944. (should
  1945. (org-test-with-temp-text "* H :tag:"
  1946. (let ((org-tags-column 10)
  1947. (org-auto-align-tags t)
  1948. (org-odd-levels-only nil))
  1949. (org-demote))
  1950. (org-move-to-column 10)
  1951. (org-looking-at-p ":tag:$")))
  1952. (should-not
  1953. (org-test-with-temp-text "* H :tag:"
  1954. (let ((org-tags-column 10)
  1955. (org-auto-align-tags nil)
  1956. (org-odd-levels-only nil))
  1957. (org-demote))
  1958. (org-move-to-column 10)
  1959. (org-looking-at-p ":tag:$")))
  1960. ;; When `org-adapt-indentation' is non-nil, always indent planning
  1961. ;; info and property drawers accordingly.
  1962. (should
  1963. (= 3
  1964. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  1965. (let ((org-odd-levels-only nil)
  1966. (org-adapt-indentation t))
  1967. (org-demote))
  1968. (forward-line)
  1969. (org-get-indentation))))
  1970. (should
  1971. (= 3
  1972. (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  1973. (let ((org-odd-levels-only nil)
  1974. (org-adapt-indentation t))
  1975. (org-demote))
  1976. (forward-line)
  1977. (org-get-indentation))))
  1978. (should-not
  1979. (= 3
  1980. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  1981. (let ((org-odd-levels-only nil)
  1982. (org-adapt-indentation nil))
  1983. (org-demote))
  1984. (forward-line)
  1985. (org-get-indentation))))
  1986. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  1987. ;; section accordingly. Ignore, however, footnote definitions and
  1988. ;; inlinetasks boundaries.
  1989. (should
  1990. (= 3
  1991. (org-test-with-temp-text "* H\n Paragraph"
  1992. (let ((org-odd-levels-only nil)
  1993. (org-adapt-indentation t))
  1994. (org-demote))
  1995. (forward-line)
  1996. (org-get-indentation))))
  1997. (should
  1998. (= 2
  1999. (org-test-with-temp-text "* H\n Paragraph"
  2000. (let ((org-odd-levels-only nil)
  2001. (org-adapt-indentation nil))
  2002. (org-demote))
  2003. (forward-line)
  2004. (org-get-indentation))))
  2005. (should
  2006. (zerop
  2007. (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
  2008. (let ((org-odd-levels-only nil)
  2009. (org-adapt-indentation t))
  2010. (org-demote))
  2011. (goto-char (point-max))
  2012. (org-get-indentation))))
  2013. (should
  2014. (= 3
  2015. (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
  2016. (let ((org-odd-levels-only nil)
  2017. (org-adapt-indentation t))
  2018. (org-demote))
  2019. (goto-char (point-max))
  2020. (org-get-indentation))))
  2021. (when (featurep 'org-inlinetask)
  2022. (should
  2023. (zerop
  2024. (let ((org-inlinetask-min-level 5)
  2025. (org-adapt-indentation t))
  2026. (org-test-with-temp-text "* H\n***** I\n***** END"
  2027. (org-demote)
  2028. (forward-line)
  2029. (org-get-indentation))))))
  2030. (when (featurep 'org-inlinetask)
  2031. (should
  2032. (= 3
  2033. (let ((org-inlinetask-min-level 5)
  2034. (org-adapt-indentation t))
  2035. (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
  2036. (org-demote)
  2037. (forward-line 2)
  2038. (org-get-indentation))))))
  2039. ;; Ignore contents of source blocks or example blocks when
  2040. ;; indentation should be preserved (through
  2041. ;; `org-src-preserve-indentation' or "-i" flag).
  2042. (should-not
  2043. (zerop
  2044. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  2045. (let ((org-adapt-indentation t)
  2046. (org-src-preserve-indentation nil))
  2047. (org-demote))
  2048. (forward-line 2)
  2049. (org-get-indentation))))
  2050. (should
  2051. (zerop
  2052. (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
  2053. (let ((org-adapt-indentation t)
  2054. (org-src-preserve-indentation t))
  2055. (org-demote))
  2056. (forward-line 2)
  2057. (org-get-indentation))))
  2058. (should
  2059. (zerop
  2060. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  2061. (let ((org-adapt-indentation t)
  2062. (org-src-preserve-indentation t))
  2063. (org-demote))
  2064. (forward-line 2)
  2065. (org-get-indentation))))
  2066. (should
  2067. (zerop
  2068. (org-test-with-temp-text
  2069. "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
  2070. (let ((org-adapt-indentation t)
  2071. (org-src-preserve-indentation nil))
  2072. (org-demote))
  2073. (forward-line 2)
  2074. (org-get-indentation)))))
  2075. (ert-deftest test-org/promote ()
  2076. "Test `org-promote' specifications."
  2077. ;; Return an error if headline is to be promoted to level 0, unless
  2078. ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
  2079. ;; headline becomes a comment.
  2080. (should-error
  2081. (org-test-with-temp-text "* H"
  2082. (let ((org-allow-promoting-top-level-subtree nil)) (org-promote))))
  2083. (should
  2084. (equal "# H"
  2085. (org-test-with-temp-text "* H"
  2086. (let ((org-allow-promoting-top-level-subtree t)) (org-promote))
  2087. (buffer-string))))
  2088. ;; Remove correct number of stars according to
  2089. ;; `org-odd-levels-only'.
  2090. (should
  2091. (= 2
  2092. (org-test-with-temp-text "*** H"
  2093. (let ((org-odd-levels-only nil)) (org-promote))
  2094. (org-current-level))))
  2095. (should
  2096. (= 1
  2097. (org-test-with-temp-text "*** H"
  2098. (let ((org-odd-levels-only t)) (org-promote))
  2099. (org-current-level))))
  2100. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  2101. (should
  2102. (org-test-with-temp-text "** H :tag:"
  2103. (let ((org-tags-column 10)
  2104. (org-auto-align-tags t)
  2105. (org-odd-levels-only nil))
  2106. (org-promote))
  2107. (org-move-to-column 10)
  2108. (org-looking-at-p ":tag:$")))
  2109. (should-not
  2110. (org-test-with-temp-text "** H :tag:"
  2111. (let ((org-tags-column 10)
  2112. (org-auto-align-tags nil)
  2113. (org-odd-levels-only nil))
  2114. (org-promote))
  2115. (org-move-to-column 10)
  2116. (org-looking-at-p ":tag:$")))
  2117. ;; When `org-adapt-indentation' is non-nil, always indent planning
  2118. ;; info and property drawers.
  2119. (should
  2120. (= 2
  2121. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  2122. (let ((org-odd-levels-only nil)
  2123. (org-adapt-indentation t))
  2124. (org-promote))
  2125. (forward-line)
  2126. (org-get-indentation))))
  2127. (should
  2128. (= 2
  2129. (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  2130. (let ((org-odd-levels-only nil)
  2131. (org-adapt-indentation t))
  2132. (org-promote))
  2133. (forward-line)
  2134. (org-get-indentation))))
  2135. (should-not
  2136. (= 2
  2137. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  2138. (let ((org-odd-levels-only nil)
  2139. (org-adapt-indentation nil))
  2140. (org-promote))
  2141. (forward-line)
  2142. (org-get-indentation))))
  2143. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  2144. ;; section accordingly. Ignore, however, footnote definitions and
  2145. ;; inlinetasks boundaries.
  2146. (should
  2147. (= 2
  2148. (org-test-with-temp-text "** H\n Paragraph"
  2149. (let ((org-odd-levels-only nil)
  2150. (org-adapt-indentation t))
  2151. (org-promote))
  2152. (forward-line)
  2153. (org-get-indentation))))
  2154. (should-not
  2155. (= 2
  2156. (org-test-with-temp-text "** H\n Paragraph"
  2157. (let ((org-odd-levels-only nil)
  2158. (org-adapt-indentation nil))
  2159. (org-promote))
  2160. (forward-line)
  2161. (org-get-indentation))))
  2162. (should
  2163. (= 2
  2164. (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
  2165. (let ((org-odd-levels-only nil)
  2166. (org-adapt-indentation t))
  2167. (org-promote))
  2168. (forward-line)
  2169. (org-get-indentation))))
  2170. (when (featurep 'org-inlinetask)
  2171. (should
  2172. (zerop
  2173. (let ((org-inlinetask-min-level 5)
  2174. (org-adapt-indentation t))
  2175. (org-test-with-temp-text "** H\n***** I\n***** END"
  2176. (org-promote)
  2177. (forward-line)
  2178. (org-get-indentation))))))
  2179. (when (featurep 'org-inlinetask)
  2180. (should
  2181. (= 2
  2182. (let ((org-inlinetask-min-level 5)
  2183. (org-adapt-indentation t))
  2184. (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
  2185. (org-promote)
  2186. (forward-line 2)
  2187. (org-get-indentation))))))
  2188. ;; Give up shifting if it would break document's structure
  2189. ;; otherwise.
  2190. (should
  2191. (= 3
  2192. (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
  2193. (let ((org-odd-levels-only nil)
  2194. (org-adapt-indentation t))
  2195. (org-promote))
  2196. (forward-line)
  2197. (org-get-indentation))))
  2198. (should
  2199. (= 3
  2200. (org-test-with-temp-text "** H\n Paragraph\n * list."
  2201. (let ((org-odd-levels-only nil)
  2202. (org-adapt-indentation t))
  2203. (org-promote))
  2204. (forward-line)
  2205. (org-get-indentation))))
  2206. ;; Ignore contents of source blocks or example blocks when
  2207. ;; indentation should be preserved (through
  2208. ;; `org-src-preserve-indentation' or "-i" flag).
  2209. (should-not
  2210. (zerop
  2211. (org-test-with-temp-text
  2212. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  2213. (let ((org-adapt-indentation t)
  2214. (org-src-preserve-indentation nil)
  2215. (org-odd-levels-only nil))
  2216. (org-promote))
  2217. (forward-line)
  2218. (org-get-indentation))))
  2219. (should
  2220. (zerop
  2221. (org-test-with-temp-text
  2222. "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
  2223. (let ((org-adapt-indentation t)
  2224. (org-src-preserve-indentation t)
  2225. (org-odd-levels-only nil))
  2226. (org-promote))
  2227. (forward-line)
  2228. (org-get-indentation))))
  2229. (should
  2230. (zerop
  2231. (org-test-with-temp-text
  2232. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  2233. (let ((org-adapt-indentation t)
  2234. (org-src-preserve-indentation t)
  2235. (org-odd-levels-only nil))
  2236. (org-promote))
  2237. (forward-line)
  2238. (org-get-indentation))))
  2239. (should
  2240. (zerop
  2241. (org-test-with-temp-text
  2242. "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
  2243. (let ((org-adapt-indentation t)
  2244. (org-src-preserve-indentation nil)
  2245. (org-odd-levels-only nil))
  2246. (org-promote))
  2247. (forward-line)
  2248. (org-get-indentation)))))
  2249. ;;; Planning
  2250. (ert-deftest test-org/timestamp-has-time-p ()
  2251. "Test `org-timestamp-has-time-p' specifications."
  2252. ;; With time.
  2253. (should
  2254. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  2255. (org-timestamp-has-time-p (org-element-context))))
  2256. ;; Without time.
  2257. (should-not
  2258. (org-test-with-temp-text "<2012-03-29 Thu>"
  2259. (org-timestamp-has-time-p (org-element-context)))))
  2260. (ert-deftest test-org/timestamp-format ()
  2261. "Test `org-timestamp-format' specifications."
  2262. ;; Regular test.
  2263. (should
  2264. (equal
  2265. "2012-03-29 16:40"
  2266. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  2267. (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
  2268. ;; Range end.
  2269. (should
  2270. (equal
  2271. "2012-03-29"
  2272. (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
  2273. (org-timestamp-format (org-element-context) "%Y-%m-%d" t)))))
  2274. (ert-deftest test-org/timestamp-split-range ()
  2275. "Test `org-timestamp-split-range' specifications."
  2276. ;; Extract range start (active).
  2277. (should
  2278. (equal '(2012 3 29)
  2279. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  2280. (let ((ts (org-timestamp-split-range (org-element-context))))
  2281. (mapcar (lambda (p) (org-element-property p ts))
  2282. '(:year-end :month-end :day-end))))))
  2283. ;; Extract range start (inactive)
  2284. (should
  2285. (equal '(2012 3 29)
  2286. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  2287. (let ((ts (org-timestamp-split-range (org-element-context))))
  2288. (mapcar (lambda (p) (org-element-property p ts))
  2289. '(:year-end :month-end :day-end))))))
  2290. ;; Extract range end (active).
  2291. (should
  2292. (equal '(2012 3 30)
  2293. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  2294. (let ((ts (org-timestamp-split-range
  2295. (org-element-context) t)))
  2296. (mapcar (lambda (p) (org-element-property p ts))
  2297. '(:year-end :month-end :day-end))))))
  2298. ;; Extract range end (inactive)
  2299. (should
  2300. (equal '(2012 3 30)
  2301. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  2302. (let ((ts (org-timestamp-split-range
  2303. (org-element-context) t)))
  2304. (mapcar (lambda (p) (org-element-property p ts))
  2305. '(:year-end :month-end :day-end))))))
  2306. ;; Return the timestamp if not a range.
  2307. (should
  2308. (org-test-with-temp-text "[2012-03-29 Thu]"
  2309. (let* ((ts-orig (org-element-context))
  2310. (ts-copy (org-timestamp-split-range ts-orig)))
  2311. (eq ts-orig ts-copy))))
  2312. (should
  2313. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  2314. (let* ((ts-orig (org-element-context))
  2315. (ts-copy (org-timestamp-split-range ts-orig)))
  2316. (eq ts-orig ts-copy))))
  2317. ;; Check that parent is the same when a range was split.
  2318. (should
  2319. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  2320. (let* ((ts-orig (org-element-context))
  2321. (ts-copy (org-timestamp-split-range ts-orig)))
  2322. (eq (org-element-property :parent ts-orig)
  2323. (org-element-property :parent ts-copy))))))
  2324. (ert-deftest test-org/timestamp-translate ()
  2325. "Test `org-timestamp-translate' specifications."
  2326. ;; Translate whole date range.
  2327. (should
  2328. (equal "<29>--<30>"
  2329. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  2330. (let ((org-display-custom-times t)
  2331. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  2332. (org-timestamp-translate (org-element-context))))))
  2333. ;; Translate date range start.
  2334. (should
  2335. (equal "<29>"
  2336. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  2337. (let ((org-display-custom-times t)
  2338. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  2339. (org-timestamp-translate (org-element-context) 'start)))))
  2340. ;; Translate date range end.
  2341. (should
  2342. (equal "<30>"
  2343. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  2344. (let ((org-display-custom-times t)
  2345. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  2346. (org-timestamp-translate (org-element-context) 'end)))))
  2347. ;; Translate time range.
  2348. (should
  2349. (equal "<08>--<16>"
  2350. (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
  2351. (let ((org-display-custom-times t)
  2352. (org-time-stamp-custom-formats '("<%d>" . "<%H>")))
  2353. (org-timestamp-translate (org-element-context))))))
  2354. ;; Translate non-range timestamp.
  2355. (should
  2356. (equal "<29>"
  2357. (org-test-with-temp-text "<2012-03-29 Thu>"
  2358. (let ((org-display-custom-times t)
  2359. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  2360. (org-timestamp-translate (org-element-context))))))
  2361. ;; Do not change `diary' timestamps.
  2362. (should
  2363. (equal "<%%(org-float t 4 2)>"
  2364. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  2365. (let ((org-display-custom-times t)
  2366. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  2367. (org-timestamp-translate (org-element-context)))))))
  2368. ;;; Property API
  2369. (ert-deftest test-org/buffer-property-keys ()
  2370. "Test `org-buffer-property-keys' specifications."
  2371. ;; Retrieve properties accross siblings.
  2372. (should
  2373. (equal '("A" "B")
  2374. (org-test-with-temp-text "
  2375. * H1
  2376. :PROPERTIES:
  2377. :A: 1
  2378. :END:
  2379. * H2
  2380. :PROPERTIES:
  2381. :B: 1
  2382. :END:"
  2383. (org-buffer-property-keys))))
  2384. ;; Retrieve properties accross children.
  2385. (should
  2386. (equal '("A" "B")
  2387. (org-test-with-temp-text "
  2388. * H1
  2389. :PROPERTIES:
  2390. :A: 1
  2391. :END:
  2392. ** H2
  2393. :PROPERTIES:
  2394. :B: 1
  2395. :END:"
  2396. (org-buffer-property-keys))))
  2397. ;; Retrieve muliple properties in the same drawer.
  2398. (should
  2399. (equal '("A" "B")
  2400. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  2401. (org-buffer-property-keys))))
  2402. ;; Ignore extension symbol in property name.
  2403. (should
  2404. (equal '("A")
  2405. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  2406. (org-buffer-property-keys))))
  2407. ;; With non-nil COLUMNS, extract property names from columns.
  2408. (should
  2409. (equal '("A" "B")
  2410. (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
  2411. (org-buffer-property-keys nil nil t))))
  2412. (should
  2413. (equal '("A" "B" "COLUMNS")
  2414. (org-test-with-temp-text
  2415. "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
  2416. (org-buffer-property-keys nil nil t)))))
  2417. (ert-deftest test-org/property-values ()
  2418. "Test `org-property-values' specifications."
  2419. ;; Regular test.
  2420. (should
  2421. (equal '("2" "1")
  2422. (org-test-with-temp-text
  2423. "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
  2424. (org-property-values "A"))))
  2425. ;; Ignore empty values.
  2426. (should-not
  2427. (org-test-with-temp-text
  2428. "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
  2429. (org-property-values "A")))
  2430. ;; Take into consideration extended values.
  2431. (should
  2432. (equal '("1 2")
  2433. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  2434. (org-property-values "A")))))
  2435. (ert-deftest test-org/entry-delete ()
  2436. "Test `org-entry-delete' specifications."
  2437. ;; Regular test.
  2438. (should
  2439. (string-match
  2440. " *:PROPERTIES:\n *:B: +2\n *:END:"
  2441. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  2442. (org-entry-delete (point) "A")
  2443. (buffer-string))))
  2444. ;; When last property is removed, remove the property drawer.
  2445. (should-not
  2446. (string-match
  2447. ":PROPERTIES:"
  2448. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
  2449. (org-entry-delete (point) "A")
  2450. (buffer-string)))))
  2451. (ert-deftest test-org/entry-get ()
  2452. "Test `org-entry-get' specifications."
  2453. ;; Regular test.
  2454. (should
  2455. (equal "1"
  2456. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  2457. (org-entry-get (point) "A"))))
  2458. ;; Ignore case.
  2459. (should
  2460. (equal "1"
  2461. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  2462. (org-entry-get (point) "a"))))
  2463. ;; Handle extended values, both before and after base value.
  2464. (should
  2465. (equal "1 2 3"
  2466. (org-test-with-temp-text
  2467. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  2468. (org-entry-get (point) "A"))))
  2469. ;; Empty values are returned as the empty string.
  2470. (should
  2471. (equal ""
  2472. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
  2473. (org-entry-get (point) "A"))))
  2474. ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
  2475. ;; otherwise, return nil.
  2476. (should-not
  2477. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  2478. (org-entry-get (point) "A")))
  2479. (should
  2480. (equal "nil"
  2481. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  2482. (org-entry-get (point) "A" nil t))))
  2483. ;; Return nil when no property is found, independently on the
  2484. ;; LITERAL-NIL argument.
  2485. (should-not
  2486. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  2487. (org-entry-get (point) "B")))
  2488. (should-not
  2489. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  2490. (org-entry-get (point) "B" nil t)))
  2491. ;; Handle inheritance, when allowed.
  2492. (should
  2493. (equal
  2494. "1"
  2495. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
  2496. (org-entry-get (point) "A" t))))
  2497. (should
  2498. (equal
  2499. "1"
  2500. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
  2501. (let ((org-use-property-inheritance t))
  2502. (org-entry-get (point) "A" 'selective)))))
  2503. (should-not
  2504. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
  2505. (let ((org-use-property-inheritance nil))
  2506. (org-entry-get (point) "A" 'selective)))))
  2507. (ert-deftest test-org/entry-properties ()
  2508. "Test `org-entry-properties' specifications."
  2509. ;; Get "ITEM" property.
  2510. (should
  2511. (equal "* H"
  2512. (org-test-with-temp-text "* TODO H"
  2513. (cdr (assoc "ITEM" (org-entry-properties nil "ITEM"))))))
  2514. ;; Get "TODO" property.
  2515. (should
  2516. (equal "TODO"
  2517. (org-test-with-temp-text "* TODO H"
  2518. (cdr (assoc "TODO" (org-entry-properties nil "TODO"))))))
  2519. (should-not
  2520. (org-test-with-temp-text "* H"
  2521. (assoc "TODO" (org-entry-properties nil "TODO"))))
  2522. ;; Get "PRIORITY" property.
  2523. (should
  2524. (equal "A"
  2525. (org-test-with-temp-text "* [#A] H"
  2526. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  2527. (should-not
  2528. (org-test-with-temp-text "* H"
  2529. (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))
  2530. ;; Get "FILE" property.
  2531. (should
  2532. (org-test-with-temp-text-in-file "* H\nParagraph"
  2533. (org-file-equal-p (cdr (assoc "FILE" (org-entry-properties nil "FILE")))
  2534. (buffer-file-name))))
  2535. (should-not
  2536. (org-test-with-temp-text "* H\nParagraph"
  2537. (cdr (assoc "FILE" (org-entry-properties nil "FILE")))))
  2538. ;; Get "TAGS" property.
  2539. (should
  2540. (equal ":tag1:tag2:"
  2541. (org-test-with-temp-text "* H :tag1:tag2:"
  2542. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS"))))))
  2543. (should-not
  2544. (org-test-with-temp-text "* H"
  2545. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS")))))
  2546. ;; Get "ALLTAGS" property.
  2547. (should
  2548. (equal ":tag1:tag2:"
  2549. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  2550. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS"))))))
  2551. (should-not
  2552. (org-test-with-temp-text "* H"
  2553. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS")))))
  2554. ;; Get "BLOCKED" property.
  2555. (should
  2556. (equal "t"
  2557. (org-test-with-temp-text "* Blocked\n** DONE one\n** TODO two"
  2558. (let ((org-enforce-todo-dependencies t)
  2559. (org-blocker-hook
  2560. '(org-block-todo-from-children-or-siblings-or-parent)))
  2561. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  2562. (should
  2563. (equal ""
  2564. (org-test-with-temp-text "* Blocked\n** DONE one\n** DONE two"
  2565. (let ((org-enforce-todo-dependencies t))
  2566. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  2567. ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
  2568. (should
  2569. (equal
  2570. "[2012-03-29 thu.]"
  2571. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  2572. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED"))))))
  2573. (should-not
  2574. (org-test-with-temp-text "* H"
  2575. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED")))))
  2576. (should
  2577. (equal
  2578. "<2014-03-04 tue.>"
  2579. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  2580. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE"))))))
  2581. (should-not
  2582. (org-test-with-temp-text "* H"
  2583. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE")))))
  2584. (should
  2585. (equal
  2586. "<2014-03-04 tue.>"
  2587. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  2588. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED"))))))
  2589. (should-not
  2590. (org-test-with-temp-text "* H"
  2591. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED")))))
  2592. ;; Get "CATEGORY"
  2593. (should
  2594. (equal "cat"
  2595. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  2596. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  2597. (should
  2598. (equal "cat"
  2599. (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
  2600. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  2601. ;; Get standard properties.
  2602. (should
  2603. (equal "1"
  2604. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  2605. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  2606. ;; Handle extended properties.
  2607. (should
  2608. (equal "1 2 3"
  2609. (org-test-with-temp-text
  2610. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  2611. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  2612. (should
  2613. (equal "1 2 3"
  2614. (org-test-with-temp-text
  2615. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
  2616. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  2617. ;; Ignore forbidden (special) properties.
  2618. (should-not
  2619. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
  2620. (cdr (assoc "TODO" (org-entry-properties nil 'standard))))))
  2621. (ert-deftest test-org/entry-put ()
  2622. "Test `org-entry-put' specifications."
  2623. ;; Error when not a string or nil.
  2624. (should-error
  2625. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  2626. (org-entry-put 1 "test" 2)))
  2627. ;; Set "TODO" property.
  2628. (should
  2629. (string-match (regexp-quote " TODO H")
  2630. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  2631. (org-entry-put (point) "TODO" "TODO")
  2632. (buffer-string))))
  2633. (should
  2634. (string-match (regexp-quote "* H")
  2635. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  2636. (org-entry-put (point) "TODO" nil)
  2637. (buffer-string))))
  2638. ;; Set "PRIORITY" property.
  2639. (should
  2640. (equal "* [#A] H"
  2641. (org-test-with-temp-text "* [#B] H"
  2642. (org-entry-put (point) "PRIORITY" "A")
  2643. (buffer-string))))
  2644. (should
  2645. (equal "* H"
  2646. (org-test-with-temp-text "* [#B] H"
  2647. (org-entry-put (point) "PRIORITY" nil)
  2648. (buffer-string))))
  2649. ;; Set "SCHEDULED" property.
  2650. (should
  2651. (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
  2652. (org-test-with-temp-text "* H"
  2653. (org-entry-put (point) "SCHEDULED" "2014-03-04")
  2654. (buffer-string))))
  2655. (should
  2656. (string= "* H\n"
  2657. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  2658. (org-entry-put (point) "SCHEDULED" nil)
  2659. (buffer-string))))
  2660. (should
  2661. (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
  2662. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  2663. (org-entry-put (point) "SCHEDULED" "earlier")
  2664. (buffer-string))))
  2665. (should
  2666. (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
  2667. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  2668. (org-entry-put (point) "SCHEDULED" "later")
  2669. (buffer-string))))
  2670. ;; Set "DEADLINE" property.
  2671. (should
  2672. (string-match "^ *DEADLINE: <2014-03-04 .*?>"
  2673. (org-test-with-temp-text "* H"
  2674. (org-entry-put (point) "DEADLINE" "2014-03-04")
  2675. (buffer-string))))
  2676. (should
  2677. (string= "* H\n"
  2678. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  2679. (org-entry-put (point) "DEADLINE" nil)
  2680. (buffer-string))))
  2681. (should
  2682. (string-match "^ *DEADLINE: <2014-03-03 .*?>"
  2683. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  2684. (org-entry-put (point) "DEADLINE" "earlier")
  2685. (buffer-string))))
  2686. (should
  2687. (string-match "^ *DEADLINE: <2014-03-05 .*?>"
  2688. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  2689. (org-entry-put (point) "DEADLINE" "later")
  2690. (buffer-string))))
  2691. ;; Regular properties, with or without pre-existing drawer.
  2692. (should
  2693. (string-match "^ *:A: +2$"
  2694. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  2695. (org-entry-put (point) "A" "2")
  2696. (buffer-string))))
  2697. (should
  2698. (string-match "^ *:A: +1$"
  2699. (org-test-with-temp-text "* H"
  2700. (org-entry-put (point) "A" "1")
  2701. (buffer-string))))
  2702. ;; Special case: two consecutive headlines.
  2703. (should
  2704. (string-match "\\* A\n *:PROPERTIES:"
  2705. (org-test-with-temp-text "* A\n** B"
  2706. (org-entry-put (point) "A" "1")
  2707. (buffer-string)))))
  2708. ;;; Radio Targets
  2709. (ert-deftest test-org/update-radio-target-regexp ()
  2710. "Test `org-update-radio-target-regexp' specifications."
  2711. ;; Properly update cache with no previous radio target regexp.
  2712. (should
  2713. (eq 'link
  2714. (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
  2715. (save-excursion (goto-char (point-max)) (org-element-context))
  2716. (insert "<<<")
  2717. (search-forward "o")
  2718. (insert ">>>")
  2719. (org-update-radio-target-regexp)
  2720. (goto-char (point-max))
  2721. (org-element-type (org-element-context)))))
  2722. ;; Properly update cache with previous radio target regexp.
  2723. (should
  2724. (eq 'link
  2725. (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
  2726. (save-excursion (goto-char (point-max)) (org-element-context))
  2727. (insert "<<<")
  2728. (search-forward "o")
  2729. (insert ">>>")
  2730. (org-update-radio-target-regexp)
  2731. (search-backward "r")
  2732. (delete-char 5)
  2733. (insert "new")
  2734. (org-update-radio-target-regexp)
  2735. (goto-char (point-max))
  2736. (delete-region (line-beginning-position) (point))
  2737. (insert "new")
  2738. (org-element-type (org-element-context))))))
  2739. ;;; Visibility
  2740. (ert-deftest test-org/flag-drawer ()
  2741. "Test `org-flag-drawer' specifications."
  2742. ;; Hide drawer.
  2743. (should
  2744. (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
  2745. (org-flag-drawer t)
  2746. (get-char-property (line-end-position) 'invisible)))
  2747. ;; Show drawer.
  2748. (should-not
  2749. (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
  2750. (org-flag-drawer t)
  2751. (org-flag-drawer nil)
  2752. (get-char-property (line-end-position) 'invisible)))
  2753. ;; Test optional argument.
  2754. (should
  2755. (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
  2756. (let ((drawer (save-excursion (search-forward ":D2")
  2757. (org-element-at-point))))
  2758. (org-flag-drawer t drawer)
  2759. (get-char-property (progn (search-forward ":D2") (line-end-position))
  2760. 'invisible))))
  2761. (should-not
  2762. (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
  2763. (let ((drawer (save-excursion (search-forward ":D2")
  2764. (org-element-at-point))))
  2765. (org-flag-drawer t drawer)
  2766. (get-char-property (line-end-position) 'invisible))))
  2767. ;; Do not hide fake drawers.
  2768. (should-not
  2769. (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
  2770. (forward-line 1)
  2771. (org-flag-drawer t)
  2772. (get-char-property (line-end-position) 'invisible)))
  2773. ;; Do not hide incomplete drawers.
  2774. (should-not
  2775. (org-test-with-temp-text ":D:\nparagraph"
  2776. (forward-line 1)
  2777. (org-flag-drawer t)
  2778. (get-char-property (line-end-position) 'invisible)))
  2779. ;; Do not hide drawers when called from final blank lines.
  2780. (should-not
  2781. (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
  2782. (goto-char (point-max))
  2783. (org-flag-drawer t)
  2784. (goto-char (point-min))
  2785. (get-char-property (line-end-position) 'invisible)))
  2786. ;; Don't leave point in an invisible part of the buffer when hiding
  2787. ;; a drawer away.
  2788. (should-not
  2789. (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
  2790. (goto-char (point-max))
  2791. (org-flag-drawer t)
  2792. (get-char-property (point) 'invisible))))
  2793. (ert-deftest test-org/hide-block-toggle ()
  2794. "Test `org-hide-block-toggle' specifications."
  2795. ;; Error when not at a block.
  2796. (should-error
  2797. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
  2798. (org-hide-block-toggle 'off)
  2799. (get-char-property (line-end-position) 'invisible)))
  2800. ;; Hide block.
  2801. (should
  2802. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  2803. (org-hide-block-toggle)
  2804. (get-char-property (line-end-position) 'invisible)))
  2805. (should
  2806. (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
  2807. (org-hide-block-toggle)
  2808. (get-char-property (line-end-position) 'invisible)))
  2809. ;; Show block unconditionally when optional argument is `off'.
  2810. (should-not
  2811. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  2812. (org-hide-block-toggle)
  2813. (org-hide-block-toggle 'off)
  2814. (get-char-property (line-end-position) 'invisible)))
  2815. (should-not
  2816. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  2817. (org-hide-block-toggle 'off)
  2818. (get-char-property (line-end-position) 'invisible)))
  2819. ;; Hide block unconditionally when optional argument is non-nil.
  2820. (should
  2821. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  2822. (org-hide-block-toggle t)
  2823. (get-char-property (line-end-position) 'invisible)))
  2824. (should
  2825. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  2826. (org-hide-block-toggle)
  2827. (org-hide-block-toggle t)
  2828. (get-char-property (line-end-position) 'invisible)))
  2829. ;; Do not hide block when called from final blank lines.
  2830. (should-not
  2831. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
  2832. (org-hide-block-toggle)
  2833. (goto-char (point-min))
  2834. (get-char-property (line-end-position) 'invisible)))
  2835. ;; Don't leave point in an invisible part of the buffer when hiding
  2836. ;; a block away.
  2837. (should-not
  2838. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
  2839. (org-hide-block-toggle)
  2840. (get-char-property (point) 'invisible))))
  2841. (ert-deftest test-org/hide-block-toggle-maybe ()
  2842. "Test `org-hide-block-toggle-maybe' specifications."
  2843. (should
  2844. (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
  2845. (org-hide-block-toggle-maybe)))
  2846. (should-not
  2847. (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
  2848. (provide 'test-org)
  2849. ;;; test-org.el ends here