aboutsummaryrefslogtreecommitdiff
path: root/tests/test-system-lib--completion-file-annotator.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-06-29 08:42:10 -0400
committerCraig Jennings <c@cjennings.net>2026-06-29 08:42:10 -0400
commit4d64437433ed221a08a5258243c01e3a05980db9 (patch)
tree5fe8b4ebe02310d33890545bc020b2c163141d40 /tests/test-system-lib--completion-file-annotator.el
parent2cec4136bcef7d984ecbafe95ad5280d7fa463f0 (diff)
downloaddotemacs-4d64437433ed221a08a5258243c01e3a05980db9.tar.gz
dotemacs-4d64437433ed221a08a5258243c01e3a05980db9.zip
feat(completion): annotate the file-basename pickers with size and date
Eight completing-read pickers listed bare file basenames, so marginalia had no directory to resolve and couldn't annotate them. Add cj/completion-file-annotator to system-lib — an annotation-function factory that takes a candidate->path resolver and yields a size + modification-date suffix (or "dir" for directories, nil for missing files). Wire each picker through cj/completion-table-annotated with a per-site category and resolver: timer sounds, drill flashcards, Info files, the test-runner focus add/remove, vc clone dirs, hugo drafts, and agenda projects (the project's todo.org mtime). music-config's existing completion table gains the category and annotator inline, keeping its sort metadata. The candidate strings and every return value are unchanged — this only adds completion metadata — so all downstream logic is untouched. The six modules that didn't already pull in system-lib now require it. Tests: cj/completion-file-annotator gets Normal/Boundary/Error coverage (file, directory, nil path, missing file). Full suite green at 5394. Claude-Session: https://claude.ai/code/session_014fyKMTTqLrZpL3rDF3dYc3
Diffstat (limited to 'tests/test-system-lib--completion-file-annotator.el')
-rw-r--r--tests/test-system-lib--completion-file-annotator.el54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/test-system-lib--completion-file-annotator.el b/tests/test-system-lib--completion-file-annotator.el
new file mode 100644
index 000000000..9e1f4aa4a
--- /dev/null
+++ b/tests/test-system-lib--completion-file-annotator.el
@@ -0,0 +1,54 @@
+;;; test-system-lib--completion-file-annotator.el --- Tests for cj/completion-file-annotator -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Unit tests for `cj/completion-file-annotator', the annotation-function
+;; factory used to annotate file-basename completion pickers with size and
+;; modification date.
+
+;;; Code:
+
+(require 'ert)
+(require 'system-lib)
+
+(ert-deftest test-system-lib-completion-file-annotator-normal-file-shows-size-and-date ()
+ "Normal: a regular file is annotated with a size and an ISO date."
+ (let ((file (make-temp-file "cfa-test-" nil ".txt" "hello world")))
+ (unwind-protect
+ (let* ((annotate (cj/completion-file-annotator
+ (lambda (_cand) file)))
+ (result (funcall annotate "anything")))
+ (should (stringp result))
+ ;; file-size-human-readable of 11 bytes is "11"
+ (should (string-match-p "11" result))
+ ;; ISO date for the file's mtime
+ (should (string-match-p
+ (format-time-string "%Y-%m-%d"
+ (file-attribute-modification-time
+ (file-attributes file)))
+ result)))
+ (delete-file file))))
+
+(ert-deftest test-system-lib-completion-file-annotator-boundary-directory-marked-dir ()
+ "Boundary: a directory candidate is annotated with the `dir' marker."
+ (let ((dir (make-temp-file "cfa-dir-" t)))
+ (unwind-protect
+ (let* ((annotate (cj/completion-file-annotator (lambda (_c) dir)))
+ (result (funcall annotate "d")))
+ (should (stringp result))
+ (should (string-match-p "dir" result)))
+ (delete-directory dir t))))
+
+(ert-deftest test-system-lib-completion-file-annotator-error-nil-path-returns-nil ()
+ "Error: a candidate whose path-resolver returns nil yields no annotation."
+ (let ((annotate (cj/completion-file-annotator (lambda (_c) nil))))
+ (should (null (funcall annotate "missing")))))
+
+(ert-deftest test-system-lib-completion-file-annotator-error-missing-file-returns-nil ()
+ "Error: a path that does not exist yields no annotation."
+ (let* ((path (expand-file-name "definitely-not-here-12345.txt"
+ temporary-file-directory))
+ (annotate (cj/completion-file-annotator (lambda (_c) path))))
+ (should (null (funcall annotate "gone")))))
+
+(provide 'test-system-lib--completion-file-annotator)
+;;; test-system-lib--completion-file-annotator.el ends here