]>
jfr.im git - solanum.git/blob - tests/match1.c
2 * Copyright (C) 2020 Ed Kellett
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.
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.
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
23 #include "tap/basic.h"
29 #define MSG "%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__
33 void match_arrange_stars(char *);
35 static void test_match(void)
37 is_int(0, match("*foo*", "bar"), MSG
);
38 is_int(1, match("*foo*", "foo"), MSG
);
40 is_int(1, match("*foo*", "xfofoo"), MSG
);
43 static void test_mask_match(void)
46 is_int(0, mask_match("*foo*", "bar"), MSG
);
47 is_int(1, mask_match("*foo*", "foo"), MSG
);
49 is_int(1, mask_match("*foo*", "xfofoo"), MSG
);
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
);
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
);
64 is_int(0, mask_match("??", "a"), MSG
);
65 is_int(1, mask_match("??", "aa"), MSG
);
66 is_int(0, mask_match("??", "aaa"), MSG
);
69 static void test_arrange_stars(void)
72 char rearrange
[] = "quick brown fox";
73 match_arrange_stars(rearrange
);
74 is_string("quick brown fox", rearrange
, MSG
);
77 char rearrange
[] = "?*?*?*";
78 match_arrange_stars(rearrange
);
79 is_string("***???", rearrange
, MSG
);
82 char rearrange
[] = "?*? *?*";
83 match_arrange_stars(rearrange
);
84 is_string("*?? **?", rearrange
, MSG
);
88 int main(int argc
, char *argv
[])