Skip to content

Commit 0b64d8a

Browse files
committed
expanduser vector, add unit test
1 parent 8d06776 commit 0b64d8a

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

+hdf5nc/TestUnit.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
classdef TestUnit < matlab.unittest.TestCase
2+
3+
methods (Test)
4+
5+
function test_expanduser(tc)
6+
tc.verifyEmpty(expanduser(string.empty))
7+
tc.verifyFalse(startsWith(expanduser("~"), "~"))
8+
tc.verifyFalse(any(startsWith(expanduser(["~","~"]), "~")))
9+
10+
a = expanduser(["~", "foo"]);
11+
tc.verifyEqual(a(2), "foo")
12+
tc.verifyNotEqual(a(1), "~")
13+
end
14+
15+
end
16+
17+
end

+hdf5nc/private/coerce_ds.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function A = coerce_ds(A, dtype)
22
% used by h5save and ncsave
33
arguments
4-
A {mustBeNonempty}
4+
A
55
dtype string
66
end
77

+hdf5nc/private/expanduser.m

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,15 @@
2424

2525
expanded = p;
2626

27-
if ~startsWith(expanded, "~")
28-
return
29-
end
30-
3127
if ispc
3228
home = getenv('USERPROFILE');
3329
else
3430
home = getenv('HOME');
3531
end
3632

3733
if ~isempty(home)
38-
expanded = fullfile(home, extractAfter(expanded, 1));
34+
i = startsWith(expanded, "~");
35+
expanded(i) = fullfile(home, extractAfter(expanded(i), 1));
3936
end
4037

4138
end %function

0 commit comments

Comments
 (0)