pathname2 1.0.0 → 1.1.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.
- data/CHANGES +3 -0
- data/lib/pathname2.rb +557 -536
- data/test/tc_pathname.rb +192 -182
- data/test/tc_pathname_win.rb +237 -227
- metadata +5 -5
data/test/tc_pathname.rb
CHANGED
@@ -1,182 +1,192 @@
|
|
1
|
-
##############################################
|
2
|
-
# tc_pathname.rb
|
3
|
-
#
|
4
|
-
# Test suite for the pathname package (Unix)
|
5
|
-
##############################################
|
6
|
-
Dir.chdir ".." if File.basename(Dir.pwd) == "test"
|
7
|
-
$LOAD_PATH.unshift Dir.pwd
|
8
|
-
$LOAD_PATH.unshift Dir.pwd + "/lib"
|
9
|
-
|
10
|
-
require "pathname2"
|
11
|
-
require "test/unit"
|
12
|
-
|
13
|
-
class TC_Pathname < Test::Unit::TestCase
|
14
|
-
def setup
|
15
|
-
@path = Pathname.new("/usr/local/bin")
|
16
|
-
end
|
17
|
-
|
18
|
-
# Convenience method for test_plus
|
19
|
-
def assert_pathname_plus(a, b, c)
|
20
|
-
a = Pathname.new(a)
|
21
|
-
b = Pathname.new(b)
|
22
|
-
c = Pathname.new(c)
|
23
|
-
assert_equal(a, b + c)
|
24
|
-
end
|
25
|
-
|
26
|
-
# Convenience method for test_spaceship operator
|
27
|
-
def assert_pathname_cmp(int, s1, s2)
|
28
|
-
p1 = Pathname.new(s1)
|
29
|
-
p2 = Pathname.new(s2)
|
30
|
-
result = p1 <=> p2
|
31
|
-
assert_equal(int, result)
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_version
|
35
|
-
assert_equal("1.
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_unc
|
39
|
-
assert_raises(NotImplementedError){ @path.unc? }
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_enumerable
|
43
|
-
assert_respond_to(@path, :each)
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_root
|
47
|
-
assert_respond_to(@path, :root)
|
48
|
-
assert_nothing_raised{ @path.root }
|
49
|
-
assert_equal("/", @path.root)
|
50
|
-
|
51
|
-
path1 = Pathname.new("foo")
|
52
|
-
path2 = Pathname.new("foo/bar/baz")
|
53
|
-
assert_equal(".", path1.root)
|
54
|
-
assert_equal(".", path2.root)
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_root?
|
58
|
-
assert_respond_to(@path, :root?)
|
59
|
-
assert_nothing_raised{ @path.root? }
|
60
|
-
|
61
|
-
path1 = Pathname.new("/")
|
62
|
-
path2 = Pathname.new("a")
|
63
|
-
assert_equal(true, path1.root?)
|
64
|
-
assert_equal(false, path2.root?)
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_absolute
|
68
|
-
assert_respond_to(@path, :absolute?)
|
69
|
-
assert_nothing_raised{ @path.absolute? }
|
70
|
-
assert_equal(true, Pathname.new("/usr/bin/ruby").absolute?)
|
71
|
-
assert_equal(false, Pathname.new("foo").absolute?)
|
72
|
-
assert_equal(false, Pathname.new("foo/bar").absolute?)
|
73
|
-
assert_equal(false, Pathname.new("../foo/bar").absolute?)
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_relative
|
77
|
-
assert_respond_to(@path, :relative?)
|
78
|
-
assert_nothing_raised{ @path.relative? }
|
79
|
-
assert_equal(false, Pathname.new("/usr/bin/ruby").relative?)
|
80
|
-
assert_equal(true, Pathname.new("foo").relative?)
|
81
|
-
assert_equal(true, Pathname.new("foo/bar").relative?)
|
82
|
-
assert_equal(true, Pathname.new("../foo/bar").relative?)
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_to_a
|
86
|
-
assert_respond_to(@path, :to_a)
|
87
|
-
assert_nothing_raised{ @path.to_a }
|
88
|
-
assert_kind_of(Array, @path.to_a)
|
89
|
-
assert_equal(%w/usr local bin/, @path.to_a)
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_spaceship_operator
|
93
|
-
assert_respond_to(@path, :<=>)
|
94
|
-
|
95
|
-
assert_pathname_cmp( 0, "/foo/bar", "/foo/bar")
|
96
|
-
assert_pathname_cmp(-1, "/foo/bar", "/foo/zap")
|
97
|
-
assert_pathname_cmp( 1, "/foo/zap", "/foo/bar")
|
98
|
-
assert_pathname_cmp(-1, "foo", "foo/")
|
99
|
-
assert_pathname_cmp(-1, "foo/", "foo/bar")
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_plus_operator
|
103
|
-
assert_respond_to(@path, :+)
|
104
|
-
|
105
|
-
# Standard stuff
|
106
|
-
assert_pathname_plus("/foo/bar", "/foo", "bar")
|
107
|
-
assert_pathname_plus("foo/bar", "foo", "bar")
|
108
|
-
assert_pathname_plus("foo", "foo", ".")
|
109
|
-
assert_pathname_plus("foo", ".", "foo")
|
110
|
-
assert_pathname_plus("/foo", "bar", "/foo")
|
111
|
-
assert_pathname_plus("foo", "foo/bar", "..")
|
112
|
-
assert_pathname_plus("/foo", "/", "../foo")
|
113
|
-
assert_pathname_plus("foo/zap", "foo/bar", "../zap")
|
114
|
-
assert_pathname_plus(".", "foo", "..")
|
115
|
-
assert_pathname_plus("foo", "..", "foo") # Auto clean
|
116
|
-
assert_pathname_plus("foo", "..", "../foo") # Auto clean
|
117
|
-
|
118
|
-
# Edge cases
|
119
|
-
assert_pathname_plus(".", ".", ".")
|
120
|
-
assert_pathname_plus("/", "/", "..")
|
121
|
-
assert_pathname_plus(".", "..", "..")
|
122
|
-
assert_pathname_plus(".", "foo", "..")
|
123
|
-
end
|
124
|
-
|
125
|
-
# Any tests marked with "***" mean that this behavior is different than
|
126
|
-
# the current implementation. It also means I disagree with the current
|
127
|
-
# implementation.
|
128
|
-
def test_cleanpath
|
129
|
-
# Standard stuff
|
130
|
-
assert_equal("/a/b/c", Pathname.new("/a/b/c").cleanpath)
|
131
|
-
assert_equal("b/c", Pathname.new("./b/c").cleanpath)
|
132
|
-
assert_equal("a", Pathname.new("a/.").cleanpath) # ***
|
133
|
-
assert_equal("a/c", Pathname.new("a/./c").cleanpath)
|
134
|
-
assert_equal("a/b", Pathname.new("a/b/.").cleanpath) # ***
|
135
|
-
assert_equal(".", Pathname.new("a/../.").cleanpath) # ***
|
136
|
-
assert_equal("/a", Pathname.new("/a/b/..").cleanpath)
|
137
|
-
assert_equal("/b", Pathname.new("/a/../b").cleanpath)
|
138
|
-
assert_equal("d", Pathname.new("a/../../d").cleanpath) # ***
|
139
|
-
|
140
|
-
# Edge cases
|
141
|
-
assert_equal("", Pathname.new("").cleanpath)
|
142
|
-
assert_equal(".", Pathname.new(".").cleanpath)
|
143
|
-
assert_equal("..", Pathname.new("..").cleanpath)
|
144
|
-
assert_equal('/', Pathname.new('/').cleanpath)
|
145
|
-
assert_equal('/', Pathname.new('//').cleanpath)
|
146
|
-
end
|
147
|
-
|
148
|
-
def test_facade_io
|
149
|
-
assert_respond_to(@path, :foreach)
|
150
|
-
assert_respond_to(@path, :read)
|
151
|
-
assert_respond_to(@path, :readlines)
|
152
|
-
assert_respond_to(@path, :sysopen)
|
153
|
-
end
|
154
|
-
|
155
|
-
def test_facade_file
|
156
|
-
File.methods(false).each{ |method|
|
157
|
-
assert_respond_to(@path, method.to_sym)
|
158
|
-
}
|
159
|
-
end
|
160
|
-
|
161
|
-
def test_facade_dir
|
162
|
-
Dir.methods(false).each{ |method|
|
163
|
-
assert_respond_to(@path, method.to_sym)
|
164
|
-
}
|
165
|
-
end
|
166
|
-
|
167
|
-
def test_facade_fileutils
|
168
|
-
methods = FileUtils.public_instance_methods
|
169
|
-
methods -= File.methods(false)
|
170
|
-
methods -= Dir.methods(false)
|
171
|
-
methods.delete_if{ |m| m =~ /stream/ }
|
172
|
-
methods.delete("identical?")
|
173
|
-
|
174
|
-
methods.each{ |method|
|
175
|
-
assert_respond_to(@path, method.to_sym)
|
176
|
-
}
|
177
|
-
end
|
178
|
-
|
179
|
-
def
|
180
|
-
@path
|
181
|
-
|
182
|
-
|
1
|
+
##############################################
|
2
|
+
# tc_pathname.rb
|
3
|
+
#
|
4
|
+
# Test suite for the pathname package (Unix)
|
5
|
+
##############################################
|
6
|
+
Dir.chdir ".." if File.basename(Dir.pwd) == "test"
|
7
|
+
$LOAD_PATH.unshift Dir.pwd
|
8
|
+
$LOAD_PATH.unshift Dir.pwd + "/lib"
|
9
|
+
|
10
|
+
require "pathname2"
|
11
|
+
require "test/unit"
|
12
|
+
|
13
|
+
class TC_Pathname < Test::Unit::TestCase
|
14
|
+
def setup
|
15
|
+
@path = Pathname.new("/usr/local/bin")
|
16
|
+
end
|
17
|
+
|
18
|
+
# Convenience method for test_plus
|
19
|
+
def assert_pathname_plus(a, b, c)
|
20
|
+
a = Pathname.new(a)
|
21
|
+
b = Pathname.new(b)
|
22
|
+
c = Pathname.new(c)
|
23
|
+
assert_equal(a, b + c)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Convenience method for test_spaceship operator
|
27
|
+
def assert_pathname_cmp(int, s1, s2)
|
28
|
+
p1 = Pathname.new(s1)
|
29
|
+
p2 = Pathname.new(s2)
|
30
|
+
result = p1 <=> p2
|
31
|
+
assert_equal(int, result)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_version
|
35
|
+
assert_equal("1.1.0", Pathname::VERSION)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_unc
|
39
|
+
assert_raises(NotImplementedError){ @path.unc? }
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_enumerable
|
43
|
+
assert_respond_to(@path, :each)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_root
|
47
|
+
assert_respond_to(@path, :root)
|
48
|
+
assert_nothing_raised{ @path.root }
|
49
|
+
assert_equal("/", @path.root)
|
50
|
+
|
51
|
+
path1 = Pathname.new("foo")
|
52
|
+
path2 = Pathname.new("foo/bar/baz")
|
53
|
+
assert_equal(".", path1.root)
|
54
|
+
assert_equal(".", path2.root)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_root?
|
58
|
+
assert_respond_to(@path, :root?)
|
59
|
+
assert_nothing_raised{ @path.root? }
|
60
|
+
|
61
|
+
path1 = Pathname.new("/")
|
62
|
+
path2 = Pathname.new("a")
|
63
|
+
assert_equal(true, path1.root?)
|
64
|
+
assert_equal(false, path2.root?)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_absolute
|
68
|
+
assert_respond_to(@path, :absolute?)
|
69
|
+
assert_nothing_raised{ @path.absolute? }
|
70
|
+
assert_equal(true, Pathname.new("/usr/bin/ruby").absolute?)
|
71
|
+
assert_equal(false, Pathname.new("foo").absolute?)
|
72
|
+
assert_equal(false, Pathname.new("foo/bar").absolute?)
|
73
|
+
assert_equal(false, Pathname.new("../foo/bar").absolute?)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_relative
|
77
|
+
assert_respond_to(@path, :relative?)
|
78
|
+
assert_nothing_raised{ @path.relative? }
|
79
|
+
assert_equal(false, Pathname.new("/usr/bin/ruby").relative?)
|
80
|
+
assert_equal(true, Pathname.new("foo").relative?)
|
81
|
+
assert_equal(true, Pathname.new("foo/bar").relative?)
|
82
|
+
assert_equal(true, Pathname.new("../foo/bar").relative?)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_to_a
|
86
|
+
assert_respond_to(@path, :to_a)
|
87
|
+
assert_nothing_raised{ @path.to_a }
|
88
|
+
assert_kind_of(Array, @path.to_a)
|
89
|
+
assert_equal(%w/usr local bin/, @path.to_a)
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_spaceship_operator
|
93
|
+
assert_respond_to(@path, :<=>)
|
94
|
+
|
95
|
+
assert_pathname_cmp( 0, "/foo/bar", "/foo/bar")
|
96
|
+
assert_pathname_cmp(-1, "/foo/bar", "/foo/zap")
|
97
|
+
assert_pathname_cmp( 1, "/foo/zap", "/foo/bar")
|
98
|
+
assert_pathname_cmp(-1, "foo", "foo/")
|
99
|
+
assert_pathname_cmp(-1, "foo/", "foo/bar")
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_plus_operator
|
103
|
+
assert_respond_to(@path, :+)
|
104
|
+
|
105
|
+
# Standard stuff
|
106
|
+
assert_pathname_plus("/foo/bar", "/foo", "bar")
|
107
|
+
assert_pathname_plus("foo/bar", "foo", "bar")
|
108
|
+
assert_pathname_plus("foo", "foo", ".")
|
109
|
+
assert_pathname_plus("foo", ".", "foo")
|
110
|
+
assert_pathname_plus("/foo", "bar", "/foo")
|
111
|
+
assert_pathname_plus("foo", "foo/bar", "..")
|
112
|
+
assert_pathname_plus("/foo", "/", "../foo")
|
113
|
+
assert_pathname_plus("foo/zap", "foo/bar", "../zap")
|
114
|
+
assert_pathname_plus(".", "foo", "..")
|
115
|
+
assert_pathname_plus("foo", "..", "foo") # Auto clean
|
116
|
+
assert_pathname_plus("foo", "..", "../foo") # Auto clean
|
117
|
+
|
118
|
+
# Edge cases
|
119
|
+
assert_pathname_plus(".", ".", ".")
|
120
|
+
assert_pathname_plus("/", "/", "..")
|
121
|
+
assert_pathname_plus(".", "..", "..")
|
122
|
+
assert_pathname_plus(".", "foo", "..")
|
123
|
+
end
|
124
|
+
|
125
|
+
# Any tests marked with "***" mean that this behavior is different than
|
126
|
+
# the current implementation. It also means I disagree with the current
|
127
|
+
# implementation.
|
128
|
+
def test_cleanpath
|
129
|
+
# Standard stuff
|
130
|
+
assert_equal("/a/b/c", Pathname.new("/a/b/c").cleanpath)
|
131
|
+
assert_equal("b/c", Pathname.new("./b/c").cleanpath)
|
132
|
+
assert_equal("a", Pathname.new("a/.").cleanpath) # ***
|
133
|
+
assert_equal("a/c", Pathname.new("a/./c").cleanpath)
|
134
|
+
assert_equal("a/b", Pathname.new("a/b/.").cleanpath) # ***
|
135
|
+
assert_equal(".", Pathname.new("a/../.").cleanpath) # ***
|
136
|
+
assert_equal("/a", Pathname.new("/a/b/..").cleanpath)
|
137
|
+
assert_equal("/b", Pathname.new("/a/../b").cleanpath)
|
138
|
+
assert_equal("d", Pathname.new("a/../../d").cleanpath) # ***
|
139
|
+
|
140
|
+
# Edge cases
|
141
|
+
assert_equal("", Pathname.new("").cleanpath)
|
142
|
+
assert_equal(".", Pathname.new(".").cleanpath)
|
143
|
+
assert_equal("..", Pathname.new("..").cleanpath)
|
144
|
+
assert_equal('/', Pathname.new('/').cleanpath)
|
145
|
+
assert_equal('/', Pathname.new('//').cleanpath)
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_facade_io
|
149
|
+
assert_respond_to(@path, :foreach)
|
150
|
+
assert_respond_to(@path, :read)
|
151
|
+
assert_respond_to(@path, :readlines)
|
152
|
+
assert_respond_to(@path, :sysopen)
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_facade_file
|
156
|
+
File.methods(false).each{ |method|
|
157
|
+
assert_respond_to(@path, method.to_sym)
|
158
|
+
}
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_facade_dir
|
162
|
+
Dir.methods(false).each{ |method|
|
163
|
+
assert_respond_to(@path, method.to_sym)
|
164
|
+
}
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_facade_fileutils
|
168
|
+
methods = FileUtils.public_instance_methods
|
169
|
+
methods -= File.methods(false)
|
170
|
+
methods -= Dir.methods(false)
|
171
|
+
methods.delete_if{ |m| m =~ /stream/ }
|
172
|
+
methods.delete("identical?")
|
173
|
+
|
174
|
+
methods.each{ |method|
|
175
|
+
assert_respond_to(@path, method.to_sym)
|
176
|
+
}
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_facade_find
|
180
|
+
assert_respond_to(@path, :find)
|
181
|
+
assert_nothing_raised{ @path.find{} }
|
182
|
+
|
183
|
+
Pathname.new(Dir.pwd).find{ |f|
|
184
|
+
Find.prune if f.match("CVS")
|
185
|
+
assert_kind_of(Pathname, f)
|
186
|
+
}
|
187
|
+
end
|
188
|
+
|
189
|
+
def teardown
|
190
|
+
@path = nil
|
191
|
+
end
|
192
|
+
end
|
data/test/tc_pathname_win.rb
CHANGED
@@ -1,227 +1,237 @@
|
|
1
|
-
############################################
|
2
|
-
# tc_pathname.rb
|
3
|
-
#
|
4
|
-
# Test suite for the pathname package.
|
5
|
-
############################################
|
6
|
-
Dir.chdir ".." if File.basename(Dir.pwd) == "test"
|
7
|
-
$LOAD_PATH.unshift Dir.pwd
|
8
|
-
$LOAD_PATH.unshift Dir.pwd + "/lib"
|
9
|
-
|
10
|
-
require "pathname2"
|
11
|
-
require "test/unit"
|
12
|
-
|
13
|
-
class TC_Pathname < Test::Unit::TestCase
|
14
|
-
def setup
|
15
|
-
@fpath = Pathname.new("C:/Program Files/Windows NT/Accessories")
|
16
|
-
@bpath = Pathname.new("C:\\Program Files\\Windows NT\\Accessories")
|
17
|
-
@upath = Pathname.new("\\\\foo\\bar\\baz")
|
18
|
-
@npath = Pathname.new("foo\\bar\\baz")
|
19
|
-
@rpath = Pathname.new("Z:\\")
|
20
|
-
@xpath = Pathname.new("\\\\foo\\bar")
|
21
|
-
@ypath = Pathname.new("\\\\foo")
|
22
|
-
@zpath = Pathname.new("\\\\")
|
23
|
-
@epath = Pathname.new("")
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_version
|
27
|
-
assert_equal("1.
|
28
|
-
end
|
29
|
-
|
30
|
-
# Convenience method for test_plus
|
31
|
-
def assert_pathname_plus(a, b, c)
|
32
|
-
a = Pathname.new(a)
|
33
|
-
b = Pathname.new(b)
|
34
|
-
c = Pathname.new(c)
|
35
|
-
assert_equal(a, b + c)
|
36
|
-
end
|
37
|
-
|
38
|
-
# Convenience method for test_spaceship operator
|
39
|
-
def assert_pathname_cmp(int, s1, s2)
|
40
|
-
p1 = Pathname.new(s1)
|
41
|
-
p2 = Pathname.new(s2)
|
42
|
-
result = p1 <=> p2
|
43
|
-
assert_equal(int, result)
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_each
|
47
|
-
assert_respond_to(@fpath, :each)
|
48
|
-
assert_nothing_raised{ @fpath.each{ |e| } }
|
49
|
-
end
|
50
|
-
|
51
|
-
# Fails due to PathIsURL for some reason
|
52
|
-
#def test_immutability
|
53
|
-
# path = "C:\\Program Files\\foo\\bar".freeze
|
54
|
-
# assert_equal(true, path.frozen?)
|
55
|
-
# assert_nothing_raised{ Pathname.new(path) }
|
56
|
-
# assert_nothing_raised{ Pathname.new(path).root }
|
57
|
-
#end
|
58
|
-
|
59
|
-
def test_plus_operator
|
60
|
-
# Standard stuff
|
61
|
-
assert_pathname_plus("C:\\a\\b", "C:\\a", "b")
|
62
|
-
assert_pathname_plus("C:\\b", "a", "C:\\b")
|
63
|
-
assert_pathname_plus("a\\b", "a", "b")
|
64
|
-
assert_pathname_plus("C:\\b", "C:\\a", "..\\b")
|
65
|
-
assert_pathname_plus("C:\\a\\b", "C:\\a\\.", "\\b")
|
66
|
-
assert_pathname_plus("C:\\a\\b.txt", "C:\\a", "b.txt")
|
67
|
-
|
68
|
-
# UNC paths
|
69
|
-
assert_pathname_plus("\\\\foo\\bar", "\\\\foo", "bar")
|
70
|
-
assert_pathname_plus("\\\\foo", "\\\\", "foo")
|
71
|
-
assert_pathname_plus("\\\\", "\\\\", "")
|
72
|
-
assert_pathname_plus("\\\\foo\\baz", "\\\\foo\\bar", "\\..\\baz")
|
73
|
-
assert_pathname_plus("\\\\", "\\\\", "..\\..\\..\\..")
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_clean
|
77
|
-
# Our preset stuff
|
78
|
-
assert_equal("C:\\Program Files\\Windows NT\\Accessories", @fpath.clean)
|
79
|
-
assert_equal("C:\\Program Files\\Windows NT\\Accessories", @bpath.clean)
|
80
|
-
assert_equal("\\\\foo\\bar\\baz", @upath.clean)
|
81
|
-
assert_equal("foo\\bar\\baz", @npath.clean)
|
82
|
-
assert_equal("Z:\\", @rpath.clean)
|
83
|
-
assert_equal("\\\\foo\\bar", @xpath.clean)
|
84
|
-
assert_equal("\\\\foo", @ypath.clean)
|
85
|
-
assert_equal("\\\\", @zpath.clean)
|
86
|
-
assert_equal("", @epath.clean)
|
87
|
-
|
88
|
-
# Standard stuff
|
89
|
-
assert_equal("C:\\a\\c", Pathname.new("C:\\a\\.\\b\\..\\c").clean)
|
90
|
-
assert_equal("C:\\a", Pathname.new("C:\\.\\a").clean)
|
91
|
-
assert_equal("C:\\a\\b", Pathname.new("C:\\a\\.\\b").clean)
|
92
|
-
assert_equal("C:\\b", Pathname.new("C:\\a\\..\\b").clean)
|
93
|
-
assert_equal("C:\\a", Pathname.new("C:\\a\\.").clean)
|
94
|
-
assert_equal("C:\\d", Pathname.new("C:\\..\\..\\..\\d").clean)
|
95
|
-
assert_equal("C:\\a\\", Pathname.new("C:\\a\\").clean)
|
96
|
-
|
97
|
-
# Edge cases
|
98
|
-
assert_equal("\\", Pathname.new(".").clean)
|
99
|
-
assert_equal("\\", Pathname.new("..").clean)
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_absolute
|
103
|
-
assert_equal(true, @fpath.absolute?)
|
104
|
-
assert_equal(true, @bpath.absolute?)
|
105
|
-
assert_equal(true, @upath.absolute?)
|
106
|
-
assert_equal(false, @npath.absolute?)
|
107
|
-
assert_equal(true, @rpath.absolute?)
|
108
|
-
assert_equal(true, @xpath.absolute?)
|
109
|
-
assert_equal(true, @ypath.absolute?)
|
110
|
-
assert_equal(true, @zpath.absolute?)
|
111
|
-
assert_equal(false, @epath.absolute?)
|
112
|
-
end
|
113
|
-
|
114
|
-
def test_relative
|
115
|
-
assert_equal(false, @fpath.relative?)
|
116
|
-
assert_equal(false, @bpath.relative?)
|
117
|
-
assert_equal(false, @upath.relative?)
|
118
|
-
assert_equal(true, @npath.relative?)
|
119
|
-
assert_equal(false, @rpath.relative?)
|
120
|
-
assert_equal(false, @xpath.relative?)
|
121
|
-
assert_equal(false, @ypath.relative?)
|
122
|
-
assert_equal(false, @zpath.relative?)
|
123
|
-
assert_equal(true, @epath.relative?)
|
124
|
-
end
|
125
|
-
|
126
|
-
def test_root
|
127
|
-
assert_equal("C:\\", @fpath.root)
|
128
|
-
assert_equal("C:\\", @bpath.root)
|
129
|
-
assert_equal("\\\\foo\\bar", @upath.root)
|
130
|
-
assert_equal(".", @npath.root)
|
131
|
-
assert_equal("Z:\\", @rpath.root)
|
132
|
-
assert_equal("\\\\foo\\bar", @xpath.root)
|
133
|
-
assert_equal("\\\\foo", @ypath.root)
|
134
|
-
assert_equal("\\\\", @zpath.root)
|
135
|
-
assert_equal(".", @epath.root)
|
136
|
-
|
137
|
-
# Edge cases
|
138
|
-
assert_equal(".", Pathname.new("..").root)
|
139
|
-
assert_equal(".", Pathname.new(".").root)
|
140
|
-
end
|
141
|
-
|
142
|
-
def test_drive_number
|
143
|
-
assert_equal(2, @fpath.drive_number)
|
144
|
-
assert_equal(2, @bpath.drive_number)
|
145
|
-
assert_equal(nil, @upath.drive_number)
|
146
|
-
assert_equal(nil, @npath.drive_number)
|
147
|
-
assert_equal(25, @rpath.drive_number)
|
148
|
-
assert_equal(nil, @xpath.drive_number)
|
149
|
-
assert_equal(nil, @ypath.drive_number)
|
150
|
-
assert_equal(nil, @zpath.drive_number)
|
151
|
-
assert_equal(nil, @epath.drive_number)
|
152
|
-
|
153
|
-
# Edge cases
|
154
|
-
assert_equal(nil, Pathname.new("..").drive_number)
|
155
|
-
assert_equal(nil, Pathname.new(".").drive_number)
|
156
|
-
end
|
157
|
-
|
158
|
-
def test_to_a
|
159
|
-
expected = ["C:", "Program Files", "Windows NT", "Accessories"]
|
160
|
-
assert_equal(expected, @fpath.to_a)
|
161
|
-
assert_equal(expected, @bpath.to_a)
|
162
|
-
assert_equal(["foo","bar","baz"], @upath.to_a)
|
163
|
-
assert_equal(["foo","bar","baz"], @npath.to_a)
|
164
|
-
assert_equal(["Z:"], @rpath.to_a)
|
165
|
-
assert_equal(["foo","bar"], @xpath.to_a)
|
166
|
-
assert_equal(["foo"], @ypath.to_a)
|
167
|
-
assert_equal([], @zpath.to_a)
|
168
|
-
assert_equal([], @epath.to_a)
|
169
|
-
end
|
170
|
-
|
171
|
-
def test_is_root
|
172
|
-
assert_equal(false, @fpath.root?)
|
173
|
-
assert_equal(false, @bpath.root?)
|
174
|
-
assert_equal(false, @upath.root?)
|
175
|
-
assert_equal(false, @npath.root?)
|
176
|
-
assert_equal(true, @rpath.root?)
|
177
|
-
assert_equal(true, @xpath.root?)
|
178
|
-
assert_equal(true, @ypath.root?)
|
179
|
-
assert_equal(true, @zpath.root?)
|
180
|
-
assert_equal(false, @epath.root?)
|
181
|
-
end
|
182
|
-
|
183
|
-
def test_facade_io
|
184
|
-
assert_respond_to(@fpath, :foreach)
|
185
|
-
assert_respond_to(@fpath, :read)
|
186
|
-
assert_respond_to(@fpath, :readlines)
|
187
|
-
assert_respond_to(@fpath, :sysopen)
|
188
|
-
end
|
189
|
-
|
190
|
-
def test_facade_file
|
191
|
-
File.methods(false).each{ |method|
|
192
|
-
assert_respond_to(@fpath, method.to_sym)
|
193
|
-
}
|
194
|
-
assert_respond_to(@fpath, :catname) # ftools check
|
195
|
-
end
|
196
|
-
|
197
|
-
def test_facade_dir
|
198
|
-
Dir.methods(false).each{ |method|
|
199
|
-
assert_respond_to(@fpath, method.to_sym)
|
200
|
-
}
|
201
|
-
end
|
202
|
-
|
203
|
-
def test_facade_fileutils
|
204
|
-
methods = FileUtils.public_instance_methods
|
205
|
-
methods -= File.methods(false)
|
206
|
-
methods -= Dir.methods(false)
|
207
|
-
methods.delete_if{ |m| m =~ /stream/ }
|
208
|
-
methods.delete_if{ |m| m =~ /^ln/ }
|
209
|
-
methods.delete("identical?")
|
210
|
-
|
211
|
-
methods.each{ |method|
|
212
|
-
assert_respond_to(@fpath, method.to_sym)
|
213
|
-
}
|
214
|
-
end
|
215
|
-
|
216
|
-
def
|
217
|
-
@fpath
|
218
|
-
@
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
1
|
+
############################################
|
2
|
+
# tc_pathname.rb
|
3
|
+
#
|
4
|
+
# Test suite for the pathname package.
|
5
|
+
############################################
|
6
|
+
Dir.chdir ".." if File.basename(Dir.pwd) == "test"
|
7
|
+
$LOAD_PATH.unshift Dir.pwd
|
8
|
+
$LOAD_PATH.unshift Dir.pwd + "/lib"
|
9
|
+
|
10
|
+
require "pathname2"
|
11
|
+
require "test/unit"
|
12
|
+
|
13
|
+
class TC_Pathname < Test::Unit::TestCase
|
14
|
+
def setup
|
15
|
+
@fpath = Pathname.new("C:/Program Files/Windows NT/Accessories")
|
16
|
+
@bpath = Pathname.new("C:\\Program Files\\Windows NT\\Accessories")
|
17
|
+
@upath = Pathname.new("\\\\foo\\bar\\baz")
|
18
|
+
@npath = Pathname.new("foo\\bar\\baz")
|
19
|
+
@rpath = Pathname.new("Z:\\")
|
20
|
+
@xpath = Pathname.new("\\\\foo\\bar")
|
21
|
+
@ypath = Pathname.new("\\\\foo")
|
22
|
+
@zpath = Pathname.new("\\\\")
|
23
|
+
@epath = Pathname.new("")
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_version
|
27
|
+
assert_equal("1.1.0", Pathname::VERSION)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Convenience method for test_plus
|
31
|
+
def assert_pathname_plus(a, b, c)
|
32
|
+
a = Pathname.new(a)
|
33
|
+
b = Pathname.new(b)
|
34
|
+
c = Pathname.new(c)
|
35
|
+
assert_equal(a, b + c)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Convenience method for test_spaceship operator
|
39
|
+
def assert_pathname_cmp(int, s1, s2)
|
40
|
+
p1 = Pathname.new(s1)
|
41
|
+
p2 = Pathname.new(s2)
|
42
|
+
result = p1 <=> p2
|
43
|
+
assert_equal(int, result)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_each
|
47
|
+
assert_respond_to(@fpath, :each)
|
48
|
+
assert_nothing_raised{ @fpath.each{ |e| } }
|
49
|
+
end
|
50
|
+
|
51
|
+
# Fails due to PathIsURL for some reason
|
52
|
+
#def test_immutability
|
53
|
+
# path = "C:\\Program Files\\foo\\bar".freeze
|
54
|
+
# assert_equal(true, path.frozen?)
|
55
|
+
# assert_nothing_raised{ Pathname.new(path) }
|
56
|
+
# assert_nothing_raised{ Pathname.new(path).root }
|
57
|
+
#end
|
58
|
+
|
59
|
+
def test_plus_operator
|
60
|
+
# Standard stuff
|
61
|
+
assert_pathname_plus("C:\\a\\b", "C:\\a", "b")
|
62
|
+
assert_pathname_plus("C:\\b", "a", "C:\\b")
|
63
|
+
assert_pathname_plus("a\\b", "a", "b")
|
64
|
+
assert_pathname_plus("C:\\b", "C:\\a", "..\\b")
|
65
|
+
assert_pathname_plus("C:\\a\\b", "C:\\a\\.", "\\b")
|
66
|
+
assert_pathname_plus("C:\\a\\b.txt", "C:\\a", "b.txt")
|
67
|
+
|
68
|
+
# UNC paths
|
69
|
+
assert_pathname_plus("\\\\foo\\bar", "\\\\foo", "bar")
|
70
|
+
assert_pathname_plus("\\\\foo", "\\\\", "foo")
|
71
|
+
assert_pathname_plus("\\\\", "\\\\", "")
|
72
|
+
assert_pathname_plus("\\\\foo\\baz", "\\\\foo\\bar", "\\..\\baz")
|
73
|
+
assert_pathname_plus("\\\\", "\\\\", "..\\..\\..\\..")
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_clean
|
77
|
+
# Our preset stuff
|
78
|
+
assert_equal("C:\\Program Files\\Windows NT\\Accessories", @fpath.clean)
|
79
|
+
assert_equal("C:\\Program Files\\Windows NT\\Accessories", @bpath.clean)
|
80
|
+
assert_equal("\\\\foo\\bar\\baz", @upath.clean)
|
81
|
+
assert_equal("foo\\bar\\baz", @npath.clean)
|
82
|
+
assert_equal("Z:\\", @rpath.clean)
|
83
|
+
assert_equal("\\\\foo\\bar", @xpath.clean)
|
84
|
+
assert_equal("\\\\foo", @ypath.clean)
|
85
|
+
assert_equal("\\\\", @zpath.clean)
|
86
|
+
assert_equal("", @epath.clean)
|
87
|
+
|
88
|
+
# Standard stuff
|
89
|
+
assert_equal("C:\\a\\c", Pathname.new("C:\\a\\.\\b\\..\\c").clean)
|
90
|
+
assert_equal("C:\\a", Pathname.new("C:\\.\\a").clean)
|
91
|
+
assert_equal("C:\\a\\b", Pathname.new("C:\\a\\.\\b").clean)
|
92
|
+
assert_equal("C:\\b", Pathname.new("C:\\a\\..\\b").clean)
|
93
|
+
assert_equal("C:\\a", Pathname.new("C:\\a\\.").clean)
|
94
|
+
assert_equal("C:\\d", Pathname.new("C:\\..\\..\\..\\d").clean)
|
95
|
+
assert_equal("C:\\a\\", Pathname.new("C:\\a\\").clean)
|
96
|
+
|
97
|
+
# Edge cases
|
98
|
+
assert_equal("\\", Pathname.new(".").clean)
|
99
|
+
assert_equal("\\", Pathname.new("..").clean)
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_absolute
|
103
|
+
assert_equal(true, @fpath.absolute?)
|
104
|
+
assert_equal(true, @bpath.absolute?)
|
105
|
+
assert_equal(true, @upath.absolute?)
|
106
|
+
assert_equal(false, @npath.absolute?)
|
107
|
+
assert_equal(true, @rpath.absolute?)
|
108
|
+
assert_equal(true, @xpath.absolute?)
|
109
|
+
assert_equal(true, @ypath.absolute?)
|
110
|
+
assert_equal(true, @zpath.absolute?)
|
111
|
+
assert_equal(false, @epath.absolute?)
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_relative
|
115
|
+
assert_equal(false, @fpath.relative?)
|
116
|
+
assert_equal(false, @bpath.relative?)
|
117
|
+
assert_equal(false, @upath.relative?)
|
118
|
+
assert_equal(true, @npath.relative?)
|
119
|
+
assert_equal(false, @rpath.relative?)
|
120
|
+
assert_equal(false, @xpath.relative?)
|
121
|
+
assert_equal(false, @ypath.relative?)
|
122
|
+
assert_equal(false, @zpath.relative?)
|
123
|
+
assert_equal(true, @epath.relative?)
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_root
|
127
|
+
assert_equal("C:\\", @fpath.root)
|
128
|
+
assert_equal("C:\\", @bpath.root)
|
129
|
+
assert_equal("\\\\foo\\bar", @upath.root)
|
130
|
+
assert_equal(".", @npath.root)
|
131
|
+
assert_equal("Z:\\", @rpath.root)
|
132
|
+
assert_equal("\\\\foo\\bar", @xpath.root)
|
133
|
+
assert_equal("\\\\foo", @ypath.root)
|
134
|
+
assert_equal("\\\\", @zpath.root)
|
135
|
+
assert_equal(".", @epath.root)
|
136
|
+
|
137
|
+
# Edge cases
|
138
|
+
assert_equal(".", Pathname.new("..").root)
|
139
|
+
assert_equal(".", Pathname.new(".").root)
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_drive_number
|
143
|
+
assert_equal(2, @fpath.drive_number)
|
144
|
+
assert_equal(2, @bpath.drive_number)
|
145
|
+
assert_equal(nil, @upath.drive_number)
|
146
|
+
assert_equal(nil, @npath.drive_number)
|
147
|
+
assert_equal(25, @rpath.drive_number)
|
148
|
+
assert_equal(nil, @xpath.drive_number)
|
149
|
+
assert_equal(nil, @ypath.drive_number)
|
150
|
+
assert_equal(nil, @zpath.drive_number)
|
151
|
+
assert_equal(nil, @epath.drive_number)
|
152
|
+
|
153
|
+
# Edge cases
|
154
|
+
assert_equal(nil, Pathname.new("..").drive_number)
|
155
|
+
assert_equal(nil, Pathname.new(".").drive_number)
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_to_a
|
159
|
+
expected = ["C:", "Program Files", "Windows NT", "Accessories"]
|
160
|
+
assert_equal(expected, @fpath.to_a)
|
161
|
+
assert_equal(expected, @bpath.to_a)
|
162
|
+
assert_equal(["foo","bar","baz"], @upath.to_a)
|
163
|
+
assert_equal(["foo","bar","baz"], @npath.to_a)
|
164
|
+
assert_equal(["Z:"], @rpath.to_a)
|
165
|
+
assert_equal(["foo","bar"], @xpath.to_a)
|
166
|
+
assert_equal(["foo"], @ypath.to_a)
|
167
|
+
assert_equal([], @zpath.to_a)
|
168
|
+
assert_equal([], @epath.to_a)
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_is_root
|
172
|
+
assert_equal(false, @fpath.root?)
|
173
|
+
assert_equal(false, @bpath.root?)
|
174
|
+
assert_equal(false, @upath.root?)
|
175
|
+
assert_equal(false, @npath.root?)
|
176
|
+
assert_equal(true, @rpath.root?)
|
177
|
+
assert_equal(true, @xpath.root?)
|
178
|
+
assert_equal(true, @ypath.root?)
|
179
|
+
assert_equal(true, @zpath.root?)
|
180
|
+
assert_equal(false, @epath.root?)
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_facade_io
|
184
|
+
assert_respond_to(@fpath, :foreach)
|
185
|
+
assert_respond_to(@fpath, :read)
|
186
|
+
assert_respond_to(@fpath, :readlines)
|
187
|
+
assert_respond_to(@fpath, :sysopen)
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_facade_file
|
191
|
+
File.methods(false).each{ |method|
|
192
|
+
assert_respond_to(@fpath, method.to_sym)
|
193
|
+
}
|
194
|
+
assert_respond_to(@fpath, :catname) # ftools check
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_facade_dir
|
198
|
+
Dir.methods(false).each{ |method|
|
199
|
+
assert_respond_to(@fpath, method.to_sym)
|
200
|
+
}
|
201
|
+
end
|
202
|
+
|
203
|
+
def test_facade_fileutils
|
204
|
+
methods = FileUtils.public_instance_methods
|
205
|
+
methods -= File.methods(false)
|
206
|
+
methods -= Dir.methods(false)
|
207
|
+
methods.delete_if{ |m| m =~ /stream/ }
|
208
|
+
methods.delete_if{ |m| m =~ /^ln/ }
|
209
|
+
methods.delete("identical?")
|
210
|
+
|
211
|
+
methods.each{ |method|
|
212
|
+
assert_respond_to(@fpath, method.to_sym)
|
213
|
+
}
|
214
|
+
end
|
215
|
+
|
216
|
+
def test_facade_find
|
217
|
+
assert_respond_to(@fpath, :find)
|
218
|
+
assert_nothing_raised{ @fpath.find{} }
|
219
|
+
|
220
|
+
Pathname.new(Dir.pwd).find{ |f|
|
221
|
+
Find.prune if f.match("CVS")
|
222
|
+
assert_kind_of(Pathname, f)
|
223
|
+
}
|
224
|
+
end
|
225
|
+
|
226
|
+
def teardown
|
227
|
+
@fpath = nil
|
228
|
+
@bpath = nil
|
229
|
+
@upath = nil
|
230
|
+
@npath = nil
|
231
|
+
@rpath = nil
|
232
|
+
@xpath = nil
|
233
|
+
@ypath = nil
|
234
|
+
@zpath = nil
|
235
|
+
@epath = nil
|
236
|
+
end
|
237
|
+
end
|