Skip to content

Commit f7194e8

Browse files
author
rwh
committed
fix tests for subdirs->dirs and filename->file
1 parent 9135042 commit f7194e8

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

test/unix_path.rb

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55

66
# Helper method to run parsing tests
77
def assert_parsing(cases)
8-
cases.each { |str, (abs, subdirs, filename)|
8+
cases.each { |str, (abs, dirs, file)|
99
path = UnixPath.parse(str)
1010
expect(path.abs).must_equal abs
11-
expect(path.subdirs).must_equal subdirs
12-
expect(path.filename).must_equal filename
11+
expect(path.dirs).must_equal dirs
12+
expect(path.file).must_equal file
1313
}
1414
end
1515

1616
def assert_filenames(cases)
17-
cases.each do |filename, (base, ext)|
18-
path = UnixPath.parse(filename)
17+
cases.each do |file, (base, ext)|
18+
path = UnixPath.parse(file)
1919
expect(path.basename).must_equal base
2020
expect(path.extension).must_equal ext
2121
end
@@ -41,6 +41,7 @@ def assert_filenames(cases)
4141
'./file.txt' => [false, [], 'file.txt'],
4242
'./.emacs' => [false, [], '.emacs'],
4343
'./././././file.txt' => [false, [], 'file.txt'],
44+
'./stuff/./things/.txt' => [false, %w[stuff things], '.txt'],
4445
}
4546
assert_parsing(cases)
4647
end
@@ -57,7 +58,7 @@ def assert_filenames(cases)
5758
assert_parsing(cases)
5859
end
5960

60-
it "parses directories with trailing slash; filename is empty" do
61+
it "parses directories with trailing slash; file is empty" do
6162
cases = {
6263
'/' => [true, [], ''],
6364
'/home/' => [true, %w[home], ''],
@@ -69,7 +70,7 @@ def assert_filenames(cases)
6970
assert_parsing(cases)
7071
end
7172

72-
it "parses filenames with no trailing slash; nonempty filename" do
73+
it "parses files with no trailing slash; nonempty file" do
7374
cases = {
7475
'/home/user/documents' => [true, %w[home user], 'documents'],
7576
'/home/user/file.txt' => [true, %w[home user], 'file.txt'],
@@ -87,12 +88,12 @@ def assert_filenames(cases)
8788
end
8889

8990
it "leads with a dot for all relpaths" do
90-
path = UnixPath.new(abs: false, subdirs: %w[path to], filename: 'file.txt')
91+
path = UnixPath.new(abs: false, dirs: %w[path to], file: 'file.txt')
9192
expect(path.to_s.start_with? './').must_equal true
9293
end
9394

9495
it "leads with a slash for all abspaths" do
95-
path = UnixPath.new(abs: true, subdirs: %w[path to], filename: 'file.txt')
96+
path = UnixPath.new(abs: true, dirs: %w[path to], file: 'file.txt')
9697
expect(path.to_s.start_with? '/').must_equal true
9798
end
9899

@@ -134,13 +135,13 @@ def assert_filenames(cases)
134135
expect(relabs.to_s).must_equal './.emacs/home/user'
135136
end
136137

137-
it "slashes liberally, promoting base filename to a subdir" do
138+
it "slashes liberally, promoting base file to a subdir" do
138139
dot_emacs = UnixPath.parse('/home/user/.emacs')
139140
init_el = UnixPath.parse('./.config/init.el')
140141
slashed = dot_emacs / init_el
141142

142-
expect(dot_emacs.filename).must_equal '.emacs'
143-
expect(slashed.subdirs).must_include '.emacs'
143+
expect(dot_emacs.file).must_equal '.emacs'
144+
expect(slashed.dirs).must_include '.emacs'
144145
expect(slashed.to_s).must_equal '/home/user/.emacs/.config/init.el'
145146
end
146147

@@ -158,7 +159,7 @@ def assert_filenames(cases)
158159
muimmu = mu / immu
159160
expect(muimmu).must_be_kind_of MutablePath
160161
expect(muimmu).must_equal mu
161-
expect(muimmu.to_s).must_equal '/etc/systemd/var/lib'
162+
expect(muimmu.to_s).must_equal '/etc/systemd/var/lib'
162163
end
163164

164165
it "handles complex slash chains with strings" do
@@ -173,11 +174,11 @@ def assert_filenames(cases)
173174
expect(result2.to_s).must_equal './relative/path/more/dirs/etc/passwd'
174175
end
175176

176-
describe 'empty filename' do
177+
describe 'empty file' do
177178
it "indicates a directory when empty" do
178179
path = UnixPath.parse("/home/user/docs/")
179180
expect(path.dir?).must_equal true
180-
expect(path.filename).must_equal ""
181+
expect(path.file).must_equal ""
181182
end
182183

183184
it "has neither basename nor extension" do

0 commit comments

Comments
 (0)