]>
git.ipfire.org Git - thirdparty/bird.git/blob - lib/patmatch_test.c
2 * BIRD Library -- Pattern Matching Tests
4 * (c) 2015 CZ.NIC z.s.p.o.
6 * Can be freely distributed and used under the terms of the GNU GPL.
9 #include "test/birdtest.h"
11 #include "nest/bird.h"
12 #include "lib/string.h"
14 #define MATCH (int) { 1 }
15 #define NOMATCH (int) { 0 }
23 test_matching(void *out_
, const void *in_
, const void *expected_out_
)
26 const struct match_pair
*in
= in_
;
27 const int *expected_out
= expected_out_
;
29 *out
= patmatch(in
->pattern
, in
->data
);
31 return *out
== *expected_out
;
35 fmt_match_pair(char *buf
, size_t size
, const void *data
)
37 const struct match_pair
*mp
= data
;
38 snprintf(buf
, size
, "pattern: '%s', subject: '%s'", mp
->pattern
, mp
->data
);
42 fmt_match_result(char *buf
, size_t size
, const void *data
)
44 const int *result
= data
;
45 snprintf(buf
, size
, *result
? "match" : "no-match");
51 struct bt_pair test_vectors
[] = {
53 .in
= & (struct match_pair
) {
60 .in
= & (struct match_pair
) {
67 .in
= & (struct match_pair
) {
74 .in
= & (struct match_pair
) {
81 .in
= & (struct match_pair
) {
88 .in
= & (struct match_pair
) {
89 .pattern
= "abcdefghijklmnopqrstuvwxyz",
90 .data
= "abcdefghijklmnopqrstuvwxyz",
95 .in
= & (struct match_pair
) {
96 .pattern
= "??????????????????????????",
97 .data
= "abcdefghijklmnopqrstuvwxyz",
102 .in
= & (struct match_pair
) {
103 .pattern
= "*abcdefghijklmnopqrstuvwxyz*",
104 .data
= "abcdefghijklmnopqrstuvwxyz",
109 .in
= & (struct match_pair
) {
110 .pattern
= "ab?defg*jklmnop*stu*wxy*z",
111 .data
= "abcdefghijklmnopqrstuvwxyz",
116 .in
= & (struct match_pair
) {
117 .pattern
= "abcdefghijklmnopqrstuvwxyz",
118 .data
= "abcdefghijklmnopqrtuvwxyz",
123 .in
= & (struct match_pair
) {
124 .pattern
= "abcdefghijklmnopqr?uvwxyz",
125 .data
= "abcdefghijklmnopqrstuvwxyz",
130 .in
= & (struct match_pair
) {
131 .pattern
= "aa*aaaaa?aaaaaaaaaaaaaaaaaaa",
132 .data
= "aaaaaaaaaaaaaaaaaaaaaaaaaa",
138 return bt_assert_batch(test_vectors
, test_matching
, fmt_match_pair
, fmt_match_result
);
142 main(int argc
, char *argv
[])
146 bt_test_suite(t_matching
, "Pattern matching");
148 return bt_exit_value();