test-org-fold.el 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. ;;; test-org.el --- tests for org.el -*- lexical-binding: t; -*-
  2. ;; Authors: Ihor Radchenko
  3. ;; This file is not part of GNU Emacs.
  4. ;; This program is free software; you can redistribute it and/or modify
  5. ;; it under the terms of the GNU General Public License as published by
  6. ;; the Free Software Foundation, either version 3 of the License, or
  7. ;; (at your option) any later version.
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;; You should have received a copy of the GNU General Public License
  13. ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. ;; Org folding tests.
  15. ;;; Code:
  16. (eval-and-compile (require 'cl-lib))
  17. (ert-deftest test-org-fold/hide-drawer-toggle ()
  18. "Test `org-fold-hide-drawer-toggle' specifications."
  19. ;; Error when not at a drawer.
  20. (should-error
  21. (org-test-with-temp-text ":fake-drawer:\ncontents"
  22. (org-fold-hide-drawer-toggle 'off)
  23. (get-char-property (line-end-position) 'invisible)))
  24. (should-error
  25. (org-test-with-temp-text
  26. "#+begin_example\n<point>:D:\nc\n:END:\n#+end_example"
  27. (org-fold-hide-drawer-toggle t)))
  28. ;; Hide drawer.
  29. (should
  30. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  31. (org-fold-show-all)
  32. (org-fold-hide-drawer-toggle)
  33. (get-char-property (line-end-position) 'invisible)))
  34. ;; Show drawer unconditionally when optional argument is `off'.
  35. (should-not
  36. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  37. (org-fold-hide-drawer-toggle)
  38. (org-fold-hide-drawer-toggle 'off)
  39. (get-char-property (line-end-position) 'invisible)))
  40. ;; Hide drawer unconditionally when optional argument is non-nil.
  41. (should
  42. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  43. (org-fold-hide-drawer-toggle t)
  44. (get-char-property (line-end-position) 'invisible)))
  45. ;; Do not hide drawer when called from final blank lines.
  46. (should-not
  47. (org-test-with-temp-text ":drawer:\ncontents\n:end:\n\n<point>"
  48. (org-fold-show-all)
  49. (org-fold-hide-drawer-toggle)
  50. (goto-char (point-min))
  51. (get-char-property (line-end-position) 'invisible)))
  52. ;; Don't leave point in an invisible part of the buffer when hiding
  53. ;; a drawer away.
  54. (should-not
  55. (org-test-with-temp-text ":drawer:\ncontents\n<point>:end:"
  56. (org-fold-hide-drawer-toggle)
  57. (get-char-property (point) 'invisible))))
  58. (ert-deftest test-org/hide-block-toggle ()
  59. "Test `org-fold-hide-block-toggle' specifications."
  60. ;; Error when not at a block.
  61. (should-error
  62. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
  63. (org-fold-hide-block-toggle 'off)
  64. (get-char-property (line-end-position) 'invisible)))
  65. ;; Hide block.
  66. (should
  67. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  68. (org-fold-hide-block-toggle)
  69. (get-char-property (line-end-position) 'invisible)))
  70. (should
  71. (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
  72. (org-fold-hide-block-toggle)
  73. (get-char-property (line-end-position) 'invisible)))
  74. ;; Show block unconditionally when optional argument is `off'.
  75. (should-not
  76. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  77. (org-fold-hide-block-toggle)
  78. (org-fold-hide-block-toggle 'off)
  79. (get-char-property (line-end-position) 'invisible)))
  80. (should-not
  81. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  82. (org-fold-hide-block-toggle 'off)
  83. (get-char-property (line-end-position) 'invisible)))
  84. ;; Hide block unconditionally when optional argument is non-nil.
  85. (should
  86. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  87. (org-fold-hide-block-toggle t)
  88. (get-char-property (line-end-position) 'invisible)))
  89. (should
  90. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  91. (org-fold-hide-block-toggle)
  92. (org-fold-hide-block-toggle t)
  93. (get-char-property (line-end-position) 'invisible)))
  94. ;; Do not hide block when called from final blank lines.
  95. (should-not
  96. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
  97. (org-fold-hide-block-toggle)
  98. (goto-char (point-min))
  99. (get-char-property (line-end-position) 'invisible)))
  100. ;; Don't leave point in an invisible part of the buffer when hiding
  101. ;; a block away.
  102. (should-not
  103. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
  104. (org-fold-hide-block-toggle)
  105. (get-char-property (point) 'invisible))))
  106. (ert-deftest test-org-fold/hide-block-toggle-maybe ()
  107. "Test `org-fold-hide-block-toggle' specifications."
  108. (should
  109. (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
  110. (org-hide-block-toggle)))
  111. (should-error
  112. (org-test-with-temp-text "Paragraph" (org-hide-block-toggle))))
  113. (ert-deftest test-org-fold/show-set-visibility ()
  114. "Test `org-fold-show-set-visibility' specifications."
  115. ;; Do not throw an error before first heading.
  116. (should
  117. (org-test-with-temp-text "Preamble\n* Headline"
  118. (org-fold-show-set-visibility 'tree)
  119. t))
  120. ;; Test all visibility spans, both on headline and in entry.
  121. (let ((list-visible-lines
  122. (lambda (state headerp)
  123. (org-test-with-temp-text "* Grandmother (0)
  124. ** Uncle (1)
  125. *** Heir (2)
  126. ** Father (3)
  127. Ancestor text (4)
  128. *** Sister (5)
  129. Sibling text (6)
  130. *** Self (7)
  131. Match (8)
  132. **** First born (9)
  133. Child text (10)
  134. **** The other child (11)
  135. *** Brother (12)
  136. ** Aunt (13)
  137. "
  138. (org-cycle t)
  139. (search-forward (if headerp "Self" "Match"))
  140. (org-fold-show-set-visibility state)
  141. (goto-char (point-min))
  142. (let (result (line 0))
  143. (while (not (eobp))
  144. (unless (org-invisible-p2) (push line result))
  145. (cl-incf line)
  146. (forward-line))
  147. (nreverse result))))))
  148. (should (equal '(0 7) (funcall list-visible-lines 'minimal t)))
  149. (should (equal '(0 7 8) (funcall list-visible-lines 'minimal nil)))
  150. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local t)))
  151. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local nil)))
  152. (should (equal '(0 3 7) (funcall list-visible-lines 'ancestors t)))
  153. (should (equal '(0 3 7 8) (funcall list-visible-lines 'ancestors nil)))
  154. (should (equal '(0 3 7 8 9 10 11)
  155. (funcall list-visible-lines 'ancestors-full t)))
  156. (should (equal '(0 3 7 8 9 10 11)
  157. (funcall list-visible-lines 'ancestors-full nil)))
  158. (should (equal '(0 3 5 7 12) (funcall list-visible-lines 'lineage t)))
  159. (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines 'lineage nil)))
  160. (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines 'tree t)))
  161. (should (equal '(0 1 3 5 7 8 9 11 12 13)
  162. (funcall list-visible-lines 'tree nil)))
  163. (should (equal '(0 1 3 4 5 7 12 13)
  164. (funcall list-visible-lines 'canonical t)))
  165. (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
  166. (funcall list-visible-lines 'canonical nil))))
  167. ;; When point is hidden in a drawer or a block, make sure to make it
  168. ;; visible.
  169. (should-not
  170. (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
  171. (org-fold-hide-block-toggle)
  172. (search-forward "Text")
  173. (org-fold-show-set-visibility 'minimal)
  174. (org-invisible-p2)))
  175. (should-not
  176. (org-test-with-temp-text ":DRAWER:\nText\n:END:"
  177. (org-fold-hide-drawer-toggle)
  178. (search-forward "Text")
  179. (org-fold-show-set-visibility 'minimal)
  180. (org-invisible-p2)))
  181. (should-not
  182. (org-test-with-temp-text
  183. "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
  184. (org-fold-hide-drawer-toggle)
  185. (forward-line -1)
  186. (org-fold-hide-block-toggle)
  187. (search-forward "Text")
  188. (org-fold-show-set-visibility 'minimal)
  189. (org-invisible-p2))))
  190. (ert-deftest test-org-fold/copy-visible ()
  191. "Test `org-copy-visible' specifications."
  192. ;;`org-unfontify-region', which is wired up to
  193. ;; `font-lock-unfontify-region-function', removes the invisible text
  194. ;; property, among other things.
  195. (cl-letf (((symbol-function 'org-unfontify-region) #'ignore))
  196. (should
  197. (equal "Foo"
  198. (org-test-with-temp-text "Foo"
  199. (let ((kill-ring nil))
  200. (org-copy-visible (point-min) (point-max))
  201. (current-kill 0 t)))))
  202. ;; Skip invisible characters by text property.
  203. (should
  204. (equal "Foo"
  205. (org-test-with-temp-text #("F<hidden>oo" 1 9 (invisible t))
  206. (let ((kill-ring nil))
  207. (org-copy-visible (point-min) (point-max))
  208. (current-kill 0 t)))))
  209. ;; Skip invisible characters by overlay.
  210. (should
  211. (equal "Foo"
  212. (org-test-with-temp-text "F<hidden>oo"
  213. (let ((o (make-overlay 2 10)))
  214. (overlay-put o 'invisible t))
  215. (let ((kill-ring nil))
  216. (org-copy-visible (point-min) (point-max))
  217. (current-kill 0 t)))))
  218. ;; Handle invisible characters at the beginning and the end of the
  219. ;; buffer.
  220. (should
  221. (equal "Foo"
  222. (org-test-with-temp-text #("<hidden>Foo" 0 8 (invisible t))
  223. (let ((kill-ring nil))
  224. (org-copy-visible (point-min) (point-max))
  225. (current-kill 0 t)))))
  226. (should
  227. (equal "Foo"
  228. (org-test-with-temp-text #("Foo<hidden>" 3 11 (invisible t))
  229. (let ((kill-ring nil))
  230. (org-copy-visible (point-min) (point-max))
  231. (current-kill 0 t)))))
  232. ;; Handle multiple visible parts.
  233. (should
  234. (equal "abc"
  235. (org-test-with-temp-text
  236. #("aXbXc" 1 2 (invisible t) 3 4 (invisible t))
  237. (let ((kill-ring nil))
  238. (org-copy-visible (point-min) (point-max))
  239. (current-kill 0 t)))))
  240. ;; Handle adjacent invisible parts.
  241. (should
  242. (equal "ab"
  243. (org-test-with-temp-text
  244. #("aXXb" 1 2 (invisible t) 2 3 (invisible org-link))
  245. (let ((kill-ring nil))
  246. (org-copy-visible (point-min) (point-max))
  247. (current-kill 0 t)))))
  248. ;; Copies text based on what's actually visible, as defined by
  249. ;; `buffer-invisibility-spec'.
  250. (should
  251. (equal "aYb"
  252. (org-test-with-temp-text
  253. #("aXYb"
  254. 1 2 (invisible t)
  255. 2 3 (invisible org-test-copy-visible))
  256. (let ((kill-ring nil))
  257. (org-copy-visible (point-min) (point-max))
  258. (current-kill 0 t)))))))
  259. (ert-deftest test-org-fold/set-visibility-according-to-property ()
  260. "Test `org-set-visibility-according-to-property' specifications."
  261. ;; "folded" state.
  262. (should
  263. (org-test-with-temp-text
  264. "
  265. * a
  266. :PROPERTIES:
  267. :VISIBILITY: folded
  268. :END:
  269. ** <point>b"
  270. (org-set-visibility-according-to-property)
  271. (invisible-p (point))))
  272. (org-test-with-temp-text
  273. "<point>
  274. #+STARTUP: overview
  275. * A
  276. ** AA
  277. ** AB
  278. *** ABA
  279. :PROPERTIES:
  280. :VISIBILITY: folded
  281. :END:
  282. **** ABAA
  283. **** ABAB
  284. **** ABAC
  285. ** AC
  286. * B
  287. "
  288. (org-set-regexps-and-options)
  289. (org-cycle-set-startup-visibility)
  290. (search-forward "A")
  291. (should-not (invisible-p (point)))
  292. (search-forward "AB")
  293. (should (invisible-p (point)))
  294. (search-forward "ABA")
  295. (should (invisible-p (point)))
  296. (search-forward "ABAB")
  297. (should (invisible-p (point)))
  298. (search-forward "AC")
  299. (should (invisible-p (point)))
  300. (search-forward "B")
  301. (should-not (invisible-p (point))))
  302. ;; "children" state.
  303. (should
  304. (org-test-with-temp-text
  305. "
  306. * a
  307. :PROPERTIES:
  308. :VISIBILITY: children
  309. :END:
  310. ** b
  311. <point>Contents
  312. ** c"
  313. (org-set-visibility-according-to-property)
  314. (invisible-p (point))))
  315. (should
  316. (org-test-with-temp-text
  317. "
  318. * a
  319. :PROPERTIES:
  320. :VISIBILITY: children
  321. :END:
  322. ** b
  323. Contents
  324. *** <point>c"
  325. (org-set-visibility-according-to-property)
  326. (invisible-p (point))))
  327. ;; "content" state.
  328. (should
  329. (org-test-with-temp-text
  330. "
  331. * a
  332. :PROPERTIES:
  333. :VISIBILITY: content
  334. :END:
  335. ** b
  336. <point>Contents
  337. *** c"
  338. (org-set-visibility-according-to-property)
  339. (invisible-p (point))))
  340. (should
  341. (org-test-with-temp-text
  342. "
  343. * a
  344. :PROPERTIES:
  345. :VISIBILITY: content
  346. :END:
  347. ** b
  348. Contents
  349. *** <point>c"
  350. (org-set-visibility-according-to-property)
  351. (not (invisible-p (point)))))
  352. ;; "showall" state.
  353. (should
  354. (org-test-with-temp-text
  355. "
  356. * a
  357. :PROPERTIES:
  358. :VISIBILITY: showall
  359. :END:
  360. ** b
  361. <point>Contents
  362. *** c"
  363. (org-set-visibility-according-to-property)
  364. (not (invisible-p (point)))))
  365. (should
  366. (org-test-with-temp-text
  367. "
  368. * a
  369. :PROPERTIES:
  370. :VISIBILITY: showall
  371. :END:
  372. ** b
  373. Contents
  374. *** <point>c"
  375. (org-set-visibility-according-to-property)
  376. (not (invisible-p (point)))))
  377. ;; When VISIBILITY properties are nested, ignore inner ones.
  378. (should
  379. (org-test-with-temp-text
  380. "
  381. * A
  382. :PROPERTIES:
  383. :VISIBILITY: folded
  384. :END:
  385. ** <point>B
  386. :PROPERTIES:
  387. :VISIBILITY: folded
  388. :END:"
  389. (org-set-visibility-according-to-property)
  390. (invisible-p (point)))))
  391. (ert-deftest test-org-fold/visibility-show-branches ()
  392. "Test visibility of inline archived subtrees."
  393. (org-test-with-temp-text
  394. "* Foo<point>
  395. ** Bar :ARCHIVE:
  396. *** Baz
  397. "
  398. (org-kill-note-or-show-branches)
  399. (should (org-invisible-p (- (point-max) 2)))))
  400. (ert-deftest test-org-fold/org-cycle-narrowed-subtree ()
  401. "Test cycling in narrowed buffer."
  402. (org-test-with-temp-text
  403. "* Heading 1<point>
  404. ** Child 1.1
  405. ** Child 1.2
  406. some text
  407. *** Sub-child 1.2.1
  408. * Heading 2"
  409. (org-overview)
  410. (org-narrow-to-subtree)
  411. (org-cycle)
  412. (re-search-forward "Sub-child")
  413. (should (org-invisible-p))))
  414. (ert-deftest test-org-fold/org-fold-reveal-broken-structure ()
  415. "Test unfolding broken elements."
  416. (let ((org-fold-core-style 'text-properties))
  417. (org-test-with-temp-text
  418. "<point>* Heading 1
  419. Text here"
  420. (org-overview)
  421. (re-search-forward "Text")
  422. (should (org-invisible-p))
  423. (goto-char 1)
  424. (org-delete-char 1)
  425. (re-search-forward "Text")
  426. (should-not (org-invisible-p)))
  427. (org-test-with-temp-text
  428. "* Heading 1
  429. <point>:PROPERTIES:
  430. :ID: something
  431. :END:
  432. Text here"
  433. (org-cycle)
  434. (org-fold-hide-drawer-all)
  435. (re-search-forward "ID")
  436. (should (org-invisible-p))
  437. (re-search-backward ":PROPERTIES:")
  438. (delete-char 1)
  439. (re-search-forward "ID")
  440. (should-not (org-invisible-p)))
  441. (org-test-with-temp-text
  442. "* Heading 1
  443. <point>:PROPERTIES:
  444. :ID: something
  445. :END:
  446. Text here"
  447. (org-cycle)
  448. (org-fold-hide-drawer-all)
  449. (re-search-forward "ID")
  450. (should (org-invisible-p))
  451. (re-search-forward ":END:")
  452. (delete-char -1)
  453. (re-search-backward "ID")
  454. (should-not (org-invisible-p)))
  455. (org-test-with-temp-text
  456. "* Heading 1
  457. <point>#+begin_src emacs-lisp
  458. (+ 1 2)
  459. #+end_src
  460. Text here"
  461. (org-cycle)
  462. (org-fold-hide-drawer-all)
  463. (re-search-forward "end")
  464. (should (org-invisible-p))
  465. (delete-char -1)
  466. (re-search-backward "2")
  467. (should-not (org-invisible-p)))))
  468. (ert-deftest test-org-fold/re-hide-edits-inside-fold ()
  469. "Test edits inside folded regions."
  470. (org-test-with-temp-text
  471. "<point>* Heading 1
  472. Text here"
  473. (org-overview)
  474. (org-set-property "TEST" "1")
  475. (re-search-forward "TEST")
  476. (should (org-invisible-p)))
  477. (org-test-with-temp-text
  478. "* Heading 1<point>
  479. Text here"
  480. (org-overview)
  481. (insert " and extra heading text")
  482. (re-search-backward "heading")
  483. (should-not (org-invisible-p)))
  484. (org-test-with-temp-text
  485. "* Heading 1
  486. Text<point> here"
  487. (org-overview)
  488. (insert " and extra text")
  489. (re-search-backward "extra")
  490. (should (org-invisible-p))))
  491. (defmacro test-org-fold-with-default-template (&rest body)
  492. "Run `org-test-with-temp-text' using default folded template."
  493. (declare (indent 0))
  494. `(let ((org-link-descriptive t))
  495. (org-test-with-temp-text
  496. "#+STARTUP: showeverything
  497. * <point>Folded heading
  498. Folded Paragraph inside heading.
  499. * Unfolded heading
  500. :FOLDED-DRAWER:
  501. Folded Paragraph inside drawer.
  502. :END:
  503. Unfolded Paragraph.
  504. #+begin_src emacs-lisp
  505. (message \"Folded block\")
  506. #+end_src
  507. [[hiddenlink][link]]
  508. "
  509. (org-cycle)
  510. (search-forward "FOLDED-DRAWER")
  511. (org-hide-drawer-toggle t)
  512. (search-forward "begin_src")
  513. (org-hide-block-toggle t)
  514. (goto-char 1)
  515. ,@body)))
  516. (ert-deftest test-org-fold/org-catch-invisible-edits ()
  517. "Test invisible edits handling."
  518. ;; Disable delay in `org-fold-check-before-invisible-edit'.
  519. (cl-letf (((symbol-function 'sit-for) #'ignore))
  520. (dolist (org-fold-core-style '(text-properties overlays))
  521. (dolist (org-fold-catch-invisible-edits
  522. '(nil error smart show show-and-error))
  523. (dolist (kind '(insert delete-backward delete nil))
  524. (message "Testing invisible edits: %S:%S:%S"
  525. org-fold-core-style
  526. org-fold-catch-invisible-edits
  527. kind)
  528. ;; Edits outside invisible.
  529. (test-org-fold-with-default-template
  530. (search-forward "Unfolded Paragraph")
  531. (message "Outside invisible")
  532. (org-fold-check-before-invisible-edit kind)
  533. (should-not (org-invisible-p)))
  534. ;; Edits inside invisible region.
  535. (test-org-fold-with-default-template
  536. (dolist (txt '("Folded Paragraph inside heading"
  537. "Folded Paragraph inside drawer"
  538. "Folded block"))
  539. (search-forward txt)
  540. (message "Inside invisible %S" txt)
  541. (pcase org-fold-catch-invisible-edits
  542. (`nil
  543. (org-fold-check-before-invisible-edit kind)
  544. (should (org-invisible-p)))
  545. (`show
  546. (org-fold-check-before-invisible-edit kind)
  547. (should-not (org-invisible-p)))
  548. ((or `smart `show-and-error)
  549. (should-error (org-fold-check-before-invisible-edit kind))
  550. (should-not (org-invisible-p)))
  551. (`error
  552. (should-error (org-fold-check-before-invisible-edit kind))
  553. (should (org-invisible-p)))))
  554. (search-forward "hiddenlink")
  555. (message "Inside hidden link")
  556. (org-fold-check-before-invisible-edit kind)
  557. (should (org-invisible-p)))
  558. ;; Edits at the left border.
  559. (test-org-fold-with-default-template
  560. (dolist (txt '("Folded heading"
  561. ":FOLDED-DRAWER:"
  562. "#+begin_src emacs-lisp"))
  563. (search-forward txt)
  564. (message "Left of folded %S" txt)
  565. (pcase org-fold-catch-invisible-edits
  566. (`nil
  567. (org-fold-check-before-invisible-edit kind)
  568. (should (org-invisible-p (1+ (point)))))
  569. (`show
  570. (org-fold-check-before-invisible-edit kind)
  571. (should-not (org-invisible-p (1+ (point)))))
  572. (`smart
  573. (if (memq kind '(insert delete-backward))
  574. (org-fold-check-before-invisible-edit kind)
  575. (should-error (org-fold-check-before-invisible-edit kind)))
  576. (should-not (org-invisible-p (1+ (point)))))
  577. (`show-and-error
  578. (should-error (org-fold-check-before-invisible-edit kind))
  579. (should-not (org-invisible-p (1+ (point)))))
  580. (`error
  581. (should-error (org-fold-check-before-invisible-edit kind))
  582. (should (org-invisible-p (1+ (point)))))))
  583. (search-forward "hiddenlink")
  584. (search-forward "lin")
  585. (message "Left border of ]] in link")
  586. (org-fold-check-before-invisible-edit kind)
  587. (should (org-invisible-p (1+ (point)))))
  588. ;; Edits at the right border.
  589. (test-org-fold-with-default-template
  590. (dolist (txt '("Folded Paragraph inside heading."
  591. ":END:"
  592. "#+end_src"))
  593. (search-forward txt)
  594. (message "After %S" txt)
  595. (pcase org-fold-catch-invisible-edits
  596. (`nil
  597. (org-fold-check-before-invisible-edit kind)
  598. (should (org-invisible-p (1- (point)))))
  599. (`show
  600. (org-fold-check-before-invisible-edit kind)
  601. (should-not (org-invisible-p (1- (point)))))
  602. ((or `smart `show-and-error)
  603. (should-error (org-fold-check-before-invisible-edit kind))
  604. (should-not (org-invisible-p (1- (point)))))
  605. (`error
  606. (should-error (org-fold-check-before-invisible-edit kind))
  607. (should (org-invisible-p (1- (point)))))))
  608. (search-forward "hiddenlink")
  609. (search-forward "link]]")
  610. (message "Right border of ]] in link")
  611. (org-fold-check-before-invisible-edit kind)
  612. (should (org-invisible-p (1- (point))))))))))
  613. (provide 'test-org-fold)
  614. ;;; test-org-fold.el ends here