Skip to content

Commit 0d6a536

Browse files
committed
with_suffix: no coerce
1 parent 9939187 commit 0d6a536

File tree

3 files changed

+10
-29
lines changed

3 files changed

+10
-29
lines changed

+stdlib/with_suffix.m

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,13 @@
77
% * f: modified filename
88

99
function f = with_suffix(p, suffix)
10-
arguments
11-
p string
12-
suffix string
13-
end
1410

1511
f = extractBefore(p, stdlib.suffix(p));
1612

17-
i = stdlib.strempty(f);
18-
f(i) = p(i);
13+
if stdlib.strempty(f)
14+
f = p;
15+
end
1916

20-
f = f + suffix;
17+
f = append(f, suffix);
2118

2219
end

test/TestExpanduser.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
classdef (SharedTestFixtures={ matlab.unittest.fixtures.PathFixture(fileparts(fileparts(mfilename('fullpath'))))}, ...
2-
TestTags = {'R2019b', 'impure'}) ...
2+
TestTags = {'R2019a', 'impure'}) ...
33
TestExpanduser < matlab.unittest.TestCase
44

55
properties (TestParameter)

test/TestWithSuffix.m

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
classdef (SharedTestFixtures={ matlab.unittest.fixtures.PathFixture(fileparts(fileparts(mfilename('fullpath'))))}, ...
2-
TestTags = {'pure'}) ...
2+
TestTags = {'R2019a', 'pure'}) ...
33
TestWithSuffix < matlab.unittest.TestCase
44

55

@@ -10,32 +10,16 @@
1010
{"", ".nc", ".nc"}, ...
1111
{"hello.txt.gz", ".bz", "hello.txt.bz"}, ...
1212
{"a/b.c/hello.txt", ".gz", "a/b.c/hello.gz"}, ...
13-
{'a/b/', '.h5', "a/b/.h5"}, ...
13+
{'a/b/', '.h5', 'a/b/.h5'}, ...
1414
{"a/b/.h5", '.nc', "a/b/.h5.nc"}, ...
1515
{".h5", ".nc", ".h5.nc"}, ...
16-
{'a/b', '.nc', "a/b.nc"}};
16+
{'a/b', '.nc', 'a/b.nc'}};
1717
end
1818

1919

20-
methods (Test, TestTags={'R2019b'})
20+
methods (Test)
2121
function test_with_suffix(tc, p)
22-
23-
r = p{3};
24-
25-
tc.verifyEqual(stdlib.with_suffix(p{1}, p{2}), r)
26-
end
27-
end
28-
29-
30-
methods (Test, TestTags={'R2020b'})
31-
32-
function test_with_suffix_array(tc)
33-
tc.assumeFalse(stdlib.matlabOlderThan('R2020b'))
34-
in = ["", ".txt", "a/b/c.txt", "a/b/c.txt.gz", "a/b/c"];
35-
new = [".txt", ".gz", "", ".bz", ".nc"];
36-
exp = [".txt", ".txt.gz", "a/b/c", "a/b/c.txt.bz", "a/b/c.nc"];
37-
out = stdlib.with_suffix(in, new);
38-
tc.verifyEqual(out, exp)
22+
tc.verifyEqual(stdlib.with_suffix(p{1}, p{2}), p{3})
3923
end
4024
end
4125

0 commit comments

Comments
 (0)