[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 20/38] Add org-fold-related tests---
From: |
Ihor Radchenko |
Subject: |
[PATCH v2 20/38] Add org-fold-related tests--- |
Date: |
Wed, 20 Apr 2022 21:26:23 +0800 |
---
testing/lisp/test-ol.el | 24 +++++
testing/lisp/test-org-list.el | 73 ++++++++++----
testing/lisp/test-org.el | 177 +++++++++++++++++++++++++++++++---
3 files changed, 238 insertions(+), 36 deletions(-)
diff --git a/testing/lisp/test-ol.el b/testing/lisp/test-ol.el
index ddcc570b3..343631623 100644
--- a/testing/lisp/test-ol.el
+++ b/testing/lisp/test-ol.el
@@ -50,6 +50,30 @@ (ert-deftest test-ol/encode-url-with-escaped-char ()
(org-link-encode "http://some.host.com/form?&id=blah%2Bblah25"
'(?\s ?\[ ?\] ?%))))))
+(ert-deftest test-ol/org-toggle-link-display ()
+ "Make sure that `org-toggle-link-display' is working.
+See https://github.com/yantar92/org/issues/4."
+ (dolist (org-link-descriptive '(nil t))
+ (org-test-with-temp-text "* Org link test
+[[https://example.com][A link to a site]]"
+ (dotimes (_ 2)
+ (goto-char 1)
+ (re-search-forward "\\[")
+ (should-not (xor org-link-descriptive (org-invisible-p)))
+ (re-search-forward "example")
+ (should-not (xor org-link-descriptive (org-invisible-p)))
+ (re-search-forward "com")
+ (should-not (xor org-link-descriptive (org-invisible-p)))
+ (re-search-forward "]")
+ (should-not (xor org-link-descriptive (org-invisible-p)))
+ (re-search-forward "\\[")
+ (should-not (org-invisible-p))
+ (re-search-forward "link")
+ (should-not (org-invisible-p))
+ (re-search-forward "]")
+ (should-not (xor org-link-descriptive (org-invisible-p)))
+ (org-toggle-link-display)))))
+
;;; Escape and Unescape Links
diff --git a/testing/lisp/test-org-list.el b/testing/lisp/test-org-list.el
index a9490692e..bc8faa672 100644
--- a/testing/lisp/test-org-list.el
+++ b/testing/lisp/test-org-list.el
@@ -580,22 +580,40 @@ (ert-deftest test-org-list/move-item-down ()
(let ((org-list-use-circular-motion t)) (org-move-item-down))
(buffer-string))))
;; Preserve item visibility.
+ (should
+ (equal
+ (make-list 2 'org-fold-outline)
+ (let ((org-fold-core-style 'text-properties))
+ (org-test-with-temp-text
+ "* Headline\n<point>- item 1\n body 1\n- item 2\n body 2"
+ (let ((org-cycle-include-plain-lists t))
+ (org-cycle)
+ (search-forward "- item 2")
+ (org-cycle))
+ (search-backward "- item 1")
+ (org-move-item-down)
+ (forward-line)
+ (list (org-fold-get-folding-spec)
+ (progn
+ (search-backward " body 2")
+ (org-fold-get-folding-spec)))))))
(should
(equal
'(outline outline)
- (org-test-with-temp-text
- "* Headline\n<point>- item 1\n body 1\n- item 2\n body 2"
- (let ((org-cycle-include-plain-lists t))
- (org-cycle)
- (search-forward "- item 2")
- (org-cycle))
- (search-backward "- item 1")
- (org-move-item-down)
- (forward-line)
- (list (org-invisible-p2)
- (progn
- (search-backward " body 2")
- (org-invisible-p2))))))
+ (let ((org-fold-core-style 'overlays))
+ (org-test-with-temp-text
+ "* Headline\n<point>- item 1\n body 1\n- item 2\n body 2"
+ (let ((org-cycle-include-plain-lists t))
+ (org-cycle)
+ (search-forward "- item 2")
+ (org-cycle))
+ (search-backward "- item 1")
+ (org-move-item-down)
+ (forward-line)
+ (list (org-invisible-p2)
+ (progn
+ (search-backward " body 2")
+ (org-invisible-p2)))))))
;; Preserve children visibility.
(org-test-with-temp-text "* Headline
- item 1
@@ -869,17 +887,30 @@ (ert-deftest test-org-list/insert-item ()
(org-insert-item)
(buffer-string))))
;; Preserve list visibility when inserting an item.
+ (should
+ (equal
+ `(org-fold-outline org-fold-outline)
+ (let ((org-fold-core-style 'text-properties))
+ (org-test-with-temp-text "- A\n - B\n- C\n - D"
+ (let ((org-cycle-include-plain-lists t))
+ (org-cycle)
+ (forward-line 2)
+ (org-cycle)
+ (org-insert-item)
+ (list (org-fold-get-folding-spec nil
(line-beginning-position 0))
+ (org-fold-get-folding-spec nil
(line-end-position 2))))))))
(should
(equal
'(outline outline)
- (org-test-with-temp-text "- A\n - B\n- C\n - D"
- (let ((org-cycle-include-plain-lists t))
- (org-cycle)
- (forward-line 2)
- (org-cycle)
- (org-insert-item)
- (list (get-char-property (line-beginning-position 0) 'invisible)
- (get-char-property (line-end-position 2) 'invisible))))))
+ (let ((org-fold-core-style 'overlays))
+ (org-test-with-temp-text "- A\n - B\n- C\n - D"
+ (let ((org-cycle-include-plain-lists t))
+ (org-cycle)
+ (forward-line 2)
+ (org-cycle)
+ (org-insert-item)
+ (list (get-char-property
(line-beginning-position 0) 'invisible)
+ (get-char-property (line-end-position 2)
'invisible)))))))
;; Test insertion in area after a sub-list. In particular, if point
;; is right at the end of the previous sub-list, still insert
;; a sub-item in that list.
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 0cc8df154..ca0dc676b 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -4462,7 +4462,9 @@ (ert-deftest test-org/drag-element-backward ()
;; Preserve visibility of elements and their contents.
(should
(equal '((63 . 82) (26 . 48))
- (org-test-with-temp-text "
+ (let ((org-fold-core-style 'text-properties))
+ (org-test-with-temp-text
+ "
#+BEGIN_CENTER
Text.
#+END_CENTER
@@ -4470,11 +4472,35 @@ (ert-deftest test-org/drag-element-backward ()
#+BEGIN_QUOTE
Text.
#+END_QUOTE"
- (while (search-forward "BEGIN_" nil t) (org-cycle))
- (search-backward "- item 1")
- (org-drag-element-backward)
- (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
- (overlays-in (point-min) (point-max))))))
+ (while (search-forward "BEGIN_" nil t) (org-cycle))
+ (search-backward "- item 1")
+ (org-drag-element-backward)
+ (let (regions)
+ (goto-char (point-min))
+ (while (< (point) (point-max))
+ (let ((region (org-fold-get-region-at-point)))
+ (if (not region)
+ (goto-char (org-fold-next-folding-state-change))
+ (goto-char (cdr region))
+ (push region regions))))
+ regions)))))
+ (should
+ (equal '((63 . 82) (26 . 48))
+ (let ((org-fold-core-style 'overlays))
+ (org-test-with-temp-text
+ "
+#+BEGIN_CENTER
+Text.
+#+END_CENTER
+- item 1
+ #+BEGIN_QUOTE
+ Text.
+ #+END_QUOTE"
+ (while (search-forward "BEGIN_" nil t) (org-cycle))
+ (search-backward "- item 1")
+ (org-drag-element-backward)
+ (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
+ (overlays-in (point-min) (point-max)))))))
;; Pathological case: handle call with point in blank lines right
;; after a headline.
(should
@@ -4511,7 +4537,9 @@ (ert-deftest test-org/drag-element-forward ()
(should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
(should (looking-at " 1")))
;; 5. Preserve visibility of elements and their contents.
- (org-test-with-temp-text "
+ (let ((org-fold-core-style 'text-properties))
+ (org-test-with-temp-text
+ "
#+BEGIN_CENTER
Text.
#+END_CENTER
@@ -4519,14 +4547,39 @@ (ert-deftest test-org/drag-element-forward ()
#+BEGIN_QUOTE
Text.
#+END_QUOTE"
- (while (search-forward "BEGIN_" nil t) (org-cycle))
- (search-backward "#+BEGIN_CENTER")
- (org-drag-element-forward)
- (should
- (equal
- '((63 . 82) (26 . 48))
- (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
- (overlays-in (point-min) (point-max)))))))
+ (while (search-forward "BEGIN_" nil t) (org-cycle))
+ (search-backward "#+BEGIN_CENTER")
+ (org-drag-element-forward)
+ (should
+ (equal
+ '((63 . 82) (26 . 48))
+ (let (regions)
+ (goto-char (point-min))
+ (while (< (point) (point-max))
+ (let ((region (org-fold-get-region-at-point)))
+ (if (not region)
+ (goto-char (org-fold-next-folding-state-change))
+ (goto-char (cdr region))
+ (push region regions))))
+ regions)))))
+ (let ((org-fold-core-style 'overlays))
+ (org-test-with-temp-text
+ "
+#+BEGIN_CENTER
+Text.
+#+END_CENTER
+- item 1
+ #+BEGIN_QUOTE
+ Text.
+ #+END_QUOTE"
+ (while (search-forward "BEGIN_" nil t) (org-cycle))
+ (search-backward "#+BEGIN_CENTER")
+ (org-drag-element-forward)
+ (should
+ (equal
+ '((63 . 82) (26 . 48))
+ (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
+ (overlays-in (point-min) (point-max))))))))
(ert-deftest test-org/next-block ()
"Test `org-next-block' specifications."
@@ -8419,6 +8472,100 @@ (ert-deftest test-org/visibility-show-branches ()
(org-kill-note-or-show-branches)
(should (org-invisible-p (- (point-max) 2)))))
+(ert-deftest test-org/org-cycle-narrowed-subtree ()
+ "Test cycling in narrowed buffer."
+ (org-test-with-temp-text
+ "* Heading 1<point>
+** Child 1.1
+** Child 1.2
+some text
+*** Sub-child 1.2.1
+* Heading 2"
+ (org-overview)
+ (org-narrow-to-subtree)
+ (org-cycle)
+ (re-search-forward "Sub-child")
+ (should (org-invisible-p))))
+
+(ert-deftest test-org/org-fold-reveal-broken-structure ()
+ "Test unfolding broken elements."
+ (let ((org-fold-core-style 'text-properties))
+ (org-test-with-temp-text
+ "<point>* Heading 1
+Text here"
+ (org-overview)
+ (re-search-forward "Text")
+ (should (org-invisible-p))
+ (goto-char 1)
+ (delete-char 1)
+ (re-search-forward "Text")
+ (should-not (org-invisible-p)))
+ (org-test-with-temp-text
+ "* Heading 1
+<point>:PROPERTIES:
+:ID: something
+:END:
+Text here"
+ (org-cycle)
+ (org-fold-hide-drawer-all)
+ (re-search-forward "ID")
+ (should (org-invisible-p))
+ (re-search-backward ":PROPERTIES:")
+ (delete-char 1)
+ (re-search-forward "ID")
+ (should-not (org-invisible-p)))
+ (org-test-with-temp-text
+ "* Heading 1
+<point>:PROPERTIES:
+:ID: something
+:END:
+Text here"
+ (org-cycle)
+ (org-fold-hide-drawer-all)
+ (re-search-forward "ID")
+ (should (org-invisible-p))
+ (re-search-forward ":END:")
+ (delete-char -1)
+ (re-search-backward "ID")
+ (should-not (org-invisible-p)))
+ (org-test-with-temp-text
+ "* Heading 1
+<point>#+begin_src emacs-lisp
+(+ 1 2)
+#+end_src
+Text here"
+ (org-cycle)
+ (org-fold-hide-drawer-all)
+ (re-search-forward "end")
+ (should (org-invisible-p))
+ (delete-char -1)
+ (re-search-backward "2")
+ (should-not (org-invisible-p)))))
+
+(ert-deftest test-org/re-hide-edits-inside-fold ()
+ "Test edits inside folded regions."
+ (org-test-with-temp-text
+ "<point>* Heading 1
+Text here"
+ (org-overview)
+ (org-set-property "TEST" "1")
+ (re-search-forward "TEST")
+ (should (org-invisible-p)))
+ (org-test-with-temp-text
+ "* Heading 1<point>
+Text here"
+ (org-overview)
+ (insert " and extra heading text")
+ (re-search-backward "heading")
+ (should-not (org-invisible-p)))
+ (org-test-with-temp-text
+ "* Heading 1
+Text<point> here"
+ (org-overview)
+ (insert " and extra text")
+ (re-search-backward "extra")
+ (should (org-invisible-p))))
+
;;; Yank and Kill
--
2.35.1
--
Ihor Radchenko,
PhD,
Center for Advancing Materials Performance from the Nanoscale (CAMP-nano)
State Key Laboratory for Mechanical Behavior of Materials, Xi'an Jiaotong
University, Xi'an, China
Email: yantar92@gmail.com, ihor_radchenko@alumni.sutd.edu.sg
- [PATCH v2 10/38] Implement link folding* lisp/ol.el (org-link--link-folding-spec):, (continued)
- [PATCH v2 10/38] Implement link folding* lisp/ol.el (org-link--link-folding-spec):, Ihor Radchenko, 2022/04/20
- [PATCH v2 12/38] org-fold: Handle indirect buffer visibility---, Ihor Radchenko, 2022/04/20
- [PATCH v2 11/38] Implement overlay- and text-property-based versions of some functions, Ihor Radchenko, 2022/04/20
- [PATCH v2 13/38] Fix subtle differences between overlays and invisible text properties, Ihor Radchenko, 2022/04/20
- [PATCH v2 14/38] Support extra org-fold optimisations for huge buffers, Ihor Radchenko, 2022/04/20
- [PATCH v2 15/38] Alias new org-fold functions to their old shorter names, Ihor Radchenko, 2022/04/20
- [PATCH v2 16/38] Obsolete old function names that are now in org-fold---, Ihor Radchenko, 2022/04/20
- [PATCH v2 18/38] Move `org-buffer-list' to org-macs.el---, Ihor Radchenko, 2022/04/20
- [PATCH v2 19/38] Restore old visibility behaviour of org-refile---, Ihor Radchenko, 2022/04/20
- [PATCH v2 17/38] org-compat: Work around some third-party packages using outline-* functions, Ihor Radchenko, 2022/04/20
- [PATCH v2 20/38] Add org-fold-related tests---,
Ihor Radchenko <=
- [PATCH v2 22/38] ORG-NEWS: Add list of changes---, Ihor Radchenko, 2022/04/20
- [PATCH v2 23/38] Backport contributed commits---, Ihor Radchenko, 2022/04/20
- [PATCH v2 21/38] org-manual: Update to new org-fold function names---, Ihor Radchenko, 2022/04/20
- [PATCH v2 25/38] Fix bug in org-get-headingFixes #26, where fontification could make the matching and extraction of heading, Anders Johansson, 2022/04/20
- [PATCH v2 24/38] Fix typo: delete-duplicates → delete-dups, Anders Johansson, 2022/04/20
- [PATCH v2 26/38] Rename remaining org-force-cycle-archived, Anders Johansson, 2022/04/20
- [PATCH v2 27/38] Fix org-fold--hide-drawers--overlays---, Ihor Radchenko, 2022/04/20
- [PATCH v2 28/38] org-string-width: Handle undefined behaviour in older Emacs, Ihor Radchenko, 2022/04/20
- [PATCH v2 29/38] org-string-width: Work around `window-pixel-width' bug in old Emacs, Ihor Radchenko, 2022/04/20
- [PATCH v2 30/38] org-fold-show-set-visibility: Fix edge case when folded region is at BOB, Ihor Radchenko, 2022/04/20