Skip to content

Commit f8b0737

Browse files
committed
add array tests
1 parent 5217d23 commit f8b0737

File tree

5 files changed

+37
-5
lines changed

5 files changed

+37
-5
lines changed

+stdlib/absolute.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
function c = absolute(p, base)
1919
arguments
2020
p string
21-
base {mustBeTextScalar} = pwd()
21+
base (1,1) string = pwd()
2222
end
2323

2424
i = stdlib.is_absolute(p);
@@ -29,6 +29,10 @@
2929
base = fullfile(pwd(), base);
3030
end
3131

32-
c(~i) = fullfile(base, p(~i));
32+
i = ~i;
33+
c(i & stdlib.strempty(p(i))) = base;
34+
35+
i = i & ~stdlib.strempty(p(i));
36+
c(i) = fullfile(base, p(i));
3337

3438
end

+stdlib/suffix.m

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
[~, n, s] = fileparts(p);
99

10-
if stdlib.strempty(n)
11-
s = n;
12-
end
10+
i = stdlib.strempty(n);
11+
s(i) = n(i);
1312

1413
end

test/TestAbsolute.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ function test_absolute2arg(tc, p2)
7272
tc.verifyEqual(rabs, string(r))
7373
end
7474

75+
76+
function test_absolute_array(tc)
77+
78+
in = ["", "hi"];
79+
r = stdlib.absolute(in);
80+
81+
tc.verifyEqual(r, [pwd(), fullfile(pwd(), "hi")])
82+
83+
end
84+
7585
end
7686

7787
end

test/TestCanonical.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ function test_canonical(tc, p, fun)
3232
tc.verifyEqual(c, p{2})
3333
end
3434

35+
function test_canonical_array(tc)
36+
in = ["", "hi", "/ok", "not-exist/a/.."];
37+
c = stdlib.canonical(in);
38+
39+
tc.verifyEqual(c, ["", "hi", filesep + "ok", "not-exist"])
40+
end
41+
3542
end
3643

3744
end

test/TestResolve.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ function test_resolve_fullpath(tc, p)
7878
tc.verifyEqual(stdlib.resolve(a), b)
7979
end
8080

81+
function test_resolve_array(tc)
82+
in = ["", "hi", "/ok", "not-exist/a/.."];
83+
c = stdlib.resolve(in);
84+
85+
exp = [pwd(), fullfile(pwd(), "hi"), filesep + "ok", fullfile(pwd(), "not-exist")];
86+
if ispc()
87+
exp(3) = fullfile(pwd(), "ok");
88+
end
89+
90+
tc.verifyEqual(c, exp)
91+
end
92+
8193
end
8294

8395
end

0 commit comments

Comments
 (0)