]> jfr.im git - solanum.git/blob - tests/match1.c
Fix a corner case of superset matching
[solanum.git] / tests / match1.c
1 /*
2 * Copyright (C) 2020 Ed Kellett
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
17 * USA
18 */
19 #include <stdio.h>
20 #include <string.h>
21 #include <stdlib.h>
22 #include <unistd.h>
23 #include "tap/basic.h"
24
25 #include "stdinc.h"
26 #include "client.h"
27 #include "match.h"
28
29 #define MSG "%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__
30
31 struct Client me;
32
33 void match_arrange_stars(char *);
34
35 static void test_match(void)
36 {
37 is_int(0, match("*foo*", "bar"), MSG);
38 is_int(1, match("*foo*", "foo"), MSG);
39
40 is_int(1, match("*foo*", "xfofoo"), MSG);
41 }
42
43 static void test_mask_match(void)
44 {
45
46 is_int(0, mask_match("*foo*", "bar"), MSG);
47 is_int(1, mask_match("*foo*", "foo"), MSG);
48
49 is_int(1, mask_match("*foo*", "xfofoo"), MSG);
50
51 is_int(1, mask_match("*", "*foo*"), MSG);
52 is_int(0, mask_match("*foo*", "*"), MSG);
53 is_int(1, mask_match("*", "*"), MSG);
54 is_int(0, mask_match("?", "*"), MSG);
55 is_int(1, mask_match("*?", "*?"), MSG);
56 is_int(1, mask_match("?*", "*?"), MSG);
57 is_int(1, mask_match("*?*?*?*", "*?????*"), MSG);
58 is_int(0, mask_match("*??*??*??*", "*?????*"), MSG);
59
60 is_int(1, mask_match("?*", "*a"), MSG);
61 is_int(1, mask_match("???*", "*a*a*a"), MSG);
62 is_int(0, mask_match("???*", "*a*a*"), MSG);
63
64 is_int(0, mask_match("??", "a"), MSG);
65 is_int(1, mask_match("??", "aa"), MSG);
66 is_int(0, mask_match("??", "aaa"), MSG);
67 }
68
69 static void test_arrange_stars(void)
70 {
71 {
72 char rearrange[] = "quick brown fox";
73 match_arrange_stars(rearrange);
74 is_string("quick brown fox", rearrange, MSG);
75 }
76 {
77 char rearrange[] = "?*?*?*";
78 match_arrange_stars(rearrange);
79 is_string("***???", rearrange, MSG);
80 }
81 {
82 char rearrange[] = "?*? *?*";
83 match_arrange_stars(rearrange);
84 is_string("*?? **?", rearrange, MSG);
85 }
86 }
87
88 int main(int argc, char *argv[])
89 {
90 plan_lazy();
91
92 test_match();
93 test_mask_match();
94 test_arrange_stars();
95
96 return 0;
97 }