note->text->setselection(note->text, begin, end);
note->text->showposition(note->text, begin);
}
+
+ if(enable_regex) {
+ regfree(®ex);
+ }
}
void note_search_next(NoteModel *note) {
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<group1>:<group2>:<group3>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);
+ }
+}
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
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;