dte test coverage


Directory: ./
File: test/regexp.c
Date: 2024-12-21 16:03:22
Exec Total Coverage
Lines: 12 12 100.0%
Functions: 1 1 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 #include <stdlib.h>
2 #include "test.h"
3 #include "regexp.h"
4
5 1 static void test_regexp_escape(TestContext *ctx)
6 {
7 1 static const char pat[] = "^([a-z]+|0-9{3,6}|\\.|-?.*)$";
8 1 ASSERT_TRUE(regexp_is_valid(pat, REG_NEWLINE));
9 1 char *escaped = regexp_escape(pat, sizeof(pat) - 1);
10 1 EXPECT_STREQ(escaped, "\\^\\(\\[a-z]\\+\\|0-9\\{3,6}\\|\\\\\\.\\|-\\?\\.\\*\\)\\$");
11
12 // Ensure the escaped pattern matches the original pattern string
13 1 regex_t re;
14 1 regmatch_t m;
15 1 ASSERT_TRUE(regexp_compile(&re, escaped, REG_NEWLINE | REG_NOSUB));
16 1 free(escaped);
17 1 EXPECT_TRUE(regexp_exec(&re, pat, sizeof(pat) - 1, 0, &m, 0));
18 1 regfree(&re);
19 1 }
20
21 static const TestEntry tests[] = {
22 TEST(test_regexp_escape),
23 };
24
25 const TestGroup regexp_tests = TEST_GROUP(tests);
26