pathname2 1.6.3-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +120 -0
- data/MANIFEST +11 -0
- data/README +109 -0
- data/Rakefile +41 -0
- data/benchmarks/bench_pathname.rb +127 -0
- data/benchmarks/bench_plus.rb +34 -0
- data/examples/example_pathname.rb +25 -0
- data/lib/pathname2.rb +1108 -0
- data/pathname2.gemspec +37 -0
- data/test/test_pathname.rb +484 -0
- data/test/test_pathname_windows.rb +666 -0
- metadata +96 -0
@@ -0,0 +1,666 @@
|
|
1
|
+
##########################################################################
|
2
|
+
# test_pathname_win.rb
|
3
|
+
#
|
4
|
+
# MS Windows test suite for the Pathname class. To test explicitly
|
5
|
+
# against the C extension pass the letter 'c' as an argument. You should
|
6
|
+
# use the 'rake test' task to run this test suite.
|
7
|
+
###########################################################################
|
8
|
+
require 'facade'
|
9
|
+
require 'pathname2'
|
10
|
+
require 'test/unit'
|
11
|
+
|
12
|
+
class MyPathname < Pathname; end
|
13
|
+
|
14
|
+
class TC_Pathname_MSWin < Test::Unit::TestCase
|
15
|
+
|
16
|
+
def setup
|
17
|
+
@fpath = Pathname.new("C:/Program Files/Windows NT/Accessories")
|
18
|
+
@bpath = Pathname.new("C:\\Program Files\\Windows NT\\Accessories")
|
19
|
+
@dpath = Pathname.new("C:\\Program Files\\File[5].txt")
|
20
|
+
@spath = Pathname.new("C:\\PROGRA~1\\WINDOW~1\\ACCESS~1")
|
21
|
+
@upath = Pathname.new("\\\\foo\\bar\\baz")
|
22
|
+
@npath = Pathname.new("foo\\bar\\baz")
|
23
|
+
@rpath = Pathname.new("Z:\\")
|
24
|
+
@xpath = Pathname.new("\\\\foo\\bar")
|
25
|
+
@ypath = Pathname.new("\\\\foo")
|
26
|
+
@zpath = Pathname.new("\\\\")
|
27
|
+
@epath = Pathname.new("")
|
28
|
+
@ppath = Pathname.new("C:\\foo\\bar\\")
|
29
|
+
@cpath = Pathname.new("C:\\foo\\..\\bar\\.\\baz")
|
30
|
+
@tpath = Pathname.new("C:\\foo\\bar")
|
31
|
+
|
32
|
+
@url_path = Pathname.new("file:///C:/Documents%20and%20Settings")
|
33
|
+
@cur_path = Pathname.new(Dir.pwd)
|
34
|
+
|
35
|
+
@mypath = MyPathname.new("C:\\Program Files")
|
36
|
+
|
37
|
+
@abs_array = []
|
38
|
+
@rel_array = []
|
39
|
+
@unc_array = []
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_aref_with_range
|
43
|
+
assert_equal("C:\\Program Files", @fpath[0..1])
|
44
|
+
assert_equal("C:\\Program Files\\Windows NT", @fpath[0..2])
|
45
|
+
assert_equal("Program Files\\Windows NT", @fpath[1..2])
|
46
|
+
assert_equal(@fpath, @fpath[0..-1])
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_aref_with_index_and_length
|
50
|
+
assert_equal("C:", @fpath[0,1])
|
51
|
+
assert_equal("C:\\Program Files", @fpath[0,2])
|
52
|
+
assert_equal("Program Files\\Windows NT", @fpath[1,2])
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_aref_with_index
|
56
|
+
assert_equal("C:", @fpath[0])
|
57
|
+
assert_equal("Program Files", @fpath[1])
|
58
|
+
assert_equal("Accessories", @fpath[-1])
|
59
|
+
assert_equal(nil, @fpath[10])
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_version
|
63
|
+
assert_equal('1.6.3', Pathname::VERSION)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Convenience method for test_plus
|
67
|
+
def assert_pathname_plus(a, b, c)
|
68
|
+
a = Pathname.new(a)
|
69
|
+
b = Pathname.new(b)
|
70
|
+
c = Pathname.new(c)
|
71
|
+
assert_equal(a, b + c)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Convenience method for test_spaceship operator
|
75
|
+
def assert_pathname_cmp(int, s1, s2)
|
76
|
+
p1 = Pathname.new(s1)
|
77
|
+
p2 = Pathname.new(s2)
|
78
|
+
result = p1 <=> p2
|
79
|
+
assert_equal(int, result)
|
80
|
+
end
|
81
|
+
|
82
|
+
# Convenience method for test_relative_path_from
|
83
|
+
def assert_relpath(result, dest, base)
|
84
|
+
assert_equal(result, Pathname.new(dest).relative_path_from(base))
|
85
|
+
end
|
86
|
+
|
87
|
+
# Convenience method for test_relative_path_from_expected_errors
|
88
|
+
def assert_relative_path_error(to, from)
|
89
|
+
assert_raise(ArgumentError) {
|
90
|
+
Pathname.new(to).relative_path_from(from)
|
91
|
+
}
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_file_urls
|
95
|
+
assert_equal("C:\\Documents and Settings", @url_path)
|
96
|
+
assert_raises(Pathname::Error){ Pathname.new('http://rubyforge.org') }
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_realpath
|
100
|
+
assert_respond_to(@fpath, :realpath)
|
101
|
+
assert_equal(@cur_path, Pathname.new('.').realpath)
|
102
|
+
assert_raises(Errno::ENOENT){ Pathname.new('../bogus').realpath }
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_relative_path_from
|
106
|
+
assert_relpath("..\\a", "a", "b")
|
107
|
+
assert_relpath("..\\a", "a", "b\\")
|
108
|
+
assert_relpath("..\\a", "a\\", "b")
|
109
|
+
assert_relpath("..\\a", "a\\", "b\\")
|
110
|
+
assert_relpath("..\\a", "c:\\a", "c:\\b")
|
111
|
+
assert_relpath("..\\a", "c:\\a", "c:\\b\\")
|
112
|
+
assert_relpath("..\\a", "c:\\a\\", "c:\\b")
|
113
|
+
assert_relpath("..\\a", "c:\\a\\", "c:\\b\\")
|
114
|
+
|
115
|
+
assert_relpath("..\\b", "a\\b", "a\\c")
|
116
|
+
assert_relpath("..\\a", "..\\a", "..\\b")
|
117
|
+
|
118
|
+
assert_relpath("a", "a", ".")
|
119
|
+
assert_relpath("..", ".", "a")
|
120
|
+
|
121
|
+
assert_relpath(".", ".", ".")
|
122
|
+
assert_relpath(".", "..", "..")
|
123
|
+
assert_relpath("..", "..", ".")
|
124
|
+
|
125
|
+
assert_relpath("c\\d", "c:\\a\\b\\c\\d", "c:\\a\\b")
|
126
|
+
assert_relpath("..\\..", "c:\\a\\b", "c:\\a\\b\\c\\d")
|
127
|
+
assert_relpath("..\\..\\..\\..\\e", "c:\\e", "c:\\a\\b\\c\\d")
|
128
|
+
assert_relpath("..\\b\\c", "a\\b\\c", "a\\d")
|
129
|
+
|
130
|
+
assert_relpath("..\\a", "c:\\..\\a", "c:\\b")
|
131
|
+
#assert_relpath("..\\..\\a", "..\\a", "b") # fails
|
132
|
+
assert_relpath(".", "c:\\a\\..\\..\\b", "c:\\b")
|
133
|
+
assert_relpath("..", "a\\..", "a")
|
134
|
+
assert_relpath(".", "a\\..\\b", "b")
|
135
|
+
|
136
|
+
assert_relpath("a", "a", "b\\..")
|
137
|
+
assert_relpath("b\\c", "b\\c", "b\\..")
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_relative_path_from_expected_errors
|
141
|
+
assert_relative_path_error("c:\\", ".")
|
142
|
+
assert_relative_path_error(".", "c:\\")
|
143
|
+
assert_relative_path_error("a", "..")
|
144
|
+
assert_relative_path_error(".", "..")
|
145
|
+
assert_relative_path_error("C:\\Temp", "D:\\Temp")
|
146
|
+
assert_relative_path_error("\\\\Server\\Temp", "D:\\Temp")
|
147
|
+
end
|
148
|
+
|
149
|
+
# Convenience method to verify that the receiver was not modified
|
150
|
+
# except perhaps slashes
|
151
|
+
def assert_non_destructive
|
152
|
+
assert_equal("C:\\Program Files\\Windows NT\\Accessories", @fpath)
|
153
|
+
assert_equal("C:\\Program Files\\Windows NT\\Accessories", @bpath)
|
154
|
+
assert_equal("C:\\Program Files\\File[5].txt", @dpath)
|
155
|
+
assert_equal("C:\\PROGRA~1\\WINDOW~1\\ACCESS~1", @spath)
|
156
|
+
assert_equal("\\\\foo\\bar\\baz", @upath)
|
157
|
+
assert_equal("foo\\bar\\baz", @npath)
|
158
|
+
assert_equal("Z:\\", @rpath)
|
159
|
+
assert_equal("\\\\foo\\bar", @xpath)
|
160
|
+
assert_equal("\\\\foo", @ypath)
|
161
|
+
assert_equal("\\\\", @zpath)
|
162
|
+
assert_equal("", @epath)
|
163
|
+
assert_equal("C:\\foo\\bar\\", @ppath)
|
164
|
+
assert_equal("C:\\foo\\..\\bar\\.\\baz", @cpath)
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_parent
|
168
|
+
assert_respond_to(@bpath, :parent)
|
169
|
+
assert_equal("C:\\Program Files\\Windows NT", @bpath.parent)
|
170
|
+
assert_equal("foo\\bar", @npath.parent)
|
171
|
+
assert_equal("Z:\\", @rpath.parent)
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_short_path
|
175
|
+
assert_respond_to(@bpath, :short_path)
|
176
|
+
assert_nothing_raised{ @bpath.short_path }
|
177
|
+
assert_kind_of(Pathname, @bpath.short_path)
|
178
|
+
assert_equal("C:\\PROGRA~1\\WINDOW~1\\ACCESS~1", @bpath.short_path)
|
179
|
+
|
180
|
+
assert_equal("C:\\Program Files\\Windows NT\\Accessories", @bpath)
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_long_path
|
184
|
+
assert_respond_to(@spath, :long_path)
|
185
|
+
assert_nothing_raised{ @spath.long_path }
|
186
|
+
assert_kind_of(Pathname, @spath.long_path)
|
187
|
+
|
188
|
+
assert_equal(
|
189
|
+
"C:\\Program Files\\Windows NT\\Accessories",
|
190
|
+
@spath.long_path
|
191
|
+
)
|
192
|
+
|
193
|
+
assert_equal("C:\\PROGRA~1\\WINDOW~1\\ACCESS~1", @spath)
|
194
|
+
end
|
195
|
+
|
196
|
+
def test_undecorate
|
197
|
+
assert_respond_to(@dpath, :undecorate)
|
198
|
+
assert_nothing_raised{ @dpath.undecorate }
|
199
|
+
assert_kind_of(Pathname, @dpath.undecorate)
|
200
|
+
|
201
|
+
assert_equal('C:\Program Files\File.txt', @dpath.undecorate)
|
202
|
+
assert_equal('C:\Path\File', Pathname.new('C:\Path\File').undecorate)
|
203
|
+
assert_equal('C:\Path\File', Pathname.new('C:\Path\File[12]').undecorate)
|
204
|
+
assert_equal('C:\Path\[3].txt',
|
205
|
+
Pathname.new('C:\Path\[3].txt').undecorate
|
206
|
+
)
|
207
|
+
assert_equal('\\foo\bar.txt',Pathname.new('\\foo\bar[5].txt').undecorate)
|
208
|
+
assert_equal('\\foo\bar', Pathname.new('\\foo\bar[5]').undecorate)
|
209
|
+
assert_equal('\\foo\bar', Pathname.new('\\foo\bar').undecorate)
|
210
|
+
|
211
|
+
assert_equal("C:\\Program Files\\File[5].txt", @dpath)
|
212
|
+
end
|
213
|
+
|
214
|
+
def test_undecorate_bang
|
215
|
+
assert_respond_to(@dpath, :undecorate!)
|
216
|
+
assert_nothing_raised{ @dpath.undecorate! }
|
217
|
+
assert_kind_of(Pathname, @dpath.undecorate!)
|
218
|
+
|
219
|
+
assert_equal('C:\Program Files\File.txt', @dpath.undecorate!)
|
220
|
+
assert_equal('C:\Path\File', Pathname.new('C:\Path\File').undecorate!)
|
221
|
+
assert_equal('C:\Path\File', Pathname.new('C:\Path\File[12]').undecorate!)
|
222
|
+
assert_equal('C:\Path\[3].txt',
|
223
|
+
Pathname.new('C:\Path\[3].txt').undecorate!
|
224
|
+
)
|
225
|
+
assert_equal('\\foo\bar.txt',Pathname.new('\\foo\bar[5].txt').undecorate!)
|
226
|
+
assert_equal('\\foo\bar', Pathname.new('\\foo\bar[5]').undecorate!)
|
227
|
+
assert_equal('\\foo\bar', Pathname.new('\\foo\bar').undecorate!)
|
228
|
+
|
229
|
+
assert_equal('C:\Program Files\File.txt', @dpath)
|
230
|
+
end
|
231
|
+
|
232
|
+
def test_unc
|
233
|
+
assert_respond_to(@upath, :unc?)
|
234
|
+
assert_nothing_raised{ @upath.unc? }
|
235
|
+
|
236
|
+
assert_equal(true, @upath.unc?)
|
237
|
+
assert_equal(true, @xpath.unc?)
|
238
|
+
assert_equal(true, @ypath.unc?)
|
239
|
+
assert_equal(true, @zpath.unc?)
|
240
|
+
assert_equal(false, @fpath.unc?)
|
241
|
+
assert_equal(false, @bpath.unc?)
|
242
|
+
assert_equal(false, @dpath.unc?)
|
243
|
+
assert_equal(false, @spath.unc?)
|
244
|
+
assert_equal(false, @epath.unc?)
|
245
|
+
|
246
|
+
# Arguably a bug in the PathIsUNC() function since drive letters
|
247
|
+
# are, in fact, a legal part of a UNC path (for historical reasons).
|
248
|
+
assert_equal(false, Pathname.new("C:\\\\foo\\bar\\baz").unc?)
|
249
|
+
|
250
|
+
assert_non_destructive
|
251
|
+
end
|
252
|
+
|
253
|
+
def test_pstrip
|
254
|
+
assert_respond_to(@ppath, :pstrip)
|
255
|
+
assert_nothing_raised{ @ppath.pstrip }
|
256
|
+
assert_nothing_raised{ @fpath.pstrip }
|
257
|
+
assert_kind_of(Pathname, @ppath.pstrip)
|
258
|
+
|
259
|
+
assert_equal('C:\foo', Pathname.new("C:\\foo\\").pstrip)
|
260
|
+
assert_equal('C:\foo', Pathname.new("C:\\foo").pstrip)
|
261
|
+
assert_equal("", Pathname.new("").pstrip)
|
262
|
+
|
263
|
+
assert_equal("C:\\foo\\bar\\", @ppath)
|
264
|
+
end
|
265
|
+
|
266
|
+
def test_pstrip_bang
|
267
|
+
assert_respond_to(@ppath, :pstrip!)
|
268
|
+
assert_nothing_raised{ @ppath.pstrip! }
|
269
|
+
assert_nothing_raised{ @fpath.pstrip! }
|
270
|
+
assert_kind_of(Pathname, @ppath.pstrip!)
|
271
|
+
|
272
|
+
assert_equal('C:\foo', Pathname.new("C:\\foo\\").pstrip!)
|
273
|
+
assert_equal('C:\foo', Pathname.new("C:\\foo").pstrip!)
|
274
|
+
assert_equal("", Pathname.new("").pstrip!)
|
275
|
+
|
276
|
+
assert_equal("C:\\foo\\bar", @ppath)
|
277
|
+
end
|
278
|
+
|
279
|
+
def test_exists
|
280
|
+
assert_respond_to(@fpath, :exists?)
|
281
|
+
assert_nothing_raised{ @fpath.exists? }
|
282
|
+
assert_equal(true, Pathname.new("C:\\").exists?)
|
283
|
+
assert_equal(false, Pathname.new("X:\\foo\\bar\\baz").exists?)
|
284
|
+
end
|
285
|
+
|
286
|
+
def test_each
|
287
|
+
array = []
|
288
|
+
|
289
|
+
assert_respond_to(@fpath, :each)
|
290
|
+
assert_nothing_raised{ @fpath.each{ |e| array.push(e) } }
|
291
|
+
assert_equal(["C:", "Program Files", "Windows NT", "Accessories"], array)
|
292
|
+
end
|
293
|
+
|
294
|
+
def test_descend
|
295
|
+
assert_respond_to(@bpath, :descend)
|
296
|
+
assert_nothing_raised{ @bpath.descend{} }
|
297
|
+
|
298
|
+
@bpath.descend{ |path| @abs_array.push(path) }
|
299
|
+
@npath.descend{ |path| @rel_array.push(path) }
|
300
|
+
@upath.descend{ |path| @unc_array.push(path) }
|
301
|
+
|
302
|
+
assert_equal("C:", @abs_array[0])
|
303
|
+
assert_equal("C:\\Program Files", @abs_array[1])
|
304
|
+
assert_equal("C:\\Program Files\\Windows NT", @abs_array[2])
|
305
|
+
assert_equal("C:\\Program Files\\Windows NT\\Accessories", @abs_array[3])
|
306
|
+
|
307
|
+
assert_equal("foo", @rel_array[0])
|
308
|
+
assert_equal("foo\\bar", @rel_array[1])
|
309
|
+
assert_equal("foo\\bar\\baz", @rel_array[2])
|
310
|
+
|
311
|
+
assert_equal("\\\\foo\\bar", @unc_array[0])
|
312
|
+
assert_equal("\\\\foo\\bar\\baz", @unc_array[1])
|
313
|
+
|
314
|
+
assert_non_destructive
|
315
|
+
end
|
316
|
+
|
317
|
+
def test_ascend
|
318
|
+
assert_respond_to(@bpath, :ascend)
|
319
|
+
assert_nothing_raised{ @bpath.ascend{} }
|
320
|
+
|
321
|
+
@bpath.ascend{ |path| @abs_array.push(path) }
|
322
|
+
@npath.ascend{ |path| @rel_array.push(path) }
|
323
|
+
@upath.ascend{ |path| @unc_array.push(path) }
|
324
|
+
|
325
|
+
assert_equal("C:\\Program Files\\Windows NT\\Accessories", @abs_array[0])
|
326
|
+
assert_equal("C:\\Program Files\\Windows NT", @abs_array[1])
|
327
|
+
assert_equal("C:\\Program Files", @abs_array[2])
|
328
|
+
assert_equal("C:", @abs_array[3])
|
329
|
+
assert_equal(4, @abs_array.length)
|
330
|
+
|
331
|
+
assert_equal("foo\\bar\\baz", @rel_array[0])
|
332
|
+
assert_equal("foo\\bar", @rel_array[1])
|
333
|
+
assert_equal("foo", @rel_array[2])
|
334
|
+
assert_equal(3, @rel_array.length)
|
335
|
+
|
336
|
+
assert_equal("\\\\foo\\bar\\baz", @unc_array[0])
|
337
|
+
assert_equal("\\\\foo\\bar", @unc_array[1])
|
338
|
+
assert_equal(2, @unc_array.length)
|
339
|
+
|
340
|
+
assert_non_destructive
|
341
|
+
end
|
342
|
+
|
343
|
+
def test_immutability
|
344
|
+
path = "C:\\Program Files\\foo\\bar".freeze
|
345
|
+
assert_equal(true, path.frozen?)
|
346
|
+
assert_nothing_raised{ Pathname.new(path) }
|
347
|
+
assert_nothing_raised{ Pathname.new(path).root }
|
348
|
+
end
|
349
|
+
|
350
|
+
def test_plus_operator
|
351
|
+
# Standard stuff
|
352
|
+
assert_pathname_plus("C:\\a\\b", "C:\\a", "b")
|
353
|
+
assert_pathname_plus("C:\\b", "a", "C:\\b")
|
354
|
+
assert_pathname_plus("a\\b", "a", "b")
|
355
|
+
assert_pathname_plus("C:\\b", "C:\\a", "..\\b")
|
356
|
+
assert_pathname_plus("C:\\a\\b", "C:\\a\\.", "\\b")
|
357
|
+
assert_pathname_plus("C:\\a\\b.txt", "C:\\a", "b.txt")
|
358
|
+
|
359
|
+
# UNC paths
|
360
|
+
assert_pathname_plus("\\\\foo\\bar", "\\\\foo", "bar")
|
361
|
+
assert_pathname_plus("\\\\foo", "\\\\", "foo")
|
362
|
+
assert_pathname_plus("\\\\", "\\\\", "")
|
363
|
+
assert_pathname_plus("\\\\foo\\baz", "\\\\foo\\bar", "\\..\\baz")
|
364
|
+
assert_pathname_plus("\\\\", "\\\\", "..\\..\\..\\..")
|
365
|
+
|
366
|
+
# Pathname + String
|
367
|
+
assert_nothing_raised{ @tpath + "bar" }
|
368
|
+
assert_equal('C:\foo\bar\baz', @tpath + 'baz')
|
369
|
+
assert_equal('C:\foo\bar', @tpath)
|
370
|
+
|
371
|
+
# Ensure neither left nor right operand are modified
|
372
|
+
assert_nothing_raised{ @tpath + @npath }
|
373
|
+
assert_equal('C:\foo\bar\foo\bar\baz', @tpath + @npath)
|
374
|
+
assert_equal('C:\foo\bar', @tpath)
|
375
|
+
assert_equal('foo\bar\baz', @npath)
|
376
|
+
end
|
377
|
+
|
378
|
+
def test_clean
|
379
|
+
assert_respond_to(@cpath, :clean)
|
380
|
+
assert_nothing_raised{ @cpath.clean }
|
381
|
+
assert_kind_of(Pathname, @cpath.clean)
|
382
|
+
|
383
|
+
# Our preset stuff
|
384
|
+
assert_equal("C:\\Program Files\\Windows NT\\Accessories", @fpath.clean)
|
385
|
+
assert_equal("C:\\Program Files\\Windows NT\\Accessories", @bpath.clean)
|
386
|
+
assert_equal("\\\\foo\\bar\\baz", @upath.clean)
|
387
|
+
assert_equal("foo\\bar\\baz", @npath.clean)
|
388
|
+
assert_equal("Z:\\", @rpath.clean)
|
389
|
+
assert_equal("\\\\foo\\bar", @xpath.clean)
|
390
|
+
assert_equal("\\\\foo", @ypath.clean)
|
391
|
+
assert_equal("\\\\", @zpath.clean)
|
392
|
+
assert_equal("", @epath.clean)
|
393
|
+
assert_equal("C:\\bar\\baz", @cpath.clean)
|
394
|
+
|
395
|
+
# Standard stuff
|
396
|
+
assert_equal("C:\\a\\c", Pathname.new("C:\\a\\.\\b\\..\\c").clean)
|
397
|
+
assert_equal("C:\\a", Pathname.new("C:\\.\\a").clean)
|
398
|
+
assert_equal("C:\\a\\b", Pathname.new("C:\\a\\.\\b").clean)
|
399
|
+
assert_equal("C:\\b", Pathname.new("C:\\a\\..\\b").clean)
|
400
|
+
assert_equal("C:\\a", Pathname.new("C:\\a\\.").clean)
|
401
|
+
assert_equal("C:\\d", Pathname.new("C:\\..\\..\\..\\d").clean)
|
402
|
+
assert_equal("C:\\a\\", Pathname.new("C:\\a\\").clean)
|
403
|
+
|
404
|
+
# Edge cases
|
405
|
+
assert_equal("\\", Pathname.new(".").clean)
|
406
|
+
assert_equal("\\", Pathname.new("..").clean)
|
407
|
+
|
408
|
+
assert_non_destructive
|
409
|
+
end
|
410
|
+
|
411
|
+
def test_clean_bang
|
412
|
+
assert_respond_to(@cpath, :clean!)
|
413
|
+
assert_nothing_raised{ @cpath.clean! }
|
414
|
+
assert_kind_of(Pathname, @cpath.clean!)
|
415
|
+
|
416
|
+
# Our preset stuff
|
417
|
+
assert_equal("C:\\Program Files\\Windows NT\\Accessories", @fpath.clean!)
|
418
|
+
assert_equal("C:\\Program Files\\Windows NT\\Accessories", @bpath.clean!)
|
419
|
+
assert_equal("\\\\foo\\bar\\baz", @upath.clean!)
|
420
|
+
assert_equal("foo\\bar\\baz", @npath.clean!)
|
421
|
+
assert_equal("Z:\\", @rpath.clean!)
|
422
|
+
assert_equal("\\\\foo\\bar", @xpath.clean!)
|
423
|
+
assert_equal("\\\\foo", @ypath.clean!)
|
424
|
+
assert_equal("\\\\", @zpath.clean!)
|
425
|
+
assert_equal("", @epath.clean!)
|
426
|
+
assert_equal("C:\\bar\\baz", @cpath.clean!)
|
427
|
+
|
428
|
+
# Standard stuff
|
429
|
+
assert_equal("C:\\a\\c", Pathname.new("C:\\a\\.\\b\\..\\c").clean!)
|
430
|
+
assert_equal("C:\\a", Pathname.new("C:\\.\\a").clean!)
|
431
|
+
assert_equal("C:\\a\\b", Pathname.new("C:\\a\\.\\b").clean!)
|
432
|
+
assert_equal("C:\\b", Pathname.new("C:\\a\\..\\b").clean!)
|
433
|
+
assert_equal("C:\\a", Pathname.new("C:\\a\\.").clean!)
|
434
|
+
assert_equal("C:\\d", Pathname.new("C:\\..\\..\\..\\d").clean!)
|
435
|
+
assert_equal("C:\\a\\", Pathname.new("C:\\a\\").clean!)
|
436
|
+
|
437
|
+
# Edge cases
|
438
|
+
assert_equal("\\", Pathname.new(".").clean!)
|
439
|
+
assert_equal("\\", Pathname.new("..").clean!)
|
440
|
+
|
441
|
+
assert_equal("C:\\bar\\baz", @cpath)
|
442
|
+
end
|
443
|
+
|
444
|
+
def test_absolute
|
445
|
+
assert_equal(true, @fpath.absolute?)
|
446
|
+
assert_equal(true, @bpath.absolute?)
|
447
|
+
assert_equal(true, @upath.absolute?)
|
448
|
+
assert_equal(false, @npath.absolute?)
|
449
|
+
assert_equal(true, @rpath.absolute?)
|
450
|
+
assert_equal(true, @xpath.absolute?)
|
451
|
+
assert_equal(true, @ypath.absolute?)
|
452
|
+
assert_equal(true, @zpath.absolute?)
|
453
|
+
assert_equal(false, @epath.absolute?)
|
454
|
+
|
455
|
+
assert_non_destructive
|
456
|
+
end
|
457
|
+
|
458
|
+
def test_relative
|
459
|
+
assert_equal(false, @fpath.relative?)
|
460
|
+
assert_equal(false, @bpath.relative?)
|
461
|
+
assert_equal(false, @upath.relative?)
|
462
|
+
assert_equal(true, @npath.relative?)
|
463
|
+
assert_equal(false, @rpath.relative?)
|
464
|
+
assert_equal(false, @xpath.relative?)
|
465
|
+
assert_equal(false, @ypath.relative?)
|
466
|
+
assert_equal(false, @zpath.relative?)
|
467
|
+
assert_equal(true, @epath.relative?)
|
468
|
+
|
469
|
+
assert_non_destructive
|
470
|
+
end
|
471
|
+
|
472
|
+
def test_root
|
473
|
+
assert_equal("C:\\", @fpath.root)
|
474
|
+
assert_equal("C:\\", @bpath.root)
|
475
|
+
assert_equal("\\\\foo\\bar", @upath.root)
|
476
|
+
assert_equal(".", @npath.root)
|
477
|
+
assert_equal("Z:\\", @rpath.root)
|
478
|
+
assert_equal("\\\\foo\\bar", @xpath.root)
|
479
|
+
assert_equal("\\\\foo", @ypath.root)
|
480
|
+
assert_equal("\\\\", @zpath.root)
|
481
|
+
assert_equal(".", @epath.root)
|
482
|
+
|
483
|
+
# Edge cases
|
484
|
+
assert_equal(".", Pathname.new("..").root)
|
485
|
+
assert_equal(".", Pathname.new(".").root)
|
486
|
+
|
487
|
+
assert_non_destructive
|
488
|
+
end
|
489
|
+
|
490
|
+
def test_drive_number
|
491
|
+
assert_equal(2, @fpath.drive_number)
|
492
|
+
assert_equal(2, @bpath.drive_number)
|
493
|
+
assert_equal(nil, @upath.drive_number)
|
494
|
+
assert_equal(nil, @npath.drive_number)
|
495
|
+
assert_equal(25, @rpath.drive_number)
|
496
|
+
assert_equal(nil, @xpath.drive_number)
|
497
|
+
assert_equal(nil, @ypath.drive_number)
|
498
|
+
assert_equal(nil, @zpath.drive_number)
|
499
|
+
assert_equal(nil, @epath.drive_number)
|
500
|
+
|
501
|
+
# Edge cases
|
502
|
+
assert_equal(nil, Pathname.new("..").drive_number)
|
503
|
+
assert_equal(nil, Pathname.new(".").drive_number)
|
504
|
+
|
505
|
+
assert_non_destructive
|
506
|
+
end
|
507
|
+
|
508
|
+
def test_to_a
|
509
|
+
expected = ["C:", "Program Files", "Windows NT", "Accessories"]
|
510
|
+
assert_equal(expected, @fpath.to_a)
|
511
|
+
assert_equal(expected, @bpath.to_a)
|
512
|
+
assert_equal(["foo","bar","baz"], @upath.to_a)
|
513
|
+
assert_equal(["foo","bar","baz"], @npath.to_a)
|
514
|
+
assert_equal(["Z:"], @rpath.to_a)
|
515
|
+
assert_equal(["foo","bar"], @xpath.to_a)
|
516
|
+
assert_equal(["foo"], @ypath.to_a)
|
517
|
+
assert_equal([], @zpath.to_a)
|
518
|
+
assert_equal([], @epath.to_a)
|
519
|
+
assert_equal(["C:", "foo", "bar"], @ppath.to_a)
|
520
|
+
|
521
|
+
assert_non_destructive
|
522
|
+
end
|
523
|
+
|
524
|
+
def test_is_root
|
525
|
+
assert_equal(false, @fpath.root?)
|
526
|
+
assert_equal(false, @bpath.root?)
|
527
|
+
assert_equal(false, @upath.root?)
|
528
|
+
assert_equal(false, @npath.root?)
|
529
|
+
assert_equal(true, @rpath.root?)
|
530
|
+
assert_equal(true, @xpath.root?)
|
531
|
+
assert_equal(true, @ypath.root?)
|
532
|
+
assert_equal(true, @zpath.root?)
|
533
|
+
assert_equal(false, @epath.root?)
|
534
|
+
assert_equal(false, @ppath.root?)
|
535
|
+
|
536
|
+
assert_non_destructive
|
537
|
+
end
|
538
|
+
|
539
|
+
# These are the methods from IO we have to explicitly define since
|
540
|
+
# they aren't handled by Facade.
|
541
|
+
def test_facade_io
|
542
|
+
assert_respond_to(@fpath, :foreach)
|
543
|
+
assert_respond_to(@fpath, :read)
|
544
|
+
assert_respond_to(@fpath, :readlines)
|
545
|
+
assert_respond_to(@fpath, :sysopen)
|
546
|
+
end
|
547
|
+
|
548
|
+
def test_facade_file
|
549
|
+
File.methods(false).each{ |method|
|
550
|
+
assert_respond_to(@fpath, method.to_sym)
|
551
|
+
}
|
552
|
+
end
|
553
|
+
|
554
|
+
def test_facade_dir
|
555
|
+
Dir.methods(false).each{ |method|
|
556
|
+
assert_respond_to(@fpath, method.to_sym)
|
557
|
+
}
|
558
|
+
end
|
559
|
+
|
560
|
+
def test_facade_fileutils
|
561
|
+
methods = FileUtils.public_instance_methods
|
562
|
+
methods -= File.methods(false)
|
563
|
+
methods -= Dir.methods(false)
|
564
|
+
methods.delete_if{ |m| m =~ /stream/ }
|
565
|
+
methods.delete_if{ |m| m =~ /^ln/ }
|
566
|
+
methods.delete("identical?")
|
567
|
+
|
568
|
+
methods.each{ |method|
|
569
|
+
assert_respond_to(@fpath, method.to_sym)
|
570
|
+
}
|
571
|
+
end
|
572
|
+
|
573
|
+
def test_facade_find
|
574
|
+
assert_respond_to(@fpath, :find)
|
575
|
+
assert_nothing_raised{ @fpath.find{} }
|
576
|
+
|
577
|
+
Pathname.new(Dir.pwd).find{ |f|
|
578
|
+
Find.prune if f.match("CVS")
|
579
|
+
assert_kind_of(Pathname, f)
|
580
|
+
}
|
581
|
+
end
|
582
|
+
|
583
|
+
def test_children
|
584
|
+
assert_respond_to(@cur_path, :children)
|
585
|
+
assert_nothing_raised{ @cur_path.children }
|
586
|
+
assert_kind_of(Array, @cur_path.children)
|
587
|
+
|
588
|
+
# Delete Eclipse related files
|
589
|
+
children = @cur_path.children
|
590
|
+
children.delete_if{ |e| File.basename(e) == "CVS" }
|
591
|
+
children.delete_if{ |e| File.basename(e) == ".cvsignore" }
|
592
|
+
children.delete_if{ |e| File.basename(e) == ".project" }
|
593
|
+
children.delete_if{ |e| File.basename(e) == ".loadpath" }
|
594
|
+
|
595
|
+
assert_equal(
|
596
|
+
[
|
597
|
+
Dir.pwd + "/benchmarks",
|
598
|
+
Dir.pwd + "/CHANGES",
|
599
|
+
Dir.pwd + "/examples",
|
600
|
+
Dir.pwd + "/lib",
|
601
|
+
Dir.pwd + "/MANIFEST",
|
602
|
+
Dir.pwd + "/pathname2.gemspec",
|
603
|
+
Dir.pwd + "/Rakefile",
|
604
|
+
Dir.pwd + "/README",
|
605
|
+
Dir.pwd + "/test"
|
606
|
+
].map{ |e| e.tr("/", "\\") },
|
607
|
+
children
|
608
|
+
)
|
609
|
+
|
610
|
+
# Delete Eclipse related files
|
611
|
+
children = @cur_path.children(false)
|
612
|
+
children.delete("CVS")
|
613
|
+
children.delete(".cvsignore")
|
614
|
+
children.delete(".project")
|
615
|
+
children.delete(".loadpath")
|
616
|
+
|
617
|
+
assert_equal(
|
618
|
+
[
|
619
|
+
"benchmarks", "CHANGES", "examples", "lib", "MANIFEST",
|
620
|
+
"pathname2.gemspec", "Rakefile", "README", "test"
|
621
|
+
],
|
622
|
+
children
|
623
|
+
)
|
624
|
+
end
|
625
|
+
|
626
|
+
# Ensures that subclasses return the subclass as the class, not a hard
|
627
|
+
# coded Pathname.
|
628
|
+
def test_subclasses
|
629
|
+
assert_kind_of(MyPathname, @mypath)
|
630
|
+
assert_kind_of(MyPathname, @mypath + MyPathname.new('foo'))
|
631
|
+
assert_kind_of(MyPathname, @mypath.realpath)
|
632
|
+
assert_kind_of(MyPathname, @mypath.children.first)
|
633
|
+
end
|
634
|
+
|
635
|
+
# Test to ensure that the pn{ } shortcut works
|
636
|
+
#
|
637
|
+
def test_kernel_method
|
638
|
+
assert_respond_to(Kernel, :pn)
|
639
|
+
assert_nothing_raised{ pn{'c:\foo'} }
|
640
|
+
assert_kind_of(Pathname, pn{'c:\foo'})
|
641
|
+
assert_equal('c:\foo', pn{'c:\foo'})
|
642
|
+
end
|
643
|
+
|
644
|
+
def teardown
|
645
|
+
@fpath = nil
|
646
|
+
@bpath = nil
|
647
|
+
@dpath = nil
|
648
|
+
@spath = nil
|
649
|
+
@upath = nil
|
650
|
+
@npath = nil
|
651
|
+
@rpath = nil
|
652
|
+
@xpath = nil
|
653
|
+
@ypath = nil
|
654
|
+
@zpath = nil
|
655
|
+
@epath = nil
|
656
|
+
@ppath = nil
|
657
|
+
@cpath = nil
|
658
|
+
@tpath = nil
|
659
|
+
|
660
|
+
@cur_path = nil
|
661
|
+
|
662
|
+
@abs_array.clear
|
663
|
+
@rel_array.clear
|
664
|
+
@unc_array.clear
|
665
|
+
end
|
666
|
+
end
|