From: Olaf Wintermann Date: Tue, 3 Feb 2026 18:01:39 +0000 (+0100) Subject: add test_text_search_match X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=61824b1acce9453ea55c96363ee1ed0c7d6d01e1;p=note.git add test_text_search_match --- diff --git a/application/note.c b/application/note.c index 075b054..acf5c83 100644 --- a/application/note.c +++ b/application/note.c @@ -451,6 +451,10 @@ static void note_search(NoteModel *note, bool backwards) { note->text->setselection(note->text, begin, end); note->text->showposition(note->text, begin); } + + if(enable_regex) { + regfree(®ex); + } } void note_search_next(NoteModel *note) { diff --git a/application/tests/test-note.c b/application/tests/test-note.c index f713d57..ab872dd 100644 --- a/application/tests/test-note.c +++ b/application/tests/test-note.c @@ -250,6 +250,34 @@ CX_TEST(test_text_search_regex) { CX_TEST_ASSERT(ret); CX_TEST_ASSERT(begin == 25); CX_TEST_ASSERT(end == 30); + + regfree(®ex); } } + +CX_TEST(test_text_search_match) { + CX_TEST_DO { + cxstring str = cx_str("hello begin::end world"); + + regex_t regex; + CX_TEST_ASSERT(!regcomp(®ex, "begin<(.*)>:<(.*)>:<(.*)>end", REG_EXTENDED)); + + int begin, end, ret; + regmatch_t match[16]; + ret = text_search_match(str, cx_str(""), 0, FALSE, FALSE, ®ex, &begin, &end, match, 16); + CX_TEST_ASSERT(ret); + CX_TEST_ASSERT(begin == 6); + CX_TEST_ASSERT(end == 40); + CX_TEST_ASSERT(match[1].rm_so == 12); + CX_TEST_ASSERT(match[1].rm_eo == 18); + CX_TEST_ASSERT(match[2].rm_so == 21); + CX_TEST_ASSERT(match[2].rm_eo == 27); + CX_TEST_ASSERT(match[3].rm_so == 30); + CX_TEST_ASSERT(match[3].rm_eo == 36); + CX_TEST_ASSERT(match[4].rm_so == -1); + CX_TEST_ASSERT(match[4].rm_eo == -1); + + regfree(®ex); + } +} diff --git a/application/tests/test-note.h b/application/tests/test-note.h index d3a629a..eefef65 100644 --- a/application/tests/test-note.h +++ b/application/tests/test-note.h @@ -39,6 +39,7 @@ CX_TEST(test_text_search_strcasestr); CX_TEST(test_text_search_cs); CX_TEST(test_text_search_ci); CX_TEST(test_text_search_regex); +CX_TEST(test_text_search_match); #ifdef __cplusplus diff --git a/application/tests/testmain.c b/application/tests/testmain.c index 481f47a..f570fbe 100644 --- a/application/tests/testmain.c +++ b/application/tests/testmain.c @@ -82,6 +82,7 @@ int main(int argc, char **argv) { cx_test_register(suite, test_text_search_cs); cx_test_register(suite, test_text_search_ci); cx_test_register(suite, test_text_search_regex); + cx_test_register(suite, test_text_search_match); cx_test_run_stdout(suite); int err = suite->failure > 0 ? 1 : 0;