0.8.7.24:
authorChristophe Rhodes <csr21@cam.ac.uk>
Tue, 27 Jan 2004 14:23:57 +0000 (14:23 +0000)
committerChristophe Rhodes <csr21@cam.ac.uk>
Tue, 27 Jan 2004 14:23:57 +0000 (14:23 +0000)
More pathname fun, *sigh*
... make logical pathnames respect print/read consistency (version
*is* significant for them)
... adjust the pathname tests so that they test equality rather
than namestring equality, but minus version testing
because that's too complicated right now.

src/code/pathname.lisp
src/code/target-pathname.lisp
tests/pathnames.impure.lisp
version.lisp-expr

index 61195bd..07e9a4e 100644 (file)
@@ -37,7 +37,7 @@
                        (lambda (x)
                          (logical-host-name (%pathname-host x))))
                       (unparse-directory #'unparse-logical-directory)
-                      (unparse-file #'unparse-unix-file)
+                      (unparse-file #'unparse-logical-file)
                       (unparse-enough #'unparse-enough-namestring)
                       (customary-case :upper)))
   (name "" :type simple-base-string)
index fa8b426..5fd2744 100644 (file)
@@ -1413,6 +1413,36 @@ a host-structure or string."
                  (t (error "invalid keyword: ~S" piece))))))
        (apply #'concatenate 'simple-string (strings))))))
 
+(defun unparse-logical-file (pathname)
+  (declare (type pathname pathname))
+    (collect ((strings))
+    (let* ((name (%pathname-name pathname))
+          (type (%pathname-type pathname))
+          (version (%pathname-version pathname))
+          (type-supplied (not (or (null type) (eq type :unspecific))))
+          (version-supplied (not (or (null version)
+                                     (eq version :unspecific)))))
+      (when name
+       (when (and (null type) (position #\. name :start 1))
+         (error "too many dots in the name: ~S" pathname))
+       (strings (unparse-logical-piece name)))
+      (when type-supplied
+       (unless name
+         (error "cannot specify the type without a file: ~S" pathname))
+       (when (typep type 'simple-base-string)
+         (when (position #\. type)
+           (error "type component can't have a #\. inside: ~S" pathname)))
+       (strings ".")
+       (strings (unparse-logical-piece type)))
+      (when version-supplied
+       (unless type-supplied
+         (error "cannot specify the version without a type: ~S" pathname))
+       (etypecase version
+         ((member :newest) (strings ".NEWEST"))
+         ((member :wild) (strings ".*"))
+         (fixnum (strings ".") (strings (format nil "~D" version))))))
+    (apply #'concatenate 'simple-string (strings))))
+
 ;;; Unparse a logical pathname string.
 (defun unparse-enough-namestring (pathname defaults)
   (let* ((path-directory (pathname-directory pathname))
@@ -1449,7 +1479,7 @@ a host-structure or string."
   (concatenate 'simple-string
               (logical-host-name (%pathname-host pathname)) ":"
               (unparse-logical-directory pathname)
-              (unparse-unix-file pathname)))
+              (unparse-logical-file pathname)))
 \f
 ;;;; logical pathname translations
 
index 9b93d33..3d5c721 100644 (file)
 
         ;; FIXME: test version handling in LPNs
         )
-      do (assert (string= (namestring (apply #'merge-pathnames params))
-                          (namestring expected-result))))
+      do (let ((result (apply #'merge-pathnames params)))
+          (macrolet ((frob (op)
+                       `(assert (equal (,op result) (,op expected-result)))))
+            (frob pathname-host)
+            (frob pathname-directory)
+            (frob pathname-name)
+            (frob pathname-type))))
 \f
 ;;; host-namestring testing
 (assert (string=
 (assert (raises-error? (merge-pathnames (make-string-output-stream))
                       type-error))
 \f
+;;; ensure read/print consistency (or print-not-readable-error) on
+;;; pathnames:
+(let ((pathnames (list
+                 (make-pathname :name "foo" :type "txt" :version :newest)
+                 (make-pathname :name "foo" :type "txt" :version 1)
+                 (make-pathname :name "foo" :type ".txt")
+                 (make-pathname :name "foo." :type "txt")
+                 (parse-namestring "SCRATCH:FOO.TXT.1")
+                 (parse-namestring "SCRATCH:FOO.TXT.NEWEST")
+                 (parse-namestring "SCRATCH:FOO.TXT"))))
+  (dolist (p pathnames)
+    (handler-case
+       (let ((*print-readably* t))
+         (assert (equal (read-from-string (format nil "~S" p)) p)))
+      (print-not-readable () nil))))
+\f
 ;;;; success
 (quit :unix-status 104)
index 2b76a5d..6a13f9e 100644 (file)
@@ -17,4 +17,4 @@
 ;;; checkins which aren't released. (And occasionally for internal
 ;;; versions, especially for internal versions off the main CVS
 ;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".)
-"0.8.7.23"
+"0.8.7.24"