test-org.el 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745
  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. ;;; Filling
  192. (ert-deftest test-org/fill-paragraph ()
  193. "Test `org-fill-paragraph' specifications."
  194. ;; At an Org table, align it.
  195. (should
  196. (equal "| a |\n"
  197. (org-test-with-temp-text "|a|"
  198. (org-fill-paragraph)
  199. (buffer-string))))
  200. (should
  201. (equal "#+name: table\n| a |\n"
  202. (org-test-with-temp-text "#+name: table\n| a |"
  203. (org-fill-paragraph)
  204. (buffer-string))))
  205. ;; At a paragraph, preserve line breaks.
  206. (org-test-with-temp-text "some \\\\\nlong\ntext"
  207. (let ((fill-column 20))
  208. (org-fill-paragraph)
  209. (should (equal (buffer-string) "some \\\\\nlong text"))))
  210. ;; Correctly fill a paragraph when point is at its very end.
  211. (should
  212. (equal "A B"
  213. (org-test-with-temp-text "A\nB"
  214. (let ((fill-column 20))
  215. (goto-char (point-max))
  216. (org-fill-paragraph)
  217. (buffer-string)))))
  218. ;; Correctly fill the last paragraph of a greater element.
  219. (should
  220. (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
  221. (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
  222. (let ((fill-column 8))
  223. (forward-line)
  224. (end-of-line)
  225. (org-fill-paragraph)
  226. (buffer-string)))))
  227. ;; Correctly fill an element in a narrowed buffer.
  228. (should
  229. (equal "01234\n6"
  230. (org-test-with-temp-text "01234 6789"
  231. (let ((fill-column 5))
  232. (narrow-to-region 1 8)
  233. (org-fill-paragraph)
  234. (buffer-string)))))
  235. ;; Handle `adaptive-fill-regexp' in paragraphs.
  236. (should
  237. (equal "> a b"
  238. (org-test-with-temp-text "> a\n> b"
  239. (let ((fill-column 5)
  240. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  241. (org-fill-paragraph)
  242. (buffer-string)))))
  243. ;; Special case: Fill first paragraph when point is at an item or
  244. ;; a plain-list or a footnote reference.
  245. (should
  246. (equal "- A B"
  247. (org-test-with-temp-text "- A\n B"
  248. (let ((fill-column 20))
  249. (org-fill-paragraph)
  250. (buffer-string)))))
  251. (should
  252. (equal "[fn:1] A B"
  253. (org-test-with-temp-text "[fn:1] A\nB"
  254. (let ((fill-column 20))
  255. (org-fill-paragraph)
  256. (buffer-string)))))
  257. (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
  258. (let ((fill-column 20))
  259. (org-fill-paragraph)
  260. (should (equal (buffer-string)
  261. "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
  262. ;; Fill contents of `comment-block' elements.
  263. (should
  264. (equal
  265. (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
  266. (let ((fill-column 20))
  267. (forward-line)
  268. (org-fill-paragraph)
  269. (buffer-string)))
  270. "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
  271. ;; Fill `comment' elements.
  272. (should
  273. (equal " # A B"
  274. (org-test-with-temp-text " # A\n # B"
  275. (let ((fill-column 20))
  276. (org-fill-paragraph)
  277. (buffer-string)))))
  278. ;; Do not mix consecutive comments when filling one of them.
  279. (should
  280. (equal "# A B\n\n# C"
  281. (org-test-with-temp-text "# A\n# B\n\n# C"
  282. (let ((fill-column 20))
  283. (org-fill-paragraph)
  284. (buffer-string)))))
  285. ;; Use commented empty lines as separators when filling comments.
  286. (should
  287. (equal "# A B\n#\n# C"
  288. (org-test-with-temp-text "# A\n# B\n#\n# C"
  289. (let ((fill-column 20))
  290. (org-fill-paragraph)
  291. (buffer-string)))))
  292. ;; Handle `adaptive-fill-regexp' in comments.
  293. (should
  294. (equal "# > a b"
  295. (org-test-with-temp-text "# > a\n# > b"
  296. (let ((fill-column 20)
  297. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  298. (org-fill-paragraph)
  299. (buffer-string)))))
  300. ;; Do nothing at affiliated keywords.
  301. (org-test-with-temp-text "#+NAME: para\nSome\ntext."
  302. (let ((fill-column 20))
  303. (org-fill-paragraph)
  304. (should (equal (buffer-string) "#+NAME: para\nSome\ntext."))))
  305. ;; Do not move point after table when filling a table.
  306. (should-not
  307. (org-test-with-temp-text "| a | b |\n| c | d |\n"
  308. (forward-char)
  309. (org-fill-paragraph)
  310. (eobp))))
  311. (ert-deftest test-org/auto-fill-function ()
  312. "Test auto-filling features."
  313. ;; Auto fill paragraph.
  314. (should
  315. (equal "12345\n7890"
  316. (org-test-with-temp-text "12345 7890"
  317. (let ((fill-column 5))
  318. (end-of-line)
  319. (org-auto-fill-function)
  320. (buffer-string)))))
  321. ;; Auto fill first paragraph in an item.
  322. (should
  323. (equal "- 12345\n 7890"
  324. (org-test-with-temp-text "- 12345 7890"
  325. (let ((fill-column 7))
  326. (end-of-line)
  327. (org-auto-fill-function)
  328. (buffer-string)))))
  329. ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
  330. (should
  331. (equal "> 12345\n 7890"
  332. (org-test-with-temp-text "> 12345 7890"
  333. (let ((fill-column 10)
  334. (adaptive-fill-regexp "[ \t]*>+[ \t]*")
  335. (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
  336. (end-of-line)
  337. (org-auto-fill-function)
  338. (buffer-string)))))
  339. (should
  340. (equal "> 12345\n> 12345\n> 7890"
  341. (org-test-with-temp-text "> 12345\n> 12345 7890"
  342. (let ((fill-column 10)
  343. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  344. (goto-char (point-max))
  345. (org-auto-fill-function)
  346. (buffer-string)))))
  347. (should-not
  348. (equal " 12345\n *12345\n *12345"
  349. (org-test-with-temp-text " 12345\n *12345 12345"
  350. (let ((fill-column 10)
  351. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  352. (goto-char (point-max))
  353. (org-auto-fill-function)
  354. (buffer-string)))))
  355. ;; Auto fill comments.
  356. (should
  357. (equal " # 12345\n # 7890"
  358. (org-test-with-temp-text " # 12345 7890"
  359. (let ((fill-column 10))
  360. (end-of-line)
  361. (org-auto-fill-function)
  362. (buffer-string)))))
  363. ;; A hash within a line isn't a comment.
  364. (should-not
  365. (equal "12345 # 7890\n# 1"
  366. (org-test-with-temp-text "12345 # 7890 1"
  367. (let ((fill-column 12))
  368. (end-of-line)
  369. (org-auto-fill-function)
  370. (buffer-string)))))
  371. ;; Correctly interpret empty prefix.
  372. (should-not
  373. (equal "# a\n# b\nRegular\n# paragraph"
  374. (org-test-with-temp-text "# a\n# b\nRegular paragraph"
  375. (let ((fill-column 12))
  376. (end-of-line 3)
  377. (org-auto-fill-function)
  378. (buffer-string)))))
  379. ;; Comment block: auto fill contents.
  380. (should
  381. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  382. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  383. (let ((fill-column 5))
  384. (forward-line)
  385. (end-of-line)
  386. (org-auto-fill-function)
  387. (buffer-string)))))
  388. (should
  389. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  390. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  391. (let ((fill-column 5))
  392. (forward-line)
  393. (end-of-line)
  394. (org-auto-fill-function)
  395. (buffer-string)))))
  396. ;; Do not fill if a new item could be created.
  397. (should-not
  398. (equal "12345\n- 90"
  399. (org-test-with-temp-text "12345 - 90"
  400. (let ((fill-column 5))
  401. (end-of-line)
  402. (org-auto-fill-function)
  403. (buffer-string)))))
  404. ;; Do not fill if a line break could be introduced.
  405. (should-not
  406. (equal "123\\\\\n7890"
  407. (org-test-with-temp-text "123\\\\ 7890"
  408. (let ((fill-column 6))
  409. (end-of-line)
  410. (org-auto-fill-function)
  411. (buffer-string)))))
  412. ;; Do not fill affiliated keywords.
  413. (should-not
  414. (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
  415. (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
  416. (let ((fill-column 20))
  417. (end-of-line)
  418. (org-auto-fill-function)
  419. (buffer-string))))))
  420. ;;; Indentation
  421. (ert-deftest test-org/indent-line ()
  422. "Test `org-indent-line' specifications."
  423. ;; Do not indent footnote definitions or headlines.
  424. (should
  425. (zerop
  426. (org-test-with-temp-text "* H"
  427. (org-indent-line)
  428. (org-get-indentation))))
  429. (should
  430. (zerop
  431. (org-test-with-temp-text "[fn:1] fn"
  432. (let ((org-adapt-indentation t)) (org-indent-line))
  433. (org-get-indentation))))
  434. ;; Do not indent before first headline.
  435. (should
  436. (zerop
  437. (org-test-with-temp-text ""
  438. (org-indent-line)
  439. (org-get-indentation))))
  440. ;; Indent according to headline level otherwise, unless
  441. ;; `org-adapt-indentation' is nil.
  442. (should
  443. (= 2
  444. (org-test-with-temp-text "* H\nA"
  445. (forward-line)
  446. (let ((org-adapt-indentation t)) (org-indent-line))
  447. (org-get-indentation))))
  448. (should
  449. (= 2
  450. (org-test-with-temp-text "* H\n\nA"
  451. (forward-line)
  452. (let ((org-adapt-indentation t)) (org-indent-line))
  453. (org-get-indentation))))
  454. (should
  455. (zerop
  456. (org-test-with-temp-text "* H\nA"
  457. (forward-line)
  458. (let ((org-adapt-indentation nil)) (org-indent-line))
  459. (org-get-indentation))))
  460. ;; Indenting preserves point position.
  461. (should
  462. (org-test-with-temp-text "* H\nAB"
  463. (forward-line)
  464. (forward-char)
  465. (let ((org-adapt-indentation t)) (org-indent-line))
  466. (looking-at "B")))
  467. ;; Do not change indentation at an item.
  468. (should
  469. (= 1
  470. (org-test-with-temp-text "* H\n - A"
  471. (forward-line)
  472. (let ((org-adapt-indentation t)) (org-indent-line))
  473. (org-get-indentation))))
  474. ;; On blank lines at the end of a list, indent like last element
  475. ;; within it if the line is still in the list. Otherwise, indent
  476. ;; like the whole list.
  477. (should
  478. (= 4
  479. (org-test-with-temp-text "* H\n- A\n - AA\n"
  480. (goto-char (point-max))
  481. (let ((org-adapt-indentation t)) (org-indent-line))
  482. (org-get-indentation))))
  483. (should
  484. (zerop
  485. (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n"
  486. (goto-char (point-max))
  487. (let ((org-adapt-indentation t)) (org-indent-line))
  488. (org-get-indentation))))
  489. ;; Likewise, on a blank line at the end of a footnote definition,
  490. ;; indent at column 0 if line belongs to the definition. Otherwise,
  491. ;; indent like the definition itself.
  492. (should
  493. (zerop
  494. (org-test-with-temp-text "* H\n[fn:1] Definition\n"
  495. (goto-char (point-max))
  496. (let ((org-adapt-indentation t)) (org-indent-line))
  497. (org-get-indentation))))
  498. (should
  499. (zerop
  500. (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n"
  501. (goto-char (point-max))
  502. (let ((org-adapt-indentation t)) (org-indent-line))
  503. (org-get-indentation))))
  504. ;; After the end of the contents of a greater element, indent like
  505. ;; the beginning of the element.
  506. (should
  507. (= 1
  508. (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
  509. (forward-line 2)
  510. (org-indent-line)
  511. (org-get-indentation))))
  512. ;; At the first line of an element, indent like previous element's
  513. ;; first line, ignoring footnotes definitions and inline tasks, or
  514. ;; according to parent.
  515. (should
  516. (= 2
  517. (org-test-with-temp-text "A\n\n B\n\nC"
  518. (goto-char (point-max))
  519. (org-indent-line)
  520. (org-get-indentation))))
  521. (should
  522. (= 1
  523. (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC"
  524. (goto-char (point-max))
  525. (org-indent-line)
  526. (org-get-indentation))))
  527. (should
  528. (= 1
  529. (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
  530. (forward-line 1)
  531. (org-indent-line)
  532. (org-get-indentation))))
  533. ;; Within code part of a source block, use language major mode if
  534. ;; `org-src-tab-acts-natively' is non-nil. Do nothing otherwise.
  535. (should
  536. (= 6
  537. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  538. (forward-line 2)
  539. (let ((org-src-tab-acts-natively t)
  540. (org-edit-src-content-indentation 0))
  541. (org-indent-line))
  542. (org-get-indentation))))
  543. (should
  544. (zerop
  545. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  546. (forward-line 2)
  547. (let ((org-src-tab-acts-natively nil)
  548. (org-edit-src-content-indentation 0))
  549. (org-indent-line))
  550. (org-get-indentation))))
  551. ;; Otherwise, indent like the first non-blank line above.
  552. (should
  553. (zerop
  554. (org-test-with-temp-text "#+BEGIN_CENTER\nline1\n\n line2\n#+END_CENTER"
  555. (forward-line 3)
  556. (org-indent-line)
  557. (org-get-indentation))))
  558. ;; Align node properties according to `org-property-format'. Handle
  559. ;; nicely empty values.
  560. (should
  561. (equal ":PROPERTIES:\n:key: value\n:END:"
  562. (org-test-with-temp-text ":PROPERTIES:\n:key: value\n:END:"
  563. (forward-line)
  564. (let ((org-property-format "%-10s %s"))
  565. (org-indent-line)
  566. (buffer-string)))))
  567. (should
  568. (equal ":PROPERTIES:\n:key:\n:END:"
  569. (org-test-with-temp-text ":PROPERTIES:\n:key:\n:END:"
  570. (forward-line)
  571. (let ((org-property-format "%-10s %s"))
  572. (org-indent-line)
  573. (buffer-string))))))
  574. ;;; Editing
  575. ;;;; Insert elements
  576. (ert-deftest test-org/meta-return ()
  577. "Test M-RET (`org-meta-return')."
  578. ;; In a table field insert a row above.
  579. (should
  580. (org-test-with-temp-text "| a |"
  581. (forward-char)
  582. (org-meta-return)
  583. (forward-line -1)
  584. (looking-at "| |$")))
  585. ;; In a paragraph change current line into a header.
  586. (should
  587. (org-test-with-temp-text "a"
  588. (org-meta-return)
  589. (beginning-of-line)
  590. (looking-at "\* a$")))
  591. ;; In an item insert an item, in this case above.
  592. (should
  593. (org-test-with-temp-text "- a"
  594. (org-meta-return)
  595. (beginning-of-line)
  596. (looking-at "- $")))
  597. ;; In a drawer and paragraph insert an empty line, in this case above.
  598. (should
  599. (org-test-with-temp-text ":MYDRAWER:\na\n:END:"
  600. (forward-line)
  601. (org-meta-return)
  602. (forward-line -1)
  603. (looking-at "$")))
  604. ;; In a drawer and item insert an item, in this case above.
  605. (should
  606. (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
  607. (forward-line)
  608. (org-meta-return)
  609. (beginning-of-line)
  610. (looking-at "- $"))))
  611. (ert-deftest test-org/insert-todo-heading-respect-content ()
  612. "Test `org-insert-todo-heading-respect-content' specifications."
  613. ;; Create a TODO heading.
  614. (should
  615. (org-test-with-temp-text "* H1\n Body"
  616. (org-insert-todo-heading-respect-content)
  617. (nth 2 (org-heading-components))))
  618. ;; Add headline at the end of the first subtree
  619. (should
  620. (org-test-with-temp-text "* H1\nH1Body\n** H2\nH2Body"
  621. (search-forward "H1Body")
  622. (org-insert-todo-heading-respect-content)
  623. (and (eobp) (org-at-heading-p))))
  624. ;; In a list, do not create a new item.
  625. (should
  626. (org-test-with-temp-text "* H\n- an item\n- another one"
  627. (search-forward "an ")
  628. (org-insert-todo-heading-respect-content)
  629. (and (eobp) (org-at-heading-p)))))
  630. ;;; Fixed-Width Areas
  631. (ert-deftest test-org/toggle-fixed-with ()
  632. "Test `org-toggle-fixed-width' specifications."
  633. ;; No region: Toggle on fixed-width marker in paragraphs.
  634. (should
  635. (equal ": A"
  636. (org-test-with-temp-text "A"
  637. (org-toggle-fixed-width)
  638. (buffer-string))))
  639. ;; No region: Toggle off fixed-width markers in fixed-width areas.
  640. (should
  641. (equal "A"
  642. (org-test-with-temp-text ": A"
  643. (org-toggle-fixed-width)
  644. (buffer-string))))
  645. ;; No region: Toggle on marker in blank lines after elements or just
  646. ;; after a headline.
  647. (should
  648. (equal "* H\n: "
  649. (org-test-with-temp-text "* H\n"
  650. (forward-line)
  651. (org-toggle-fixed-width)
  652. (buffer-string))))
  653. (should
  654. (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
  655. (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
  656. (goto-char (point-max))
  657. (org-toggle-fixed-width)
  658. (buffer-string))))
  659. ;; No region: Toggle on marker in front of one line elements (e.g.,
  660. ;; headlines, clocks)
  661. (should
  662. (equal ": * Headline"
  663. (org-test-with-temp-text "* Headline"
  664. (org-toggle-fixed-width)
  665. (buffer-string))))
  666. (should
  667. (equal ": #+KEYWORD: value"
  668. (org-test-with-temp-text "#+KEYWORD: value"
  669. (org-toggle-fixed-width)
  670. (buffer-string))))
  671. ;; No region: error in other situations.
  672. (should-error
  673. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
  674. (forward-line)
  675. (org-toggle-fixed-width)
  676. (buffer-string)))
  677. ;; No region: Indentation is preserved.
  678. (should
  679. (equal "- A\n : B"
  680. (org-test-with-temp-text "- A\n B"
  681. (forward-line)
  682. (org-toggle-fixed-width)
  683. (buffer-string))))
  684. ;; Region: If it contains only fixed-width elements and blank lines,
  685. ;; toggle off fixed-width markup.
  686. (should
  687. (equal "A\n\nB"
  688. (org-test-with-temp-text ": A\n\n: B"
  689. (transient-mark-mode 1)
  690. (push-mark (point) t t)
  691. (goto-char (point-max))
  692. (org-toggle-fixed-width)
  693. (buffer-string))))
  694. ;; Region: If it contains anything else, toggle on fixed-width but
  695. ;; not on fixed-width areas.
  696. (should
  697. (equal ": A\n: \n: B\n: \n: C"
  698. (org-test-with-temp-text "A\n\n: B\n\nC"
  699. (transient-mark-mode 1)
  700. (push-mark (point) t t)
  701. (goto-char (point-max))
  702. (org-toggle-fixed-width)
  703. (buffer-string))))
  704. ;; Region: Ignore blank lines at its end, unless it contains only
  705. ;; such lines.
  706. (should
  707. (equal ": A\n\n"
  708. (org-test-with-temp-text "A\n\n"
  709. (transient-mark-mode 1)
  710. (push-mark (point) t t)
  711. (goto-char (point-max))
  712. (org-toggle-fixed-width)
  713. (buffer-string))))
  714. (should
  715. (equal ": \n: \n"
  716. (org-test-with-temp-text "\n\n"
  717. (transient-mark-mode 1)
  718. (push-mark (point) t t)
  719. (goto-char (point-max))
  720. (org-toggle-fixed-width)
  721. (buffer-string)))))
  722. ;;; Headline
  723. (ert-deftest test-org/in-commented-heading-p ()
  724. "Test `org-in-commented-heading-p' specifications."
  725. ;; Commented headline.
  726. (should
  727. (org-test-with-temp-text "* COMMENT Headline\nBody"
  728. (goto-char (point-max))
  729. (org-in-commented-heading-p)))
  730. ;; Commented ancestor.
  731. (should
  732. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  733. (goto-char (point-max))
  734. (org-in-commented-heading-p)))
  735. ;; Comment keyword is case-sensitive.
  736. (should-not
  737. (org-test-with-temp-text "* Comment Headline\nBody"
  738. (goto-char (point-max))
  739. (org-in-commented-heading-p)))
  740. ;; Keyword is standalone.
  741. (should-not
  742. (org-test-with-temp-text "* COMMENTHeadline\nBody"
  743. (goto-char (point-max))
  744. (org-in-commented-heading-p)))
  745. ;; Optional argument.
  746. (should-not
  747. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  748. (goto-char (point-max))
  749. (org-in-commented-heading-p t))))
  750. ;;; Links
  751. ;;;; Coderefs
  752. (ert-deftest test-org/coderef ()
  753. "Test coderef links specifications."
  754. (should
  755. (org-test-with-temp-text "
  756. #+BEGIN_SRC emacs-lisp
  757. \(+ 1 1) (ref:sc)
  758. #+END_SRC
  759. \[[(sc)]]"
  760. (goto-char (point-max))
  761. (org-open-at-point)
  762. (looking-at "(ref:sc)"))))
  763. ;;;; Custom ID
  764. (ert-deftest test-org/custom-id ()
  765. "Test custom ID links specifications."
  766. (should
  767. (org-test-with-temp-text
  768. "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom]]"
  769. (goto-char (point-max))
  770. (org-open-at-point)
  771. (org-looking-at-p "\\* H1"))))
  772. ;;;; Fuzzy Links
  773. ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
  774. ;; a named element (#+name: text) and to headlines (* Text).
  775. (ert-deftest test-org/fuzzy-links ()
  776. "Test fuzzy links specifications."
  777. ;; Fuzzy link goes in priority to a matching target.
  778. (should
  779. (org-test-with-temp-text "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n[[Test]]"
  780. (goto-line 5)
  781. (org-open-at-point)
  782. (looking-at "<<Test>>")))
  783. ;; Then fuzzy link points to an element with a given name.
  784. (should
  785. (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n[[Test]]"
  786. (goto-line 5)
  787. (org-open-at-point)
  788. (looking-at "#\\+NAME: Test")))
  789. ;; A target still lead to a matching headline otherwise.
  790. (should
  791. (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n[[Head2]]"
  792. (goto-line 4)
  793. (org-open-at-point)
  794. (looking-at "\\* Head2")))
  795. ;; With a leading star in link, enforce heading match.
  796. (should
  797. (org-test-with-temp-text "* Test\n<<Test>>\n[[*Test]]"
  798. (goto-line 3)
  799. (org-open-at-point)
  800. (looking-at "\\* Test")))
  801. ;; Correctly un-hexify fuzzy links.
  802. (should
  803. (org-test-with-temp-text "* With space\n[[*With%20space][With space]]"
  804. (goto-char (point-max))
  805. (org-open-at-point)
  806. (bobp))))
  807. ;;;; Link Escaping
  808. (ert-deftest test-org/org-link-escape-ascii-character ()
  809. "Escape an ascii character."
  810. (should
  811. (string=
  812. "%5B"
  813. (org-link-escape "["))))
  814. (ert-deftest test-org/org-link-escape-ascii-ctrl-character ()
  815. "Escape an ascii control character."
  816. (should
  817. (string=
  818. "%09"
  819. (org-link-escape "\t"))))
  820. (ert-deftest test-org/org-link-escape-multibyte-character ()
  821. "Escape an unicode multibyte character."
  822. (should
  823. (string=
  824. "%E2%82%AC"
  825. (org-link-escape "€"))))
  826. (ert-deftest test-org/org-link-escape-custom-table ()
  827. "Escape string with custom character table."
  828. (should
  829. (string=
  830. "Foo%3A%42ar%0A"
  831. (org-link-escape "Foo:Bar\n" '(?\: ?\B)))))
  832. (ert-deftest test-org/org-link-escape-custom-table-merge ()
  833. "Escape string with custom table merged with default table."
  834. (should
  835. (string=
  836. "%5BF%6F%6F%3A%42ar%0A%5D"
  837. (org-link-escape "[Foo:Bar\n]" '(?\: ?\B ?\o) t))))
  838. (ert-deftest test-org/org-link-unescape-ascii-character ()
  839. "Unescape an ascii character."
  840. (should
  841. (string=
  842. "["
  843. (org-link-unescape "%5B"))))
  844. (ert-deftest test-org/org-link-unescape-ascii-ctrl-character ()
  845. "Unescpae an ascii control character."
  846. (should
  847. (string=
  848. "\n"
  849. (org-link-unescape "%0A"))))
  850. (ert-deftest test-org/org-link-unescape-multibyte-character ()
  851. "Unescape unicode multibyte character."
  852. (should
  853. (string=
  854. "€"
  855. (org-link-unescape "%E2%82%AC"))))
  856. (ert-deftest test-org/org-link-unescape-ascii-extended-char ()
  857. "Unescape old style percent escaped character."
  858. (should
  859. (string=
  860. "àâçèéêîôùû"
  861. (decode-coding-string
  862. (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1))))
  863. (ert-deftest test-org/org-link-escape-url-with-escaped-char ()
  864. "Escape and unescape a URL that includes an escaped char.
  865. http://article.gmane.org/gmane.emacs.orgmode/21459/"
  866. (should
  867. (string=
  868. "http://some.host.com/form?&id=blah%2Bblah25"
  869. (org-link-unescape
  870. (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
  871. (ert-deftest test-org/org-link-escape-chars-browser ()
  872. "Test of the constant `org-link-escape-chars-browser'.
  873. See there why this test is a candidate to be removed once Org
  874. drops support for Emacs 24.1 and 24.2."
  875. (should
  876. (string=
  877. (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
  878. "%22Release%208.2%22&idxname=emacs-orgmode")
  879. (org-link-escape-browser ; Do not replace with `url-encode-url',
  880. ; see docstring above.
  881. (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
  882. "\"Release 8.2\"&idxname=emacs-orgmode")))))
  883. ;;; Node Properties
  884. (ert-deftest test-org/accumulated-properties-in-drawers ()
  885. "Ensure properties accumulate in subtree drawers."
  886. (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
  887. (org-babel-next-src-block)
  888. (should (equal '(2 1) (org-babel-execute-src-block)))))
  889. ;;; Mark Region
  890. (ert-deftest test-org/mark-subtree ()
  891. "Test `org-mark-subtree' specifications."
  892. ;; Error when point is before first headline.
  893. (should-error
  894. (org-test-with-temp-text "Paragraph\n* Headline\nBody"
  895. (progn (transient-mark-mode 1)
  896. (org-mark-subtree))))
  897. ;; Without argument, mark current subtree.
  898. (should
  899. (equal
  900. '(12 32)
  901. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  902. (progn (transient-mark-mode 1)
  903. (forward-line 2)
  904. (org-mark-subtree)
  905. (list (region-beginning) (region-end))))))
  906. ;; With an argument, move ARG up.
  907. (should
  908. (equal
  909. '(1 32)
  910. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  911. (progn (transient-mark-mode 1)
  912. (forward-line 2)
  913. (org-mark-subtree 1)
  914. (list (region-beginning) (region-end))))))
  915. ;; Do not get fooled by inlinetasks.
  916. (when (featurep 'org-inlinetask)
  917. (should
  918. (= 1
  919. (org-test-with-temp-text "* Headline\n*************** Task\nContents"
  920. (progn (transient-mark-mode 1)
  921. (forward-line 1)
  922. (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
  923. (region-beginning)))))))
  924. ;;; Navigation
  925. (ert-deftest test-org/beginning-of-line ()
  926. "Test `org-beginning-of-line' specifications."
  927. ;; Standard test.
  928. (should
  929. (org-test-with-temp-text "Some text\nSome other text"
  930. (progn (org-beginning-of-line) (bolp))))
  931. ;; Standard test with `visual-line-mode'.
  932. (should-not
  933. (org-test-with-temp-text "A long line of text\nSome other text"
  934. (progn (visual-line-mode)
  935. (forward-char 2)
  936. (dotimes (i 1000) (insert "very "))
  937. (org-beginning-of-line)
  938. (bolp))))
  939. ;; At an headline with special movement.
  940. (should
  941. (org-test-with-temp-text "* TODO Headline"
  942. (let ((org-special-ctrl-a/e t))
  943. (org-end-of-line)
  944. (and (progn (org-beginning-of-line) (looking-at "Headline"))
  945. (progn (org-beginning-of-line) (bolp))
  946. (progn (org-beginning-of-line) (looking-at "Headline")))))))
  947. (ert-deftest test-org/end-of-line ()
  948. "Test `org-end-of-line' specifications."
  949. ;; Standard test.
  950. (should
  951. (org-test-with-temp-text "Some text\nSome other text"
  952. (progn (org-end-of-line) (eolp))))
  953. ;; Standard test with `visual-line-mode'.
  954. (should-not
  955. (org-test-with-temp-text "A long line of text\nSome other text"
  956. (progn (visual-line-mode)
  957. (forward-char 2)
  958. (dotimes (i 1000) (insert "very "))
  959. (goto-char (point-min))
  960. (org-end-of-line)
  961. (eolp))))
  962. ;; At an headline with special movement.
  963. (should
  964. (org-test-with-temp-text "* Headline1 :tag:\n"
  965. (let ((org-special-ctrl-a/e t))
  966. (and (progn (org-end-of-line) (looking-at " :tag:"))
  967. (progn (org-end-of-line) (eolp))
  968. (progn (org-end-of-line) (looking-at " :tag:"))))))
  969. ;; At an headline without special movement.
  970. (should
  971. (org-test-with-temp-text "* Headline2 :tag:\n"
  972. (let ((org-special-ctrl-a/e nil))
  973. (and (progn (org-end-of-line) (eolp))
  974. (progn (org-end-of-line) (eolp))))))
  975. ;; At an headline, with reversed movement.
  976. (should
  977. (org-test-with-temp-text "* Headline3 :tag:\n"
  978. (let ((org-special-ctrl-a/e 'reversed)
  979. (this-command last-command))
  980. (and (progn (org-end-of-line) (eolp))
  981. (progn (org-end-of-line) (looking-at " :tag:"))))))
  982. ;; At a block without hidden contents.
  983. (should
  984. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  985. (progn (org-end-of-line) (eolp))))
  986. ;; At a block with hidden contents.
  987. (should-not
  988. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  989. (let ((org-special-ctrl-a/e t))
  990. (org-hide-block-toggle)
  991. (org-end-of-line)
  992. (eobp)))))
  993. (ert-deftest test-org/forward-paragraph ()
  994. "Test `org-forward-paragraph' specifications."
  995. ;; At end of buffer, return an error.
  996. (should-error
  997. (org-test-with-temp-text "Paragraph"
  998. (goto-char (point-max))
  999. (org-forward-paragraph)))
  1000. ;; Standard test.
  1001. (should
  1002. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  1003. (org-forward-paragraph)
  1004. (looking-at "P2")))
  1005. ;; Ignore depth.
  1006. (should
  1007. (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
  1008. (org-forward-paragraph)
  1009. (looking-at "P1")))
  1010. ;; Do not enter elements with invisible contents.
  1011. (should
  1012. (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
  1013. (org-hide-block-toggle)
  1014. (org-forward-paragraph)
  1015. (looking-at "P3")))
  1016. ;; On an affiliated keyword, jump to the beginning of the element.
  1017. (should
  1018. (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
  1019. (org-forward-paragraph)
  1020. (looking-at "Para")))
  1021. ;; On an item or a footnote definition, move to the second element
  1022. ;; inside, if any.
  1023. (should
  1024. (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
  1025. (org-forward-paragraph)
  1026. (looking-at " Paragraph")))
  1027. (should
  1028. (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
  1029. (org-forward-paragraph)
  1030. (looking-at "Paragraph")))
  1031. ;; On an item, or a footnote definition, when the first line is
  1032. ;; empty, move to the first item.
  1033. (should
  1034. (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
  1035. (org-forward-paragraph)
  1036. (looking-at " Paragraph")))
  1037. (should
  1038. (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
  1039. (org-forward-paragraph)
  1040. (looking-at "Paragraph")))
  1041. ;; On a table (resp. a property drawer) do not move through table
  1042. ;; rows (resp. node properties).
  1043. (should
  1044. (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
  1045. (org-forward-paragraph)
  1046. (looking-at "Paragraph")))
  1047. (should
  1048. (org-test-with-temp-text ":PROPERTIES:\n:prop: value\n:END:\nParagraph"
  1049. (org-forward-paragraph)
  1050. (looking-at "Paragraph")))
  1051. ;; On a verse or source block, stop after blank lines.
  1052. (should
  1053. (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
  1054. (org-forward-paragraph)
  1055. (looking-at "L2")))
  1056. (should
  1057. (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
  1058. (org-forward-paragraph)
  1059. (looking-at "L2"))))
  1060. (ert-deftest test-org/backward-paragraph ()
  1061. "Test `org-backward-paragraph' specifications."
  1062. ;; Error at beginning of buffer.
  1063. (should-error
  1064. (org-test-with-temp-text "Paragraph"
  1065. (org-backward-paragraph)))
  1066. ;; Regular test.
  1067. (should
  1068. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  1069. (goto-char (point-max))
  1070. (org-backward-paragraph)
  1071. (looking-at "P3")))
  1072. (should
  1073. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  1074. (goto-char (point-max))
  1075. (beginning-of-line)
  1076. (org-backward-paragraph)
  1077. (looking-at "P2")))
  1078. ;; Ignore depth.
  1079. (should
  1080. (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
  1081. (goto-char (point-max))
  1082. (beginning-of-line)
  1083. (org-backward-paragraph)
  1084. (looking-at "P2")))
  1085. ;; Ignore invisible elements.
  1086. (should
  1087. (org-test-with-temp-text "* H1\n P1\n* H2"
  1088. (org-cycle)
  1089. (goto-char (point-max))
  1090. (beginning-of-line)
  1091. (org-backward-paragraph)
  1092. (bobp)))
  1093. ;; On an affiliated keyword, jump to the first one.
  1094. (should
  1095. (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
  1096. (search-forward "c2")
  1097. (org-backward-paragraph)
  1098. (looking-at "#\\+name")))
  1099. ;; On the second element in an item or a footnote definition, jump
  1100. ;; to item or the definition.
  1101. (should
  1102. (org-test-with-temp-text "- line1\n\n line2"
  1103. (goto-char (point-max))
  1104. (beginning-of-line)
  1105. (org-backward-paragraph)
  1106. (looking-at "- line1")))
  1107. (should
  1108. (org-test-with-temp-text "[fn:1] line1\n\n line2"
  1109. (goto-char (point-max))
  1110. (beginning-of-line)
  1111. (org-backward-paragraph)
  1112. (looking-at "\\[fn:1\\] line1")))
  1113. ;; On a table (resp. a property drawer), ignore table rows
  1114. ;; (resp. node properties).
  1115. (should
  1116. (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
  1117. (goto-char (point-max))
  1118. (beginning-of-line)
  1119. (org-backward-paragraph)
  1120. (bobp)))
  1121. (should
  1122. (org-test-with-temp-text ":PROPERTIES:\n:prop: value\n:END:\nP1"
  1123. (goto-char (point-max))
  1124. (beginning-of-line)
  1125. (org-backward-paragraph)
  1126. (bobp)))
  1127. ;; On a source or verse block, stop before blank lines.
  1128. (should
  1129. (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
  1130. (search-forward "L3")
  1131. (beginning-of-line)
  1132. (org-backward-paragraph)
  1133. (looking-at "L2")))
  1134. (should
  1135. (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
  1136. (search-forward "L3")
  1137. (beginning-of-line)
  1138. (org-backward-paragraph)
  1139. (looking-at "L2"))))
  1140. (ert-deftest test-org/forward-element ()
  1141. "Test `org-forward-element' specifications."
  1142. ;; 1. At EOB: should error.
  1143. (org-test-with-temp-text "Some text\n"
  1144. (goto-char (point-max))
  1145. (should-error (org-forward-element)))
  1146. ;; 2. Standard move: expected to ignore blank lines.
  1147. (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
  1148. (org-forward-element)
  1149. (should (looking-at (regexp-quote "Second paragraph."))))
  1150. ;; 3. Headline tests.
  1151. (org-test-with-temp-text "
  1152. * Head 1
  1153. ** Head 1.1
  1154. *** Head 1.1.1
  1155. ** Head 1.2"
  1156. ;; 3.1. At an headline beginning: move to next headline at the
  1157. ;; same level.
  1158. (goto-line 3)
  1159. (org-forward-element)
  1160. (should (looking-at (regexp-quote "** Head 1.2")))
  1161. ;; 3.2. At an headline beginning: move to parent headline if no
  1162. ;; headline at the same level.
  1163. (goto-line 3)
  1164. (org-forward-element)
  1165. (should (looking-at (regexp-quote "** Head 1.2"))))
  1166. ;; 4. Greater element tests.
  1167. (org-test-with-temp-text
  1168. "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
  1169. ;; 4.1. At a greater element: expected to skip contents.
  1170. (org-forward-element)
  1171. (should (looking-at (regexp-quote "Outside.")))
  1172. ;; 4.2. At the end of greater element contents: expected to skip
  1173. ;; to the end of the greater element.
  1174. (goto-line 2)
  1175. (org-forward-element)
  1176. (should (looking-at (regexp-quote "Outside."))))
  1177. ;; 5. List tests.
  1178. (org-test-with-temp-text "
  1179. - item1
  1180. - sub1
  1181. - sub2
  1182. - sub3
  1183. Inner paragraph.
  1184. - item2
  1185. Outside."
  1186. ;; 5.1. At list top point: expected to move to the element after
  1187. ;; the list.
  1188. (goto-line 2)
  1189. (org-forward-element)
  1190. (should (looking-at (regexp-quote "Outside.")))
  1191. ;; 5.2. Special case: at the first line of a sub-list, but not at
  1192. ;; beginning of line, move to next item.
  1193. (goto-line 2)
  1194. (forward-char)
  1195. (org-forward-element)
  1196. (should (looking-at "- item2"))
  1197. (goto-line 4)
  1198. (forward-char)
  1199. (org-forward-element)
  1200. (should (looking-at " - sub2"))
  1201. ;; 5.3 At sub-list beginning: expected to move after the sub-list.
  1202. (goto-line 4)
  1203. (org-forward-element)
  1204. (should (looking-at (regexp-quote " Inner paragraph.")))
  1205. ;; 5.4. At sub-list end: expected to move outside the sub-list.
  1206. (goto-line 8)
  1207. (org-forward-element)
  1208. (should (looking-at (regexp-quote " Inner paragraph.")))
  1209. ;; 5.5. At an item: expected to move to next item, if any.
  1210. (goto-line 6)
  1211. (org-forward-element)
  1212. (should (looking-at " - sub3"))))
  1213. (ert-deftest test-org/backward-element ()
  1214. "Test `org-backward-element' specifications."
  1215. ;; 1. Should error at BOB.
  1216. (org-test-with-temp-text " \nParagraph."
  1217. (should-error (org-backward-element)))
  1218. ;; 2. Should move at BOB when called on the first element in buffer.
  1219. (should
  1220. (org-test-with-temp-text "\n#+TITLE: test"
  1221. (progn (forward-line)
  1222. (org-backward-element)
  1223. (bobp))))
  1224. ;; 3. Not at the beginning of an element: move at its beginning.
  1225. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  1226. (goto-line 3)
  1227. (end-of-line)
  1228. (org-backward-element)
  1229. (should (looking-at (regexp-quote "Paragraph2."))))
  1230. ;; 4. Headline tests.
  1231. (org-test-with-temp-text "
  1232. * Head 1
  1233. ** Head 1.1
  1234. *** Head 1.1.1
  1235. ** Head 1.2"
  1236. ;; 4.1. At an headline beginning: move to previous headline at the
  1237. ;; same level.
  1238. (goto-line 5)
  1239. (org-backward-element)
  1240. (should (looking-at (regexp-quote "** Head 1.1")))
  1241. ;; 4.2. At an headline beginning: move to parent headline if no
  1242. ;; headline at the same level.
  1243. (goto-line 3)
  1244. (org-backward-element)
  1245. (should (looking-at (regexp-quote "* Head 1")))
  1246. ;; 4.3. At the first top-level headline: should error.
  1247. (goto-line 2)
  1248. (should-error (org-backward-element)))
  1249. ;; 5. At beginning of first element inside a greater element:
  1250. ;; expected to move to greater element's beginning.
  1251. (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
  1252. (goto-line 3)
  1253. (org-backward-element)
  1254. (should (looking-at "#\\+BEGIN_CENTER")))
  1255. ;; 6. At the beginning of the first element in a section: should
  1256. ;; move back to headline, if any.
  1257. (should
  1258. (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
  1259. (progn (goto-char (point-max))
  1260. (beginning-of-line)
  1261. (org-backward-element)
  1262. (org-at-heading-p))))
  1263. ;; 7. List tests.
  1264. (org-test-with-temp-text "
  1265. - item1
  1266. - sub1
  1267. - sub2
  1268. - sub3
  1269. Inner paragraph.
  1270. - item2
  1271. Outside."
  1272. ;; 7.1. At beginning of sub-list: expected to move to the
  1273. ;; paragraph before it.
  1274. (goto-line 4)
  1275. (org-backward-element)
  1276. (should (looking-at "item1"))
  1277. ;; 7.2. At an item in a list: expected to move at previous item.
  1278. (goto-line 8)
  1279. (org-backward-element)
  1280. (should (looking-at " - sub2"))
  1281. (goto-line 12)
  1282. (org-backward-element)
  1283. (should (looking-at "- item1"))
  1284. ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
  1285. ;; beginning.
  1286. (goto-line 10)
  1287. (org-backward-element)
  1288. (should (looking-at " - sub1"))
  1289. (goto-line 15)
  1290. (org-backward-element)
  1291. (should (looking-at "- item1"))
  1292. ;; 7.4. At blank-lines before list end: expected to move to top
  1293. ;; item.
  1294. (goto-line 14)
  1295. (org-backward-element)
  1296. (should (looking-at "- item1"))))
  1297. (ert-deftest test-org/up-element ()
  1298. "Test `org-up-element' specifications."
  1299. ;; 1. At BOB or with no surrounding element: should error.
  1300. (org-test-with-temp-text "Paragraph."
  1301. (should-error (org-up-element)))
  1302. (org-test-with-temp-text "* Head1\n* Head2"
  1303. (goto-line 2)
  1304. (should-error (org-up-element)))
  1305. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  1306. (goto-line 3)
  1307. (should-error (org-up-element)))
  1308. ;; 2. At an headline: move to parent headline.
  1309. (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
  1310. (goto-line 3)
  1311. (org-up-element)
  1312. (should (looking-at "\\* Head1")))
  1313. ;; 3. Inside a greater element: move to greater element beginning.
  1314. (org-test-with-temp-text
  1315. "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
  1316. (goto-line 3)
  1317. (org-up-element)
  1318. (should (looking-at "#\\+BEGIN_CENTER")))
  1319. ;; 4. List tests.
  1320. (org-test-with-temp-text "* Top
  1321. - item1
  1322. - sub1
  1323. - sub2
  1324. Paragraph within sub2.
  1325. - item2"
  1326. ;; 4.1. Within an item: move to the item beginning.
  1327. (goto-line 8)
  1328. (org-up-element)
  1329. (should (looking-at " - sub2"))
  1330. ;; 4.2. At an item in a sub-list: move to parent item.
  1331. (goto-line 4)
  1332. (org-up-element)
  1333. (should (looking-at "- item1"))
  1334. ;; 4.3. At an item in top list: move to beginning of whole list.
  1335. (goto-line 10)
  1336. (org-up-element)
  1337. (should (looking-at "- item1"))
  1338. ;; 4.4. Special case. At very top point: should move to parent of
  1339. ;; list.
  1340. (goto-line 2)
  1341. (org-up-element)
  1342. (should (looking-at "\\* Top"))))
  1343. (ert-deftest test-org/down-element ()
  1344. "Test `org-down-element' specifications."
  1345. ;; Error when the element hasn't got a recursive type.
  1346. (org-test-with-temp-text "Paragraph."
  1347. (should-error (org-down-element)))
  1348. ;; Error when the element has no contents
  1349. (org-test-with-temp-text "* Headline"
  1350. (should-error (org-down-element)))
  1351. ;; When at a plain-list, move to first item.
  1352. (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
  1353. (goto-line 2)
  1354. (org-down-element)
  1355. (should (looking-at " - Item 1.1")))
  1356. (org-test-with-temp-text "#+NAME: list\n- Item 1"
  1357. (org-down-element)
  1358. (should (looking-at " Item 1")))
  1359. ;; When at a table, move to first row
  1360. (org-test-with-temp-text "#+NAME: table\n| a | b |"
  1361. (org-down-element)
  1362. (should (looking-at " a | b |")))
  1363. ;; Otherwise, move inside the greater element.
  1364. (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
  1365. (org-down-element)
  1366. (should (looking-at "Paragraph"))))
  1367. (ert-deftest test-org/drag-element-backward ()
  1368. "Test `org-drag-element-backward' specifications."
  1369. ;; 1. Error when trying to move first element of buffer.
  1370. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  1371. (should-error (org-drag-element-backward)))
  1372. ;; 2. Error when trying to swap nested elements.
  1373. (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
  1374. (forward-line)
  1375. (should-error (org-drag-element-backward)))
  1376. ;; 3. Error when trying to swap an headline element and
  1377. ;; a non-headline element.
  1378. (org-test-with-temp-text "Test.\n* Head 1"
  1379. (forward-line)
  1380. (should-error (org-drag-element-backward)))
  1381. ;; 4. Otherwise, swap elements, preserving column and blank lines
  1382. ;; between elements.
  1383. (org-test-with-temp-text "Para1\n\n\nParagraph 2\n\nPara3"
  1384. (search-forward "graph")
  1385. (org-drag-element-backward)
  1386. (should (equal (buffer-string) "Paragraph 2\n\n\nPara1\n\nPara3"))
  1387. (should (looking-at " 2")))
  1388. ;; 5. Preserve visibility of elements and their contents.
  1389. (org-test-with-temp-text "
  1390. #+BEGIN_CENTER
  1391. Text.
  1392. #+END_CENTER
  1393. - item 1
  1394. #+BEGIN_QUOTE
  1395. Text.
  1396. #+END_QUOTE"
  1397. (while (search-forward "BEGIN_" nil t) (org-cycle))
  1398. (search-backward "- item 1")
  1399. (org-drag-element-backward)
  1400. (should
  1401. (equal
  1402. '((63 . 82) (26 . 48))
  1403. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  1404. (overlays-in (point-min) (point-max)))))))
  1405. (ert-deftest test-org/drag-element-forward ()
  1406. "Test `org-drag-element-forward' specifications."
  1407. ;; 1. Error when trying to move first element of buffer.
  1408. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  1409. (goto-line 3)
  1410. (should-error (org-drag-element-forward)))
  1411. ;; 2. Error when trying to swap nested elements.
  1412. (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
  1413. (forward-line)
  1414. (should-error (org-drag-element-forward)))
  1415. ;; 3. Error when trying to swap a non-headline element and an
  1416. ;; headline.
  1417. (org-test-with-temp-text "Test.\n* Head 1"
  1418. (should-error (org-drag-element-forward)))
  1419. ;; 4. Otherwise, swap elements, preserving column and blank lines
  1420. ;; between elements.
  1421. (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
  1422. (search-forward "graph")
  1423. (org-drag-element-forward)
  1424. (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
  1425. (should (looking-at " 1")))
  1426. ;; 5. Preserve visibility of elements and their contents.
  1427. (org-test-with-temp-text "
  1428. #+BEGIN_CENTER
  1429. Text.
  1430. #+END_CENTER
  1431. - item 1
  1432. #+BEGIN_QUOTE
  1433. Text.
  1434. #+END_QUOTE"
  1435. (while (search-forward "BEGIN_" nil t) (org-cycle))
  1436. (search-backward "#+BEGIN_CENTER")
  1437. (org-drag-element-forward)
  1438. (should
  1439. (equal
  1440. '((63 . 82) (26 . 48))
  1441. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  1442. (overlays-in (point-min) (point-max)))))))
  1443. ;;; Planning
  1444. (ert-deftest test-org/timestamp-has-time-p ()
  1445. "Test `org-timestamp-has-time-p' specifications."
  1446. ;; With time.
  1447. (should
  1448. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  1449. (org-timestamp-has-time-p (org-element-context))))
  1450. ;; Without time.
  1451. (should-not
  1452. (org-test-with-temp-text "<2012-03-29 Thu>"
  1453. (org-timestamp-has-time-p (org-element-context)))))
  1454. (ert-deftest test-org/timestamp-format ()
  1455. "Test `org-timestamp-format' specifications."
  1456. ;; Regular test.
  1457. (should
  1458. (equal
  1459. "2012-03-29 16:40"
  1460. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  1461. (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
  1462. ;; Range end.
  1463. (should
  1464. (equal
  1465. "2012-03-29"
  1466. (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
  1467. (org-timestamp-format (org-element-context) "%Y-%m-%d" t)))))
  1468. (ert-deftest test-org/timestamp-split-range ()
  1469. "Test `org-timestamp-split-range' specifications."
  1470. ;; Extract range start (active).
  1471. (should
  1472. (equal '(2012 3 29)
  1473. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  1474. (let ((ts (org-timestamp-split-range (org-element-context))))
  1475. (mapcar (lambda (p) (org-element-property p ts))
  1476. '(:year-end :month-end :day-end))))))
  1477. ;; Extract range start (inactive)
  1478. (should
  1479. (equal '(2012 3 29)
  1480. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  1481. (let ((ts (org-timestamp-split-range (org-element-context))))
  1482. (mapcar (lambda (p) (org-element-property p ts))
  1483. '(:year-end :month-end :day-end))))))
  1484. ;; Extract range end (active).
  1485. (should
  1486. (equal '(2012 3 30)
  1487. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  1488. (let ((ts (org-timestamp-split-range
  1489. (org-element-context) t)))
  1490. (mapcar (lambda (p) (org-element-property p ts))
  1491. '(:year-end :month-end :day-end))))))
  1492. ;; Extract range end (inactive)
  1493. (should
  1494. (equal '(2012 3 30)
  1495. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  1496. (let ((ts (org-timestamp-split-range
  1497. (org-element-context) t)))
  1498. (mapcar (lambda (p) (org-element-property p ts))
  1499. '(:year-end :month-end :day-end))))))
  1500. ;; Return the timestamp if not a range.
  1501. (should
  1502. (org-test-with-temp-text "[2012-03-29 Thu]"
  1503. (let* ((ts-orig (org-element-context))
  1504. (ts-copy (org-timestamp-split-range ts-orig)))
  1505. (eq ts-orig ts-copy))))
  1506. (should
  1507. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  1508. (let* ((ts-orig (org-element-context))
  1509. (ts-copy (org-timestamp-split-range ts-orig)))
  1510. (eq ts-orig ts-copy))))
  1511. ;; Check that parent is the same when a range was split.
  1512. (should
  1513. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  1514. (let* ((ts-orig (org-element-context))
  1515. (ts-copy (org-timestamp-split-range ts-orig)))
  1516. (eq (org-element-property :parent ts-orig)
  1517. (org-element-property :parent ts-copy))))))
  1518. (ert-deftest test-org/timestamp-translate ()
  1519. "Test `org-timestamp-translate' specifications."
  1520. ;; Translate whole date range.
  1521. (should
  1522. (equal "<29>--<30>"
  1523. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  1524. (let ((org-display-custom-times t)
  1525. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  1526. (org-timestamp-translate (org-element-context))))))
  1527. ;; Translate date range start.
  1528. (should
  1529. (equal "<29>"
  1530. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  1531. (let ((org-display-custom-times t)
  1532. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  1533. (org-timestamp-translate (org-element-context) 'start)))))
  1534. ;; Translate date range end.
  1535. (should
  1536. (equal "<30>"
  1537. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  1538. (let ((org-display-custom-times t)
  1539. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  1540. (org-timestamp-translate (org-element-context) 'end)))))
  1541. ;; Translate time range.
  1542. (should
  1543. (equal "<08>--<16>"
  1544. (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
  1545. (let ((org-display-custom-times t)
  1546. (org-time-stamp-custom-formats '("<%d>" . "<%H>")))
  1547. (org-timestamp-translate (org-element-context))))))
  1548. ;; Translate non-range timestamp.
  1549. (should
  1550. (equal "<29>"
  1551. (org-test-with-temp-text "<2012-03-29 Thu>"
  1552. (let ((org-display-custom-times t)
  1553. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  1554. (org-timestamp-translate (org-element-context))))))
  1555. ;; Do not change `diary' timestamps.
  1556. (should
  1557. (equal "<%%(org-float t 4 2)>"
  1558. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  1559. (let ((org-display-custom-times t)
  1560. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  1561. (org-timestamp-translate (org-element-context)))))))
  1562. ;;; Radio Targets
  1563. (ert-deftest test-org/update-radio-target-regexp ()
  1564. "Test `org-update-radio-target-regexp' specifications."
  1565. (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
  1566. (save-excursion (goto-char (point-max)) (org-element-context))
  1567. (insert "<<<")
  1568. (search-forward "o")
  1569. (insert ">>>")
  1570. (org-update-radio-target-regexp)
  1571. (goto-char (point-max))
  1572. (org-element-type (org-element-context))))
  1573. ;;; Visibility
  1574. (ert-deftest test-org/flag-drawer ()
  1575. "Test `org-flag-drawer' specifications."
  1576. ;; Hide drawer.
  1577. (should
  1578. (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
  1579. (org-flag-drawer t)
  1580. (get-char-property (line-end-position) 'invisible)))
  1581. ;; Show drawer.
  1582. (should-not
  1583. (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
  1584. (org-flag-drawer t)
  1585. (org-flag-drawer nil)
  1586. (get-char-property (line-end-position) 'invisible)))
  1587. ;; Test optional argument.
  1588. (should
  1589. (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
  1590. (let ((drawer (save-excursion (search-forward ":D2")
  1591. (org-element-at-point))))
  1592. (org-flag-drawer t drawer)
  1593. (get-char-property (progn (search-forward ":D2") (line-end-position))
  1594. 'invisible))))
  1595. (should-not
  1596. (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
  1597. (let ((drawer (save-excursion (search-forward ":D2")
  1598. (org-element-at-point))))
  1599. (org-flag-drawer t drawer)
  1600. (get-char-property (line-end-position) 'invisible))))
  1601. ;; Do not hide fake drawers.
  1602. (should-not
  1603. (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
  1604. (forward-line 1)
  1605. (org-flag-drawer t)
  1606. (get-char-property (line-end-position) 'invisible)))
  1607. ;; Do not hide incomplete drawers.
  1608. (should-not
  1609. (org-test-with-temp-text ":D:\nparagraph"
  1610. (forward-line 1)
  1611. (org-flag-drawer t)
  1612. (get-char-property (line-end-position) 'invisible)))
  1613. ;; Do not hide drawers when called from final blank lines.
  1614. (should-not
  1615. (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
  1616. (goto-char (point-max))
  1617. (org-flag-drawer t)
  1618. (goto-char (point-min))
  1619. (get-char-property (line-end-position) 'invisible)))
  1620. ;; Don't leave point in an invisible part of the buffer when hiding
  1621. ;; a drawer away.
  1622. (should-not
  1623. (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
  1624. (goto-char (point-max))
  1625. (org-flag-drawer t)
  1626. (get-char-property (point) 'invisible))))
  1627. (provide 'test-org)
  1628. ;;; test-org.el ends here