aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test-pearl-merge.el92
1 files changed, 92 insertions, 0 deletions
diff --git a/tests/test-pearl-merge.el b/tests/test-pearl-merge.el
index 122e5fa..711e772 100644
--- a/tests/test-pearl-merge.el
+++ b/tests/test-pearl-merge.el
@@ -175,6 +175,98 @@ Merge must protect any locally-edited field, not only the description."
(goto-char (point-min))
(should (re-search-forward "UNPUSHED EDIT" nil t)))))
+;;; touched-markers + per-subtree fold
+
+(ert-deftest test-pearl-merge-returns-touched-markers-for-updated-and-added ()
+ "The merge result carries one marker per re-rendered or appended subtree.
+The marker list is the foundation of the per-subtree fold path that
+replaced the global re-fold: callers fold just the touched subtrees so
+an edit-then-merge flow leaves the rest of the page (and point) alone."
+ (test-pearl-merge--in-org
+ (test-pearl-merge--buffer (test-pearl-merge--issue "a" "Alpha" "Desc.")
+ (test-pearl-merge--issue "b" "Beta" "Desc."))
+ (let* ((counts (pearl--merge-issues-into-buffer
+ (list (test-pearl-merge--issue "a" "Alpha Renamed" "Desc.")
+ (test-pearl-merge--issue "b" "Beta" "Desc.")
+ (test-pearl-merge--issue "c" "Gamma" "Desc."))))
+ (markers (plist-get counts :touched-markers)))
+ ;; 2 updated + 1 added = 3 markers
+ (should (= 3 (length markers)))
+ ;; Every marker points at a live position in this buffer
+ (dolist (m markers)
+ (should (markerp m))
+ (should (eq (current-buffer) (marker-buffer m))))
+ ;; Each marker sits on or before an issue heading
+ (dolist (m markers)
+ (save-excursion
+ (goto-char m)
+ (org-back-to-heading t)
+ (should (org-entry-get nil "LINEAR-ID")))))))
+
+(ert-deftest test-pearl-merge-skipped-issues-do-not-add-to-touched-markers ()
+ "A locally-edited subtree the merge kept (skipped) is not in :touched-markers.
+The fold should leave kept subtrees exactly as the user had them, so they
+must not appear in the marker list the fold iterates."
+ (test-pearl-merge--in-org
+ (test-pearl-merge--buffer (test-pearl-merge--issue "a" "Alpha" "Desc Alpha.")
+ (test-pearl-merge--issue "b" "Beta" "Desc Beta."))
+ ;; Mark the "a" subtree dirty by editing its description.
+ (goto-char (point-min))
+ (re-search-forward "Desc Alpha.")
+ (replace-match "Desc Alpha (locally edited).")
+ (let* ((counts (pearl--merge-issues-into-buffer
+ (list (test-pearl-merge--issue "a" "Alpha" "Desc Alpha.")
+ (test-pearl-merge--issue "b" "Beta Renamed" "Desc Beta."))))
+ (markers (plist-get counts :touched-markers)))
+ (should (= 1 (plist-get counts :skipped))) ; a was kept
+ (should (= 1 (plist-get counts :updated))) ; b was re-rendered
+ ;; Only one marker, and it sits on the "b" subtree.
+ (should (= 1 (length markers)))
+ (save-excursion
+ (goto-char (car markers))
+ (org-back-to-heading t)
+ (should (equal "b" (org-entry-get nil "LINEAR-ID")))))))
+
+;;; pearl--fold-subtree-at-marker
+
+(ert-deftest test-pearl-fold-subtree-at-marker-folds-heading-content ()
+ "Folding a subtree leaves the heading visible and hides the content."
+ (let ((pearl-fold-after-update t))
+ (test-pearl-merge--in-org
+ (test-pearl-merge--buffer (test-pearl-merge--issue "a" "Alpha" "Body line."))
+ (goto-char (point-min))
+ (re-search-forward "^\\*\\* ")
+ (beginning-of-line)
+ (let ((heading-pos (point)))
+ (pearl--fold-subtree-at-marker (copy-marker heading-pos))
+ ;; The heading itself is visible
+ (goto-char heading-pos)
+ (should-not (invisible-p (point)))
+ ;; A position inside the body is now invisible
+ (re-search-forward "Body line.")
+ (should (invisible-p (point)))))))
+
+(ert-deftest test-pearl-fold-touched-subtrees-no-op-when-disabled ()
+ "With `pearl-fold-after-update' nil, the fold helper does nothing."
+ (let ((pearl-fold-after-update nil))
+ (test-pearl-merge--in-org
+ (test-pearl-merge--buffer (test-pearl-merge--issue "a" "Alpha" "Body."))
+ (goto-char (point-min))
+ (re-search-forward "^\\*\\* ")
+ (beginning-of-line)
+ (let ((m (copy-marker (point))))
+ (pearl--fold-touched-subtrees (list m))
+ ;; Body stays visible
+ (re-search-forward "Body")
+ (should-not (invisible-p (point)))))))
+
+(ert-deftest test-pearl-fold-subtree-at-marker-tolerates-nil-marker ()
+ "A nil or dead marker is a silent no-op rather than erroring."
+ (let ((pearl-fold-after-update t))
+ (test-pearl-merge--in-org
+ (test-pearl-merge--buffer (test-pearl-merge--issue "a" "Alpha" "Body."))
+ (should-not (pearl--fold-subtree-at-marker nil)))))
+
(ert-deftest test-pearl-merge-updates-rich-description-issue-in-place ()
"An unedited issue with lossy markdown (a heading) is updated, not skipped.
Regression: the dirty check round-tripped Org back to markdown and mistook a