view src/lib/test-wildcard-match.c @ 18137:3009a1a6f6d5

global: freshen copyright Robomatically: git ls-files | xargs perl -p -i -e 's/(\d+)-201[0-4]/$1-2015/g;s/ (201[0-4]) Dovecot/ $1-2015 Dovecot/' Happy 2015 everyone! Signed-off-by: Phil Carmody <phil@dovecot.fi>
author Phil Carmody <phil@dovecot.fi>
date Mon, 05 Jan 2015 22:20:10 +0200
parents d1d4beff99f7
children 91852459f388
line wrap: on
line source

/* Copyright (c) 2014-2015 Dovecot authors, see the included COPYING file */

#include "test-lib.h"
#include "wildcard-match.h"

static 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 },

	{ "", "*", 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();
}