Skip to content

Commit c9c1cf4

Browse files
committed
test:parent own file
1 parent 31f7271 commit c9c1cf4

File tree

2 files changed

+83
-35
lines changed

2 files changed

+83
-35
lines changed

test/TestFilePure.m

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
{"a/b/c.txt.gz", "c.txt.gz"}
1818
};
1919

20-
p_parent
21-
2220
p_stem ={{"/a/b/c", "c"}, {"/a/b/c/", ""}, {"a/b/c/", ""}, {"a/b/c.txt", "c"}, {"a/b/c.txt.gz", "c.txt"}}
2321

2422
p_join = {{"", "", ""}, ...
@@ -70,7 +68,7 @@
7068

7169
methods (TestParameterDefinition, Static)
7270

73-
function [p_root, p_root_name, p_parent] = init_relative_to(classToTest) %#ok<INUSD>
71+
function [p_root, p_root_name] = init_relative_to(classToTest) %#ok<INUSD>
7472

7573
p_root = {{"", ""}, ...
7674
{"a/b", ""}, ...
@@ -84,37 +82,11 @@
8482
{"/etc", ""}, ...
8583
{"c:/etc", ""}};
8684

87-
p_parent = {
88-
{"", "."}, ...
89-
{".", "."}, ...
90-
{"..", "."}, ...
91-
{"../..", ".."}, ...
92-
{"a/", "."}, ...
93-
{"a/b", "a"}, ...
94-
{"a/b/", "a"}, ...
95-
{"ab/.parent", "ab"}, ...
96-
{"ab/.parent.txt", "ab"}, ...
97-
{"a/b/../.parent.txt", "a/b/.."}, ...
98-
{"a/////b////c", "a/b"}, ...
99-
{"c:/", "."}, ...
100-
{"c:\", "."}, ...
101-
{"c:/a/b", "c:/a"}, ...
102-
{"c:\a/b", "c:\a"}
103-
};
104-
10585
if ispc
106-
p_parent{12}{2} = "c:/";
107-
p_parent{13}{2} = "c:/";
108-
p_parent{14}{2} = "c:/a";
109-
p_parent{15}{2} = "c:/a";
110-
p_parent{end+1} = {"c:/a", "c:/"};
111-
p_parent{end+1} = {"c:", "c:/"};
112-
11386
p_root{5}{2} = "c:";
11487
p_root{6}{2} = "c:/";
11588

11689
p_root_name{4}{2} = "c:";
117-
11890
end
11991

12092
end
@@ -170,16 +142,10 @@ function test_join(tc, p_join)
170142
tc.verifyEqual(stdlib.join(p_join{1}, p_join{2}), p_join{3})
171143
end
172144

173-
174145
function test_filename(tc, p_filename)
175146
tc.verifyEqual(stdlib.filename(p_filename{1}), string(p_filename{2}))
176147
end
177148

178-
179-
function test_parent(tc, p_parent)
180-
tc.verifyEqual(stdlib.parent(p_parent{1}), p_parent{2}, p_parent{1})
181-
end
182-
183149
function test_suffix(tc, p_suffix)
184150
tc.verifyEqual(stdlib.suffix(p_suffix{1}), string(p_suffix{2}))
185151
end

test/TestParent.m

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
classdef TestParent < matlab.unittest.TestCase
2+
3+
properties (ClassSetupParameter)
4+
classToTest = {"TestParent"};
5+
end
6+
7+
properties (TestParameter)
8+
p_parent
9+
end
10+
11+
properties
12+
tobj
13+
end
14+
15+
16+
methods (TestParameterDefinition, Static)
17+
18+
function [p_parent] = init_relative_to(classToTest) %#ok<INUSD>
19+
20+
p_parent = {
21+
{"", "."}, ...
22+
{".", "."}, ...
23+
{"..", "."}, ...
24+
{"../..", ".."}, ...
25+
{"a/", "."}, ...
26+
{"a/b", "a"}, ...
27+
{"a/b/", "a"}, ...
28+
{"ab/.parent", "ab"}, ...
29+
{"ab/.parent.txt", "ab"}, ...
30+
{"a/b/../.parent.txt", "a/b/.."}, ...
31+
{"a/////b////c", "a/b"}, ...
32+
{"c:/", "."}, ...
33+
{"c:\", "."}, ...
34+
{"c:/a/b", "c:/a"}, ...
35+
{"c:\a/b", "c:\a"}
36+
};
37+
38+
if ispc
39+
p_parent{12}{2} = "c:/";
40+
p_parent{13}{2} = "c:/";
41+
p_parent{14}{2} = "c:/a";
42+
p_parent{15}{2} = "c:/a";
43+
p_parent{end+1} = {"c:/a", "c:/"};
44+
p_parent{end+1} = {"c:", "c:/"};
45+
46+
p_root{5}{2} = "c:";
47+
p_root{6}{2} = "c:/";
48+
49+
p_root_name{4}{2} = "c:";
50+
51+
end
52+
53+
end
54+
55+
end
56+
57+
methods (TestClassSetup)
58+
59+
function classSetup(tc, classToTest)
60+
constructor = str2func(classToTest);
61+
tc.tobj = constructor();
62+
end
63+
64+
function setup_path(tc)
65+
import matlab.unittest.fixtures.PathFixture
66+
cwd = fileparts(mfilename("fullpath"));
67+
top = fullfile(cwd, "..");
68+
tc.applyFixture(PathFixture(top))
69+
end
70+
71+
end
72+
73+
74+
methods (Test, ParameterCombination = "sequential")
75+
76+
function test_parent(tc, p_parent)
77+
tc.verifyEqual(stdlib.parent(p_parent{1}), p_parent{2}, p_parent{1})
78+
end
79+
80+
end
81+
82+
end

0 commit comments

Comments
 (0)