5
5
6
6
# Helper method to run parsing tests
7
7
def assert_parsing ( cases )
8
- cases . each { |str , ( abs , subdirs , filename ) |
8
+ cases . each { |str , ( abs , dirs , file ) |
9
9
path = UnixPath . parse ( str )
10
10
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
13
13
}
14
14
end
15
15
16
16
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 )
19
19
expect ( path . basename ) . must_equal base
20
20
expect ( path . extension ) . must_equal ext
21
21
end
@@ -41,6 +41,7 @@ def assert_filenames(cases)
41
41
'./file.txt' => [ false , [ ] , 'file.txt' ] ,
42
42
'./.emacs' => [ false , [ ] , '.emacs' ] ,
43
43
'./././././file.txt' => [ false , [ ] , 'file.txt' ] ,
44
+ './stuff/./things/.txt' => [ false , %w[ stuff things ] , '.txt' ] ,
44
45
}
45
46
assert_parsing ( cases )
46
47
end
@@ -57,7 +58,7 @@ def assert_filenames(cases)
57
58
assert_parsing ( cases )
58
59
end
59
60
60
- it "parses directories with trailing slash; filename is empty" do
61
+ it "parses directories with trailing slash; file is empty" do
61
62
cases = {
62
63
'/' => [ true , [ ] , '' ] ,
63
64
'/home/' => [ true , %w[ home ] , '' ] ,
@@ -69,7 +70,7 @@ def assert_filenames(cases)
69
70
assert_parsing ( cases )
70
71
end
71
72
72
- it "parses filenames with no trailing slash; nonempty filename " do
73
+ it "parses files with no trailing slash; nonempty file " do
73
74
cases = {
74
75
'/home/user/documents' => [ true , %w[ home user ] , 'documents' ] ,
75
76
'/home/user/file.txt' => [ true , %w[ home user ] , 'file.txt' ] ,
@@ -87,12 +88,12 @@ def assert_filenames(cases)
87
88
end
88
89
89
90
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' )
91
92
expect ( path . to_s . start_with? './' ) . must_equal true
92
93
end
93
94
94
95
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' )
96
97
expect ( path . to_s . start_with? '/' ) . must_equal true
97
98
end
98
99
@@ -134,13 +135,13 @@ def assert_filenames(cases)
134
135
expect ( relabs . to_s ) . must_equal './.emacs/home/user'
135
136
end
136
137
137
- it "slashes liberally, promoting base filename to a subdir" do
138
+ it "slashes liberally, promoting base file to a subdir" do
138
139
dot_emacs = UnixPath . parse ( '/home/user/.emacs' )
139
140
init_el = UnixPath . parse ( './.config/init.el' )
140
141
slashed = dot_emacs / init_el
141
142
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'
144
145
expect ( slashed . to_s ) . must_equal '/home/user/.emacs/.config/init.el'
145
146
end
146
147
@@ -158,7 +159,7 @@ def assert_filenames(cases)
158
159
muimmu = mu / immu
159
160
expect ( muimmu ) . must_be_kind_of MutablePath
160
161
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'
162
163
end
163
164
164
165
it "handles complex slash chains with strings" do
@@ -173,11 +174,11 @@ def assert_filenames(cases)
173
174
expect ( result2 . to_s ) . must_equal './relative/path/more/dirs/etc/passwd'
174
175
end
175
176
176
- describe 'empty filename ' do
177
+ describe 'empty file ' do
177
178
it "indicates a directory when empty" do
178
179
path = UnixPath . parse ( "/home/user/docs/" )
179
180
expect ( path . dir? ) . must_equal true
180
- expect ( path . filename ) . must_equal ""
181
+ expect ( path . file ) . must_equal ""
181
182
end
182
183
183
184
it "has neither basename nor extension" do
0 commit comments