Commits

Stephen Compall committed fef88ac

Accept pathnames in maybe-add-trailing-slash, test

Comments (0)

Files changed (2)

src/utils/misc.lisp

 
 (defun maybe-add-trailing-slash (s)
   "Supply a trailing slash if needed."
-  (if (equal (subseq s (1- (length s))) "/")
-    s
-    (concatenate 'string s "/")))
+  (typecase s
+    (pathname (fad:pathname-as-directory s))
+    (otherwise
+       (if (equal (subseq s (1- (length s))) "/")
+	   s
+	   (concatenate 'string s "/")))))
 

test/utils-test/misc.lisp

 
 (in-package :weblocks-test)
 
+(deftestsuite utils/misc-suite (weblocks-suite)
+  ())
+
 ;;; Test humanize-name function
 (deftest humanize-name-1
     (humanize-name 'hello-world)
 (deftest function-designator-p-4
     (function-designator-p (list))
   nil)
+
+;;; maybe-add-trailing-slash
+(addtest maybe-add-trailing-slash-accept-pathnames
+  (let* ((p (make-pathname :directory '(:absolute "usr" "bin")))
+	 (p2 (make-pathname :defaults p :name "env" :type nil
+			    :version :newest)))
+    (ensure-same (weblocks::maybe-add-trailing-slash p) p)
+    (ensure-same (weblocks::maybe-add-trailing-slash p2)
+		 (make-pathname :directory '(:absolute "usr" "bin" "env")))))