]> uap-core.de Git - note.git/commitdiff
add test_text_search_match
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Tue, 3 Feb 2026 18:01:39 +0000 (19:01 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Tue, 3 Feb 2026 18:01:39 +0000 (19:01 +0100)
application/note.c
application/tests/test-note.c
application/tests/test-note.h
application/tests/testmain.c

index 075b0546021c86292776779164c62affe2282ecb..acf5c83b8424b0f1286c0efaaf7b841940cba913 100644 (file)
@@ -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(&regex);
+    }
 }
 
 void note_search_next(NoteModel *note) {
index f713d570ffeff9167f142178ed6cd19770fedbf5..ab872ddaef04972f20ad34a4d6e268fe18aa6214 100644 (file)
@@ -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(&regex);
     }
     
 }
+
+CX_TEST(test_text_search_match) {
+    CX_TEST_DO {
+        cxstring str = cx_str("hello begin<group1>:<group2>:<group3>end world");
+        
+        regex_t regex;
+        CX_TEST_ASSERT(!regcomp(&regex, "begin<(.*)>:<(.*)>:<(.*)>end", REG_EXTENDED));
+        
+        int begin, end, ret;
+        regmatch_t match[16];
+        ret = text_search_match(str, cx_str(""), 0, FALSE, FALSE, &regex, &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(&regex);
+    }
+}
index d3a629aed1916d64670933590c1fdbafcc32f2c9..eefef655c077d7ba1304bfdb66939f86fd583f80 100644 (file)
@@ -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
index 481f47a29e68ed304032c36803ecfbc3cc9c4138..f570fbe75b69f6235ba934e6b549b0cd4bc7c19c 100644 (file)
@@ -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;