Add unit test

This commit is contained in:
Sergey Lyubka 2015-05-19 15:52:39 +01:00
parent deb7c0dddf
commit 15b7ff90f8

View File

@ -260,12 +260,14 @@ int main(void) {
{
/* Example more complex regular expression */
static const char * str = "aa 1234 xy\nz";
static const char * regex = "aa ([0-9]*) *([x-z]*)";
struct slre_cap caps[2];
ASSERT(slre_match(regex, str, strlen(str), caps, 2, 0) > 0);
static const char * str = "aa 1234 xy\nxyz";
static const char * regex = "aa ([0-9]*) *([x-z]*)\\s+xy([yz])";
struct slre_cap caps[3];
ASSERT(slre_match(regex, str, strlen(str), caps, 3, 0) > 0);
ASSERT(caps[0].len == 4);
ASSERT(caps[1].len == 2); /* Fails here */
ASSERT(caps[1].len == 2);
ASSERT(caps[2].len == 1);
ASSERT(caps[2].ptr[0] == 'z');
}
printf("Unit test %s (total test: %d, failed tests: %d)\n",