11classdef TestFilePure < matlab .unittest .TestCase
22
33properties (ClassSetupParameter )
4- classToTest = {" TestFilePure" };
4+ classToTest = {" TestFilePure" };
55end
66
77properties (TestParameter )
8- p_relative_to
9- p_proximate_to
8+
109p_is_absolute
11- in_filename = {" " , " /a/b/c" , " /a/b/c/" , " a/b/c.txt" , " a/b/c.txt.gz" }
12- ref_filename = {" " , " c" , " " , " c.txt" , " c.txt.gz" }
1310
14- p_is_subdir
11+
12+ p_filename = {
13+ {" " , " " }, ...
14+ {" /a/b/c" , " c" }, ...
15+ {" /a/b/c/" , " " }, ...
16+ {" a/b/c.txt" , " c.txt" }, ...
17+ {" a/b/c.txt.gz" , " c.txt.gz" }
18+ };
19+
1520p_parent
1621
22+ p_stem = {{" /a/b/c" , " c" }, {" /a/b/c/" , " " }, {" a/b/c/" , " " }, {" a/b/c.txt" , " c" }, {" a/b/c.txt.gz" , " c.txt" }}
23+
1724p_join = {{" " , " " , " " }, ...
1825{" a" , " " , " a" }, ...
1926{" " , " a" , " a" }, ...
2633{" a/b" , " .." , " a/b/.." }, ...
2734{" a/b" , " c/d" , " a/b/c/d" }, ...
2835{" ab/cd" , " /ef" , " /ef" } ...
29- };
36+ }
3037
31- in_suffix = {" " , " /a/b/c" , " /a/b/c/" , " a/b/c.txt" , " a/b/c.txt.gz" , " .stat" , " .stat.txt" }
32- ref_suffix = {" " , " " , " " , " .txt" , " .gz" , " .stat" , " .txt" }
38+ p_suffix = {{" " , " " }, {" /a/b/c" , " " }, {" /a/b/c/" , " " }, {" a/b/c.txt" , " .txt" }, {" a/b/c.txt.gz" , " .gz" }, {" .stat" , " .stat" }, {" .stat.txt" , " .txt" }}
3339
34- in_norm = {" " , " a/.." , " //a/b/" , " /a/b/" , " a/b/" , " a/../c" , " a/b/../c" , " a/b/../../c" , " a/b/../../c/.." , ...
35- " a/b/../../c/../.." , " a////b" , " .a" , " ..a" , " a." , " a.." , " ./a/." , " ../a" }
36- ref_norm = {" ." , " ." , " /a/b" , " /a/b" , " a/b" , " c" , " a/c" , " c" , " ." , ...
37- " .." , " a/b" , " .a" , " ..a" , " a." , " a.." , " a" , " ../a" }
40+ p_with_suffix = {{" foo.h5" , " .nc" , " foo.nc" }, {" c" , " " , " c" }, {" c.nc" , " " , " c" }, {" " , " .nc" , " .nc" }, {" a//b///c///" , " .h5" , " a/b/c/.h5" }}
41+
42+ p_norm = {
43+ {" " , " ." }, ...
44+ {" a/.." , " ." }, ...
45+ {" //a/b/" , " /a/b" }, ...
46+ {" /a/b/" , " /a/b" }, ...
47+ {" a/b/" , " a/b" }, ...
48+ {" a/../c" , " c" }, ...
49+ {" a/b/../c" , " a/c" }, ...
50+ {" a/b/../../c" , " c" }, ...
51+ {" a/b/../../c/.." , " ." }, ...
52+ {" a/b/../../c/../.." , " .." }, ...
53+ {" a////b" , " a/b" }, ...
54+ {" .a" , " .a" }, ...
55+ {" ..a" , " ..a" }, ...
56+ {" a." , " a." }, ...
57+ {" a.." , " a.." }, ...
58+ {" ./a/." , " a" }, ...
59+ {" ../a" , " ../a" }
60+ };
3861
3962p_root
4063p_root_name
4467tobj
4568end
4669
70+
4771methods (TestParameterDefinition , Static )
48- function [p_relative_to , p_proximate_to , p_root , p_root_name , p_parent ] = init_relative_to(classToTest ) % #ok<INUSD>
72+
73+ function [p_root , p_root_name , p_parent ] = init_relative_to(classToTest ) % #ok<INUSD>
4974
5075p_root = {{" " , " " }, ...
5176{" a/b" , " " }, ...
77102 {" c:\a/b" , " c:\a" }
78103};
79104
80- p_relative_to = {{" " , " " , " ." }, ...
81- {" Hello" , " Hello" , " ." }, ...
82- {" Hello" , " Hello/" , " ." }, ...
83- {" a/./b" , " a/b" , " ." }, ...
84- {" a/b" , " a/./b" , " ." }, ...
85- {" ./this/one" , " ./this/two" , " ../two" }, ...
86- {" /path/same" , " /path/same/hi/.." , " hi/.." }, ...
87- {" " , " /" , " " }, ...
88- {" /" , " " , " " }, ...
89- {" /" , " /" , " ." }, ...
90- {" /dev/null" , " /dev/null" , " ." }, ...
91- {" /a/b" , " c" , " " }, ...
92- {" c" , " /a/b" , " " }, ...
93- {" /a/b" , " /a/b" , " ." }, ...
94- {" /a/b" , " /a" , " .." }, ...
95- {" /a/b/c/d" , " /a/b" , " ../.." }, ...
96- {" this/one" , " this/two" , " ../two" }};
97- % NOTE: ".." in relative_to(base) is ambiguous including for python.pathlib, C++ <filesystem>, etc.
98-
99- p_proximate_to = p_relative_to ;
100-
101- p_proximate_to{6 }{3 } = " /" ;
102- p_proximate_to{10 }{3 } = " c" ;
103- p_proximate_to{11 }{3 } = " /a/b" ;
104-
105105if ispc
106-
107- p_relative_to = [p_relative_to , ...
108- {{" c:\a\b" , " c:/" , " ../.." }, ...
109- {" c:\" , " c:/a/b" , " a/b" }, ...
110- {" c:/a/b" , " c:/a/b" , " ." }, ...
111- {" c:/a/b" , " c:/a" , " .." }, ...
112- {" c:\a/b\c/d" , " c:/a\b" , " ../.." }, ...
113- {" c:/path" , " d:/path" , " " }}];
114-
115- p_proximate_to = p_relative_to ;
116- % NOTE: ".." in proximate_to(base) is ambiguous including for python.pathlib, C++ <filesystem>, etc
117-
118- p_proximate_to{8 }{3 } = " /" ;
119- p_proximate_to{12 }{3 } = " c" ;
120- p_proximate_to{13 }{3 } = " /a/b" ;
121-
122- p_proximate_to{end }{3 } = " d:/path" ;
123-
124106p_parent{12 }{2 } = " c:/" ;
125107p_parent{13 }{2 } = " c:/" ;
126108p_parent{14 }{2 } = " c:/a" ;
133115
134116p_root_name{4 }{2 } = " c:" ;
135117
136- end % if ispc
118+ end
137119
138120end
139121
149131
150132end
151133
152-
153- function [p_is_subdir ] = init_is_subdir(classToTest ) % #ok<INUSD>
154-
155- p_is_subdir = {
156- {" a/b" , " a/b" , false }, ...
157- {" a//b/c" , " a/b" , false }, ...
158- {" a/b" , " a//b" , false }, ...
159- {" a/./b/c" , " a/b" , false }, ...
160- {" a/b/c" , " a/./b" , true }, ...
161- {" a/b" , " a/b/" , false }, ...
162- {" a/b" , " a" , true }, ...
163- {" a/.c" , " a" , true }
164- };
165- % NOTE: ".." in is_subdir (either argument) is ambiguous
166-
167- if ispc
168- p_is_subdir{end + 1 } = {" c:\" , " c:/" , false };
169- else
170- p_is_subdir{end + 1 } = {" /" , " /" , false };
171- end
172-
173134end
174135
175- end
176136
177137
178138methods (TestClassSetup )
@@ -211,32 +171,22 @@ function test_join(tc, p_join)
211171end
212172
213173
214- function test_filename(tc , in_filename , ref_filename )
215- tc .verifyEqual(stdlib .filename(in_filename ), string(ref_filename ))
174+ function test_filename(tc , p_filename )
175+ tc .verifyEqual(stdlib .filename(p_filename{ 1 } ), string(p_filename{ 2 } ))
216176end
217177
218178
219179function test_parent(tc , p_parent )
220180tc .verifyEqual(stdlib .parent(p_parent{1 }), p_parent{2 }, p_parent{1 })
221181end
222182
223- function test_suffix(tc , in_suffix , ref_suffix )
224- tc .verifyEqual(stdlib .suffix(in_suffix ), string(ref_suffix ))
183+ function test_suffix(tc , p_suffix )
184+ tc .verifyEqual(stdlib .suffix(p_suffix{ 1 } ), string(p_suffix{ 2 } ))
225185end
226186
227187
228- function test_stem(tc )
229-
230- tc .verifyEqual(stdlib .stem(" " ), " " )
231-
232- tc .verifyEqual(stdlib .stem(" /a/b/c" ), " c" )
233- tc .verifyEqual(stdlib .stem(" /a/b/c/" ), " " )
234-
235- tc .verifyEqual(stdlib .stem(" a/b/c/" ), " " )
236-
237- tc .verifyEqual(stdlib .stem(" a/b/c.txt" ), " c" )
238- tc .verifyEqual(stdlib .stem(" a/b/c.txt.gz" ), " c.txt" )
239-
188+ function test_stem(tc , p_stem )
189+ tc .verifyEqual(stdlib .stem(p_stem{1 }), p_stem{2 })
240190end
241191
242192
@@ -245,9 +195,9 @@ function test_is_absolute(tc, p_is_absolute)
245195end
246196
247197
248- function test_normalize(tc , in_norm , ref_norm )
198+ function test_normalize(tc , p_norm )
249199
250- tc .verifyEqual(stdlib .normalize(in_norm ), ref_norm )
200+ tc .verifyEqual(stdlib .normalize(p_norm{ 1 } ), p_norm{ 2 } )
251201
252202end
253203
@@ -257,35 +207,8 @@ function test_root(tc, p_root)
257207end
258208
259209
260- function test_with_suffix(tc )
261-
262- tc .verifyEqual(stdlib .with_suffix(" " , " " ), " " )
263-
264- tc .verifyEqual(stdlib .with_suffix(" foo.h5" , " .nc" ), " foo.nc" )
265-
266- tc .verifyEqual(stdlib .with_suffix(" c" , " " ), " c" )
267- tc .verifyEqual(stdlib .with_suffix(" c.nc" , " " ), " c" )
268- tc .verifyEqual(stdlib .with_suffix(" " , " .nc" ), " .nc" )
269-
270- tc .verifyEqual(stdlib .with_suffix(" a//b///c///" , " .h5" ), " a/b/c/.h5" )
271- end
272-
273-
274- function test_relative_to(tc , p_relative_to )
275- tc .assumeTrue(stdlib .has_java )
276- tc .verifyEqual(stdlib .relative_to(p_relative_to{1 }, p_relative_to{2 }), p_relative_to{3 }, " relative_to(" + p_relative_to{1 } + " ," + p_relative_to{2 }+" )" )
277- end
278-
279-
280- function test_proximate_to(tc , p_proximate_to )
281- tc .assumeTrue(stdlib .has_java )
282- tc .verifyEqual(stdlib .proximate_to(p_proximate_to{1 }, p_proximate_to{2 }), p_proximate_to{3 }, " proximate_to(" + p_proximate_to{1 } + " ," + p_proximate_to{2 }+" )" )
283- end
284-
285-
286- function test_is_subdir(tc , p_is_subdir )
287- tc .assumeTrue(stdlib .has_java )
288- tc .verifyEqual(stdlib .is_subdir(p_is_subdir{1 }, p_is_subdir{2 }), p_is_subdir{3 }, " subdir(" + p_is_subdir{1 } + " ," + p_is_subdir{2 } + " )" )
210+ function test_with_suffix(tc , p_with_suffix )
211+ tc .verifyEqual(stdlib .with_suffix(p_with_suffix{1 }, p_with_suffix{2 }), p_with_suffix{3 })
289212end
290213
291214
0 commit comments