From: Olaf Wintermann Date: Sun, 1 Feb 2026 11:19:50 +0000 (+0100) Subject: add test_text_search_cs/test_text_search_ci X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=HEAD;p=note.git add test_text_search_cs/test_text_search_ci --- diff --git a/application/tests/test-note.c b/application/tests/test-note.c index 0accaa6..fd23ec7 100644 --- a/application/tests/test-note.c +++ b/application/tests/test-note.c @@ -60,3 +60,146 @@ CX_TEST(test_text_search_strcasestr) { CX_TEST_ASSERT(result.ptr == NULL && result.length == 0); } } + +CX_TEST(test_text_search_cs) { + CX_TEST_DO { + cxstring str = cx_str("123 4567 890 abcd edfghj 123 xyz abc"); + + // test from pos 0 + int begin = -1; + int end = -1; + int ret = text_search(str, cx_str("123"), 0, FALSE, TRUE, FALSE, &begin, &end); + CX_TEST_ASSERT(ret); + CX_TEST_ASSERT(begin == 0); + CX_TEST_ASSERT(end == 3); + + begin = -1; + end = -1; + ret = text_search(str, cx_str("4567"), 0, FALSE, TRUE, FALSE, &begin, &end); + CX_TEST_ASSERT(ret); + CX_TEST_ASSERT(begin == 4); + CX_TEST_ASSERT(end == 8); + + begin = -1; + end = -1; + ret = text_search(str, cx_str("edfghj"), 0, FALSE, TRUE, FALSE, &begin, &end); + CX_TEST_ASSERT(ret); + CX_TEST_ASSERT(begin == 18); + CX_TEST_ASSERT(end == 24); + + begin = -1; + end = -1; + ret = text_search(str, cx_str("abc"), 0, FALSE, TRUE, FALSE, &begin, &end); + CX_TEST_ASSERT(ret); + CX_TEST_ASSERT(begin == 13); + CX_TEST_ASSERT(end == 16); + + // test from other positions + begin = -1; + end = -1; + ret = text_search(str, cx_str("4567"), 4, FALSE, TRUE, FALSE, &begin, &end); + CX_TEST_ASSERT(ret); + CX_TEST_ASSERT(begin == 4); + CX_TEST_ASSERT(end == 8); + + begin = -1; + end = -1; + ret = text_search(str, cx_str("abc"), 14, FALSE, TRUE, FALSE, &begin, &end); + CX_TEST_ASSERT(ret); + CX_TEST_ASSERT(begin == 33); + CX_TEST_ASSERT(end == 36); + + ret = text_search(str, cx_str("4567"), 20, FALSE, TRUE, FALSE, &begin, &end); + CX_TEST_ASSERT(!ret); + + ret = text_search(str, cx_str("edfghj"), 19, FALSE, TRUE, FALSE, &begin, &end); + CX_TEST_ASSERT(!ret); + + // case sensitive test + ret = text_search(str, cx_str("ABCD"), 0, FALSE, TRUE, FALSE, &begin, &end); + CX_TEST_ASSERT(!ret); + + ret = text_search(str, cx_str("Xyz"), 0, FALSE, TRUE, FALSE, &begin, &end); + CX_TEST_ASSERT(!ret); + + // backwards search + begin = -1; + end = -1; + ret = text_search(str, cx_str("abc"), 36, TRUE, TRUE, FALSE, &begin, &end); + CX_TEST_ASSERT(ret); + CX_TEST_ASSERT(begin == 33); + CX_TEST_ASSERT(end == 36); + + begin = -1; + end = -1; + ret = text_search(str, cx_str("edf"), 25, TRUE, TRUE, FALSE, &begin, &end); + CX_TEST_ASSERT(ret); + CX_TEST_ASSERT(begin == 18); + CX_TEST_ASSERT(end == 21); + + begin = -1; + end = -1; + ret = text_search(str, cx_str("abc"), 25, TRUE, TRUE, FALSE, &begin, &end); + CX_TEST_ASSERT(ret); + CX_TEST_ASSERT(begin == 13); + CX_TEST_ASSERT(end == 16); + } +} + +CX_TEST(test_text_search_ci) { + CX_TEST_DO { + cxstring str = cx_str("Abc dEF 123 XYZ abc"); + + // test from pos 0 + int begin = -1; + int end = -1; + int ret = text_search(str, cx_str("abc"), 0, FALSE, FALSE, FALSE, &begin, &end); + CX_TEST_ASSERT(ret); + CX_TEST_ASSERT(begin == 0); + CX_TEST_ASSERT(end == 3); + + begin = -1; + end = -1; + ret = text_search(str, cx_str("def"), 0, FALSE, FALSE, FALSE, &begin, &end); + CX_TEST_ASSERT(ret); + CX_TEST_ASSERT(begin == 4); + CX_TEST_ASSERT(end == 7); + + begin = -1; + end = -1; + ret = text_search(str, cx_str("DEF"), 0, FALSE, FALSE, FALSE, &begin, &end); + CX_TEST_ASSERT(ret); + CX_TEST_ASSERT(begin == 4); + CX_TEST_ASSERT(end == 7); + + // test other pos + begin = -1; + end = -1; + ret = text_search(str, cx_str("DEF"), 4, FALSE, FALSE, FALSE, &begin, &end); + CX_TEST_ASSERT(ret); + CX_TEST_ASSERT(begin == 4); + CX_TEST_ASSERT(end == 7); + + begin = -1; + end = -1; + ret = text_search(str, cx_str("ABC"), 8, FALSE, FALSE, FALSE, &begin, &end); + CX_TEST_ASSERT(ret); + CX_TEST_ASSERT(begin == 16); + CX_TEST_ASSERT(end == 19); + + // backwards + begin = -1; + end = -1; + ret = text_search(str, cx_str("aBc"), 19, TRUE, FALSE, FALSE, &begin, &end); + CX_TEST_ASSERT(ret); + CX_TEST_ASSERT(begin == 16); + CX_TEST_ASSERT(end == 19); + + begin = -1; + end = -1; + ret = text_search(str, cx_str("xyz"), 19, TRUE, FALSE, FALSE, &begin, &end); + CX_TEST_ASSERT(ret); + CX_TEST_ASSERT(begin == 12); + CX_TEST_ASSERT(end == 15); + } +} diff --git a/application/tests/test-note.h b/application/tests/test-note.h index 44fe7f5..3404d3c 100644 --- a/application/tests/test-note.h +++ b/application/tests/test-note.h @@ -36,6 +36,8 @@ extern "C" { #endif CX_TEST(test_text_search_strcasestr); +CX_TEST(test_text_search_cs); +CX_TEST(test_text_search_ci); #ifdef __cplusplus diff --git a/application/tests/testmain.c b/application/tests/testmain.c index 49fe831..36fcb61 100644 --- a/application/tests/testmain.c +++ b/application/tests/testmain.c @@ -79,6 +79,8 @@ int main(int argc, char **argv) { cx_test_register(suite, test_mddoc_linearization); cx_test_register(suite, test_text_search_strcasestr); + cx_test_register(suite, test_text_search_cs); + cx_test_register(suite, test_text_search_ci); cx_test_run_stdout(suite); int err = suite->failure > 0 ? 1 : 0;