diff options
| author | Christopher R. Nelson <christopher.nelson@languidnights.com> | 2026-11-01 00:16:04 -0400 |
|---|---|---|
| committer | Christopher R. Nelson <christopher.nelson@languidnights.com> | 2026-11-01 00:16:04 -0400 |
| commit | 7fb53e418a48b8baa7bcab89967a0755f2230162 (patch) | |
| tree | e2e4ce1a04ac33650d5c7be06ebdc295ce9112c8 /t | |
| parent | 0bca7a7eb09f0e094aa721f75d23f771d20c6bf3 (diff) | |
Show subdirectories as nested submenus
Each subdirectory of the wallpaper directory becomes an inline Openbox
submenu, recursively, listed before the files at that level. A directory
with no wallpapers and no subdirectories gets the same "No wallpapers in
..." header as an empty root. Hidden directories are skipped, and
symlinks pointing back up the tree are not followed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 't')
| -rw-r--r-- | t/tests.lisp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/t/tests.lisp b/t/tests.lisp index 6baf5ed..bdb109f 100644 --- a/t/tests.lisp +++ b/t/tests.lisp @@ -138,3 +138,72 @@ extensions = .PNG, jpg webp"))) (render-menu (make-config :directory (namestring dir)) s)))) (check (search "<separator label=\"No wallpapers in" xml)) (check (not (search "<item" xml)))))) + +(defun subdir (dir name) + (ensure-directories-exist (merge-pathnames (format nil "~A/" name) dir))) + +(defun render-to-string (dir) + (with-output-to-string (s) + (render-menu (make-config :directory (namestring dir)) s))) + +(deftest test-find-subdirectories + (with-temp-dir (dir) + (dolist (n '("zeta" "Alpha" ".hidden" "beta")) + (subdir dir n)) + (touch dir "file.png") + (check-equal '("Alpha" "beta" "zeta") + (mapcar (lambda (d) (car (last (pathname-directory d)))) + (find-subdirectories (namestring dir)))))) + +(deftest test-render-submenus + (with-temp-dir (dir) + (touch dir "top.png") + (touch (subdir dir "nature") "forest.webp") + (touch (subdir dir "nature/deep_sea") "reef.png") + (let ((xml (render-to-string dir))) + (check (search "<menu id=\"wallpaper-switcher:" xml)) + (check (search "label=\"nature\"" xml)) + (check (search "label=\"deep__sea\"" xml)) + (check (search "label=\"forest\"" xml)) + (check (search "label=\"reef\"" xml)) + ;; Directories come before files, and nesting is preserved. + (check (< (search "label=\"nature\"" xml) (search "label=\"top\"" xml))) + (check (< (search "label=\"deep__sea\"" xml) + (search "label=\"forest\"" xml) + (search "</menu>" xml :from-end t))) + (check (not (search "No wallpapers" xml)))))) + +(deftest test-render-empty-subdirectory + (with-temp-dir (dir) + (touch dir "top.png") + (let ((empty (subdir dir "empty"))) + (touch empty "readme.txt") + (let ((xml (render-to-string dir))) + (check (search "label=\"empty\"" xml)) + (check (search (format nil "<separator label=\"No wallpapers in ~A\"/>" + (uiop:native-namestring empty)) + xml)))))) + +(deftest test-render-root-with-only-subdirectories + (with-temp-dir (dir) + (touch (subdir dir "only") "a.png") + (let ((xml (render-to-string dir))) + (check (search "label=\"a\"" xml)) + (check (not (search "No wallpapers" xml)))))) + +(deftest test-render-skips-hidden-directories + (with-temp-dir (dir) + (touch (subdir dir ".thumbnails") "a.png") + (let ((xml (render-to-string dir))) + (check (not (search "thumbnails" xml))) + (check (search "No wallpapers in" xml))))) + +(deftest test-render-symlink-loop + (with-temp-dir (dir) + (let ((sub (subdir dir "sub"))) + (touch sub "a.png") + (uiop:run-program (list "ln" "-s" (uiop:native-namestring dir) + (uiop:native-namestring (merge-pathnames "loop" sub)))) + (let ((xml (render-to-string dir))) + (check (search "label=\"a\"" xml)) + (check (not (search "label=\"loop\"" xml))))))) |
