Skip to content

Commit 3cee22a

Browse files
committed
correct validate
1 parent dc5dbab commit 3cee22a

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

+stdlib/+fileio/path_tail.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
% get last part of directory path
44
% if filename, return filename with suffix
55
arguments
6-
apath (1,:) string
6+
apath string {mustBeScalarOrEmpty}
77
end
88

99
import stdlib.fileio.absolute_path
1010

11+
if strlength(apath) == 0
12+
last = "";
13+
return
14+
end
15+
1116
[~, name, ext] = fileparts(absolute_path(apath));
1217

1318
last = append(name, ext);

+stdlib/+test/TestFileImpure.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
function test_expanduser(tc)
66
import stdlib.fileio.expanduser
77

8+
tc.verifyEmpty(expanduser(string.empty))
9+
tc.verifyEqual(expanduser(""), "")
10+
811
tc.verifyFalse(startsWith(expanduser('~/foo'), "~"))
912
tc.verifyFalse(any(startsWith(expanduser(["~/abc", "~/123"]), "~")))
1013

1114
tc.verifyTrue(endsWith(expanduser('~/foo'), "foo"))
1215
tc.verifyTrue(all(endsWith(expanduser(["~/abc", "~/123"]), ["abc", "123"])))
13-
14-
tc.verifyEmpty(expanduser(string.empty))
15-
tc.verifyEqual(expanduser(""), "")
1616
end
1717

1818
function test_makedir(tc)

+stdlib/+test/TestFilePure.m

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,22 @@
55
function test_posix(tc)
66
import stdlib.fileio.posix
77

8+
tc.verifyEmpty(posix(string.empty))
9+
tc.verifyEqual(posix(""), "")
10+
811
if ispc
912
tc.verifyFalse(contains(posix("c:\foo"), "\"))
1013
tc.verifyFalse(all(contains(posix(["x:\123", "d:\abc"]), "\")))
1114
end
1215

13-
tc.verifyEmpty(posix(string.empty))
1416
end
1517

1618
function test_path_tail(tc)
1719

1820
import stdlib.fileio.path_tail
1921

22+
tc.verifyEmpty(path_tail(string.empty))
23+
tc.verifyEqual(path_tail(""), "")
2024
tc.verifyEqual(path_tail("/foo/bar/baz"), "baz")
2125
tc.verifyEqual(path_tail("/foo/bar/baz/"), "baz")
2226
tc.verifyEqual(path_tail("/foo/bar/baz/."), "baz")
@@ -29,6 +33,10 @@ function test_is_absolute_path(tc)
2933

3034
import stdlib.fileio.is_absolute_path
3135
% path need not exist
36+
37+
tc.verifyEmpty(is_absolute_path(string.empty))
38+
tc.verifyFalse(is_absolute_path(""))
39+
3240
tc.verifyTrue(is_absolute_path('~/foo'))
3341
if ispc
3442
tc.verifyTrue(is_absolute_path('x:/foo'))
@@ -37,15 +45,16 @@ function test_is_absolute_path(tc)
3745
tc.verifyTrue(is_absolute_path('/foo'))
3846
end
3947

40-
tc.verifyEmpty(is_absolute_path(string.empty))
41-
tc.verifyFalse(is_absolute_path(""))
4248
tc.verifyFalse(is_absolute_path("c"))
4349
end
4450

4551
function test_absolute_path(tc)
4652

4753
import stdlib.fileio.absolute_path
4854

55+
tc.verifyEmpty(absolute_path(string.empty))
56+
tc.verifyEqual(absolute_path(""), string(pwd))
57+
4958
pabs = absolute_path('2foo');
5059
pabs2 = absolute_path('4foo');
5160
tc.verifyFalse(startsWith(pabs, "2"))
@@ -64,19 +73,19 @@ function test_absolute_path(tc)
6473
tc.verifyFalse(startsWith(va, "2"))
6574
tc.verifyTrue(strncmp(va, vb, 2))
6675

67-
tc.verifyEmpty(absolute_path(string.empty))
68-
tc.verifyEqual(absolute_path(""), string(pwd))
6976
end
7077

7178
function test_with_suffix(tc)
7279
import stdlib.fileio.with_suffix
80+
81+
tc.verifyEmpty(with_suffix(string.empty, ".nc"))
82+
tc.verifyEqual(with_suffix("", ""), "")
83+
7384
tc.verifyEqual(with_suffix("foo.h5", ".nc"), "foo.nc")
7485
if ~verLessThan("matlab", "9.9")
7586
% fileparts vectorized in R2020b
7687
tc.verifyEqual(with_suffix(["foo.h5", "bar.dat"], ".nc"), ["foo.nc", "bar.nc"])
7788

78-
tc.verifyEmpty(with_suffix(string.empty, ".nc"))
79-
tc.verifyEqual(with_suffix("", ""), "")
8089
tc.verifyEqual(with_suffix("c", ""), "c")
8190
tc.verifyEqual(with_suffix("c.nc", ""), "c")
8291
tc.verifyEqual(with_suffix("", ".nc"), ".nc")

0 commit comments

Comments
 (0)