Skip to content

Commit

Permalink
test: consolidate values
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Oct 22, 2024
1 parent 8d73f6b commit c69422c
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 63 deletions.
35 changes: 17 additions & 18 deletions test/TestFileImpure.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
end

properties(TestParameter)
in_exists = {pwd, mfilename("fullpath") + ".m", "not-exists"}
ref_exists = {true, true, false}
p_exists = {{pwd, true}, {mfilename("fullpath") + ".m", true}, {tempname, false}}
% on CI matlabroot can be writable!
in_is_write = {pwd, "not-exists"};
ref_is_write = {true, false}
in_expand = {"", "~abc", "~", "~/foo"}
ref_expand
in_same = {"", tempname, "..", ".."}
other_same = {"", tempname, "./..", fullfile(pwd, "..")}
ref_same = {false, false, true, true}
p_expand
p_same = {...
{"","", false}, ...
{tempname, tempname, false}, ...
{"..", "./..", true}, ...
{"..", pwd + "/..", true}}
end

properties
Expand All @@ -24,12 +24,11 @@

methods (TestParameterDefinition, Static)

function ref_expand = init_expand(classToTest) %#ok<INUSD>
function p_expand = init_expand(classToTest) %#ok<INUSD>
cwd = fileparts(mfilename("fullpath"));
top = fullfile(cwd, "..");
addpath(top)

ref_expand = {"", "~abc", stdlib.homedir, stdlib.join(stdlib.homedir, "foo")};
p_expand = {{"", ""}, {"~abc", "~abc"}, {"~", stdlib.homedir}, {"~/foo", stdlib.join(stdlib.homedir, "foo")}};
end
end

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

methods (Test, ParameterCombination = 'sequential')

function test_exists(tc, in_exists, ref_exists)
tc.verifyEqual(stdlib.exists(in_exists), ref_exists)
function test_exists(tc, p_exists)
tc.verifyEqual(stdlib.exists(p_exists{1}), p_exists{2})
end


function test_is_readable(tc, in_exists, ref_exists)
tc.verifyEqual(stdlib.is_readable(in_exists), ref_exists)
function test_is_readable(tc, p_exists)
tc.verifyEqual(stdlib.is_readable(p_exists{1}), p_exists{2})
end


Expand All @@ -67,8 +66,8 @@ function test_is_writable(tc, in_is_write, ref_is_write)
end


function test_expanduser(tc, in_expand, ref_expand)
tc.verifyEqual(stdlib.expanduser(in_expand), ref_expand)
function test_expanduser(tc, p_expand)
tc.verifyEqual(stdlib.expanduser(p_expand{1}), p_expand{2})
end


Expand All @@ -87,8 +86,8 @@ function test_makedir(tc)
end

%%
function test_samepath(tc, in_same, other_same, ref_same)
tc.verifyEqual(stdlib.samepath(in_same, other_same), ref_same)
function test_samepath(tc, p_same)
tc.verifyEqual(stdlib.samepath(p_same{1}, p_same{2}), p_same{3})
end


Expand Down
104 changes: 59 additions & 45 deletions test/TestFilePure.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
end

properties (TestParameter)
base_relative_to
other_relative_to
ref_relative_to
ref_proximate_to
p_relative_to
p_proximate_to
in_is_absolute
ref_is_absolute
in_filename = {'', '/foo/bar/baz', '/foo/bar/baz/', 'foo/bar/baz.txt', 'foo/bar/baz.txt.gz'}
Expand All @@ -20,17 +18,27 @@
in_parent
ref_parent

in_join = {"", "a", "", "a/b/", "/", "", "a", "a//", "a/b/../", "a/b", "a/b", "ab/cd"}
other_join = {"", "", "b", "c/", "", "/", "b//", "b//", "c/d/../", "..", "c/d", "/ef"}
ref_join = {"", "a", "b", "a/b/c", "/", "/", "a/b", "a/b", "a/c", "a", "a/b/c/d", "/ef"}
p_join = {{"", "", ""}, ...
{"a", "", "a"}, ...
{"", "a", "a"}, ...
{"a/b/", "c/", "a/b/c"}, ...
{"/", "", "/"}, ...
{"", "/", "/"}, ...
{"a", "b//", "a/b"}, ...
{"a//", "b//", "a/b"}, ...
{"a/b/../", "c/d/../", "a/c"}, ...
{"a/b", "..", "a"}, ...
{"a/b", "c/d", "a/b/c/d"}, ...
{"ab/cd", "/ef", "/ef"} ...
};

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

in_norm = {"", "//a/b/", "/a/b/", "a/b/", "a/../c", "a/b/../c", "a/b/../../c", "a/b/../../c/..", ...
"a/b/../../c/../..", "a////b"}
ref_norm = {".", "/a/b", "/a/b", "a/b", "c", "a/c", "c", ".", ...
"..", "a/b"}
in_norm = {"", "a/..", "//a/b/", "/a/b/", "a/b/", "a/../c", "a/b/../c", "a/b/../../c", "a/b/../../c/..", ...
"a/b/../../c/../..", "a////b", ".a", "..a", "a.", "a..", "./a/.", "../a"}
ref_norm = {".", ".", "/a/b", "/a/b", "a/b", "c", "a/c", "c", ".", ...
"..", "a/b", ".a", "..a", "a.", "a..", "a", "../a"}

in_root
ref_root
Expand All @@ -41,26 +49,32 @@
end

methods (TestParameterDefinition, Static)
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>
function [p_relative_to, p_proximate_to, in_root, ref_root, in_parent, ref_parent] = init_relative_to(classToTest) %#ok<INUSD>

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

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"};
ref_parent = {".", ".", ".", "..", ".", "a", "a", "ab", "ab", "a/b/..", "a/b", ".", ".", "c:/a", "c:\a"};

if ispc

base_relative_to = {'', 'Hello', 'Hello', ...
'c:\a\b', 'c:\', 'c:/a/b', 'c:/a/b', 'c:\a/b\c/d', 'c:/path'};
p_relative_to = {{'', '', '.'}, ...
{'Hello', 'Hello', '.'}, ...
{'Hello', 'Hello/', '.'}, ...
{'./this/one', './this/two', '../two'}, ...
{'/path/same', '/path/same/hi/..', '.'}};

other_relative_to = {'', 'Hello', 'Hello/', ...
'c:/', 'c:/a/b', 'c:/a/b', 'c:/a', 'c:/a\b', 'd:/path'};
if ispc

ref_relative_to = {'.', '.', '.', '../..', 'a/b', '.', '..', '../..', ''};
p_relative_to = [p_relative_to, ...{
{{'c:\a\b', 'c:/', '../..'}, ...
{'c:\', 'c:/a/b', 'a/b'}, ...
{'c:/a/b', 'c:/a/b', '.'}, ...
{'c:/a/b', 'c:/a', '..'}, ...
{'c:\a/b\c/d', 'c:/a\b', '../..'}, ...
{'c:/path', 'd:/path', ''}}];

ref_proximate_to = ref_relative_to;
ref_proximate_to{end} = other_relative_to{end};
p_proximate_to = p_relative_to;
p_proximate_to{end}{3} = "d:/path";

ref_parent{12} = "c:/";
ref_parent{13} = "c:/";
Expand All @@ -72,27 +86,27 @@

else

base_relative_to = {'', '', '/', '/', 'Hello', 'Hello', '/dev/null', '/a/b', 'c', ...
'/a/b', '/a/b', '/a/b/c/d', '/this/one', '/path/same'};

other_relative_to = {'', '/', '', '/', 'Hello', 'Hello/', '/dev/null', 'c', '/a/b', ...
'/a/b', '/a', '/a/b', '/this/two', '/path/same/hi/..'};

ref_relative_to = {'.', '', '', '.', '.', '.', '.', '', '', ...
'.', '..', '../..', '../two', '.'};

ref_proximate_to = ref_relative_to;
ref_proximate_to{2} = '/';
ref_proximate_to{8} = 'c';
ref_proximate_to{9} = '/a/b';
p_relative_to = [p_relative_to, ...
{{'', '/', ''}, ...
{'/', '', ''}, ...
{'/', '/', '.'}, ...
{'/dev/null', '/dev/null', '.'}, ...
{'/a/b', 'c', ''}, ...
{'c', '/a/b', ''}, ...
{'/a/b', '/a/b', '.'}, ...
{'/a/b', '/a', '..'}, ...
{'/a/b/c/d', '/a/b', '../..'}, ...
{'/this/one', '/this/two', '../two'}, ...
{'/path/same', '/path/same/hi/..', '.'}}];


p_proximate_to = p_relative_to;
p_proximate_to{7}{3} = '/';
p_proximate_to{13}{3} = 'c';
p_proximate_to{14}{3} = '/a/b';

end

base_relative_to{end+1} = './this/one';
other_relative_to{end+1} = './this/two';
ref_relative_to{end+1} = '../two';
ref_proximate_to{end+1} = ref_relative_to{end};

end


Expand Down Expand Up @@ -170,8 +184,8 @@ function test_posix(tc)
end


function test_join(tc, in_join, other_join, ref_join)
tc.verifyEqual(stdlib.join(in_join, other_join), ref_join)
function test_join(tc, p_join)
tc.verifyEqual(stdlib.join(p_join{1}, p_join{2}), p_join{3})
end


Expand Down Expand Up @@ -236,15 +250,15 @@ function test_with_suffix(tc)
end


function test_relative_to(tc, base_relative_to, other_relative_to, ref_relative_to)
function test_relative_to(tc, p_relative_to)
tc.assumeTrue(stdlib.has_java)
tc.verifyEqual(stdlib.relative_to(base_relative_to, other_relative_to), string(ref_relative_to))
tc.verifyEqual(stdlib.relative_to(p_relative_to{1}, p_relative_to{2}), string(p_relative_to{3}))
end


function test_proximate_to(tc, base_relative_to, other_relative_to, ref_proximate_to)
function test_proximate_to(tc, p_proximate_to)
tc.assumeTrue(stdlib.has_java)
tc.verifyEqual(stdlib.proximate_to(base_relative_to, other_relative_to), string(ref_proximate_to))
tc.verifyEqual(stdlib.proximate_to(p_proximate_to{1}, p_proximate_to{2}), string(p_proximate_to{3}))
end


Expand Down

0 comments on commit c69422c

Please sign in to comment.