3 class TestPath < Test::Unit::TestCase
5 assert_equal("a", File.basename("a"))
6 assert_equal("b", File.basename("a/b"))
7 assert_equal("b", File.basename("a/b/"))
8 assert_equal("/", File.basename("/"))
9 assert_equal("/", File.basename("//"))
10 assert_equal("/", File.basename("///"))
11 assert_equal("b", File.basename("a/b////"))
12 assert_equal("a", File.basename("a.rb", ".rb"))
13 assert_equal("a", File.basename("a.rb///", ".rb"))
14 assert_equal("a", File.basename("a.rb///", ".*"))
15 assert_equal("a.rb", File.basename("a.rb///", ".c"))
16 assert_equal(".", File.dirname("a"))
17 assert_equal("/", File.dirname("/"))
18 assert_equal("/", File.dirname("/a"))
19 assert_equal("a", File.dirname("a/b"))
20 assert_equal("a/b", File.dirname("a/b/c"))
21 assert_equal("/a/b", File.dirname("/a/b/c"))
22 assert_equal("/a", File.dirname("/a/b/"))
23 assert_equal("/a", File.dirname("/a/b///"))
26 assert_match(/\A\w:\/\z/, File.expand_path(".", "/"))
27 assert_match(/\A\w:\/a\z/, File.expand_path("a", "/"))
30 assert_match(%r'\A//[^/]+/[^/]+\z', File.expand_path(".", "/"))
31 assert_match(%r'\A//[^/]+/[^/]+/a\z', File.expand_path(".", "/"))
34 assert_equal("/", File.expand_path(".", "/"))
35 assert_equal("/sub", File.expand_path("sub", "/"))
38 assert_equal("//machine/share", File.expand_path("/", "//machine/share/sub"))
39 assert_equal("//machine/share/dir", File.expand_path("/dir", "//machine/share/sub"))
40 assert_equal("z:/", File.expand_path("/", "z:/sub"))
41 assert_equal("z:/dir", File.expand_path("/dir", "z:/sub"))
43 assert_equal("//", File.expand_path(".", "//"))
44 assert_equal("//sub", File.expand_path("sub", "//"))
48 if /(bcc|ms)win\d|mingw|cygwin|djgpp|human|emx/ =~ RUBY_PLATFORM
50 assert_equal('C:.', File.dirname('C:'))
51 assert_equal('C:.', File.dirname('C:a'))
52 assert_equal('C:.', File.dirname('C:a/'))
53 assert_equal('C:a', File.dirname('C:a/b'), "[ruby-dev:27738]")
55 assert_equal('C:/', File.dirname('C:/'))
56 assert_equal('C:/', File.dirname('C:/a'))
57 assert_equal('C:/', File.dirname('C:/a/'))
58 assert_equal('C:/a', File.dirname('C:/a/b'))
60 assert_equal('C:/', File.dirname('C://'))
61 assert_equal('C:/', File.dirname('C://a'))
62 assert_equal('C:/', File.dirname('C://a/'))
63 assert_equal('C:/a', File.dirname('C://a/b'))
65 assert_equal('C:/', File.dirname('C:///'), "[ruby-dev:27738]")
66 assert_equal('C:/', File.dirname('C:///a'))
67 assert_equal('C:/', File.dirname('C:///a/'))
68 assert_equal('C:/a', File.dirname('C:///a/b'))
71 assert_equal('.', File.dirname('C:'))
72 assert_equal('.', File.dirname('C:a'))
73 assert_equal('.', File.dirname('C:a/'))
74 assert_equal('C:a', File.dirname('C:a/b'))
76 assert_equal('.', File.dirname('C:/'))
77 assert_equal('C:', File.dirname('C:/a'))
78 assert_equal('C:', File.dirname('C:/a/'))
79 assert_equal('C:/a', File.dirname('C:/a/b'))
81 assert_equal('.', File.dirname('C://'))
82 assert_equal('C:', File.dirname('C://a'))
83 assert_equal('C:', File.dirname('C://a/'))
85 #assert_equal('C://a', File.dirname('C://a/b'))
87 assert_equal('.', File.dirname('C:///'))
88 assert_equal('C:', File.dirname('C:///a'))
89 assert_equal('C:', File.dirname('C:///a/'))
91 #assert_equal('C:///a', File.dirname('C:///a/b'))
94 assert_equal('.', File.dirname(''))
95 assert_equal('.', File.dirname('a'))
96 assert_equal('.', File.dirname('a/'))
97 assert_equal('a', File.dirname('a/b'))
99 assert_equal('/', File.dirname('/'))
100 assert_equal('/', File.dirname('/a'))
101 assert_equal('/', File.dirname('/a/'))
102 assert_equal('/a', File.dirname('/a/b'))
104 if /(bcc|ms|cyg)win|mingw|djgpp|human|emx/ =~ RUBY_PLATFORM
106 assert_equal('//', File.dirname('//'))
107 assert_equal('//a', File.dirname('//a'))
108 assert_equal('//a', File.dirname('//a/'))
109 assert_equal('//a/b', File.dirname('//a/b'))
110 assert_equal('//a/b', File.dirname('//a/b/'))
111 assert_equal('//a/b', File.dirname('//a/b/c'))
113 assert_equal('//', File.dirname('///'))
114 assert_equal('//a', File.dirname('///a'))
115 assert_equal('//a', File.dirname('///a/'))
116 assert_equal('//a/b', File.dirname('///a/b'))
117 assert_equal('//a/b', File.dirname('///a/b/'))
118 assert_equal('//a/b', File.dirname('///a/b/c'))
121 assert_equal('/', File.dirname('//'))
122 assert_equal('/', File.dirname('//a'))
123 assert_equal('/', File.dirname('//a/'))
124 assert_equal('/a', File.dirname('//a/b'))
125 assert_equal('/a', File.dirname('//a/b/'))
126 assert_equal('/a/b', File.dirname('//a/b/c'))
128 assert_equal('/', File.dirname('///'))
129 assert_equal('/', File.dirname('///a'))
130 assert_equal('/', File.dirname('///a/'))
131 assert_equal('/a', File.dirname('///a/b'))
132 assert_equal('/a', File.dirname('///a/b/'))
133 assert_equal('/a/b', File.dirname('///a/b/c'))
138 if /(bcc|ms)win\d|mingw|cygwin|djgpp|human|emx/ =~ RUBY_PLATFORM
139 # DOSISH_DRIVE_LETTER
140 assert_equal('', File.basename('C:'))
141 assert_equal('a', File.basename('C:a'))
142 assert_equal('a', File.basename('C:a/'))
143 assert_equal('b', File.basename('C:a/b'))
145 assert_equal('/', File.basename('C:/'))
146 assert_equal('a', File.basename('C:/a'))
147 assert_equal('a', File.basename('C:/a/'))
148 assert_equal('b', File.basename('C:/a/b'))
150 assert_equal('/', File.basename('C://'))
151 assert_equal('a', File.basename('C://a'))
152 assert_equal('a', File.basename('C://a/'))
153 assert_equal('b', File.basename('C://a/b'))
155 assert_equal('/', File.basename('C:///'))
156 assert_equal('a', File.basename('C:///a'))
157 assert_equal('a', File.basename('C:///a/'))
158 assert_equal('b', File.basename('C:///a/b'))
161 assert_equal('C:', File.basename('C:'))
162 assert_equal('C:a', File.basename('C:a'))
163 assert_equal('C:a', File.basename('C:a/'))
164 assert_equal('b', File.basename('C:a/b'))
166 assert_equal('C:', File.basename('C:/'))
167 assert_equal('a', File.basename('C:/a'))
168 assert_equal('a', File.basename('C:/a/'))
169 assert_equal('b', File.basename('C:/a/b'))
171 assert_equal('C:', File.basename('C://'))
172 assert_equal('a', File.basename('C://a'))
173 assert_equal('a', File.basename('C://a/'))
174 assert_equal('b', File.basename('C://a/b'))
176 assert_equal('C:', File.basename('C:///'))
177 assert_equal('a', File.basename('C:///a'))
178 assert_equal('a', File.basename('C:///a/'))
179 assert_equal('b', File.basename('C:///a/b'))
182 assert_equal('', File.basename(''))
183 assert_equal('a', File.basename('a'))
184 assert_equal('a', File.basename('a/'))
185 assert_equal('b', File.basename('a/b'))
187 assert_equal('/', File.basename('/'))
188 assert_equal('a', File.basename('/a'))
189 assert_equal('a', File.basename('/a/'))
190 assert_equal('b', File.basename('/a/b'))
192 if /(bcc|ms|cyg)win|mingw|djgpp|human|emx/ =~ RUBY_PLATFORM
194 assert_equal('/', File.basename('//'))
195 assert_equal('/', File.basename('//a'))
196 assert_equal('/', File.basename('//a/'))
197 assert_equal('/', File.basename('//a/b'), "[ruby-dev:27776]")
198 assert_equal('/', File.basename('//a/b/'))
199 assert_equal('c', File.basename('//a/b/c'))
201 assert_equal('/', File.basename('///'))
202 assert_equal('/', File.basename('///a'))
203 assert_equal('/', File.basename('///a/'))
204 assert_equal('/', File.basename('///a/b'))
205 assert_equal('/', File.basename('///a/b/'))
206 assert_equal('c', File.basename('///a/b/c'))
209 assert_equal('/', File.basename('//'))
210 assert_equal('a', File.basename('//a'))
211 assert_equal('a', File.basename('//a/'))
212 assert_equal('b', File.basename('//a/b'))
213 assert_equal('b', File.basename('//a/b/'))
214 assert_equal('c', File.basename('//a/b/c'))
216 assert_equal('/', File.basename('///'))
217 assert_equal('a', File.basename('///a'))
218 assert_equal('a', File.basename('///a/'))
219 assert_equal('b', File.basename('///a/b'))
220 assert_equal('b', File.basename('///a/b/'))
221 assert_equal('c', File.basename('///a/b/c'))