pathname-match-p.lsp 2.69 KB
Newer Older
pfdietz's avatar
pfdietz committed
1 2 3 4 5
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sun Aug 15 07:46:22 2004
;;;; Contains: Tests for PATHNAME-MATCH-P

6

pfdietz's avatar
pfdietz committed
7

8

pfdietz's avatar
pfdietz committed
9 10 11 12 13

;;; Much of the behavior cannot be tested portably.

(deftest pathname-match-p.1
  (let ((pn1 (make-pathname :name :wild))
sds's avatar
sds committed
14
        (pn2 (make-pathname :name "foo")))
pfdietz's avatar
pfdietz committed
15 16 17 18 19
    (pathname-match-p pn1 pn2))
  nil)

(deftest pathname-match-p.2
  (let ((pn1 (make-pathname :type :wild))
sds's avatar
sds committed
20
        (pn2 (make-pathname :type "txt")))
pfdietz's avatar
pfdietz committed
21 22 23 24 25
    (pathname-match-p pn1 pn2))
  nil)

(deftest pathname-match-p.3
  (let ((pn1 (make-pathname :directory '(:absolute :wild)))
sds's avatar
sds committed
26
        (pn2 (make-pathname :directory '(:absolute))))
pfdietz's avatar
pfdietz committed
27 28 29 30 31
    (pathname-match-p pn1 pn2))
  nil)

(deftest pathname-match-p.4
  (let ((pn1 (make-pathname :directory '(:relative :wild)))
sds's avatar
sds committed
32
        (pn2 (make-pathname :directory '(:relative))))
pfdietz's avatar
pfdietz committed
33 34 35 36 37
    (pathname-match-p pn1 pn2))
  nil)

(deftest pathname-match-p.5
  (let ((pn1 (make-pathname :directory '(:relative :wild)))
sds's avatar
sds committed
38
        (pn2 (make-pathname :directory nil)))
pfdietz's avatar
pfdietz committed
39
    (and (wild-pathname-p pn1)
sds's avatar
sds committed
40 41
         (not (pathname-directory pn2))
         (not (pathname-match-p pn1 pn2))))
pfdietz's avatar
pfdietz committed
42 43 44 45
  nil)

(deftest pathname-match-p.6
  (let ((pn1 (make-pathname :version :wild))
sds's avatar
sds committed
46
        (pn2 (make-pathname)))
pfdietz's avatar
pfdietz committed
47
    (and (wild-pathname-p pn1)
sds's avatar
sds committed
48 49
         (not (pathname-version pn2))
         (not (pathname-match-p pn1 pn2))))
pfdietz's avatar
pfdietz committed
50 51
  nil)

52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
;;; Specialized string tests

(deftest pathname-match-p.7
  (let ((wpn (parse-namestring "CLTEST:*.LSP")))
    (assert (wild-pathname-p wpn))
    (do-special-strings
     (s "CLTEST:FOO.LSP" nil)
     (assert (pathname-match-p s wpn))))
  nil)

(deftest pathname-match-p.8
  (do-special-strings
   (s "CLTEST:*.LSP" nil)
   (assert (pathname-match-p "CLTEST:FOO.LSP" s)))
  nil)
sds's avatar
sds committed
67

68

69 70
;;; Add more tests here

pfdietz's avatar
pfdietz committed
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
;;; Here are error tests

(deftest pathname-match-p.error.1
  (signals-error (pathname-match-p) program-error)
  t)

(deftest pathname-match-p.error.2
  (signals-error (pathname-match-p #p"") program-error)
  t)

(deftest pathname-match-p.error.3
  (signals-error (pathname-match-p #p"" #p"" nil) program-error)
  t)

(deftest pathname-match-p.error.4
pfdietz's avatar
pfdietz committed
86
  (check-type-error #'(lambda (x) (pathname-match-p x #p""))
sds's avatar
sds committed
87
                    #'could-be-pathname-designator)
pfdietz's avatar
pfdietz committed
88 89 90
  nil)

(deftest pathname-match-p.error.5
pfdietz's avatar
pfdietz committed
91
  (check-type-error #'(lambda (x) (declare (optimize (safety 0))) (pathname-match-p x #p""))
sds's avatar
sds committed
92
                    #'could-be-pathname-designator)
pfdietz's avatar
pfdietz committed
93 94 95
  nil)

(deftest pathname-match-p.error.6
pfdietz's avatar
pfdietz committed
96
  (check-type-error #'(lambda (x) (pathname-match-p #p"" x))
sds's avatar
sds committed
97
                    #'could-be-pathname-designator)
pfdietz's avatar
pfdietz committed
98 99 100
  nil)

(deftest pathname-match-p.error.7
pfdietz's avatar
pfdietz committed
101
  (check-type-error #'(lambda (x) (declare (optimize (safety 0))) (pathname-match-p #p"" x))
sds's avatar
sds committed
102
                    #'could-be-pathname-designator)
pfdietz's avatar
pfdietz committed
103
  nil)