aboutsummaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/tests.lisp69
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)))))))