diff options
| author | Craig Jennings <c@cjennings.net> | 2026-02-15 19:58:15 -0600 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-02-15 19:58:15 -0600 |
| commit | 61bfb79f2c55983697f87b9ba3961a9fb46de2fe (patch) | |
| tree | 6a9ebc025dcd71cba68f4612aef7b658781f4b8f /tests/test-org-capture-config-event-content.el | |
| parent | 8eab9ccde339829c1866a40f51f942a6b36f2b02 (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-org-capture-config-event-content.el')
| -rw-r--r-- | tests/test-org-capture-config-event-content.el | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/tests/test-org-capture-config-event-content.el b/tests/test-org-capture-config-event-content.el new file mode 100644 index 00000000..d32b9ef8 --- /dev/null +++ b/tests/test-org-capture-config-event-content.el @@ -0,0 +1,89 @@ +;;; test-org-capture-config-event-content.el --- Tests for cj/org-capture-event-content -*- lexical-binding: t; -*- + +;;; Commentary: +;; Tests for the cj/org-capture-event-content function from org-capture-config.el. +;; +;; Returns selected text for event capture, prioritizing: +;; 1. org-store-link-plist :initial (from browser via org-protocol) +;; 2. org-capture-plist :initial (from Emacs region) +;; 3. Empty string (no selection) +;; +;; Note: org-capture-plist is defined by org-capture at runtime. We ensure +;; it's declared before tests so let-binding works in batch mode. + +;;; Code: + +(require 'ert) +(require 'org) + +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) +(require 'org-capture-config) + +;; Ensure org-capture-plist is declared (normally defined by org-capture at runtime) +(defvar org-capture-plist nil) + +;;; Normal Cases + +(ert-deftest test-org-capture-config-event-content-normal-browser-selection () + "Browser selection via org-protocol should be returned with leading newline." + (let ((org-store-link-plist '(:initial "selected from browser")) + (org-capture-plist '(:initial ""))) + (should (equal (cj/org-capture-event-content) + "\nselected from browser")))) + +(ert-deftest test-org-capture-config-event-content-normal-emacs-region () + "Emacs region selection should be returned with leading newline." + (let ((org-store-link-plist nil) + (org-capture-plist '(:initial "selected in emacs"))) + (should (equal (cj/org-capture-event-content) + "\nselected in emacs")))) + +(ert-deftest test-org-capture-config-event-content-normal-no-selection () + "No selection in either plist should return empty string." + (let ((org-store-link-plist nil) + (org-capture-plist '(:initial ""))) + (should (equal (cj/org-capture-event-content) "")))) + +(ert-deftest test-org-capture-config-event-content-normal-browser-takes-priority () + "Browser selection should take priority over Emacs region." + (let ((org-store-link-plist '(:initial "from browser")) + (org-capture-plist '(:initial "from emacs"))) + (should (equal (cj/org-capture-event-content) + "\nfrom browser")))) + +;;; Boundary Cases + +(ert-deftest test-org-capture-config-event-content-boundary-store-link-no-initial () + "org-store-link-plist without :initial should fall through to capture plist." + (let ((org-store-link-plist '(:url "http://example.com")) + (org-capture-plist '(:initial "from emacs"))) + (should (equal (cj/org-capture-event-content) + "\nfrom emacs")))) + +(ert-deftest test-org-capture-config-event-content-boundary-store-link-empty-initial () + "org-store-link-plist with empty :initial should fall through, not produce stray newline." + (let ((org-store-link-plist '(:initial "")) + (org-capture-plist '(:initial ""))) + (should (equal (cj/org-capture-event-content) "")))) + +(ert-deftest test-org-capture-config-event-content-boundary-capture-plist-nil-initial () + "Nil :initial in capture plist should return empty string." + (let ((org-store-link-plist nil) + (org-capture-plist '(:initial nil))) + (should (equal (cj/org-capture-event-content) "")))) + +(ert-deftest test-org-capture-config-event-content-boundary-multiline-selection () + "Multi-line selection should be preserved." + (let ((org-store-link-plist nil) + (org-capture-plist '(:initial "line one\nline two\nline three"))) + (should (equal (cj/org-capture-event-content) + "\nline one\nline two\nline three")))) + +(ert-deftest test-org-capture-config-event-content-boundary-both-plists-nil () + "Both plists nil should return empty string." + (let ((org-store-link-plist nil) + (org-capture-plist nil)) + (should (equal (cj/org-capture-event-content) "")))) + +(provide 'test-org-capture-config-event-content) +;;; test-org-capture-config-event-content.el ends here |
