summaryrefslogtreecommitdiff
path: root/tests/test-custom-case-downcase-dwim.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-02-15 19:58:15 -0600
committerCraig Jennings <c@cjennings.net>2026-02-15 19:58:15 -0600
commit61bfb79f2c55983697f87b9ba3961a9fb46de2fe (patch)
tree6a9ebc025dcd71cba68f4612aef7b658781f4b8f /tests/test-custom-case-downcase-dwim.el
parent8eab9ccde339829c1866a40f51f942a6b36f2b02 (diff)
test: add 86 new tests, fix 3 production bugs, fix 8 stale tests
New test coverage (86 tests across 7 files): - custom-case: 43 tests (title-case-region, upcase-dwim, downcase-dwim) - custom-datetime: 10 tests (all insert methods with mocked time) - config-utilities: 11 tests (format-build-time type branching) - org-capture-config: 22 tests (date-prefix + event-content) Production bugs found and fixed: - custom-case: title-case-region crashes on whitespace/punctuation-only input (char-after returns nil when no word chars found) - org-capture-config: browser branch missing empty-string guard on :initial plist value, producing stray newline in capture output - mousetrap-mode: keymap never registered in minor-mode-map-alist, so mode was silently not blocking any mouse events. Now pushes/removes on toggle. Additional fixes: - local-repository: fix cons cell syntax bug in localrepo-initialize (was calling vars as functions instead of using cons) - dupre-theme tests: update rainbow-delimiter color expectations - mousetrap tests: update dashboard profile (primary-click → scroll+primary) - music completion test: bind completion-ignore-case to prevent pollution - Delete redundant interactive recording test (duplicate of ERT version) Refactoring: - org-capture-config: extract cj/org-capture--date-prefix pure function from cj/org-capture-format-event-headline for testability Test checklist: todo.org updated to [11/25], removed untestable modules
Diffstat (limited to 'tests/test-custom-case-downcase-dwim.el')
-rw-r--r--tests/test-custom-case-downcase-dwim.el86
1 files changed, 86 insertions, 0 deletions
diff --git a/tests/test-custom-case-downcase-dwim.el b/tests/test-custom-case-downcase-dwim.el
new file mode 100644
index 00000000..78c79b7e
--- /dev/null
+++ b/tests/test-custom-case-downcase-dwim.el
@@ -0,0 +1,86 @@
+;;; test-custom-case-downcase-dwim.el --- Tests for cj/downcase-dwim -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Tests for the cj/downcase-dwim function from custom-case.el.
+;;
+;; Mirror of upcase-dwim: if a region is active, downcase the region;
+;; otherwise downcase the symbol at point. Signals user-error if no symbol.
+;; Tests focus on the dispatch logic, not on Emacs's downcase-region.
+
+;;; Code:
+
+(require 'ert)
+
+(unless (boundp 'cj/custom-keymap)
+ (defvar cj/custom-keymap (make-sparse-keymap)))
+
+(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
+(require 'custom-case)
+
+;;; Normal Cases
+
+(ert-deftest test-custom-case-downcase-dwim-normal-region-downcased ()
+ "Active region should be downcased."
+ (with-temp-buffer
+ (insert "HELLO WORLD")
+ (set-mark (point-min))
+ (goto-char (point-max))
+ (activate-mark)
+ (cj/downcase-dwim)
+ (should (equal (buffer-string) "hello world"))))
+
+(ert-deftest test-custom-case-downcase-dwim-normal-partial-region ()
+ "Only the selected region should be downcased."
+ (with-temp-buffer
+ (insert "HELLO WORLD")
+ (set-mark 1)
+ (goto-char 6)
+ (activate-mark)
+ (cj/downcase-dwim)
+ (should (equal (buffer-string) "hello WORLD"))))
+
+(ert-deftest test-custom-case-downcase-dwim-normal-symbol-at-point ()
+ "Without region, symbol at point should be downcased."
+ (with-temp-buffer
+ (insert "HELLO WORLD")
+ (goto-char 1)
+ (cj/downcase-dwim)
+ (should (equal (buffer-string) "hello WORLD"))))
+
+(ert-deftest test-custom-case-downcase-dwim-normal-symbol-mid-word ()
+ "Point in the middle of a symbol should downcase the whole symbol."
+ (with-temp-buffer
+ (insert "HELLO WORLD")
+ (goto-char 3)
+ (cj/downcase-dwim)
+ (should (equal (buffer-string) "hello WORLD"))))
+
+(ert-deftest test-custom-case-downcase-dwim-normal-already-lowercase ()
+ "Already lowercase text should remain unchanged."
+ (with-temp-buffer
+ (insert "hello WORLD")
+ (goto-char 1)
+ (cj/downcase-dwim)
+ (should (equal (buffer-string) "hello WORLD"))))
+
+;;; Boundary Cases
+
+(ert-deftest test-custom-case-downcase-dwim-boundary-single-char-symbol ()
+ "Single character symbol should be downcased."
+ (with-temp-buffer
+ (insert "A")
+ (goto-char 1)
+ (cj/downcase-dwim)
+ (should (equal (buffer-string) "a"))))
+
+;;; Error Cases
+
+(ert-deftest test-custom-case-downcase-dwim-error-no-symbol-signals-error ()
+ "With no region and no symbol at point, should signal user-error."
+ (with-temp-buffer
+ (insert " ")
+ (goto-char 2)
+ (should-error (cj/downcase-dwim) :type 'user-error)))
+
+(provide 'test-custom-case-downcase-dwim)
+;;; test-custom-case-downcase-dwim.el ends here