-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathfile-paths-unix.lisp
323 lines (220 loc) · 11.9 KB
/
file-paths-unix.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
;;;; -*- Mode: Lisp; indent-tabs-mode: nil -*-
;;;
;;; --- iolib/pathnames test suite.
;;;
(in-package :iolib/tests)
(in-suite :iolib/pathnames)
(defmacro is-file-path (path (&rest components))
(with-gensyms (p)
`(is-true
(let ((,p ,path))
(and (eql (file-path-host ,p) :unspecific)
(eql (file-path-device ,p) :unspecific)
(and (= (length ',components)
(length (file-path-components ,p)))
(every #'(lambda (x y)
(typecase x
(keyword (eql x y))
(string (string= x y))))
(file-path-components ,p)
',components)))))))
(test (file-path.null.1 :compile-at :definition-time)
(signals invalid-file-path
(parse-file-path "")))
(test (file-path.null.2 :compile-at :definition-time)
(signals invalid-file-path
(parse-file-path "" :expand-user t)))
(test (file-path.root.1 :compile-at :definition-time)
(is-file-path (parse-file-path "/")
(:root)))
(test (file-path.root.2 :compile-at :definition-time)
(is-file-path (parse-file-path "/" :expand-user t)
(:root)))
(test (file-path.relative.1 :compile-at :definition-time)
(is-file-path (parse-file-path "a")
("a")))
(test (file-path.relative.2 :compile-at :definition-time)
(is-file-path (parse-file-path "a" :expand-user t)
("a")))
(test (file-path.relative.3 :compile-at :definition-time)
(is-file-path (parse-file-path "a/")
("a")))
(test (file-path.relative.4 :compile-at :definition-time)
(is-file-path (parse-file-path "a/" :expand-user t)
("a")))
(test (file-path.relative.5 :compile-at :definition-time)
(is-file-path (parse-file-path "a/b")
("a" "b")))
(test (file-path.relative.6 :compile-at :definition-time)
(is-file-path (parse-file-path "a/b" :expand-user t)
("a" "b")))
(test (file-path.absolute.1 :compile-at :definition-time)
(is-file-path (parse-file-path "/a")
(:root "a")))
(test (file-path.absolute.2 :compile-at :definition-time)
(is-file-path (parse-file-path "/a" :expand-user t)
(:root "a")))
(test (file-path.absolute.3 :compile-at :definition-time)
(is-file-path (parse-file-path "/a/")
(:root "a")))
(test (file-path.absolute.4 :compile-at :definition-time)
(is-file-path (parse-file-path "/a/" :expand-user t)
(:root "a")))
(test (file-path.absolute.5 :compile-at :definition-time)
(is-file-path (parse-file-path "/a/b")
(:root "a" "b")))
(test (file-path.absolute.6 :compile-at :definition-time)
(is-file-path (parse-file-path "/a/b" :expand-user t)
(:root "a" "b")))
(test (file-path.expand-user.1 :compile-at :definition-time)
(is-file-path (parse-file-path "~root" :expand-user nil)
("~root")))
(test (file-path.expand-user.2 :compile-at :definition-time)
(is-file-path (parse-file-path "~root" :expand-user t)
(:root #+darwin "var" "root")))
(test (file-path.expand-user.3 :compile-at :definition-time)
(is-file-path (parse-file-path "/~root")
(:root "~root")))
(test (file-path.expand-user.4 :compile-at :definition-time)
(is-file-path (parse-file-path "/~root" :expand-user t)
(:root "~root")))
(test (file-path.expand-user.5 :compile-at :definition-time)
(is-file-path (parse-file-path "~root/a" :expand-user nil)
("~root" "a")))
(test (file-path.expand-user.6 :compile-at :definition-time)
(is-file-path (parse-file-path "~root/a" :expand-user t)
(:root #+darwin "var" "root" "a")))
(test (file-path.namestring.1 :compile-at :definition-time)
(is (equal "/" (file-path-namestring (file-path "/")))))
(test (file-path.namestring.2 :compile-at :definition-time)
(is (equal "/." (file-path-namestring (file-path "/.")))))
(test (file-path.namestring.3 :compile-at :definition-time)
(is (equal "/.." (file-path-namestring (file-path "/..")))))
(test (file-path.namestring.4 :compile-at :definition-time)
(is (equal "." (file-path-namestring (file-path ".")))))
(test (file-path.namestring.5 :compile-at :definition-time)
(is (equal "." (file-path-namestring (file-path "./")))))
(test (file-path.namestring.6 :compile-at :definition-time)
(is (equal "../." (file-path-namestring (file-path "../.")))))
(test (file-path.namestring.7 :compile-at :definition-time)
(is (equal "../." (file-path-namestring (file-path ".././")))))
(test (file-path.namestring.8 :compile-at :definition-time)
(is (equal "../.." (file-path-namestring (file-path "../..")))))
(test (file-path.namestring.9 :compile-at :definition-time)
(is (equal "a/./b" (file-path-namestring (file-path "a/./b")))))
(test (file-path.namestring.10 :compile-at :definition-time)
(is (equal "a/../b" (file-path-namestring (file-path "a/../b")))))
(test (file-path.directory.1 :compile-at :definition-time)
(is (equal '(:root) (file-path-directory (file-path "/")))))
(test (file-path.directory.2 :compile-at :definition-time)
(is (equal '(:root) (file-path-directory (file-path "/.")))))
(test (file-path.directory.3 :compile-at :definition-time)
(is (equal '(:root) (file-path-directory (file-path "/..")))))
(test (file-path.directory.4 :compile-at :definition-time)
(is (equal '(".") (file-path-directory (file-path ".")))))
(test (file-path.directory.5 :compile-at :definition-time)
(is (equal '(".") (file-path-directory (file-path "./")))))
(test (file-path.directory.6 :compile-at :definition-time)
(is (equal '(".") (file-path-directory (file-path "..")))))
(test (file-path.directory.7 :compile-at :definition-time)
(is (equal '(".") (file-path-directory (file-path "../")))))
(test (file-path.directory.8 :compile-at :definition-time)
(is (equal '("..") (file-path-directory (file-path "../.")))))
(test (file-path.directory.9 :compile-at :definition-time)
(is (equal '("..") (file-path-directory (file-path ".././")))))
(test (file-path.directory.10 :compile-at :definition-time)
(is (equal '("..") (file-path-directory (file-path "../..")))))
(test (file-path.directory.11 :compile-at :definition-time)
(is (equal '("..") (file-path-directory (file-path "../../")))))
(test (file-path.directory.12 :compile-at :definition-time)
(is (equal '("a" ".") (file-path-directory (file-path "a/./b")))))
(test (file-path.directory.13 :compile-at :definition-time)
(is (equal '("a" "..") (file-path-directory (file-path "a/../b")))))
(test (file-path.directory-namestring.1 :compile-at :definition-time)
(is (equal "/" (file-path-directory (file-path "/") :namestring t))))
(test (file-path.directory-namestring.2 :compile-at :definition-time)
(is (equal "/" (file-path-directory (file-path "/.") :namestring t))))
(test (file-path.directory-namestring.3 :compile-at :definition-time)
(is (equal "/" (file-path-directory (file-path "/..") :namestring t))))
(test (file-path.directory-namestring.4 :compile-at :definition-time)
(is (equal "." (file-path-directory (file-path ".") :namestring t))))
(test (file-path.directory-namestring.5 :compile-at :definition-time)
(is (equal "." (file-path-directory (file-path "./") :namestring t))))
(test (file-path.directory-namestring.6 :compile-at :definition-time)
(is (equal "." (file-path-directory (file-path "..") :namestring t))))
(test (file-path.directory-namestring.7 :compile-at :definition-time)
(is (equal "." (file-path-directory (file-path "../") :namestring t))))
(test (file-path.directory-namestring.8 :compile-at :definition-time)
(is (equal ".." (file-path-directory (file-path "../.") :namestring t))))
(test (file-path.directory-namestring.9 :compile-at :definition-time)
(is (equal ".." (file-path-directory (file-path ".././") :namestring t))))
(test (file-path.directory-namestring.10 :compile-at :definition-time)
(is (equal ".." (file-path-directory (file-path "../..") :namestring t))))
(test (file-path.directory-namestring.11 :compile-at :definition-time)
(is (equal ".." (file-path-directory (file-path "../../") :namestring t))))
(test (file-path.directory-namestring.12 :compile-at :definition-time)
(is (equal "a/." (file-path-directory (file-path "a/./b") :namestring t))))
(test (file-path.directory-namestring.13 :compile-at :definition-time)
(is (equal "a/.." (file-path-directory (file-path "a/../b") :namestring t))))
(test (file-path.file.1 :compile-at :definition-time)
(is (equal "." (file-path-file (file-path "/")))))
(test (file-path.file.2 :compile-at :definition-time)
(is (equal "." (file-path-file (file-path "/.")))))
(test (file-path.file.3 :compile-at :definition-time)
(is (equal ".." (file-path-file (file-path "/..")))))
(test (file-path.file.4 :compile-at :definition-time)
(is (equal "." (file-path-file (file-path ".")))))
(test (file-path.file.5 :compile-at :definition-time)
(is (equal "." (file-path-file (file-path "./")))))
(test (file-path.file.6 :compile-at :definition-time)
(is (equal ".." (file-path-file (file-path "..")))))
(test (file-path.file.7 :compile-at :definition-time)
(is (equal ".." (file-path-file (file-path "../")))))
(test (file-path.file.8 :compile-at :definition-time)
(is (equal "." (file-path-file (file-path "../.")))))
(test (file-path.file.9 :compile-at :definition-time)
(is (equal "." (file-path-file (file-path ".././")))))
(test (file-path.file.10 :compile-at :definition-time)
(is (equal ".." (file-path-file (file-path "../..")))))
(test (file-path.file.11 :compile-at :definition-time)
(is (equal ".." (file-path-file (file-path "../../")))))
(test (file-path.file.12 :compile-at :definition-time)
(is (equal "b" (file-path-file (file-path "a/./b")))))
(test (file-path.file.13 :compile-at :definition-time)
(is (equal "b" (file-path-file (file-path "a/../b")))))
(test (file-path.file-name.1 :compile-at :definition-time)
(is (equal "." (file-path-file-name (file-path "/")))))
(test (file-path.file-name.2 :compile-at :definition-time)
(is (equal "." (file-path-file-name (file-path ".")))))
(test (file-path.file-name.3 :compile-at :definition-time)
(is (equal "." (file-path-file-name (file-path "./")))))
(test (file-path.file-name.4 :compile-at :definition-time)
(is (equal ".." (file-path-file-name (file-path "..")))))
(test (file-path.file-name.5 :compile-at :definition-time)
(is (equal ".." (file-path-file-name (file-path "../")))))
(test (file-path.file-name.6 :compile-at :definition-time)
(is (equal "a" (file-path-file-name (file-path "a")))))
(test (file-path.file-name.7 :compile-at :definition-time)
(is (equal "a" (file-path-file-name (file-path "a.")))))
(test (file-path.file-name.8 :compile-at :definition-time)
(is (equal ".a" (file-path-file-name (file-path ".a")))))
(test (file-path.file-name.9 :compile-at :definition-time)
(is (equal "a" (file-path-file-name (file-path "a.b")))))
(test (file-path.file-type.1 :compile-at :definition-time)
(is (eql nil (file-path-file-type (file-path "/")))))
(test (file-path.file-type.2 :compile-at :definition-time)
(is (eql nil (file-path-file-type (file-path ".")))))
(test (file-path.file-type.3 :compile-at :definition-time)
(is (eql nil (file-path-file-type (file-path "./")))))
(test (file-path.file-type.4 :compile-at :definition-time)
(is (eql nil (file-path-file-type (file-path "..")))))
(test (file-path.file-type.5 :compile-at :definition-time)
(is (eql nil (file-path-file-type (file-path "../")))))
(test (file-path.file-type.6 :compile-at :definition-time)
(is (eql nil (file-path-file-type (file-path "a")))))
(test (file-path.file-type.7 :compile-at :definition-time)
(is (eql nil (file-path-file-type (file-path "a.")))))
(test (file-path.file-type.8 :compile-at :definition-time)
(is (eql nil (file-path-file-type (file-path ".a")))))
(test (file-path.file-type.9 :compile-at :definition-time)
(is (equal "b" (file-path-file-type (file-path "a.b")))))