summaryrefslogtreecommitdiff
path: root/tests/test-chime-apply-blacklist.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2025-10-25 20:51:15 -0500
committerCraig Jennings <c@cjennings.net>2025-10-25 20:51:15 -0500
commite5f99f9aae1a772f4ac3cab85c6dbb89ccc57a1c (patch)
tree96241398db8e873fee226437359e30fee20df891 /tests/test-chime-apply-blacklist.el
parent4f8ee4eb200922df24388afb0efafec90987a761 (diff)
fix:chime: Use org-get-todo-state for TODOs, not org-entry-getHEADmain
Changed chime--whitelist-predicates and chime--blacklist-predicates to use org-get-todo-state instead of org-entry-get for retrieving TODO keywords. org-entry-get is for reading properties from the properties drawer, not for getting the TODO state of a heading. Also rewrote test-chime-apply-blacklist.el and test-chime-apply-whitelist.el to remove over-mocking. Tests now use real org-mode buffers with actual TODO keywords and tags instead of mocking org-entry-get, which was hiding a bug.
Diffstat (limited to 'tests/test-chime-apply-blacklist.el')
-rw-r--r--tests/test-chime-apply-blacklist.el199
1 files changed, 77 insertions, 122 deletions
diff --git a/tests/test-chime-apply-blacklist.el b/tests/test-chime-apply-blacklist.el
index 6f785ef..6a82030 100644
--- a/tests/test-chime-apply-blacklist.el
+++ b/tests/test-chime-apply-blacklist.el
@@ -20,6 +20,7 @@
;;; Commentary:
;; Unit tests for chime--apply-blacklist function.
+;; Tests use real org-mode buffers with real org syntax.
;; Tests cover normal cases, boundary cases, and error cases.
;;; Code:
@@ -80,27 +81,21 @@
(with-temp-buffer
(org-mode)
(insert "* TODO Task 1\n")
- (let ((marker1 (copy-marker (point))))
- (insert "* DONE Task 2\n")
- (let ((marker2 (copy-marker (point))))
- (insert "* TODO Task 3\n")
- (let ((marker3 (copy-marker (point)))
+ (insert "* DONE Task 2\n")
+ (insert "* TODO Task 3\n")
+ (goto-char (point-min))
+ (let ((marker1 (point-marker)))
+ (forward-line 1)
+ (let ((marker2 (point-marker)))
+ (forward-line 1)
+ (let ((marker3 (point-marker))
(chime-keyword-blacklist '("DONE")))
- ;; Mock org-entry-get to return appropriate keywords
- (cl-letf (((symbol-function 'org-entry-get)
- (lambda (pom property &optional inherit literal-nil)
- (when (equal property "TODO")
- (cond
- ((equal pom marker1) "TODO")
- ((equal pom marker2) "DONE")
- ((equal pom marker3) "TODO")
- (t nil))))))
- (let ((result (chime--apply-blacklist (list marker1 marker2 marker3))))
- ;; Should filter out DONE marker
- (should (= (length result) 2))
- (should (member marker1 result))
- (should-not (member marker2 result))
- (should (member marker3 result))))))))
+ (let ((result (chime--apply-blacklist (list marker1 marker2 marker3))))
+ ;; Should filter out DONE marker
+ (should (= (length result) 2))
+ (should (member marker1 result))
+ (should-not (member marker2 result))
+ (should (member marker3 result)))))))
(test-chime-apply-blacklist-teardown)))
(ert-deftest test-chime-apply-blacklist-tags-blacklist-filters-correctly ()
@@ -109,27 +104,22 @@
(unwind-protect
(with-temp-buffer
(org-mode)
- (insert "* Task 1\n")
- (let ((marker1 (copy-marker (point))))
- (insert "* Task 2\n")
- (let ((marker2 (copy-marker (point))))
- (insert "* Task 3\n")
- (let ((marker3 (copy-marker (point)))
+ (insert "* Task 1 :work:urgent:\n")
+ (insert "* Task 2 :personal:\n")
+ (insert "* Task 3 :work:\n")
+ (goto-char (point-min))
+ (let ((marker1 (point-marker)))
+ (forward-line 1)
+ (let ((marker2 (point-marker)))
+ (forward-line 1)
+ (let ((marker3 (point-marker))
(chime-tags-blacklist '("personal")))
- ;; Mock chime--get-tags to return appropriate tags
- (cl-letf (((symbol-function 'chime--get-tags)
- (lambda (pom)
- (cond
- ((equal pom marker1) '("work" "urgent"))
- ((equal pom marker2) '("personal"))
- ((equal pom marker3) '("work"))
- (t nil)))))
- (let ((result (chime--apply-blacklist (list marker1 marker2 marker3))))
- ;; Should filter out marker with "personal" tag
- (should (= (length result) 2))
- (should (member marker1 result))
- (should-not (member marker2 result))
- (should (member marker3 result))))))))
+ (let ((result (chime--apply-blacklist (list marker1 marker2 marker3))))
+ ;; Should filter out marker with "personal" tag
+ (should (= (length result) 2))
+ (should (member marker1 result))
+ (should-not (member marker2 result))
+ (should (member marker3 result)))))))
(test-chime-apply-blacklist-teardown)))
(ert-deftest test-chime-apply-blacklist-keyword-and-tags-blacklist-uses-or-logic ()
@@ -139,35 +129,22 @@
(with-temp-buffer
(org-mode)
(insert "* TODO Task 1\n")
- (let ((marker1 (copy-marker (point))))
- (insert "* DONE Task 2\n")
- (let ((marker2 (copy-marker (point))))
- (insert "* NEXT Task 3\n")
- (let ((marker3 (copy-marker (point)))
+ (insert "* DONE Task 2\n")
+ (insert "* NEXT Task 3 :archive:\n")
+ (goto-char (point-min))
+ (let ((marker1 (point-marker)))
+ (forward-line 1)
+ (let ((marker2 (point-marker)))
+ (forward-line 1)
+ (let ((marker3 (point-marker))
(chime-keyword-blacklist '("DONE"))
(chime-tags-blacklist '("archive")))
- ;; Mock functions
- (cl-letf (((symbol-function 'org-entry-get)
- (lambda (pom property &optional inherit literal-nil)
- (when (equal property "TODO")
- (cond
- ((equal pom marker1) "TODO")
- ((equal pom marker2) "DONE")
- ((equal pom marker3) "NEXT")
- (t nil)))))
- ((symbol-function 'chime--get-tags)
- (lambda (pom)
- (cond
- ((equal pom marker1) nil)
- ((equal pom marker2) nil)
- ((equal pom marker3) '("archive"))
- (t nil)))))
- (let ((result (chime--apply-blacklist (list marker1 marker2 marker3))))
- ;; Should filter out marker2 (DONE) and marker3 (archive tag)
- (should (= (length result) 1))
- (should (member marker1 result))
- (should-not (member marker2 result))
- (should-not (member marker3 result))))))))
+ (let ((result (chime--apply-blacklist (list marker1 marker2 marker3))))
+ ;; Should filter out marker2 (DONE) and marker3 (archive tag)
+ (should (= (length result) 1))
+ (should (member marker1 result))
+ (should-not (member marker2 result))
+ (should-not (member marker3 result)))))))
(test-chime-apply-blacklist-teardown)))
(ert-deftest test-chime-apply-blacklist-multiple-keywords-filters-all ()
@@ -177,24 +154,19 @@
(with-temp-buffer
(org-mode)
(insert "* TODO Task 1\n")
- (let ((marker1 (copy-marker (point))))
- (insert "* DONE Task 2\n")
- (let ((marker2 (copy-marker (point))))
- (insert "* CANCELLED Task 3\n")
- (let ((marker3 (copy-marker (point)))
- (chime-keyword-blacklist '("DONE" "CANCELLED")))
- (cl-letf (((symbol-function 'org-entry-get)
- (lambda (pom property &optional inherit literal-nil)
- (when (equal property "TODO")
- (cond
- ((equal pom marker1) "TODO")
- ((equal pom marker2) "DONE")
- ((equal pom marker3) "CANCELLED")
- (t nil))))))
- (let ((result (chime--apply-blacklist (list marker1 marker2 marker3))))
- ;; Should only keep TODO marker
- (should (= (length result) 1))
- (should (member marker1 result))))))))
+ (insert "* DONE Task 2\n")
+ (insert "* DONE Task 3\n")
+ (goto-char (point-min))
+ (let ((marker1 (point-marker)))
+ (forward-line 1)
+ (let ((marker2 (point-marker)))
+ (forward-line 1)
+ (let ((marker3 (point-marker))
+ (chime-keyword-blacklist '("DONE")))
+ (let ((result (chime--apply-blacklist (list marker1 marker2 marker3))))
+ ;; Should only keep TODO marker, filter out both DONE markers
+ (should (= (length result) 1))
+ (should (member marker1 result)))))))
(test-chime-apply-blacklist-teardown)))
;;; Boundary Cases
@@ -215,20 +187,15 @@
(with-temp-buffer
(org-mode)
(insert "* TODO Task 1\n")
- (let ((marker1 (copy-marker (point))))
- (insert "* DONE Task 2\n")
- (let ((marker2 (copy-marker (point)))
+ (insert "* DONE Task 2\n")
+ (goto-char (point-min))
+ (let ((marker1 (point-marker)))
+ (forward-line 1)
+ (let ((marker2 (point-marker))
(chime-keyword-blacklist '("DONE")))
- (cl-letf (((symbol-function 'org-entry-get)
- (lambda (pom property &optional inherit literal-nil)
- (when (equal property "TODO")
- (cond
- ((equal pom marker1) "TODO")
- ((equal pom marker2) "DONE")
- (t nil))))))
- (let ((result (chime--apply-blacklist (list marker1 marker2))))
- (should (= (length result) 1))
- (should (member marker1 result)))))))
+ (let ((result (chime--apply-blacklist (list marker1 marker2))))
+ (should (= (length result) 1))
+ (should (member marker1 result))))))
(test-chime-apply-blacklist-teardown)))
(ert-deftest test-chime-apply-blacklist-all-markers-blacklisted-returns-empty ()
@@ -238,19 +205,12 @@
(with-temp-buffer
(org-mode)
(insert "* DONE Task 1\n")
- (let ((marker1 (copy-marker (point))))
+ (let ((marker1 (point-marker)))
(insert "* DONE Task 2\n")
- (let ((marker2 (copy-marker (point)))
+ (let ((marker2 (point-marker))
(chime-keyword-blacklist '("DONE")))
- (cl-letf (((symbol-function 'org-entry-get)
- (lambda (pom property &optional inherit literal-nil)
- (when (equal property "TODO")
- (cond
- ((equal pom marker1) "DONE")
- ((equal pom marker2) "DONE")
- (t nil))))))
- (let ((result (chime--apply-blacklist (list marker1 marker2))))
- (should (equal result '())))))))
+ (let ((result (chime--apply-blacklist (list marker1 marker2))))
+ (should (equal result '()))))))
(test-chime-apply-blacklist-teardown)))
;;; Error Cases
@@ -262,14 +222,11 @@
(with-temp-buffer
(org-mode)
(insert "* Entry without TODO keyword\n")
- (let ((marker1 (copy-marker (point)))
+ (let ((marker1 (point-marker))
(chime-keyword-blacklist '("DONE")))
- (cl-letf (((symbol-function 'org-entry-get)
- (lambda (pom property &optional inherit literal-nil)
- nil)))
- (let ((result (chime--apply-blacklist (list marker1))))
- ;; Should keep marker with nil keyword (not in blacklist)
- (should (= (length result) 1))))))
+ (let ((result (chime--apply-blacklist (list marker1))))
+ ;; Should keep marker with nil keyword (not in blacklist)
+ (should (= (length result) 1)))))
(test-chime-apply-blacklist-teardown)))
(ert-deftest test-chime-apply-blacklist-handles-nil-tags-gracefully ()
@@ -279,13 +236,11 @@
(with-temp-buffer
(org-mode)
(insert "* Entry without tags\n")
- (let ((marker1 (copy-marker (point)))
+ (let ((marker1 (point-marker))
(chime-tags-blacklist '("archive")))
- (cl-letf (((symbol-function 'chime--get-tags)
- (lambda (pom) nil)))
- (let ((result (chime--apply-blacklist (list marker1))))
- ;; Should keep marker with nil tags (not in blacklist)
- (should (= (length result) 1))))))
+ (let ((result (chime--apply-blacklist (list marker1))))
+ ;; Should keep marker with nil tags (not in blacklist)
+ (should (= (length result) 1)))))
(test-chime-apply-blacklist-teardown)))
(provide 'test-chime-apply-blacklist)