summaryrefslogtreecommitdiffstats
path: root/tests/018/path.tl
blob: dd22339fc469fc2017cd1b99e3ba1316e53cf2cb (plain)
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
(load "../common")

(mtest
  (short-suffix 42) :error
  (short-suffix #\a) :error
  (short-suffix "") nil
  (short-suffix "" 0) 0
  (short-suffix "a") nil
  (short-suffix "a" 0) 0
  (short-suffix ".") nil
  (short-suffix "a.") "."
  (short-suffix "a.b.") "."
  (short-suffix ".c") nil
  (short-suffix "a.c") ".c"
  (short-suffix ".a.c") ".c"
  (short-suffix "a.b.c") ".c"
  (short-suffix "foo.txt.gz") ".gz"
  (short-suffix "txt.gz") ".gz"
  (short-suffix ".gz") nil)

(mtest
  (long-suffix 42) :error
  (long-suffix #\a) :error
  (long-suffix "") nil
  (long-suffix "" 0) 0
  (long-suffix "a") nil
  (long-suffix "a" 0) 0
  (long-suffix ".") nil
  (long-suffix "a.") "."
  (long-suffix "a.b.") ".b."
  (long-suffix ".c") nil
  (long-suffix "a.c") ".c"
  (long-suffix "a.b.c") ".b.c"
  (long-suffix "foo.txt.gz") ".txt.gz"
  (long-suffix ".gz") nil
  (long-suffix ".txt.gz") ".gz"
  (long-suffix "/.txt.gz") ".gz"
  (long-suffix "a/.txt.gz") ".gz"
  (long-suffix "a/.txt.tar.gz") ".tar.gz")

(mtest
  (short-suffix "/") nil
  (short-suffix "a/") nil
  (short-suffix "/.") nil
  (short-suffix "a/.") nil
  (short-suffix ".a/") nil
  (short-suffix ".a/b") nil
  (short-suffix ".a/c.b") ".b"
  (short-suffix ".a/b/") nil
  (short-suffix ".a/b/.b") nil
  (short-suffix ".a/b/.b/") nil
  (short-suffix ".a/b/c.b") ".b"
  (short-suffix ".a/b/c.b/") ".b"
  (short-suffix ".a/b/c.b//") ".b"
  (short-suffix ".a/b/c.b///") ".b"
  (short-suffix ".a/b/c.") "."
  (short-suffix ".a/b/c./") "."
  (short-suffix ".a/b/c.//") "."
  (short-suffix ".a/b/c.///") ".")

(mtest
  (long-suffix "/") nil
  (long-suffix "a/") nil
  (long-suffix "/.") nil
  (long-suffix "a/.") nil
  (long-suffix ".a/") nil
  (long-suffix ".a/b") nil
  (long-suffix ".a/b/") nil
  (long-suffix ".a/b/.b") nil
  (long-suffix ".a/b/.b/") nil
  (long-suffix ".a/b/c.b") ".b"
  (long-suffix ".a/b/c.b/") ".b"
  (long-suffix "a.b/c.d.e") ".d.e"
  (long-suffix "a.b/c.d.e/") ".d.e"
  (long-suffix "a.b/c.d.e/f") nil
  (long-suffix "a.b/c.d.e/f.g.h") ".g.h"
  (long-suffix "a.b/c.d.e//") ".d.e"
  (long-suffix "a.b/c.d.e///") ".d.e"
  (long-suffix "a.b/c.d.") ".d."
  (long-suffix "a.b/c.d./") ".d."
  (long-suffix "a.b/c.d.//") ".d."
  (long-suffix "a.b/c.d.///") ".d."
  (long-suffix "a.b/c.") "."
  (long-suffix "a.b/c./") "."
  (long-suffix "a.b/c.//") "."
  (long-suffix "a.b/c.///") ".")

(mtest
  (trim-short-suffix "") ""
  (trim-short-suffix ".") "."
  (trim-short-suffix "/.") "/."
  (trim-short-suffix ".b") ".b"
  (trim-short-suffix ".a.b") ".a"
  (trim-short-suffix ".a.b.c") ".a.b"
  (trim-short-suffix "/.b") "/.b"
  (trim-short-suffix "/.b/") "/.b/"
  (trim-short-suffix "/.b//") "/.b//"
  (trim-short-suffix "a.b") "a"
  (trim-short-suffix "/a.b") "/a"
  (trim-short-suffix "/a.b/") "/a/"
  (trim-short-suffix "/a.b//") "/a//"
  (trim-short-suffix "a.") "a"
  (trim-short-suffix "/a.") "/a"
  (trim-short-suffix "/a./") "/a/"
  (trim-short-suffix "/a.//") "/a//")

(mtest
  (trim-long-suffix "") ""
  (trim-long-suffix ".") "."
  (trim-long-suffix "/.") "/."
  (trim-long-suffix ".b") ".b"
  (trim-long-suffix ".a.b") ".a"
  (trim-long-suffix ".a.b.c") ".a"
  (trim-long-suffix "/.b") "/.b"
  (trim-long-suffix "/.b/") "/.b/"
  (trim-long-suffix "/.b//") "/.b//"
  (trim-long-suffix "a.b") "a"
  (trim-long-suffix "/a.b") "/a"
  (trim-long-suffix "/a.b/") "/a/"
  (trim-long-suffix "/a.b//") "/a//"
  (trim-long-suffix "/.b.c") "/.b"
  (trim-long-suffix "/.b.c/") "/.b/"
  (trim-long-suffix "/.b.c//") "/.b//"
  (trim-long-suffix "/.b.c.d") "/.b"
  (trim-long-suffix "/.b.c.d/") "/.b/"
  (trim-long-suffix "/.b.c.d//") "/.b//"
  (trim-long-suffix "a.b.c") "a"
  (trim-long-suffix "/a.b.c") "/a"
  (trim-long-suffix "/a.b.c/") "/a/"
  (trim-long-suffix "/a.b.c//") "/a//"
  (trim-long-suffix "a.") "a"
  (trim-long-suffix "/a.") "/a"
  (trim-long-suffix "/a./") "/a/"
  (trim-long-suffix "/a.//") "/a//")

(mtest
  (add-suffix "" "") ""
  (add-suffix "" "a") "a"
  (add-suffix "." "a") ".a"
  (add-suffix "." ".a") "..a"
  (add-suffix "/" ".b") "/.b"
  (add-suffix "//" ".b") "/.b/"
  (add-suffix "//" "b") "/b/"
  (add-suffix "a" "") "a"
  (add-suffix "a" ".b") "a.b"
  (add-suffix "a/" ".b") "a.b/"
  (add-suffix "a//" ".b") "a.b//"

  (add-suffix "c://" "x") "c:/x/"
  (add-suffix "0://" "x") "0:/x/"
  (add-suffix "host://" "x") "host://x"
  (add-suffix "host:///" "x") "host://x/"
  (add-suffix "1234:///" "x") "1234://x/")

(mtest
  (base-name "") ""
  (base-name "/") "/"
  (base-name ".") "."
  (base-name "./") "."
  (base-name "a") "a"
  (base-name "a/") "a"
  (base-name "/a") "a"
  (base-name "/a/") "a"
  (base-name "/a/b") "b"
  (base-name "/a/b/") "b"
  (base-name "/a/b//") "b"
  (base-name "/a/b///") "b")

(mtest
  (base-name "" "") ""
  (base-name "/" "/") "/"
  (base-name "/" "") "/"
  (base-name "." ".") "."
  (base-name "." "") "."
  (base-name "./" "/") "."
  (base-name "a" "a") "a"
  (base-name "a" "") "a"
  (base-name "a.b" ".b") "a"
  (base-name "a.b/" ".b") "a"
  (base-name "a.b/" ".b/") "a.b"
  (base-name "a.b/" "a.b") "a.b")

(mtest
  (path-cat "" "") ""
  (path-cat "" ".") "."
  (path-cat "." "") "."
  (path-cat "." ".") "."
  (path-cat "abc" ".") "abc"
  (path-cat "." "abc") "abc"
  (path-cat "./" ".") "./"
  (path-cat "."  "./") "./"
  (path-cat "abc/" ".") "abc/"
  (path-cat "./" "abc") "abc"
  (path-cat "/" ".") "/"
  (path-cat "/" "abc") "/abc"
  (path-cat "ab/cd" "ef") "ab/cd/ef"
  (path-cat "a" "b" "c") "a/b/c"
  (path-cat "a" "b" "" "c" "/") "a/b/c/")

(mtest
  (path-cat) "."
  (path-cat 3) :error
  (path-cat "") ""
  (path-cat "/") "/"
  (path-cat ".") "."
  (path-cat "" "" "") ""
  (path-cat "." "" "") "."
  (path-cat "" "." "") "."
  (path-cat "" "" ".") "."
  (path-cat "." "." ".") "."
  (path-cat "abc/" "/def/" "g") "abc/def/g"
  (path-cat "abc/" "/def/" "g/") "abc/def/g/"
  (path-cat "" "abc/" "/def/" "g/") "abc/def/g/")

(mtest
  (abs-path-p "") nil
  (abs-path-p "/") t
  (abs-path-p "/abc") t
  (abs-path-p "abc") nil
  (abs-path-p ".") nil)

(if (eql [path-sep-chars 0] #\\)
  (mtest
    (abs-path-p "\\abc") t
    (abs-path-p "a:\\abc") t
    (abs-path-p "0:\\abc") t
    (abs-path-p "AB0:\\abc") t
    (abs-path-p "cd5:\\abc") t
    (abs-path-p "a:/abc") t
    (abs-path-p "0:/abc") t
    (abs-path-p "AB0:/abc") t
    (abs-path-p "cd5:/abc") t)
  (mtest
    (abs-path-p "\\abs") nil
    (abs-path-p "a:\\abc") nil
    (abs-path-p "0:\\abc") nil
    (abs-path-p "AB0:\\abc") nil
    (abs-path-p "cd5:\\abc") nil
    (abs-path-p "a:/abc") nil
    (abs-path-p "0:/abc") nil
    (abs-path-p "AB0:/abc") nil
    (abs-path-p "cd5:/abc") nil))

(mtest
  (portable-abs-path-p "") nil
  (portable-abs-path-p "/") t
  (portable-abs-path-p "/abc") t
  (portable-abs-path-p "\\abc") t
  (portable-abs-path-p "abc") nil
  (portable-abs-path-p ".") nil
  (portable-abs-path-p "\\abc") t
  (portable-abs-path-p "a:\\abc") t
  (portable-abs-path-p "0:\\abc") t
  (portable-abs-path-p "AB0:\\abc") t
  (portable-abs-path-p "cd5:\\abc") t
  (portable-abs-path-p "a:/abc") t
  (portable-abs-path-p "0:/abc") t
  (portable-abs-path-p "AB0:/abc") t
  (portable-abs-path-p "cd5:/abc") t)

(mtest
  (pure-rel-path-p "") t
  (pure-rel-path-p "/") nil
  (pure-rel-path-p "\\") nil
  (pure-rel-path-p "/abc") nil
  (pure-rel-path-p ".") nil
  (pure-rel-path-p "./") nil
  (pure-rel-path-p ".\\") nil
  (pure-rel-path-p ".abc") t
  (pure-rel-path-p ".abc/") t
  (pure-rel-path-p ".abc\\") t
  (pure-rel-path-p ":") t
  (pure-rel-path-p "a:") nil
  (pure-rel-path-p "A:") nil
  (pure-rel-path-p "0:") nil
  (pure-rel-path-p "9:") nil
  (pure-rel-path-p "_:") t
  (pure-rel-path-p "abc") t
  (pure-rel-path-p "abc/def") t
  (pure-rel-path-p "abc/.") t
  (pure-rel-path-p "abc\\def") t
  (pure-rel-path-p "abc\\.") t)

(mtest
  (trim-path-seps "") ""
  (trim-path-seps "/") "/"
  (trim-path-seps "//") "/"
  (trim-path-seps "///") "/"
  (trim-path-seps "a///") "a"
  (trim-path-seps "/a///") "/a")

(mtest
  (trim-path-seps "c:/") "c:/"
  (trim-path-seps "c://") "c:/"
  (trim-path-seps "c:///") "c:/"
  (trim-path-seps "c:a///") "c:a"
  (trim-path-seps "/c:/a///") "/c:/a"
  (trim-path-seps "/c://///") "/c:")

(mtest
  (trim-path-seps "\\") "\\"
  (trim-path-seps "\\\\") "\\"
  (trim-path-seps "\\\\\\") "\\"
  (trim-path-seps "a\\\\\\") "a"
  (trim-path-seps "\\a\\\\\\") "\\a")

(mtest
  (trim-path-seps "c:\\") "c:\\"
  (trim-path-seps "c:\\\\") "c:\\"
  (trim-path-seps "c:\\\\\\") "c:\\"
  (trim-path-seps "c:a\\\\\\") "c:a"
  (trim-path-seps "\\c:\\a\\\\\\") "\\c:\\a"
  (trim-path-seps "\\c:\\\\\\\\\\") "\\c:")

(mtest
  (trim-path-seps "/c:\\") "/c:"
  (trim-path-seps "c:/\\/\\/") "c:/"
  (trim-path-seps "c:a\\\\\\") "c:a"
  (trim-path-seps "\\c:\\a/\\\\\\") "\\c:\\a"
  (trim-path-seps "/c:\\\\\\\\\\") "/c:")