-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
TestFilePure.m
144 lines (92 loc) · 3.24 KB
/
TestFilePure.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
classdef TestFilePure < matlab.unittest.TestCase
methods (TestClassSetup)
function setup_path(tc)
import matlab.unittest.fixtures.PathFixture
cwd = fileparts(mfilename("fullpath"));
top = fullfile(cwd, "..");
tc.applyFixture(PathFixture(top))
end
end
methods (Test)
function test_posix(tc)
import matlab.unittest.constraints.ContainsSubstring
tc.verifyEmpty(stdlib.posix(string.empty))
tc.verifyEqual(stdlib.posix(""), "")
if ispc
tc.verifyThat(stdlib.posix("c:\foo"), ~ContainsSubstring("\"))
tc.verifyThat(stdlib.posix(["x:\123", "d:\abc"]), ~ContainsSubstring("\"))
end
end
function test_filename(tc)
tc.verifyEqual(stdlib.filename(""), "")
tc.verifyEqual(stdlib.filename("/foo/bar/baz"), "baz")
tc.verifyEqual(stdlib.filename("/foo/bar/baz/"), "")
tc.verifyEqual(stdlib.filename("foo/bar/baz.txt"), "baz.txt")
tc.verifyEqual(stdlib.filename("foo/bar/baz.txt.gz"), "baz.txt.gz")
end
function test_parent(tc)
tc.verifyEqual(stdlib.parent(""), "")
tc.verifyEqual(stdlib.parent("/foo/bar/baz"), "/foo/bar")
tc.verifyEqual(stdlib.parent("/foo/bar/baz/"), "/foo/bar")
tc.verifyEqual(stdlib.parent("foo/bar/baz/"), "foo/bar")
end
function test_suffix(tc)
tc.verifyEmpty(stdlib.suffix(string.empty))
tc.verifyEqual(stdlib.suffix(""), "")
tc.verifyEqual(stdlib.suffix("/foo/bar/baz"), "")
tc.verifyEqual(stdlib.suffix("/foo/bar/baz/"), "")
tc.verifyEqual(stdlib.suffix("foo/bar/baz.txt"), ".txt")
tc.verifyEqual(stdlib.suffix("foo/bar/baz.txt.gz"), ".gz")
end
function test_stem(tc)
tc.verifyEmpty(stdlib.stem(string.empty))
tc.verifyEqual(stdlib.stem(""), "")
tc.verifyEqual(stdlib.stem("/foo/bar/baz"), "baz")
tc.verifyEqual(stdlib.stem("/foo/bar/baz/"), "")
tc.verifyEqual(stdlib.stem("foo/bar/baz/"), "")
tc.verifyEqual(stdlib.stem("foo/bar/baz.txt"), "baz")
tc.verifyEqual(stdlib.stem("foo/bar/baz.txt.gz"), "baz.txt")
end
function test_is_absolute_path(tc)
tc.verifyFalse(stdlib.is_absolute_path(""))
tc.verifyTrue(stdlib.is_absolute_path('~/foo'))
if ispc
tc.verifyTrue(stdlib.is_absolute_path('x:/foo'))
tc.verifyFalse(stdlib.is_absolute_path('/foo'))
else
tc.verifyTrue(stdlib.is_absolute_path('/foo'))
end
tc.verifyFalse(stdlib.is_absolute_path("c"))
end
function test_absolute_path(tc)
import matlab.unittest.constraints.StartsWithSubstring
tc.verifyEqual(stdlib.absolute_path(""), "")
pabs = stdlib.absolute_path('2foo');
pabs2 = stdlib.absolute_path('4foo');
tc.verifyThat(pabs, ~StartsWithSubstring("2"))
tc.verifyTrue(strncmp(pabs, pabs2, 2))
par1 = stdlib.absolute_path("../2foo");
tc.verifyNotEmpty(par1)
par2 = stdlib.absolute_path("../4foo");
tc.verifyTrue(strncmp(par2, pabs2, 2))
pt1 = stdlib.absolute_path("bar/../2foo");
tc.verifyNotEmpty(pt1)
va = stdlib.absolute_path("2foo");
vb = stdlib.absolute_path("4foo");
tc.verifyThat(va, ~StartsWithSubstring("2"))
tc.verifyTrue(strncmp(va, vb, 2))
end
function test_normalize(tc)
tc.verifyEqual(stdlib.normalize(""), "")
pabs = stdlib.normalize('2foo//');
tc.verifyEqual(pabs, "2foo")
end
function test_with_suffix(tc)
tc.verifyEqual(stdlib.with_suffix("", ""), "")
tc.verifyEqual(stdlib.with_suffix("foo.h5", ".nc"), "foo.nc")
tc.verifyEqual(stdlib.with_suffix("c", ""), "c")
tc.verifyEqual(stdlib.with_suffix("c.nc", ""), "c")
tc.verifyEqual(stdlib.with_suffix("", ".nc"), ".nc")
end
end
end