pathname2 1.6.5-universal-mingw32 → 1.7.1-universal-mingw32
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 +15 -0
- data/CHANGES +10 -0
- data/MANIFEST +28 -1
- data/README +5 -6
- data/Rakefile +179 -3
- data/lib/pathname2.rb +128 -134
- data/pathname2.gemspec +7 -10
- data/test/test_pathname.rb +15 -18
- data/test/test_version.rb +13 -0
- data/test/windows/test_append.rb +59 -0
- data/test/windows/test_aref.rb +37 -0
- data/test/windows/test_ascend.rb +51 -0
- data/test/windows/test_children.rb +42 -0
- data/test/windows/test_clean.rb +50 -0
- data/test/windows/test_clean_bang.rb +50 -0
- data/test/windows/test_constructor.rb +48 -0
- data/test/windows/test_descend.rb +51 -0
- data/test/windows/test_drive_number.rb +58 -0
- data/test/windows/test_each.rb +28 -0
- data/test/windows/test_facade.rb +64 -0
- data/test/windows/test_is_absolute.rb +47 -0
- data/test/windows/test_is_relative.rb +46 -0
- data/test/windows/test_is_root.rb +44 -0
- data/test/windows/test_is_unc.rb +51 -0
- data/test/windows/test_long_path.rb +41 -0
- data/test/windows/test_misc.rb +33 -0
- data/test/windows/test_parent.rb +37 -0
- data/test/windows/test_pstrip.rb +42 -0
- data/test/windows/test_pstrip_bang.rb +46 -0
- data/test/windows/test_realpath.rb +39 -0
- data/test/windows/test_relative_path_from.rb +60 -0
- data/test/windows/test_root.rb +59 -0
- data/test/windows/test_short_path.rb +41 -0
- data/test/windows/test_to_a.rb +46 -0
- data/test/windows/test_undecorate.rb +47 -0
- data/test/windows/test_undecorate_bang.rb +53 -0
- metadata +137 -82
- data/test/test_pathname_windows.rb +0 -678
@@ -0,0 +1,51 @@
|
|
1
|
+
########################################################################
|
2
|
+
# test_descend.rb
|
3
|
+
#
|
4
|
+
# Test suite for the Pathname#descend method.
|
5
|
+
########################################################################
|
6
|
+
require 'pathname2'
|
7
|
+
require 'test-unit'
|
8
|
+
|
9
|
+
class TC_Pathname_Descend < Test::Unit::TestCase
|
10
|
+
def setup
|
11
|
+
@path = Pathname.new("C:\\foo\\bar\\baz")
|
12
|
+
end
|
13
|
+
|
14
|
+
test "descend basic functionality" do
|
15
|
+
assert_respond_to(@path, :descend)
|
16
|
+
assert_nothing_raised{ @path.descend{} }
|
17
|
+
end
|
18
|
+
|
19
|
+
test "descend works as expected on a standard absolute path" do
|
20
|
+
array = []
|
21
|
+
@path.descend{ |e| array << e }
|
22
|
+
assert_equal('C:', array[0])
|
23
|
+
assert_equal('C:\foo', array[1])
|
24
|
+
assert_equal('C:\foo\bar', array[2])
|
25
|
+
assert_equal('C:\foo\bar\baz', array[3])
|
26
|
+
end
|
27
|
+
|
28
|
+
test "descend works as expected on a UNC path" do
|
29
|
+
array = []
|
30
|
+
Pathname.new('//foo/bar/baz').descend{ |e| array << e }
|
31
|
+
assert_equal("\\\\foo\\bar", array[0])
|
32
|
+
assert_equal("\\\\foo\\bar\\baz", array[1])
|
33
|
+
end
|
34
|
+
|
35
|
+
test "descend works as expected on a relative path" do
|
36
|
+
array = []
|
37
|
+
Pathname.new('foo/bar/baz').descend{ |e| array << e }
|
38
|
+
assert_equal('foo', array[0])
|
39
|
+
assert_equal('foo\bar', array[1])
|
40
|
+
assert_equal('foo\bar\baz', array[2])
|
41
|
+
end
|
42
|
+
|
43
|
+
test "descend does not modify the receiver" do
|
44
|
+
@path.descend{}
|
45
|
+
assert_equal('C:\foo\bar\baz', @path)
|
46
|
+
end
|
47
|
+
|
48
|
+
def teardown
|
49
|
+
@path = nil
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
########################################################################
|
2
|
+
# test_drive_number.rb
|
3
|
+
#
|
4
|
+
# Test suite for the Pathname#drive_number method
|
5
|
+
########################################################################
|
6
|
+
require 'test-unit'
|
7
|
+
require 'pathname2'
|
8
|
+
|
9
|
+
class TC_Pathname_DriveNumber < Test::Unit::TestCase
|
10
|
+
def setup
|
11
|
+
@abs_path = Pathname.new("C:\\Program Files")
|
12
|
+
@unc_path = Pathname.new("\\\\foo\\bar\\baz")
|
13
|
+
@rel_path = Pathname.new("foo\\bar\\baz")
|
14
|
+
end
|
15
|
+
|
16
|
+
test "drive_number method returns expected results for absolute paths" do
|
17
|
+
assert_equal(2, @abs_path.drive_number)
|
18
|
+
end
|
19
|
+
|
20
|
+
test "drive_number method returns expected results for paths with forward slashes" do
|
21
|
+
assert_equal(2, Pathname.new("C:/Program Files").drive_number)
|
22
|
+
end
|
23
|
+
|
24
|
+
test "drive_number method returns expected results for unc paths" do
|
25
|
+
assert_nil(@unc_path.drive_number)
|
26
|
+
assert_nil(Pathname.new("\\\\foo").drive_number)
|
27
|
+
assert_nil(Pathname.new("\\\\").drive_number)
|
28
|
+
end
|
29
|
+
|
30
|
+
test "drive_number method returns dot for relative paths" do
|
31
|
+
assert_nil(@rel_path.drive_number)
|
32
|
+
end
|
33
|
+
|
34
|
+
test "drive_number method returns expected result for root path" do
|
35
|
+
assert_equal(25, Pathname.new("Z:\\").drive_number)
|
36
|
+
end
|
37
|
+
|
38
|
+
test "drive_number method returns expected result for empty string" do
|
39
|
+
assert_nil(Pathname.new("").drive_number)
|
40
|
+
end
|
41
|
+
|
42
|
+
test "drive_number method returns expected result for dot and dotdot" do
|
43
|
+
assert_nil(Pathname.new(".").drive_number)
|
44
|
+
assert_nil(Pathname.new("..").drive_number)
|
45
|
+
end
|
46
|
+
|
47
|
+
test "drive_number method is not destructive" do
|
48
|
+
str = 'C:/Program Files'
|
49
|
+
assert_nothing_raised{ Pathname.new(str).drive_number }
|
50
|
+
assert_equal('C:/Program Files', str)
|
51
|
+
end
|
52
|
+
|
53
|
+
def teardown
|
54
|
+
@abs_path = nil
|
55
|
+
@unc_path = nil
|
56
|
+
@rel_path = nil
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
########################################################################
|
2
|
+
# test_each.rb
|
3
|
+
#
|
4
|
+
# Test suite for the Pathname#each method.
|
5
|
+
########################################################################
|
6
|
+
require 'pathname2'
|
7
|
+
require 'test-unit'
|
8
|
+
|
9
|
+
class TC_Pathname_Each < Test::Unit::TestCase
|
10
|
+
def setup
|
11
|
+
@path = Pathname.new("C:/Users/foo/bar")
|
12
|
+
end
|
13
|
+
|
14
|
+
test "each basic functionality" do
|
15
|
+
assert_respond_to(@path, :each)
|
16
|
+
assert_nothing_raised{ @path.each{} }
|
17
|
+
end
|
18
|
+
|
19
|
+
test "each returns the expected results" do
|
20
|
+
arr = []
|
21
|
+
@path.each{ |e| arr << e }
|
22
|
+
assert_equal(['C:', 'Users', 'foo', 'bar'], arr)
|
23
|
+
end
|
24
|
+
|
25
|
+
def teardown
|
26
|
+
@path = nil
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
########################################################################
|
2
|
+
# test_facade.rb
|
3
|
+
#
|
4
|
+
# Test suite for the various facade methods.
|
5
|
+
########################################################################
|
6
|
+
require 'test-unit'
|
7
|
+
require 'pathname2'
|
8
|
+
|
9
|
+
class TC_Pathname_Facade < Test::Unit::TestCase
|
10
|
+
def setup
|
11
|
+
@path = Pathname.new("C:/Program Files")
|
12
|
+
end
|
13
|
+
|
14
|
+
test "file facade methods are defined" do
|
15
|
+
File.methods(false).each{ |m| assert_respond_to(@path, m.to_sym) }
|
16
|
+
end
|
17
|
+
|
18
|
+
test "dir facade methods are defined" do
|
19
|
+
Dir.methods(false).each{ |m| assert_respond_to(@path, m.to_sym) }
|
20
|
+
end
|
21
|
+
|
22
|
+
test "fileutils facade methods are defined" do
|
23
|
+
methods = FileUtils.public_instance_methods
|
24
|
+
methods -= File.methods(false)
|
25
|
+
methods -= Dir.methods(false)
|
26
|
+
|
27
|
+
# Ruby 1.9.x and 2.0 incorrectly made some of these methods public
|
28
|
+
methods.delete_if{ |m|
|
29
|
+
m =~ /stream|^ln|identical\?|mode_to_s|^sh|ruby|safe_ln|split_all/i
|
30
|
+
}
|
31
|
+
|
32
|
+
methods.each{ |method|
|
33
|
+
assert_respond_to(@path, method.to_sym)
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
test "find facade works as expected" do
|
38
|
+
assert_respond_to(@path, :find)
|
39
|
+
assert_nothing_raised{ @path.find{} }
|
40
|
+
|
41
|
+
Pathname.new(Dir.pwd).find{ |f|
|
42
|
+
Find.prune if f.match("git")
|
43
|
+
assert_kind_of(Pathname, f)
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
test "custom io methods are defined" do
|
48
|
+
assert_respond_to(@path, :foreach)
|
49
|
+
assert_respond_to(@path, :read)
|
50
|
+
assert_respond_to(@path, :readlines)
|
51
|
+
assert_respond_to(@path, :sysopen)
|
52
|
+
end
|
53
|
+
|
54
|
+
test "exists? facade works as expected" do
|
55
|
+
assert_respond_to(@path, :exists?)
|
56
|
+
assert_nothing_raised{ @path.exists? }
|
57
|
+
assert_true(Pathname.new("C:\\").exists?)
|
58
|
+
assert_false(Pathname.new("X:\\foo\\bar\\baz").exists?)
|
59
|
+
end
|
60
|
+
|
61
|
+
def teardown
|
62
|
+
@path = nil
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
########################################################################
|
2
|
+
# test_is_absolute.rb
|
3
|
+
#
|
4
|
+
# Test suite for the Pathname#absolute method
|
5
|
+
########################################################################
|
6
|
+
require 'test-unit'
|
7
|
+
require 'pathname2'
|
8
|
+
|
9
|
+
class TC_Pathname_IsAbsolute < Test::Unit::TestCase
|
10
|
+
def setup
|
11
|
+
@abs_std = Pathname.new("C:/foo/bar/baz")
|
12
|
+
@abs_unc = Pathname.new("//foo/bar/baz")
|
13
|
+
end
|
14
|
+
|
15
|
+
test "absolute? basic functionality" do
|
16
|
+
assert_respond_to(@abs_std, :absolute?)
|
17
|
+
assert_nothing_raised{ @abs_std.absolute? }
|
18
|
+
assert_boolean(@abs_std.absolute?)
|
19
|
+
end
|
20
|
+
|
21
|
+
test "absolute? method returns true for absolute paths" do
|
22
|
+
assert_true(@abs_std.absolute?)
|
23
|
+
assert_true(@abs_unc.absolute?)
|
24
|
+
end
|
25
|
+
|
26
|
+
test "absolute? method returns false for non-absolute paths" do
|
27
|
+
assert_false(Pathname.new("foo").absolute?)
|
28
|
+
assert_false(Pathname.new("foo/bar").absolute?)
|
29
|
+
end
|
30
|
+
|
31
|
+
test "absolute? method returns false for empty path" do
|
32
|
+
assert_false(Pathname.new("").absolute?)
|
33
|
+
end
|
34
|
+
|
35
|
+
test "absolute? method is not destructive" do
|
36
|
+
str = 'C:/foo'
|
37
|
+
path = Pathname.new(str)
|
38
|
+
assert_nothing_raised{ path.absolute? }
|
39
|
+
assert_equal('C:\foo', path.to_s)
|
40
|
+
assert_equal('C:/foo', str)
|
41
|
+
end
|
42
|
+
|
43
|
+
def teardown
|
44
|
+
@std_absolute = nil
|
45
|
+
@unc_absolute = nil
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
########################################################################
|
2
|
+
# test_is_relative.rb
|
3
|
+
#
|
4
|
+
# Test suite for the Pathname#relative method
|
5
|
+
########################################################################
|
6
|
+
require 'test-unit'
|
7
|
+
require 'pathname2'
|
8
|
+
|
9
|
+
class TC_Pathname_IsRelative < Test::Unit::TestCase
|
10
|
+
def setup
|
11
|
+
@relative = Pathname.new("foo/bar")
|
12
|
+
@absolute = Pathname.new("C:/foo/bar")
|
13
|
+
end
|
14
|
+
|
15
|
+
test "relative? basic functionality" do
|
16
|
+
assert_respond_to(@relative, :relative?)
|
17
|
+
assert_nothing_raised{ @relative.relative? }
|
18
|
+
assert_boolean(@relative.relative?)
|
19
|
+
end
|
20
|
+
|
21
|
+
test "relative? method returns true for relative paths" do
|
22
|
+
assert_true(@relative.relative?)
|
23
|
+
end
|
24
|
+
|
25
|
+
test "relative? method returns false for non-relative paths" do
|
26
|
+
assert_false(@absolute.relative?)
|
27
|
+
assert_false(Pathname.new("//foo/bar").relative?)
|
28
|
+
end
|
29
|
+
|
30
|
+
test "relative? method returns true for empty path" do
|
31
|
+
assert_true(Pathname.new("").relative?)
|
32
|
+
end
|
33
|
+
|
34
|
+
test "relative? method is not destructive" do
|
35
|
+
str = 'C:/foo'
|
36
|
+
path = Pathname.new(str)
|
37
|
+
assert_nothing_raised{ path.relative? }
|
38
|
+
assert_equal('C:\foo', path.to_s)
|
39
|
+
assert_equal('C:/foo', str)
|
40
|
+
end
|
41
|
+
|
42
|
+
def teardown
|
43
|
+
@std_relative = nil
|
44
|
+
@unc_relative = nil
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
########################################################################
|
2
|
+
# test_is_root.rb
|
3
|
+
#
|
4
|
+
# Test suite for the Pathname#root method
|
5
|
+
########################################################################
|
6
|
+
require 'test-unit'
|
7
|
+
require 'pathname2'
|
8
|
+
|
9
|
+
class TC_Pathname_IsRoot < Test::Unit::TestCase
|
10
|
+
def setup
|
11
|
+
@std_root = Pathname.new("C:\\")
|
12
|
+
@unc_root = Pathname.new("\\\\foo\\bar")
|
13
|
+
end
|
14
|
+
|
15
|
+
test "root? basic functionality" do
|
16
|
+
assert_respond_to(@std_root, :root?)
|
17
|
+
assert_nothing_raised{ @std_root.root? }
|
18
|
+
assert_boolean(@std_root.root?)
|
19
|
+
end
|
20
|
+
|
21
|
+
test "root? method returns true for root paths" do
|
22
|
+
assert_true(@std_root.root?)
|
23
|
+
assert_true(@unc_root.root?)
|
24
|
+
end
|
25
|
+
|
26
|
+
test "root? method returns false for non-root paths" do
|
27
|
+
assert_false(Pathname.new("C:/foo").root?)
|
28
|
+
assert_false(Pathname.new("//foo/bar/baz").root?)
|
29
|
+
assert_false(Pathname.new("").root?)
|
30
|
+
end
|
31
|
+
|
32
|
+
test "root? method is not destructive" do
|
33
|
+
str = 'C:/foo'
|
34
|
+
path = Pathname.new(str)
|
35
|
+
assert_nothing_raised{ path.root }
|
36
|
+
assert_equal('C:\foo', path.to_s)
|
37
|
+
assert_equal('C:/foo', str)
|
38
|
+
end
|
39
|
+
|
40
|
+
def teardown
|
41
|
+
@std_root = nil
|
42
|
+
@unc_root = nil
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
########################################################################
|
2
|
+
# test_is_unc.rb
|
3
|
+
#
|
4
|
+
# Test suite for the Pathname#unc? method
|
5
|
+
########################################################################
|
6
|
+
require 'test-unit'
|
7
|
+
require 'pathname2'
|
8
|
+
|
9
|
+
class TC_Pathname_IsUNC < Test::Unit::TestCase
|
10
|
+
def setup
|
11
|
+
@abs_path = Pathname.new("C:\\Program Files")
|
12
|
+
@unc_path = Pathname.new("\\\\foo\\bar\\baz")
|
13
|
+
@rel_path = Pathname.new("foo\\bar\\baz")
|
14
|
+
end
|
15
|
+
|
16
|
+
test "unc? basic functionality" do
|
17
|
+
assert_respond_to(@unc_path, :unc?)
|
18
|
+
assert_nothing_raised{ @unc_path.unc? }
|
19
|
+
assert_boolean(@unc_path.unc?)
|
20
|
+
end
|
21
|
+
|
22
|
+
test "unc? method returns false for non-unc paths" do
|
23
|
+
assert_false(Pathname.new("C:\\").unc?)
|
24
|
+
assert_false(Pathname.new("C:\\Program Files").unc?)
|
25
|
+
assert_false(Pathname.new("C:\\\\Program Files").unc?)
|
26
|
+
assert_false(Pathname.new("C:/Program Files/File.txt").unc?)
|
27
|
+
assert_false(Pathname.new("C:\\Program Files\\File[12].txt").unc?)
|
28
|
+
assert_false(Pathname.new("foo\\bar").unc?)
|
29
|
+
assert_false(Pathname.new(".").unc?)
|
30
|
+
end
|
31
|
+
|
32
|
+
test "unc? method returns true for unc paths" do
|
33
|
+
assert_true(Pathname.new("\\\\foo\\bar").unc?)
|
34
|
+
assert_true(Pathname.new("//foo/bar").unc?)
|
35
|
+
assert_true(Pathname.new("\\\\foo\\bar\\baz").unc?)
|
36
|
+
assert_true(Pathname.new("\\\\foo").unc?)
|
37
|
+
assert_true(Pathname.new("\\\\").unc?)
|
38
|
+
end
|
39
|
+
|
40
|
+
test "unc? method is not destructive" do
|
41
|
+
str = '//foo/bar'
|
42
|
+
assert_nothing_raised{ Pathname.new(str).unc? }
|
43
|
+
assert_equal('//foo/bar', str)
|
44
|
+
end
|
45
|
+
|
46
|
+
def teardown
|
47
|
+
@abs_path = nil
|
48
|
+
@unc_path = nil
|
49
|
+
@rel_path = nil
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
########################################################################
|
2
|
+
# test_long_path.rb
|
3
|
+
#
|
4
|
+
# Test suite for the Pathname#long_path method
|
5
|
+
########################################################################
|
6
|
+
require 'test-unit'
|
7
|
+
require 'pathname2'
|
8
|
+
|
9
|
+
class TC_Pathname_LongPath < Test::Unit::TestCase
|
10
|
+
def setup
|
11
|
+
@abs_path = Pathname.new("C:\\PROGRA~1")
|
12
|
+
end
|
13
|
+
|
14
|
+
test "long_path basic functionality" do
|
15
|
+
assert_respond_to(@abs_path, :long_path)
|
16
|
+
assert_nothing_raised{ @abs_path.long_path }
|
17
|
+
assert_kind_of(String, @abs_path.long_path)
|
18
|
+
end
|
19
|
+
|
20
|
+
test "long_path returns the expected result" do
|
21
|
+
assert_equal("C:\\Program Files", @abs_path.long_path)
|
22
|
+
end
|
23
|
+
|
24
|
+
test "long_path returns the same string if it's already long" do
|
25
|
+
assert_equal("C:\\Program Files", Pathname.new("C:/Program Files").long_path)
|
26
|
+
end
|
27
|
+
|
28
|
+
test "long_path fails if the path does not exist" do
|
29
|
+
assert_raise(Errno::ESRCH){ Pathname.new("C:/Bogus/AlsoBogus").long_path }
|
30
|
+
end
|
31
|
+
|
32
|
+
test "long_path method is not destructive" do
|
33
|
+
str = 'C:/Program Files'
|
34
|
+
assert_nothing_raised{ Pathname.new(str).long_path }
|
35
|
+
assert_equal('C:/Program Files', str)
|
36
|
+
end
|
37
|
+
|
38
|
+
def teardown
|
39
|
+
@abs_path = nil
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
########################################################################
|
2
|
+
# test_misc.rb
|
3
|
+
#
|
4
|
+
# Test suite for miscellaneous items that didn't warrant their own
|
5
|
+
# test file.
|
6
|
+
########################################################################
|
7
|
+
require 'pathname2'
|
8
|
+
require 'test-unit'
|
9
|
+
|
10
|
+
class MyPathname < Pathname; end
|
11
|
+
|
12
|
+
class TC_Pathname_Misc < Test::Unit::TestCase
|
13
|
+
def setup
|
14
|
+
@mypath = MyPathname.new(Dir.pwd)
|
15
|
+
end
|
16
|
+
|
17
|
+
test "subclasses return instances of that subclass" do
|
18
|
+
assert_kind_of(MyPathname, @mypath)
|
19
|
+
assert_kind_of(MyPathname, @mypath + MyPathname.new('foo'))
|
20
|
+
assert_kind_of(MyPathname, @mypath.realpath)
|
21
|
+
end
|
22
|
+
|
23
|
+
test "custom pn method works as expected" do
|
24
|
+
assert_respond_to(Kernel, :pn)
|
25
|
+
assert_nothing_raised{ pn{'c:\foo'} }
|
26
|
+
assert_kind_of(Pathname, pn{'c:\foo'})
|
27
|
+
assert_equal('c:\foo', pn{'c:\foo'})
|
28
|
+
end
|
29
|
+
|
30
|
+
def teardown
|
31
|
+
@mypath = nil
|
32
|
+
end
|
33
|
+
end
|