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
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
########################################################################
|
|
2
2
|
# test_descend.rb
|
|
3
3
|
#
|
|
4
|
-
# Test suite for the
|
|
4
|
+
# Test suite for the Pathname2#descend method.
|
|
5
5
|
########################################################################
|
|
6
6
|
require 'pathname2'
|
|
7
7
|
require 'test-unit'
|
|
8
8
|
|
|
9
|
-
class
|
|
9
|
+
class TC_Pathname2_Descend < 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 "descend basic functionality" do
|
|
@@ -27,14 +27,14 @@ class TC_Pathname_Descend < Test::Unit::TestCase
|
|
|
27
27
|
|
|
28
28
|
test "descend works as expected on a UNC path" do
|
|
29
29
|
array = []
|
|
30
|
-
|
|
30
|
+
Pathname2.new('//foo/bar/baz').descend{ |e| array << e }
|
|
31
31
|
assert_equal("\\\\foo\\bar", array[0])
|
|
32
32
|
assert_equal("\\\\foo\\bar\\baz", array[1])
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
test "descend works as expected on a relative path" do
|
|
36
36
|
array = []
|
|
37
|
-
|
|
37
|
+
Pathname2.new('foo/bar/baz').descend{ |e| array << e }
|
|
38
38
|
assert_equal('foo', array[0])
|
|
39
39
|
assert_equal('foo\bar', array[1])
|
|
40
40
|
assert_equal('foo\bar\baz', array[2])
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
########################################################################
|
|
2
2
|
# test_drive_number.rb
|
|
3
3
|
#
|
|
4
|
-
# Test suite for the
|
|
4
|
+
# Test suite for the Pathname2#drive_number method
|
|
5
5
|
########################################################################
|
|
6
6
|
require 'test-unit'
|
|
7
7
|
require 'pathname2'
|
|
8
8
|
|
|
9
|
-
class
|
|
9
|
+
class TC_Pathname2_DriveNumber < Test::Unit::TestCase
|
|
10
10
|
def setup
|
|
11
|
-
@abs_path =
|
|
12
|
-
@unc_path =
|
|
13
|
-
@rel_path =
|
|
11
|
+
@abs_path = Pathname2.new("C:\\Program Files")
|
|
12
|
+
@unc_path = Pathname2.new("\\\\foo\\bar\\baz")
|
|
13
|
+
@rel_path = Pathname2.new("foo\\bar\\baz")
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
test "drive_number method returns expected results for absolute paths" do
|
|
@@ -18,13 +18,13 @@ class TC_Pathname_DriveNumber < Test::Unit::TestCase
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
test "drive_number method returns expected results for paths with forward slashes" do
|
|
21
|
-
assert_equal(2,
|
|
21
|
+
assert_equal(2, Pathname2.new("C:/Program Files").drive_number)
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
test "drive_number method returns expected results for unc paths" do
|
|
25
25
|
assert_nil(@unc_path.drive_number)
|
|
26
|
-
assert_nil(
|
|
27
|
-
assert_nil(
|
|
26
|
+
assert_nil(Pathname2.new("\\\\foo").drive_number)
|
|
27
|
+
assert_nil(Pathname2.new("\\\\").drive_number)
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
test "drive_number method returns dot for relative paths" do
|
|
@@ -32,21 +32,21 @@ class TC_Pathname_DriveNumber < Test::Unit::TestCase
|
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
test "drive_number method returns expected result for root path" do
|
|
35
|
-
assert_equal(25,
|
|
35
|
+
assert_equal(25, Pathname2.new("Z:\\").drive_number)
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
test "drive_number method returns expected result for empty string" do
|
|
39
|
-
assert_nil(
|
|
39
|
+
assert_nil(Pathname2.new("").drive_number)
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
test "drive_number method returns expected result for dot and dotdot" do
|
|
43
|
-
assert_nil(
|
|
44
|
-
assert_nil(
|
|
43
|
+
assert_nil(Pathname2.new(".").drive_number)
|
|
44
|
+
assert_nil(Pathname2.new("..").drive_number)
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
test "drive_number method is not destructive" do
|
|
48
48
|
str = 'C:/Program Files'
|
|
49
|
-
assert_nothing_raised{
|
|
49
|
+
assert_nothing_raised{ Pathname2.new(str).drive_number }
|
|
50
50
|
assert_equal('C:/Program Files', str)
|
|
51
51
|
end
|
|
52
52
|
|
data/test/windows/test_each.rb
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
########################################################################
|
|
2
2
|
# test_each.rb
|
|
3
3
|
#
|
|
4
|
-
# Test suite for the
|
|
4
|
+
# Test suite for the Pathname2#each method.
|
|
5
5
|
########################################################################
|
|
6
6
|
require 'pathname2'
|
|
7
7
|
require 'test-unit'
|
|
8
8
|
|
|
9
|
-
class
|
|
9
|
+
class TC_Pathname2_Each < Test::Unit::TestCase
|
|
10
10
|
def setup
|
|
11
|
-
@path =
|
|
11
|
+
@path = Pathname2.new("C:/Users/foo/bar")
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
test "each basic functionality" do
|
data/test/windows/test_facade.rb
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
require 'test-unit'
|
|
7
7
|
require 'pathname2'
|
|
8
8
|
|
|
9
|
-
class
|
|
9
|
+
class TC_Pathname2_Facade < Test::Unit::TestCase
|
|
10
10
|
def setup
|
|
11
|
-
@path =
|
|
11
|
+
@path = Pathname2.new("C:/Program Files")
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
test "file facade methods are defined" do
|
|
@@ -38,9 +38,9 @@ class TC_Pathname_Facade < Test::Unit::TestCase
|
|
|
38
38
|
assert_respond_to(@path, :find)
|
|
39
39
|
assert_nothing_raised{ @path.find{} }
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
Pathname2.new(Dir.pwd).find{ |f|
|
|
42
42
|
Find.prune if f.match("git")
|
|
43
|
-
assert_kind_of(
|
|
43
|
+
assert_kind_of(Pathname2, f)
|
|
44
44
|
}
|
|
45
45
|
end
|
|
46
46
|
|
|
@@ -54,8 +54,8 @@ class TC_Pathname_Facade < Test::Unit::TestCase
|
|
|
54
54
|
test "exist? facade works as expected" do
|
|
55
55
|
assert_respond_to(@path, :exist?)
|
|
56
56
|
assert_nothing_raised{ @path.exist? }
|
|
57
|
-
assert_true(
|
|
58
|
-
assert_false(
|
|
57
|
+
assert_true(Pathname2.new("C:\\").exist?)
|
|
58
|
+
assert_false(Pathname2.new("X:\\foo\\bar\\baz").exist?)
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
def teardown
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
########################################################################
|
|
2
2
|
# test_is_absolute.rb
|
|
3
3
|
#
|
|
4
|
-
# Test suite for the
|
|
4
|
+
# Test suite for the Pathname2#absolute method
|
|
5
5
|
########################################################################
|
|
6
6
|
require 'test-unit'
|
|
7
7
|
require 'pathname2'
|
|
8
8
|
|
|
9
|
-
class
|
|
9
|
+
class TC_Pathname2_IsAbsolute < Test::Unit::TestCase
|
|
10
10
|
def setup
|
|
11
|
-
@abs_std =
|
|
12
|
-
@abs_unc =
|
|
11
|
+
@abs_std = Pathname2.new("C:/foo/bar/baz")
|
|
12
|
+
@abs_unc = Pathname2.new("//foo/bar/baz")
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
test "absolute? basic functionality" do
|
|
@@ -24,17 +24,17 @@ class TC_Pathname_IsAbsolute < Test::Unit::TestCase
|
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
test "absolute? method returns false for non-absolute paths" do
|
|
27
|
-
assert_false(
|
|
28
|
-
assert_false(
|
|
27
|
+
assert_false(Pathname2.new("foo").absolute?)
|
|
28
|
+
assert_false(Pathname2.new("foo/bar").absolute?)
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
test "absolute? method returns false for empty path" do
|
|
32
|
-
assert_false(
|
|
32
|
+
assert_false(Pathname2.new("").absolute?)
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
test "absolute? method is not destructive" do
|
|
36
36
|
str = 'C:/foo'
|
|
37
|
-
path =
|
|
37
|
+
path = Pathname2.new(str)
|
|
38
38
|
assert_nothing_raised{ path.absolute? }
|
|
39
39
|
assert_equal('C:\foo', path.to_s)
|
|
40
40
|
assert_equal('C:/foo', str)
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
########################################################################
|
|
2
2
|
# test_is_relative.rb
|
|
3
3
|
#
|
|
4
|
-
# Test suite for the
|
|
4
|
+
# Test suite for the Pathname2#relative method
|
|
5
5
|
########################################################################
|
|
6
6
|
require 'test-unit'
|
|
7
7
|
require 'pathname2'
|
|
8
8
|
|
|
9
|
-
class
|
|
9
|
+
class TC_Pathname2_IsRelative < Test::Unit::TestCase
|
|
10
10
|
def setup
|
|
11
|
-
@relative =
|
|
12
|
-
@absolute =
|
|
11
|
+
@relative = Pathname2.new("foo/bar")
|
|
12
|
+
@absolute = Pathname2.new("C:/foo/bar")
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
test "relative? basic functionality" do
|
|
@@ -24,16 +24,16 @@ class TC_Pathname_IsRelative < Test::Unit::TestCase
|
|
|
24
24
|
|
|
25
25
|
test "relative? method returns false for non-relative paths" do
|
|
26
26
|
assert_false(@absolute.relative?)
|
|
27
|
-
assert_false(
|
|
27
|
+
assert_false(Pathname2.new("//foo/bar").relative?)
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
test "relative? method returns true for empty path" do
|
|
31
|
-
assert_true(
|
|
31
|
+
assert_true(Pathname2.new("").relative?)
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
test "relative? method is not destructive" do
|
|
35
35
|
str = 'C:/foo'
|
|
36
|
-
path =
|
|
36
|
+
path = Pathname2.new(str)
|
|
37
37
|
assert_nothing_raised{ path.relative? }
|
|
38
38
|
assert_equal('C:\foo', path.to_s)
|
|
39
39
|
assert_equal('C:/foo', str)
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
########################################################################
|
|
2
2
|
# test_is_root.rb
|
|
3
3
|
#
|
|
4
|
-
# Test suite for the
|
|
4
|
+
# Test suite for the Pathname2#root method
|
|
5
5
|
########################################################################
|
|
6
6
|
require 'test-unit'
|
|
7
7
|
require 'pathname2'
|
|
8
8
|
|
|
9
|
-
class
|
|
9
|
+
class TC_Pathname2_IsRoot < Test::Unit::TestCase
|
|
10
10
|
def setup
|
|
11
|
-
@std_root =
|
|
12
|
-
@unc_root =
|
|
11
|
+
@std_root = Pathname2.new("C:\\")
|
|
12
|
+
@unc_root = Pathname2.new("\\\\foo\\bar")
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
test "root? basic functionality" do
|
|
@@ -24,14 +24,14 @@ class TC_Pathname_IsRoot < Test::Unit::TestCase
|
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
test "root? method returns false for non-root paths" do
|
|
27
|
-
assert_false(
|
|
28
|
-
assert_false(
|
|
29
|
-
assert_false(
|
|
27
|
+
assert_false(Pathname2.new("C:/foo").root?)
|
|
28
|
+
assert_false(Pathname2.new("//foo/bar/baz").root?)
|
|
29
|
+
assert_false(Pathname2.new("").root?)
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
test "root? method is not destructive" do
|
|
33
33
|
str = 'C:/foo'
|
|
34
|
-
path =
|
|
34
|
+
path = Pathname2.new(str)
|
|
35
35
|
assert_nothing_raised{ path.root }
|
|
36
36
|
assert_equal('C:\foo', path.to_s)
|
|
37
37
|
assert_equal('C:/foo', str)
|
data/test/windows/test_is_unc.rb
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
########################################################################
|
|
2
2
|
# test_is_unc.rb
|
|
3
3
|
#
|
|
4
|
-
# Test suite for the
|
|
4
|
+
# Test suite for the Pathname2#unc? method
|
|
5
5
|
########################################################################
|
|
6
6
|
require 'test-unit'
|
|
7
7
|
require 'pathname2'
|
|
8
8
|
|
|
9
|
-
class
|
|
9
|
+
class TC_Pathname2_IsUNC < Test::Unit::TestCase
|
|
10
10
|
def setup
|
|
11
|
-
@abs_path =
|
|
12
|
-
@unc_path =
|
|
13
|
-
@rel_path =
|
|
11
|
+
@abs_path = Pathname2.new("C:\\Program Files")
|
|
12
|
+
@unc_path = Pathname2.new("\\\\foo\\bar\\baz")
|
|
13
|
+
@rel_path = Pathname2.new("foo\\bar\\baz")
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
test "unc? basic functionality" do
|
|
@@ -20,26 +20,26 @@ class TC_Pathname_IsUNC < Test::Unit::TestCase
|
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
test "unc? method returns false for non-unc paths" do
|
|
23
|
-
assert_false(
|
|
24
|
-
assert_false(
|
|
25
|
-
assert_false(
|
|
26
|
-
assert_false(
|
|
27
|
-
assert_false(
|
|
28
|
-
assert_false(
|
|
29
|
-
assert_false(
|
|
23
|
+
assert_false(Pathname2.new("C:\\").unc?)
|
|
24
|
+
assert_false(Pathname2.new("C:\\Program Files").unc?)
|
|
25
|
+
assert_false(Pathname2.new("C:\\\\Program Files").unc?)
|
|
26
|
+
assert_false(Pathname2.new("C:/Program Files/File.txt").unc?)
|
|
27
|
+
assert_false(Pathname2.new("C:\\Program Files\\File[12].txt").unc?)
|
|
28
|
+
assert_false(Pathname2.new("foo\\bar").unc?)
|
|
29
|
+
assert_false(Pathname2.new(".").unc?)
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
test "unc? method returns true for unc paths" do
|
|
33
|
-
assert_true(
|
|
34
|
-
assert_true(
|
|
35
|
-
assert_true(
|
|
36
|
-
assert_true(
|
|
37
|
-
assert_true(
|
|
33
|
+
assert_true(Pathname2.new("\\\\foo\\bar").unc?)
|
|
34
|
+
assert_true(Pathname2.new("//foo/bar").unc?)
|
|
35
|
+
assert_true(Pathname2.new("\\\\foo\\bar\\baz").unc?)
|
|
36
|
+
assert_true(Pathname2.new("\\\\foo").unc?)
|
|
37
|
+
assert_true(Pathname2.new("\\\\").unc?)
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
test "unc? method is not destructive" do
|
|
41
41
|
str = '//foo/bar'
|
|
42
|
-
assert_nothing_raised{
|
|
42
|
+
assert_nothing_raised{ Pathname2.new(str).unc? }
|
|
43
43
|
assert_equal('//foo/bar', str)
|
|
44
44
|
end
|
|
45
45
|
|
data/test/windows/test_join.rb
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
########################################################################
|
|
2
2
|
# test_join.rb
|
|
3
3
|
#
|
|
4
|
-
# Test suite for the
|
|
4
|
+
# Test suite for the Pathname2#join method.
|
|
5
5
|
########################################################################
|
|
6
6
|
require 'test-unit'
|
|
7
7
|
require 'pathname2'
|
|
8
8
|
|
|
9
|
-
class
|
|
9
|
+
class TC_Pathname2_Join < Test::Unit::TestCase
|
|
10
10
|
def setup
|
|
11
|
-
@apath =
|
|
12
|
-
@rpath =
|
|
11
|
+
@apath = Pathname2.new("C:\\foo\\bar")
|
|
12
|
+
@rpath = Pathname2.new("foo\\bar\\baz")
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def assert_pathname_join(final, initial, *rest)
|
|
16
|
-
a =
|
|
17
|
-
b =
|
|
16
|
+
a = Pathname2.new(final)
|
|
17
|
+
b = Pathname2.new(initial)
|
|
18
18
|
assert_equal(a, b.join(*rest))
|
|
19
19
|
end
|
|
20
20
|
|
|
@@ -41,8 +41,8 @@ class TC_Pathname_Join < Test::Unit::TestCase
|
|
|
41
41
|
assert_pathname_join("D:\\", "C:\\", "foo", "bar", "D:\\")
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
-
test "join returns an instance of
|
|
45
|
-
assert_kind_of(
|
|
44
|
+
test "join returns an instance of Pathname2" do
|
|
45
|
+
assert_kind_of(Pathname2, @apath.join("foo"))
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
def teardown
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
########################################################################
|
|
2
2
|
# test_long_path.rb
|
|
3
3
|
#
|
|
4
|
-
# Test suite for the
|
|
4
|
+
# Test suite for the Pathname2#long_path method
|
|
5
5
|
########################################################################
|
|
6
6
|
require 'test-unit'
|
|
7
7
|
require 'pathname2'
|
|
8
8
|
|
|
9
|
-
class
|
|
9
|
+
class TC_Pathname2_LongPath < Test::Unit::TestCase
|
|
10
10
|
def setup
|
|
11
|
-
@abs_path =
|
|
11
|
+
@abs_path = Pathname2.new("C:\\PROGRA~1")
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
test "long_path basic functionality" do
|
|
@@ -22,16 +22,16 @@ class TC_Pathname_LongPath < Test::Unit::TestCase
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
test "long_path returns the same string if it's already long" do
|
|
25
|
-
assert_equal("C:\\Program Files",
|
|
25
|
+
assert_equal("C:\\Program Files", Pathname2.new("C:/Program Files").long_path)
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
test "long_path fails if the path does not exist" do
|
|
29
|
-
assert_raise(Errno::ESRCH){
|
|
29
|
+
assert_raise(Errno::ESRCH){ Pathname2.new("C:/Bogus/AlsoBogus").long_path }
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
test "long_path method is not destructive" do
|
|
33
33
|
str = 'C:/Program Files'
|
|
34
|
-
assert_nothing_raised{
|
|
34
|
+
assert_nothing_raised{ Pathname2.new(str).long_path }
|
|
35
35
|
assert_equal('C:/Program Files', str)
|
|
36
36
|
end
|
|
37
37
|
|
data/test/windows/test_misc.rb
CHANGED
|
@@ -7,23 +7,23 @@
|
|
|
7
7
|
require 'pathname2'
|
|
8
8
|
require 'test-unit'
|
|
9
9
|
|
|
10
|
-
class
|
|
10
|
+
class MyPathname2 < Pathname2; end
|
|
11
11
|
|
|
12
|
-
class
|
|
12
|
+
class TC_Pathname2_Misc < Test::Unit::TestCase
|
|
13
13
|
def setup
|
|
14
|
-
@mypath =
|
|
14
|
+
@mypath = MyPathname2.new(Dir.pwd)
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
test "subclasses return instances of that subclass" do
|
|
18
|
-
assert_kind_of(
|
|
19
|
-
assert_kind_of(
|
|
20
|
-
assert_kind_of(
|
|
18
|
+
assert_kind_of(MyPathname2, @mypath)
|
|
19
|
+
assert_kind_of(MyPathname2, @mypath + MyPathname2.new('foo'))
|
|
20
|
+
assert_kind_of(MyPathname2, @mypath.realpath)
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
test "custom pn method works as expected" do
|
|
24
24
|
assert_respond_to(Kernel, :pn)
|
|
25
25
|
assert_nothing_raised{ pn{'c:\foo'} }
|
|
26
|
-
assert_kind_of(
|
|
26
|
+
assert_kind_of(Pathname2, pn{'c:\foo'})
|
|
27
27
|
assert_equal('c:\foo', pn{'c:\foo'})
|
|
28
28
|
end
|
|
29
29
|
|
data/test/windows/test_parent.rb
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
########################################################################
|
|
2
2
|
# test_parent.rb
|
|
3
3
|
#
|
|
4
|
-
# Test suite for the
|
|
4
|
+
# Test suite for the Pathname2#parent method.
|
|
5
5
|
########################################################################
|
|
6
6
|
require 'test-unit'
|
|
7
7
|
require 'pathname2'
|
|
8
8
|
|
|
9
|
-
class
|
|
9
|
+
class TC_Pathname2_Parent < 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 "parent basic functionality" do
|
|
15
15
|
assert_respond_to(@path, :parent)
|
|
16
16
|
assert_nothing_raised{ @path.parent }
|
|
17
|
-
assert_kind_of(
|
|
17
|
+
assert_kind_of(Pathname2, @path.parent)
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
test "parent returns expected results for an absolute path" do
|
|
21
|
-
assert_equal("C:\\foo\\bar",
|
|
22
|
-
assert_equal("C:\\",
|
|
21
|
+
assert_equal("C:\\foo\\bar", Pathname2.new("C:\\foo\\bar\\baz").parent)
|
|
22
|
+
assert_equal("C:\\", Pathname2.new("C:\\foo").parent)
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
test "parent returns expected results for a relative path" do
|
|
26
|
-
assert_equal("foo",
|
|
26
|
+
assert_equal("foo", Pathname2.new("foo\\bar").parent)
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
test "parent method returns root if already a root path" do
|
|
30
|
-
assert_equal("C:\\",
|
|
31
|
-
assert_equal("\\\\foo\\bar",
|
|
30
|
+
assert_equal("C:\\", Pathname2.new("C:\\").parent)
|
|
31
|
+
assert_equal("\\\\foo\\bar", Pathname2.new("//foo/bar").parent)
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
def teardown
|
data/test/windows/test_pstrip.rb
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
########################################################################
|
|
2
2
|
# test_pstrip.rb
|
|
3
3
|
#
|
|
4
|
-
# Test suite for the
|
|
4
|
+
# Test suite for the Pathname2#pstrip method
|
|
5
5
|
########################################################################
|
|
6
6
|
require 'test-unit'
|
|
7
7
|
require 'pathname2'
|
|
8
8
|
|
|
9
|
-
class
|
|
9
|
+
class TC_Pathname2_Pstrip < Test::Unit::TestCase
|
|
10
10
|
def setup
|
|
11
|
-
@path =
|
|
11
|
+
@path = Pathname2.new("C:/Program Files////")
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
test "pstrip basic functionality" do
|
|
15
15
|
assert_respond_to(@path, :pstrip)
|
|
16
16
|
assert_nothing_raised{ @path.pstrip }
|
|
17
|
-
assert_kind_of(
|
|
17
|
+
assert_kind_of(Pathname2, @path.pstrip)
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
test "pstrip returns expected result for path with trailing slashes" do
|
|
21
21
|
assert_equal("C:\\Program Files", @path.pstrip)
|
|
22
|
-
assert_equal("C:\\Program Files",
|
|
23
|
-
assert_equal("C:\\Program Files",
|
|
22
|
+
assert_equal("C:\\Program Files", Pathname2.new("C:\\Program Files\\\\").pstrip)
|
|
23
|
+
assert_equal("C:\\Program Files", Pathname2.new("C:\\Program Files//\\").pstrip)
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
test "pstrip returns the path as is if it does not contain a trailing slash" do
|
|
27
|
-
assert_equal("C:\\Program Files",
|
|
28
|
-
assert_equal("",
|
|
27
|
+
assert_equal("C:\\Program Files", Pathname2.new("C:\\Program Files").pstrip)
|
|
28
|
+
assert_equal("", Pathname2.new("").pstrip)
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
test "pstrip method is not destructive" do
|
|
32
32
|
str = 'C:/Program Files////'
|
|
33
|
-
assert_nothing_raised{
|
|
33
|
+
assert_nothing_raised{ Pathname2.new(str).pstrip }
|
|
34
34
|
assert_equal('C:/Program Files////', str)
|
|
35
35
|
end
|
|
36
36
|
|
|
@@ -1,42 +1,42 @@
|
|
|
1
1
|
########################################################################
|
|
2
2
|
# test_pstrip_bang.rb
|
|
3
3
|
#
|
|
4
|
-
# Test suite for the
|
|
4
|
+
# Test suite for the Pathname2#pstrip! method
|
|
5
5
|
########################################################################
|
|
6
6
|
require 'test-unit'
|
|
7
7
|
require 'pathname2'
|
|
8
8
|
|
|
9
|
-
class
|
|
9
|
+
class TC_Pathname2_PstripBang < Test::Unit::TestCase
|
|
10
10
|
def setup
|
|
11
|
-
@path =
|
|
11
|
+
@path = Pathname2.new("C:/Program Files////")
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
test "pstrip! basic functionality" do
|
|
15
15
|
assert_respond_to(@path, :pstrip!)
|
|
16
16
|
assert_nothing_raised{ @path.pstrip! }
|
|
17
|
-
assert_kind_of(
|
|
17
|
+
assert_kind_of(Pathname2, @path.pstrip!)
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
test "pstrip! returns expected result for path with trailing slashes" do
|
|
21
21
|
assert_equal("C:\\Program Files", @path.pstrip!)
|
|
22
|
-
assert_equal("C:\\Program Files",
|
|
23
|
-
assert_equal("C:\\Program Files",
|
|
22
|
+
assert_equal("C:\\Program Files", Pathname2.new("C:\\Program Files\\\\").pstrip!)
|
|
23
|
+
assert_equal("C:\\Program Files", Pathname2.new("C:\\Program Files//\\").pstrip!)
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
test "pstrip! returns the path as is if it does not contain a trailing slash" do
|
|
27
|
-
assert_equal("C:\\Program Files",
|
|
28
|
-
assert_equal("",
|
|
27
|
+
assert_equal("C:\\Program Files", Pathname2.new("C:\\Program Files").pstrip!)
|
|
28
|
+
assert_equal("", Pathname2.new("").pstrip!)
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
test "pstrip! alters pathname object" do
|
|
32
|
-
path =
|
|
32
|
+
path = Pathname2.new('C:/Program Files////')
|
|
33
33
|
assert_nothing_raised{ path.pstrip! }
|
|
34
34
|
assert_equal('C:\Program Files', path.to_s)
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
test "pstrip! method does not modify original constructor argument" do
|
|
38
38
|
str = 'C:/Program Files////'
|
|
39
|
-
assert_nothing_raised{
|
|
39
|
+
assert_nothing_raised{ Pathname2.new(str).pstrip! }
|
|
40
40
|
assert_equal('C:/Program Files////', str)
|
|
41
41
|
end
|
|
42
42
|
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
########################################################################
|
|
2
2
|
# test_realpath.rb
|
|
3
3
|
#
|
|
4
|
-
# Test suite for the
|
|
4
|
+
# Test suite for the Pathname2#realpath method
|
|
5
5
|
########################################################################
|
|
6
6
|
require 'test-unit'
|
|
7
7
|
require 'pathname2'
|
|
8
8
|
|
|
9
|
-
class
|
|
9
|
+
class TC_Pathname2_Realpath < Test::Unit::TestCase
|
|
10
10
|
def setup
|
|
11
11
|
@cwd = Dir.pwd.tr('/', "\\")
|
|
12
|
-
@path =
|
|
12
|
+
@path = Pathname2.new(Dir.pwd)
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
test "realpath basic functionality" do
|
|
@@ -23,12 +23,12 @@ class TC_Pathname_Realpath < Test::Unit::TestCase
|
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
test "realpath fails if the path does not exist" do
|
|
26
|
-
assert_raise(Errno::ENOENT){
|
|
26
|
+
assert_raise(Errno::ENOENT){ Pathname2.new("C:/Bogus/AlsoBogus").realpath }
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
test "realpath method is not destructive" do
|
|
30
30
|
str = 'C:/Program Files'
|
|
31
|
-
assert_nothing_raised{
|
|
31
|
+
assert_nothing_raised{ Pathname2.new(str).realpath }
|
|
32
32
|
assert_equal('C:/Program Files', str)
|
|
33
33
|
end
|
|
34
34
|
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
########################################################################
|
|
2
2
|
# test_relative_path_from.rb
|
|
3
3
|
#
|
|
4
|
-
# Test suite for the
|
|
4
|
+
# Test suite for the Pathname2#relative_path_from method.
|
|
5
5
|
########################################################################
|
|
6
6
|
require 'test-unit'
|
|
7
7
|
require 'pathname2'
|
|
8
8
|
|
|
9
|
-
class
|
|
9
|
+
class TC_Pathname2_RelativePathFrom < Test::Unit::TestCase
|
|
10
10
|
def assert_relpath(result, dest, base)
|
|
11
|
-
assert_equal(result,
|
|
11
|
+
assert_equal(result, Pathname2.new(dest).relative_path_from(base))
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def assert_relative_path_error(to, from)
|
|
15
|
-
assert_raise(ArgumentError){
|
|
15
|
+
assert_raise(ArgumentError){ Pathname2.new(to).relative_path_from(from) }
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
test "relative_path_from works as expected between two relative paths" do
|