Skip to content

Commit e473964

Browse files
committed
absolute: no drop_slash. Make test robust
1 parent d761731 commit e473964

File tree

3 files changed

+48
-20
lines changed

3 files changed

+48
-20
lines changed

+stdlib/absolute.m

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@
4242
end
4343
b = stdlib.posix(b);
4444

45-
if stdlib.is_absolute(b)
46-
c = strcat(b, "/", c);
47-
else
48-
c = strcat(pwd(), "/", b, "/", c);
45+
if ~stdlib.is_absolute(b)
46+
b = strcat(pwd(), "/", b);
4947
end
5048

51-
c = stdlib.drop_slash(c);
49+
if stdlib.len(c) == 0
50+
c = b;
51+
else
52+
c = strcat(b, "/", c);
53+
end
5254

5355
end
5456

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Filesystem.class
2+
CodeIssues.sarif
23

34
code-coverage.xml
45

test/TestAbsolute.m

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,61 @@
11
classdef TestAbsolute < matlab.unittest.TestCase
22

3+
34
properties (TestParameter)
4-
p1 = init1arg()
5-
p2 = init2arg()
5+
p1
6+
p2
67
end
78

89

9-
methods(Test)
10+
methods (TestParameterDefinition, Static)
1011

11-
function test_absolute1arg(tc, p1)
12-
tc.verifyEqual(stdlib.absolute(p1{1}), p1{2})
12+
function p1 = init1arg()
13+
p1 = {"", "hi", "./hi", "../hi"};
1314
end
1415

15-
function test_absolute2arg(tc, p2)
16-
tc.verifyEqual(stdlib.absolute(p2{1}, p2{2}), p2{3})
16+
function p2 = init2arg()
17+
p2 = {{"", ""}, {"", "hi"}, {"hi", ""}, {"there", "hi"}};
18+
end
19+
20+
1721
end
1822

23+
24+
methods(Test)
25+
26+
function test_absolute1arg(tc, p1)
27+
import matlab.unittest.fixtures.CurrentFolderFixture
28+
td = tc.createTemporaryFolder();
29+
tc.applyFixture(CurrentFolderFixture(td))
30+
31+
r = stdlib.posix(td);
32+
33+
if strlength(p1)
34+
r = r + "/" + p1;
1935
end
2036

37+
tc.verifyEqual(stdlib.absolute(p1), r)
2138
end
2239

2340

24-
function p = init1arg()
25-
td = stdlib.posix(pwd());
26-
r = td + "/hi";
41+
function test_absolute2arg(tc, p2)
42+
import matlab.unittest.fixtures.CurrentFolderFixture
43+
td = tc.createTemporaryFolder();
44+
tc.applyFixture(CurrentFolderFixture(td))
45+
46+
r = stdlib.posix(td);
47+
48+
if strlength(p2{2})
49+
r = r + "/" + p2{2};
50+
end
2751

28-
p = {{"", td}, {"hi", r}, {"./hi", td + "/./hi"}, {"../hi", td + "/../hi"}};
52+
if strlength(p2{1})
53+
r = r + "/" + p2{1};
2954
end
3055

31-
function p = init2arg()
32-
td = stdlib.posix(pwd());
33-
r = td + "/hi";
56+
tc.verifyEqual(stdlib.absolute(p2{1}, p2{2}), r)
57+
end
58+
59+
end
3460

35-
p = {{"", "", td}, {"", "hi", r}, {"hi", "", r}, {"there", "hi", td + "/hi/there"}};
3661
end

0 commit comments

Comments
 (0)