Browse Source

Add org-fold-related tests

Ihor Radchenko 3 năm trước cách đây
mục cha
commit
6d4e65a124
3 tập tin đã thay đổi với 238 bổ sung36 xóa
  1. 24 0
      testing/lisp/test-ol.el
  2. 52 21
      testing/lisp/test-org-list.el
  3. 162 15
      testing/lisp/test-org.el

+ 24 - 0
testing/lisp/test-ol.el

@@ -50,6 +50,30 @@
 	     (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
 

+ 52 - 21
testing/lisp/test-org-list.el

@@ -580,22 +580,40 @@ b. Item 2<point>"
 	     (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 @@ b. Item 2<point>"
 	    (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.

+ 162 - 15
testing/lisp/test-org.el

@@ -4462,7 +4462,9 @@ Outside."
   ;; 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 @@ Text.
   #+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 @@ Text.
     (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 @@ Text.
   #+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 @@ Contents
    (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