| 1 |
/* |
| 2 |
* Copyright (C) 2024 Linux Studio Plugins Project <https://lsp-plug.in/> |
| 3 |
* (C) 2024 Vladimir Sadovnikov <[email protected]> |
| 4 |
* |
| 5 |
* This file is part of lsp-runtime-lib |
| 6 |
* Created on: 17 окт. 2020 г. |
| 7 |
* |
| 8 |
* lsp-runtime-lib is free software: you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU Lesser General Public License as published by |
| 10 |
* the Free Software Foundation, either version 3 of the License, or |
| 11 |
* any later version. |
| 12 |
* |
| 13 |
* lsp-runtime-lib is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU Lesser General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Lesser General Public License |
| 19 |
* along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#include <lsp-plug.in/test-fw/utest.h> |
| 23 |
#include <lsp-plug.in/common/status.h> |
| 24 |
#include <lsp-plug.in/io/PathPattern.h> |
| 25 |
|
| 26 |
UTEST_BEGIN("runtime.io", pathpattern) |
| 27 |
|
| 28 |
class TestPathPattern: public io::PathPattern |
| 29 |
{ |
| 30 |
private: |
| 31 |
test_type_t *pTest; |
| 32 |
|
| 33 |
public: |
| 34 |
explicit TestPathPattern(test_type_t *test) |
| 35 |
{ |
| 36 |
pTest = test; |
| 37 |
} |
| 38 |
|
| 39 |
protected: |
| 40 |
status_t do_dump(size_t offset, cmd_t *cmd) |
| 41 |
{ |
| 42 |
for (size_t i=0; i<offset; ++i) |
| 43 |
pTest->printf(" "); |
| 44 |
|
| 45 |
if (cmd->bInverse) |
| 46 |
pTest->printf("!"); |
| 47 |
|
| 48 |
switch (cmd->nCommand) |
| 49 |
{ |
| 50 |
case CMD_SEQUENCE: |
| 51 |
pTest->printf("SEQUENCE"); |
| 52 |
if (cmd->sChildren.is_empty()) |
| 53 |
pTest->printf(" (empty)\n"); |
| 54 |
else |
| 55 |
{ |
| 56 |
pTest->printf("\n"); |
| 57 |
for (size_t j=0, n=cmd->sChildren.size(); j<n; ++j) |
| 58 |
do_dump(offset+2, cmd->sChildren.uget(j)); |
| 59 |
} |
| 60 |
break; |
| 61 |
case CMD_AND: |
| 62 |
pTest->printf("AND ('&')\n"); |
| 63 |
for (size_t j=0, n=cmd->sChildren.size(); j<n; ++j) |
| 64 |
do_dump(offset+2, cmd->sChildren.uget(j)); |
| 65 |
break; |
| 66 |
case CMD_OR: |
| 67 |
pTest->printf("OR ('|')\n"); |
| 68 |
for (size_t j=0, n=cmd->sChildren.size(); j<n; ++j) |
| 69 |
do_dump(offset+2, cmd->sChildren.uget(j)); |
| 70 |
break; |
| 71 |
|
| 72 |
case CMD_PATTERN: |
| 73 |
{ |
| 74 |
LSPString tmp; |
| 75 |
tmp.set(&sMask, cmd->nStart, cmd->nStart + cmd->nLength); |
| 76 |
pTest->printf("PATTERN (\"%s\") start=%d, length=%d, chars=%d\n", |
| 77 |
tmp.get_utf8(), |
| 78 |
int(cmd->nStart), int(cmd->nLength), int(cmd->nChars) |
| 79 |
); |
| 80 |
break; |
| 81 |
} |
| 82 |
|
| 83 |
case CMD_ANY: |
| 84 |
{ |
| 85 |
pTest->printf("ANY ('*'"); |
| 86 |
if (cmd->nChars >= 0) |
| 87 |
{ |
| 88 |
LSPString tmp; |
| 89 |
tmp.set(&sMask, cmd->nStart, cmd->nStart + cmd->nLength); |
| 90 |
pTest->printf(", except=\"%s\"", tmp.get_utf8()); |
| 91 |
} |
| 92 |
pTest->printf(")\n"); |
| 93 |
break; |
| 94 |
} |
| 95 |
|
| 96 |
case CMD_ANYPATH: |
| 97 |
{ |
| 98 |
pTest->printf("ANYPATH (\"**/\", \"**\\\")\n"); |
| 99 |
break; |
| 100 |
} |
| 101 |
|
| 102 |
default: |
| 103 |
return STATUS_CORRUPTED; |
| 104 |
} |
| 105 |
|
| 106 |
return STATUS_OK; |
| 107 |
} |
| 108 |
|
| 109 |
public: |
| 110 |
status_t dump() |
| 111 |
{ |
| 112 |
return (pRoot != NULL) ? do_dump(0, pRoot) : STATUS_OK; |
| 113 |
} |
| 114 |
}; |
| 115 |
|
| 116 |
void test_parse() |
| 117 |
{ |
| 118 |
static const char *pattern[] = |
| 119 |
{ |
| 120 |
"", |
| 121 |
"file.ext", |
| 122 |
"!file.ext", |
| 123 |
"!!!file.ext", |
| 124 |
"file().txt", |
| 125 |
"file!().txt", |
| 126 |
"file!(-test).txt", |
| 127 |
"file!(!-test).txt", |
| 128 |
"file.!(c|h)", |
| 129 |
"!?file.ext", |
| 130 |
"?file.ext", |
| 131 |
"``quoted`?``.file", |
| 132 |
"``quoted`?``.file`", |
| 133 |
"file.ext?", |
| 134 |
"file*.ext", |
| 135 |
"file.???", |
| 136 |
"file.*", |
| 137 |
"path/file.ext", |
| 138 |
"path\\file.ext", |
| 139 |
"**/file.ext", |
| 140 |
"**/**/file.ext", |
| 141 |
"path/**/file.ext", |
| 142 |
"**/path/**/file.ext", |
| 143 |
"**/path/**/**/file.ext", |
| 144 |
"*.c|*.h", |
| 145 |
"*.c|*.cc|*.cpp|*.h|*.hpp", |
| 146 |
"*.c&test-*|*.h&test-*", |
| 147 |
"!*.c&!*.h", |
| 148 |
"!(*.c|*.h)&!(test-*)", |
| 149 |
"file**.log", |
| 150 |
"file***.log", |
| 151 |
"file(!test).log", |
| 152 |
"file*(!test).log", |
| 153 |
"file(!test)*.log", |
| 154 |
"file*(!test)*.log", |
| 155 |
"file*?*.log", |
| 156 |
"(*.c|*.h)&test-*", |
| 157 |
"(*.c|*.h)&!(*.cc|*.cpp)", |
| 158 |
NULL |
| 159 |
}; |
| 160 |
|
| 161 |
for (const char * const *p = pattern; *p != NULL; ++p) |
| 162 |
{ |
| 163 |
TestPathPattern xp(this); |
| 164 |
printf("Testing pattern \"%s\"...\n", *p); |
| 165 |
UTEST_ASSERT(xp.set(*p) == STATUS_OK); |
| 166 |
UTEST_ASSERT(xp.dump() == STATUS_OK); |
| 167 |
printf("\n"); |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
typedef struct match_t |
| 172 |
{ |
| 173 |
const char *pattern; |
| 174 |
bool full; |
| 175 |
const char *value; |
| 176 |
bool match; |
| 177 |
} match_t; |
| 178 |
|
| 179 |
void test_match_patterns(const match_t *matches) |
| 180 |
{ |
| 181 |
TestPathPattern p(this); |
| 182 |
|
| 183 |
for (const match_t *m = matches; m->pattern != NULL; ++m) |
| 184 |
{ |
| 185 |
size_t flags = 0; |
| 186 |
if (m->full) |
| 187 |
flags |= io::PathPattern::FULL_PATH; |
| 188 |
printf("Testing match for pattern \"%s\", value=\"%s\", full=%s, match=%s\n", |
| 189 |
m->pattern, m->value, |
| 190 |
(m->full) ? "true" : "false", |
| 191 |
(m->match) ? "true" : "false" |
| 192 |
); |
| 193 |
|
| 194 |
// Test direct |
| 195 |
UTEST_ASSERT(p.set(m->pattern, flags) == STATUS_OK); |
| 196 |
if (p.test(m->value) != m->match) |
| 197 |
{ |
| 198 |
p.dump(); |
| 199 |
UTEST_FAIL_MSG("Falied direct match for pattern \"%s\", value=\"%s\", match=%s", |
| 200 |
m->pattern, m->value, (m->match) ? "true" : "false" |
| 201 |
); |
| 202 |
} |
| 203 |
|
| 204 |
// Test inverse |
| 205 |
UTEST_ASSERT(p.set(m->pattern, flags | io::PathPattern::INVERSE) == STATUS_OK); |
| 206 |
if (p.test(m->value) == m->match) |
| 207 |
{ |
| 208 |
p.dump(); |
| 209 |
UTEST_FAIL_MSG("Falied inverse match for pattern \"%s\", value=\"%s\", match=%s", |
| 210 |
m->pattern, m->value, (m->match) ? "true" : "false" |
| 211 |
); |
| 212 |
} |
| 213 |
} |
| 214 |
} |
| 215 |
|
| 216 |
void test_match_simple() |
| 217 |
{ |
| 218 |
static const match_t matches[] = |
| 219 |
{ |
| 220 |
// PATTERN match |
| 221 |
{ "test", false, "test", true }, |
| 222 |
{ "test", false, "", false }, |
| 223 |
{ "test", false, "test.log", false }, |
| 224 |
{ "!test", false, "test", false }, |
| 225 |
{ "!test", false, "", true }, |
| 226 |
{ "!test", false, "test.log", true }, |
| 227 |
|
| 228 |
{ "`", false, "`", true }, |
| 229 |
{ "`", false, "``", false }, |
| 230 |
|
| 231 |
{ "`a", false, "`", false }, |
| 232 |
{ "`a", false, "`a", true }, |
| 233 |
{ "``a", false, "`", false }, |
| 234 |
{ "``a", false, "`a", true }, |
| 235 |
|
| 236 |
{ "`a`", false, "`a", false }, |
| 237 |
{ "`a`", false, "`a`", true }, |
| 238 |
{ "``a`", false, "`a", false }, |
| 239 |
{ "``a`", false, "`a`", true }, |
| 240 |
{ "``a``", false, "`a", false }, |
| 241 |
{ "``a``", false, "`a`", true }, |
| 242 |
|
| 243 |
// ANY match |
| 244 |
{ "*", false, "test.log", true }, |
| 245 |
{ "*", false, "", true }, |
| 246 |
{ "*", false, "/", true }, |
| 247 |
{ "!*", false, "/", false }, |
| 248 |
{ "*", true, "/", false }, |
| 249 |
{ "!*", true, "/", true }, |
| 250 |
{ "!()", false, "", false }, |
| 251 |
{ "!()", false, "1", true }, |
| 252 |
{ "!(test)", false, "", true }, |
| 253 |
{ "!(test)", false, "tes", true }, |
| 254 |
{ "!(test)", false, "test", false }, |
| 255 |
{ "!(test)", false, "test.txt", false }, |
| 256 |
{ "!(test)", false, "local.test", false }, |
| 257 |
{ "!(test)", false, "some-test.log", false }, |
| 258 |
|
| 259 |
// ANYPATH match |
| 260 |
{ "**/", false, "", true }, |
| 261 |
{ "**/", true, "", true }, |
| 262 |
{ "**/", false, "/", true }, |
| 263 |
{ "**/", true, "/", true }, |
| 264 |
{ "**/", true, "//", true }, |
| 265 |
{ "**/", true, "/a", true }, |
| 266 |
{ "**/", true, "/a/b/c", true }, |
| 267 |
{ "**/", true, "a/b/c", true }, |
| 268 |
{ "**/", true, "a/b/", true }, |
| 269 |
{ "**/", true, "a/b/", true }, |
| 270 |
|
| 271 |
// OR match |
| 272 |
{ "a|b|c", false, "a", true }, |
| 273 |
{ "a|b|c", false, "b", true }, |
| 274 |
{ "a|b|c", false, "c", true }, |
| 275 |
{ "a|b|c", false, "d", false }, |
| 276 |
{ "!a|b|c", false, "a", false }, |
| 277 |
{ "!a|b|c", false, "b", true }, |
| 278 |
{ "!a|b|c", false, "c", true }, |
| 279 |
{ "!a|b|c", false, "d", true }, |
| 280 |
{ "a|b|!c", false, "a", true }, |
| 281 |
{ "a|b|!c", false, "b", true }, |
| 282 |
{ "a|b|!c", false, "c", false }, |
| 283 |
{ "a|b|!c", false, "d", true }, |
| 284 |
{ "!(a|b|c)", false, "a", false }, |
| 285 |
{ "!(a|b|c)", false, "b", false }, |
| 286 |
{ "!(a|b|c)", false, "c", false }, |
| 287 |
{ "!(a|b|c)", false, "d", true }, |
| 288 |
|
| 289 |
// AND match |
| 290 |
{ "!a&!b&!c", false, "a", false }, |
| 291 |
{ "!a&!b&!c", false, "b", false }, |
| 292 |
{ "!a&!b&!c", false, "c", false }, |
| 293 |
{ "!a&!b&!c", false, "d", true }, |
| 294 |
{ "a&!b&!c", false, "a", true }, |
| 295 |
{ "a&!b&!c", false, "b", false }, |
| 296 |
{ "a&!b&!c", false, "c", false }, |
| 297 |
{ "a&!b&!c", false, "d", false }, |
| 298 |
{ "!a&!b&c", false, "a", false }, |
| 299 |
{ "!a&!b&c", false, "b", false }, |
| 300 |
{ "!a&!b&c", false, "c", true }, |
| 301 |
{ "!a&!b&c", false, "d", false }, |
| 302 |
{ "!(a&b&c)", false, "a", true }, |
| 303 |
{ "!(a&b&c)", false, "b", true }, |
| 304 |
{ "!(a&b&c)", false, "c", true }, |
| 305 |
{ "!(a&b&c)", false, "d", true }, |
| 306 |
|
| 307 |
{ NULL, false, NULL, false } |
| 308 |
}; |
| 309 |
|
| 310 |
test_match_patterns(matches); |
| 311 |
} |
| 312 |
|
| 313 |
void test_match_sequence_only() |
| 314 |
{ |
| 315 |
static const match_t matches[] = |
| 316 |
{ |
| 317 |
// Prefix test |
| 318 |
{ "a*", false, "a", true }, |
| 319 |
{ "a*", false, "ab", true }, |
| 320 |
{ "a*", false, "abc", true }, |
| 321 |
|
| 322 |
{ "a()b*", false, "a", false }, |
| 323 |
{ "a()b*", false, "ab", true }, |
| 324 |
{ "a()b*", false, "ad", false }, |
| 325 |
{ "a()b*", false, "abc", true }, |
| 326 |
|
| 327 |
{ "a!(b)", false, "a", true }, |
| 328 |
{ "a!(b)", false, "b", false }, |
| 329 |
{ "a!(b)", false, "ab", false }, |
| 330 |
{ "a!(b)", false, "ac", true }, |
| 331 |
{ "a!(b)", false, "acb", false }, |
| 332 |
{ "a!(b)", false, "acd", true }, |
| 333 |
{ "a!(b)", true, "a/b", false }, |
| 334 |
|
| 335 |
{ "a()b()c", false, "a", false }, |
| 336 |
{ "a()b()c", false, "ab", false }, |
| 337 |
{ "a()b()c", false, "abc", true }, |
| 338 |
{ "a()b()c", false, "abcd", false }, |
| 339 |
|
| 340 |
// Postfix test |
| 341 |
{ "*b", false, "b", true }, |
| 342 |
{ "*b", false, "ab", true }, |
| 343 |
{ "*b", false, "ba", false }, |
| 344 |
{ "*b", false, "cab", true }, |
| 345 |
|
| 346 |
{ "*b()c", false, "c", false }, |
| 347 |
{ "*b()c", false, "bc", true }, |
| 348 |
{ "*b()c", false, "ac", false }, |
| 349 |
{ "*b()c", false, "abc", true }, |
| 350 |
|
| 351 |
{ "!(a)b", false, "a", false }, |
| 352 |
{ "!(a)b", false, "b", true }, |
| 353 |
{ "!(a)b", false, "ab", false }, |
| 354 |
{ "!(a)b", false, "ac", false }, |
| 355 |
{ "!(a)b", false, "cb", true }, |
| 356 |
{ "!(a)b", false, "dcb", true }, |
| 357 |
{ "!(a)b", true, "a/b", false }, |
| 358 |
|
| 359 |
// Variants test |
| 360 |
{ "a(!b)c(!d)e", false, "ace", true }, |
| 361 |
{ "a(!b)c(!d)e", false, "abcde", false }, |
| 362 |
{ "a(!b)c(!d)e", false, "abcxe", false }, |
| 363 |
{ "a(!b)c(!d)e", false, "axcde", false }, |
| 364 |
{ "a(!b)c(!d)e", false, "abce", false }, |
| 365 |
{ "a(!b)c(!d)e", false, "acde", false }, |
| 366 |
{ "a(!b)c(!d)e", false, "a12c34e", true }, |
| 367 |
|
| 368 |
{ "ab*cd*ef", false, "abbccddeef", true }, |
| 369 |
{ "a*bcb(!b)d", false, "aXYbcbcbXYd", true }, |
| 370 |
{ "a*bcb(!b)ded(!d)f", false, "aXYbcbcbXYdededXYf", true }, |
| 371 |
{ "a*bcb(!b)ded(!d)f", false, "aXYbcbcbXYdeddedXYdf", false }, |
| 372 |
|
| 373 |
// Paths |
| 374 |
{ "**/ab/cd*", true, "x/y/z/ab/cd", true }, |
| 375 |
{ "**/ab/cd*", true, "x/y/z/ab/cdef", true }, |
| 376 |
{ "**/ab/cd*", true, "x/y/z/ab/cd/ef", false }, |
| 377 |
{ "**/ab/cd*", true, "x/y/ab/z/cd", false }, |
| 378 |
{ "**/ab/cd*", true, "/ab/x/ab/cd", true }, |
| 379 |
{ "**/ab/**/cd*", true, "x/y/z/ab/cd", true }, |
| 380 |
{ "**/ab/**/cd*", true, "x/y/ab/z/cd", true }, |
| 381 |
{ "**/ab/**/cd*", true, "x/y/ab/z/cdef", true }, |
| 382 |
{ "**/ab/**/cd*", true, "x/y/ab/z/cd/ef", false }, |
| 383 |
{ "(!**/)ab/**/cd*", true, "ab/x/cd", true }, |
| 384 |
{ "(!**/)ab/**/cd*", true, "12ab/x/cd", true }, |
| 385 |
{ "(!**/)ab/**/cd*", true, "/ab/x/cd", false }, |
| 386 |
{ "ab/**/", true, "ab/cd/ef", true }, |
| 387 |
{ "ab/**/", true, "ab/cd/ef.gh", true }, |
| 388 |
{ "ab/**/", true, "ab", false }, |
| 389 |
{ "ab/**/", true, "cd", false }, |
| 390 |
|
| 391 |
// Sub-pattern |
| 392 |
{ "a(b|c)d", false, "a", false }, |
| 393 |
{ "a(b|c)d", false, "d", false }, |
| 394 |
{ "a(b|c)d", false, "ad", false }, |
| 395 |
{ "a(b|c)d", false, "abd", true }, |
| 396 |
{ "a(b|c)d", false, "acd", true }, |
| 397 |
{ "a(b|c)d", false, "abcd", false }, |
| 398 |
|
| 399 |
{ "a!(b|c)d", false, "a", false }, |
| 400 |
{ "a!(b|c)d", false, "ad", true }, |
| 401 |
{ "a!(b|c)d", false, "abd", false }, |
| 402 |
{ "a!(b|c)d", false, "acd", false }, |
| 403 |
{ "a!(b|c)d", false, "aed", true }, |
| 404 |
{ "a!(b|c)d", false, "a12d", true }, |
| 405 |
{ "a!(b|c)d", false, "abcd", true }, |
| 406 |
|
| 407 |
// Logic expressions |
| 408 |
{ "a!(*b*|*c*)d", false, "abcd", false }, |
| 409 |
{ "a!(*b*|*c*)d", false, "a123b456d", false }, |
| 410 |
{ "a!(*b*|*c*)d", false, "a123c456d", false }, |
| 411 |
{ "a!(*b*|*c*)d", false, "a123e456d", true }, |
| 412 |
{ "a(*b*&*c*)d", false, "a123x456d", false }, |
| 413 |
{ "a(*b*&*c*)d", false, "a123b456d", false }, |
| 414 |
{ "a(*b*&*c*)d", false, "a123c456d", false }, |
| 415 |
{ "a(*b*&*c*)d", false, "a12bc456d", true }, |
| 416 |
|
| 417 |
// Including full path |
| 418 |
{ "ab/*cd/*ef", true, "ab/cd/ef", true }, |
| 419 |
{ "ab/*cd/*ef", true, "ab/1cd/2ef", true }, |
| 420 |
{ "ab*/*cd*/*ef", true, "abcd/cdef/ghef", true }, |
| 421 |
|
| 422 |
{ NULL, false, NULL, false } |
| 423 |
}; |
| 424 |
|
| 425 |
test_match_patterns(matches); |
| 426 |
} |
| 427 |
|
| 428 |
void test_match_brute() |
| 429 |
{ |
| 430 |
static const match_t matches[] = |
| 431 |
{ |
| 432 |
// Simple group |
| 433 |
{ "*(*b*)*", false, "a", false }, |
| 434 |
{ "*(*b*)*", false, "b", true }, |
| 435 |
{ "*(*b*)*", false, "ab", true }, |
| 436 |
{ "*(*b*)*", false, "bb", true }, |
| 437 |
{ "(!*b*)", false, "a", true }, |
| 438 |
{ "(!*b*)", false, "b", false }, |
| 439 |
{ "(!*b*)", false, "ab", false }, |
| 440 |
{ "(!*b*)", false, "bb", false }, |
| 441 |
|
| 442 |
// Multiple matches |
| 443 |
{ "*(a*|b*)*(c*|d*)", false, "a", false }, |
| 444 |
{ "*(a*|b*)*(c*|d*)", false, "b", false }, |
| 445 |
{ "*(a*|b*)*(c*|d*)", false, "c", false }, |
| 446 |
{ "*(a*|b*)*(c*|d*)", false, "d", false }, |
| 447 |
{ "*(a*|b*)*(c*|d*)", false, "ab", false }, |
| 448 |
{ "*(a*|b*)*(c*|d*)", false, "ac", true }, |
| 449 |
{ "*(a*|b*)*(c*|d*)", false, "ad", true }, |
| 450 |
{ "*(a*|b*)*(c*|d*)", false, "ab", false }, |
| 451 |
{ "*(a*|b*)*(c*|d*)", false, "ba", false }, |
| 452 |
{ "*(a*|b*)*(c*|d*)", false, "bc", true }, |
| 453 |
{ "*(a*|b*)*(c*|d*)", false, "bd", true }, |
| 454 |
{ "*(a*|b*)*(c*|d*)", false, "aXc", true }, |
| 455 |
{ "*(a*|b*)*(c*|d*)", false, "aXd", true }, |
| 456 |
{ "*(a*|b*)*(c*|d*)", false, "aXe", false }, |
| 457 |
{ "*(a*|b*)*(c*|d*)", false, "bXc", true }, |
| 458 |
{ "*(a*|b*)*(c*|d*)", false, "bXd", true }, |
| 459 |
{ "*(a*|b*)*(c*|d*)", false, "eXc", false }, |
| 460 |
{ "*(a*|b*)*(c*|d*)", false, "eXd", false }, |
| 461 |
{ "*(a*|b*)*(c*|d*)", false, "abcd", true }, |
| 462 |
{ "*(a*|b*)*(c*|d*)", false, "12a34b56c78d90", true }, |
| 463 |
{ "*(a*|b*)*(c*|d*)", false, "12a34b56", false }, |
| 464 |
{ "*(a*|b*)*(c*|d*)", false, "12c34d56", false }, |
| 465 |
{ "*(a*|b*)*(c*|d*)", false, "12a34c56", true }, |
| 466 |
{ "*(a*|b*)*(c*|d*)", false, "12c34a56", false }, |
| 467 |
{ "*(a*|b*)*(c*|d*)", false, "12a34d56", true }, |
| 468 |
{ "*(a*|b*)*(c*|d*)", false, "12d34a56", false }, |
| 469 |
{ "*(a*|b*)*(c*|d*)", false, "12b34c56", true }, |
| 470 |
{ "*(a*|b*)*(c*|d*)", false, "12c34b56", false }, |
| 471 |
{ "*(a*|b*)*(c*|d*)", false, "12b34d56", true }, |
| 472 |
{ "*(a*|b*)*(c*|d*)", false, "12d34b56", false }, |
| 473 |
|
| 474 |
// Multiple matches with path |
| 475 |
{ "*(a*|b*)*(c*|d*)", true, "a/b", false }, |
| 476 |
{ "*(a*|b*)*(c*|d*)", true, "a/c", false }, |
| 477 |
{ "*(a*|b*)*(c*|d*)", true, "a/d", false }, |
| 478 |
{ "*(a*|b*)*(c*|d*)", true, "b/a", false }, |
| 479 |
{ "*(a*|b*)*(c*|d*)", true, "b/c", false }, |
| 480 |
{ "*(a*|b*)*(c*|d*)", true, "b/d", false }, |
| 481 |
{ "*(a*|b*)*(c*|d*)", true, "c/a", false }, |
| 482 |
{ "*(a*|b*)*(c*|d*)", true, "c/b", false }, |
| 483 |
{ "*(a*|b*)*(c*|d*)", true, "c/d", false }, |
| 484 |
{ "*(a*|b*)*(c*|d*)", true, "d/a", false }, |
| 485 |
{ "*(a*|b*)*(c*|d*)", true, "d/b", false }, |
| 486 |
{ "*(a*|b*)*(c*|d*)", true, "d/c", false }, |
| 487 |
|
| 488 |
// Test with path at beginning |
| 489 |
{ "**/(a*|b*)*(c*|d*)", true, "ac", true }, |
| 490 |
{ "**/(a*|b*)*(c*|d*)", true, "ad", true }, |
| 491 |
{ "**/(a*|b*)*(c*|d*)", true, "bc", true }, |
| 492 |
{ "**/(a*|b*)*(c*|d*)", true, "bd", true }, |
| 493 |
{ "**/(a*|b*)*(c*|d*)", true, "x/ac", true }, |
| 494 |
{ "**/(a*|b*)*(c*|d*)", true, "x/ad", true }, |
| 495 |
{ "**/(a*|b*)*(c*|d*)", true, "x/bc", true }, |
| 496 |
{ "**/(a*|b*)*(c*|d*)", true, "x/bd", true }, |
| 497 |
{ "**/(a*|b*)*(c*|d*)", true, "x/a/c", false }, |
| 498 |
{ "**/(a*|b*)*(c*|d*)", true, "x/a/d", false }, |
| 499 |
{ "**/(a*|b*)*(c*|d*)", true, "x/b/c", false }, |
| 500 |
{ "**/(a*|b*)*(c*|d*)", true, "x/b/d", false }, |
| 501 |
{ "**/(a*|b*)*(c*|d*)", true, "x/a/a12c", true }, |
| 502 |
{ "**/(a*|b*)*(c*|d*)", true, "x/a/a12d", true }, |
| 503 |
{ "**/(a*|b*)*(c*|d*)", true, "x/a/b12c", true }, |
| 504 |
{ "**/(a*|b*)*(c*|d*)", true, "x/a/b12d", true }, |
| 505 |
{ "**/(a*|b*)*(c*|d*)", true, "x/a/0a12c34", false }, |
| 506 |
{ "**/(a*|b*)*(c*|d*)", true, "x/a/0a12d34", false }, |
| 507 |
{ "**/(a*|b*)*(c*|d*)", true, "x/a/0b12c34", false }, |
| 508 |
{ "**/(a*|b*)*(c*|d*)", true, "x/a/0b12d34", false }, |
| 509 |
|
| 510 |
{ NULL, false, NULL, false } |
| 511 |
}; |
| 512 |
|
| 513 |
test_match_patterns(matches); |
| 514 |
} |
| 515 |
|
| 516 |
void test_match_examples() |
| 517 |
{ |
| 518 |
static const match_t matches[] = |
| 519 |
{ |
| 520 |
// One file type |
| 521 |
{ "*.c", false, "main.c", true }, |
| 522 |
{ "*.c", false, "src/main.c", true }, |
| 523 |
{ "!*.c", false, "main.c", false }, |
| 524 |
{ "!*.c", false, "main.o", true }, |
| 525 |
|
| 526 |
// Two file types |
| 527 |
{ "*.c|*.h", false, "main.c", true }, |
| 528 |
{ "*.c|*.h", false, "main.h", true }, |
| 529 |
{ "*.c|*.h", false, "src/main.c", true }, |
| 530 |
{ "*.c|*.h", false, "include/main.h", true }, |
| 531 |
|
| 532 |
// Except two file types |
| 533 |
{ "(!*.c)&(!*.h)", false, "main.c", false }, |
| 534 |
{ "(!*.c)&(!*.h)", false, "main.h", false }, |
| 535 |
{ "(!*.c)&(!*.h)", false, "src/main.c", false }, |
| 536 |
{ "(!*.c)&(!*.h)", false, "include/main.h", false }, |
| 537 |
{ "(!*.c)&(!*.h)", true, "src/main.c", true }, |
| 538 |
{ "(!*.c)&(!*.h)", true, "include/main.h", true }, |
| 539 |
|
| 540 |
// Additional exceptions |
| 541 |
{ "(*.c|*.h)&(!test-*)", false, "main.c", true }, |
| 542 |
{ "(*.c|*.h)&(!test-*)", false, "main.h", true }, |
| 543 |
{ "(*.c|*.h)&(!test-*)", false, "test-main.c", false }, |
| 544 |
{ "(*.c|*.h)&(!test-*)", false, "test-main.h", false }, |
| 545 |
{ "(*.c|*.h)&(!test-*)", false, "src/main.c", true }, |
| 546 |
{ "(*.c|*.h)&(!test-*)", false, "include/main.h", true }, |
| 547 |
{ "(*.c|*.h)&(!test-*)", false, "src/test-main.c", false }, |
| 548 |
{ "(*.c|*.h)&(!test-*)", false, "include/test-main.h", false }, |
| 549 |
{ "(*.c|*.h)&(!test-*)", true, "src/main.c", false }, |
| 550 |
{ "(*.c|*.h)&(!test-*)", true, "include/main.h", false }, |
| 551 |
{ "(*.c|*.h)&(!test-*)", true, "src/test-main.c", false }, |
| 552 |
{ "(*.c|*.h)&(!test-*)", true, "include/test-main.h", false }, |
| 553 |
|
| 554 |
// With paths |
| 555 |
{ "**/((*.c|*.h)&(!test-*))", false, "prj/main.c", true }, |
| 556 |
{ "**/((*.c|*.h)&(!test-*))", false, "prj/main.h", true }, |
| 557 |
{ "**/((*.c|*.h)&(!test-*))", false, "prj/test-main.c", false }, |
| 558 |
{ "**/((*.c|*.h)&(!test-*))", false, "prj/test-main.h", false }, |
| 559 |
{ "**/((*.c|*.h)&(!test-*))", false, "prj/src/main.c", true }, |
| 560 |
{ "**/((*.c|*.h)&(!test-*))", false, "prj/include/main.h", true }, |
| 561 |
{ "**/((*.c|*.h)&(!test-*))", false, "prj/src/test-main.c", false }, |
| 562 |
{ "**/((*.c|*.h)&(!test-*))", false, "prj/include/test-main.h", false }, |
| 563 |
{ "**/((*.c|*.h)&(!test-*))", true, "prj/src/main.c", true }, |
| 564 |
{ "**/((*.c|*.h)&(!test-*))", true, "prj/include/main.h", true }, |
| 565 |
{ "**/((*.c|*.h)&(!test-*))", true, "prj/src/test-main.c", false }, |
| 566 |
{ "**/((*.c|*.h)&(!test-*))", true, "prj/include/test-main.h", false }, |
| 567 |
|
| 568 |
// More complicated condition |
| 569 |
{ "(*.c|*.h)&(test-*)|(*.o|*.a)&(!test-*)", true, "main.c", false }, |
| 570 |
{ "(*.c|*.h)&(test-*)|(*.o|*.a)&(!test-*)", true, "main.h", false }, |
| 571 |
{ "(*.c|*.h)&(test-*)|(*.o|*.a)&(!test-*)", true, "test-main.c", true }, |
| 572 |
{ "(*.c|*.h)&(test-*)|(*.o|*.a)&(!test-*)", true, "test-main.h", true }, |
| 573 |
{ "(*.c|*.h)&(test-*)|(*.o|*.a)&(!test-*)", true, "main.o", true }, |
| 574 |
{ "(*.c|*.h)&(test-*)|(*.o|*.a)&(!test-*)", true, "main.a", true }, |
| 575 |
{ "(*.c|*.h)&(test-*)|(*.o|*.a)&(!test-*)", true, "test-main.o", false }, |
| 576 |
{ "(*.c|*.h)&(test-*)|(*.o|*.a)&(!test-*)", true, "test-main.a", false }, |
| 577 |
|
| 578 |
{ NULL, false, NULL, false } |
| 579 |
}; |
| 580 |
|
| 581 |
test_match_patterns(matches); |
| 582 |
} |
| 583 |
|
| 584 |
UTEST_MAIN |
| 585 |
{ |
| 586 |
test_parse(); |
| 587 |
test_match_simple(); |
| 588 |
test_match_sequence_only(); |
| 589 |
test_match_brute(); |
| 590 |
test_match_examples(); |
| 591 |
} |
| 592 |
|
| 593 |
UTEST_END |
| 594 |
|
| 595 |
|