Skip to content

Commit 904e995

Browse files
committed
parent: correct '' case
1 parent 2df1b52 commit 904e995

File tree

2 files changed

+11
-26
lines changed

2 files changed

+11
-26
lines changed

+stdlib/+fileio/parent.m

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,9 @@
77

88
jp = java.io.File(path).getParent();
99
if isempty(jp)
10-
jp = "";
10+
jp = ".";
1111
end
1212

1313
p = stdlib.fileio.posix(jp);
1414

15-
% must drop trailing slash - need to as_posix for windows
16-
%p = fileparts(strip(stdlib.fileio.posix(path), 'right', '/'));
17-
1815
end

test/TestFilePure.m

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@
1111
ref_proximate_to
1212
in_is_absolute
1313
ref_is_absolute
14-
in_filename = {'', '/foo/bar/baz', '/foo/bar/baz/', 'foo/bar/baz.txt', 'foo/bar/baz.txt.gz'};
15-
ref_filename = {'', 'baz', '', 'baz.txt', 'baz.txt.gz'};
14+
in_filename = {'', '/foo/bar/baz', '/foo/bar/baz/', 'foo/bar/baz.txt', 'foo/bar/baz.txt.gz'}
15+
ref_filename = {'', 'baz', '', 'baz.txt', 'baz.txt.gz'}
1616
dir_is_subdir
1717
sub_is_subdir
1818
ref_is_subdir
19+
in_parent = {"", ".", "..", "../..", "a/b", "a/b/", "ab/.parent", "ab/.parent.txt", "a/b/../.parent.txt"}
20+
ref_parent = {".", ".", ".", "..", "a", "a", "ab", "ab", "a/b/.."}
21+
in_suffix = {"", "/foo/bar/baz", "/foo/bar/baz/", "foo/bar/baz.txt", "foo/bar/baz.txt.gz", ".stat", ".stat.txt"}
22+
ref_suffix = {"", "", "", ".txt", ".gz", ".stat", ".txt"}
1923
end
2024

2125
properties
@@ -143,28 +147,12 @@ function test_filename(tc, in_filename, ref_filename)
143147
end
144148

145149

146-
function test_parent(tc)
147-
148-
tc.verifyEqual(stdlib.parent(""), "")
149-
150-
tc.verifyEqual(stdlib.parent("/foo/bar/baz"), "/foo/bar")
151-
tc.verifyEqual(stdlib.parent("/foo/bar/baz/"), "/foo/bar")
152-
153-
tc.verifyEqual(stdlib.parent("foo/bar/baz/"), "foo/bar")
154-
150+
function test_parent(tc, in_parent, ref_parent)
151+
tc.verifyEqual(stdlib.parent(in_parent), ref_parent)
155152
end
156153

157-
function test_suffix(tc)
158-
159-
tc.verifyEmpty(stdlib.suffix(string.empty))
160-
tc.verifyEqual(stdlib.suffix(""), "")
161-
162-
tc.verifyEqual(stdlib.suffix("/foo/bar/baz"), "")
163-
tc.verifyEqual(stdlib.suffix("/foo/bar/baz/"), "")
164-
165-
tc.verifyEqual(stdlib.suffix("foo/bar/baz.txt"), ".txt")
166-
tc.verifyEqual(stdlib.suffix("foo/bar/baz.txt.gz"), ".gz")
167-
154+
function test_suffix(tc, in_suffix, ref_suffix)
155+
tc.verifyEqual(stdlib.suffix(in_suffix), string(ref_suffix))
168156
end
169157

170158

0 commit comments

Comments
 (0)