--- /dev/null
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2026 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "test-note.h"
+
+#include "../note.h"
+
+
+CX_TEST(test_text_search_strcasestr) {
+ CX_TEST_DO {
+ cxstring str = cx_str("Hello World\nöäüOAUÖÄÜ!\nend line");
+
+ cxstring result = text_search_strcasestr(str, cx_str("end"));
+ CX_TEST_ASSERT(!cx_strcmp(result, "end line"));
+ CX_TEST_ASSERT(result.ptr > str.ptr && result.ptr < str.ptr+str.length);
+
+ result = text_search_strcasestr(str, cx_str("EnD"));
+ CX_TEST_ASSERT(!cx_strcmp(result, "end line"));
+
+ result = text_search_strcasestr(str, cx_str("öäü"));
+ CX_TEST_ASSERT(!cx_strcmp(result, "öäüOAUÖÄÜ!\nend line"));
+
+ // unicode not supported yet
+ //result = text_search_strcasestr(str, cx_str("ÖÄÜ"));
+ //CX_TEST_ASSERT(!cx_strcmp(result, "öäüOAUÖÄÜ!\nend line"));
+
+ result = text_search_strcasestr(str, cx_str("hello"));
+ CX_TEST_ASSERT(!cx_strcmp(result, str));
+
+ result = text_search_strcasestr(str, cx_str("HELLO"));
+ CX_TEST_ASSERT(!cx_strcmp(result, str));
+
+ // test non-match
+ result = text_search_strcasestr(str, cx_str("World!"));
+ CX_TEST_ASSERT(result.ptr == NULL && result.length == 0);
+ }
+}
--- /dev/null
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2026 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef TEST_NOTE_H
+#define TEST_NOTE_H
+
+#include <cx/test.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+CX_TEST(test_text_search_strcasestr);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* TEST_NOTE_H */
+
#include <ui/ui.h>
#include <sys/stat.h>
+#include <locale.h>
#include "test-editor.h"
#include "test-store.h"
+#include "test-note.h"
#include "../types.h"
int main(int argc, char **argv) {
+ setlocale(LC_ALL, "de_DE.UTF-8");
+
struct stat s;
if(!stat("notetestdata", &s)) {
system("rm -Rf notetestdata");
}
-
+
ui_setappdir("notetestdata");
ui_init(NULL, 0, NULL);
register_types();
cx_test_register(suite, test_parse_markdown_list);
cx_test_register(suite, test_mddoc_linearization);
+ cx_test_register(suite, test_text_search_strcasestr);
+
cx_test_run_stdout(suite);
int err = suite->failure > 0 ? 1 : 0;
cx_test_suite_free(suite);