Skip to content

Commit 10a6841

Browse files
committed
relative_to: choose_method
1 parent 24ba223 commit 10a6841

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

+stdlib/private/choose_method.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
end
2828
case {"legacy", "sys"}, has = true;
2929
case "native", has = stdlib.strempty(minVersion) || ~isMATLABReleaseOlderThan(minVersion);
30-
case "sys"
31-
has = true;
3230
otherwise
3331
has = str2func("stdlib.has_" + m);
3432
end

+stdlib/relative_to.m

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@
1010
% javaPathObject(base).relativize(javaPathObject(other))
1111
% https://docs.oracle.com/javase/8/docs/api/java/nio/file/Path.html#relativize-java.nio.file.Path-
1212

13-
function rel = relative_to(base, other)
13+
function rel = relative_to(base, other, method)
1414
arguments
1515
base {mustBeTextScalar}
1616
other {mustBeTextScalar}
17+
method (1,:) string = ["python", "native"]
1718
end
1819

19-
if stdlib.has_python()
20-
rel = stdlib.python.relative_to(base, other);
21-
else
22-
rel = stdlib.native.relative_to(base, other);
23-
end
20+
fun = choose_method(method, "relative_to");
21+
22+
rel = fun(base, other);
2423

2524
end

test/TestRelative.m

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
properties (TestParameter)
88
pr = init_rel()
99
pp = init_prox()
10-
rel_fun = {@stdlib.relative_to, @stdlib.native.relative_to, @stdlib.python.relative_to}
10+
rel_fun = {"native", "python"}
1111
end
1212

1313
methods(TestClassSetup)
@@ -18,13 +18,12 @@ function pkg_path(tc)
1818
end
1919

2020

21-
2221
methods (Test)
2322

2423
function test_relative_to(tc, pr, rel_fun)
25-
is_capable(tc, rel_fun)
24+
is_capable(tc, str2func("stdlib." + rel_fun + ".relative_to"))
2625

27-
tc.verifyEqual(rel_fun(pr{1}, pr{2}), pr{3}, ...
26+
tc.verifyEqual(stdlib.relative_to(pr{1}, pr{2}, rel_fun), pr{3}, ...
2827
"relative_to(" + pr{1} + "," + pr{2}+")")
2928
end
3029

0 commit comments

Comments
 (0)