aboutsummaryrefslogtreecommitdiff
path: root/tests/test-system-lib--ensure-marginalia-align.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-07-18 16:56:22 -0500
committerCraig Jennings <c@cjennings.net>2026-07-18 16:56:22 -0500
commit11de26eb9ac5d79ac1303ff89dfd995fd18cd0ed (patch)
tree4b5c5b3da9cefe6b570f86fad0106f5d153c6a11 /tests/test-system-lib--ensure-marginalia-align.el
parent4e63f665bf153203377f58161aa782a25ffd5e9f (diff)
downloaddotemacs-11de26eb9ac5d79ac1303ff89dfd995fd18cd0ed.tar.gz
dotemacs-11de26eb9ac5d79ac1303ff89dfd995fd18cd0ed.zip
feat(completion): right-align custom category annotations
marginalia-align has been right for months, but annotations from the custom completion categories (radio stations, music files, and everything built through the system-lib table helpers) never went through marginalia. They rendered unaligned. A registration helper adds a builtin registry entry per category at table construction, which routes the table's own annotation function through marginalia's aligned field. The radio table converts from an affixation function with hand-rolled padding to a plain annotation, since marginalia now owns the alignment. Self-maintaining: any future custom category built through the helpers registers itself.
Diffstat (limited to 'tests/test-system-lib--ensure-marginalia-align.el')
-rw-r--r--tests/test-system-lib--ensure-marginalia-align.el57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/test-system-lib--ensure-marginalia-align.el b/tests/test-system-lib--ensure-marginalia-align.el
new file mode 100644
index 00000000..33ff2ba2
--- /dev/null
+++ b/tests/test-system-lib--ensure-marginalia-align.el
@@ -0,0 +1,57 @@
+;;; test-system-lib--ensure-marginalia-align.el --- Tests for marginalia category registration -*- coding: utf-8; lexical-binding: t; -*-
+;;
+;; Author: Craig Jennings <c@cjennings.net>
+;;
+;;; Commentary:
+;; Custom completion categories (cj-music-file, cj-radio-station, and every
+;; category passed to the system-lib table helpers) bypass marginalia, so
+;; their annotations never get its right-alignment even with marginalia-align
+;; set. The registration helper adds a builtin entry per category so the
+;; table's own annotation function renders through marginalia's aligned field.
+
+;;; Code:
+
+(require 'ert)
+
+;; The module's bare defvar marks this special only file-locally; declare it
+;; here too so `let' binds dynamically (the scope-shadowing trap).
+(defvar marginalia-annotator-registry)
+
+(require 'system-lib)
+
+;;; Normal Cases
+
+(ert-deftest test-system-lib-ensure-marginalia-align-registers-category ()
+ "Normal: an unregistered category gains a builtin registry entry."
+ (let ((marginalia-annotator-registry '((file some-annotator builtin none))))
+ (cj/completion-ensure-marginalia-align 'cj-test-category)
+ (should (equal (assq 'cj-test-category marginalia-annotator-registry)
+ '(cj-test-category builtin none)))))
+
+(ert-deftest test-system-lib-ensure-marginalia-align-idempotent ()
+ "Normal: registering the same category twice leaves one entry."
+ (let ((marginalia-annotator-registry '()))
+ (cj/completion-ensure-marginalia-align 'cj-test-category)
+ (cj/completion-ensure-marginalia-align 'cj-test-category)
+ (should (= 1 (length marginalia-annotator-registry)))))
+
+;;; Boundary Cases
+
+(ert-deftest test-system-lib-ensure-marginalia-align-preserves-existing-entry ()
+ "Boundary: a category with an existing (possibly custom) entry is untouched."
+ (let ((marginalia-annotator-registry '((cj-test-category my-custom-annotator))))
+ (cj/completion-ensure-marginalia-align 'cj-test-category)
+ (should (equal (assq 'cj-test-category marginalia-annotator-registry)
+ '(cj-test-category my-custom-annotator)))))
+
+;;; Error Cases
+
+(ert-deftest test-system-lib-ensure-marginalia-align-marginalia-absent-noop ()
+ "Error: without marginalia loaded (registry void) the helper is a silent
+no-op -- annotations just stay unaligned, nothing breaks."
+ ;; marginalia is not loadable in the batch environment, so the global
+ ;; registry is genuinely void outside the `let's above.
+ (should-not (cj/completion-ensure-marginalia-align 'cj-test-category)))
+
+(provide 'test-system-lib--ensure-marginalia-align)
+;;; test-system-lib--ensure-marginalia-align.el ends here