Skip to content

Commit aae6780

Browse files
committed
testFilename: simpler
1 parent 92e7313 commit aae6780

File tree

4 files changed

+76
-84
lines changed

4 files changed

+76
-84
lines changed

test/TestExpanduser.m

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

55
properties (TestParameter)
6-
p
6+
p = init_exp()
7+
end
8+
9+
10+
methods (Test)
11+
12+
function test_expanduser(tc, p)
13+
tc.verifyEqual(stdlib.expanduser(p{1}), p{2})
14+
end
15+
16+
end
17+
718
end
819

920

10-
methods (TestParameterDefinition, Static)
1121
function p = init_exp()
1222

1323
if ispc
@@ -27,14 +37,3 @@
2737
{"~" + filesep() + "c", fullfile(h, "c")}};
2838

2939
end
30-
end
31-
32-
methods (Test)
33-
34-
function test_expanduser(tc, p)
35-
tc.verifyEqual(stdlib.expanduser(p{1}), p{2})
36-
end
37-
38-
end
39-
40-
end

test/TestFilename.m

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

55
properties (TestParameter)
6-
p
6+
p = init_p()
77
backend = {'regexp', 'pattern'}
88
end
99

1010

11-
methods (TestParameterDefinition, Static)
12-
function p = init_p()
13-
p = {
14-
{'', ""}, ...
15-
{"", ""}, ...
16-
{"Hi", "Hi"}, ...
17-
{"/a/b/c", "c"}, ...
18-
{'a/b/c.txt', "c.txt"}, ...
19-
{"a///b//c.txt.gz", "c.txt.gz"}, ...
20-
{"a/b/.hello", ".hello"}
21-
};
22-
23-
if ispc()
24-
p{end+1} = {"c:/df\df.txt", "df.txt"};
25-
end
26-
end
27-
end
28-
29-
3011
methods (Test)
3112

3213
function test_filename(tc, p, backend)
@@ -44,3 +25,20 @@ function test_filename_array(tc, backend)
4425
end
4526

4627
end
28+
29+
30+
function p = init_p()
31+
p = {
32+
{'', ""}, ...
33+
{"", ""}, ...
34+
{"Hi", "Hi"}, ...
35+
{"/a/b/c", "c"}, ...
36+
{'a/b/c.txt', "c.txt"}, ...
37+
{"a///b//c.txt.gz", "c.txt.gz"}, ...
38+
{"a/b/.hello", ".hello"}
39+
};
40+
41+
if ispc()
42+
p{end+1} = {"c:/df\df.txt", "df.txt"};
43+
end
44+
end

test/TestNormalize.m

Lines changed: 20 additions & 24 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 = {'R2021a', 'pure'}) ...
2+
TestTags = {'R2019b', 'pure'}) ...
33
TestNormalize < matlab.unittest.TestCase
44

55
properties (TestParameter)
@@ -16,11 +16,28 @@
1616
{"./a/.", "a"}, ...
1717
{"../a", "../a"}
1818
};
19-
d
19+
d = init_drop_slash()
2020
end
2121

2222

23-
methods (TestParameterDefinition, Static)
23+
methods (Test)
24+
25+
function test_normalize(tc, p)
26+
c = stdlib.normalize(p{1});
27+
28+
tc.verifyEqual(c, p{2}, ...
29+
sprintf("normalize(%s)", p{1}))
30+
end
31+
32+
function test_drop_slash(tc, d)
33+
tc.verifyEqual(stdlib.drop_slash(d{1}), d{2}, ...
34+
sprintf("drop_slash(%s)", d{1}))
35+
end
36+
37+
end
38+
39+
end
40+
2441

2542
function d = init_drop_slash()
2643
d = {...
@@ -45,24 +62,3 @@
4562
end
4663

4764
end
48-
49-
end
50-
51-
52-
methods (Test)
53-
54-
function test_normalize(tc, p)
55-
c = stdlib.normalize(p{1});
56-
57-
tc.verifyEqual(c, p{2}, ...
58-
sprintf("normalize(%s)", p{1}))
59-
end
60-
61-
function test_drop_slash(tc, d)
62-
tc.verifyEqual(stdlib.drop_slash(d{1}), d{2}, ...
63-
sprintf("drop_slash(%s)", d{1}))
64-
end
65-
66-
end
67-
68-
end

test/TestParent.m

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

55
properties (TestParameter)
6-
p
6+
p = init_parent()
77
end
88

9-
methods (TestParameterDefinition, Static)
9+
10+
methods (Test, TestTags=["pure"])
11+
12+
function test_parent(tc, p)
13+
pr = stdlib.parent(p{1});
14+
tc.verifyEqual(pr, p{2}, sprintf("parent(%s)", p{1}))
15+
end
16+
17+
18+
function test_parent_array(tc)
19+
20+
in = ["", ".", "..", "../..", "a/", "a/b", "ab/.parent", "ab/.parent.txt", "a/b/../.parent.txt"];
21+
exp = [".", ".", ".", "..", ".", "a", "ab", "ab", "a/b/.."];
22+
23+
out = stdlib.parent(in);
24+
tc.verifyEqual(out, exp)
25+
end
26+
27+
end
28+
end
29+
30+
1031
function p = init_parent()
1132

1233
p = {
@@ -33,25 +54,3 @@
3354
p{end+1} = {'a//b', "a"};
3455

3556
end
36-
end
37-
38-
39-
methods (Test, TestTags=["pure"])
40-
41-
function test_parent(tc, p)
42-
pr = stdlib.parent(p{1});
43-
tc.verifyEqual(pr, p{2}, sprintf("parent(%s)", p{1}))
44-
end
45-
46-
47-
function test_parent_array(tc)
48-
49-
in = ["", ".", "..", "../..", "a/", "a/b", "ab/.parent", "ab/.parent.txt", "a/b/../.parent.txt"];
50-
exp = [".", ".", ".", "..", ".", "a", "ab", "ab", "a/b/.."];
51-
52-
out = stdlib.parent(in);
53-
tc.verifyEqual(out, exp)
54-
end
55-
56-
end
57-
end

0 commit comments

Comments
 (0)