]> gitweb.factorcode.org Git - factor.git/blob - core/io/pathnames/pathnames-tests.factor
vocabs.loader: fix vocab:path to use an existing path
[factor.git] / core / io / pathnames / pathnames-tests.factor
1 USING: io.backend io.directories io.files.private io.pathnames
2 kernel math namespaces sequences system tools.test vocabs.loader ;
3
4 { "passwd" } [ "/etc/passwd" file-name ] unit-test
5 { "awk" } [ "/usr/libexec/awk/" file-name ] unit-test
6 { "awk" } [ "/usr/libexec/awk///" file-name ] unit-test
7 { "" } [ "" file-name ] unit-test
8
9 { "freetype6.dll" } [ "resource:freetype6.dll" file-name ] unit-test
10 { "freetype6.dll" } [ "resource:/freetype6.dll" file-name ] unit-test
11
12 { "/usr/lib" } [ "/usr" "lib" append-path ] unit-test
13 { "/usr/lib" } [ "/usr/" "lib" append-path ] unit-test
14 { "/usr/lib" } [ "/usr" "./lib" append-path ] unit-test
15 { "/usr/lib/" } [ "/usr" "./lib/" append-path ] unit-test
16 { "/lib" } [ "/usr" "../lib" append-path ] unit-test
17 { "/lib/" } [ "/usr" "../lib/" append-path ] unit-test
18
19 { "" } [ "" "." append-path ] unit-test
20 [ "" ".." append-path ] must-fail
21
22 { "/" } [ "/" "./." append-path ] unit-test
23 { "/" } [ "/" "././" append-path ] unit-test
24 { "/a/b/lib" } [ "/a/b/c/d/e/f/" "../../../../lib" append-path ] unit-test
25 { "/a/b/lib/" } [ "/a/b/c/d/e/f/" "../../../../lib/" append-path ] unit-test
26
27 [ "" "../lib/" append-path ] must-fail
28 { "lib" } [ "" "lib" append-path ] unit-test
29 { "lib" } [ "" "./lib" append-path ] unit-test
30
31 [ "foo/bar/." parent-directory ] must-fail
32 [ "foo/bar/./" parent-directory ] must-fail
33 [ "foo/bar/baz/.." parent-directory ] must-fail
34 [ "foo/bar/baz/../" parent-directory ] must-fail
35
36 [ "." parent-directory ] must-fail
37 [ "./" parent-directory ] must-fail
38 [ ".." parent-directory ] must-fail
39 [ "../" parent-directory ] must-fail
40 [ "../../" parent-directory ] must-fail
41 [ "foo/.." parent-directory ] must-fail
42 [ "foo/../" parent-directory ] must-fail
43 [ "" parent-directory ] must-fail
44 { "." } [ "boot.x86.64.image" parent-directory ] unit-test
45
46 { "bar/foo" } [ "bar/baz" "..///foo" append-path ] unit-test
47 { "bar/baz/foo" } [ "bar/baz" ".///foo" append-path ] unit-test
48 { "bar/foo" } [ "bar/baz" "./..//foo" append-path ] unit-test
49 { "bar/foo" } [ "bar/baz" "./../././././././///foo" append-path ] unit-test
50
51 { t } [ "resource:core" absolute-path? ] unit-test
52 { f } [ "" absolute-path? ] unit-test
53
54 [| path |
55     { } [ 2 [ path touch-file ] times ] unit-test
56 ] with-test-file
57
58 ! aum's bug
59 H{
60     { current-directory "." }
61     { "resource-path" ".." }
62 } [
63     [ "../core/bootstrap/stage2.factor" ]
64     [ "resource:core/bootstrap/stage2.factor" absolute-path ]
65     unit-test
66 ] with-variables
67
68 { t } [ cwd "misc" resource-path [ ] with-directory cwd = ] unit-test
69
70 ! Regression test for bug in file-extension
71 { f } [ "/funny.directory/file-with-no-extension" file-extension ] unit-test
72 { "" } [ "/funny.directory/file-with-no-extension." file-extension ] unit-test
73
74 ! Testing ~ special pathname
75 { t } [ os windows? "~\\" "~/" ? absolute-path home = ] unit-test
76 { t } [ "~/" home [ normalize-path ] same? ] unit-test
77
78 { t } [ "~" absolute-path home = ] unit-test
79 { t } [ "~" home [ normalize-path ] same? ] unit-test
80
81 { t } [ "~" home [ "foo" append-path ] bi@ [ normalize-path ] same? ] unit-test
82 { t } [ os windows? "~\\~/" "~/~/" ? "~" "~" append-path [ path-components ] same? ] unit-test
83
84 ! Absolute paths
85 os windows? [
86     { "c:/" } [ "c:/" canonicalize-path ] unit-test
87     { "c:/" } [ "c:/." canonicalize-path ] unit-test
88     { "c:/" } [ "c:/.." canonicalize-path ] unit-test
89     { "c:/" } [ "c:/Users/.." canonicalize-path ] unit-test
90     { "c:/" } [ "c:/Users/../" canonicalize-path ] unit-test
91     { "c:/" } [ "c:/Users/../." canonicalize-path ] unit-test
92     { "c:/" } [ "c:/Users/.././" canonicalize-path ] unit-test
93     { "c:/" } [ "c:/Users/.././././././" canonicalize-path ] unit-test
94     { "c:/" } [ "c:/Users/../././/////./././/././././//././././././." canonicalize-path ] unit-test
95     { "c:/" } [ "c:/Users/../../../..////.././././././/../" canonicalize-path ] unit-test
96     { "c:/Users" } [ "c:/Users/../../../Users" canonicalize-path ] unit-test
97
98     { "c:/Users" } [ "c:/Users" canonicalize-path ] unit-test
99     { "c:/Users" } [ "c:/Users/." canonicalize-path ] unit-test
100     { "c:/Users\\foo\\bar" } [ "c:/Users/foo/bar" canonicalize-path ] unit-test
101 ] [
102     { "/" } [ "/" canonicalize-path ] unit-test
103     { "/" } [ "/." canonicalize-path ] unit-test
104     { "/" } [ "/.." canonicalize-path ] unit-test
105     { "/" } [ "/Users/.." canonicalize-path ] unit-test
106     { "/" } [ "/Users/../" canonicalize-path ] unit-test
107     { "/" } [ "/Users/../." canonicalize-path ] unit-test
108     { "/" } [ "/Users/.././" canonicalize-path ] unit-test
109     { "/" } [ "/Users/.././././././" canonicalize-path ] unit-test
110     { "/" } [ "/Users/../././/////./././/././././//././././././." canonicalize-path ] unit-test
111     { "/" } [ "/Users/../../../..////.././././././/../" canonicalize-path ] unit-test
112     { "/Users" } [ "/Users/../../../Users" canonicalize-path ] unit-test
113
114     { "/Users" } [ "/Users" canonicalize-path ] unit-test
115     { "/Users" } [ "/Users/." canonicalize-path ] unit-test
116     { "/Users/foo/bar" } [ "/Users/foo/bar" canonicalize-path ] unit-test
117 ] if
118
119
120 ! Relative paths
121 { "." } [ f canonicalize-path ] unit-test
122 { "." } [ "" canonicalize-path ] unit-test
123 { "." } [ "." canonicalize-path ] unit-test
124 { "." } [ "./" canonicalize-path ] unit-test
125 { "." } [ "./." canonicalize-path ] unit-test
126 { ".." } [ ".." canonicalize-path ] unit-test
127 { ".." } [ "../" canonicalize-path ] unit-test
128 { ".." } [ "../." canonicalize-path ] unit-test
129 { ".." } [ ".././././././//." canonicalize-path ] unit-test
130
131 { t } [ "../.." canonicalize-path { "../.." "..\\.." } member? ] unit-test
132 { t } [ "../../" canonicalize-path { "../.." "..\\.." } member? ] unit-test
133 { t } [ "../.././././/./././" canonicalize-path { "../.." "..\\.." } member? ] unit-test
134
135
136 ! Root paths
137 os windows? [
138     { "d:\\" } [ "d:\\" root-path ] unit-test
139     { "d:\\" } [ "d:\\\\\\\\//////" root-path ] unit-test
140     { "c:\\" } [ "c:\\Users\\merlen" root-path ] unit-test
141     { "c:\\" } [ "c:\\\\\\//Users//\\//merlen//" root-path ] unit-test
142     { "d:\\" } [ "d:\\././././././/../../../" root-path ] unit-test
143     { "d:\\" } [ "d:\\merlen\\dog" root-path ] unit-test
144
145     { "d:\\" } [ "\\\\?\\d:\\" root-path ] unit-test
146     { "d:\\" } [ "\\\\?\\d:\\\\\\\\//////" root-path ] unit-test
147     { "c:\\" } [ "\\\\?\\c:\\Users\\merlen" root-path ] unit-test
148     { "c:\\" } [ "\\\\?\\c:\\\\\\//Users//\\//merlen//" root-path ] unit-test
149     { "d:\\" } [ "\\\\?\\d:\\././././././/../../../" root-path ] unit-test
150     { "d:\\" } [ "\\\\?\\d:\\merlen\\dog" root-path ] unit-test
151 ] [
152     { "/" } [ "/" root-path ] unit-test
153     { "/" } [ "//" root-path ] unit-test
154     { "/" } [ "/Users" root-path ] unit-test
155     { "/" } [ "//Users" root-path ] unit-test
156     { "/" } [ "/Users/foo/bar////././." root-path ] unit-test
157     { "/" } [ "/Users/foo/bar////.//../../../../../../////./." root-path ] unit-test
158     { "/" } [ "/Users/////" root-path ] unit-test
159 ] if
160
161 { t } [ "." has-file-extension? ] unit-test
162 { t } [ ".." has-file-extension? ] unit-test
163 { t } [ "a.b" has-file-extension? ] unit-test
164 { f } [ "a/" has-file-extension? ] unit-test
165 { f } [ "a.b/" has-file-extension? ] unit-test
166 { t } [ "math.factor" has-file-extension? ] unit-test
167 { t } [ "math." has-file-extension? ] unit-test
168 { f } [ "math" has-file-extension? ] unit-test
169
170 { "resource:core/math" } [ "math" vocab-path ] unit-test
171 { "resource:core/math/" } [ "math/" vocab-path ] unit-test
172
173 [ "math.omg" vocab-path ] [ not-found-in-roots? ] must-fail-with
174 [ "math.omg/" vocab-path ] [ not-found-in-roots? ] must-fail-with
175 [ "accessors" vocab-path ] [ not-found-in-roots? ] must-fail-with
176 [ "asdfasdfasdfasfd1231231" vocab-path ] [ not-found-in-roots? ] must-fail-with
177 [ "resource:extra/benchmark/sum-file/sum-file.txt/" vocab-path ]
178 [ not-found-in-roots? ] must-fail-with
179
180 { "resource:extra/benchmark/sum-file/sum-file.txt" }
181 [ "benchmark/sum-file/sum-file.txt" vocab-path ] unit-test
182
183 { "resource:extra/benchmark/sum-file" }
184 [ "benchmark/sum-file" vocab-path ] unit-test
185
186 { "resource:extra/benchmark/sum-file/" }
187 [ "benchmark/sum-file/" vocab-path ] unit-test
188
189 ! Would be a core/ path except the path already exists in basis
190 { "resource:basis/bootstrap/finish-bootstrap.factor" }
191 [ "bootstrap/finish-bootstrap.factor" vocab-path ] unit-test