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-custom-datetime-all-methods.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-custom-datetime-all-methods.el')
| -rw-r--r-- | tests/test-custom-datetime-all-methods.el | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/tests/test-custom-datetime-all-methods.el b/tests/test-custom-datetime-all-methods.el new file mode 100644 index 00000000..c9cfa41e --- /dev/null +++ b/tests/test-custom-datetime-all-methods.el @@ -0,0 +1,112 @@ +;;; test-custom-datetime-all-methods.el --- Tests for custom-datetime.el -*- lexical-binding: t; -*- + +;;; Commentary: +;; Tests for all six insert functions in custom-datetime.el. +;; +;; All functions follow the same pattern: (insert (format-time-string FMT (current-time))) +;; They are thin wrappers, so tests focus on: +;; - Each function inserts text matching its format variable +;; - Custom format variables are respected +;; - Trailing space convention is preserved where present +;; +;; We mock current-time to a fixed value for deterministic output. + +;;; 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-datetime) + +;; Fixed time: 2026-02-15 14:30:45 CST (UTC-6) +(defconst test-datetime--fixed-time (encode-time 45 30 14 15 2 2026) + "Fixed time value for deterministic tests.") + +(defmacro test-datetime--with-fixed-time (&rest body) + "Execute BODY with current-time mocked to test-datetime--fixed-time." + `(cl-letf (((symbol-function 'current-time) + (lambda () test-datetime--fixed-time))) + ,@body)) + +;; Helper: call FUNC in a temp buffer with mocked time and return inserted text +(defun test-datetime--run (func) + "Call FUNC with mocked time and return the buffer contents." + (with-temp-buffer + (test-datetime--with-fixed-time + (funcall func)) + (buffer-string))) + +;;; Normal Cases — Each function inserts expected format + +(ert-deftest test-custom-datetime-all-methods-normal-readable-date-time () + "cj/insert-readable-date-time should insert human-readable date and time." + (let ((result (test-datetime--run #'cj/insert-readable-date-time))) + (should (string-match-p "Sunday, February 15, 2026" result)) + (should (string-match-p "02:30:45 PM" result)))) + +(ert-deftest test-custom-datetime-all-methods-normal-sortable-date-time () + "cj/insert-sortable-date-time should insert ISO-style date and time." + (let ((result (test-datetime--run #'cj/insert-sortable-date-time))) + (should (string-match-p "2026-02-15" result)) + (should (string-match-p "14:30:45" result)))) + +(ert-deftest test-custom-datetime-all-methods-normal-sortable-time () + "cj/insert-sortable-time should insert time with AM/PM and timezone." + (let ((result (test-datetime--run #'cj/insert-sortable-time))) + (should (string-match-p "02:30:45 PM" result)))) + +(ert-deftest test-custom-datetime-all-methods-normal-readable-time () + "cj/insert-readable-time should insert short time with AM/PM." + (let ((result (test-datetime--run #'cj/insert-readable-time))) + (should (string-match-p "2:30 PM" result)))) + +(ert-deftest test-custom-datetime-all-methods-normal-sortable-date () + "cj/insert-sortable-date should insert ISO date with day abbreviation." + (let ((result (test-datetime--run #'cj/insert-sortable-date))) + (should (string-match-p "2026-02-15 Sun" result)))) + +(ert-deftest test-custom-datetime-all-methods-normal-readable-date () + "cj/insert-readable-date should insert full human-readable date." + (let ((result (test-datetime--run #'cj/insert-readable-date))) + (should (equal result "Sunday, February 15, 2026")))) + +;;; Boundary Cases + +(ert-deftest test-custom-datetime-all-methods-boundary-trailing-space-convention () + "Functions with trailing space in format should include it in output." + ;; These formats have trailing spaces by default + (let ((result-rdt (test-datetime--run #'cj/insert-readable-date-time)) + (result-sdt (test-datetime--run #'cj/insert-sortable-date-time)) + (result-st (test-datetime--run #'cj/insert-sortable-time)) + (result-rt (test-datetime--run #'cj/insert-readable-time))) + (should (string-suffix-p " " result-rdt)) + (should (string-suffix-p " " result-sdt)) + (should (string-suffix-p " " result-st)) + (should (string-suffix-p " " result-rt)))) + +(ert-deftest test-custom-datetime-all-methods-boundary-no-trailing-space () + "Functions without trailing space in format should not add one." + (let ((result-sd (test-datetime--run #'cj/insert-sortable-date)) + (result-rd (test-datetime--run #'cj/insert-readable-date))) + (should-not (string-suffix-p " " result-sd)) + (should-not (string-suffix-p " " result-rd)))) + +(ert-deftest test-custom-datetime-all-methods-boundary-custom-format-override () + "Overriding a format variable should change the output." + (let ((readable-date-format "%d/%m/%Y")) + (should (equal (test-datetime--run #'cj/insert-readable-date) + "15/02/2026")))) + +(ert-deftest test-custom-datetime-all-methods-boundary-inserts-at-point () + "Inserted text should appear at point, not replacing buffer contents." + (with-temp-buffer + (insert "before ") + (test-datetime--with-fixed-time + (cj/insert-sortable-date)) + (should (string-prefix-p "before 2026-02-15" (buffer-string))))) + +(provide 'test-custom-datetime-all-methods) +;;; test-custom-datetime-all-methods.el ends here |
