diff options
Diffstat (limited to 'src/lib/test-wildcard-match.c')
-rw-r--r-- | src/lib/test-wildcard-match.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/lib/test-wildcard-match.c b/src/lib/test-wildcard-match.c new file mode 100644 index 0000000..7a459da --- /dev/null +++ b/src/lib/test-wildcard-match.c @@ -0,0 +1,48 @@ +/* Copyright (c) 2014-2018 Dovecot authors, see the included COPYING file */ + +#include "test-lib.h" +#include "wildcard-match.h" + +static const struct { + const char *data; + const char *mask; + bool result; +} tests[] = { + { "foo", "*", TRUE }, + { "foo", "*foo*", TRUE }, + { "foo", "foo", TRUE }, + { "foo", "f*o*o", TRUE }, + { "foo", "f??", TRUE }, + { "foo", "f?o", TRUE }, + { "foo", "*??", TRUE }, + { "foo", "???", TRUE }, + { "foo", "f??*", TRUE }, + { "foo", "???*", TRUE }, + + { "foo", "", FALSE }, + { "foo", "f", FALSE }, + { "foo", "fo", FALSE }, + { "foo", "fooo", FALSE }, + { "foo", "????", FALSE }, + { "foo", "f*o*o*o", FALSE }, + { "foo", "f???*", FALSE }, + + { "*foo", "foo", FALSE }, + { "foo*", "foo", FALSE }, + { "*foo*", "foo", FALSE }, + + { "", "*", TRUE }, + { "", "", TRUE }, + { "", "?", FALSE } +}; + +void test_wildcard_match(void) +{ + unsigned int i; + + test_begin("wildcard_match()"); + for (i = 0; i < N_ELEMENTS(tests); i++) { + test_assert_idx(wildcard_match(tests[i].data, tests[i].mask) == tests[i].result, i); + } + test_end(); +} |