-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfilepath-test.scm
62 lines (53 loc) · 1.71 KB
/
filepath-test.scm
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
(import
(only (chicken process-context) current-directory)
(distill filepath))
(include "test-helpers.scm")
(test* eq? string-prefix?
((#t "pre" "prefix")
(#t "pre" "pre")
(#f "pre" "pr")
(#t "" "anything")
(#f "anything" "")))
(test* eq? string-suffix?
((#t "fix" "prefix")
(#f "ref" "prefix")
(#t "fix" "fix")
(#t "" "anything")
(#f "anything" "")))
(test* string=? filepath-join
(("a/b/c" "a/b/c")
("a/b/c" "a/b/c/")
("a/b/c" "a" "b" "c")
("/a/b/c" "/a/b/c")
("/b/c" "/a/" "../b" "./c")
("/a/b/c" "/a" "./b/" "./c")
("a/b/c/d" "a/b" "c/d")
("foo/bar" "foo" "baz" ".." "bar")))
(test string=? (current-directory) (abspath "."))
(test string=? (filepath-join (current-directory) "foo") (abspath "./foo"))
(test* string=? dirname
(("/foo" "/foo/bar.txt")
("/foo/bar/baz" "/foo/bar/baz/")
("/foo/bar" "/foo/bar/baz.txt")
("." "foo")
("/" "/")
("/" "/foo")))
(test* string=? basename
(("foo" "/foo")
("bar.txt" "/foo/bar.txt")
("foo" "foo")
("." ".")
("" "/")
("" "/foo/bar/")))
(let ((rdir (folddir cons '() (current-directory))))
(test eq? #t
(let loop ((head (car rdir))
(rest (cdr rdir)))
(or (null? rest)
(and
(string<? (car rest) head)
(loop (car rest) (cdr rest)))))))
;; hopefully this is the case?
(test string=? "/bin/sh" (pathfind "sh"))
;; ... and hopefully this isn't the case
(test eq? #f (pathfind "really!not!a!program"))