aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-24 15:04:30 -0500
committerCraig Jennings <c@cjennings.net>2026-05-24 15:04:30 -0500
commit5f72705cf8534543134da907a26069fff97b799c (patch)
tree361618bf645e69b8f8d9613a02fcf26b91f6d767
parent56d95e96490732b4d88bcd0d8c16708b998be285 (diff)
downloadpearl-5f72705cf8534543134da907a26069fff97b799c.tar.gz
pearl-5f72705cf8534543134da907a26069fff97b799c.zip
test: assert the dirty-buffer path preserves disk and buffer state
Extended the dirty-buffer coverage: with known content saved to disk and an unsaved edit on top, pearl--update-org-from-issues leaves the buffer modified with its edit, leaves the on-disk file at the original saved content (not the render, not the buffer text), and still surfaces the dirty buffer per the UX contract. 362 tests green.
-rw-r--r--tests/test-pearl-org-write.el29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/test-pearl-org-write.el b/tests/test-pearl-org-write.el
index c253190..bd06ef0 100644
--- a/tests/test-pearl-org-write.el
+++ b/tests/test-pearl-org-write.el
@@ -26,6 +26,7 @@
;;; Code:
(require 'test-bootstrap (expand-file-name "test-bootstrap.el"))
+(require 'cl-lib)
(defvar test-pearl--sample-issues
'((:id "u" :identifier "ENG-1" :title "T" :priority 3 :state (:name "Todo")))
@@ -81,5 +82,33 @@ The state mapping is bound so rendering is deterministic."
(should (string-match-p "unsaved edits" (buffer-string)))
(should-not (string-match-p "ENG-1" (buffer-string)))))))
+(ert-deftest test-pearl-update-org-dirty-buffer-preserves-disk-and-surfaces ()
+ "A dirty buffer is left as-is, the on-disk file is untouched, and the buffer is surfaced."
+ (test-pearl--with-org-file tmp
+ (let ((buf (find-file-noselect tmp))
+ (surfaced nil))
+ (with-current-buffer buf
+ (insert "ORIGINAL DISK CONTENT\n")
+ (save-buffer)
+ ;; an unsaved edit on top of the saved content
+ (goto-char (point-max))
+ (insert "UNSAVED EDIT\n"))
+ (cl-letf (((symbol-function 'pearl--surface-buffer)
+ (lambda (b) (setq surfaced b))))
+ (pearl--update-org-from-issues test-pearl--sample-issues))
+ ;; buffer keeps the unsaved edit and stays modified
+ (with-current-buffer buf
+ (should (buffer-modified-p))
+ (should (string-match-p "UNSAVED EDIT" (buffer-string)))
+ (should-not (string-match-p "ENG-1" (buffer-string))))
+ ;; the disk file still holds the original saved content — not the render,
+ ;; and not the unsaved buffer text
+ (let ((disk (with-temp-buffer (insert-file-contents tmp) (buffer-string))))
+ (should (string-match-p "ORIGINAL DISK CONTENT" disk))
+ (should-not (string-match-p "UNSAVED EDIT" disk))
+ (should-not (string-match-p "ENG-1" disk)))
+ ;; the dirty buffer is still surfaced, per the UX contract
+ (should (eq surfaced buf)))))
+
(provide 'test-pearl-org-write)
;;; test-pearl-org-write.el ends here