pathname2 1.6.5 → 1.7.0

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