mirror of
https://source.denx.de/u-boot/u-boot.git
synced 2025-12-24 02:42:18 +01:00
Add some tests for the "drop wrong anchored optimization". Without
the previous commit, the first, fifth and seventh of these would fail,
i.e. those:
{ "xby", "^a|b", 1},
{ "", "x*$", 1},
{ "yy", "x*$", 1},
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Rasmus Villemoes <ravi@prevas.dk>
45 lines
888 B
C
45 lines
888 B
C
// SPDX-License-Identifier: GPL-2.0 OR MIT
|
|
|
|
#include <test/lib.h>
|
|
#include <test/ut.h>
|
|
#include <slre.h>
|
|
|
|
struct re_test {
|
|
const char *str;
|
|
const char *re;
|
|
int match;
|
|
};
|
|
|
|
static const struct re_test re_test[] = {
|
|
{ "123", "^\\d+$", 1},
|
|
{ "x23", "^\\d+$", 0},
|
|
{ "banana", "^([bn]a)*$", 1},
|
|
{ "panama", "^([bn]a)*$", 0},
|
|
{ "xby", "^a|b", 1},
|
|
{ "xby", "b|^a", 1},
|
|
{ "xby", "b|c$", 1},
|
|
{ "xby", "c$|b", 1},
|
|
{ "", "x*$", 1},
|
|
{ "", "^x*$", 1},
|
|
{ "yy", "x*$", 1},
|
|
{ "yy", "^x*$", 0},
|
|
{}
|
|
};
|
|
|
|
static int lib_slre(struct unit_test_state *uts)
|
|
{
|
|
const struct re_test *t;
|
|
|
|
for (t = re_test; t->str; t++) {
|
|
struct slre slre;
|
|
|
|
ut_assert(slre_compile(&slre, t->re));
|
|
ut_assertf(!!slre_match(&slre, t->str, strlen(t->str), NULL) == t->match,
|
|
"'%s' unexpectedly %s '%s'\n", t->str,
|
|
t->match ? "didn't match" : "matched", t->re);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
LIB_TEST(lib_slre, 0);
|