Skip to content

Commit 0532b05

Browse files
committed
canonical: choose_method
1 parent 8f80d5e commit 0532b05

File tree

4 files changed

+13
-17
lines changed

4 files changed

+13
-17
lines changed

+stdlib/+native/canonical_legacy.m renamed to +stdlib/+legacy/canonical.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function c = canonical_legacy(file, strict)
1+
function c = canonical(file, strict)
22

33
c = "";
44

+stdlib/canonical.m

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,15 @@
1212
%%% Outputs
1313
% * c: canonical path, if determined
1414

15-
function c = canonical(p, strict)
15+
function c = canonical(p, strict, method)
1616
arguments
1717
p {mustBeTextScalar}
1818
strict (1,1) logical = false
19+
method (1,:) string = ["native", "legacy"]
1920
end
2021

22+
fun = choose_method(method, "canonical", 'R2024a');
2123

22-
if isMATLABReleaseOlderThan('R2024a')
23-
c = stdlib.native.canonical_legacy(p, strict);
24-
else
25-
c = stdlib.native.canonical(p, strict);
26-
end
24+
c = fun(p, strict);
2725

2826
end

test/TestCanonical.m

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{"not-exist/a/..", "not-exist"}, ...
1010
{"./not-exist", "not-exist"}
1111
};
12-
fun = {@stdlib.canonical, @stdlib.native.canonical, @stdlib.native.canonical_legacy}
12+
fun = {"native", "legacy"}
1313
end
1414

1515
methods(TestClassSetup)
@@ -23,9 +23,13 @@ function pkg_path(tc)
2323
methods(Test, TestTags="impure")
2424

2525
function test_canonical(tc, p, fun)
26-
is_capable(tc, fun)
27-
28-
tc.verifyEqual(fun(p{1}, false), p{2})
26+
try
27+
c = stdlib.canonical(p{1}, false, fun);
28+
catch e
29+
tc.verifyEqual(e.identifier, 'stdlib:choose_method:NameError', e.message)
30+
return
31+
end
32+
tc.verifyEqual(c, p{2})
2933
end
3034

3135
end

test/is_capable.m

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ function is_capable(tc, f)
4242
tc.assumeTrue(isunix(), "unix only function")
4343
end
4444

45-
elseif contains(n, ".native.")
46-
47-
if endsWith(n, "canonical")
48-
tc.assumeFalse(isMATLABReleaseOlderThan('R2024a'))
49-
end
50-
5145
end
5246

5347
end

0 commit comments

Comments
 (0)