aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pearl.el16
-rw-r--r--tests/test-pearl-bugfixes.el23
2 files changed, 36 insertions, 3 deletions
diff --git a/pearl.el b/pearl.el
index 58e5bd3..ae02f1f 100644
--- a/pearl.el
+++ b/pearl.el
@@ -5042,12 +5042,22 @@ decided later."
(defun pearl--priority-number-at-point ()
"Return the Linear priority (0-4) implied by the heading cookie at point.
-A/B/C/D map to Urgent/High/Medium/Low (1-4); no cookie is None (0)."
+A/B/C/D map to Urgent/High/Medium/Low (1-4); no cookie is None (0). A cookie
+present but outside A-D (e.g. \\='[#E]\\=') is not a Linear priority: it signals
+a `user-error' rather than silently mapping to None, which would clear the
+issue's priority on save. Linear has exactly five priorities, so A-D plus
+no-cookie is the whole range."
(save-excursion
(org-back-to-heading t)
(let ((case-fold-search nil))
- (if (re-search-forward "\\[#\\([A-D]\\)\\]" (line-end-position) t)
- (cdr (assoc (match-string 1) '(("A" . 1) ("B" . 2) ("C" . 3) ("D" . 4))))
+ (if (re-search-forward "\\[#\\([A-Z]\\)\\]" (line-end-position) t)
+ (let ((letter (match-string 1)))
+ (or (cdr (assoc letter '(("A" . 1) ("B" . 2) ("C" . 3) ("D" . 4))))
+ (user-error
+ (concat "Priority cookie [#%s] is not a Linear priority; "
+ "use A-D (A=Urgent, B=High, C=Medium, D=Low) "
+ "or no cookie for None")
+ letter)))
0))))
(defun pearl--priority-dirty-p ()
diff --git a/tests/test-pearl-bugfixes.el b/tests/test-pearl-bugfixes.el
index c1348f1..3d8d53e 100644
--- a/tests/test-pearl-bugfixes.el
+++ b/tests/test-pearl-bugfixes.el
@@ -150,5 +150,28 @@
(should-error (pearl-run-local-view "bad") :type 'user-error)
(should-not fetched))))
+;;; Bug: an out-of-range priority cookie ([#E]) silently downgraded to None
+
+(ert-deftest test-pearl-priority-number-in-range ()
+ "A/B/C/D cookies map to Linear 1-4; a heading with no cookie is 0 (None)."
+ (test-pearl-bug--in-org "* TODO [#A] Urgent issue\n"
+ (should (= 1 (pearl--priority-number-at-point))))
+ (test-pearl-bug--in-org "* TODO [#C] Medium issue\n"
+ (should (= 3 (pearl--priority-number-at-point))))
+ (test-pearl-bug--in-org "* TODO [#D] Low issue\n"
+ (should (= 4 (pearl--priority-number-at-point))))
+ (test-pearl-bug--in-org "* TODO No cookie issue\n"
+ (should (= 0 (pearl--priority-number-at-point)))))
+
+(ert-deftest test-pearl-priority-number-out-of-range-errors ()
+ "An out-of-range cookie ([#E]) signals a user-error, not a silent None.
+The old reader matched only [#A-D], so [#E] fell through to 0 and a save
+silently pushed None, clearing the issue's Linear priority. Now it refuses
+at read time so the bad cookie surfaces before any push."
+ (test-pearl-bug--in-org "* TODO [#E] Bogus priority\n"
+ (should-error (pearl--priority-number-at-point) :type 'user-error))
+ (test-pearl-bug--in-org "* TODO [#Z] Also bogus\n"
+ (should-error (pearl--priority-number-at-point) :type 'user-error)))
+
(provide 'test-pearl-bugfixes)
;;; test-pearl-bugfixes.el ends here