Skip to content

Commit c0b31da

Browse files
committed
is_writable: choose_method
1 parent 4e6252f commit c0b31da

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

+stdlib/+native/is_writable_legacy.m renamed to +stdlib/+legacy/is_writable.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function y = is_writable_legacy(file)
1+
function y = is_writable(file)
22

33
if stdlib.exists(file)
44
a = stdlib.native.file_attributes(file);

+stdlib/is_writable.m

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,14 @@
55
%% Outputs
66
% ok: true if file is writable
77

8-
function y = is_writable(file)
8+
function y = is_writable(file, method)
99
arguments
1010
file {mustBeTextScalar}
11+
method (1,:) string = ["java", "native", "legacy"]
1112
end
1213

13-
if stdlib.has_java()
14-
y = stdlib.java.is_writable(file);
15-
elseif isMATLABReleaseOlderThan('R2025a')
16-
y = stdlib.native.is_writable_legacy(file);
17-
else
18-
y = stdlib.native.is_writable(file);
19-
end
14+
fun = choose_method(method, "is_writable", 'R2025a');
15+
16+
y = fun(file);
2017

2118
end

test/TestExists.m

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
}
1212
% on CI matlabroot can be writable!
1313
isr_method = {'java', 'native', 'legacy'}
14-
isw_fun = {@stdlib.is_writable, @stdlib.java.is_writable, @stdlib.native.is_writable, @stdlib.native.is_writable_legacy}
14+
isw_method = {'java', 'native', 'legacy'}
1515
end
1616

1717
methods(TestClassSetup)
@@ -37,19 +37,21 @@ function test_is_readable(tc, Ps, isr_method)
3737
end
3838

3939

40-
function test_is_writable(tc, Ps, isw_fun)
41-
is_capable(tc, isw_fun)
40+
function test_is_writable(tc, Ps, isw_method)
41+
is_capable(tc, str2func("stdlib." + isw_method + ".is_writable"))
4242

43-
ok = isw_fun(Ps{1});
43+
ok = stdlib.is_writable(Ps{1}, isw_method);
4444
tc.verifyEqual(ok, Ps{2}, Ps{1})
4545
end
4646

47-
function test_is_writable_dir(tc)
47+
function test_is_writable_dir(tc, isw_method)
48+
is_capable(tc, str2func("stdlib." + isw_method + ".is_writable"))
49+
4850
tc.assumeFalse(isMATLABReleaseOlderThan('R2022a'))
4951

5052
td = tc.createTemporaryFolder();
5153

52-
tc.verifyTrue(stdlib.is_writable(td))
54+
tc.verifyTrue(stdlib.is_writable(td, isw_method))
5355
end
5456

5557
end

0 commit comments

Comments
 (0)