test-org-fold.el 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  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/org-fold-hide-entry ()
  114. "Test `org-fold-hide-entry' specifications."
  115. ;; Do nothing on empty heading with children.
  116. (should-not
  117. (org-test-with-temp-text
  118. "* H<point>EADING
  119. ** subheading1
  120. ** subheading2
  121. "
  122. (org-fold-hide-entry)
  123. (org-invisible-p (line-end-position))))
  124. ;; Text inside entry. Hide it.
  125. (should
  126. (org-test-with-temp-text
  127. "* H<point>EADING
  128. Some text here
  129. ** subheading1
  130. ** subheading2
  131. "
  132. (org-fold-hide-entry)
  133. (org-invisible-p (line-end-position))))
  134. ;; Heading at EOB. Do nothing.
  135. (should-not
  136. (org-test-with-temp-text
  137. "* H<point>EADING"
  138. (org-fold-hide-entry)
  139. (org-invisible-p (line-end-position)))))
  140. (ert-deftest test-org-fold/show-set-visibility ()
  141. "Test `org-fold-show-set-visibility' specifications."
  142. ;; Do not throw an error before first heading.
  143. (should
  144. (org-test-with-temp-text "Preamble\n* Headline"
  145. (org-fold-show-set-visibility 'tree)
  146. t))
  147. ;; Test all visibility spans, both on headline and in entry.
  148. (let ((list-visible-lines
  149. (lambda (state headerp)
  150. (org-test-with-temp-text "* Grandmother (0)
  151. ** Uncle (1)
  152. *** Heir (2)
  153. ** Father (3)
  154. Ancestor text (4)
  155. *** Sister (5)
  156. Sibling text (6)
  157. *** Self (7)
  158. Match (8)
  159. **** First born (9)
  160. Child text (10)
  161. **** The other child (11)
  162. *** Brother (12)
  163. ** Aunt (13)
  164. "
  165. (org-cycle t)
  166. (search-forward (if headerp "Self" "Match"))
  167. (org-fold-show-set-visibility state)
  168. (goto-char (point-min))
  169. (let (result (line 0))
  170. (while (not (eobp))
  171. (unless (org-invisible-p2) (push line result))
  172. (cl-incf line)
  173. (forward-line))
  174. (nreverse result))))))
  175. (should (equal '(0 7) (funcall list-visible-lines 'minimal t)))
  176. (should (equal '(0 7 8) (funcall list-visible-lines 'minimal nil)))
  177. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local t)))
  178. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local nil)))
  179. (should (equal '(0 3 7) (funcall list-visible-lines 'ancestors t)))
  180. (should (equal '(0 3 7 8) (funcall list-visible-lines 'ancestors nil)))
  181. (should (equal '(0 3 7 8 9 10 11)
  182. (funcall list-visible-lines 'ancestors-full t)))
  183. (should (equal '(0 3 7 8 9 10 11)
  184. (funcall list-visible-lines 'ancestors-full nil)))
  185. (should (equal '(0 3 5 7 12) (funcall list-visible-lines 'lineage t)))
  186. (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines 'lineage nil)))
  187. (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines 'tree t)))
  188. (should (equal '(0 1 3 5 7 8 9 11 12 13)
  189. (funcall list-visible-lines 'tree nil)))
  190. (should (equal '(0 1 3 4 5 7 12 13)
  191. (funcall list-visible-lines 'canonical t)))
  192. (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
  193. (funcall list-visible-lines 'canonical nil))))
  194. ;; When point is hidden in a drawer or a block, make sure to make it
  195. ;; visible.
  196. (should-not
  197. (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
  198. (org-fold-hide-block-toggle)
  199. (search-forward "Text")
  200. (org-fold-show-set-visibility 'minimal)
  201. (org-invisible-p2)))
  202. (should-not
  203. (org-test-with-temp-text ":DRAWER:\nText\n:END:"
  204. (org-fold-hide-drawer-toggle)
  205. (search-forward "Text")
  206. (org-fold-show-set-visibility 'minimal)
  207. (org-invisible-p2)))
  208. (should-not
  209. (org-test-with-temp-text
  210. "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
  211. (org-fold-hide-drawer-toggle)
  212. (forward-line -1)
  213. (org-fold-hide-block-toggle)
  214. (search-forward "Text")
  215. (org-fold-show-set-visibility 'minimal)
  216. (org-invisible-p2))))
  217. (ert-deftest test-org-fold/copy-visible ()
  218. "Test `org-copy-visible' specifications."
  219. ;;`org-unfontify-region', which is wired up to
  220. ;; `font-lock-unfontify-region-function', removes the invisible text
  221. ;; property, among other things.
  222. (cl-letf (((symbol-function 'org-unfontify-region) #'ignore))
  223. (should
  224. (equal "Foo"
  225. (org-test-with-temp-text "Foo"
  226. (let ((kill-ring nil))
  227. (org-copy-visible (point-min) (point-max))
  228. (current-kill 0 t)))))
  229. ;; Skip invisible characters by text property.
  230. (should
  231. (equal "Foo"
  232. (org-test-with-temp-text #("F<hidden>oo" 1 9 (invisible t))
  233. (let ((kill-ring nil))
  234. (org-copy-visible (point-min) (point-max))
  235. (current-kill 0 t)))))
  236. ;; Skip invisible characters by overlay.
  237. (should
  238. (equal "Foo"
  239. (org-test-with-temp-text "F<hidden>oo"
  240. (let ((o (make-overlay 2 10)))
  241. (overlay-put o 'invisible t))
  242. (let ((kill-ring nil))
  243. (org-copy-visible (point-min) (point-max))
  244. (current-kill 0 t)))))
  245. ;; Handle invisible characters at the beginning and the end of the
  246. ;; buffer.
  247. (should
  248. (equal "Foo"
  249. (org-test-with-temp-text #("<hidden>Foo" 0 8 (invisible t))
  250. (let ((kill-ring nil))
  251. (org-copy-visible (point-min) (point-max))
  252. (current-kill 0 t)))))
  253. (should
  254. (equal "Foo"
  255. (org-test-with-temp-text #("Foo<hidden>" 3 11 (invisible t))
  256. (let ((kill-ring nil))
  257. (org-copy-visible (point-min) (point-max))
  258. (current-kill 0 t)))))
  259. ;; Handle multiple visible parts.
  260. (should
  261. (equal "abc"
  262. (org-test-with-temp-text
  263. #("aXbXc" 1 2 (invisible t) 3 4 (invisible t))
  264. (let ((kill-ring nil))
  265. (org-copy-visible (point-min) (point-max))
  266. (current-kill 0 t)))))
  267. ;; Handle adjacent invisible parts.
  268. (should
  269. (equal "ab"
  270. (org-test-with-temp-text
  271. #("aXXb" 1 2 (invisible t) 2 3 (invisible org-link))
  272. (let ((kill-ring nil))
  273. (org-copy-visible (point-min) (point-max))
  274. (current-kill 0 t)))))
  275. ;; Copies text based on what's actually visible, as defined by
  276. ;; `buffer-invisibility-spec'.
  277. (should
  278. (equal "aYb"
  279. (org-test-with-temp-text
  280. #("aXYb"
  281. 1 2 (invisible t)
  282. 2 3 (invisible org-test-copy-visible))
  283. (let ((kill-ring nil))
  284. (org-copy-visible (point-min) (point-max))
  285. (current-kill 0 t)))))))
  286. (ert-deftest test-org-fold/set-visibility-according-to-property ()
  287. "Test `org-set-visibility-according-to-property' specifications."
  288. ;; "folded" state.
  289. (should
  290. (org-test-with-temp-text
  291. "
  292. * a
  293. :PROPERTIES:
  294. :VISIBILITY: folded
  295. :END:
  296. ** <point>b"
  297. (org-set-visibility-according-to-property)
  298. (invisible-p (point))))
  299. (org-test-with-temp-text
  300. "<point>
  301. #+STARTUP: overview
  302. * A
  303. ** AA
  304. ** AB
  305. *** ABA
  306. :PROPERTIES:
  307. :VISIBILITY: folded
  308. :END:
  309. **** ABAA
  310. **** ABAB
  311. **** ABAC
  312. ** AC
  313. * B
  314. "
  315. (org-set-regexps-and-options)
  316. (org-cycle-set-startup-visibility)
  317. (search-forward "A")
  318. (should-not (invisible-p (point)))
  319. (search-forward "AB")
  320. (should (invisible-p (point)))
  321. (search-forward "ABA")
  322. (should (invisible-p (point)))
  323. (search-forward "ABAB")
  324. (should (invisible-p (point)))
  325. (search-forward "AC")
  326. (should (invisible-p (point)))
  327. (search-forward "B")
  328. (should-not (invisible-p (point))))
  329. ;; "children" state.
  330. (should
  331. (org-test-with-temp-text
  332. "
  333. * a
  334. :PROPERTIES:
  335. :VISIBILITY: children
  336. :END:
  337. ** b
  338. <point>Contents
  339. ** c"
  340. (org-set-visibility-according-to-property)
  341. (invisible-p (point))))
  342. (should
  343. (org-test-with-temp-text
  344. "
  345. * a
  346. :PROPERTIES:
  347. :VISIBILITY: children
  348. :END:
  349. ** b
  350. Contents
  351. *** <point>c"
  352. (org-set-visibility-according-to-property)
  353. (invisible-p (point))))
  354. ;; "content" state.
  355. (should
  356. (org-test-with-temp-text
  357. "
  358. * a
  359. :PROPERTIES:
  360. :VISIBILITY: content
  361. :END:
  362. ** b
  363. <point>Contents
  364. *** c"
  365. (org-set-visibility-according-to-property)
  366. (invisible-p (point))))
  367. (should
  368. (org-test-with-temp-text
  369. "
  370. * a
  371. :PROPERTIES:
  372. :VISIBILITY: content
  373. :END:
  374. ** b
  375. Contents
  376. *** <point>c"
  377. (org-set-visibility-according-to-property)
  378. (not (invisible-p (point)))))
  379. ;; "showall" state.
  380. (should
  381. (org-test-with-temp-text
  382. "
  383. * a
  384. :PROPERTIES:
  385. :VISIBILITY: showall
  386. :END:
  387. ** b
  388. <point>Contents
  389. *** c"
  390. (org-set-visibility-according-to-property)
  391. (not (invisible-p (point)))))
  392. (should
  393. (org-test-with-temp-text
  394. "
  395. * a
  396. :PROPERTIES:
  397. :VISIBILITY: showall
  398. :END:
  399. ** b
  400. Contents
  401. *** <point>c"
  402. (org-set-visibility-according-to-property)
  403. (not (invisible-p (point)))))
  404. ;; When VISIBILITY properties are nested, ignore inner ones.
  405. (should
  406. (org-test-with-temp-text
  407. "
  408. * A
  409. :PROPERTIES:
  410. :VISIBILITY: folded
  411. :END:
  412. ** <point>B
  413. :PROPERTIES:
  414. :VISIBILITY: folded
  415. :END:"
  416. (org-set-visibility-according-to-property)
  417. (invisible-p (point)))))
  418. (ert-deftest test-org-fold/visibility-show-branches ()
  419. "Test visibility of inline archived subtrees."
  420. (org-test-with-temp-text
  421. "* Foo<point>
  422. ** Bar :ARCHIVE:
  423. *** Baz
  424. "
  425. (org-kill-note-or-show-branches)
  426. (should (org-invisible-p (- (point-max) 2)))))
  427. (ert-deftest test-org-fold/org-cycle-narrowed-subtree ()
  428. "Test cycling in narrowed buffer."
  429. (org-test-with-temp-text
  430. "* Heading 1<point>
  431. ** Child 1.1
  432. ** Child 1.2
  433. some text
  434. *** Sub-child 1.2.1
  435. * Heading 2"
  436. (org-overview)
  437. (org-narrow-to-subtree)
  438. (org-cycle)
  439. (re-search-forward "Sub-child")
  440. (should (org-invisible-p))))
  441. (ert-deftest test-org-fold/org-fold-reveal-broken-structure ()
  442. "Test unfolding broken elements."
  443. (let ((org-fold-core-style 'text-properties))
  444. (org-test-with-temp-text
  445. "<point>* Heading 1
  446. Text here"
  447. (org-overview)
  448. (re-search-forward "Text")
  449. (should (org-invisible-p))
  450. (goto-char 1)
  451. (org-delete-char 1)
  452. (re-search-forward "Text")
  453. (should-not (org-invisible-p)))
  454. (org-test-with-temp-text
  455. "* Heading 1
  456. <point>:PROPERTIES:
  457. :ID: something
  458. :END:
  459. Text here"
  460. (org-cycle)
  461. (org-fold-hide-drawer-all)
  462. (re-search-forward "ID")
  463. (should (org-invisible-p))
  464. (re-search-backward ":PROPERTIES:")
  465. (delete-char 1)
  466. (re-search-forward "ID")
  467. (should-not (org-invisible-p)))
  468. (org-test-with-temp-text
  469. "* Heading 1
  470. <point>:PROPERTIES:
  471. :ID: something
  472. :END:
  473. Text here"
  474. (org-cycle)
  475. (org-fold-hide-drawer-all)
  476. (re-search-forward "ID")
  477. (should (org-invisible-p))
  478. (re-search-forward ":END:")
  479. (delete-char -1)
  480. (re-search-backward "ID")
  481. (should-not (org-invisible-p)))
  482. (org-test-with-temp-text
  483. "* Heading 1
  484. <point>#+begin_src emacs-lisp
  485. (+ 1 2)
  486. #+end_src
  487. Text here"
  488. (org-cycle)
  489. (org-fold-hide-drawer-all)
  490. (re-search-forward "end")
  491. (should (org-invisible-p))
  492. (delete-char -1)
  493. (re-search-backward "2")
  494. (should-not (org-invisible-p)))))
  495. (ert-deftest test-org-fold/re-hide-edits-inside-fold ()
  496. "Test edits inside folded regions."
  497. (org-test-with-temp-text
  498. "<point>* Heading 1
  499. Text here"
  500. (org-overview)
  501. (org-set-property "TEST" "1")
  502. (re-search-forward "TEST")
  503. (should (org-invisible-p)))
  504. (org-test-with-temp-text
  505. "* Heading 1<point>
  506. Text here"
  507. (org-overview)
  508. (insert " and extra heading text")
  509. (re-search-backward "heading")
  510. (should-not (org-invisible-p)))
  511. (org-test-with-temp-text
  512. "* Heading 1
  513. Text<point> here"
  514. (org-overview)
  515. (insert " and extra text")
  516. (re-search-backward "extra")
  517. (should (org-invisible-p))))
  518. (defmacro test-org-fold-with-default-template (&rest body)
  519. "Run `org-test-with-temp-text' using default folded template."
  520. (declare (indent 0))
  521. `(let ((org-link-descriptive t))
  522. (org-test-with-temp-text
  523. "#+STARTUP: showeverything
  524. * <point>Folded heading
  525. Folded Paragraph inside heading.
  526. * Unfolded heading
  527. :FOLDED-DRAWER:
  528. Folded Paragraph inside drawer.
  529. :END:
  530. Unfolded Paragraph.
  531. #+begin_src emacs-lisp
  532. (message \"Folded block\")
  533. #+end_src
  534. [[hiddenlink][link]]
  535. "
  536. (org-cycle)
  537. (search-forward "FOLDED-DRAWER")
  538. (org-hide-drawer-toggle t)
  539. (search-forward "begin_src")
  540. (org-hide-block-toggle t)
  541. (goto-char 1)
  542. ,@body)))
  543. (ert-deftest test-org-fold/org-catch-invisible-edits ()
  544. "Test invisible edits handling."
  545. ;; Disable delay in `org-fold-check-before-invisible-edit'.
  546. (cl-letf (((symbol-function 'sit-for) #'ignore))
  547. (dolist (org-fold-core-style '(text-properties overlays))
  548. (dolist (org-fold-catch-invisible-edits
  549. '(nil error smart show show-and-error))
  550. (dolist (kind '(insert delete-backward delete nil))
  551. (message "Testing invisible edits: %S:%S:%S"
  552. org-fold-core-style
  553. org-fold-catch-invisible-edits
  554. kind)
  555. ;; Edits outside invisible.
  556. (test-org-fold-with-default-template
  557. (search-forward "Unfolded Paragraph")
  558. (message "Outside invisible")
  559. (org-fold-check-before-invisible-edit kind)
  560. (should-not (org-invisible-p)))
  561. ;; Edits inside invisible region.
  562. (test-org-fold-with-default-template
  563. (dolist (txt '("Folded Paragraph inside heading"
  564. "Folded Paragraph inside drawer"
  565. "Folded block"))
  566. (search-forward txt)
  567. (message "Inside invisible %S" txt)
  568. (pcase org-fold-catch-invisible-edits
  569. (`nil
  570. (org-fold-check-before-invisible-edit kind)
  571. (should (org-invisible-p)))
  572. (`show
  573. (org-fold-check-before-invisible-edit kind)
  574. (should-not (org-invisible-p)))
  575. ((or `smart `show-and-error)
  576. (should-error (org-fold-check-before-invisible-edit kind))
  577. (should-not (org-invisible-p)))
  578. (`error
  579. (should-error (org-fold-check-before-invisible-edit kind))
  580. (should (org-invisible-p)))))
  581. (search-forward "hiddenlink")
  582. (message "Inside hidden link")
  583. (org-fold-check-before-invisible-edit kind)
  584. (should (org-invisible-p)))
  585. ;; Edits at the left border.
  586. (test-org-fold-with-default-template
  587. (dolist (txt '("Folded heading"
  588. ":FOLDED-DRAWER:"
  589. "#+begin_src emacs-lisp"))
  590. (search-forward txt)
  591. (message "Left of folded %S" txt)
  592. (pcase org-fold-catch-invisible-edits
  593. (`nil
  594. (org-fold-check-before-invisible-edit kind)
  595. (should (org-invisible-p (1+ (point)))))
  596. (`show
  597. (org-fold-check-before-invisible-edit kind)
  598. (should-not (org-invisible-p (1+ (point)))))
  599. (`smart
  600. (if (memq kind '(insert delete-backward))
  601. (org-fold-check-before-invisible-edit kind)
  602. (should-error (org-fold-check-before-invisible-edit kind)))
  603. (should-not (org-invisible-p (1+ (point)))))
  604. (`show-and-error
  605. (should-error (org-fold-check-before-invisible-edit kind))
  606. (should-not (org-invisible-p (1+ (point)))))
  607. (`error
  608. (should-error (org-fold-check-before-invisible-edit kind))
  609. (should (org-invisible-p (1+ (point)))))))
  610. (search-forward "hiddenlink")
  611. (search-forward "lin")
  612. (message "Left border of ]] in link")
  613. (org-fold-check-before-invisible-edit kind)
  614. (should (org-invisible-p (1+ (point)))))
  615. ;; Edits at the right border.
  616. (test-org-fold-with-default-template
  617. (dolist (txt '("Folded Paragraph inside heading."
  618. ":END:"
  619. "#+end_src"))
  620. (search-forward txt)
  621. (message "After %S" txt)
  622. (pcase org-fold-catch-invisible-edits
  623. (`nil
  624. (org-fold-check-before-invisible-edit kind)
  625. (should (org-invisible-p (1- (point)))))
  626. (`show
  627. (org-fold-check-before-invisible-edit kind)
  628. (should-not (org-invisible-p (1- (point)))))
  629. ((or `smart `show-and-error)
  630. (should-error (org-fold-check-before-invisible-edit kind))
  631. (should-not (org-invisible-p (1- (point)))))
  632. (`error
  633. (should-error (org-fold-check-before-invisible-edit kind))
  634. (should (org-invisible-p (1- (point)))))))
  635. (search-forward "hiddenlink")
  636. (search-forward "link]]")
  637. (message "Right border of ]] in link")
  638. (org-fold-check-before-invisible-edit kind)
  639. (should (org-invisible-p (1- (point))))))))))
  640. (provide 'test-org-fold)
  641. ;;; test-org-fold.el ends here