-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathUSimpleStringTest.cpp
More file actions
287 lines (239 loc) · 8.43 KB
/
Copy pathUSimpleStringTest.cpp
File metadata and controls
287 lines (239 loc) · 8.43 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#include "pch.h"
#include <kf/USimpleString.h>
SCENARIO("USimpleString::matches")
{
GIVEN("A pattern with '*' wildcard")
{
WHEN("'*' at the beginning")
{
kf::USimpleString pattern(L"*.txt");
kf::USimpleString matchingStr(L"example.txt");
kf::USimpleString matchingStr2(L"other-example123.txt");
kf::USimpleString matchingStr3(L"file.doc");
THEN("example.txt and other-example123.txt match the pattern")
{
REQUIRE(matchingStr.matches(pattern));
REQUIRE(matchingStr2.matches(pattern));
}
THEN("file.doc doesn't match the pattern")
{
REQUIRE(!matchingStr3.matches(pattern));
}
}
WHEN("'*' in the middle")
{
kf::USimpleString pattern(L"ex*.txt");
kf::USimpleString matchingStr(L"example.txt");
kf::USimpleString nonMatching(L"other-example123.txt");
THEN("example.txt matches the pattern ex*.txt")
{
REQUIRE(matchingStr.matches(pattern));
}
THEN("other-example123.txt doesn't match the pattern ex*.txt")
{
REQUIRE(!nonMatching.matches(pattern));
}
}
WHEN("'*' in the end")
{
kf::USimpleString pattern(L"example*");
kf::USimpleString matchingStr(L"example.txt");
kf::USimpleString nonMatching(L"other-example123.txt");
THEN("example.txt matches the pattern example*")
{
REQUIRE(matchingStr.matches(pattern));
}
THEN("other-example123.txt doesn't match the pattern example*")
{
REQUIRE(!nonMatching.matches(pattern));
}
}
WHEN("'*' at the beginning, in the middle and in the end")
{
kf::USimpleString pattern(L"*ex*le*");
kf::USimpleString matchingStr(L"example.txt");
kf::USimpleString matchingStr2(L"other-example123.txt");
kf::USimpleString nonMatching(L"file.csv");
THEN("example.txt and other-example123.txt match the pattern *ex*le*")
{
REQUIRE(matchingStr.matches(pattern));
REQUIRE(matchingStr2.matches(pattern));
}
THEN("file.csv doesn't match the pattern *ex*le*")
{
REQUIRE(!nonMatching.matches(pattern));
}
}
}
GIVEN("A pattern with '?' wildcard")
{
WHEN("'?' at the beginning")
{
kf::USimpleString pattern(L"?xample.txt");
kf::USimpleString matchingStr(L"example.txt");
kf::USimpleString nonMatchingStr(L"eeamppe.txt");
THEN("example.txt matches the pattern ?xample.txt")
{
REQUIRE(matchingStr.matches(pattern));
}
THEN("eeamppe.txt does not match the pattern ?xample.txt")
{
REQUIRE(!nonMatchingStr.matches(pattern));
}
}
WHEN("'?' in the middle")
{
kf::USimpleString pattern(L"exa?ple.txt");
kf::USimpleString matchingStr(L"example.txt");
kf::USimpleString nonMatchingStr(L"eeamppe.txt");
THEN("example.txt matches the pattern exa?ple.txt")
{
REQUIRE(matchingStr.matches(pattern));
}
THEN("eeamppe.txt does not match the pattern exa?ple.txt")
{
REQUIRE(!nonMatchingStr.matches(pattern));
}
}
WHEN("'?' in the end")
{
kf::USimpleString pattern(L"example.tx?");
kf::USimpleString matchingStr(L"example.txt");
kf::USimpleString nonMatchingStr(L"eeamppe.txt");
THEN("example.txt matches the pattern example.tx?")
{
REQUIRE(matchingStr.matches(pattern));
}
THEN("eeamppe.txt does not match the pattern example.tx?")
{
REQUIRE(!nonMatchingStr.matches(pattern));
}
}
}
GIVEN("A pattern with mixed '*' and '?' wildcards")
{
kf::USimpleString pattern (L"?xample*.txt");
WHEN("The string matches the pattern")
{
kf::USimpleString matchingStr (L"xxample_123.txt");
THEN("The string matches the pattern")
{
REQUIRE(matchingStr.matches(pattern));
}
}
WHEN("The string does not match the pattern")
{
kf::USimpleString str (L"non-example.exe");
THEN("The string does not match")
{
REQUIRE(!str.matches(pattern));
}
}
}
WHEN("Empty pattern and empty string")
{
kf::USimpleString pattern (L"");
kf::USimpleString str (L"");
THEN("They match")
{
REQUIRE(str.matches(pattern));
}
}
WHEN("Pattern is '*' and string is empty")
{
kf::USimpleString pattern (L"*");
kf::USimpleString str (L"");
THEN("'*' does not match an empty string")
{
REQUIRE(!str.matches(pattern));
}
}
WHEN("Pattern is empty and string is not")
{
kf::USimpleString pattern (L"");
kf::USimpleString str (L"file.txt");
THEN("They do not match")
{
REQUIRE(!str.matches(pattern));
}
}
WHEN("The string has different case")
{
kf::USimpleString pattern (L"example.txt");
kf::USimpleString str1 (L"Example.txt");
kf::USimpleString str2 (L"EXAMPLE.TXT");
kf::USimpleString str3 (L"eXample.TxT");
THEN("They do not match")
{
REQUIRE(!str1.matches(pattern));
REQUIRE(!str2.matches(pattern));
REQUIRE(!str3.matches(pattern));
}
}
}
SCENARIO("USimpleString::matchesIgnoreCase")
{
GIVEN("A pattern with '*' wildcard")
{
kf::USimpleString pattern(L"*.TXT");
kf::USimpleString matchingStr (L"EXAMPLE.TXT");
kf::USimpleString matchingStr2 (L"Example.txt");
kf::USimpleString matchingStr3 (L"example.txt");
kf::USimpleString nonMatchingStr (L"NoN-matching.ExE");
THEN("EXAMPLE.TXT, Example.txt, example.txt match the pattern *.txt")
{
REQUIRE(matchingStr.matchesIgnoreCase(pattern));
REQUIRE(matchingStr2.matchesIgnoreCase(pattern));
REQUIRE(matchingStr3.matchesIgnoreCase(pattern));
}
THEN("NoN-matching.ExE does not match *.txt")
{
REQUIRE(!nonMatchingStr.matchesIgnoreCase(pattern));
}
}
GIVEN("A pattern with '?' wildcard")
{
kf::USimpleString pattern (L"E?AMP?E.TXT");
kf::USimpleString matchingStr (L"EXAMPLE.txt");
kf::USimpleString matchingStr2 (L"eeamppe.txt");
kf::USimpleString matchingStr3 (L"eXampLe.TXT");
kf::USimpleString nonMatchingStr (L"Example.EXE");
THEN("EXAMPLE.txt, eeamppe.txt, eXampLe.TXT match the pattern e?amp?e.txt")
{
REQUIRE(matchingStr.matchesIgnoreCase(pattern));
REQUIRE(matchingStr2.matchesIgnoreCase(pattern));
REQUIRE(matchingStr3.matchesIgnoreCase(pattern));
}
THEN("Example.EXE does not match e?amp?e.txt")
{
REQUIRE(!nonMatchingStr.matchesIgnoreCase(pattern));
}
}
GIVEN("A pattern with mixed '*' and '?' wildcards")
{
kf::USimpleString pattern (L"?XAMPLE*.TXT");
kf::USimpleString matchingStr (L"xxample_123.txt");
kf::USimpleString matchingStr2 (L"xxAMPle_123.TXT");
kf::USimpleString str (L"NoN-Example.exe");
THEN("xxample_123.txt, xxAMPle_123.TXT match the pattern ?xample*.txt")
{
REQUIRE(matchingStr.matchesIgnoreCase(pattern));
REQUIRE(matchingStr2.matchesIgnoreCase(pattern));
}
THEN("NoN-Example.exe does not match the pattern ?xample*.txt")
{
REQUIRE(!str.matchesIgnoreCase(pattern));
}
}
WHEN("Pattern is empty and string is not")
{
kf::USimpleString pattern (L"");
kf::USimpleString str (L"file.txt");
kf::USimpleString str2 (L"FILE.TXT");
THEN("They do not match")
{
REQUIRE(!str.matchesIgnoreCase(pattern));
REQUIRE(!str2.matchesIgnoreCase(pattern));
}
}
}