Skip to content

Commit 96cd631

Browse files
committed
fileio.samepath: correct validation, add test
1 parent 3cee22a commit 96cd631

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function mustBeScalarOrEmpty(x)
2+
3+
if ~(isempty(x) || isscalar(x))
4+
throwAsCaller(MException('MATLAB:validators:mustBeScalarOrEmpty', "must be scalar or empty"))
5+
end
6+
7+
end

+stdlib/+fileio/samepath.m

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
function issame = samepath(path1, path2)
22
%% samepath(path1, path)
33
% true if inputs resolve to same path
4+
% files need not exist
5+
%%% Inputs
6+
% * path1, path2: paths to compare
7+
%%% Outputs
8+
% issame: logical
49
arguments
5-
path1 (1,1) string {mustBeNonzeroLengthText}
6-
path2 (1,1) string {mustBeNonzeroLengthText}
10+
path1 string {mustBeScalarOrEmpty}
11+
path2 string {mustBeScalarOrEmpty}
712
end
813

914
import stdlib.fileio.absolute_path

+stdlib/+test/TestFilePure.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ function test_posix(tc)
1212
tc.verifyFalse(contains(posix("c:\foo"), "\"))
1313
tc.verifyFalse(all(contains(posix(["x:\123", "d:\abc"]), "\")))
1414
end
15+
end
16+
17+
function test_samepath(tc)
18+
import stdlib.fileio.samepath
19+
20+
tc.verifyEmpty(samepath(string.empty, string.empty))
21+
tc.verifyTrue(samepath("", ""))
22+
tc.verifyFalse(samepath("a", "b"))
23+
tc.verifyTrue(samepath("a/b/..", "a/c/.."))
24+
tc.verifyTrue(samepath(".", "a/.."))
1525

1626
end
1727

0 commit comments

Comments
 (0)