dte test coverage


Directory: ./
File: test/regexp.c
Date: 2025-07-19 20:13:10
Exec Total Coverage
Lines: 11 11 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(NULL, 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 ASSERT_TRUE(regexp_compile(NULL, &re, escaped, REG_NEWLINE | REG_NOSUB));
15 1 free(escaped);
16 1 EXPECT_TRUE(regexp_exec(&re, pat, sizeof(pat) - 1, 0, NULL, 0));
17 1 regfree(&re);
18 1 }
19
20 static const TestEntry tests[] = {
21 TEST(test_regexp_escape),
22 };
23
24 const TestGroup regexp_tests = TEST_GROUP(tests);
25