pathname2 1.8.4 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGES.md +7 -0
- data/Gemfile +2 -3
- data/MANIFEST.md +2 -2
- data/README.md +6 -0
- data/Rakefile +227 -222
- data/benchmarks/bench_pathname2.rb +127 -0
- data/examples/{example_pathname.rb → example_pathname2.rb} +7 -7
- data/lib/pathname2.rb +160 -169
- data/pathname2.gemspec +13 -9
- data/test/{test_pathname.rb → test_pathname2.rb} +67 -63
- data/test/test_version.rb +3 -3
- data/test/windows/test_append.rb +7 -7
- data/test/windows/test_aref.rb +3 -3
- data/test/windows/test_ascend.rb +5 -5
- data/test/windows/test_children.rb +7 -7
- data/test/windows/test_clean.rb +17 -17
- data/test/windows/test_clean_bang.rb +17 -17
- data/test/windows/test_constructor.rb +12 -12
- data/test/windows/test_descend.rb +5 -5
- data/test/windows/test_drive_number.rb +13 -13
- data/test/windows/test_each.rb +3 -3
- data/test/windows/test_facade.rb +6 -6
- data/test/windows/test_is_absolute.rb +8 -8
- data/test/windows/test_is_relative.rb +7 -7
- data/test/windows/test_is_root.rb +8 -8
- data/test/windows/test_is_unc.rb +18 -18
- data/test/windows/test_join.rb +8 -8
- data/test/windows/test_long_path.rb +6 -6
- data/test/windows/test_misc.rb +7 -7
- data/test/windows/test_parent.rb +9 -9
- data/test/windows/test_pstrip.rb +9 -9
- data/test/windows/test_pstrip_bang.rb +10 -10
- data/test/windows/test_realpath.rb +5 -5
- data/test/windows/test_relative_path_from.rb +4 -4
- data/test/windows/test_root.rb +14 -14
- data/test/windows/test_short_path.rb +6 -6
- data/test/windows/test_to_a.rb +12 -12
- data/test/windows/test_undecorate.rb +12 -12
- data/test/windows/test_undecorate_bang.rb +13 -13
- data.tar.gz.sig +0 -0
- metadata +61 -54
- metadata.gz.sig +0 -0
- data/benchmarks/bench_pathname.rb +0 -127
data/pathname2.gemspec
CHANGED
|
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
|
2
2
|
|
|
3
3
|
Gem::Specification.new do |spec|
|
|
4
4
|
spec.name = 'pathname2'
|
|
5
|
-
spec.version = '
|
|
5
|
+
spec.version = '2.0.0'
|
|
6
6
|
spec.author = 'Daniel J. Berger'
|
|
7
7
|
spec.license = 'Apache-2.0'
|
|
8
8
|
spec.email = 'djberg96@gmail.com'
|
|
@@ -11,17 +11,21 @@ Gem::Specification.new do |spec|
|
|
|
11
11
|
spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
|
|
12
12
|
spec.cert_chain = ['certs/djberg96_pub.pem']
|
|
13
13
|
|
|
14
|
-
spec.add_dependency('facade')
|
|
15
|
-
spec.
|
|
14
|
+
spec.add_dependency('facade', '~> 1.2')
|
|
15
|
+
spec.add_dependency('addressable', '~> 2.8')
|
|
16
|
+
spec.add_development_dependency('test-unit', '~> 3.4')
|
|
16
17
|
spec.add_development_dependency('rake')
|
|
17
18
|
|
|
18
19
|
spec.metadata = {
|
|
19
|
-
'homepage_uri'
|
|
20
|
-
'bug_tracker_uri'
|
|
21
|
-
'changelog_uri'
|
|
22
|
-
'documentation_uri'
|
|
23
|
-
'source_code_uri'
|
|
24
|
-
'wiki_uri'
|
|
20
|
+
'homepage_uri' => 'https://github.com/djberg96/pathname2',
|
|
21
|
+
'bug_tracker_uri' => 'https://github.com/djberg96/pathname2/issues',
|
|
22
|
+
'changelog_uri' => 'https://github.com/djberg96/pathname2/blob/main/CHANGES.md',
|
|
23
|
+
'documentation_uri' => 'https://github.com/djberg96/pathname2/wiki',
|
|
24
|
+
'source_code_uri' => 'https://github.com/djberg96/pathname2',
|
|
25
|
+
'wiki_uri' => 'https://github.com/djberg96/pathname2/wiki',
|
|
26
|
+
'rubygems_mfa_required' => 'true',
|
|
27
|
+
'github_repo' => 'https://github.com/djberg96/pathname2',
|
|
28
|
+
'funding_uri' => 'https://github.com/sponsors/djberg96'
|
|
25
29
|
}
|
|
26
30
|
|
|
27
31
|
if File::ALT_SEPARATOR
|
|
@@ -10,27 +10,27 @@ require 'rbconfig'
|
|
|
10
10
|
require 'test-unit'
|
|
11
11
|
include RbConfig
|
|
12
12
|
|
|
13
|
-
class
|
|
13
|
+
class MyPathname2 < Pathname2; end
|
|
14
14
|
|
|
15
|
-
class
|
|
15
|
+
class TC_Pathname2 < Test::Unit::TestCase
|
|
16
16
|
def self.startup
|
|
17
17
|
Dir.chdir(File.expand_path(File.dirname(__FILE__)))
|
|
18
18
|
@@pwd = Dir.pwd
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def setup
|
|
22
|
-
@abs_path =
|
|
23
|
-
@rel_path =
|
|
24
|
-
@trl_path =
|
|
25
|
-
@mul_path =
|
|
26
|
-
@rul_path =
|
|
27
|
-
@url_path =
|
|
28
|
-
@cur_path =
|
|
22
|
+
@abs_path = Pathname2.new('/usr/local/bin')
|
|
23
|
+
@rel_path = Pathname2.new('usr/local/bin')
|
|
24
|
+
@trl_path = Pathname2.new('/usr/local/bin/')
|
|
25
|
+
@mul_path = Pathname2.new('/usr/local/lib/local/lib')
|
|
26
|
+
@rul_path = Pathname2.new('usr/local/lib/local/lib')
|
|
27
|
+
@url_path = Pathname2.new('file:///foo%20bar/baz')
|
|
28
|
+
@cur_path = Pathname2.new(@@pwd)
|
|
29
29
|
|
|
30
30
|
@abs_array = []
|
|
31
31
|
@rel_array = []
|
|
32
32
|
|
|
33
|
-
@mypath =
|
|
33
|
+
@mypath = MyPathname2.new('/usr/bin')
|
|
34
34
|
|
|
35
35
|
@test_file = 'realpath_test.txt'
|
|
36
36
|
@link_file = 'realpath_symlink.txt'
|
|
@@ -46,28 +46,32 @@ class TC_Pathname < Test::Unit::TestCase
|
|
|
46
46
|
|
|
47
47
|
# Convenience method for test_plus
|
|
48
48
|
def assert_pathname_plus(a, b, c)
|
|
49
|
-
a =
|
|
50
|
-
b =
|
|
51
|
-
c =
|
|
49
|
+
a = Pathname2.new(a)
|
|
50
|
+
b = Pathname2.new(b)
|
|
51
|
+
c = Pathname2.new(c)
|
|
52
52
|
assert_equal(a, b + c)
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
# Convenience method for test_spaceship operator
|
|
56
56
|
def assert_pathname_cmp(int, s1, s2)
|
|
57
|
-
p1 =
|
|
58
|
-
p2 =
|
|
57
|
+
p1 = Pathname2.new(s1)
|
|
58
|
+
p2 = Pathname2.new(s2)
|
|
59
59
|
result = p1 <=> p2
|
|
60
60
|
assert_equal(int, result)
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
# Convenience method for test_relative_path_from
|
|
64
64
|
def assert_relpath(result, dest, base)
|
|
65
|
-
assert_equal(result,
|
|
65
|
+
assert_equal(result, Pathname2.new(dest).relative_path_from(base))
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
# Convenience method for test_relative_path_from_expected_errors
|
|
69
69
|
def assert_relpath_err(to, from)
|
|
70
|
-
assert_raise(ArgumentError) {
|
|
70
|
+
assert_raise(ArgumentError) { Pathname2.new(to).relative_path_from(from) }
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
test "VERSION constant is set to expected value" do
|
|
74
|
+
assert_equal("2.0.0", Pathname2::VERSION)
|
|
71
75
|
end
|
|
72
76
|
|
|
73
77
|
test "url_path returns expected result" do
|
|
@@ -77,20 +81,20 @@ class TC_Pathname < Test::Unit::TestCase
|
|
|
77
81
|
test "realpath basic functionality" do
|
|
78
82
|
FileUtils.touch(@test_file) && File.symlink(@test_file, @link_file)
|
|
79
83
|
assert_respond_to(@abs_path, :realpath)
|
|
80
|
-
assert_equal(@@pwd,
|
|
81
|
-
assert_kind_of(
|
|
84
|
+
assert_equal(@@pwd, Pathname2.new('.').realpath)
|
|
85
|
+
assert_kind_of(Pathname2, Pathname2.new(@link_file).realpath)
|
|
82
86
|
end
|
|
83
87
|
|
|
84
88
|
test "realpath returns expected result for simple symlink" do
|
|
85
89
|
FileUtils.touch(@test_file) && File.symlink(@test_file, @link_file)
|
|
86
|
-
assert_true(
|
|
87
|
-
assert_raises(Errno::ENOENT){
|
|
90
|
+
assert_true(Pathname2.new(@link_file) != Pathname2.new(@link_file).realpath)
|
|
91
|
+
assert_raises(Errno::ENOENT){ Pathname2.new('../bogus').realpath }
|
|
88
92
|
end
|
|
89
93
|
|
|
90
94
|
test "realpath returns expected result for nested symlink" do
|
|
91
95
|
FileUtils.touch(@test_file) && File.symlink(@test_file, @link_file) && File.symlink(@link_file, @link_file2)
|
|
92
|
-
assert_true(
|
|
93
|
-
assert_equal(
|
|
96
|
+
assert_true(Pathname2.new(@link_file) != Pathname2.new(@link_file2).realpath)
|
|
97
|
+
assert_equal(Pathname2.new(@link_file).realpath, Pathname2.new(@link_file2).realpath)
|
|
94
98
|
end
|
|
95
99
|
|
|
96
100
|
# These tests taken directly from Tanaka's pathname.rb. The one failure
|
|
@@ -144,7 +148,7 @@ class TC_Pathname < Test::Unit::TestCase
|
|
|
144
148
|
assert_respond_to(@abs_path, :parent)
|
|
145
149
|
assert_equal('/usr/local', @abs_path.parent)
|
|
146
150
|
assert_equal('usr/local', @rel_path.parent)
|
|
147
|
-
assert_equal('/',
|
|
151
|
+
assert_equal('/', Pathname2.new('/').parent)
|
|
148
152
|
end
|
|
149
153
|
|
|
150
154
|
def test_pstrip
|
|
@@ -211,7 +215,7 @@ class TC_Pathname < Test::Unit::TestCase
|
|
|
211
215
|
children = @cur_path.children.sort.reject{ |f| f.include?('git') || f.include?('.swp') }
|
|
212
216
|
assert_equal(
|
|
213
217
|
[
|
|
214
|
-
Dir.pwd + '/
|
|
218
|
+
Dir.pwd + '/test_pathname2.rb',
|
|
215
219
|
Dir.pwd + '/test_version.rb',
|
|
216
220
|
Dir.pwd + '/windows'
|
|
217
221
|
],
|
|
@@ -223,7 +227,7 @@ class TC_Pathname < Test::Unit::TestCase
|
|
|
223
227
|
assert_nothing_raised{ @cur_path.children(false) }
|
|
224
228
|
|
|
225
229
|
children = @cur_path.children(false).reject{ |f| f.include?('git') || f.include?('.swp') }
|
|
226
|
-
assert_equal(['
|
|
230
|
+
assert_equal(['test_pathname2.rb', 'test_version.rb', 'windows'], children.sort)
|
|
227
231
|
end
|
|
228
232
|
|
|
229
233
|
def test_unc
|
|
@@ -250,8 +254,8 @@ class TC_Pathname < Test::Unit::TestCase
|
|
|
250
254
|
assert_nothing_raised{ @abs_path.root? }
|
|
251
255
|
assert_nothing_raised{ @rel_path.root? }
|
|
252
256
|
|
|
253
|
-
path1 =
|
|
254
|
-
path2 =
|
|
257
|
+
path1 = Pathname2.new('/')
|
|
258
|
+
path2 = Pathname2.new('a')
|
|
255
259
|
assert_equal(true, path1.root?)
|
|
256
260
|
assert_equal(false, path2.root?)
|
|
257
261
|
|
|
@@ -266,10 +270,10 @@ class TC_Pathname < Test::Unit::TestCase
|
|
|
266
270
|
assert_equal(true, @abs_path.absolute?)
|
|
267
271
|
assert_equal(false, @rel_path.absolute?)
|
|
268
272
|
|
|
269
|
-
assert_equal(true,
|
|
270
|
-
assert_equal(false,
|
|
271
|
-
assert_equal(false,
|
|
272
|
-
assert_equal(false,
|
|
273
|
+
assert_equal(true, Pathname2.new('/usr/bin/ruby').absolute?)
|
|
274
|
+
assert_equal(false, Pathname2.new('foo').absolute?)
|
|
275
|
+
assert_equal(false, Pathname2.new('foo/bar').absolute?)
|
|
276
|
+
assert_equal(false, Pathname2.new('../foo/bar').absolute?)
|
|
273
277
|
|
|
274
278
|
assert_non_destructive
|
|
275
279
|
end
|
|
@@ -282,10 +286,10 @@ class TC_Pathname < Test::Unit::TestCase
|
|
|
282
286
|
assert_equal(false, @abs_path.relative?)
|
|
283
287
|
assert_equal(true, @rel_path.relative?)
|
|
284
288
|
|
|
285
|
-
assert_equal(false,
|
|
286
|
-
assert_equal(true,
|
|
287
|
-
assert_equal(true,
|
|
288
|
-
assert_equal(true,
|
|
289
|
+
assert_equal(false, Pathname2.new('/usr/bin/ruby').relative?)
|
|
290
|
+
assert_equal(true, Pathname2.new('foo').relative?)
|
|
291
|
+
assert_equal(true, Pathname2.new('foo/bar').relative?)
|
|
292
|
+
assert_equal(true, Pathname2.new('../foo/bar').relative?)
|
|
289
293
|
|
|
290
294
|
assert_non_destructive
|
|
291
295
|
end
|
|
@@ -333,7 +337,7 @@ class TC_Pathname < Test::Unit::TestCase
|
|
|
333
337
|
assert_pathname_plus('.', 'foo', '..')
|
|
334
338
|
|
|
335
339
|
# Alias
|
|
336
|
-
assert_equal('/foo/bar',
|
|
340
|
+
assert_equal('/foo/bar', Pathname2.new('/foo') / Pathname2.new('bar'))
|
|
337
341
|
end
|
|
338
342
|
|
|
339
343
|
# Any tests marked with '***' mean that this behavior is different than
|
|
@@ -341,22 +345,22 @@ class TC_Pathname < Test::Unit::TestCase
|
|
|
341
345
|
# implementation.
|
|
342
346
|
def test_clean
|
|
343
347
|
# Standard stuff
|
|
344
|
-
assert_equal('/a/b/c',
|
|
345
|
-
assert_equal('b/c',
|
|
346
|
-
assert_equal('a',
|
|
347
|
-
assert_equal('a/c',
|
|
348
|
-
assert_equal('a/b',
|
|
349
|
-
assert_equal('.',
|
|
350
|
-
assert_equal('/a',
|
|
351
|
-
assert_equal('/b',
|
|
352
|
-
assert_equal('d',
|
|
348
|
+
assert_equal('/a/b/c', Pathname2.new('/a/b/c').cleanpath)
|
|
349
|
+
assert_equal('b/c', Pathname2.new('./b/c').cleanpath)
|
|
350
|
+
assert_equal('a', Pathname2.new('a/.').cleanpath) # ***
|
|
351
|
+
assert_equal('a/c', Pathname2.new('a/./c').cleanpath)
|
|
352
|
+
assert_equal('a/b', Pathname2.new('a/b/.').cleanpath) # ***
|
|
353
|
+
assert_equal('.', Pathname2.new('a/../.').cleanpath) # ***
|
|
354
|
+
assert_equal('/a', Pathname2.new('/a/b/..').cleanpath)
|
|
355
|
+
assert_equal('/b', Pathname2.new('/a/../b').cleanpath)
|
|
356
|
+
assert_equal('d', Pathname2.new('a/../../d').cleanpath) # ***
|
|
353
357
|
|
|
354
358
|
# Edge cases
|
|
355
|
-
assert_equal('',
|
|
356
|
-
assert_equal('.',
|
|
357
|
-
assert_equal('..',
|
|
358
|
-
assert_equal('/',
|
|
359
|
-
assert_equal('/',
|
|
359
|
+
assert_equal('', Pathname2.new('').cleanpath)
|
|
360
|
+
assert_equal('.', Pathname2.new('.').cleanpath)
|
|
361
|
+
assert_equal('..', Pathname2.new('..').cleanpath)
|
|
362
|
+
assert_equal('/', Pathname2.new('/').cleanpath)
|
|
363
|
+
assert_equal('/', Pathname2.new('//').cleanpath)
|
|
360
364
|
|
|
361
365
|
assert_non_destructive
|
|
362
366
|
end
|
|
@@ -419,20 +423,20 @@ class TC_Pathname < Test::Unit::TestCase
|
|
|
419
423
|
assert_respond_to(@abs_path, :find)
|
|
420
424
|
assert_nothing_raised{ @abs_path.find{} }
|
|
421
425
|
|
|
422
|
-
|
|
426
|
+
Pathname2.new(Dir.pwd).find{ |f|
|
|
423
427
|
Find.prune if f.match('CVS')
|
|
424
|
-
assert_kind_of(
|
|
428
|
+
assert_kind_of(Pathname2, f)
|
|
425
429
|
}
|
|
426
430
|
end
|
|
427
431
|
|
|
428
432
|
# Ensures that subclasses return the subclass as the class, not a hard
|
|
429
|
-
# coded
|
|
433
|
+
# coded Pathname2.
|
|
430
434
|
#
|
|
431
435
|
def test_subclasses
|
|
432
|
-
assert_kind_of(
|
|
433
|
-
assert_kind_of(
|
|
434
|
-
assert_kind_of(
|
|
435
|
-
assert_kind_of(
|
|
436
|
+
assert_kind_of(MyPathname2, @mypath)
|
|
437
|
+
assert_kind_of(MyPathname2, @mypath + MyPathname2.new('foo'))
|
|
438
|
+
assert_kind_of(MyPathname2, @mypath.realpath)
|
|
439
|
+
assert_kind_of(MyPathname2, @mypath.children.first)
|
|
436
440
|
end
|
|
437
441
|
|
|
438
442
|
# Test to ensure that the pn{ } shortcut works
|
|
@@ -440,21 +444,21 @@ class TC_Pathname < Test::Unit::TestCase
|
|
|
440
444
|
def test_kernel_method
|
|
441
445
|
assert_respond_to(Kernel, :pn)
|
|
442
446
|
assert_nothing_raised{ pn{'/foo'} }
|
|
443
|
-
assert_kind_of(
|
|
447
|
+
assert_kind_of(Pathname2, pn{'/foo'})
|
|
444
448
|
assert_equal('/foo', pn{'/foo'})
|
|
445
449
|
end
|
|
446
450
|
|
|
447
451
|
def test_pwd_singleton_method
|
|
448
|
-
assert_respond_to(
|
|
449
|
-
assert_kind_of(String,
|
|
450
|
-
assert_equal(@@pwd,
|
|
452
|
+
assert_respond_to(Pathname2, :pwd)
|
|
453
|
+
assert_kind_of(String, Pathname2.pwd)
|
|
454
|
+
assert_equal(@@pwd, Pathname2.pwd)
|
|
451
455
|
end
|
|
452
456
|
|
|
453
457
|
test "String#to_path instance method is implemented" do
|
|
454
458
|
string = "/usr/local/bin"
|
|
455
459
|
assert_respond_to(string, :to_path)
|
|
456
460
|
assert_nothing_raised{ string.to_path }
|
|
457
|
-
assert_kind_of(
|
|
461
|
+
assert_kind_of(Pathname2, string.to_path)
|
|
458
462
|
end
|
|
459
463
|
|
|
460
464
|
def teardown
|
data/test/test_version.rb
CHANGED
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
require 'pathname2'
|
|
7
7
|
require 'test-unit'
|
|
8
8
|
|
|
9
|
-
class
|
|
9
|
+
class TC_Pathname2_Version < Test::Unit::TestCase
|
|
10
10
|
test "version is set to expected value" do
|
|
11
|
-
assert_equal('
|
|
11
|
+
assert_equal('2.0.0', Pathname2::VERSION)
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
test "version is frozen" do
|
|
15
|
-
assert_true(
|
|
15
|
+
assert_true(Pathname2::VERSION.frozen?)
|
|
16
16
|
end
|
|
17
17
|
end
|
data/test/windows/test_append.rb
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
########################################################################
|
|
2
2
|
# test_append.rb
|
|
3
3
|
#
|
|
4
|
-
# Test suite for the
|
|
4
|
+
# Test suite for the Pathname2#append method.
|
|
5
5
|
########################################################################
|
|
6
6
|
require 'test-unit'
|
|
7
7
|
require 'pathname2'
|
|
8
8
|
|
|
9
|
-
class
|
|
9
|
+
class TC_Pathname2_Append < Test::Unit::TestCase
|
|
10
10
|
def setup
|
|
11
|
-
@abs_path =
|
|
12
|
-
@rel_path =
|
|
11
|
+
@abs_path = Pathname2.new("C:\\foo\\bar")
|
|
12
|
+
@rel_path = Pathname2.new("foo\\bar\\baz")
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def assert_pathname_plus(a, b, c)
|
|
16
|
-
a =
|
|
17
|
-
b =
|
|
18
|
-
c =
|
|
16
|
+
a = Pathname2.new(a)
|
|
17
|
+
b = Pathname2.new(b)
|
|
18
|
+
c = Pathname2.new(c)
|
|
19
19
|
assert_equal(a, b + c)
|
|
20
20
|
end
|
|
21
21
|
|
data/test/windows/test_aref.rb
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
########################################################################
|
|
2
2
|
# test_aref.rb
|
|
3
3
|
#
|
|
4
|
-
# Test suite for the
|
|
4
|
+
# Test suite for the Pathname2#[] method.
|
|
5
5
|
########################################################################
|
|
6
6
|
require 'test-unit'
|
|
7
7
|
require 'pathname2'
|
|
8
8
|
|
|
9
|
-
class
|
|
9
|
+
class TC_Pathname2_Aref < Test::Unit::TestCase
|
|
10
10
|
def setup
|
|
11
|
-
@path =
|
|
11
|
+
@path = Pathname2.new("C:/Program Files/Windows NT/Accessories")
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
test "[] with index works as expected" do
|
data/test/windows/test_ascend.rb
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
########################################################################
|
|
2
2
|
# test_ascend.rb
|
|
3
3
|
#
|
|
4
|
-
# Test suite for the
|
|
4
|
+
# Test suite for the Pathname2#ascend method.
|
|
5
5
|
########################################################################
|
|
6
6
|
require 'pathname2'
|
|
7
7
|
require 'test-unit'
|
|
8
8
|
|
|
9
|
-
class
|
|
9
|
+
class TC_Pathname2_Ascend < Test::Unit::TestCase
|
|
10
10
|
def setup
|
|
11
|
-
@path =
|
|
11
|
+
@path = Pathname2.new("C:\\foo\\bar\\baz")
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
test "ascend basic functionality" do
|
|
@@ -27,14 +27,14 @@ class TC_Pathname_Ascend < Test::Unit::TestCase
|
|
|
27
27
|
|
|
28
28
|
test "ascend works as expected on a UNC path" do
|
|
29
29
|
array = []
|
|
30
|
-
|
|
30
|
+
Pathname2.new('//foo/bar/baz').ascend{ |e| array << e }
|
|
31
31
|
assert_equal("\\\\foo\\bar\\baz", array[0])
|
|
32
32
|
assert_equal("\\\\foo\\bar", array[1])
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
test "ascend works as expected on a relative path" do
|
|
36
36
|
array = []
|
|
37
|
-
|
|
37
|
+
Pathname2.new('foo/bar/baz').ascend{ |e| array << e }
|
|
38
38
|
assert_equal('foo\bar\baz', array[0])
|
|
39
39
|
assert_equal('foo\bar', array[1])
|
|
40
40
|
assert_equal('foo', array[2])
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
########################################################################
|
|
2
2
|
# test_children.rb
|
|
3
3
|
#
|
|
4
|
-
# Test suite for the
|
|
4
|
+
# Test suite for the Pathname2#children method.
|
|
5
5
|
########################################################################
|
|
6
6
|
require 'pathname2'
|
|
7
7
|
require 'test-unit'
|
|
8
8
|
|
|
9
|
-
class
|
|
9
|
+
class TC_Pathname2_Children < Test::Unit::TestCase
|
|
10
10
|
def setup
|
|
11
11
|
@dir = 'foo'
|
|
12
|
-
@path =
|
|
12
|
+
@path = Pathname2.new(File.dirname(File.dirname(__FILE__)))
|
|
13
13
|
|
|
14
14
|
Dir.mkdir(@dir)
|
|
15
15
|
Dir.chdir(@dir){
|
|
@@ -26,13 +26,13 @@ class TC_Pathname_Children < Test::Unit::TestCase
|
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
test "children method returns expected results" do
|
|
29
|
-
path =
|
|
29
|
+
path = Pathname2.new(@dir)
|
|
30
30
|
assert_equal(%w[foo\alpha foo\beta foo\gamma], path.children)
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
test "each result of the children method is a
|
|
34
|
-
path =
|
|
35
|
-
assert_kind_of(
|
|
33
|
+
test "each result of the children method is a Pathname2 object" do
|
|
34
|
+
path = Pathname2.new(@dir)
|
|
35
|
+
assert_kind_of(Pathname2, path.children.first)
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
def teardown
|
data/test/windows/test_clean.rb
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
1
|
########################################################################
|
|
2
2
|
# test_clean.rb
|
|
3
3
|
#
|
|
4
|
-
# Test suite for the
|
|
4
|
+
# Test suite for the Pathname2#clean method.
|
|
5
5
|
########################################################################
|
|
6
6
|
require 'test-unit'
|
|
7
7
|
require 'pathname2'
|
|
8
8
|
|
|
9
|
-
class
|
|
9
|
+
class TC_Pathname2_Clean < Test::Unit::TestCase
|
|
10
10
|
def setup
|
|
11
|
-
@path =
|
|
11
|
+
@path = Pathname2.new("C:\\foo\\..\\bar\\.\\baz")
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
test "clean basic functionality" do
|
|
15
15
|
assert_respond_to(@path, :clean)
|
|
16
16
|
assert_nothing_raised{ @path.clean }
|
|
17
|
-
assert_kind_of(
|
|
17
|
+
assert_kind_of(Pathname2, @path.clean)
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
test "clean returns expected results for unclean paths" do
|
|
21
|
-
assert_equal("C:\\a\\c",
|
|
22
|
-
assert_equal("C:\\a",
|
|
23
|
-
assert_equal("C:\\a\\b",
|
|
24
|
-
assert_equal("C:\\b",
|
|
25
|
-
assert_equal("C:\\a",
|
|
26
|
-
assert_equal("C:\\d",
|
|
21
|
+
assert_equal("C:\\a\\c", Pathname2.new("C:\\a\\.\\b\\..\\c").clean)
|
|
22
|
+
assert_equal("C:\\a", Pathname2.new("C:\\.\\a").clean)
|
|
23
|
+
assert_equal("C:\\a\\b", Pathname2.new("C:\\a\\.\\b").clean)
|
|
24
|
+
assert_equal("C:\\b", Pathname2.new("C:\\a\\..\\b").clean)
|
|
25
|
+
assert_equal("C:\\a", Pathname2.new("C:\\a\\.").clean)
|
|
26
|
+
assert_equal("C:\\d", Pathname2.new("C:\\..\\..\\..\\d").clean)
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
test "clean returns already clean paths unmodified" do
|
|
30
|
-
assert_equal("C:\\",
|
|
31
|
-
assert_equal("C:\\a",
|
|
32
|
-
assert_equal("C:\\a\\",
|
|
33
|
-
assert_equal("\\\\foo\\bar",
|
|
34
|
-
assert_equal("a",
|
|
30
|
+
assert_equal("C:\\", Pathname2.new("C:\\").clean)
|
|
31
|
+
assert_equal("C:\\a", Pathname2.new("C:\\a").clean)
|
|
32
|
+
assert_equal("C:\\a\\", Pathname2.new("C:\\a\\").clean)
|
|
33
|
+
assert_equal("\\\\foo\\bar", Pathname2.new("\\\\foo\\bar").clean)
|
|
34
|
+
assert_equal("a", Pathname2.new("a").clean)
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
test "clean returns a slash for . and .." do
|
|
38
|
-
assert_equal("\\",
|
|
39
|
-
assert_equal("\\",
|
|
38
|
+
assert_equal("\\", Pathname2.new(".").clean)
|
|
39
|
+
assert_equal("\\", Pathname2.new("..").clean)
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
test "clean does not modify receiver" do
|
|
@@ -1,42 +1,42 @@
|
|
|
1
1
|
########################################################################
|
|
2
2
|
# test_clean_bang.rb
|
|
3
3
|
#
|
|
4
|
-
# Test suite for the
|
|
4
|
+
# Test suite for the Pathname2#clean! method.
|
|
5
5
|
########################################################################
|
|
6
6
|
require 'test-unit'
|
|
7
7
|
require 'pathname2'
|
|
8
8
|
|
|
9
|
-
class
|
|
9
|
+
class TC_Pathname2_CleanBang < Test::Unit::TestCase
|
|
10
10
|
def setup
|
|
11
|
-
@path =
|
|
11
|
+
@path = Pathname2.new("C:\\foo\\..\\bar\\.\\baz")
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
test "clean basic functionality" do
|
|
15
15
|
assert_respond_to(@path, :clean!)
|
|
16
16
|
assert_nothing_raised{ @path.clean! }
|
|
17
|
-
assert_kind_of(
|
|
17
|
+
assert_kind_of(Pathname2, @path.clean!)
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
test "clean returns expected results for unclean paths" do
|
|
21
|
-
assert_equal("C:\\a\\c",
|
|
22
|
-
assert_equal("C:\\a",
|
|
23
|
-
assert_equal("C:\\a\\b",
|
|
24
|
-
assert_equal("C:\\b",
|
|
25
|
-
assert_equal("C:\\a",
|
|
26
|
-
assert_equal("C:\\d",
|
|
21
|
+
assert_equal("C:\\a\\c", Pathname2.new("C:\\a\\.\\b\\..\\c").clean!)
|
|
22
|
+
assert_equal("C:\\a", Pathname2.new("C:\\.\\a").clean!)
|
|
23
|
+
assert_equal("C:\\a\\b", Pathname2.new("C:\\a\\.\\b").clean!)
|
|
24
|
+
assert_equal("C:\\b", Pathname2.new("C:\\a\\..\\b").clean!)
|
|
25
|
+
assert_equal("C:\\a", Pathname2.new("C:\\a\\.").clean!)
|
|
26
|
+
assert_equal("C:\\d", Pathname2.new("C:\\..\\..\\..\\d").clean!)
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
test "clean returns already clean paths unmodified" do
|
|
30
|
-
assert_equal("C:\\",
|
|
31
|
-
assert_equal("C:\\a",
|
|
32
|
-
assert_equal("C:\\a\\",
|
|
33
|
-
assert_equal("\\\\foo\\bar",
|
|
34
|
-
assert_equal("a",
|
|
30
|
+
assert_equal("C:\\", Pathname2.new("C:\\").clean!)
|
|
31
|
+
assert_equal("C:\\a", Pathname2.new("C:\\a").clean!)
|
|
32
|
+
assert_equal("C:\\a\\", Pathname2.new("C:\\a\\").clean!)
|
|
33
|
+
assert_equal("\\\\foo\\bar", Pathname2.new("\\\\foo\\bar").clean!)
|
|
34
|
+
assert_equal("a", Pathname2.new("a").clean!)
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
test "clean returns a slash for . and .." do
|
|
38
|
-
assert_equal("\\",
|
|
39
|
-
assert_equal("\\",
|
|
38
|
+
assert_equal("\\", Pathname2.new(".").clean!)
|
|
39
|
+
assert_equal("\\", Pathname2.new("..").clean!)
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
test "clean! modifies receiver" do
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
########################################################################
|
|
2
2
|
# test_constructor.rb
|
|
3
3
|
#
|
|
4
|
-
# Various tests for the
|
|
4
|
+
# Various tests for the Pathname2.new method.
|
|
5
5
|
########################################################################
|
|
6
6
|
require 'pathname2'
|
|
7
7
|
require 'test-unit'
|
|
8
8
|
|
|
9
|
-
class
|
|
9
|
+
class TC_Pathname2_Constructor < Test::Unit::TestCase
|
|
10
10
|
def setup
|
|
11
11
|
@abs_path = "C:/Users"
|
|
12
12
|
@rel_path = "Users"
|
|
@@ -14,30 +14,30 @@ class TC_Pathname_Constructor < Test::Unit::TestCase
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
test "constructor handles absolute paths properly" do
|
|
17
|
-
assert_nothing_raised{
|
|
18
|
-
assert_equal("C:\\Users",
|
|
17
|
+
assert_nothing_raised{ Pathname2.new(@abs_path) }
|
|
18
|
+
assert_equal("C:\\Users", Pathname2.new(@abs_path).to_s)
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
test "constructor handles relative paths properly" do
|
|
22
|
-
assert_nothing_raised{
|
|
23
|
-
assert_equal("Users",
|
|
22
|
+
assert_nothing_raised{ Pathname2.new(@rel_path) }
|
|
23
|
+
assert_equal("Users", Pathname2.new(@rel_path).to_s)
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
test "constructor handles file URL's properly" do
|
|
27
|
-
assert_nothing_raised{
|
|
28
|
-
assert_equal("C:\\Documents and Settings",
|
|
27
|
+
assert_nothing_raised{ Pathname2.new(@url_path) }
|
|
28
|
+
assert_equal("C:\\Documents and Settings", Pathname2.new(@url_path).to_s)
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
test "constructor returns a
|
|
32
|
-
assert_kind_of(
|
|
31
|
+
test "constructor returns a Pathname2 object" do
|
|
32
|
+
assert_kind_of(Pathname2, Pathname2.new(@abs_path))
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
test "constructor handles frozen arguments without issue" do
|
|
36
|
-
assert_nothing_raised{
|
|
36
|
+
assert_nothing_raised{ Pathname2.new(@abs_path.freeze) }
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
test "constructor raises an error if string argument is too long" do
|
|
40
|
-
assert_raise(ArgumentError){
|
|
40
|
+
assert_raise(ArgumentError){ Pathname2.new("foo" * 1000) }
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
def teardown
|