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 <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 String escaped = regexp_escape(strview(pat));
10
11 1 EXPECT_STRING_EQ_CSTRING (
12 &escaped,
13 "\\^\\(\\[a-z]\\+\\|0-9\\{3,6}\\|\\\\\\.\\|-\\?\\.\\*\\)\\$"
14 );
15
16 // Ensure the escaped pattern matches the original pattern string
17 1 const char *cstr = string_borrow_cstring(&escaped);
18 1 regex_t re;
19 1 ASSERT_TRUE(regexp_compile(NULL, &re, cstr, REG_NEWLINE | REG_NOSUB));
20 1 string_free(&escaped);
21 1 EXPECT_TRUE(regexp_exec(&re, strview(pat), 0, NULL, 0));
22 1 regfree(&re);
23 1 }
24
25 static const TestEntry tests[] = {
26 TEST(test_regexp_escape),
27 };
28
29 const TestGroup regexp_tests = TEST_GROUP(tests);
30