Skip to content

Commit c972820

Browse files
committed
testResolve: improve use_java coverage
1 parent 4c1d019 commit c972820

File tree

2 files changed

+36
-32
lines changed

2 files changed

+36
-32
lines changed

test/TestCanonical.m

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
p = {{"", ""}, {"not-exist", "not-exist"}, {"a/../b", "b"}, ...
77
{"~", stdlib.homedir()}, {"~/", stdlib.homedir()}, ...
88
{"~/..", stdlib.parent(stdlib.homedir())}, ...
9-
{mfilename("fullpath") + ".m/..", stdlib.parent(mfilename("fullpath"))}};
9+
{mfilename("fullpath") + ".m/..", stdlib.parent(mfilename("fullpath"))}, ...
10+
{"~/not-exist/a/..", stdlib.homedir() + "/not-exist"}
11+
};
1012
end
1113

1214

@@ -16,11 +18,6 @@ function test_canonical(tc, p, use_java)
1618
tc.verifyEqual(stdlib.canonical(p{1}, true, use_java), p{2})
1719
end
1820

19-
function test_static(tc)
20-
% ~ is expanded even without expanduser when path exists
21-
tc.verifyEqual(stdlib.canonical("~/nobody/a/..", false), "~/nobody")
22-
end
23-
2421
end
2522

2623
end

test/TestResolve.m

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,66 @@
11
classdef TestResolve < matlab.unittest.TestCase
22

3+
properties (TestParameter)
4+
use_java = num2cell(unique([stdlib.has_java(), false]))
5+
6+
p
7+
end
8+
9+
methods (TestParameterDefinition, Static)
10+
11+
function p = init()
12+
c = stdlib.posix(pwd());
13+
p = {...
14+
{"", c}, {"not-exist", c + "/not-exist"}, ...
15+
{"a/../b", c + "/b"}, ...
16+
{"~", stdlib.homedir()}, {"~/", stdlib.homedir()}, ...
17+
{"~/..", stdlib.parent(stdlib.homedir())}, ...
18+
{mfilename("fullpath") + ".m/..", stdlib.parent(mfilename("fullpath"))}, ...
19+
{"~/not-exist/a/..", stdlib.homedir() + "/not-exist"}
20+
};
21+
end
22+
23+
end
24+
325
methods (Test)
426

5-
function test_resolve_non_exist(tc)
27+
function test_resolve_relative(tc, use_java)
628
import matlab.unittest.constraints.StartsWithSubstring
729
import matlab.unittest.constraints.ContainsSubstring
830

931
td = stdlib.posix(pwd());
1032

1133
% all non-existing files
1234

13-
tc.verifyEqual(stdlib.resolve(""), stdlib.posix(td))
35+
tc.verifyEqual(stdlib.resolve("", true, use_java), stdlib.posix(td))
1436

15-
pabs = stdlib.resolve('2foo');
16-
pabs2 = stdlib.resolve('4foo');
37+
pabs = stdlib.resolve('2foo', true, use_java);
38+
pabs2 = stdlib.resolve('4foo', true, use_java);
1739
tc.verifyThat(pabs, ~StartsWithSubstring("2"))
1840
tc.verifyTrue(strncmp(pabs, pabs2, 2))
1941

20-
par1 = stdlib.resolve("../2foo");
42+
par1 = stdlib.resolve("../2foo", true, use_java);
2143
tc.verifyNotEmpty(par1)
2244
tc.verifyThat(par1, ~ContainsSubstring(".."))
2345

24-
par2 = stdlib.resolve("../4foo");
46+
par2 = stdlib.resolve("../4foo", true, use_java);
2547
tc.verifyTrue(strncmp(par2, pabs2, 2))
2648

27-
pt1 = stdlib.resolve("bar/../2foo");
49+
pt1 = stdlib.resolve("bar/../2foo", true, use_java);
2850
tc.verifyNotEmpty(pt1)
2951
tc.verifyThat(pt1, ~ContainsSubstring(".."))
3052

31-
va = stdlib.resolve("2foo");
32-
vb = stdlib.resolve("4foo");
53+
va = stdlib.resolve("2foo", true, use_java);
54+
vb = stdlib.resolve("4foo", true, use_java);
3355
tc.verifyThat(va, ~StartsWithSubstring("2"))
3456
tc.verifyTrue(strncmp(va, vb, 2))
3557

3658
end
3759

38-
function test_resolve_exist(tc)
39-
40-
td = stdlib.posix(pwd());
41-
42-
r = stdlib.parent(mfilename('fullpath'));
43-
rp = stdlib.parent(r);
44-
tc.verifyEqual(stdlib.resolve(rp), stdlib.parent(r))
45-
46-
h = stdlib.homedir();
47-
tc.verifyEqual(stdlib.resolve("~"), h)
48-
tc.verifyEqual(stdlib.resolve("~/"), h)
49-
tc.verifyEqual(stdlib.resolve("~/.."), stdlib.parent(h))
50-
51-
tc.verifyEqual(stdlib.resolve("nobody.txt"), td + "/nobody.txt")
52-
tc.verifyEqual(stdlib.resolve("../nobody.txt"), stdlib.parent(td) + "/nobody.txt")
53-
60+
function test_resolve_fullpath(tc, p, use_java)
61+
tc.verifyEqual(stdlib.resolve(p{1}, true, use_java), p{2})
5462
end
5563

56-
5764
end
5865

5966
end

0 commit comments

Comments
 (0)