Skip to content

Commit 47db630

Browse files
cosmo0920edsiper
authored andcommitted
tests: internal: Add test cases for a slash literal
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
1 parent a915534 commit 47db630

1 file changed

Lines changed: 92 additions & 0 deletions

File tree

tests/internal/regex.c

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,12 +319,104 @@ static void test_option_i_x()
319319
}
320320
}
321321

322+
static void test_literal_slash()
323+
{
324+
struct flb_regex *regex = NULL;
325+
int ret;
326+
327+
regex = flb_regex_create("/");
328+
if (!TEST_CHECK(regex != NULL)) {
329+
TEST_MSG("flb_regex_create failed");
330+
exit(1);
331+
}
332+
333+
ret = flb_regex_match(regex, (unsigned char *) "/tmp", 4);
334+
if (!TEST_CHECK(ret == 1)) {
335+
TEST_MSG("literal slash did not match");
336+
flb_regex_destroy(regex);
337+
exit(1);
338+
}
339+
340+
ret = flb_regex_match(regex, (unsigned char *) "tmp", 3);
341+
if (!TEST_CHECK(ret == 0)) {
342+
TEST_MSG("literal slash matched string without slash");
343+
flb_regex_destroy(regex);
344+
exit(1);
345+
}
346+
347+
ret = flb_regex_destroy(regex);
348+
if (!TEST_CHECK(ret == 0)) {
349+
TEST_MSG("flb_regex_destroy failed");
350+
exit(1);
351+
}
352+
}
353+
354+
static void test_slash_delimited_pattern()
355+
{
356+
struct flb_regex *regex = NULL;
357+
int ret;
358+
359+
regex = flb_regex_create("/tmp/");
360+
if (!TEST_CHECK(regex != NULL)) {
361+
TEST_MSG("flb_regex_create failed");
362+
exit(1);
363+
}
364+
365+
ret = flb_regex_match(regex, (unsigned char *) "tmp", 3);
366+
if (!TEST_CHECK(ret == 1)) {
367+
TEST_MSG("slash-delimited pattern did not match");
368+
flb_regex_destroy(regex);
369+
exit(1);
370+
}
371+
372+
ret = flb_regex_destroy(regex);
373+
if (!TEST_CHECK(ret == 0)) {
374+
TEST_MSG("flb_regex_destroy failed");
375+
exit(1);
376+
}
377+
}
378+
379+
static void test_slash_delimited_literal_slashes()
380+
{
381+
struct flb_regex *regex = NULL;
382+
int ret;
383+
384+
regex = flb_regex_create("//tmp//");
385+
if (!TEST_CHECK(regex != NULL)) {
386+
TEST_MSG("flb_regex_create failed");
387+
exit(1);
388+
}
389+
390+
ret = flb_regex_match(regex, (unsigned char *) "/tmp/", 5);
391+
if (!TEST_CHECK(ret == 1)) {
392+
TEST_MSG("slash-delimited literal slash pattern did not match");
393+
flb_regex_destroy(regex);
394+
exit(1);
395+
}
396+
397+
ret = flb_regex_match(regex, (unsigned char *) "tmp", 3);
398+
if (!TEST_CHECK(ret == 0)) {
399+
TEST_MSG("slash-delimited literal slash pattern matched string without slashes");
400+
flb_regex_destroy(regex);
401+
exit(1);
402+
}
403+
404+
ret = flb_regex_destroy(regex);
405+
if (!TEST_CHECK(ret == 0)) {
406+
TEST_MSG("flb_regex_destroy failed");
407+
exit(1);
408+
}
409+
}
410+
322411
TEST_LIST = {
323412
{ "basic" , test_basic},
324413
{ "uri" , test_uri},
325414
{ "option_ignore_case", test_option_ignore_case},
326415
{ "option_multiline" , test_option_multiline},
327416
{ "option_extend" , test_option_extend},
328417
{ "option_i_x" , test_option_i_x},
418+
{ "literal_slash" , test_literal_slash},
419+
{ "slash_delimited_pattern" , test_slash_delimited_pattern},
420+
{ "slash_delimited_literal_slashes" , test_slash_delimited_literal_slashes},
329421
{ 0 }
330422
};

0 commit comments

Comments
 (0)