|
1 | 1 | classdef TestResolve < matlab.unittest.TestCase |
2 | 2 |
|
| 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 | + |
3 | 25 | methods (Test) |
4 | 26 |
|
5 | | -function test_resolve_non_exist(tc) |
| 27 | +function test_resolve_relative(tc, use_java) |
6 | 28 | import matlab.unittest.constraints.StartsWithSubstring |
7 | 29 | import matlab.unittest.constraints.ContainsSubstring |
8 | 30 |
|
9 | 31 | td = stdlib.posix(pwd()); |
10 | 32 |
|
11 | 33 | % all non-existing files |
12 | 34 |
|
13 | | -tc.verifyEqual(stdlib.resolve(""), stdlib.posix(td)) |
| 35 | +tc.verifyEqual(stdlib.resolve("", true, use_java), stdlib.posix(td)) |
14 | 36 |
|
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); |
17 | 39 | tc.verifyThat(pabs, ~StartsWithSubstring("2")) |
18 | 40 | tc.verifyTrue(strncmp(pabs, pabs2, 2)) |
19 | 41 |
|
20 | | -par1 = stdlib.resolve("../2foo"); |
| 42 | +par1 = stdlib.resolve("../2foo", true, use_java); |
21 | 43 | tc.verifyNotEmpty(par1) |
22 | 44 | tc.verifyThat(par1, ~ContainsSubstring("..")) |
23 | 45 |
|
24 | | -par2 = stdlib.resolve("../4foo"); |
| 46 | +par2 = stdlib.resolve("../4foo", true, use_java); |
25 | 47 | tc.verifyTrue(strncmp(par2, pabs2, 2)) |
26 | 48 |
|
27 | | -pt1 = stdlib.resolve("bar/../2foo"); |
| 49 | +pt1 = stdlib.resolve("bar/../2foo", true, use_java); |
28 | 50 | tc.verifyNotEmpty(pt1) |
29 | 51 | tc.verifyThat(pt1, ~ContainsSubstring("..")) |
30 | 52 |
|
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); |
33 | 55 | tc.verifyThat(va, ~StartsWithSubstring("2")) |
34 | 56 | tc.verifyTrue(strncmp(va, vb, 2)) |
35 | 57 |
|
36 | 58 | end |
37 | 59 |
|
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}) |
54 | 62 | end |
55 | 63 |
|
56 | | - |
57 | 64 | end |
58 | 65 |
|
59 | 66 | end |
0 commit comments