Skip to content

Commit 2b149e7

Browse files
committed
test: consolidate values
1 parent 8d73f6b commit 2b149e7

File tree

2 files changed

+79
-65
lines changed

2 files changed

+79
-65
lines changed

test/TestFileImpure.m

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
end
66

77
properties(TestParameter)
8-
in_exists = {pwd, mfilename("fullpath") + ".m", "not-exists"}
9-
ref_exists = {true, true, false}
8+
p_exists = {{pwd, true}, {mfilename("fullpath") + ".m", true}, {tempname, false}}
109
% on CI matlabroot can be writable!
1110
in_is_write = {pwd, "not-exists"};
1211
ref_is_write = {true, false}
13-
in_expand = {"", "~abc", "~", "~/foo"}
14-
ref_expand
15-
in_same = {"", tempname, "..", ".."}
16-
other_same = {"", tempname, "./..", fullfile(pwd, "..")}
17-
ref_same = {false, false, true, true}
12+
p_expand
13+
p_same = {...
14+
{"","", false}, ...
15+
{tempname, tempname, false}, ...
16+
{"..", "./..", true}, ...
17+
{"..", pwd + "/..", true}}
1818
end
1919

2020
properties
@@ -24,12 +24,11 @@
2424

2525
methods (TestParameterDefinition, Static)
2626

27-
function ref_expand = init_expand(classToTest) %#ok<INUSD>
27+
function p_expand = init_expand(classToTest) %#ok<INUSD>
2828
cwd = fileparts(mfilename("fullpath"));
2929
top = fullfile(cwd, "..");
3030
addpath(top)
31-
32-
ref_expand = {"", "~abc", stdlib.homedir, stdlib.join(stdlib.homedir, "foo")};
31+
p_expand = {{"", ""}, {"~abc", "~abc"}, {"~", stdlib.homedir}, {"~/foo", stdlib.join(stdlib.homedir, "foo")}};
3332
end
3433
end
3534

@@ -52,13 +51,13 @@ function setup_path(tc)
5251

5352
methods (Test, ParameterCombination = 'sequential')
5453

55-
function test_exists(tc, in_exists, ref_exists)
56-
tc.verifyEqual(stdlib.exists(in_exists), ref_exists)
54+
function test_exists(tc, p_exists)
55+
tc.verifyEqual(stdlib.exists(p_exists{1}), p_exists{2})
5756
end
5857

5958

60-
function test_is_readable(tc, in_exists, ref_exists)
61-
tc.verifyEqual(stdlib.is_readable(in_exists), ref_exists)
59+
function test_is_readable(tc, p_exists)
60+
tc.verifyEqual(stdlib.is_readable(p_exists{1}), p_exists{2})
6261
end
6362

6463

@@ -67,8 +66,8 @@ function test_is_writable(tc, in_is_write, ref_is_write)
6766
end
6867

6968

70-
function test_expanduser(tc, in_expand, ref_expand)
71-
tc.verifyEqual(stdlib.expanduser(in_expand), ref_expand)
69+
function test_expanduser(tc, p_expand)
70+
tc.verifyEqual(stdlib.expanduser(p_expand{1}), p_expand{2})
7271
end
7372

7473

@@ -87,8 +86,8 @@ function test_makedir(tc)
8786
end
8887

8988
%%
90-
function test_samepath(tc, in_same, other_same, ref_same)
91-
tc.verifyEqual(stdlib.samepath(in_same, other_same), ref_same)
89+
function test_samepath(tc, p_same)
90+
tc.verifyEqual(stdlib.samepath(p_same{1}, p_same{2}), p_same{3})
9291
end
9392

9493

test/TestFilePure.m

Lines changed: 62 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
end
66

77
properties (TestParameter)
8-
base_relative_to
9-
other_relative_to
10-
ref_relative_to
11-
ref_proximate_to
8+
p_relative_to
9+
p_proximate_to
1210
in_is_absolute
1311
ref_is_absolute
1412
in_filename = {'', '/foo/bar/baz', '/foo/bar/baz/', 'foo/bar/baz.txt', 'foo/bar/baz.txt.gz'}
@@ -20,17 +18,27 @@
2018
in_parent
2119
ref_parent
2220

23-
in_join = {"", "a", "", "a/b/", "/", "", "a", "a//", "a/b/../", "a/b", "a/b", "ab/cd"}
24-
other_join = {"", "", "b", "c/", "", "/", "b//", "b//", "c/d/../", "..", "c/d", "/ef"}
25-
ref_join = {"", "a", "b", "a/b/c", "/", "/", "a/b", "a/b", "a/c", "a", "a/b/c/d", "/ef"}
21+
p_join = {{"", "", ""}, ...
22+
{"a", "", "a"}, ...
23+
{"", "a", "a"}, ...
24+
{"a/b/", "c/", "a/b/c"}, ...
25+
{"/", "", "/"}, ...
26+
{"", "/", "/"}, ...
27+
{"a", "b//", "a/b"}, ...
28+
{"a//", "b//", "a/b"}, ...
29+
{"a/b/../", "c/d/../", "a/c"}, ...
30+
{"a/b", "..", "a"}, ...
31+
{"a/b", "c/d", "a/b/c/d"}, ...
32+
{"ab/cd", "/ef", "/ef"} ...
33+
};
2634

2735
in_suffix = {"", "/foo/bar/baz", "/foo/bar/baz/", "foo/bar/baz.txt", "foo/bar/baz.txt.gz", ".stat", ".stat.txt"}
2836
ref_suffix = {"", "", "", ".txt", ".gz", ".stat", ".txt"}
2937

30-
in_norm = {"", "//a/b/", "/a/b/", "a/b/", "a/../c", "a/b/../c", "a/b/../../c", "a/b/../../c/..", ...
31-
"a/b/../../c/../..", "a////b"}
32-
ref_norm = {".", "/a/b", "/a/b", "a/b", "c", "a/c", "c", ".", ...
33-
"..", "a/b"}
38+
in_norm = {"", "a/..", "//a/b/", "/a/b/", "a/b/", "a/../c", "a/b/../c", "a/b/../../c", "a/b/../../c/..", ...
39+
"a/b/../../c/../..", "a////b", ".a", "..a", "a.", "a..", "./a/.", "../a"}
40+
ref_norm = {".", ".", "/a/b", "/a/b", "a/b", "c", "a/c", "c", ".", ...
41+
"..", "a/b", ".a", "..a", "a.", "a..", "a", "../a"}
3442

3543
in_root
3644
ref_root
@@ -41,26 +49,54 @@
4149
end
4250

4351
methods (TestParameterDefinition, Static)
44-
function [base_relative_to, other_relative_to, ref_relative_to, ref_proximate_to, in_root, ref_root, in_parent, ref_parent] = init_relative_to(classToTest) %#ok<INUSD>
52+
function [p_relative_to, p_proximate_to, in_root, ref_root, in_parent, ref_parent] = init_relative_to(classToTest) %#ok<INUSD>
4553

4654
in_root = {"", "a/b", "./a/b", "../a/b", "/etc", "c:/etc"};
4755
ref_root = {"", "", "", "", "/", ""};
4856

4957
in_parent = {"", ".", "..", "../..", "a/", "a/b", "a/b/", "ab/.parent", "ab/.parent.txt", "a/b/../.parent.txt", "a/////b////c", "c:/", "c:\", "c:/a/b", "c:\a/b"};
5058
ref_parent = {".", ".", ".", "..", ".", "a", "a", "ab", "ab", "a/b/..", "a/b", ".", ".", "c:/a", "c:\a"};
5159

60+
p_relative_to = {{'', '', '.'}, ...
61+
{'Hello', 'Hello', '.'}, ...
62+
{'Hello', 'Hello/', '.'}, ...
63+
{'./this/one', './this/two', '../two'}, ...
64+
{'/path/same', '/path/same/hi/..', '.'}, ...
65+
{'', '/', ''}, ...
66+
{'/', '', ''}, ...
67+
{'/', '/', '.'}, ...
68+
{'/dev/null', '/dev/null', '.'}, ...
69+
{'/a/b', 'c', ''}, ...
70+
{'c', '/a/b', ''}, ...
71+
{'/a/b', '/a/b', '.'}, ...
72+
{'/a/b', '/a', '..'}, ...
73+
{'/a/b/c/d', '/a/b', '../..'}, ...
74+
{'/this/one', '/this/two', '../two'}, ...
75+
{'/path/same', '/path/same/hi/..', '.'}};
76+
77+
p_proximate_to = p_relative_to;
78+
79+
p_proximate_to{6}{3} = '/';
80+
p_proximate_to{10}{3} = 'c';
81+
p_proximate_to{11}{3} = '/a/b';
82+
5283
if ispc
5384

54-
base_relative_to = {'', 'Hello', 'Hello', ...
55-
'c:\a\b', 'c:\', 'c:/a/b', 'c:/a/b', 'c:\a/b\c/d', 'c:/path'};
85+
p_relative_to = [p_relative_to, ...
86+
{{'c:\a\b', 'c:/', '../..'}, ...
87+
{'c:\', 'c:/a/b', 'a/b'}, ...
88+
{'c:/a/b', 'c:/a/b', '.'}, ...
89+
{'c:/a/b', 'c:/a', '..'}, ...
90+
{'c:\a/b\c/d', 'c:/a\b', '../..'}, ...
91+
{'c:/path', 'd:/path', ''}}];
5692

57-
other_relative_to = {'', 'Hello', 'Hello/', ...
58-
'c:/', 'c:/a/b', 'c:/a/b', 'c:/a', 'c:/a\b', 'd:/path'};
93+
p_proximate_to = p_relative_to;
5994

60-
ref_relative_to = {'.', '.', '.', '../..', 'a/b', '.', '..', '../..', ''};
95+
p_proximate_to{6}{3} = '/';
96+
p_proximate_to{10}{3} = 'c';
97+
p_proximate_to{11}{3} = '/a/b';
6198

62-
ref_proximate_to = ref_relative_to;
63-
ref_proximate_to{end} = other_relative_to{end};
99+
p_proximate_to{end}{3} = "d:/path";
64100

65101
ref_parent{12} = "c:/";
66102
ref_parent{13} = "c:/";
@@ -70,28 +106,7 @@
70106
ref_root{5} = "";
71107
ref_root{6} = "c:/";
72108

73-
else
74-
75-
base_relative_to = {'', '', '/', '/', 'Hello', 'Hello', '/dev/null', '/a/b', 'c', ...
76-
'/a/b', '/a/b', '/a/b/c/d', '/this/one', '/path/same'};
77-
78-
other_relative_to = {'', '/', '', '/', 'Hello', 'Hello/', '/dev/null', 'c', '/a/b', ...
79-
'/a/b', '/a', '/a/b', '/this/two', '/path/same/hi/..'};
80-
81-
ref_relative_to = {'.', '', '', '.', '.', '.', '.', '', '', ...
82-
'.', '..', '../..', '../two', '.'};
83-
84-
ref_proximate_to = ref_relative_to;
85-
ref_proximate_to{2} = '/';
86-
ref_proximate_to{8} = 'c';
87-
ref_proximate_to{9} = '/a/b';
88-
89-
end
90-
91-
base_relative_to{end+1} = './this/one';
92-
other_relative_to{end+1} = './this/two';
93-
ref_relative_to{end+1} = '../two';
94-
ref_proximate_to{end+1} = ref_relative_to{end};
109+
end % if ispc
95110

96111
end
97112

@@ -170,8 +185,8 @@ function test_posix(tc)
170185
end
171186

172187

173-
function test_join(tc, in_join, other_join, ref_join)
174-
tc.verifyEqual(stdlib.join(in_join, other_join), ref_join)
188+
function test_join(tc, p_join)
189+
tc.verifyEqual(stdlib.join(p_join{1}, p_join{2}), p_join{3})
175190
end
176191

177192

@@ -236,15 +251,15 @@ function test_with_suffix(tc)
236251
end
237252

238253

239-
function test_relative_to(tc, base_relative_to, other_relative_to, ref_relative_to)
254+
function test_relative_to(tc, p_relative_to)
240255
tc.assumeTrue(stdlib.has_java)
241-
tc.verifyEqual(stdlib.relative_to(base_relative_to, other_relative_to), string(ref_relative_to))
256+
tc.verifyEqual(stdlib.relative_to(p_relative_to{1}, p_relative_to{2}), string(p_relative_to{3}))
242257
end
243258

244259

245-
function test_proximate_to(tc, base_relative_to, other_relative_to, ref_proximate_to)
260+
function test_proximate_to(tc, p_proximate_to)
246261
tc.assumeTrue(stdlib.has_java)
247-
tc.verifyEqual(stdlib.proximate_to(base_relative_to, other_relative_to), string(ref_proximate_to))
262+
tc.verifyEqual(stdlib.proximate_to(p_proximate_to{1}, p_proximate_to{2}), string(p_proximate_to{3}))
248263
end
249264

250265

0 commit comments

Comments
 (0)