Skip to content

Commit 129c90c

Browse files
committed
absolute: don't normalize, add test cases like Ffilesystem'
1 parent 8a4dd4f commit 129c90c

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

+stdlib/absolute.m

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
use_java (1,1) logical = false
2525
end
2626

27+
cwd = stdlib.posix(pwd());
28+
29+
if (isempty(p) || strlength(p) == 0) && (isempty(base) || strlength(base) == 0)
30+
c = cwd;
31+
return
32+
end
33+
2734
if expand_tilde
2835
c = stdlib.expanduser(p, use_java);
2936
else
@@ -36,9 +43,14 @@
3643
% .getAbsolutePath(), .toAbsolutePath()
3744
% default is Documents/Matlab, which is probably not wanted.
3845
if isempty(base) || strlength(base) == 0
39-
c = stdlib.join(pwd, c);
46+
c = cwd + "/" + c;
4047
else
41-
c = stdlib.join(stdlib.absolute(base, string.empty, expand_tilde, use_java), c);
48+
d = stdlib.absolute(base, string.empty, expand_tilde, use_java);
49+
if isempty(c) || strlength(c) == 0
50+
c = d;
51+
else
52+
c = d + "/" + c;
53+
end
4254
end
4355
end
4456

test/TestResolve.m

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
classdef TestResolve < matlab.unittest.TestCase
22

3+
methods(TestClassSetup)
4+
5+
function setup_path(tc)
6+
import matlab.unittest.fixtures.PathFixture
7+
cwd = fileparts(mfilename("fullpath"));
8+
top = fullfile(cwd, "..");
9+
tc.applyFixture(PathFixture(top))
10+
end
11+
12+
end
13+
14+
315
methods(Test)
416

517

@@ -12,11 +24,20 @@ function test_absolute(tc)
1224
td = tc.applyFixture(TemporaryFolderFixture).Folder;
1325
tc.applyFixture(CurrentFolderFixture(td))
1426

15-
tc.verifyEqual(stdlib.absolute(""), stdlib.posix(td))
16-
tc.verifyEqual(stdlib.absolute("",""), stdlib.posix(td))
17-
tc.verifyEqual(stdlib.absolute("hi"), stdlib.join(td, "hi"))
18-
tc.verifyEqual(stdlib.absolute("", "hi"), stdlib.join(td, "hi"))
19-
tc.verifyEqual(stdlib.absolute("there", "hi"), stdlib.join(td, "hi/there"))
27+
td = stdlib.posix(td);
28+
29+
tc.verifyEqual(stdlib.absolute(""), td)
30+
tc.verifyEqual(stdlib.absolute("",""), td)
31+
32+
r = td + "/hi";
33+
tc.verifyEqual(stdlib.absolute("hi"), r)
34+
tc.verifyEqual(stdlib.absolute("", "hi"), r)
35+
tc.verifyEqual(stdlib.absolute("hi", ""), r)
36+
37+
tc.verifyEqual(stdlib.absolute("./hi"), td + "/./hi")
38+
tc.verifyEqual(stdlib.absolute("../hi"), td + "/../hi")
39+
40+
tc.verifyEqual(stdlib.absolute("there", "hi"), td + "/hi/there")
2041

2142
end
2243

0 commit comments

Comments
 (0)