]> uap-core.de Git - note.git/commitdiff
add test_text_search_cs/test_text_search_ci main
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 1 Feb 2026 11:19:50 +0000 (12:19 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 1 Feb 2026 11:19:50 +0000 (12:19 +0100)
application/tests/test-note.c
application/tests/test-note.h
application/tests/testmain.c

index 0accaa675a1408ded5bcf1e03194e39c48e48fa8..fd23ec71aef2713cac231ea36e3755e9093fce43 100644 (file)
@@ -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);
+    }
+}
index 44fe7f55f47657854ff67242ccf68a97fc50905f..3404d3caf8ffc3095afd2e23d38baebe10bb6c8a 100644 (file)
@@ -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
index 49fe83135ab3360cd52d44b6b68ac96d6751a288..36fcb619bf28300a8860ae2a7ed10d2d6eb63d5a 100644 (file)
@@ -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;