dte test coverage


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 50.0% high: ≥ 85.0%
Coverage Exec / Excl / Total
Lines: 100.0% 12 / 0 / 12
Functions: 100.0% 1 / 0 / 1
Branches: -% 0 / 0 / 0

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