mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-12-23 10:11:53 +00:00
Birdtest: Add Pattern Matching Tests
This commit is contained in:
parent
9334886d1a
commit
7e035b81cb
133
lib/patmatch_test.c
Normal file
133
lib/patmatch_test.c
Normal file
@ -0,0 +1,133 @@
|
||||
/*
|
||||
* BIRD Library -- Pattern Matching Tests
|
||||
*
|
||||
* (c) 2015 CZ.NIC z.s.p.o.
|
||||
*
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*/
|
||||
|
||||
#include "test/birdtest.h"
|
||||
#include "test/birdtest_support.h" /* REMOVE ME */
|
||||
|
||||
#include "lib/patmatch.c" /* REMOVE ME */
|
||||
|
||||
#define MATCH 1
|
||||
#define NOMATCH 0
|
||||
|
||||
struct in {
|
||||
byte *pattern;
|
||||
byte *data;
|
||||
};
|
||||
|
||||
struct in_out {
|
||||
struct in in;
|
||||
byte out;
|
||||
};
|
||||
|
||||
static void
|
||||
match(struct in in, byte *out)
|
||||
{
|
||||
*out = patmatch(in.pattern, in.data) ? MATCH : NOMATCH;
|
||||
}
|
||||
|
||||
static int
|
||||
t_matching(void)
|
||||
{
|
||||
struct in_out in_out[] = {
|
||||
{
|
||||
.in = {
|
||||
.pattern = "",
|
||||
.data = "",
|
||||
},
|
||||
.out = MATCH,
|
||||
},
|
||||
{
|
||||
.in = {
|
||||
.pattern = "*",
|
||||
.data = "",
|
||||
},
|
||||
.out = MATCH,
|
||||
},
|
||||
{
|
||||
.in = {
|
||||
.pattern = "\\*",
|
||||
.data = "*",
|
||||
},
|
||||
.out = MATCH,
|
||||
},
|
||||
{
|
||||
.in = {
|
||||
.pattern = "\\*",
|
||||
.data = "a",
|
||||
},
|
||||
.out = NOMATCH,
|
||||
}, {
|
||||
.in = {
|
||||
.pattern = "?",
|
||||
.data = "",
|
||||
},
|
||||
.out = NOMATCH,
|
||||
},
|
||||
{
|
||||
.in = {
|
||||
.pattern = "abcdefghijklmnopqrstuvwxyz",
|
||||
.data = "abcdefghijklmnopqrstuvwxyz",
|
||||
},
|
||||
.out = MATCH,
|
||||
},
|
||||
{
|
||||
.in = {
|
||||
.pattern = "??????????????????????????",
|
||||
.data = "abcdefghijklmnopqrstuvwxyz",
|
||||
},
|
||||
.out = MATCH,
|
||||
},
|
||||
{
|
||||
.in = {
|
||||
.pattern = "*abcdefghijklmnopqrstuvwxyz*",
|
||||
.data = "abcdefghijklmnopqrstuvwxyz",
|
||||
},
|
||||
.out = MATCH,
|
||||
}, {
|
||||
.in = {
|
||||
.pattern = "ab?defg*jklmnop*stu*wxy*z",
|
||||
.data = "abcdefghijklmnopqrstuvwxyz",
|
||||
},
|
||||
.out = MATCH,
|
||||
},
|
||||
{
|
||||
.in = {
|
||||
.pattern = "abcdefghijklmnopqrstuvwxyz",
|
||||
.data = "abcdefghijklmnopqrtuvwxyz",
|
||||
},
|
||||
.out = NOMATCH,
|
||||
},
|
||||
{
|
||||
.in = {
|
||||
.pattern = "abcdefghijklmnopqr?uvwxyz",
|
||||
.data = "abcdefghijklmnopqrstuvwxyz",
|
||||
},
|
||||
.out = NOMATCH,
|
||||
},
|
||||
{
|
||||
.in = {
|
||||
.pattern = "aa*aaaaa?aaaaaaaaaaaaaaaaaaa",
|
||||
.data = "aaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
},
|
||||
.out = NOMATCH,
|
||||
},
|
||||
};
|
||||
|
||||
bt_assert_fn_in_out(match, in_out, "'%s' ~ '%s'", "%d");
|
||||
|
||||
return BT_SUCCESS;
|
||||
}
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
bt_init(argc, argv);
|
||||
|
||||
bt_test_suite(t_matching, "Pattern matching");
|
||||
|
||||
return bt_end();
|
||||
}
|
Loading…
Reference in New Issue
Block a user