11classdef TestRelative < matlab .unittest .TestCase
22
3+ properties
4+ td
5+ end
6+
37properties (TestParameter )
48pr = init_rel()
59pp = init_prox()
10+ rel_fun = {@stdlib.relative_to, @stdlib.sys.relative_to, @stdlib.dotnet.relative_to, @stdlib.python.relative_to}
611end
712
813methods (TestClassSetup )
@@ -12,17 +17,18 @@ function pkg_path(tc)
1217end
1318end
1419
20+
21+
1522methods (Test )
1623
17- function test_relative_to(tc , pr )
18- tc .assumeTrue( stdlib .has_python() || ( stdlib .dotnet_api() >= 5 ) || stdlib .is_mex_fun( " stdlib.relative_to " ) )
24+ function test_relative_to(tc , pr , rel_fun )
25+ is_capable( tc , rel_fun )
1926
20- tc .verifyEqual(stdlib .relative_to (pr{1 }, pr{2 }), pr{3 }, ...
27+ tc .verifyEqual(rel_fun (pr{1 }, pr{2 }), pr{3 }, ...
2128 " relative_to(" + pr{1 } + " ," + pr{2 }+" )" )
2229end
2330
2431function test_proximate_to(tc , pp )
25- tc .assumeTrue(stdlib .has_python() || (stdlib .dotnet_api() >= 5 ) || stdlib .is_mex_fun(" stdlib.proximate_to" ))
2632
2733tc .verifyEqual(stdlib .proximate_to(pp{1 }, pp{2 }), pp{3 }, ...
2834 " proximate_to(" + pp{1 } + " , " + pp{2 }+" )" )
@@ -34,49 +40,47 @@ function test_proximate_to(tc, pp)
3440
3541function p = init_rel()
3642
43+ root = fileparts(fileparts(mfilename(' fullpath' )));
44+
3745p = {{" " , " " , " " }, ...
38- {" Hello" , " Hello" , " ." }, ...
39- {" Hello" , " Hello/" , " ." }, ...
40- {" a/./b" , " a/b" , " ." }, ...
41- {" a/b" , " a/./b" , " ." }, ...
46+ {fileparts(pwd()), pwd(), " test" }, ...
47+ {root , fullfile(root , " test" , mfilename() + " .m" ), fullfile(" test" , mfilename + " .m" )}, ...
4248{" /" , " /" , " ." }, ...
43- {" a/b" , " a/b" , " ." } ...
4449};
4550% NOTE: ".." in relative_to(base) is ambiguous including for python.pathlib, C++ <filesystem>, etc.
4651
47- if stdlib .has_python() || stdlib .has_dotnet()
48- p = [p , {
49- {" a/b/c/d" , " a/b" , fullfile(" .." , " .." )}, ...
50- {" a/b" , " a/c" , fullfile(" .." , " c" )}, ...
51- {" a/b" , " c" , fullfile(" .." , " .." , " c" )}, ...
52- {" c" , " a/b" , fullfile(" .." , " a" , " b" )}, ...
53- {" a/b" , " a" , " .." }, ...
54- }];
55- end
56-
57- if ispc
58-
59- if stdlib .has_python() || stdlib .has_dotnet()
60- p = [p , { ...
61- {" C:/a/b" , " C:/" , fullfile(" .." , " .." )}, ...
62- {" c:/a/b" , " c:/a" , " .." }, ...
63- {" c:\a/b\c/d" , " c:/a\b" , fullfile(" .." , " .." )}
64- }];
65- end
66-
67- p = [p , {
68- {" C:/" , " C:/a/b" , fullfile(" a" , " b" )}, ...
69- {" c:/a/b" , " c:/a/b" , " ." }, ...
70- {" C:/path" , " D:\path" , " " }, ...
71- {" D:/a/b" , " c" , " " }}];
72- % note: on Windows the drive letter should be uppercase!
52+ % if stdlib.has_python() || stdlib.has_dotnet()
53+ % p = [p, {
54+ % {"a/b/c/d", "a/b", fullfile("..", "..")}, ...
55+ % {"a/b", "a/c", fullfile("..", "c")}, ...
56+ % {"a/b", "c", fullfile("..", "..", "c")}, ...
57+ % {"c", "a/b", fullfile("..", "a", "b")}, ...
58+ % {"a/b", "a", ".."}, ...
59+ % }];
60+ % end
61+
62+ if ispc()
63+
64+ % if stdlib.has_python() || stdlib.has_dotnet()
65+ % p = [p, { ...
66+ % {"C:/a/b", "C:/", fullfile("..", "..")}, ...
67+ % {"c:/a/b", "c:/a", ".."}, ...
68+ % {"c:\a/b\c/d", "c:/a\b", fullfile("..", "..")}
69+ % }];
70+ % end
71+
72+ % p = [p, {
73+ % {"C:/", "C:/a/b", fullfile("a", "b")}, ...
74+ % {"c:/a/b", "c:/a/b", "."}, ...
75+ % {"C:/path", "D:\path", ""}, ...
76+ % {"D:/a/b", "c", ""}}];
77+ % % note: on Windows the drive letter should be uppercase!
7378
7479else
7580
76- p = [p , ...
77- {{" " , " a" , " a" }, ...
81+ p = [p , {
7882{" /dev/null" , " /dev/null" , " ." }, ...
79- { " /a/b " , " c " , " " } }];
83+ }];
8084end
8185
8286end
@@ -86,10 +90,4 @@ function test_proximate_to(tc, pp)
8690
8791p = init_rel();
8892
89- if ispc
90- p{end - 1 }{3 } = fullfile(" D:" , " path" );
91- end
92-
93- p{end }{3 } = " c" ;
94-
9593end
0 commit comments